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, 2013 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 /***************************************************************************/
20 #include "../../include/ft2build.h"
21 #include "../../include/freetype/internal/ftdebug.h"
22 #include "../../include/freetype/internal/ftstream.h"
23 #include "../../include/freetype/tttags.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_get_nexttable(TT_Table first, TT_Table limit, TT_Table entry)
59 if (!entry) return NULL;
61 for (; first < limit; first++){
62 if (entry->Offset + entry->Length <= first->Offset){
63 if (!temp || first->Offset < temp->Offset){
71 FT_LOCAL_DEF( TT_Table )
72 tt_face_lookup_table( TT_Face face,
77 #ifdef FT_DEBUG_LEVEL_TRACE
78 FT_Bool zero_length = FALSE;
82 FT_TRACE4(( "tt_face_lookup_table: %08p, `%c%c%c%c' -- ",
84 (FT_Char)( tag >> 24 ),
85 (FT_Char)( tag >> 16 ),
86 (FT_Char)( tag >> 8 ),
89 entry = face->dir_tables;
90 limit = entry + face->num_tables;
92 for ( ; entry < limit; entry++ )
94 /* For compatibility with Windows, we consider */
95 /* zero-length tables the same as missing tables. */
96 if ( entry->Tag == tag )
98 if ( entry->Length != 0 )
100 if (tag == TTAG_loca){
101 TT_Table next = tt_face_get_nexttable(face->dir_tables, limit, entry);
102 if (next && entry->Offset + entry->Length < next->Offset)
103 entry->Length = next->Offset - entry->Offset;
105 FT_TRACE4(( "found table.\n" ));
108 #ifdef FT_DEBUG_LEVEL_TRACE
114 #ifdef FT_DEBUG_LEVEL_TRACE
116 FT_TRACE4(( "ignoring empty table\n" ));
118 FT_TRACE4(( "could not find table\n" ));
125 /*************************************************************************/
128 /* tt_face_goto_table */
131 /* Looks for a TrueType table by name, then seek a stream to it. */
134 /* face :: A face object handle. */
136 /* tag :: The searched tag. */
138 /* stream :: The stream to seek when the table is found. */
141 /* length :: The length of the table if found, undefined otherwise. */
144 /* FreeType error code. 0 means success. */
146 FT_LOCAL_DEF( FT_Error )
147 tt_face_goto_table( TT_Face face,
156 table = tt_face_lookup_table( face, tag );
160 *length = table->Length;
162 if ( FT_STREAM_SEEK( table->Offset ) )
166 error = FT_THROW( Table_Missing );
175 /* - check that `num_tables' is valid (and adjust it if necessary) */
177 /* - look for a `head' table, check its size, and parse it to check */
178 /* whether its `magic' field is correctly set */
180 /* - errors (except errors returned by stream handling) */
182 /* SFNT_Err_Unknown_File_Format: */
183 /* no table is defined in directory, it is not sfnt-wrapped */
185 /* SFNT_Err_Table_Missing: */
186 /* table directory is valid, but essential tables */
187 /* (head/bhed/SING) are missing */
190 check_table_dir( SFNT_Header sfnt,
194 FT_UShort nn, valid_entries = 0;
195 FT_UInt has_head = 0, has_sing = 0, has_meta = 0;
196 FT_ULong offset = sfnt->offset + 12;
198 static const FT_Frame_Field table_dir_entry_fields[] =
201 #define FT_STRUCTURE TT_TableRec
203 FT_FRAME_START( 16 ),
204 FT_FRAME_ULONG( Tag ),
205 FT_FRAME_ULONG( CheckSum ),
206 FT_FRAME_ULONG( Offset ),
207 FT_FRAME_ULONG( Length ),
212 if ( FT_STREAM_SEEK( offset ) )
215 for ( nn = 0; nn < sfnt->num_tables; nn++ )
220 if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields, &table ) )
223 FT_TRACE2(( "check_table_dir:"
224 " can read only %d table%s in font (instead of %d)\n",
225 nn, nn == 1 ? "" : "s", sfnt->num_tables ));
226 sfnt->num_tables = nn;
230 /* we ignore invalid tables */
231 if ( table.Offset + table.Length > stream->size )
233 //BUGID: 53876, the cmap table is invalid, the font file couldn't be used.
234 if (table.Tag == TTAG_cmap) break;
235 FT_TRACE2(( "check_table_dir: table entry %d invalid\n", nn ));
241 if ( table.Tag == TTAG_head || table.Tag == TTAG_bhed )
246 #ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
247 if ( table.Tag == TTAG_head )
252 * The table length should be 0x36, but certain font tools make it
253 * 0x38, so we will just check that it is greater.
255 * Note that according to the specification, the table must be
256 * padded to 32-bit lengths, but this doesn't apply to the value of
257 * its `Length' field!
260 if ( table.Length < 0x36 )
262 FT_TRACE2(( "check_table_dir: `head' table too small\n" ));
263 error = FT_THROW( Table_Missing );
267 if ( FT_STREAM_SEEK( table.Offset + 12 ) ||
268 FT_READ_ULONG( magic ) )
271 if ( magic != 0x5F0F3CF5UL )
273 FT_TRACE2(( "check_table_dir:"
274 " no magic number found in `head' table\n"));
275 error = FT_THROW( Table_Missing );
279 if ( FT_STREAM_SEEK( offset + ( nn + 1 ) * 16 ) )
282 else if ( table.Tag == TTAG_SING )
284 else if ( table.Tag == TTAG_META )
288 sfnt->num_tables = valid_entries;
290 if ( sfnt->num_tables == 0 )
292 FT_TRACE2(( "check_table_dir: no tables found\n" ));
293 error = FT_THROW( Unknown_File_Format );
297 /* if `sing' and `meta' tables are present, there is no `head' table */
298 if ( has_head || ( has_sing && has_meta ) )
305 FT_TRACE2(( "check_table_dir:" ));
306 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
307 FT_TRACE2(( " neither `head', `bhed', nor `sing' table found\n" ));
309 FT_TRACE2(( " neither `head' nor `sing' table found\n" ));
311 error = FT_THROW( Table_Missing );
319 /*************************************************************************/
322 /* tt_face_load_font_dir */
325 /* Loads the header of a SFNT font file. */
328 /* face :: A handle to the target face object. */
330 /* stream :: The input stream. */
333 /* sfnt :: The SFNT header. */
336 /* FreeType error code. 0 means success. */
339 /* The stream cursor must be at the beginning of the font directory. */
341 FT_LOCAL_DEF( FT_Error )
342 tt_face_load_font_dir( TT_Face face,
347 FT_Memory memory = stream->memory;
351 static const FT_Frame_Field offset_table_fields[] =
354 #define FT_STRUCTURE SFNT_HeaderRec
357 FT_FRAME_USHORT( num_tables ),
358 FT_FRAME_USHORT( search_range ),
359 FT_FRAME_USHORT( entry_selector ),
360 FT_FRAME_USHORT( range_shift ),
365 FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face ));
367 /* read the offset table */
369 sfnt.offset = FT_STREAM_POS();
371 if ( FT_READ_ULONG( sfnt.format_tag ) ||
372 FT_STREAM_READ_FIELDS( offset_table_fields, &sfnt ) )
375 /* many fonts don't have these fields set correctly */
377 if ( sfnt.search_range != 1 << ( sfnt.entry_selector + 4 ) ||
378 sfnt.search_range + sfnt.range_shift != sfnt.num_tables << 4 )
379 return FT_THROW( Unknown_File_Format );
382 /* load the table directory */
384 FT_TRACE2(( "-- Number of tables: %10u\n", sfnt.num_tables ));
385 FT_TRACE2(( "-- Format version: 0x%08lx\n", sfnt.format_tag ));
387 if ( sfnt.format_tag != TTAG_OTTO )
390 error = check_table_dir( &sfnt, stream );
393 FT_TRACE2(( "tt_face_load_font_dir:"
394 " invalid table directory for TrueType\n" ));
400 face->num_tables = sfnt.num_tables;
401 face->format_tag = sfnt.format_tag;
403 if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) )
406 if ( FT_STREAM_SEEK( sfnt.offset + 12 ) ||
407 FT_FRAME_ENTER( face->num_tables * 16L ) )
410 entry = face->dir_tables;
413 " tag offset length checksum\n"
414 " ----------------------------------\n" ));
416 for ( nn = 0; nn < sfnt.num_tables; nn++ )
418 entry->Tag = FT_GET_TAG4();
419 entry->CheckSum = FT_GET_ULONG();
420 entry->Offset = FT_GET_LONG();
421 entry->Length = FT_GET_LONG();
423 /* ignore invalid tables */
424 if ( entry->Offset + entry->Length > stream->size )
428 FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx\n",
429 (FT_Char)( entry->Tag >> 24 ),
430 (FT_Char)( entry->Tag >> 16 ),
431 (FT_Char)( entry->Tag >> 8 ),
432 (FT_Char)( entry->Tag ),
442 FT_TRACE2(( "table directory loaded\n\n" ));
449 /*************************************************************************/
452 /* tt_face_load_any */
455 /* Loads any font table into client memory. */
458 /* face :: The face object to look for. */
460 /* tag :: The tag of table to load. Use the value 0 if you want */
461 /* to access the whole font file, else set this parameter */
462 /* to a valid TrueType table tag that you can forge with */
463 /* the MAKE_TT_TAG macro. */
465 /* offset :: The starting offset in the table (or the file if */
468 /* length :: The address of the decision variable: */
470 /* If length == NULL: */
471 /* Loads the whole table. Returns an error if */
474 /* If *length == 0: */
475 /* Exits immediately; returning the length of the given */
476 /* table or of the font file, depending on the value of */
479 /* If *length != 0: */
480 /* Loads the next `length' bytes of table or font, */
481 /* starting at offset `offset' (in table or font too). */
484 /* buffer :: The address of target buffer. */
487 /* FreeType error code. 0 means success. */
489 FT_LOCAL_DEF( FT_Error )
490 tt_face_load_any( TT_Face face,
504 /* look for tag in font directory */
505 table = tt_face_lookup_table( face, tag );
508 error = FT_THROW( Table_Missing );
512 offset += table->Offset;
513 size = table->Length;
516 /* tag == 0 -- the user wants to access the font file directly */
517 size = face->root.stream->size;
519 if ( length && *length == 0 )
529 stream = face->root.stream;
530 /* the `if' is syntactic sugar for picky compilers */
531 if ( FT_STREAM_READ_AT( offset, buffer, size ) )
539 /*************************************************************************/
542 /* tt_face_load_generic_header */
545 /* Loads the TrueType table `head' or `bhed'. */
548 /* face :: A handle to the target face object. */
550 /* stream :: The input stream. */
553 /* FreeType error code. 0 means success. */
556 tt_face_load_generic_header( TT_Face face,
563 static const FT_Frame_Field header_fields[] =
566 #define FT_STRUCTURE TT_Header
568 FT_FRAME_START( 54 ),
569 FT_FRAME_ULONG ( Table_Version ),
570 FT_FRAME_ULONG ( Font_Revision ),
571 FT_FRAME_LONG ( CheckSum_Adjust ),
572 FT_FRAME_LONG ( Magic_Number ),
573 FT_FRAME_USHORT( Flags ),
574 FT_FRAME_USHORT( Units_Per_EM ),
575 FT_FRAME_LONG ( Created[0] ),
576 FT_FRAME_LONG ( Created[1] ),
577 FT_FRAME_LONG ( Modified[0] ),
578 FT_FRAME_LONG ( Modified[1] ),
579 FT_FRAME_SHORT ( xMin ),
580 FT_FRAME_SHORT ( yMin ),
581 FT_FRAME_SHORT ( xMax ),
582 FT_FRAME_SHORT ( yMax ),
583 FT_FRAME_USHORT( Mac_Style ),
584 FT_FRAME_USHORT( Lowest_Rec_PPEM ),
585 FT_FRAME_SHORT ( Font_Direction ),
586 FT_FRAME_SHORT ( Index_To_Loc_Format ),
587 FT_FRAME_SHORT ( Glyph_Data_Format ),
592 error = face->goto_table( face, tag, stream, 0 );
596 header = &face->header;
598 if ( FT_STREAM_READ_FIELDS( header_fields, header ) )
601 FT_TRACE3(( "Units per EM: %4u\n", header->Units_Per_EM ));
602 FT_TRACE3(( "IndexToLoc: %4d\n", header->Index_To_Loc_Format ));
609 FT_LOCAL_DEF( FT_Error )
610 tt_face_load_head( TT_Face face,
613 return tt_face_load_generic_header( face, stream, TTAG_head );
617 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
619 FT_LOCAL_DEF( FT_Error )
620 tt_face_load_bhed( TT_Face face,
623 return tt_face_load_generic_header( face, stream, TTAG_bhed );
626 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
629 /*************************************************************************/
632 /* tt_face_load_max_profile */
635 /* Loads the maximum profile into a face object. */
638 /* face :: A handle to the target face object. */
640 /* stream :: The input stream. */
643 /* FreeType error code. 0 means success. */
645 FT_LOCAL_DEF( FT_Error )
646 tt_face_load_maxp( TT_Face face,
650 TT_MaxProfile* maxProfile = &face->max_profile;
652 static const FT_Frame_Field maxp_fields[] =
655 #define FT_STRUCTURE TT_MaxProfile
658 FT_FRAME_LONG ( version ),
659 FT_FRAME_USHORT( numGlyphs ),
663 static const FT_Frame_Field maxp_fields_extra[] =
665 FT_FRAME_START( 26 ),
666 FT_FRAME_USHORT( maxPoints ),
667 FT_FRAME_USHORT( maxContours ),
668 FT_FRAME_USHORT( maxCompositePoints ),
669 FT_FRAME_USHORT( maxCompositeContours ),
670 FT_FRAME_USHORT( maxZones ),
671 FT_FRAME_USHORT( maxTwilightPoints ),
672 FT_FRAME_USHORT( maxStorage ),
673 FT_FRAME_USHORT( maxFunctionDefs ),
674 FT_FRAME_USHORT( maxInstructionDefs ),
675 FT_FRAME_USHORT( maxStackElements ),
676 FT_FRAME_USHORT( maxSizeOfInstructions ),
677 FT_FRAME_USHORT( maxComponentElements ),
678 FT_FRAME_USHORT( maxComponentDepth ),
683 error = face->goto_table( face, TTAG_maxp, stream, 0 );
687 if ( FT_STREAM_READ_FIELDS( maxp_fields, maxProfile ) )
690 maxProfile->maxPoints = 0;
691 maxProfile->maxContours = 0;
692 maxProfile->maxCompositePoints = 0;
693 maxProfile->maxCompositeContours = 0;
694 maxProfile->maxZones = 0;
695 maxProfile->maxTwilightPoints = 0;
696 maxProfile->maxStorage = 0;
697 maxProfile->maxFunctionDefs = 0;
698 maxProfile->maxInstructionDefs = 0;
699 maxProfile->maxStackElements = 0;
700 maxProfile->maxSizeOfInstructions = 0;
701 maxProfile->maxComponentElements = 0;
702 maxProfile->maxComponentDepth = 0;
704 if ( maxProfile->version >= 0x10000L )
706 if ( FT_STREAM_READ_FIELDS( maxp_fields_extra, maxProfile ) )
709 /* XXX: an adjustment that is necessary to load certain */
710 /* broken fonts like `Keystrokes MT' :-( */
712 /* We allocate 64 function entries by default when */
713 /* the maxFunctionDefs value is smaller. */
715 if ( maxProfile->maxFunctionDefs < 64 )
716 maxProfile->maxFunctionDefs = 64;
718 /* we add 4 phantom points later */
719 if ( maxProfile->maxTwilightPoints > ( 0xFFFFU - 4 ) )
721 FT_TRACE0(( "tt_face_load_maxp:"
722 " too much twilight points in `maxp' table;\n"
724 " some glyphs might be rendered incorrectly\n" ));
726 maxProfile->maxTwilightPoints = 0xFFFFU - 4;
729 /* we arbitrarily limit recursion to avoid stack exhaustion */
730 if ( maxProfile->maxComponentDepth > 100 )
732 FT_TRACE0(( "tt_face_load_maxp:"
733 " abnormally large component depth (%d) set to 100\n",
734 maxProfile->maxComponentDepth ));
735 maxProfile->maxComponentDepth = 100;
739 FT_TRACE3(( "numGlyphs: %u\n", maxProfile->numGlyphs ));
746 /*************************************************************************/
749 /* tt_face_load_name */
752 /* Loads the name records. */
755 /* face :: A handle to the target face object. */
757 /* stream :: The input stream. */
760 /* FreeType error code. 0 means success. */
762 FT_LOCAL_DEF( FT_Error )
763 tt_face_load_name( TT_Face face,
767 FT_Memory memory = stream->memory;
768 FT_ULong table_pos, table_len;
769 FT_ULong storage_start, storage_limit;
773 static const FT_Frame_Field name_table_fields[] =
776 #define FT_STRUCTURE TT_NameTableRec
779 FT_FRAME_USHORT( format ),
780 FT_FRAME_USHORT( numNameRecords ),
781 FT_FRAME_USHORT( storageOffset ),
785 static const FT_Frame_Field name_record_fields[] =
788 #define FT_STRUCTURE TT_NameEntryRec
790 /* no FT_FRAME_START */
791 FT_FRAME_USHORT( platformID ),
792 FT_FRAME_USHORT( encodingID ),
793 FT_FRAME_USHORT( languageID ),
794 FT_FRAME_USHORT( nameID ),
795 FT_FRAME_USHORT( stringLength ),
796 FT_FRAME_USHORT( stringOffset ),
801 table = &face->name_table;
802 table->stream = stream;
804 error = face->goto_table( face, TTAG_name, stream, &table_len );
808 table_pos = FT_STREAM_POS();
811 if ( FT_STREAM_READ_FIELDS( name_table_fields, table ) )
814 /* Some popular Asian fonts have an invalid `storageOffset' value */
815 /* (it should be at least "6 + 12*num_names"). However, the string */
816 /* offsets, computed as "storageOffset + entry->stringOffset", are */
817 /* valid pointers within the name table... */
819 /* We thus can't check `storageOffset' right now. */
821 storage_start = table_pos + 6 + 12*table->numNameRecords;
822 storage_limit = table_pos + table_len;
824 if ( storage_start > storage_limit )
826 FT_ERROR(( "tt_face_load_name: invalid `name' table\n" ));
827 error = FT_THROW( Name_Table_Missing );
831 /* Allocate the array of name records. */
832 count = table->numNameRecords;
833 table->numNameRecords = 0;
835 if ( FT_NEW_ARRAY( table->names, count ) ||
836 FT_FRAME_ENTER( count * 12 ) )
839 /* Load the name records and determine how much storage is needed */
840 /* to hold the strings themselves. */
842 TT_NameEntryRec* entry = table->names;
845 for ( ; count > 0; count-- )
847 if ( FT_STREAM_READ_FIELDS( name_record_fields, entry ) )
850 /* check that the name is not empty */
851 if ( entry->stringLength == 0 )
854 /* check that the name string is within the table */
855 entry->stringOffset += table_pos + table->storageOffset;
856 if ( entry->stringOffset < storage_start ||
857 entry->stringOffset + entry->stringLength > storage_limit )
859 /* invalid entry - ignore it */
860 entry->stringOffset = 0;
861 entry->stringLength = 0;
868 table->numNameRecords = (FT_UInt)( entry - table->names );
873 /* everything went well, update face->num_names */
874 face->num_names = (FT_UShort) table->numNameRecords;
881 /*************************************************************************/
884 /* tt_face_free_names */
887 /* Frees the name records. */
890 /* face :: A handle to the target face object. */
893 tt_face_free_name( TT_Face face )
895 FT_Memory memory = face->root.driver->root.memory;
896 TT_NameTable table = &face->name_table;
897 TT_NameEntry entry = table->names;
898 FT_UInt count = table->numNameRecords;
903 for ( ; count > 0; count--, entry++ )
905 FT_FREE( entry->string );
906 entry->stringLength = 0;
909 /* free strings table */
910 FT_FREE( table->names );
913 table->numNameRecords = 0;
915 table->storageOffset = 0;
919 /*************************************************************************/
922 /* tt_face_load_cmap */
925 /* Loads the cmap directory in a face object. The cmaps themselves */
926 /* are loaded on demand in the `ttcmap.c' module. */
929 /* face :: A handle to the target face object. */
931 /* stream :: A handle to the input stream. */
934 /* FreeType error code. 0 means success. */
937 FT_LOCAL_DEF( FT_Error )
938 tt_face_load_cmap( TT_Face face,
944 error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size );
948 if ( FT_FRAME_EXTRACT( face->cmap_size, face->cmap_table ) )
957 /*************************************************************************/
960 /* tt_face_load_os2 */
963 /* Loads the OS2 table. */
966 /* face :: A handle to the target face object. */
968 /* stream :: A handle to the input stream. */
971 /* FreeType error code. 0 means success. */
973 FT_LOCAL_DEF( FT_Error )
974 tt_face_load_os2( TT_Face face,
980 static const FT_Frame_Field os2_fields[] =
983 #define FT_STRUCTURE TT_OS2
985 FT_FRAME_START( 78 ),
986 FT_FRAME_USHORT( version ),
987 FT_FRAME_SHORT ( xAvgCharWidth ),
988 FT_FRAME_USHORT( usWeightClass ),
989 FT_FRAME_USHORT( usWidthClass ),
990 FT_FRAME_SHORT ( fsType ),
991 FT_FRAME_SHORT ( ySubscriptXSize ),
992 FT_FRAME_SHORT ( ySubscriptYSize ),
993 FT_FRAME_SHORT ( ySubscriptXOffset ),
994 FT_FRAME_SHORT ( ySubscriptYOffset ),
995 FT_FRAME_SHORT ( ySuperscriptXSize ),
996 FT_FRAME_SHORT ( ySuperscriptYSize ),
997 FT_FRAME_SHORT ( ySuperscriptXOffset ),
998 FT_FRAME_SHORT ( ySuperscriptYOffset ),
999 FT_FRAME_SHORT ( yStrikeoutSize ),
1000 FT_FRAME_SHORT ( yStrikeoutPosition ),
1001 FT_FRAME_SHORT ( sFamilyClass ),
1002 FT_FRAME_BYTE ( panose[0] ),
1003 FT_FRAME_BYTE ( panose[1] ),
1004 FT_FRAME_BYTE ( panose[2] ),
1005 FT_FRAME_BYTE ( panose[3] ),
1006 FT_FRAME_BYTE ( panose[4] ),
1007 FT_FRAME_BYTE ( panose[5] ),
1008 FT_FRAME_BYTE ( panose[6] ),
1009 FT_FRAME_BYTE ( panose[7] ),
1010 FT_FRAME_BYTE ( panose[8] ),
1011 FT_FRAME_BYTE ( panose[9] ),
1012 FT_FRAME_ULONG ( ulUnicodeRange1 ),
1013 FT_FRAME_ULONG ( ulUnicodeRange2 ),
1014 FT_FRAME_ULONG ( ulUnicodeRange3 ),
1015 FT_FRAME_ULONG ( ulUnicodeRange4 ),
1016 FT_FRAME_BYTE ( achVendID[0] ),
1017 FT_FRAME_BYTE ( achVendID[1] ),
1018 FT_FRAME_BYTE ( achVendID[2] ),
1019 FT_FRAME_BYTE ( achVendID[3] ),
1021 FT_FRAME_USHORT( fsSelection ),
1022 FT_FRAME_USHORT( usFirstCharIndex ),
1023 FT_FRAME_USHORT( usLastCharIndex ),
1024 FT_FRAME_SHORT ( sTypoAscender ),
1025 FT_FRAME_SHORT ( sTypoDescender ),
1026 FT_FRAME_SHORT ( sTypoLineGap ),
1027 FT_FRAME_USHORT( usWinAscent ),
1028 FT_FRAME_USHORT( usWinDescent ),
1032 static const FT_Frame_Field os2_fields_extra[] =
1034 FT_FRAME_START( 8 ),
1035 FT_FRAME_ULONG( ulCodePageRange1 ),
1036 FT_FRAME_ULONG( ulCodePageRange2 ),
1040 static const FT_Frame_Field os2_fields_extra2[] =
1042 FT_FRAME_START( 10 ),
1043 FT_FRAME_SHORT ( sxHeight ),
1044 FT_FRAME_SHORT ( sCapHeight ),
1045 FT_FRAME_USHORT( usDefaultChar ),
1046 FT_FRAME_USHORT( usBreakChar ),
1047 FT_FRAME_USHORT( usMaxContext ),
1052 /* We now support old Mac fonts where the OS/2 table doesn't */
1053 /* exist. Simply put, we set the `version' field to 0xFFFF */
1054 /* and test this value each time we need to access the table. */
1055 error = face->goto_table( face, TTAG_OS2, stream, 0 );
1061 if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) )
1064 os2->ulCodePageRange1 = 0;
1065 os2->ulCodePageRange2 = 0;
1067 os2->sCapHeight = 0;
1068 os2->usDefaultChar = 0;
1069 os2->usBreakChar = 0;
1070 os2->usMaxContext = 0;
1072 if ( os2->version >= 0x0001 )
1074 /* only version 1 tables */
1075 if ( FT_STREAM_READ_FIELDS( os2_fields_extra, os2 ) )
1078 if ( os2->version >= 0x0002 )
1080 /* only version 2 tables */
1081 if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, 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 ));
1094 return 0; /* XYQ 2007-11-23 We can't just quit if OS/2 table can't be loaded.
1095 TESTDOC: Bug #3160 - MyDoc.pdf */
1100 /*************************************************************************/
1103 /* tt_face_load_postscript */
1106 /* Loads the Postscript table. */
1109 /* face :: A handle to the target face object. */
1111 /* stream :: A handle to the input stream. */
1114 /* FreeType error code. 0 means success. */
1116 FT_LOCAL_DEF( FT_Error )
1117 tt_face_load_post( TT_Face face,
1121 TT_Postscript* post = &face->postscript;
1123 static const FT_Frame_Field post_fields[] =
1126 #define FT_STRUCTURE TT_Postscript
1128 FT_FRAME_START( 32 ),
1129 FT_FRAME_ULONG( FormatType ),
1130 FT_FRAME_ULONG( italicAngle ),
1131 FT_FRAME_SHORT( underlinePosition ),
1132 FT_FRAME_SHORT( underlineThickness ),
1133 FT_FRAME_ULONG( isFixedPitch ),
1134 FT_FRAME_ULONG( minMemType42 ),
1135 FT_FRAME_ULONG( maxMemType42 ),
1136 FT_FRAME_ULONG( minMemType1 ),
1137 FT_FRAME_ULONG( maxMemType1 ),
1142 error = face->goto_table( face, TTAG_post, stream, 0 );
1146 if ( FT_STREAM_READ_FIELDS( post_fields, post ) )
1149 /* we don't load the glyph names, we do that in another */
1150 /* module (ttpost). */
1152 FT_TRACE3(( "FormatType: 0x%x\n", post->FormatType ));
1153 FT_TRACE3(( "isFixedPitch: %s\n", post->isFixedPitch
1154 ? " yes" : " no" ));
1160 /*************************************************************************/
1163 /* tt_face_load_pclt */
1166 /* Loads the PCL 5 Table. */
1169 /* face :: A handle to the target face object. */
1171 /* stream :: A handle to the input stream. */
1174 /* FreeType error code. 0 means success. */
1176 FT_LOCAL_DEF( FT_Error )
1177 tt_face_load_pclt( TT_Face face,
1180 static const FT_Frame_Field pclt_fields[] =
1183 #define FT_STRUCTURE TT_PCLT
1185 FT_FRAME_START( 54 ),
1186 FT_FRAME_ULONG ( Version ),
1187 FT_FRAME_ULONG ( FontNumber ),
1188 FT_FRAME_USHORT( Pitch ),
1189 FT_FRAME_USHORT( xHeight ),
1190 FT_FRAME_USHORT( Style ),
1191 FT_FRAME_USHORT( TypeFamily ),
1192 FT_FRAME_USHORT( CapHeight ),
1193 FT_FRAME_BYTES ( TypeFace, 16 ),
1194 FT_FRAME_BYTES ( CharacterComplement, 8 ),
1195 FT_FRAME_BYTES ( FileName, 6 ),
1196 FT_FRAME_CHAR ( StrokeWeight ),
1197 FT_FRAME_CHAR ( WidthType ),
1198 FT_FRAME_BYTE ( SerifStyle ),
1199 FT_FRAME_BYTE ( Reserved ),
1204 TT_PCLT* pclt = &face->pclt;
1207 /* optional table */
1208 error = face->goto_table( face, TTAG_PCLT, stream, 0 );
1212 if ( FT_STREAM_READ_FIELDS( pclt_fields, pclt ) )
1220 /*************************************************************************/
1223 /* tt_face_load_gasp */
1226 /* Loads the `gasp' table into a face object. */
1229 /* face :: A handle to the target face object. */
1231 /* stream :: The input stream. */
1234 /* FreeType error code. 0 means success. */
1236 FT_LOCAL_DEF( FT_Error )
1237 tt_face_load_gasp( TT_Face face,
1241 FT_Memory memory = stream->memory;
1243 FT_UInt j,num_ranges;
1244 TT_GaspRange gaspranges = NULL;
1247 /* the gasp table is optional */
1248 error = face->goto_table( face, TTAG_gasp, stream, 0 );
1252 if ( FT_FRAME_ENTER( 4L ) )
1255 face->gasp.version = FT_GET_USHORT();
1256 face->gasp.numRanges = FT_GET_USHORT();
1260 /* only support versions 0 and 1 of the table */
1261 if ( face->gasp.version >= 2 )
1263 face->gasp.numRanges = 0;
1264 error = FT_THROW( Invalid_Table );
1268 num_ranges = face->gasp.numRanges;
1269 FT_TRACE3(( "numRanges: %u\n", num_ranges ));
1271 if ( FT_QNEW_ARRAY( face->gasp.gaspRanges, num_ranges ) ||
1272 FT_FRAME_ENTER( num_ranges * 4L ) )
1275 gaspranges = face->gasp.gaspRanges;
1277 for ( j = 0; j < num_ranges; j++ )
1279 gaspranges[j].maxPPEM = FT_GET_USHORT();
1280 gaspranges[j].gaspFlag = FT_GET_USHORT();
1282 FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n",
1284 gaspranges[j].maxPPEM,
1285 gaspranges[j].gaspFlag ));