1 /***************************************************************************/
5 /* Load the basic TrueType tables, i.e., tables that can be either in */
6 /* TTF or OTF fonts (body). */
8 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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
) {
81 if ( entry
->Length
!= 0 )
83 FT_TRACE4(( "found table.\n" ));
86 #ifdef FT_DEBUG_LEVEL_TRACE
92 #ifdef FT_DEBUG_LEVEL_TRACE
94 FT_TRACE4(( "ignoring empty table\n" ));
96 FT_TRACE4(( "could not find table\n" ));
103 /*************************************************************************/
106 /* tt_face_goto_table */
109 /* Looks for a TrueType table by name, then seek a stream to it. */
112 /* face :: A face object handle. */
114 /* tag :: The searched tag. */
116 /* stream :: The stream to seek when the table is found. */
119 /* length :: The length of the table if found, undefined otherwise. */
122 /* FreeType error code. 0 means success. */
124 FT_LOCAL_DEF( FT_Error
)
125 tt_face_goto_table( TT_Face face
,
134 table
= tt_face_lookup_table( face
, tag
);
138 *length
= table
->Length
;
140 if ( FT_STREAM_SEEK( table
->Offset
) )
144 error
= SFNT_Err_Table_Missing
;
153 /* - check that `num_tables' is valid (and adjust it if necessary) */
155 /* - look for a `head' table, check its size, and parse it to check */
156 /* whether its `magic' field is correctly set */
158 /* - errors (except errors returned by stream handling) */
160 /* SFNT_Err_Unknown_File_Format: */
161 /* no table is defined in directory, it is not sfnt-wrapped */
163 /* SFNT_Err_Table_Missing: */
164 /* table directory is valid, but essential tables */
165 /* (head/bhed/SING) are missing */
168 check_table_dir( SFNT_Header sfnt
,
172 FT_UShort nn
, valid_entries
= 0;
173 FT_UInt has_head
= 0, has_sing
= 0, has_meta
= 0;
174 FT_ULong offset
= sfnt
->offset
+ 12;
176 static const FT_Frame_Field table_dir_entry_fields
[] =
179 #define FT_STRUCTURE TT_TableRec
181 FT_FRAME_START( 16 ),
182 FT_FRAME_ULONG( Tag
),
183 FT_FRAME_ULONG( CheckSum
),
184 FT_FRAME_ULONG( Offset
),
185 FT_FRAME_ULONG( Length
),
190 if ( FT_STREAM_SEEK( offset
) )
193 for ( nn
= 0; nn
< sfnt
->num_tables
; nn
++ )
198 if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields
, &table
) )
201 FT_TRACE2(( "check_table_dir:"
202 " can read only %d table%s in font (instead of %d)\n",
203 nn
, nn
== 1 ? "" : "s", sfnt
->num_tables
));
204 sfnt
->num_tables
= nn
;
208 /* we ignore invalid tables */
209 if ( table
.Offset
+ table
.Length
> stream
->size
)
211 FT_TRACE2(( "check_table_dir: table entry %d invalid\n", nn
));
217 if ( table
.Tag
== TTAG_head
|| table
.Tag
== TTAG_bhed
)
222 #ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
223 if ( table
.Tag
== TTAG_head
)
228 * The table length should be 0x36, but certain font tools make it
229 * 0x38, so we will just check that it is greater.
231 * Note that according to the specification, the table must be
232 * padded to 32-bit lengths, but this doesn't apply to the value of
233 * its `Length' field!
236 if ( table
.Length
< 0x36 )
238 FT_TRACE2(( "check_table_dir: `head' table too small\n" ));
239 error
= SFNT_Err_Table_Missing
;
243 if ( FT_STREAM_SEEK( table
.Offset
+ 12 ) ||
244 FT_READ_ULONG( magic
) )
247 if ( magic
!= 0x5F0F3CF5UL
)
249 FT_TRACE2(( "check_table_dir:"
250 " no magic number found in `head' table\n"));
251 error
= SFNT_Err_Table_Missing
;
255 if ( FT_STREAM_SEEK( offset
+ ( nn
+ 1 ) * 16 ) )
258 else if ( table
.Tag
== TTAG_SING
)
260 else if ( table
.Tag
== TTAG_META
)
264 sfnt
->num_tables
= valid_entries
;
266 if ( sfnt
->num_tables
== 0 )
268 FT_TRACE2(( "check_table_dir: no tables found\n" ));
269 error
= SFNT_Err_Unknown_File_Format
;
273 /* if `sing' and `meta' tables are present, there is no `head' table */
274 if ( has_head
|| ( has_sing
&& has_meta
) )
281 FT_TRACE2(( "check_table_dir:" ));
282 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
283 FT_TRACE2(( " neither `head', `bhed', nor `sing' table found\n" ));
285 FT_TRACE2(( " neither `head' nor `sing' table found\n" ));
287 error
= SFNT_Err_Table_Missing
;
295 /*************************************************************************/
298 /* tt_face_load_font_dir */
301 /* Loads the header of a SFNT font file. */
304 /* face :: A handle to the target face object. */
306 /* stream :: The input stream. */
309 /* sfnt :: The SFNT header. */
312 /* FreeType error code. 0 means success. */
315 /* The stream cursor must be at the beginning of the font directory. */
317 FT_LOCAL_DEF( FT_Error
)
318 tt_face_load_font_dir( TT_Face face
,
323 FT_Memory memory
= stream
->memory
;
327 static const FT_Frame_Field offset_table_fields
[] =
330 #define FT_STRUCTURE SFNT_HeaderRec
333 FT_FRAME_USHORT( num_tables
),
334 FT_FRAME_USHORT( search_range
),
335 FT_FRAME_USHORT( entry_selector
),
336 FT_FRAME_USHORT( range_shift
),
341 FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face
));
343 /* read the offset table */
345 sfnt
.offset
= FT_STREAM_POS();
347 if ( FT_READ_ULONG( sfnt
.format_tag
) ||
348 FT_STREAM_READ_FIELDS( offset_table_fields
, &sfnt
) )
351 /* many fonts don't have these fields set correctly */
353 if ( sfnt
.search_range
!= 1 << ( sfnt
.entry_selector
+ 4 ) ||
354 sfnt
.search_range
+ sfnt
.range_shift
!= sfnt
.num_tables
<< 4 )
355 return SFNT_Err_Unknown_File_Format
;
358 /* load the table directory */
360 FT_TRACE2(( "-- Number of tables: %10u\n", sfnt
.num_tables
));
361 FT_TRACE2(( "-- Format version: 0x%08lx\n", sfnt
.format_tag
));
364 error
= check_table_dir( &sfnt
, stream
);
367 FT_TRACE2(( "tt_face_load_font_dir:"
368 " invalid table directory for TrueType\n" ));
373 face
->num_tables
= sfnt
.num_tables
;
374 face
->format_tag
= sfnt
.format_tag
;
376 if ( FT_QNEW_ARRAY( face
->dir_tables
, face
->num_tables
) )
379 if ( FT_STREAM_SEEK( sfnt
.offset
+ 12 ) ||
380 FT_FRAME_ENTER( face
->num_tables
* 16L ) )
383 entry
= face
->dir_tables
;
385 for ( nn
= 0; nn
< sfnt
.num_tables
; nn
++ )
387 entry
->Tag
= FT_GET_TAG4();
388 entry
->CheckSum
= FT_GET_ULONG();
389 entry
->Offset
= FT_GET_LONG();
390 entry
->Length
= FT_GET_LONG();
392 /* ignore invalid tables */
393 if ( entry
->Offset
+ entry
->Length
> stream
->size
)
397 FT_TRACE2(( " %c%c%c%c - %08lx - %08lx\n",
398 (FT_Char
)( entry
->Tag
>> 24 ),
399 (FT_Char
)( entry
->Tag
>> 16 ),
400 (FT_Char
)( entry
->Tag
>> 8 ),
401 (FT_Char
)( entry
->Tag
),
410 FT_TRACE2(( "table directory loaded\n\n" ));
417 /*************************************************************************/
420 /* tt_face_load_any */
423 /* Loads any font table into client memory. */
426 /* face :: The face object to look for. */
428 /* tag :: The tag of table to load. Use the value 0 if you want */
429 /* to access the whole font file, else set this parameter */
430 /* to a valid TrueType table tag that you can forge with */
431 /* the MAKE_TT_TAG macro. */
433 /* offset :: The starting offset in the table (or the file if */
436 /* length :: The address of the decision variable: */
438 /* If length == NULL: */
439 /* Loads the whole table. Returns an error if */
442 /* If *length == 0: */
443 /* Exits immediately; returning the length of the given */
444 /* table or of the font file, depending on the value of */
447 /* If *length != 0: */
448 /* Loads the next `length' bytes of table or font, */
449 /* starting at offset `offset' (in table or font too). */
452 /* buffer :: The address of target buffer. */
455 /* FreeType error code. 0 means success. */
457 FT_LOCAL_DEF( FT_Error
)
458 tt_face_load_any( TT_Face face
,
472 /* look for tag in font directory */
473 table
= tt_face_lookup_table( face
, tag
);
476 error
= SFNT_Err_Table_Missing
;
480 offset
+= table
->Offset
;
481 size
= table
->Length
;
484 /* tag == 0 -- the user wants to access the font file directly */
485 size
= face
->root
.stream
->size
;
487 if ( length
&& *length
== 0 )
497 stream
= face
->root
.stream
;
498 /* the `if' is syntactic sugar for picky compilers */
499 if ( FT_STREAM_READ_AT( offset
, buffer
, size
) )
507 /*************************************************************************/
510 /* tt_face_load_generic_header */
513 /* Loads the TrueType table `head' or `bhed'. */
516 /* face :: A handle to the target face object. */
518 /* stream :: The input stream. */
521 /* FreeType error code. 0 means success. */
524 tt_face_load_generic_header( TT_Face face
,
531 static const FT_Frame_Field header_fields
[] =
534 #define FT_STRUCTURE TT_Header
536 FT_FRAME_START( 54 ),
537 FT_FRAME_ULONG ( Table_Version
),
538 FT_FRAME_ULONG ( Font_Revision
),
539 FT_FRAME_LONG ( CheckSum_Adjust
),
540 FT_FRAME_LONG ( Magic_Number
),
541 FT_FRAME_USHORT( Flags
),
542 FT_FRAME_USHORT( Units_Per_EM
),
543 FT_FRAME_LONG ( Created
[0] ),
544 FT_FRAME_LONG ( Created
[1] ),
545 FT_FRAME_LONG ( Modified
[0] ),
546 FT_FRAME_LONG ( Modified
[1] ),
547 FT_FRAME_SHORT ( xMin
),
548 FT_FRAME_SHORT ( yMin
),
549 FT_FRAME_SHORT ( xMax
),
550 FT_FRAME_SHORT ( yMax
),
551 FT_FRAME_USHORT( Mac_Style
),
552 FT_FRAME_USHORT( Lowest_Rec_PPEM
),
553 FT_FRAME_SHORT ( Font_Direction
),
554 FT_FRAME_SHORT ( Index_To_Loc_Format
),
555 FT_FRAME_SHORT ( Glyph_Data_Format
),
560 error
= face
->goto_table( face
, tag
, stream
, 0 );
564 header
= &face
->header
;
566 if ( FT_STREAM_READ_FIELDS( header_fields
, header
) )
569 FT_TRACE3(( "Units per EM: %4u\n", header
->Units_Per_EM
));
570 FT_TRACE3(( "IndexToLoc: %4d\n", header
->Index_To_Loc_Format
));
577 FT_LOCAL_DEF( FT_Error
)
578 tt_face_load_head( TT_Face face
,
581 return tt_face_load_generic_header( face
, stream
, TTAG_head
);
585 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
587 FT_LOCAL_DEF( FT_Error
)
588 tt_face_load_bhed( TT_Face face
,
591 return tt_face_load_generic_header( face
, stream
, TTAG_bhed
);
594 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
597 /*************************************************************************/
600 /* tt_face_load_max_profile */
603 /* Loads the maximum profile into a face object. */
606 /* face :: A handle to the target face object. */
608 /* stream :: The input stream. */
611 /* FreeType error code. 0 means success. */
613 FT_LOCAL_DEF( FT_Error
)
614 tt_face_load_maxp( TT_Face face
,
618 TT_MaxProfile
* maxProfile
= &face
->max_profile
;
620 const FT_Frame_Field maxp_fields
[] =
623 #define FT_STRUCTURE TT_MaxProfile
626 FT_FRAME_LONG ( version
),
627 FT_FRAME_USHORT( numGlyphs
),
631 const FT_Frame_Field maxp_fields_extra
[] =
633 FT_FRAME_START( 26 ),
634 FT_FRAME_USHORT( maxPoints
),
635 FT_FRAME_USHORT( maxContours
),
636 FT_FRAME_USHORT( maxCompositePoints
),
637 FT_FRAME_USHORT( maxCompositeContours
),
638 FT_FRAME_USHORT( maxZones
),
639 FT_FRAME_USHORT( maxTwilightPoints
),
640 FT_FRAME_USHORT( maxStorage
),
641 FT_FRAME_USHORT( maxFunctionDefs
),
642 FT_FRAME_USHORT( maxInstructionDefs
),
643 FT_FRAME_USHORT( maxStackElements
),
644 FT_FRAME_USHORT( maxSizeOfInstructions
),
645 FT_FRAME_USHORT( maxComponentElements
),
646 FT_FRAME_USHORT( maxComponentDepth
),
651 error
= face
->goto_table( face
, TTAG_maxp
, stream
, 0 );
655 if ( FT_STREAM_READ_FIELDS( maxp_fields
, maxProfile
) )
658 maxProfile
->maxPoints
= 0;
659 maxProfile
->maxContours
= 0;
660 maxProfile
->maxCompositePoints
= 0;
661 maxProfile
->maxCompositeContours
= 0;
662 maxProfile
->maxZones
= 0;
663 maxProfile
->maxTwilightPoints
= 0;
664 maxProfile
->maxStorage
= 0;
665 maxProfile
->maxFunctionDefs
= 0;
666 maxProfile
->maxInstructionDefs
= 0;
667 maxProfile
->maxStackElements
= 0;
668 maxProfile
->maxSizeOfInstructions
= 0;
669 maxProfile
->maxComponentElements
= 0;
670 maxProfile
->maxComponentDepth
= 0;
672 if ( maxProfile
->version
>= 0x10000L
)
674 if ( FT_STREAM_READ_FIELDS( maxp_fields_extra
, maxProfile
) )
677 /* XXX: an adjustment that is necessary to load certain */
678 /* broken fonts like `Keystrokes MT' :-( */
680 /* We allocate 64 function entries by default when */
681 /* the maxFunctionDefs field is null. */
683 if ( maxProfile
->maxFunctionDefs
== 0 )
684 maxProfile
->maxFunctionDefs
= 64;
686 /* we add 4 phantom points later */
687 if ( maxProfile
->maxTwilightPoints
> ( 0xFFFFU
- 4 ) )
689 FT_TRACE0(( "tt_face_load_maxp:"
690 " too much twilight points in `maxp' table;\n"
692 " some glyphs might be rendered incorrectly\n" ));
694 maxProfile
->maxTwilightPoints
= 0xFFFFU
- 4;
698 FT_TRACE3(( "numGlyphs: %u\n", maxProfile
->numGlyphs
));
705 /*************************************************************************/
708 /* tt_face_load_names */
711 /* Loads the name records. */
714 /* face :: A handle to the target face object. */
716 /* stream :: The input stream. */
719 /* FreeType error code. 0 means success. */
721 FT_LOCAL_DEF( FT_Error
)
722 tt_face_load_name( TT_Face face
,
726 FT_Memory memory
= stream
->memory
;
727 FT_ULong table_pos
, table_len
;
728 FT_ULong storage_start
, storage_limit
;
732 static const FT_Frame_Field name_table_fields
[] =
735 #define FT_STRUCTURE TT_NameTableRec
738 FT_FRAME_USHORT( format
),
739 FT_FRAME_USHORT( numNameRecords
),
740 FT_FRAME_USHORT( storageOffset
),
744 static const FT_Frame_Field name_record_fields
[] =
747 #define FT_STRUCTURE TT_NameEntryRec
749 /* no FT_FRAME_START */
750 FT_FRAME_USHORT( platformID
),
751 FT_FRAME_USHORT( encodingID
),
752 FT_FRAME_USHORT( languageID
),
753 FT_FRAME_USHORT( nameID
),
754 FT_FRAME_USHORT( stringLength
),
755 FT_FRAME_USHORT( stringOffset
),
760 table
= &face
->name_table
;
761 table
->stream
= stream
;
763 error
= face
->goto_table( face
, TTAG_name
, stream
, &table_len
);
767 table_pos
= FT_STREAM_POS();
770 if ( FT_STREAM_READ_FIELDS( name_table_fields
, table
) )
773 /* Some popular Asian fonts have an invalid `storageOffset' value */
774 /* (it should be at least "6 + 12*num_names"). However, the string */
775 /* offsets, computed as "storageOffset + entry->stringOffset", are */
776 /* valid pointers within the name table... */
778 /* We thus can't check `storageOffset' right now. */
780 storage_start
= table_pos
+ 6 + 12*table
->numNameRecords
;
781 storage_limit
= table_pos
+ table_len
;
783 if ( storage_start
> storage_limit
)
785 FT_ERROR(( "tt_face_load_name: invalid `name' table\n" ));
786 error
= SFNT_Err_Name_Table_Missing
;
790 /* Allocate the array of name records. */
791 count
= table
->numNameRecords
;
792 table
->numNameRecords
= 0;
794 if ( FT_NEW_ARRAY( table
->names
, count
) ||
795 FT_FRAME_ENTER( count
* 12 ) )
798 /* Load the name records and determine how much storage is needed */
799 /* to hold the strings themselves. */
801 TT_NameEntryRec
* entry
= table
->names
;
804 for ( ; count
> 0; count
-- )
806 if ( FT_STREAM_READ_FIELDS( name_record_fields
, entry
) )
809 /* check that the name is not empty */
810 if ( entry
->stringLength
== 0 )
813 /* check that the name string is within the table */
814 entry
->stringOffset
+= table_pos
+ table
->storageOffset
;
815 if ( entry
->stringOffset
< storage_start
||
816 entry
->stringOffset
+ entry
->stringLength
> storage_limit
)
818 /* invalid entry - ignore it */
819 entry
->stringOffset
= 0;
820 entry
->stringLength
= 0;
827 table
->numNameRecords
= (FT_UInt
)( entry
- table
->names
);
832 /* everything went well, update face->num_names */
833 face
->num_names
= (FT_UShort
) table
->numNameRecords
;
840 /*************************************************************************/
843 /* tt_face_free_names */
846 /* Frees the name records. */
849 /* face :: A handle to the target face object. */
852 tt_face_free_name( TT_Face face
)
854 FT_Memory memory
= face
->root
.driver
->root
.memory
;
855 TT_NameTable table
= &face
->name_table
;
856 TT_NameEntry entry
= table
->names
;
857 FT_UInt count
= table
->numNameRecords
;
862 for ( ; count
> 0; count
--, entry
++ )
864 FT_FREE( entry
->string
);
865 entry
->stringLength
= 0;
868 /* free strings table */
869 FT_FREE( table
->names
);
872 table
->numNameRecords
= 0;
874 table
->storageOffset
= 0;
878 /*************************************************************************/
881 /* tt_face_load_cmap */
884 /* Loads the cmap directory in a face object. The cmaps themselves */
885 /* are loaded on demand in the `ttcmap.c' module. */
888 /* face :: A handle to the target face object. */
890 /* stream :: A handle to the input stream. */
893 /* FreeType error code. 0 means success. */
896 FT_LOCAL_DEF( FT_Error
)
897 tt_face_load_cmap( TT_Face face
,
903 error
= face
->goto_table( face
, TTAG_cmap
, stream
, &face
->cmap_size
);
907 if ( FT_FRAME_EXTRACT( face
->cmap_size
, face
->cmap_table
) )
916 /*************************************************************************/
919 /* tt_face_load_os2 */
922 /* Loads the OS2 table. */
925 /* face :: A handle to the target face object. */
927 /* stream :: A handle to the input stream. */
930 /* FreeType error code. 0 means success. */
932 FT_LOCAL_DEF( FT_Error
)
933 tt_face_load_os2( TT_Face face
,
939 const FT_Frame_Field os2_fields
[] =
942 #define FT_STRUCTURE TT_OS2
944 FT_FRAME_START( 78 ),
945 FT_FRAME_USHORT( version
),
946 FT_FRAME_SHORT ( xAvgCharWidth
),
947 FT_FRAME_USHORT( usWeightClass
),
948 FT_FRAME_USHORT( usWidthClass
),
949 FT_FRAME_SHORT ( fsType
),
950 FT_FRAME_SHORT ( ySubscriptXSize
),
951 FT_FRAME_SHORT ( ySubscriptYSize
),
952 FT_FRAME_SHORT ( ySubscriptXOffset
),
953 FT_FRAME_SHORT ( ySubscriptYOffset
),
954 FT_FRAME_SHORT ( ySuperscriptXSize
),
955 FT_FRAME_SHORT ( ySuperscriptYSize
),
956 FT_FRAME_SHORT ( ySuperscriptXOffset
),
957 FT_FRAME_SHORT ( ySuperscriptYOffset
),
958 FT_FRAME_SHORT ( yStrikeoutSize
),
959 FT_FRAME_SHORT ( yStrikeoutPosition
),
960 FT_FRAME_SHORT ( sFamilyClass
),
961 FT_FRAME_BYTE ( panose
[0] ),
962 FT_FRAME_BYTE ( panose
[1] ),
963 FT_FRAME_BYTE ( panose
[2] ),
964 FT_FRAME_BYTE ( panose
[3] ),
965 FT_FRAME_BYTE ( panose
[4] ),
966 FT_FRAME_BYTE ( panose
[5] ),
967 FT_FRAME_BYTE ( panose
[6] ),
968 FT_FRAME_BYTE ( panose
[7] ),
969 FT_FRAME_BYTE ( panose
[8] ),
970 FT_FRAME_BYTE ( panose
[9] ),
971 FT_FRAME_ULONG ( ulUnicodeRange1
),
972 FT_FRAME_ULONG ( ulUnicodeRange2
),
973 FT_FRAME_ULONG ( ulUnicodeRange3
),
974 FT_FRAME_ULONG ( ulUnicodeRange4
),
975 FT_FRAME_BYTE ( achVendID
[0] ),
976 FT_FRAME_BYTE ( achVendID
[1] ),
977 FT_FRAME_BYTE ( achVendID
[2] ),
978 FT_FRAME_BYTE ( achVendID
[3] ),
980 FT_FRAME_USHORT( fsSelection
),
981 FT_FRAME_USHORT( usFirstCharIndex
),
982 FT_FRAME_USHORT( usLastCharIndex
),
983 FT_FRAME_SHORT ( sTypoAscender
),
984 FT_FRAME_SHORT ( sTypoDescender
),
985 FT_FRAME_SHORT ( sTypoLineGap
),
986 FT_FRAME_USHORT( usWinAscent
),
987 FT_FRAME_USHORT( usWinDescent
),
991 const FT_Frame_Field os2_fields_extra
[] =
994 FT_FRAME_ULONG( ulCodePageRange1
),
995 FT_FRAME_ULONG( ulCodePageRange2
),
999 const FT_Frame_Field os2_fields_extra2
[] =
1001 FT_FRAME_START( 10 ),
1002 FT_FRAME_SHORT ( sxHeight
),
1003 FT_FRAME_SHORT ( sCapHeight
),
1004 FT_FRAME_USHORT( usDefaultChar
),
1005 FT_FRAME_USHORT( usBreakChar
),
1006 FT_FRAME_USHORT( usMaxContext
),
1011 /* We now support old Mac fonts where the OS/2 table doesn't */
1012 /* exist. Simply put, we set the `version' field to 0xFFFF */
1013 /* and test this value each time we need to access the table. */
1014 error
= face
->goto_table( face
, TTAG_OS2
, stream
, 0 );
1020 if ( FT_STREAM_READ_FIELDS( os2_fields
, os2
) )
1023 os2
->ulCodePageRange1
= 0;
1024 os2
->ulCodePageRange2
= 0;
1026 os2
->sCapHeight
= 0;
1027 os2
->usDefaultChar
= 0;
1028 os2
->usBreakChar
= 0;
1029 os2
->usMaxContext
= 0;
1031 if ( os2
->version
>= 0x0001 )
1033 /* only version 1 tables */
1034 if ( FT_STREAM_READ_FIELDS( os2_fields_extra
, os2
) )
1037 if ( os2
->version
>= 0x0002 )
1039 /* only version 2 tables */
1040 if ( FT_STREAM_READ_FIELDS( os2_fields_extra2
, os2
) )
1045 FT_TRACE3(( "sTypoAscender: %4d\n", os2
->sTypoAscender
));
1046 FT_TRACE3(( "sTypoDescender: %4d\n", os2
->sTypoDescender
));
1047 FT_TRACE3(( "usWinAscent: %4u\n", os2
->usWinAscent
));
1048 FT_TRACE3(( "usWinDescent: %4u\n", os2
->usWinDescent
));
1049 FT_TRACE3(( "fsSelection: 0x%2x\n", os2
->fsSelection
));
1056 /*************************************************************************/
1059 /* tt_face_load_postscript */
1062 /* Loads the Postscript table. */
1065 /* face :: A handle to the target face object. */
1067 /* stream :: A handle to the input stream. */
1070 /* FreeType error code. 0 means success. */
1072 FT_LOCAL_DEF( FT_Error
)
1073 tt_face_load_post( TT_Face face
,
1077 TT_Postscript
* post
= &face
->postscript
;
1079 static const FT_Frame_Field post_fields
[] =
1082 #define FT_STRUCTURE TT_Postscript
1084 FT_FRAME_START( 32 ),
1085 FT_FRAME_ULONG( FormatType
),
1086 FT_FRAME_ULONG( italicAngle
),
1087 FT_FRAME_SHORT( underlinePosition
),
1088 FT_FRAME_SHORT( underlineThickness
),
1089 FT_FRAME_ULONG( isFixedPitch
),
1090 FT_FRAME_ULONG( minMemType42
),
1091 FT_FRAME_ULONG( maxMemType42
),
1092 FT_FRAME_ULONG( minMemType1
),
1093 FT_FRAME_ULONG( maxMemType1
),
1098 error
= face
->goto_table( face
, TTAG_post
, stream
, 0 );
1102 if ( FT_STREAM_READ_FIELDS( post_fields
, post
) )
1105 /* we don't load the glyph names, we do that in another */
1106 /* module (ttpost). */
1108 FT_TRACE3(( "FormatType: 0x%x\n", post
->FormatType
));
1109 FT_TRACE3(( "isFixedPitch: %s\n", post
->isFixedPitch
1110 ? " yes" : " no" ));
1116 /*************************************************************************/
1119 /* tt_face_load_pclt */
1122 /* Loads the PCL 5 Table. */
1125 /* face :: A handle to the target face object. */
1127 /* stream :: A handle to the input stream. */
1130 /* FreeType error code. 0 means success. */
1132 FT_LOCAL_DEF( FT_Error
)
1133 tt_face_load_pclt( TT_Face face
,
1136 static const FT_Frame_Field pclt_fields
[] =
1139 #define FT_STRUCTURE TT_PCLT
1141 FT_FRAME_START( 54 ),
1142 FT_FRAME_ULONG ( Version
),
1143 FT_FRAME_ULONG ( FontNumber
),
1144 FT_FRAME_USHORT( Pitch
),
1145 FT_FRAME_USHORT( xHeight
),
1146 FT_FRAME_USHORT( Style
),
1147 FT_FRAME_USHORT( TypeFamily
),
1148 FT_FRAME_USHORT( CapHeight
),
1149 FT_FRAME_BYTES ( TypeFace
, 16 ),
1150 FT_FRAME_BYTES ( CharacterComplement
, 8 ),
1151 FT_FRAME_BYTES ( FileName
, 6 ),
1152 FT_FRAME_CHAR ( StrokeWeight
),
1153 FT_FRAME_CHAR ( WidthType
),
1154 FT_FRAME_BYTE ( SerifStyle
),
1155 FT_FRAME_BYTE ( Reserved
),
1160 TT_PCLT
* pclt
= &face
->pclt
;
1163 /* optional table */
1164 error
= face
->goto_table( face
, TTAG_PCLT
, stream
, 0 );
1168 if ( FT_STREAM_READ_FIELDS( pclt_fields
, pclt
) )
1176 /*************************************************************************/
1179 /* tt_face_load_gasp */
1182 /* Loads the `gasp' table into a face object. */
1185 /* face :: A handle to the target face object. */
1187 /* stream :: The input stream. */
1190 /* FreeType error code. 0 means success. */
1192 FT_LOCAL_DEF( FT_Error
)
1193 tt_face_load_gasp( TT_Face face
,
1197 FT_Memory memory
= stream
->memory
;
1199 FT_UInt j
,num_ranges
;
1200 TT_GaspRange gaspranges
;
1203 /* the gasp table is optional */
1204 error
= face
->goto_table( face
, TTAG_gasp
, stream
, 0 );
1208 if ( FT_FRAME_ENTER( 4L ) )
1211 face
->gasp
.version
= FT_GET_USHORT();
1212 face
->gasp
.numRanges
= FT_GET_USHORT();
1216 /* only support versions 0 and 1 of the table */
1217 if ( face
->gasp
.version
>= 2 )
1219 face
->gasp
.numRanges
= 0;
1220 error
= SFNT_Err_Invalid_Table
;
1224 num_ranges
= face
->gasp
.numRanges
;
1225 FT_TRACE3(( "numRanges: %u\n", num_ranges
));
1227 if ( FT_QNEW_ARRAY( gaspranges
, num_ranges
) ||
1228 FT_FRAME_ENTER( num_ranges
* 4L ) )
1231 face
->gasp
.gaspRanges
= gaspranges
;
1233 for ( j
= 0; j
< num_ranges
; j
++ )
1235 gaspranges
[j
].maxPPEM
= FT_GET_USHORT();
1236 gaspranges
[j
].gaspFlag
= FT_GET_USHORT();
1238 FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n",
1240 gaspranges
[j
].maxPPEM
,
1241 gaspranges
[j
].gaspFlag
));