📄 ttload.c
字号:
FT_TRACE2(( "Directory loaded\n\n" )); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Any */ /* */ /* <Description> */ /* Loads any font table into client memory. */ /* */ /* <Input> */ /* face :: The face object to look for. */ /* */ /* tag :: The tag of table to load. Use the value 0 if you want */ /* to access the whole font file, else set this parameter */ /* to a valid TrueType table tag that you can forge with */ /* the MAKE_TT_TAG macro. */ /* */ /* offset :: The starting offset in the table (or the file if */ /* tag == 0). */ /* */ /* length :: The address of the decision variable: */ /* */ /* If length == NULL: */ /* Loads the whole table. Returns an error if */ /* `offset' == 0! */ /* */ /* If *length == 0: */ /* Exits immediately; returning the length of the given */ /* table or of the font file, depending on the value of */ /* `tag'. */ /* */ /* If *length != 0: */ /* Loads the next `length' bytes of table or font, */ /* starting at offset `offset' (in table or font too). */ /* */ /* <Output> */ /* buffer :: The address of target buffer. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF FT_Error TT_Load_Any( TT_Face face, FT_ULong tag, FT_Long offset, FT_Byte* buffer, FT_ULong* length ) { FT_Error error; FT_Stream stream; TT_Table* table; FT_ULong size; if ( tag != 0 ) { /* look for tag in font directory */ table = TT_LookUp_Table( face, tag ); if ( !table ) { error = TT_Err_Table_Missing; goto Exit; } offset += table->Offset; size = table->Length; } else /* tag == 0 -- the user wants to access the font file directly */ size = face->root.stream->size; if ( length && *length == 0 ) { *length = size; return TT_Err_Ok; } if ( length ) size = *length; stream = face->root.stream; /* the `if' is syntactic sugar for picky compilers */ if ( FILE_Read_At( offset, buffer, size ) ) goto Exit; Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Generic_Header */ /* */ /* <Description> */ /* Loads the TrueType table `head' or `bhed'. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* stream :: The input stream. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ static FT_Error TT_Load_Generic_Header( TT_Face face, FT_Stream stream, FT_ULong tag ) { FT_Error error; TT_Header* header; static const FT_Frame_Field header_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_Header FT_FRAME_START( 54 ), FT_FRAME_ULONG ( Table_Version ), FT_FRAME_ULONG ( Font_Revision ), FT_FRAME_LONG ( CheckSum_Adjust ), FT_FRAME_LONG ( Magic_Number ), FT_FRAME_USHORT( Flags ), FT_FRAME_USHORT( Units_Per_EM ), FT_FRAME_LONG ( Created[0] ), FT_FRAME_LONG ( Created[1] ), FT_FRAME_LONG ( Modified[0] ), FT_FRAME_LONG ( Modified[1] ), FT_FRAME_SHORT ( xMin ), FT_FRAME_SHORT ( yMin ), FT_FRAME_SHORT ( xMax ), FT_FRAME_SHORT ( yMax ), FT_FRAME_USHORT( Mac_Style ), FT_FRAME_USHORT( Lowest_Rec_PPEM ), FT_FRAME_SHORT ( Font_Direction ), FT_FRAME_SHORT ( Index_To_Loc_Format ), FT_FRAME_SHORT ( Glyph_Data_Format ), FT_FRAME_END }; FT_TRACE2(( "TT_Load_Generic_Header: " "%08p, looking up font table `%c%c%c%c'.\n", face, (FT_Char)( tag >> 24 ), (FT_Char)( tag >> 16 ), (FT_Char)( tag >> 8 ), (FT_Char)( tag ) )); error = face->goto_table( face, tag, stream, 0 ); if ( error ) { FT_TRACE2(( "TT_Load_Generic_Table: Font table is missing!\n" )); goto Exit; } header = &face->header; if ( READ_Fields( header_fields, header ) ) goto Exit; FT_TRACE2(( " Units per EM: %8u\n", header->Units_Per_EM )); FT_TRACE2(( " IndexToLoc: %8d\n", header->Index_To_Loc_Format )); FT_TRACE2(( "TT_Load_Generic_Table: Font table loaded.\n" )); Exit: return error; } FT_LOCAL_DEF FT_Error TT_Load_Header( TT_Face face, FT_Stream stream ) { return TT_Load_Generic_Header( face, stream, TTAG_head ); }#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS FT_LOCAL_DEF FT_Error TT_Load_Bitmap_Header( TT_Face face, FT_Stream stream ) { return TT_Load_Generic_Header( face, stream, TTAG_bhed ); }#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_MaxProfile */ /* */ /* <Description> */ /* Loads the maximum profile into a face object. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* stream :: The input stream. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF FT_Error TT_Load_MaxProfile( TT_Face face, FT_Stream stream ) { FT_Error error; TT_MaxProfile* maxProfile = &face->max_profile; const FT_Frame_Field maxp_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_MaxProfile FT_FRAME_START( 32 ), FT_FRAME_ULONG ( version ), FT_FRAME_USHORT( numGlyphs ), FT_FRAME_USHORT( maxPoints ), FT_FRAME_USHORT( maxContours ), FT_FRAME_USHORT( maxCompositePoints ), FT_FRAME_USHORT( maxCompositeContours ), FT_FRAME_USHORT( maxZones ), FT_FRAME_USHORT( maxTwilightPoints ), FT_FRAME_USHORT( maxStorage ), FT_FRAME_USHORT( maxFunctionDefs ), FT_FRAME_USHORT( maxInstructionDefs ), FT_FRAME_USHORT( maxStackElements ), FT_FRAME_USHORT( maxSizeOfInstructions ), FT_FRAME_USHORT( maxComponentElements ), FT_FRAME_USHORT( maxComponentDepth ), FT_FRAME_END }; FT_TRACE2(( "Load_TT_MaxProfile: %08p\n", face )); error = face->goto_table( face, TTAG_maxp, stream, 0 ); if ( error ) goto Exit; if ( READ_Fields( maxp_fields, maxProfile ) ) goto Exit; /* XXX: an adjustment that is necessary to load certain */ /* broken fonts like `Keystrokes MT' :-( */ /* */ /* We allocate 64 function entries by default when */ /* the maxFunctionDefs field is null. */ if ( maxProfile->maxFunctionDefs == 0 ) maxProfile->maxFunctionDefs = 64; face->root.num_glyphs = maxProfile->numGlyphs; face->root.internal->max_points = MAX( maxProfile->maxCompositePoints, maxProfile->maxPoints ); face->root.internal->max_contours = MAX( maxProfile->maxCompositeContours, maxProfile->maxContours ); face->max_components = (FT_ULong)maxProfile->maxComponentElements + maxProfile->maxComponentDepth; /* XXX: some fonts have maxComponents set to 0; we will */ /* then use 16 of them by default. */ if ( face->max_components == 0 ) face->max_components = 16; /* We also increase maxPoints and maxContours in order to support */ /* some broken fonts. */ face->root.internal->max_points += 8; face->root.internal->max_contours += 4; FT_TRACE2(( "MAXP loaded.\n" )); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Metrics */ /* */ /* <Description> */ /* Loads the horizontal or vertical metrics table into a face object. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* stream :: The input stream. */ /* vertical :: A boolean flag. If set, load vertical metrics. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ static FT_Error TT_Load_Metrics( TT_Face face, FT_Stream stream, FT_Bool vertical ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_len; FT_Long num_shorts, num_longs, num_shorts_checked; TT_LongMetrics** longs; TT_ShortMetrics** shorts; FT_TRACE2(( "TT_Load_%s_Metrics: %08p\n", vertical ? "Vertical" : "Horizontal", face )); if ( vertical ) { /* The table is optional, quit silently if it wasn't found */ /* XXX: Some fonts have a valid vertical header with a non-null */ /* `number_of_VMetrics' fields, but no corresponding `vmtx' */ /* table to get the metrics from (e.g. mingliu). */ /* */ /* For safety, we set the field to 0! */ /* */ error = face->goto_table( face, TTAG_vmtx, stream, &table_len ); if ( error ) { /* Set number_Of_VMetrics to 0! */ FT_TRACE2(( " no vertical header in file.\n" )); face->vertical.number_Of_VMetrics = 0; error = TT_Err_Ok; goto Exit; } num_longs = face->vertical.number_Of_VMetrics; longs = (TT_LongMetrics**)&face->vertical.long_metrics; shorts = (TT_ShortMetrics**)&face->vertical.short_metrics; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -