OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* t1parse.c */ | 3 /* t1parse.c */ |
4 /* */ | 4 /* */ |
5 /* Type 1 parser (body). */ | 5 /* Type 1 parser (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2005, 2008, 2009, 2012, 2013 by */ | 7 /* Copyright 1996-2005, 2008, 2009, 2012-2014 by */ |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 /* */ | 9 /* */ |
10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
11 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
15 /* */ | 15 /* */ |
16 /***************************************************************************/ | 16 /***************************************************************************/ |
17 | 17 |
18 | 18 |
19 /*************************************************************************/ | 19 /*************************************************************************/ |
20 /* */ | 20 /* */ |
21 /* The Type 1 parser is in charge of the following: */ | 21 /* The Type 1 parser is in charge of the following: */ |
22 /* */ | 22 /* */ |
23 /* - provide an implementation of a growing sequence of objects called */ | 23 /* - provide an implementation of a growing sequence of objects called */ |
24 /* a `T1_Table' (used to build various tables needed by the loader). */ | 24 /* a `T1_Table' (used to build various tables needed by the loader). */ |
25 /* */ | 25 /* */ |
26 /* - opening .pfb and .pfa files to extract their top-level and private */ | 26 /* - opening .pfb and .pfa files to extract their top-level and private */ |
27 /* dictionaries. */ | 27 /* dictionaries. */ |
28 /* */ | 28 /* */ |
29 /* - read numbers, arrays & strings from any dictionary. */ | 29 /* - read numbers, arrays & strings from any dictionary. */ |
30 /* */ | 30 /* */ |
31 /* See `t1load.c' to see how data is loaded from the font file. */ | 31 /* See `t1load.c' to see how data is loaded from the font file. */ |
32 /* */ | 32 /* */ |
33 /*************************************************************************/ | 33 /*************************************************************************/ |
34 | 34 |
35 | 35 |
36 #include "../../include/ft2build.h" | 36 #include <ft2build.h> |
37 #include "../../include/freetype/internal/ftdebug.h" | 37 #include FT_INTERNAL_DEBUG_H |
38 #include "../../include/freetype/internal/ftstream.h" | 38 #include FT_INTERNAL_STREAM_H |
39 #include "../../include/freetype/internal/psaux.h" | 39 #include FT_INTERNAL_POSTSCRIPT_AUX_H |
40 | 40 |
41 #include "t1parse.h" | 41 #include "t1parse.h" |
42 | 42 |
43 #include "t1errors.h" | 43 #include "t1errors.h" |
44 | 44 |
45 | 45 |
46 /*************************************************************************/ | 46 /*************************************************************************/ |
47 /* */ | 47 /* */ |
48 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ | 48 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
49 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ | 49 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 325 } |
326 } | 326 } |
327 else | 327 else |
328 { | 328 { |
329 /* We have already `loaded' the whole PFA font file into memory; */ | 329 /* We have already `loaded' the whole PFA font file into memory; */ |
330 /* if this is a memory resource, allocate a new block to hold */ | 330 /* if this is a memory resource, allocate a new block to hold */ |
331 /* the private dict. Otherwise, simply overwrite into the base */ | 331 /* the private dict. Otherwise, simply overwrite into the base */ |
332 /* dictionary block in the heap. */ | 332 /* dictionary block in the heap. */ |
333 | 333 |
334 /* first of all, look at the `eexec' keyword */ | 334 /* first of all, look at the `eexec' keyword */ |
335 FT_Byte* cur = parser->base_dict; | 335 FT_Byte* cur = parser->base_dict; |
336 FT_Byte* limit = cur + parser->base_len; | 336 FT_Byte* limit = cur + parser->base_len; |
337 FT_Byte c; | 337 FT_Byte c; |
| 338 FT_Pointer pos_lf; |
| 339 FT_Bool test_cr; |
338 | 340 |
339 | 341 |
340 Again: | 342 Again: |
341 for (;;) | 343 for (;;) |
342 { | 344 { |
343 c = cur[0]; | 345 c = cur[0]; |
344 if ( c == 'e' && cur + 9 < limit ) /* 9 = 5 letters for `eexec' + */ | 346 if ( c == 'e' && cur + 9 < limit ) /* 9 = 5 letters for `eexec' + */ |
345 /* whitespace + 4 chars */ | 347 /* whitespace + 4 chars */ |
346 { | 348 { |
347 if ( cur[1] == 'e' && | 349 if ( cur[1] == 'e' && |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 /* dictionary. We overwrite the base dictionary for disk-based */ | 395 /* dictionary. We overwrite the base dictionary for disk-based */ |
394 /* resources and allocate a new block otherwise */ | 396 /* resources and allocate a new block otherwise */ |
395 | 397 |
396 Found: | 398 Found: |
397 parser->root.limit = parser->base_dict + parser->base_len; | 399 parser->root.limit = parser->base_dict + parser->base_len; |
398 | 400 |
399 T1_Skip_PS_Token( parser ); | 401 T1_Skip_PS_Token( parser ); |
400 cur = parser->root.cursor; | 402 cur = parser->root.cursor; |
401 limit = parser->root.limit; | 403 limit = parser->root.limit; |
402 | 404 |
403 /* according to the Type1 spec, the first cipher byte must not be */ | 405 /* According to the Type 1 spec, the first cipher byte must not be */ |
404 /* an ASCII whitespace character code (blank, tab, carriage return */ | 406 /* an ASCII whitespace character code (blank, tab, carriage return */ |
405 /* or line feed). We have seen Type 1 fonts with two line feed */ | 407 /* or line feed). We have seen Type 1 fonts with two line feed */ |
406 /* characters... So skip now all whitespace character codes. */ | 408 /* characters... So skip now all whitespace character codes. */ |
407 while ( cur < limit && | 409 /* */ |
408 ( *cur == ' ' || | 410 /* On the other hand, Adobe's Type 1 parser handles fonts just */ |
409 *cur == '\t' || | 411 /* fine that are violating this limitation, so we add a heuristic */ |
410 *cur == '\r' || | 412 /* test to stop at \r only if it is not used for EOL. */ |
411 *cur == '\n' ) ) | 413 |
| 414 pos_lf = ft_memchr( cur, '\n', limit - cur ); |
| 415 test_cr = FT_BOOL( !pos_lf || |
| 416 pos_lf > ft_memchr( cur, '\r', limit - cur ) ); |
| 417 |
| 418 while ( cur < limit && |
| 419 ( *cur == ' ' || |
| 420 *cur == '\t' || |
| 421 (test_cr && *cur == '\r' ) || |
| 422 *cur == '\n' ) ) |
412 ++cur; | 423 ++cur; |
413 if ( cur >= limit ) | 424 if ( cur >= limit ) |
414 { | 425 { |
415 FT_ERROR(( "T1_Get_Private_Dict:" | 426 FT_ERROR(( "T1_Get_Private_Dict:" |
416 " `eexec' not properly terminated\n" )); | 427 " `eexec' not properly terminated\n" )); |
417 error = FT_THROW( Invalid_File_Format ); | 428 error = FT_THROW( Invalid_File_Format ); |
418 goto Exit; | 429 goto Exit; |
419 } | 430 } |
420 | 431 |
421 size = (FT_ULong)( parser->base_len - ( cur - parser->base_dict ) ); | 432 size = (FT_ULong)( parser->base_len - ( cur - parser->base_dict ) ); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 parser->root.cursor = parser->private_dict; | 499 parser->root.cursor = parser->private_dict; |
489 parser->root.limit = parser->root.cursor + parser->private_len; | 500 parser->root.limit = parser->root.cursor + parser->private_len; |
490 | 501 |
491 Fail: | 502 Fail: |
492 Exit: | 503 Exit: |
493 return error; | 504 return error; |
494 } | 505 } |
495 | 506 |
496 | 507 |
497 /* END */ | 508 /* END */ |
OLD | NEW |