1 /***************************************************************************/
5 /* Load the basic TrueType tables, i.e., tables that can be either in */
6 /* TTF or OTF fonts (body). */
8 /* Copyright 1996-2010, 2012-2014 by */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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 */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
17 /***************************************************************************/
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_TRUETYPE_TAGS_H
29 /*************************************************************************/
31 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
32 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
33 /* messages during execution. */
36 #define FT_COMPONENT trace_ttload
39 /*************************************************************************/
42 /* tt_face_lookup_table */
45 /* Looks for a TrueType table by name. */
48 /* face :: A face object handle. */
50 /* tag :: The searched tag. */
53 /* A pointer to the table directory entry. 0 if not found. */
55 FT_LOCAL_DEF( TT_Table )
56 tt_face_lookup_table( TT_Face face,
61 #ifdef FT_DEBUG_LEVEL_TRACE
62 FT_Bool zero_length = FALSE;
66 FT_TRACE4(( "tt_face_lookup_table: %08p, `%c%c%c%c' -- ",
68 (FT_Char)( tag >> 24 ),
69 (FT_Char)( tag >> 16 ),
70 (FT_Char)( tag >> 8 ),
73 entry = face->dir_tables;
74 limit = entry + face->num_tables;
76 for ( ; entry < limit; entry++ )
78 /* For compatibility with Windows, we consider */
79 /* zero-length tables the same as missing tables. */
80 if ( entry->Tag == tag )
82 if ( entry->Length != 0 )
84 FT_TRACE4(( "found table.\n" ));
87 #ifdef FT_DEBUG_LEVEL_TRACE
93 #ifdef FT_DEBUG_LEVEL_TRACE
95 FT_TRACE4(( "ignoring empty table\n" ));
97 FT_TRACE4(( "could not find table\n" ));
104 /*************************************************************************/
107 /* tt_face_goto_table */
110 /* Looks for a TrueType table by name, then seek a stream to it. */
113 /* face :: A face object handle. */
115 /* tag :: The searched tag. */
117 /* stream :: The stream to seek when the table is found. */
120 /* length :: The length of the table if found, undefined otherwise. */
123 /* FreeType error code. 0 means success. */
125 FT_LOCAL_DEF( FT_Error )
126 tt_face_goto_table( TT_Face face,
135 table = tt_face_lookup_table( face, tag );
139 *length = table->Length;
141 if ( FT_STREAM_SEEK( table->Offset ) )
145 error = FT_THROW( Table_Missing );
154 /* - check that `num_tables' is valid (and adjust it if necessary) */
156 /* - look for a `head' table, check its size, and parse it to check */
157 /* whether its `magic' field is correctly set */
159 /* - errors (except errors returned by stream handling) */
161 /* SFNT_Err_Unknown_File_Format: */
162 /* no table is defined in directory, it is not sfnt-wrapped */
164 /* SFNT_Err_Table_Missing: */
165 /* table directory is valid, but essential tables */
166 /* (head/bhed/SING) are missing */
169 check_table_dir( SFNT_Header sfnt,
173 FT_UShort nn, valid_entries = 0;
174 FT_UInt has_head = 0, has_sing = 0, has_meta = 0;
175 FT_ULong offset = sfnt->offset + 12;
177 static const FT_Frame_Field table_dir_entry_fields[] =
180 #define FT_STRUCTURE TT_TableRec
182 FT_FRAME_START( 16 ),
183 FT_FRAME_ULONG( Tag ),
184 FT_FRAME_ULONG( CheckSum ),
185 FT_FRAME_ULONG( Offset ),
186 FT_FRAME_ULONG( Length ),
191 if ( FT_STREAM_SEEK( offset ) )
194 for ( nn = 0; nn < sfnt->num_tables; nn++ )
199 if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields, &table ) )
202 FT_TRACE2(( "check_table_dir:"
203 " can read only %d table%s in font (instead of %d)\n",
204 nn, nn == 1 ? "" : "s", sfnt->num_tables ));
205 sfnt->num_tables = nn;
209 /* we ignore invalid tables */
211 /* table.Offset + table.Length > stream->size ? */
212 if ( table.Length > stream->size ||
213 table.Offset > stream->size - table.Length )
215 FT_TRACE2(( "check_table_dir: table entry %d invalid\n", nn ));
221 if ( table.Tag == TTAG_head || table.Tag == TTAG_bhed )
226 #ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
227 if ( table.Tag == TTAG_head )
232 * The table length should be 0x36, but certain font tools make it
233 * 0x38, so we will just check that it is greater.
235 * Note that according to the specification, the table must be
236 * padded to 32-bit lengths, but this doesn't apply to the value of
237 * its `Length' field!
240 if ( table.Length < 0x36 )
242 FT_TRACE2(( "check_table_dir:"
243 " `head' or `bhed' table too small\n" ));
244 error = FT_THROW( Table_Missing );
248 if ( FT_STREAM_SEEK( table.Offset + 12 ) ||
249 FT_READ_ULONG( magic ) )
252 if ( magic != 0x5F0F3CF5UL )
253 FT_TRACE2(( "check_table_dir:"
254 " invalid magic number in `head' or `bhed' table\n"));
256 if ( FT_STREAM_SEEK( offset + ( nn + 1 ) * 16 ) )
259 else if ( table.Tag == TTAG_SING )
261 else if ( table.Tag == TTAG_META )
265 sfnt->num_tables = valid_entries;
267 if ( sfnt->num_tables == 0 )
269 FT_TRACE2(( "check_table_dir: no tables found\n" ));
270 error = FT_THROW( Unknown_File_Format );
274 /* if `sing' and `meta' tables are present, there is no `head' table */
275 if ( has_head || ( has_sing && has_meta ) )
282 FT_TRACE2(( "check_table_dir:" ));
283 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
284 FT_TRACE2(( " neither `head', `bhed', nor `sing' table found\n" ));
286 FT_TRACE2(( " neither `head' nor `sing' table found\n" ));
288 error = FT_THROW( Table_Missing );
296 /*************************************************************************/
299 /* tt_face_load_font_dir */
302 /* Loads the header of a SFNT font file. */
305 /* face :: A handle to the target face object. */
307 /* stream :: The input stream. */
310 /* sfnt :: The SFNT header. */
313 /* FreeType error code. 0 means success. */
316 /* The stream cursor must be at the beginning of the font directory. */
318 FT_LOCAL_DEF( FT_Error )
319 tt_face_load_font_dir( TT_Face face,
324 FT_Memory memory = stream->memory;
328 static const FT_Frame_Field offset_table_fields[] =
331 #define FT_STRUCTURE SFNT_HeaderRec
334 FT_FRAME_USHORT( num_tables ),
335 FT_FRAME_USHORT( search_range ),
336 FT_FRAME_USHORT( entry_selector ),
337 FT_FRAME_USHORT( range_shift ),
342 FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face ));
344 /* read the offset table */
346 sfnt.offset = FT_STREAM_POS();
348 if ( FT_READ_ULONG( sfnt.format_tag ) ||
349 FT_STREAM_READ_FIELDS( offset_table_fields, &sfnt ) )
352 /* many fonts don't have these fields set correctly */
354 if ( sfnt.search_range != 1 << ( sfnt.entry_selector + 4 ) ||
355 sfnt.search_range + sfnt.range_shift != sfnt.num_tables << 4 )
356 return FT_THROW( Unknown_File_Format );
359 /* load the table directory */
361 FT_TRACE2(( "-- Number of tables: %10u\n", sfnt.num_tables ));
362 FT_TRACE2(( "-- Format version: 0x%08lx\n", sfnt.format_tag ));
364 if ( sfnt.format_tag != TTAG_OTTO )
367 error = check_table_dir( &sfnt, stream );
370 FT_TRACE2(( "tt_face_load_font_dir:"
371 " invalid table directory for TrueType\n" ));
377 face->num_tables = sfnt.num_tables;
378 face->format_tag = sfnt.format_tag;
380 if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) )
383 if ( FT_STREAM_SEEK( sfnt.offset + 12 ) ||
384 FT_FRAME_ENTER( face->num_tables * 16L ) )
387 entry = face->dir_tables;
390 " tag offset length checksum\n"
391 " ----------------------------------\n" ));
393 for ( nn = 0; nn < sfnt.num_tables; nn++ )
395 entry->Tag = FT_GET_TAG4();
396 entry->CheckSum = FT_GET_ULONG();
397 entry->Offset = FT_GET_ULONG();
398 entry->Length = FT_GET_ULONG();
400 /* ignore invalid tables */
402 /* entry->Offset + entry->Length > stream->size ? */
403 if ( entry->Length > stream->size ||
404 entry->Offset > stream->size - entry->Length )
408 FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx\n",
409 (FT_Char)( entry->Tag >> 24 ),
410 (FT_Char)( entry->Tag >> 16 ),
411 (FT_Char)( entry->Tag >> 8 ),
412 (FT_Char)( entry->Tag ),
422 FT_TRACE2(( "table directory loaded\n\n" ));
429 /*************************************************************************/
432 /* tt_face_load_any */
435 /* Loads any font table into client memory. */
438 /* face :: The face object to look for. */
440 /* tag :: The tag of table to load. Use the value 0 if you want */
441 /* to access the whole font file, else set this parameter */
442 /* to a valid TrueType table tag that you can forge with */
443 /* the MAKE_TT_TAG macro. */
445 /* offset :: The starting offset in the table (or the file if */
448 /* length :: The address of the decision variable: */
450 /* If length == NULL: */
451 /* Loads the whole table. Returns an error if */
454 /* If *length == 0: */
455 /* Exits immediately; returning the length of the given */
456 /* table or of the font file, depending on the value of */
459 /* If *length != 0: */
460 /* Loads the next `length' bytes of table or font, */
461 /* starting at offset `offset' (in table or font too). */
464 /* buffer :: The address of target buffer. */
467 /* FreeType error code. 0 means success. */
469 FT_LOCAL_DEF( FT_Error )
470 tt_face_load_any( TT_Face face,
484 /* look for tag in font directory */
485 table = tt_face_lookup_table( face, tag );
488 error = FT_THROW( Table_Missing );
492 offset += table->Offset;
493 size = table->Length;
496 /* tag == 0 -- the user wants to access the font file directly */
497 size = face->root.stream->size;
499 if ( length && *length == 0 )
509 stream = face->root.stream;
510 /* the `if' is syntactic sugar for picky compilers */
511 if ( FT_STREAM_READ_AT( offset, buffer, size ) )
519 /*************************************************************************/
522 /* tt_face_load_generic_header */
525 /* Loads the TrueType table `head' or `bhed'. */
528 /* face :: A handle to the target face object. */
530 /* stream :: The input stream. */
533 /* FreeType error code. 0 means success. */
536 tt_face_load_generic_header( TT_Face face,
543 static const FT_Frame_Field header_fields[] =
546 #define FT_STRUCTURE TT_Header
548 FT_FRAME_START( 54 ),
549 FT_FRAME_ULONG ( Table_Version ),
550 FT_FRAME_ULONG ( Font_Revision ),
551 FT_FRAME_LONG ( CheckSum_Adjust ),
552 FT_FRAME_LONG ( Magic_Number ),
553 FT_FRAME_USHORT( Flags ),
554 FT_FRAME_USHORT( Units_Per_EM ),
555 FT_FRAME_LONG ( Created[0] ),
556 FT_FRAME_LONG ( Created[1] ),
557 FT_FRAME_LONG ( Modified[0] ),
558 FT_FRAME_LONG ( Modified[1] ),
559 FT_FRAME_SHORT ( xMin ),
560 FT_FRAME_SHORT ( yMin ),
561 FT_FRAME_SHORT ( xMax ),
562 FT_FRAME_SHORT ( yMax ),
563 FT_FRAME_USHORT( Mac_Style ),
564 FT_FRAME_USHORT( Lowest_Rec_PPEM ),
565 FT_FRAME_SHORT ( Font_Direction ),
566 FT_FRAME_SHORT ( Index_To_Loc_Format ),
567 FT_FRAME_SHORT ( Glyph_Data_Format ),
572 error = face->goto_table( face, tag, stream, 0 );
576 header = &face->header;
578 if ( FT_STREAM_READ_FIELDS( header_fields, header ) )
581 FT_TRACE3(( "Units per EM: %4u\n", header->Units_Per_EM ));
582 FT_TRACE3(( "IndexToLoc: %4d\n", header->Index_To_Loc_Format ));
589 FT_LOCAL_DEF( FT_Error )
590 tt_face_load_head( TT_Face face,
593 return tt_face_load_generic_header( face, stream, TTAG_head );
597 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
599 FT_LOCAL_DEF( FT_Error )
600 tt_face_load_bhed( TT_Face face,
603 return tt_face_load_generic_header( face, stream, TTAG_bhed );
606 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
609 /*************************************************************************/
612 /* tt_face_load_max_profile */
615 /* Loads the maximum profile into a face object. */
618 /* face :: A handle to the target face object. */
620 /* stream :: The input stream. */
623 /* FreeType error code. 0 means success. */
625 FT_LOCAL_DEF( FT_Error )
626 tt_face_load_maxp( TT_Face face,
630 TT_MaxProfile* maxProfile = &face->max_profile;
632 static const FT_Frame_Field maxp_fields[] =
635 #define FT_STRUCTURE TT_MaxProfile
638 FT_FRAME_LONG ( version ),
639 FT_FRAME_USHORT( numGlyphs ),
643 static const FT_Frame_Field maxp_fields_extra[] =
645 FT_FRAME_START( 26 ),
646 FT_FRAME_USHORT( maxPoints ),
647 FT_FRAME_USHORT( maxContours ),
648 FT_FRAME_USHORT( maxCompositePoints ),
649 FT_FRAME_USHORT( maxCompositeContours ),
650 FT_FRAME_USHORT( maxZones ),
651 FT_FRAME_USHORT( maxTwilightPoints ),
652 FT_FRAME_USHORT( maxStorage ),
653 FT_FRAME_USHORT( maxFunctionDefs ),
654 FT_FRAME_USHORT( maxInstructionDefs ),
655 FT_FRAME_USHORT( maxStackElements ),
656 FT_FRAME_USHORT( maxSizeOfInstructions ),
657 FT_FRAME_USHORT( maxComponentElements ),
658 FT_FRAME_USHORT( maxComponentDepth ),
663 error = face->goto_table( face, TTAG_maxp, stream, 0 );
667 if ( FT_STREAM_READ_FIELDS( maxp_fields, maxProfile ) )
670 maxProfile->maxPoints = 0;
671 maxProfile->maxContours = 0;
672 maxProfile->maxCompositePoints = 0;
673 maxProfile->maxCompositeContours = 0;
674 maxProfile->maxZones = 0;
675 maxProfile->maxTwilightPoints = 0;
676 maxProfile->maxStorage = 0;
677 maxProfile->maxFunctionDefs = 0;
678 maxProfile->maxInstructionDefs = 0;
679 maxProfile->maxStackElements = 0;
680 maxProfile->maxSizeOfInstructions = 0;
681 maxProfile->maxComponentElements = 0;
682 maxProfile->maxComponentDepth = 0;
684 if ( maxProfile->version >= 0x10000L )
686 if ( FT_STREAM_READ_FIELDS( maxp_fields_extra, maxProfile ) )
689 /* XXX: an adjustment that is necessary to load certain */
690 /* broken fonts like `Keystrokes MT' :-( */
692 /* We allocate 64 function entries by default when */
693 /* the maxFunctionDefs value is smaller. */
695 if ( maxProfile->maxFunctionDefs < 64 )
696 maxProfile->maxFunctionDefs = 64;
698 /* we add 4 phantom points later */
699 if ( maxProfile->maxTwilightPoints > ( 0xFFFFU - 4 ) )
701 FT_TRACE0(( "tt_face_load_maxp:"
702 " too much twilight points in `maxp' table;\n"
704 " some glyphs might be rendered incorrectly\n" ));
706 maxProfile->maxTwilightPoints = 0xFFFFU - 4;
709 /* we arbitrarily limit recursion to avoid stack exhaustion */
710 if ( maxProfile->maxComponentDepth > 100 )
712 FT_TRACE0(( "tt_face_load_maxp:"
713 " abnormally large component depth (%d) set to 100\n",
714 maxProfile->maxComponentDepth ));
715 maxProfile->maxComponentDepth = 100;
719 FT_TRACE3(( "numGlyphs: %u\n", maxProfile->numGlyphs ));
726 /*************************************************************************/
729 /* tt_face_load_name */
732 /* Loads the name records. */
735 /* face :: A handle to the target face object. */
737 /* stream :: The input stream. */
740 /* FreeType error code. 0 means success. */
742 FT_LOCAL_DEF( FT_Error )
743 tt_face_load_name( TT_Face face,
747 FT_Memory memory = stream->memory;
748 FT_ULong table_pos, table_len;
749 FT_ULong storage_start, storage_limit;
753 static const FT_Frame_Field name_table_fields[] =
756 #define FT_STRUCTURE TT_NameTableRec
759 FT_FRAME_USHORT( format ),
760 FT_FRAME_USHORT( numNameRecords ),
761 FT_FRAME_USHORT( storageOffset ),
765 static const FT_Frame_Field name_record_fields[] =
768 #define FT_STRUCTURE TT_NameEntryRec
770 /* no FT_FRAME_START */
771 FT_FRAME_USHORT( platformID ),
772 FT_FRAME_USHORT( encodingID ),
773 FT_FRAME_USHORT( languageID ),
774 FT_FRAME_USHORT( nameID ),
775 FT_FRAME_USHORT( stringLength ),
776 FT_FRAME_USHORT( stringOffset ),
781 table = &face->name_table;
782 table->stream = stream;
784 error = face->goto_table( face, TTAG_name, stream, &table_len );
788 table_pos = FT_STREAM_POS();
791 if ( FT_STREAM_READ_FIELDS( name_table_fields, table ) )
794 /* Some popular Asian fonts have an invalid `storageOffset' value */
795 /* (it should be at least "6 + 12*num_names"). However, the string */
796 /* offsets, computed as "storageOffset + entry->stringOffset", are */
797 /* valid pointers within the name table... */
799 /* We thus can't check `storageOffset' right now. */
801 storage_start = table_pos + 6 + 12*table->numNameRecords;
802 storage_limit = table_pos + table_len;
804 if ( storage_start > storage_limit )
806 FT_ERROR(( "tt_face_load_name: invalid `name' table\n" ));
807 error = FT_THROW( Name_Table_Missing );
811 /* Allocate the array of name records. */
812 count = table->numNameRecords;
813 table->numNameRecords = 0;
815 if ( FT_NEW_ARRAY( table->names, count ) ||
816 FT_FRAME_ENTER( count * 12 ) )
819 /* Load the name records and determine how much storage is needed */
820 /* to hold the strings themselves. */
822 TT_NameEntryRec* entry = table->names;
825 for ( ; count > 0; count-- )
827 if ( FT_STREAM_READ_FIELDS( name_record_fields, entry ) )
830 /* check that the name is not empty */
831 if ( entry->stringLength == 0 )
834 /* check that the name string is within the table */
835 entry->stringOffset += table_pos + table->storageOffset;
836 if ( entry->stringOffset < storage_start ||
837 entry->stringOffset + entry->stringLength > storage_limit )
839 /* invalid entry - ignore it */
840 entry->stringOffset = 0;
841 entry->stringLength = 0;
848 table->numNameRecords = (FT_UInt)( entry - table->names );
853 /* everything went well, update face->num_names */
854 face->num_names = (FT_UShort) table->numNameRecords;
861 /*************************************************************************/
864 /* tt_face_free_names */
867 /* Frees the name records. */
870 /* face :: A handle to the target face object. */
873 tt_face_free_name( TT_Face face )
875 FT_Memory memory = face->root.driver->root.memory;
876 TT_NameTable table = &face->name_table;
877 TT_NameEntry entry = table->names;
878 FT_UInt count = table->numNameRecords;
883 for ( ; count > 0; count--, entry++ )
885 FT_FREE( entry->string );
886 entry->stringLength = 0;
889 /* free strings table */
890 FT_FREE( table->names );
893 table->numNameRecords = 0;
895 table->storageOffset = 0;
899 /*************************************************************************/
902 /* tt_face_load_cmap */
905 /* Loads the cmap directory in a face object. The cmaps themselves */
906 /* are loaded on demand in the `ttcmap.c' module. */
909 /* face :: A handle to the target face object. */
911 /* stream :: A handle to the input stream. */
914 /* FreeType error code. 0 means success. */
917 FT_LOCAL_DEF( FT_Error )
918 tt_face_load_cmap( TT_Face face,
924 error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size );
928 if ( FT_FRAME_EXTRACT( face->cmap_size, face->cmap_table ) )
937 /*************************************************************************/
940 /* tt_face_load_os2 */
943 /* Loads the OS2 table. */
946 /* face :: A handle to the target face object. */
948 /* stream :: A handle to the input stream. */
951 /* FreeType error code. 0 means success. */
953 FT_LOCAL_DEF( FT_Error )
954 tt_face_load_os2( TT_Face face,
960 static const FT_Frame_Field os2_fields[] =
963 #define FT_STRUCTURE TT_OS2
965 FT_FRAME_START( 78 ),
966 FT_FRAME_USHORT( version ),
967 FT_FRAME_SHORT ( xAvgCharWidth ),
968 FT_FRAME_USHORT( usWeightClass ),
969 FT_FRAME_USHORT( usWidthClass ),
970 FT_FRAME_SHORT ( fsType ),
971 FT_FRAME_SHORT ( ySubscriptXSize ),
972 FT_FRAME_SHORT ( ySubscriptYSize ),
973 FT_FRAME_SHORT ( ySubscriptXOffset ),
974 FT_FRAME_SHORT ( ySubscriptYOffset ),
975 FT_FRAME_SHORT ( ySuperscriptXSize ),
976 FT_FRAME_SHORT ( ySuperscriptYSize ),
977 FT_FRAME_SHORT ( ySuperscriptXOffset ),
978 FT_FRAME_SHORT ( ySuperscriptYOffset ),
979 FT_FRAME_SHORT ( yStrikeoutSize ),
980 FT_FRAME_SHORT ( yStrikeoutPosition ),
981 FT_FRAME_SHORT ( sFamilyClass ),
982 FT_FRAME_BYTE ( panose[0] ),
983 FT_FRAME_BYTE ( panose[1] ),
984 FT_FRAME_BYTE ( panose[2] ),
985 FT_FRAME_BYTE ( panose[3] ),
986 FT_FRAME_BYTE ( panose[4] ),
987 FT_FRAME_BYTE ( panose[5] ),
988 FT_FRAME_BYTE ( panose[6] ),
989 FT_FRAME_BYTE ( panose[7] ),
990 FT_FRAME_BYTE ( panose[8] ),
991 FT_FRAME_BYTE ( panose[9] ),
992 FT_FRAME_ULONG ( ulUnicodeRange1 ),
993 FT_FRAME_ULONG ( ulUnicodeRange2 ),
994 FT_FRAME_ULONG ( ulUnicodeRange3 ),
995 FT_FRAME_ULONG ( ulUnicodeRange4 ),
996 FT_FRAME_BYTE ( achVendID[0] ),
997 FT_FRAME_BYTE ( achVendID[1] ),
998 FT_FRAME_BYTE ( achVendID[2] ),
999 FT_FRAME_BYTE ( achVendID[3] ),
1001 FT_FRAME_USHORT( fsSelection ),
1002 FT_FRAME_USHORT( usFirstCharIndex ),
1003 FT_FRAME_USHORT( usLastCharIndex ),
1004 FT_FRAME_SHORT ( sTypoAscender ),
1005 FT_FRAME_SHORT ( sTypoDescender ),
1006 FT_FRAME_SHORT ( sTypoLineGap ),
1007 FT_FRAME_USHORT( usWinAscent ),
1008 FT_FRAME_USHORT( usWinDescent ),
1012 /* `OS/2' version 1 and newer */
1013 static const FT_Frame_Field os2_fields_extra1[] =
1015 FT_FRAME_START( 8 ),
1016 FT_FRAME_ULONG( ulCodePageRange1 ),
1017 FT_FRAME_ULONG( ulCodePageRange2 ),
1021 /* `OS/2' version 2 and newer */
1022 static const FT_Frame_Field os2_fields_extra2[] =
1024 FT_FRAME_START( 10 ),
1025 FT_FRAME_SHORT ( sxHeight ),
1026 FT_FRAME_SHORT ( sCapHeight ),
1027 FT_FRAME_USHORT( usDefaultChar ),
1028 FT_FRAME_USHORT( usBreakChar ),
1029 FT_FRAME_USHORT( usMaxContext ),
1033 /* `OS/2' version 5 and newer */
1034 static const FT_Frame_Field os2_fields_extra5[] =
1036 FT_FRAME_START( 4 ),
1037 FT_FRAME_USHORT( usLowerOpticalPointSize ),
1038 FT_FRAME_USHORT( usUpperOpticalPointSize ),
1043 /* We now support old Mac fonts where the OS/2 table doesn't */
1044 /* exist. Simply put, we set the `version' field to 0xFFFF */
1045 /* and test this value each time we need to access the table. */
1046 error = face->goto_table( face, TTAG_OS2, stream, 0 );
1052 if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) )
1055 os2->ulCodePageRange1 = 0;
1056 os2->ulCodePageRange2 = 0;
1058 os2->sCapHeight = 0;
1059 os2->usDefaultChar = 0;
1060 os2->usBreakChar = 0;
1061 os2->usMaxContext = 0;
1062 os2->usLowerOpticalPointSize = 0;
1063 os2->usUpperOpticalPointSize = 0xFFFF;
1065 if ( os2->version >= 0x0001 )
1067 /* only version 1 tables */
1068 if ( FT_STREAM_READ_FIELDS( os2_fields_extra1, os2 ) )
1071 if ( os2->version >= 0x0002 )
1073 /* only version 2 tables */
1074 if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) )
1077 if ( os2->version >= 0x0005 )
1079 /* only version 5 tables */
1080 if ( FT_STREAM_READ_FIELDS( os2_fields_extra5, os2 ) )
1086 FT_TRACE3(( "sTypoAscender: %4d\n", os2->sTypoAscender ));
1087 FT_TRACE3(( "sTypoDescender: %4d\n", os2->sTypoDescender ));
1088 FT_TRACE3(( "usWinAscent: %4u\n", os2->usWinAscent ));
1089 FT_TRACE3(( "usWinDescent: %4u\n", os2->usWinDescent ));
1090 FT_TRACE3(( "fsSelection: 0x%2x\n", os2->fsSelection ));
1097 /*************************************************************************/
1100 /* tt_face_load_postscript */
1103 /* Loads the Postscript table. */
1106 /* face :: A handle to the target face object. */
1108 /* stream :: A handle to the input stream. */
1111 /* FreeType error code. 0 means success. */
1113 FT_LOCAL_DEF( FT_Error )
1114 tt_face_load_post( TT_Face face,
1118 TT_Postscript* post = &face->postscript;
1120 static const FT_Frame_Field post_fields[] =
1123 #define FT_STRUCTURE TT_Postscript
1125 FT_FRAME_START( 32 ),
1126 FT_FRAME_ULONG( FormatType ),
1127 FT_FRAME_ULONG( italicAngle ),
1128 FT_FRAME_SHORT( underlinePosition ),
1129 FT_FRAME_SHORT( underlineThickness ),
1130 FT_FRAME_ULONG( isFixedPitch ),
1131 FT_FRAME_ULONG( minMemType42 ),
1132 FT_FRAME_ULONG( maxMemType42 ),
1133 FT_FRAME_ULONG( minMemType1 ),
1134 FT_FRAME_ULONG( maxMemType1 ),
1139 error = face->goto_table( face, TTAG_post, stream, 0 );
1143 if ( FT_STREAM_READ_FIELDS( post_fields, post ) )
1146 /* we don't load the glyph names, we do that in another */
1147 /* module (ttpost). */
1149 FT_TRACE3(( "FormatType: 0x%x\n", post->FormatType ));
1150 FT_TRACE3(( "isFixedPitch: %s\n", post->isFixedPitch
1151 ? " yes" : " no" ));
1157 /*************************************************************************/
1160 /* tt_face_load_pclt */
1163 /* Loads the PCL 5 Table. */
1166 /* face :: A handle to the target face object. */
1168 /* stream :: A handle to the input stream. */
1171 /* FreeType error code. 0 means success. */
1173 FT_LOCAL_DEF( FT_Error )
1174 tt_face_load_pclt( TT_Face face,
1177 static const FT_Frame_Field pclt_fields[] =
1180 #define FT_STRUCTURE TT_PCLT
1182 FT_FRAME_START( 54 ),
1183 FT_FRAME_ULONG ( Version ),
1184 FT_FRAME_ULONG ( FontNumber ),
1185 FT_FRAME_USHORT( Pitch ),
1186 FT_FRAME_USHORT( xHeight ),
1187 FT_FRAME_USHORT( Style ),
1188 FT_FRAME_USHORT( TypeFamily ),
1189 FT_FRAME_USHORT( CapHeight ),
1190 FT_FRAME_USHORT( SymbolSet ),
1191 FT_FRAME_BYTES ( TypeFace, 16 ),
1192 FT_FRAME_BYTES ( CharacterComplement, 8 ),
1193 FT_FRAME_BYTES ( FileName, 6 ),
1194 FT_FRAME_CHAR ( StrokeWeight ),
1195 FT_FRAME_CHAR ( WidthType ),
1196 FT_FRAME_BYTE ( SerifStyle ),
1197 FT_FRAME_BYTE ( Reserved ),
1202 TT_PCLT* pclt = &face->pclt;
1205 /* optional table */
1206 error = face->goto_table( face, TTAG_PCLT, stream, 0 );
1210 if ( FT_STREAM_READ_FIELDS( pclt_fields, pclt ) )
1218 /*************************************************************************/
1221 /* tt_face_load_gasp */
1224 /* Loads the `gasp' table into a face object. */
1227 /* face :: A handle to the target face object. */
1229 /* stream :: The input stream. */
1232 /* FreeType error code. 0 means success. */
1234 FT_LOCAL_DEF( FT_Error )
1235 tt_face_load_gasp( TT_Face face,
1239 FT_Memory memory = stream->memory;
1241 FT_UInt j,num_ranges;
1242 TT_GaspRange gaspranges = NULL;
1245 /* the gasp table is optional */
1246 error = face->goto_table( face, TTAG_gasp, stream, 0 );
1250 if ( FT_FRAME_ENTER( 4L ) )
1253 face->gasp.version = FT_GET_USHORT();
1254 face->gasp.numRanges = FT_GET_USHORT();
1258 /* only support versions 0 and 1 of the table */
1259 if ( face->gasp.version >= 2 )
1261 face->gasp.numRanges = 0;
1262 error = FT_THROW( Invalid_Table );
1266 num_ranges = face->gasp.numRanges;
1267 FT_TRACE3(( "numRanges: %u\n", num_ranges ));
1269 if ( FT_QNEW_ARRAY( face->gasp.gaspRanges, num_ranges ) ||
1270 FT_FRAME_ENTER( num_ranges * 4L ) )
1273 gaspranges = face->gasp.gaspRanges;
1275 for ( j = 0; j < num_ranges; j++ )
1277 gaspranges[j].maxPPEM = FT_GET_USHORT();
1278 gaspranges[j].gaspFlag = FT_GET_USHORT();
1280 FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n",
1282 gaspranges[j].maxPPEM,
1283 gaspranges[j].gaspFlag ));