1 /***************************************************************************/
5 /* Type 42 font parser (body). */
7 /* Copyright 2002-2014 by */
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 */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_INTERNAL_POSTSCRIPT_AUX_H
26 /*************************************************************************/
28 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
29 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
30 /* messages during execution. */
33 #define FT_COMPONENT trace_t42
37 t42_parse_font_matrix( T42_Face face,
40 t42_parse_encoding( T42_Face face,
44 t42_parse_charstrings( T42_Face face,
48 t42_parse_sfnts( T42_Face face,
52 /* as Type42 fonts have no Private dict, */
53 /* we set the last argument of T1_FIELD_XXX to 0 */
55 T1_FieldRec t42_keywords[] =
59 #define FT_STRUCTURE T1_FontInfo
61 #define T1CODE T1_FIELD_LOCATION_FONT_INFO
63 T1_FIELD_STRING( "version", version, 0 )
64 T1_FIELD_STRING( "Notice", notice, 0 )
65 T1_FIELD_STRING( "FullName", full_name, 0 )
66 T1_FIELD_STRING( "FamilyName", family_name, 0 )
67 T1_FIELD_STRING( "Weight", weight, 0 )
68 T1_FIELD_NUM ( "ItalicAngle", italic_angle, 0 )
69 T1_FIELD_BOOL ( "isFixedPitch", is_fixed_pitch, 0 )
70 T1_FIELD_NUM ( "UnderlinePosition", underline_position, 0 )
71 T1_FIELD_NUM ( "UnderlineThickness", underline_thickness, 0 )
74 #define FT_STRUCTURE PS_FontExtraRec
76 #define T1CODE T1_FIELD_LOCATION_FONT_EXTRA
78 T1_FIELD_NUM ( "FSType", fs_type, 0 )
81 #define FT_STRUCTURE T1_FontRec
83 #define T1CODE T1_FIELD_LOCATION_FONT_DICT
85 T1_FIELD_KEY ( "FontName", font_name, 0 )
86 T1_FIELD_NUM ( "PaintType", paint_type, 0 )
87 T1_FIELD_NUM ( "FontType", font_type, 0 )
88 T1_FIELD_FIXED( "StrokeWidth", stroke_width, 0 )
91 #define FT_STRUCTURE FT_BBox
93 #define T1CODE T1_FIELD_LOCATION_BBOX
95 T1_FIELD_BBOX("FontBBox", xMin, 0 )
97 T1_FIELD_CALLBACK( "FontMatrix", t42_parse_font_matrix, 0 )
98 T1_FIELD_CALLBACK( "Encoding", t42_parse_encoding, 0 )
99 T1_FIELD_CALLBACK( "CharStrings", t42_parse_charstrings, 0 )
100 T1_FIELD_CALLBACK( "sfnts", t42_parse_sfnts, 0 )
102 { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0, 0 }
106 #define T1_Add_Table( p, i, o, l ) (p)->funcs.add( (p), i, o, l )
107 #define T1_Done_Table( p ) \
110 if ( (p)->funcs.done ) \
111 (p)->funcs.done( p ); \
113 #define T1_Release_Table( p ) \
116 if ( (p)->funcs.release ) \
117 (p)->funcs.release( p ); \
120 #define T1_Skip_Spaces( p ) (p)->root.funcs.skip_spaces( &(p)->root )
121 #define T1_Skip_PS_Token( p ) (p)->root.funcs.skip_PS_token( &(p)->root )
123 #define T1_ToInt( p ) \
124 (p)->root.funcs.to_int( &(p)->root )
125 #define T1_ToBytes( p, b, m, n, d ) \
126 (p)->root.funcs.to_bytes( &(p)->root, b, m, n, d )
128 #define T1_ToFixedArray( p, m, f, t ) \
129 (p)->root.funcs.to_fixed_array( &(p)->root, m, f, t )
130 #define T1_ToToken( p, t ) \
131 (p)->root.funcs.to_token( &(p)->root, t )
133 #define T1_Load_Field( p, f, o, m, pf ) \
134 (p)->root.funcs.load_field( &(p)->root, f, o, m, pf )
135 #define T1_Load_Field_Table( p, f, o, m, pf ) \
136 (p)->root.funcs.load_field_table( &(p)->root, f, o, m, pf )
139 /********************* Parsing Functions ******************/
141 FT_LOCAL_DEF( FT_Error )
142 t42_parser_init( T42_Parser parser,
145 PSAux_Service psaux )
147 FT_Error error = FT_Err_Ok;
151 psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
153 parser->stream = stream;
154 parser->base_len = 0;
155 parser->base_dict = 0;
156 parser->in_memory = 0;
158 /*******************************************************************/
160 /* Here a short summary of what is going on: */
162 /* When creating a new Type 42 parser, we try to locate and load */
163 /* the base dictionary, loading the whole font into memory. */
165 /* When `loading' the base dictionary, we only set up pointers */
166 /* in the case of a memory-based stream. Otherwise, we allocate */
167 /* and load the base dictionary in it. */
169 /* parser->in_memory is set if we have a memory stream. */
172 if ( FT_STREAM_SEEK( 0L ) ||
173 FT_FRAME_ENTER( 17 ) )
176 if ( ft_memcmp( stream->cursor, "%!PS-TrueTypeFont", 17 ) != 0 )
178 FT_TRACE2(( " not a Type42 font\n" ));
179 error = FT_THROW( Unknown_File_Format );
184 if ( error || FT_STREAM_SEEK( 0 ) )
189 /* now, try to load `size' bytes of the `base' dictionary we */
190 /* found previously */
192 /* if it is a memory-based resource, set up pointers */
195 parser->base_dict = (FT_Byte*)stream->base + stream->pos;
196 parser->base_len = size;
197 parser->in_memory = 1;
199 /* check that the `size' field is valid */
200 if ( FT_STREAM_SKIP( size ) )
205 /* read segment in memory */
206 if ( FT_ALLOC( parser->base_dict, size ) ||
207 FT_STREAM_READ( parser->base_dict, size ) )
210 parser->base_len = size;
213 parser->root.base = parser->base_dict;
214 parser->root.cursor = parser->base_dict;
215 parser->root.limit = parser->root.cursor + parser->base_len;
218 if ( error && !parser->in_memory )
219 FT_FREE( parser->base_dict );
226 t42_parser_done( T42_Parser parser )
228 FT_Memory memory = parser->root.memory;
231 /* free the base dictionary only when we have a disk stream */
232 if ( !parser->in_memory )
233 FT_FREE( parser->base_dict );
235 parser->root.funcs.done( &parser->root );
240 t42_is_space( FT_Byte c )
242 return ( c == ' ' || c == '\t' ||
243 c == '\r' || c == '\n' || c == '\f' ||
249 t42_parse_font_matrix( T42_Face face,
252 T42_Parser parser = &loader->parser;
253 FT_Matrix* matrix = &face->type1.font_matrix;
254 FT_Vector* offset = &face->type1.font_offset;
255 FT_Face root = (FT_Face)&face->root;
261 result = T1_ToFixedArray( parser, 6, temp, 3 );
265 parser->root.error = FT_THROW( Invalid_File_Format );
269 temp_scale = FT_ABS( temp[3] );
271 if ( temp_scale == 0 )
273 FT_ERROR(( "t1_parse_font_matrix: invalid font matrix\n" ));
274 parser->root.error = FT_THROW( Invalid_File_Format );
278 /* Set Units per EM based on FontMatrix values. We set the value to */
279 /* 1000 / temp_scale, because temp_scale was already multiplied by */
280 /* 1000 (in t1_tofixed, from psobjs.c). */
282 root->units_per_EM = (FT_UShort)FT_DivFix( 1000, temp_scale );
284 /* we need to scale the values by 1.0/temp_scale */
285 if ( temp_scale != 0x10000L )
287 temp[0] = FT_DivFix( temp[0], temp_scale );
288 temp[1] = FT_DivFix( temp[1], temp_scale );
289 temp[2] = FT_DivFix( temp[2], temp_scale );
290 temp[4] = FT_DivFix( temp[4], temp_scale );
291 temp[5] = FT_DivFix( temp[5], temp_scale );
292 temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L;
295 matrix->xx = temp[0];
296 matrix->yx = temp[1];
297 matrix->xy = temp[2];
298 matrix->yy = temp[3];
300 /* note that the offsets must be expressed in integer font units */
301 offset->x = temp[4] >> 16;
302 offset->y = temp[5] >> 16;
307 t42_parse_encoding( T42_Face face,
310 T42_Parser parser = &loader->parser;
312 FT_Byte* limit = parser->root.limit;
314 PSAux_Service psaux = (PSAux_Service)face->psaux;
317 T1_Skip_Spaces( parser );
318 cur = parser->root.cursor;
321 FT_ERROR(( "t42_parse_encoding: out of bounds\n" ));
322 parser->root.error = FT_THROW( Invalid_File_Format );
326 /* if we have a number or `[', the encoding is an array, */
327 /* and we must load it now */
328 if ( ft_isdigit( *cur ) || *cur == '[' )
330 T1_Encoding encode = &face->type1.encoding;
332 PS_Table char_table = &loader->encoding_table;
333 FT_Memory memory = parser->root.memory;
335 FT_Bool only_immediates = 0;
338 /* read the number of entries in the encoding; should be 256 */
343 parser->root.cursor++;
346 count = (FT_Int)T1_ToInt( parser );
348 T1_Skip_Spaces( parser );
349 if ( parser->root.cursor >= limit )
352 /* we use a T1_Table to store our charnames */
353 loader->num_chars = encode->num_chars = count;
354 if ( FT_NEW_ARRAY( encode->char_index, count ) ||
355 FT_NEW_ARRAY( encode->char_name, count ) ||
356 FT_SET_ERROR( psaux->ps_table_funcs->init(
357 char_table, count, memory ) ) )
359 parser->root.error = error;
363 /* We need to `zero' out encoding_table.elements */
364 for ( n = 0; n < count; n++ )
366 char* notdef = (char *)".notdef";
369 (void)T1_Add_Table( char_table, n, notdef, 8 );
372 /* Now we need to read records of the form */
374 /* ... charcode /charname ... */
376 /* for each entry in our table. */
378 /* We simply look for a number followed by an immediate */
379 /* name. Note that this ignores correctly the sequence */
380 /* that is often seen in type42 fonts: */
382 /* 0 1 255 { 1 index exch /.notdef put } for dup */
384 /* used to clean the encoding array before anything else. */
386 /* Alternatively, if the array is directly given as */
388 /* /Encoding [ ... ] */
390 /* we only read immediates. */
393 T1_Skip_Spaces( parser );
395 while ( parser->root.cursor < limit )
397 cur = parser->root.cursor;
399 /* we stop when we encounter `def' or `]' */
400 if ( *cur == 'd' && cur + 3 < limit )
402 if ( cur[1] == 'e' &&
404 t42_is_space( cur[3] ) )
406 FT_TRACE6(( "encoding end\n" ));
413 FT_TRACE6(( "encoding end\n" ));
418 /* check whether we have found an entry */
419 if ( ft_isdigit( *cur ) || only_immediates )
424 if ( only_immediates )
428 charcode = (FT_Int)T1_ToInt( parser );
429 T1_Skip_Spaces( parser );
432 cur = parser->root.cursor;
434 if ( cur + 2 < limit && *cur == '/' && n < count )
441 parser->root.cursor = cur;
442 T1_Skip_PS_Token( parser );
443 if ( parser->root.cursor >= limit )
445 if ( parser->root.error )
448 len = parser->root.cursor - cur;
450 parser->root.error = T1_Add_Table( char_table, charcode,
452 if ( parser->root.error )
454 char_table->elements[charcode][len] = '\0';
458 else if ( only_immediates )
460 /* Since the current position is not updated for */
461 /* immediates-only mode we would get an infinite loop if */
462 /* we don't do anything here. */
464 /* This encoding array is not valid according to the type1 */
465 /* specification (it might be an encoding for a CID type1 */
466 /* font, however), so we conclude that this font is NOT a */
468 parser->root.error = FT_THROW( Unknown_File_Format );
474 T1_Skip_PS_Token( parser );
475 if ( parser->root.error )
479 T1_Skip_Spaces( parser );
482 face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY;
483 parser->root.cursor = cur;
486 /* Otherwise, we should have either `StandardEncoding', */
487 /* `ExpertEncoding', or `ISOLatin1Encoding' */
490 if ( cur + 17 < limit &&
491 ft_strncmp( (const char*)cur, "StandardEncoding", 16 ) == 0 )
492 face->type1.encoding_type = T1_ENCODING_TYPE_STANDARD;
494 else if ( cur + 15 < limit &&
495 ft_strncmp( (const char*)cur, "ExpertEncoding", 14 ) == 0 )
496 face->type1.encoding_type = T1_ENCODING_TYPE_EXPERT;
498 else if ( cur + 18 < limit &&
499 ft_strncmp( (const char*)cur, "ISOLatin1Encoding", 17 ) == 0 )
500 face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1;
503 parser->root.error = FT_THROW( Ignore );
508 typedef enum T42_Load_Status_
518 t42_parse_sfnts( T42_Face face,
521 T42_Parser parser = &loader->parser;
522 FT_Memory memory = parser->root.memory;
524 FT_Byte* limit = parser->root.limit;
526 FT_Int num_tables = 0;
529 FT_Long n, string_size, old_string_size, real_size;
530 FT_Byte* string_buf = NULL;
531 FT_Bool allocated = 0;
533 T42_Load_Status status;
538 /* /sfnts [ <hexstring> <hexstring> ... ] def */
543 /* <num_bin_bytes> RD <binary data> */
544 /* <num_bin_bytes> RD <binary data> */
548 /* with exactly one space after the `RD' token. */
550 T1_Skip_Spaces( parser );
552 if ( parser->root.cursor >= limit || *parser->root.cursor++ != '[' )
554 FT_ERROR(( "t42_parse_sfnts: can't find begin of sfnts vector\n" ));
555 error = FT_THROW( Invalid_File_Format );
559 T1_Skip_Spaces( parser );
560 status = BEFORE_START;
565 while ( parser->root.cursor < limit )
567 cur = parser->root.cursor;
571 parser->root.cursor++;
575 else if ( *cur == '<' )
577 T1_Skip_PS_Token( parser );
578 if ( parser->root.error )
581 /* don't include delimiters */
582 string_size = (FT_Long)( ( parser->root.cursor - cur - 2 + 1 ) / 2 );
585 FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" ));
586 error = FT_THROW( Invalid_File_Format );
589 if ( FT_REALLOC( string_buf, old_string_size, string_size ) )
594 parser->root.cursor = cur;
595 (void)T1_ToBytes( parser, string_buf, string_size, &real_size, 1 );
596 old_string_size = string_size;
597 string_size = real_size;
600 else if ( ft_isdigit( *cur ) )
604 FT_ERROR(( "t42_parse_sfnts: "
605 "can't handle mixed binary and hex strings\n" ));
606 error = FT_THROW( Invalid_File_Format );
610 string_size = T1_ToInt( parser );
611 if ( string_size < 0 )
613 FT_ERROR(( "t42_parse_sfnts: invalid string size\n" ));
614 error = FT_THROW( Invalid_File_Format );
618 T1_Skip_PS_Token( parser ); /* `RD' */
619 if ( parser->root.error )
622 string_buf = parser->root.cursor + 1; /* one space after `RD' */
624 if ( limit - parser->root.cursor < string_size )
626 FT_ERROR(( "t42_parse_sfnts: too much binary data\n" ));
627 error = FT_THROW( Invalid_File_Format );
631 parser->root.cursor += string_size + 1;
636 FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" ));
637 error = FT_THROW( Invalid_File_Format );
641 /* A string can have a trailing zero (odd) byte for padding. */
643 if ( ( string_size & 1 ) && string_buf[string_size - 1] == 0 )
648 FT_ERROR(( "t42_parse_sfnts: invalid string\n" ));
649 error = FT_THROW( Invalid_File_Format );
653 for ( n = 0; n < string_size; n++ )
658 /* load offset table, 12 bytes */
661 face->ttf_data[count++] = string_buf[n];
666 num_tables = 16 * face->ttf_data[4] + face->ttf_data[5];
667 status = BEFORE_TABLE_DIR;
668 face->ttf_size = 12 + 16 * num_tables;
670 if ( (FT_ULong)( limit - parser->root.cursor ) < face->ttf_size )
672 FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" ));
673 error = FT_THROW( Invalid_File_Format );
677 if ( FT_REALLOC( face->ttf_data, 12, face->ttf_size ) )
682 case BEFORE_TABLE_DIR:
683 /* the offset table is read; read the table directory */
684 if ( count < face->ttf_size )
686 face->ttf_data[count++] = string_buf[n];
695 for ( i = 0; i < num_tables; i++ )
697 FT_Byte* p = face->ttf_data + 12 + 16 * i + 12;
700 len = FT_PEEK_ULONG( p );
702 /* Pad to a 4-byte boundary length */
703 face->ttf_size += ( len + 3 ) & ~3;
706 status = OTHER_TABLES;
708 /* there are no more than 256 tables, so no size check here */
709 if ( FT_REALLOC( face->ttf_data, 12 + 16 * num_tables,
710 face->ttf_size + 1 ) )
716 /* all other tables are just copied */
717 if ( count >= face->ttf_size )
719 FT_ERROR(( "t42_parse_sfnts: too much binary data\n" ));
720 error = FT_THROW( Invalid_File_Format );
723 face->ttf_data[count++] = string_buf[n];
727 T1_Skip_Spaces( parser );
730 /* if control reaches this point, the format was not valid */
731 error = FT_THROW( Invalid_File_Format );
734 parser->root.error = error;
738 FT_FREE( string_buf );
743 t42_parse_charstrings( T42_Face face,
746 T42_Parser parser = &loader->parser;
747 PS_Table code_table = &loader->charstrings;
748 PS_Table name_table = &loader->glyph_names;
749 PS_Table swap_table = &loader->swap_table;
750 FT_Memory memory = parser->root.memory;
753 PSAux_Service psaux = (PSAux_Service)face->psaux;
756 FT_Byte* limit = parser->root.limit;
758 FT_UInt notdef_index = 0;
759 FT_Byte notdef_found = 0;
762 T1_Skip_Spaces( parser );
764 if ( parser->root.cursor >= limit )
766 FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
767 error = FT_THROW( Invalid_File_Format );
771 if ( ft_isdigit( *parser->root.cursor ) )
773 loader->num_glyphs = (FT_UInt)T1_ToInt( parser );
774 if ( parser->root.error )
777 else if ( *parser->root.cursor == '<' )
779 /* We have `<< ... >>'. Count the number of `/' in the dictionary */
780 /* to get its size. */
784 T1_Skip_PS_Token( parser );
785 if ( parser->root.error )
787 T1_Skip_Spaces( parser );
788 cur = parser->root.cursor;
790 while ( parser->root.cursor < limit )
792 if ( *parser->root.cursor == '/' )
794 else if ( *parser->root.cursor == '>' )
796 loader->num_glyphs = count;
797 parser->root.cursor = cur; /* rewind */
800 T1_Skip_PS_Token( parser );
801 if ( parser->root.error )
803 T1_Skip_Spaces( parser );
808 FT_ERROR(( "t42_parse_charstrings: invalid token\n" ));
809 error = FT_THROW( Invalid_File_Format );
813 if ( parser->root.cursor >= limit )
815 FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
816 error = FT_THROW( Invalid_File_Format );
820 /* initialize tables */
822 error = psaux->ps_table_funcs->init( code_table,
828 error = psaux->ps_table_funcs->init( name_table,
834 /* Initialize table for swapping index notdef_index and */
835 /* index 0 names and codes (if necessary). */
837 error = psaux->ps_table_funcs->init( swap_table, 4, memory );
845 /* The format is simple: */
846 /* `/glyphname' + index [+ def] */
848 T1_Skip_Spaces( parser );
850 cur = parser->root.cursor;
854 /* We stop when we find an `end' keyword or '>' */
859 t42_is_space( cur[3] ) )
864 T1_Skip_PS_Token( parser );
865 if ( parser->root.cursor >= limit )
867 FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
868 error = FT_THROW( Invalid_File_Format );
871 if ( parser->root.error )
879 if ( cur + 2 >= limit )
881 FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
882 error = FT_THROW( Invalid_File_Format );
886 cur++; /* skip `/' */
887 len = parser->root.cursor - cur;
889 error = T1_Add_Table( name_table, n, cur, len + 1 );
893 /* add a trailing zero to the name table */
894 name_table->elements[n][len] = '\0';
896 /* record index of /.notdef */
898 ft_strcmp( ".notdef",
899 (const char*)(name_table->elements[n]) ) == 0 )
905 T1_Skip_Spaces( parser );
907 cur = parser->root.cursor;
909 (void)T1_ToInt( parser );
910 if ( parser->root.cursor >= limit )
912 FT_ERROR(( "t42_parse_charstrings: out of bounds\n" ));
913 error = FT_THROW( Invalid_File_Format );
917 len = parser->root.cursor - cur;
919 error = T1_Add_Table( code_table, n, cur, len + 1 );
923 code_table->elements[n][len] = '\0';
926 if ( n >= loader->num_glyphs )
931 loader->num_glyphs = n;
935 FT_ERROR(( "t42_parse_charstrings: no /.notdef glyph\n" ));
936 error = FT_THROW( Invalid_File_Format );
940 /* if /.notdef does not occupy index 0, do our magic. */
941 if ( ft_strcmp( (const char*)".notdef",
942 (const char*)name_table->elements[0] ) )
944 /* Swap glyph in index 0 with /.notdef glyph. First, add index 0 */
945 /* name and code entries to swap_table. Then place notdef_index */
946 /* name and code entries into swap_table. Then swap name and code */
947 /* entries at indices notdef_index and 0 using values stored in */
951 error = T1_Add_Table( swap_table, 0,
952 name_table->elements[0],
953 name_table->lengths [0] );
958 error = T1_Add_Table( swap_table, 1,
959 code_table->elements[0],
960 code_table->lengths [0] );
964 /* Index notdef_index name */
965 error = T1_Add_Table( swap_table, 2,
966 name_table->elements[notdef_index],
967 name_table->lengths [notdef_index] );
971 /* Index notdef_index code */
972 error = T1_Add_Table( swap_table, 3,
973 code_table->elements[notdef_index],
974 code_table->lengths [notdef_index] );
978 error = T1_Add_Table( name_table, notdef_index,
979 swap_table->elements[0],
980 swap_table->lengths [0] );
984 error = T1_Add_Table( code_table, notdef_index,
985 swap_table->elements[1],
986 swap_table->lengths [1] );
990 error = T1_Add_Table( name_table, 0,
991 swap_table->elements[2],
992 swap_table->lengths [2] );
996 error = T1_Add_Table( code_table, 0,
997 swap_table->elements[3],
998 swap_table->lengths [3] );
1007 parser->root.error = error;
1012 t42_load_keyword( T42_Face face,
1019 FT_UInt max_objects = 0;
1022 /* if the keyword has a dedicated callback, call it */
1023 if ( field->type == T1_FIELD_TYPE_CALLBACK )
1025 field->reader( (FT_Face)face, loader );
1026 error = loader->parser.root.error;
1030 /* now the keyword is either a simple field or a table of fields; */
1031 /* we are now going to take care of it */
1033 switch ( field->location )
1035 case T1_FIELD_LOCATION_FONT_INFO:
1036 dummy_object = &face->type1.font_info;
1039 case T1_FIELD_LOCATION_FONT_EXTRA:
1040 dummy_object = &face->type1.font_extra;
1043 case T1_FIELD_LOCATION_BBOX:
1044 dummy_object = &face->type1.font_bbox;
1048 dummy_object = &face->type1;
1051 objects = &dummy_object;
1053 if ( field->type == T1_FIELD_TYPE_INTEGER_ARRAY ||
1054 field->type == T1_FIELD_TYPE_FIXED_ARRAY )
1055 error = T1_Load_Field_Table( &loader->parser, field,
1056 objects, max_objects, 0 );
1058 error = T1_Load_Field( &loader->parser, field,
1059 objects, max_objects, 0 );
1066 FT_LOCAL_DEF( FT_Error )
1067 t42_parse_dict( T42_Face face,
1072 T42_Parser parser = &loader->parser;
1074 FT_Int n_keywords = (FT_Int)( sizeof ( t42_keywords ) /
1075 sizeof ( t42_keywords[0] ) );
1078 parser->root.cursor = base;
1079 parser->root.limit = base + size;
1080 parser->root.error = FT_Err_Ok;
1082 limit = parser->root.limit;
1084 T1_Skip_Spaces( parser );
1086 while ( parser->root.cursor < limit )
1091 cur = parser->root.cursor;
1093 /* look for `FontDirectory' which causes problems for some fonts */
1094 if ( *cur == 'F' && cur + 25 < limit &&
1095 ft_strncmp( (char*)cur, "FontDirectory", 13 ) == 0 )
1100 /* skip the `FontDirectory' keyword */
1101 T1_Skip_PS_Token( parser );
1102 T1_Skip_Spaces ( parser );
1103 cur = cur2 = parser->root.cursor;
1105 /* look up the `known' keyword */
1106 while ( cur < limit )
1108 if ( *cur == 'k' && cur + 5 < limit &&
1109 ft_strncmp( (char*)cur, "known", 5 ) == 0 )
1112 T1_Skip_PS_Token( parser );
1113 if ( parser->root.error )
1115 T1_Skip_Spaces ( parser );
1116 cur = parser->root.cursor;
1124 /* skip the `known' keyword and the token following it */
1125 T1_Skip_PS_Token( parser );
1126 T1_ToToken( parser, &token );
1128 /* if the last token was an array, skip it! */
1129 if ( token.type == T1_TOKEN_TYPE_ARRAY )
1130 cur2 = parser->root.cursor;
1132 parser->root.cursor = cur2;
1135 /* look for immediates */
1136 else if ( *cur == '/' && cur + 2 < limit )
1143 parser->root.cursor = cur;
1144 T1_Skip_PS_Token( parser );
1145 if ( parser->root.error )
1148 len = parser->root.cursor - cur;
1150 if ( len > 0 && len < 22 && parser->root.cursor < limit )
1155 /* now compare the immediate name to the keyword table */
1157 /* loop through all known keywords */
1158 for ( i = 0; i < n_keywords; i++ )
1160 T1_Field keyword = (T1_Field)&t42_keywords[i];
1161 FT_Byte *name = (FT_Byte*)keyword->ident;
1167 if ( cur[0] == name[0] &&
1168 len == (FT_PtrDist)ft_strlen( (const char *)name ) &&
1169 ft_memcmp( cur, name, len ) == 0 )
1171 /* we found it -- run the parsing callback! */
1172 parser->root.error = t42_load_keyword( face,
1175 if ( parser->root.error )
1176 return parser->root.error;
1184 T1_Skip_PS_Token( parser );
1185 if ( parser->root.error )
1189 T1_Skip_Spaces( parser );
1193 return parser->root.error;
1197 FT_LOCAL_DEF( void )
1198 t42_loader_init( T42_Loader loader,
1203 FT_MEM_ZERO( loader, sizeof ( *loader ) );
1204 loader->num_glyphs = 0;
1205 loader->num_chars = 0;
1207 /* initialize the tables -- simply set their `init' field to 0 */
1208 loader->encoding_table.init = 0;
1209 loader->charstrings.init = 0;
1210 loader->glyph_names.init = 0;
1214 FT_LOCAL_DEF( void )
1215 t42_loader_done( T42_Loader loader )
1217 T42_Parser parser = &loader->parser;
1220 /* finalize tables */
1221 T1_Release_Table( &loader->encoding_table );
1222 T1_Release_Table( &loader->charstrings );
1223 T1_Release_Table( &loader->glyph_names );
1224 T1_Release_Table( &loader->swap_table );
1226 /* finalize parser */
1227 t42_parser_done( parser );