📄 ttload.c
字号:
/* Loads any font table into client memory. Used by the */ /* TT_Get_Font_Data() API function. */ /* */ /* <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> */ /* TrueType error code. 0 means success. */ /* */ LOCAL_FUNC TT_Error TT_Load_Any( TT_Face face, TT_ULong tag, TT_Long offset, void* buffer, TT_Long* length ) { TT_Error error; FT_Stream stream; TT_Table* table; TT_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 use want 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; (void)FILE_Read_At( offset, buffer, size ); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Header */ /* */ /* <Description> */ /* Loads the TrueType font header. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* stream :: The input stream. */ /* */ /* <Return> */ /* TrueType error code. 0 means success. */ /* */ LOCAL_FUNC TT_Error TT_Load_Header( TT_Face face, FT_Stream stream ) { TT_Error error; TT_Header* header;#ifdef READ_FIELDS const FT_Frame_Field header_fields[] = { { ft_frame_start, 0, 54 }, FT_FRAME_ULONG( TT_Header, Table_Version ), FT_FRAME_ULONG( TT_Header, Font_Revision ), FT_FRAME_LONG( TT_Header, CheckSum_Adjust ), FT_FRAME_LONG( TT_Header, Magic_Number ), FT_FRAME_USHORT( TT_Header, Flags ), FT_FRAME_USHORT( TT_Header, Units_Per_EM ), FT_FRAME_LONG( TT_Header, Created[0] ), FT_FRAME_LONG( TT_Header, Created[1] ), FT_FRAME_LONG( TT_Header, Modified[0] ), FT_FRAME_LONG( TT_Header, Modified[1] ), FT_FRAME_SHORT( TT_Header, xMin ), FT_FRAME_SHORT( TT_Header, yMin ), FT_FRAME_SHORT( TT_Header, xMax ), FT_FRAME_SHORT( TT_Header, yMax ), FT_FRAME_USHORT( TT_Header, Mac_Style ), FT_FRAME_USHORT( TT_Header, Lowest_Rec_PPEM ), FT_FRAME_SHORT( TT_Header, Font_Direction ), FT_FRAME_SHORT( TT_Header, Index_To_Loc_Format ), FT_FRAME_SHORT( TT_Header, Glyph_Data_Format ), { ft_frame_end } };#endif FT_TRACE2(( "Load_TT_Header( %08lx )\n", (TT_Long)face )); error = face->goto_table( face, TTAG_head, stream, 0 ); if ( error ) { FT_TRACE0(( "Font Header is missing!\n" )); goto Exit; } header = &face->header;#ifdef READ_FIELDS if ( READ_Fields( header_fields, header ) ) goto Exit;#else if ( ACCESS_Frame( 54L ) ) goto Exit; header->Table_Version = GET_ULong(); header->Font_Revision = GET_ULong(); header->CheckSum_Adjust = GET_Long(); header->Magic_Number = GET_Long(); header->Flags = GET_UShort(); header->Units_Per_EM = GET_UShort(); header->Created [0] = GET_Long(); header->Created [1] = GET_Long(); header->Modified[0] = GET_Long(); header->Modified[1] = GET_Long(); header->xMin = GET_Short(); header->yMin = GET_Short(); header->xMax = GET_Short(); header->yMax = GET_Short(); header->Mac_Style = GET_UShort(); header->Lowest_Rec_PPEM = GET_UShort(); header->Font_Direction = GET_Short(); header->Index_To_Loc_Format = GET_Short(); header->Glyph_Data_Format = GET_Short(); FORGET_Frame();#endif FT_TRACE2(( " Units per EM : %8u\n", header->Units_Per_EM )); FT_TRACE2(( " IndexToLoc : %8d\n", header->Index_To_Loc_Format )); FT_TRACE2(( "Font Header Loaded.\n" )); Exit: return error; } /*************************************************************************/ /* */ /* <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> */ /* TrueType error code. 0 means success. */ /* */ LOCAL_FUNC TT_Error TT_Load_MaxProfile( TT_Face face, FT_Stream stream ) { TT_Error error; TT_MaxProfile* maxProfile = &face->max_profile;#ifdef READ_FIELDS const FT_Frame_Field maxp_fields[] = { { ft_frame_start, 0, 32 }, FT_FRAME_ULONG( TT_MaxProfile, version ), FT_FRAME_USHORT( TT_MaxProfile, numGlyphs ), FT_FRAME_USHORT( TT_MaxProfile, maxPoints ), FT_FRAME_USHORT( TT_MaxProfile, maxContours ), FT_FRAME_USHORT( TT_MaxProfile, maxCompositePoints ), FT_FRAME_USHORT( TT_MaxProfile, maxCompositeContours ), FT_FRAME_USHORT( TT_MaxProfile, maxZones ), FT_FRAME_USHORT( TT_MaxProfile, maxTwilightPoints ), FT_FRAME_USHORT( TT_MaxProfile, maxStorage ), FT_FRAME_USHORT( TT_MaxProfile, maxFunctionDefs ), FT_FRAME_USHORT( TT_MaxProfile, maxInstructionDefs ), FT_FRAME_USHORT( TT_MaxProfile, maxStackElements ), FT_FRAME_USHORT( TT_MaxProfile, maxSizeOfInstructions ), FT_FRAME_USHORT( TT_MaxProfile, maxComponentElements ), FT_FRAME_USHORT( TT_MaxProfile, maxComponentDepth ), { ft_frame_end } };#endif FT_TRACE2(( "Load_TT_MaxProfile( %08lx )\n", (TT_Long)face )); error = face->goto_table( face, TTAG_maxp, stream, 0 ); if (error) goto Exit;#ifdef READ_FIELDS if ( READ_Fields( maxp_fields, maxProfile ) ) goto Exit;#else if ( ACCESS_Frame( 32L ) ) goto Exit; /* read frame data into face table */ maxProfile->version = GET_ULong(); maxProfile->numGlyphs = GET_UShort(); maxProfile->maxPoints = GET_UShort(); maxProfile->maxContours = GET_UShort(); maxProfile->maxCompositePoints = GET_UShort(); maxProfile->maxCompositeContours = GET_UShort(); maxProfile->maxZones = GET_UShort(); maxProfile->maxTwilightPoints = GET_UShort(); maxProfile->maxStorage = GET_UShort(); maxProfile->maxFunctionDefs = GET_UShort(); maxProfile->maxInstructionDefs = GET_UShort(); maxProfile->maxStackElements = GET_UShort(); maxProfile->maxSizeOfInstructions = GET_UShort(); maxProfile->maxComponentElements = GET_UShort(); maxProfile->maxComponentDepth = GET_UShort(); FORGET_Frame();#endif /* 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.max_points = MAX( maxProfile->maxCompositePoints, maxProfile->maxPoints ); face->root.max_contours = MAX( maxProfile->maxCompositeContours, maxProfile->maxContours ); face->max_components = (TT_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.max_points += 8; face->root.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> */ /* TrueType error code. 0 means success. */ /* */ static TT_Error TT_Load_Metrics( TT_Face face, FT_Stream stream, TT_Bool vertical ) { TT_Error error; FT_Memory memory = stream->memory; TT_ULong table_len; TT_Long num_shorts, num_longs, num_shorts_checked; TT_LongMetrics** longs; TT_ShortMetrics** shorts; FT_TRACE2(( "TT_Load_%s_Metrics( %08lx )\n", vertical ? "Vertical" : "Horizontal", (TT_Long)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). */ /* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -