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 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
,
63 FT_TRACE4(( "tt_face_lookup_table: %08p, `%c%c%c%c' -- ",
65 (FT_Char
)( tag
>> 24 ),
66 (FT_Char
)( tag
>> 16 ),
67 (FT_Char
)( tag
>> 8 ),
70 entry
= face
->dir_tables
;
71 limit
= entry
+ face
->num_tables
;
73 for ( ; entry
< limit
; entry
++ )
75 /* For compatibility with Windows, we consider 0-length */
76 /* tables the same as missing tables. */
77 if ( entry
->Tag
== tag
&& entry
->Length
!= 0 )
79 FT_TRACE4(( "found table.\n" ));
84 FT_TRACE4(( "could not find table!\n" ));
89 /*************************************************************************/
92 /* tt_face_goto_table */
95 /* Looks for a TrueType table by name, then seek a stream to it. */
98 /* face :: A face object handle. */
100 /* tag :: The searched tag. */
102 /* stream :: The stream to seek when the table is found. */
105 /* length :: The length of the table if found, undefined otherwise. */
108 /* FreeType error code. 0 means success. */
110 FT_LOCAL_DEF( FT_Error
)
111 tt_face_goto_table( TT_Face face
,
120 table
= tt_face_lookup_table( face
, tag
);
124 *length
= table
->Length
;
126 if ( FT_STREAM_SEEK( table
->Offset
) )
130 error
= SFNT_Err_Table_Missing
;
139 /* - check that `num_tables' is valid */
140 /* - look for a `head' table, check its size, and parse it to check */
141 /* whether its `magic' field is correctly set */
143 /* When checking directory entries, ignore the tables `glyx' and `locx' */
144 /* which are hacked-out versions of `glyf' and `loca' in some PostScript */
145 /* Type 42 fonts, and which are generally invalid. */
148 check_table_dir( SFNT_Header sfnt
,
153 FT_UInt has_head
= 0, has_sing
= 0, has_meta
= 0;
154 FT_ULong offset
= sfnt
->offset
+ 12;
156 const FT_ULong glyx_tag
= FT_MAKE_TAG( 'g', 'l', 'y', 'x' );
157 const FT_ULong locx_tag
= FT_MAKE_TAG( 'l', 'o', 'c', 'x' );
159 static const FT_Frame_Field table_dir_entry_fields
[] =
162 #define FT_STRUCTURE TT_TableRec
164 FT_FRAME_START( 16 ),
165 FT_FRAME_ULONG( Tag
),
166 FT_FRAME_ULONG( CheckSum
),
167 FT_FRAME_ULONG( Offset
),
168 FT_FRAME_ULONG( Length
),
173 if ( sfnt
->num_tables
== 0 ||
174 offset
+ sfnt
->num_tables
* 16 > stream
->size
)
175 return SFNT_Err_Unknown_File_Format
;
177 if ( FT_STREAM_SEEK( offset
) )
180 for ( nn
= 0; nn
< sfnt
->num_tables
; nn
++ )
185 if ( FT_STREAM_READ_FIELDS( table_dir_entry_fields
, &table
) )
188 if ( table
.Offset
+ table
.Length
> stream
->size
&&
189 table
.Tag
!= glyx_tag
&&
190 table
.Tag
!= locx_tag
)
191 return SFNT_Err_Unknown_File_Format
;
193 if ( table
.Tag
== TTAG_head
|| table
.Tag
== TTAG_bhed
)
198 #ifndef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
199 if ( table
.Tag
== TTAG_head
)
204 * The table length should be 0x36, but certain font tools make it
205 * 0x38, so we will just check that it is greater.
207 * Note that according to the specification, the table must be
208 * padded to 32-bit lengths, but this doesn't apply to the value of
209 * its `Length' field!
212 if ( table
.Length
< 0x36 )
213 return SFNT_Err_Unknown_File_Format
;
215 if ( FT_STREAM_SEEK( table
.Offset
+ 12 ) ||
216 FT_READ_ULONG( magic
) )
219 if ( magic
!= 0x5F0F3CF5UL
)
220 return SFNT_Err_Unknown_File_Format
;
222 if ( FT_STREAM_SEEK( offset
+ ( nn
+ 1 ) * 16 ) )
225 else if ( table
.Tag
== TTAG_SING
)
227 else if ( table
.Tag
== TTAG_META
)
231 /* if `sing' and `meta' tables are present, there is no `head' table */
232 if ( has_head
|| ( has_sing
&& has_meta
) )
235 return SFNT_Err_Unknown_File_Format
;
239 /*************************************************************************/
242 /* tt_face_load_font_dir */
245 /* Loads the header of a SFNT font file. */
248 /* face :: A handle to the target face object. */
250 /* stream :: The input stream. */
253 /* sfnt :: The SFNT header. */
256 /* FreeType error code. 0 means success. */
259 /* The stream cursor must be at the beginning of the font directory. */
261 FT_LOCAL_DEF( FT_Error
)
262 tt_face_load_font_dir( TT_Face face
,
267 FT_Memory memory
= stream
->memory
;
271 static const FT_Frame_Field offset_table_fields
[] =
274 #define FT_STRUCTURE SFNT_HeaderRec
277 FT_FRAME_USHORT( num_tables
),
278 FT_FRAME_USHORT( search_range
),
279 FT_FRAME_USHORT( entry_selector
),
280 FT_FRAME_USHORT( range_shift
),
285 FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face
));
287 /* read the offset table */
289 sfnt
.offset
= FT_STREAM_POS();
291 if ( FT_READ_ULONG( sfnt
.format_tag
) ||
292 FT_STREAM_READ_FIELDS( offset_table_fields
, &sfnt
) )
295 /* many fonts don't have these fields set correctly */
297 if ( sfnt
.search_range
!= 1 << ( sfnt
.entry_selector
+ 4 ) ||
298 sfnt
.search_range
+ sfnt
.range_shift
!= sfnt
.num_tables
<< 4 )
299 return SFNT_Err_Unknown_File_Format
;
302 /* load the table directory */
304 FT_TRACE2(( "-- Tables count: %12u\n", sfnt
.num_tables
));
305 FT_TRACE2(( "-- Format version: %08lx\n", sfnt
.format_tag
));
308 error
= check_table_dir( &sfnt
, stream
);
311 FT_TRACE2(( "tt_face_load_font_dir: invalid table directory!\n" ));
316 face
->num_tables
= sfnt
.num_tables
;
317 face
->format_tag
= sfnt
.format_tag
;
319 if ( FT_QNEW_ARRAY( face
->dir_tables
, face
->num_tables
) )
322 if ( FT_STREAM_SEEK( sfnt
.offset
+ 12 ) ||
323 FT_FRAME_ENTER( face
->num_tables
* 16L ) )
326 entry
= face
->dir_tables
;
327 limit
= entry
+ face
->num_tables
;
329 for ( ; entry
< limit
; entry
++ )
331 entry
->Tag
= FT_GET_TAG4();
332 entry
->CheckSum
= FT_GET_ULONG();
333 entry
->Offset
= FT_GET_LONG();
334 entry
->Length
= FT_GET_LONG();
336 FT_TRACE2(( " %c%c%c%c - %08lx - %08lx\n",
337 (FT_Char
)( entry
->Tag
>> 24 ),
338 (FT_Char
)( entry
->Tag
>> 16 ),
339 (FT_Char
)( entry
->Tag
>> 8 ),
340 (FT_Char
)( entry
->Tag
),
347 FT_TRACE2(( "table directory loaded\n\n" ));
353 /*************************************************************************/
356 /* tt_face_load_any */
359 /* Loads any font table into client memory. */
362 /* face :: The face object to look for. */
364 /* tag :: The tag of table to load. Use the value 0 if you want */
365 /* to access the whole font file, else set this parameter */
366 /* to a valid TrueType table tag that you can forge with */
367 /* the MAKE_TT_TAG macro. */
369 /* offset :: The starting offset in the table (or the file if */
372 /* length :: The address of the decision variable: */
374 /* If length == NULL: */
375 /* Loads the whole table. Returns an error if */
378 /* If *length == 0: */
379 /* Exits immediately; returning the length of the given */
380 /* table or of the font file, depending on the value of */
383 /* If *length != 0: */
384 /* Loads the next `length' bytes of table or font, */
385 /* starting at offset `offset' (in table or font too). */
388 /* buffer :: The address of target buffer. */
391 /* FreeType error code. 0 means success. */
393 FT_LOCAL_DEF( FT_Error
)
394 tt_face_load_any( TT_Face face
,
408 /* look for tag in font directory */
409 table
= tt_face_lookup_table( face
, tag
);
412 error
= SFNT_Err_Table_Missing
;
416 offset
+= table
->Offset
;
417 size
= table
->Length
;
420 /* tag == 0 -- the user wants to access the font file directly */
421 size
= face
->root
.stream
->size
;
423 if ( length
&& *length
== 0 )
433 stream
= face
->root
.stream
;
434 /* the `if' is syntactic sugar for picky compilers */
435 if ( FT_STREAM_READ_AT( offset
, buffer
, size
) )
443 /*************************************************************************/
446 /* tt_face_load_generic_header */
449 /* Loads the TrueType table `head' or `bhed'. */
452 /* face :: A handle to the target face object. */
454 /* stream :: The input stream. */
457 /* FreeType error code. 0 means success. */
460 tt_face_load_generic_header( TT_Face face
,
467 static const FT_Frame_Field header_fields
[] =
470 #define FT_STRUCTURE TT_Header
472 FT_FRAME_START( 54 ),
473 FT_FRAME_ULONG ( Table_Version
),
474 FT_FRAME_ULONG ( Font_Revision
),
475 FT_FRAME_LONG ( CheckSum_Adjust
),
476 FT_FRAME_LONG ( Magic_Number
),
477 FT_FRAME_USHORT( Flags
),
478 FT_FRAME_USHORT( Units_Per_EM
),
479 FT_FRAME_LONG ( Created
[0] ),
480 FT_FRAME_LONG ( Created
[1] ),
481 FT_FRAME_LONG ( Modified
[0] ),
482 FT_FRAME_LONG ( Modified
[1] ),
483 FT_FRAME_SHORT ( xMin
),
484 FT_FRAME_SHORT ( yMin
),
485 FT_FRAME_SHORT ( xMax
),
486 FT_FRAME_SHORT ( yMax
),
487 FT_FRAME_USHORT( Mac_Style
),
488 FT_FRAME_USHORT( Lowest_Rec_PPEM
),
489 FT_FRAME_SHORT ( Font_Direction
),
490 FT_FRAME_SHORT ( Index_To_Loc_Format
),
491 FT_FRAME_SHORT ( Glyph_Data_Format
),
496 error
= face
->goto_table( face
, tag
, stream
, 0 );
500 header
= &face
->header
;
502 if ( FT_STREAM_READ_FIELDS( header_fields
, header
) )
505 FT_TRACE3(( "Units per EM: %4u\n", header
->Units_Per_EM
));
506 FT_TRACE3(( "IndexToLoc: %4d\n", header
->Index_To_Loc_Format
));
513 FT_LOCAL_DEF( FT_Error
)
514 tt_face_load_head( TT_Face face
,
517 return tt_face_load_generic_header( face
, stream
, TTAG_head
);
521 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
523 FT_LOCAL_DEF( FT_Error
)
524 tt_face_load_bhed( TT_Face face
,
527 return tt_face_load_generic_header( face
, stream
, TTAG_bhed
);
530 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
533 /*************************************************************************/
536 /* tt_face_load_max_profile */
539 /* Loads the maximum profile into a face object. */
542 /* face :: A handle to the target face object. */
544 /* stream :: The input stream. */
547 /* FreeType error code. 0 means success. */
549 FT_LOCAL_DEF( FT_Error
)
550 tt_face_load_maxp( TT_Face face
,
554 TT_MaxProfile
* maxProfile
= &face
->max_profile
;
556 const FT_Frame_Field maxp_fields
[] =
559 #define FT_STRUCTURE TT_MaxProfile
562 FT_FRAME_LONG ( version
),
563 FT_FRAME_USHORT( numGlyphs
),
567 const FT_Frame_Field maxp_fields_extra
[] =
569 FT_FRAME_START( 26 ),
570 FT_FRAME_USHORT( maxPoints
),
571 FT_FRAME_USHORT( maxContours
),
572 FT_FRAME_USHORT( maxCompositePoints
),
573 FT_FRAME_USHORT( maxCompositeContours
),
574 FT_FRAME_USHORT( maxZones
),
575 FT_FRAME_USHORT( maxTwilightPoints
),
576 FT_FRAME_USHORT( maxStorage
),
577 FT_FRAME_USHORT( maxFunctionDefs
),
578 FT_FRAME_USHORT( maxInstructionDefs
),
579 FT_FRAME_USHORT( maxStackElements
),
580 FT_FRAME_USHORT( maxSizeOfInstructions
),
581 FT_FRAME_USHORT( maxComponentElements
),
582 FT_FRAME_USHORT( maxComponentDepth
),
587 error
= face
->goto_table( face
, TTAG_maxp
, stream
, 0 );
591 if ( FT_STREAM_READ_FIELDS( maxp_fields
, maxProfile
) )
594 maxProfile
->maxPoints
= 0;
595 maxProfile
->maxContours
= 0;
596 maxProfile
->maxCompositePoints
= 0;
597 maxProfile
->maxCompositeContours
= 0;
598 maxProfile
->maxZones
= 0;
599 maxProfile
->maxTwilightPoints
= 0;
600 maxProfile
->maxStorage
= 0;
601 maxProfile
->maxFunctionDefs
= 0;
602 maxProfile
->maxInstructionDefs
= 0;
603 maxProfile
->maxStackElements
= 0;
604 maxProfile
->maxSizeOfInstructions
= 0;
605 maxProfile
->maxComponentElements
= 0;
606 maxProfile
->maxComponentDepth
= 0;
608 if ( maxProfile
->version
>= 0x10000L
)
610 if ( FT_STREAM_READ_FIELDS( maxp_fields_extra
, maxProfile
) )
613 /* XXX: an adjustment that is necessary to load certain */
614 /* broken fonts like `Keystrokes MT' :-( */
616 /* We allocate 64 function entries by default when */
617 /* the maxFunctionDefs field is null. */
619 if ( maxProfile
->maxFunctionDefs
== 0 )
620 maxProfile
->maxFunctionDefs
= 64;
623 FT_TRACE3(( "numGlyphs: %u\n", maxProfile
->numGlyphs
));
630 /*************************************************************************/
633 /* tt_face_load_names */
636 /* Loads the name records. */
639 /* face :: A handle to the target face object. */
641 /* stream :: The input stream. */
644 /* FreeType error code. 0 means success. */
646 FT_LOCAL_DEF( FT_Error
)
647 tt_face_load_name( TT_Face face
,
651 FT_Memory memory
= stream
->memory
;
652 FT_ULong table_pos
, table_len
;
653 FT_ULong storage_start
, storage_limit
;
657 static const FT_Frame_Field name_table_fields
[] =
660 #define FT_STRUCTURE TT_NameTableRec
663 FT_FRAME_USHORT( format
),
664 FT_FRAME_USHORT( numNameRecords
),
665 FT_FRAME_USHORT( storageOffset
),
669 static const FT_Frame_Field name_record_fields
[] =
672 #define FT_STRUCTURE TT_NameEntryRec
674 /* no FT_FRAME_START */
675 FT_FRAME_USHORT( platformID
),
676 FT_FRAME_USHORT( encodingID
),
677 FT_FRAME_USHORT( languageID
),
678 FT_FRAME_USHORT( nameID
),
679 FT_FRAME_USHORT( stringLength
),
680 FT_FRAME_USHORT( stringOffset
),
685 table
= &face
->name_table
;
686 table
->stream
= stream
;
688 error
= face
->goto_table( face
, TTAG_name
, stream
, &table_len
);
692 table_pos
= FT_STREAM_POS();
695 if ( FT_STREAM_READ_FIELDS( name_table_fields
, table
) )
698 /* Some popular Asian fonts have an invalid `storageOffset' value */
699 /* (it should be at least "6 + 12*num_names"). However, the string */
700 /* offsets, computed as "storageOffset + entry->stringOffset", are */
701 /* valid pointers within the name table... */
703 /* We thus can't check `storageOffset' right now. */
705 storage_start
= table_pos
+ 6 + 12*table
->numNameRecords
;
706 storage_limit
= table_pos
+ table_len
;
708 if ( storage_start
> storage_limit
)
710 FT_ERROR(( "invalid `name' table\n" ));
711 error
= SFNT_Err_Name_Table_Missing
;
715 /* Allocate the array of name records. */
716 count
= table
->numNameRecords
;
717 table
->numNameRecords
= 0;
719 if ( FT_NEW_ARRAY( table
->names
, count
) ||
720 FT_FRAME_ENTER( count
* 12 ) )
723 /* Load the name records and determine how much storage is needed */
724 /* to hold the strings themselves. */
726 TT_NameEntryRec
* entry
= table
->names
;
729 for ( ; count
> 0; count
-- )
731 if ( FT_STREAM_READ_FIELDS( name_record_fields
, entry
) )
734 /* check that the name is not empty */
735 if ( entry
->stringLength
== 0 )
738 /* check that the name string is within the table */
739 entry
->stringOffset
+= table_pos
+ table
->storageOffset
;
740 if ( entry
->stringOffset
< storage_start
||
741 entry
->stringOffset
+ entry
->stringLength
> storage_limit
)
743 /* invalid entry - ignore it */
744 entry
->stringOffset
= 0;
745 entry
->stringLength
= 0;
752 table
->numNameRecords
= (FT_UInt
)( entry
- table
->names
);
757 /* everything went well, update face->num_names */
758 face
->num_names
= (FT_UShort
) table
->numNameRecords
;
765 /*************************************************************************/
768 /* tt_face_free_names */
771 /* Frees the name records. */
774 /* face :: A handle to the target face object. */
777 tt_face_free_name( TT_Face face
)
779 FT_Memory memory
= face
->root
.driver
->root
.memory
;
780 TT_NameTable table
= &face
->name_table
;
781 TT_NameEntry entry
= table
->names
;
782 FT_UInt count
= table
->numNameRecords
;
787 for ( ; count
> 0; count
--, entry
++ )
789 FT_FREE( entry
->string
);
790 entry
->stringLength
= 0;
793 /* free strings table */
794 FT_FREE( table
->names
);
797 table
->numNameRecords
= 0;
799 table
->storageOffset
= 0;
803 /*************************************************************************/
806 /* tt_face_load_cmap */
809 /* Loads the cmap directory in a face object. The cmaps themselves */
810 /* are loaded on demand in the `ttcmap.c' module. */
813 /* face :: A handle to the target face object. */
815 /* stream :: A handle to the input stream. */
818 /* FreeType error code. 0 means success. */
821 FT_LOCAL_DEF( FT_Error
)
822 tt_face_load_cmap( TT_Face face
,
828 error
= face
->goto_table( face
, TTAG_cmap
, stream
, &face
->cmap_size
);
832 if ( FT_FRAME_EXTRACT( face
->cmap_size
, face
->cmap_table
) )
841 /*************************************************************************/
844 /* tt_face_load_os2 */
847 /* Loads the OS2 table. */
850 /* face :: A handle to the target face object. */
852 /* stream :: A handle to the input stream. */
855 /* FreeType error code. 0 means success. */
857 FT_LOCAL_DEF( FT_Error
)
858 tt_face_load_os2( TT_Face face
,
864 const FT_Frame_Field os2_fields
[] =
867 #define FT_STRUCTURE TT_OS2
869 FT_FRAME_START( 78 ),
870 FT_FRAME_USHORT( version
),
871 FT_FRAME_SHORT ( xAvgCharWidth
),
872 FT_FRAME_USHORT( usWeightClass
),
873 FT_FRAME_USHORT( usWidthClass
),
874 FT_FRAME_SHORT ( fsType
),
875 FT_FRAME_SHORT ( ySubscriptXSize
),
876 FT_FRAME_SHORT ( ySubscriptYSize
),
877 FT_FRAME_SHORT ( ySubscriptXOffset
),
878 FT_FRAME_SHORT ( ySubscriptYOffset
),
879 FT_FRAME_SHORT ( ySuperscriptXSize
),
880 FT_FRAME_SHORT ( ySuperscriptYSize
),
881 FT_FRAME_SHORT ( ySuperscriptXOffset
),
882 FT_FRAME_SHORT ( ySuperscriptYOffset
),
883 FT_FRAME_SHORT ( yStrikeoutSize
),
884 FT_FRAME_SHORT ( yStrikeoutPosition
),
885 FT_FRAME_SHORT ( sFamilyClass
),
886 FT_FRAME_BYTE ( panose
[0] ),
887 FT_FRAME_BYTE ( panose
[1] ),
888 FT_FRAME_BYTE ( panose
[2] ),
889 FT_FRAME_BYTE ( panose
[3] ),
890 FT_FRAME_BYTE ( panose
[4] ),
891 FT_FRAME_BYTE ( panose
[5] ),
892 FT_FRAME_BYTE ( panose
[6] ),
893 FT_FRAME_BYTE ( panose
[7] ),
894 FT_FRAME_BYTE ( panose
[8] ),
895 FT_FRAME_BYTE ( panose
[9] ),
896 FT_FRAME_ULONG ( ulUnicodeRange1
),
897 FT_FRAME_ULONG ( ulUnicodeRange2
),
898 FT_FRAME_ULONG ( ulUnicodeRange3
),
899 FT_FRAME_ULONG ( ulUnicodeRange4
),
900 FT_FRAME_BYTE ( achVendID
[0] ),
901 FT_FRAME_BYTE ( achVendID
[1] ),
902 FT_FRAME_BYTE ( achVendID
[2] ),
903 FT_FRAME_BYTE ( achVendID
[3] ),
905 FT_FRAME_USHORT( fsSelection
),
906 FT_FRAME_USHORT( usFirstCharIndex
),
907 FT_FRAME_USHORT( usLastCharIndex
),
908 FT_FRAME_SHORT ( sTypoAscender
),
909 FT_FRAME_SHORT ( sTypoDescender
),
910 FT_FRAME_SHORT ( sTypoLineGap
),
911 FT_FRAME_USHORT( usWinAscent
),
912 FT_FRAME_USHORT( usWinDescent
),
916 const FT_Frame_Field os2_fields_extra
[] =
919 FT_FRAME_ULONG( ulCodePageRange1
),
920 FT_FRAME_ULONG( ulCodePageRange2
),
924 const FT_Frame_Field os2_fields_extra2
[] =
926 FT_FRAME_START( 10 ),
927 FT_FRAME_SHORT ( sxHeight
),
928 FT_FRAME_SHORT ( sCapHeight
),
929 FT_FRAME_USHORT( usDefaultChar
),
930 FT_FRAME_USHORT( usBreakChar
),
931 FT_FRAME_USHORT( usMaxContext
),
936 /* We now support old Mac fonts where the OS/2 table doesn't */
937 /* exist. Simply put, we set the `version' field to 0xFFFF */
938 /* and test this value each time we need to access the table. */
939 error
= face
->goto_table( face
, TTAG_OS2
, stream
, 0 );
945 if ( FT_STREAM_READ_FIELDS( os2_fields
, os2
) )
948 os2
->ulCodePageRange1
= 0;
949 os2
->ulCodePageRange2
= 0;
952 os2
->usDefaultChar
= 0;
953 os2
->usBreakChar
= 0;
954 os2
->usMaxContext
= 0;
956 if ( os2
->version
>= 0x0001 )
958 /* only version 1 tables */
959 if ( FT_STREAM_READ_FIELDS( os2_fields_extra
, os2
) )
962 if ( os2
->version
>= 0x0002 )
964 /* only version 2 tables */
965 if ( FT_STREAM_READ_FIELDS( os2_fields_extra2
, os2
) )
970 FT_TRACE3(( "sTypoAscender: %4d\n", os2
->sTypoAscender
));
971 FT_TRACE3(( "sTypoDescender: %4d\n", os2
->sTypoDescender
));
972 FT_TRACE3(( "usWinAscent: %4u\n", os2
->usWinAscent
));
973 FT_TRACE3(( "usWinDescent: %4u\n", os2
->usWinDescent
));
974 FT_TRACE3(( "fsSelection: 0x%2x\n", os2
->fsSelection
));
981 /*************************************************************************/
984 /* tt_face_load_postscript */
987 /* Loads the Postscript table. */
990 /* face :: A handle to the target face object. */
992 /* stream :: A handle to the input stream. */
995 /* FreeType error code. 0 means success. */
997 FT_LOCAL_DEF( FT_Error
)
998 tt_face_load_post( TT_Face face
,
1002 TT_Postscript
* post
= &face
->postscript
;
1004 static const FT_Frame_Field post_fields
[] =
1007 #define FT_STRUCTURE TT_Postscript
1009 FT_FRAME_START( 32 ),
1010 FT_FRAME_ULONG( FormatType
),
1011 FT_FRAME_ULONG( italicAngle
),
1012 FT_FRAME_SHORT( underlinePosition
),
1013 FT_FRAME_SHORT( underlineThickness
),
1014 FT_FRAME_ULONG( isFixedPitch
),
1015 FT_FRAME_ULONG( minMemType42
),
1016 FT_FRAME_ULONG( maxMemType42
),
1017 FT_FRAME_ULONG( minMemType1
),
1018 FT_FRAME_ULONG( maxMemType1
),
1023 error
= face
->goto_table( face
, TTAG_post
, stream
, 0 );
1027 if ( FT_STREAM_READ_FIELDS( post_fields
, post
) )
1030 /* we don't load the glyph names, we do that in another */
1031 /* module (ttpost). */
1033 FT_TRACE3(( "FormatType: 0x%x\n", post
->FormatType
));
1034 FT_TRACE3(( "isFixedPitch: %s\n", post
->isFixedPitch
1035 ? " yes" : " no" ));
1041 /*************************************************************************/
1044 /* tt_face_load_pclt */
1047 /* Loads the PCL 5 Table. */
1050 /* face :: A handle to the target face object. */
1052 /* stream :: A handle to the input stream. */
1055 /* FreeType error code. 0 means success. */
1057 FT_LOCAL_DEF( FT_Error
)
1058 tt_face_load_pclt( TT_Face face
,
1061 static const FT_Frame_Field pclt_fields
[] =
1064 #define FT_STRUCTURE TT_PCLT
1066 FT_FRAME_START( 54 ),
1067 FT_FRAME_ULONG ( Version
),
1068 FT_FRAME_ULONG ( FontNumber
),
1069 FT_FRAME_USHORT( Pitch
),
1070 FT_FRAME_USHORT( xHeight
),
1071 FT_FRAME_USHORT( Style
),
1072 FT_FRAME_USHORT( TypeFamily
),
1073 FT_FRAME_USHORT( CapHeight
),
1074 FT_FRAME_BYTES ( TypeFace
, 16 ),
1075 FT_FRAME_BYTES ( CharacterComplement
, 8 ),
1076 FT_FRAME_BYTES ( FileName
, 6 ),
1077 FT_FRAME_CHAR ( StrokeWeight
),
1078 FT_FRAME_CHAR ( WidthType
),
1079 FT_FRAME_BYTE ( SerifStyle
),
1080 FT_FRAME_BYTE ( Reserved
),
1085 TT_PCLT
* pclt
= &face
->pclt
;
1088 /* optional table */
1089 error
= face
->goto_table( face
, TTAG_PCLT
, stream
, 0 );
1093 if ( FT_STREAM_READ_FIELDS( pclt_fields
, pclt
) )
1101 /*************************************************************************/
1104 /* tt_face_load_gasp */
1107 /* Loads the `gasp' table into a face object. */
1110 /* face :: A handle to the target face object. */
1112 /* stream :: The input stream. */
1115 /* FreeType error code. 0 means success. */
1117 FT_LOCAL_DEF( FT_Error
)
1118 tt_face_load_gasp( TT_Face face
,
1122 FT_Memory memory
= stream
->memory
;
1124 FT_UInt j
,num_ranges
;
1125 TT_GaspRange gaspranges
;
1128 /* the gasp table is optional */
1129 error
= face
->goto_table( face
, TTAG_gasp
, stream
, 0 );
1133 if ( FT_FRAME_ENTER( 4L ) )
1136 face
->gasp
.version
= FT_GET_USHORT();
1137 face
->gasp
.numRanges
= FT_GET_USHORT();
1141 /* only support versions 0 and 1 of the table */
1142 if ( face
->gasp
.version
>= 2 )
1144 face
->gasp
.numRanges
= 0;
1145 error
= SFNT_Err_Invalid_Table
;
1149 num_ranges
= face
->gasp
.numRanges
;
1150 FT_TRACE3(( "numRanges: %u\n", num_ranges
));
1152 if ( FT_QNEW_ARRAY( gaspranges
, num_ranges
) ||
1153 FT_FRAME_ENTER( num_ranges
* 4L ) )
1156 face
->gasp
.gaspRanges
= gaspranges
;
1158 for ( j
= 0; j
< num_ranges
; j
++ )
1160 gaspranges
[j
].maxPPEM
= FT_GET_USHORT();
1161 gaspranges
[j
].gaspFlag
= FT_GET_USHORT();
1163 FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n",
1165 gaspranges
[j
].maxPPEM
,
1166 gaspranges
[j
].gaspFlag
));