📄 ttload.c
字号:
/* <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. */ /* */ FT_LOCAL_DEF( FT_Error ) tt_face_load_metrics_header( TT_Face face, FT_Stream stream, FT_Bool vertical ) { FT_Error error; TT_HoriHeader* header; const FT_Frame_Field metrics_header_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_HoriHeader FT_FRAME_START( 36 ), FT_FRAME_ULONG ( Version ), FT_FRAME_SHORT ( Ascender ), FT_FRAME_SHORT ( Descender ), FT_FRAME_SHORT ( Line_Gap ), FT_FRAME_USHORT( advance_Width_Max ), FT_FRAME_SHORT ( min_Left_Side_Bearing ), FT_FRAME_SHORT ( min_Right_Side_Bearing ), FT_FRAME_SHORT ( xMax_Extent ), FT_FRAME_SHORT ( caret_Slope_Rise ), FT_FRAME_SHORT ( caret_Slope_Run ), FT_FRAME_SHORT ( caret_Offset ), FT_FRAME_SHORT ( Reserved[0] ), FT_FRAME_SHORT ( Reserved[1] ), FT_FRAME_SHORT ( Reserved[2] ), FT_FRAME_SHORT ( Reserved[3] ), FT_FRAME_SHORT ( metric_Data_Format ), FT_FRAME_USHORT( number_Of_HMetrics ), FT_FRAME_END }; FT_TRACE2(( vertical ? "Vertical header " : "Horizontal header " )); if ( vertical ) { face->vertical_info = 0; /* The vertical header table is optional, so return quietly if */ /* we don't find it. */ error = face->goto_table( face, TTAG_vhea, stream, 0 ); if ( error ) { error = SFNT_Err_Ok; goto Exit; } face->vertical_info = 1; header = (TT_HoriHeader*)&face->vertical; } else { /* The horizontal header is mandatory; return an error if we */ /* don't find it. */ error = face->goto_table( face, TTAG_hhea, stream, 0 ); if ( error ) { error = SFNT_Err_Horiz_Header_Missing; goto Exit; } header = &face->horizontal; } if ( FT_STREAM_READ_FIELDS( metrics_header_fields, header ) ) goto Exit; header->long_metrics = NULL; header->short_metrics = NULL; FT_TRACE2(( "loaded\n" )); /* Now try to load the corresponding metrics */ error = tt_face_load_metrics( face, stream, vertical ); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* tt_face_load_names */ /* */ /* <Description> */ /* Loads the name records. */ /* */ /* <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_face_load_names( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_pos, table_len; FT_ULong storage_start, storage_limit; FT_UInt count; TT_NameTable table; static const FT_Frame_Field name_table_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_NameTableRec FT_FRAME_START( 6 ), FT_FRAME_USHORT( format ), FT_FRAME_USHORT( numNameRecords ), FT_FRAME_USHORT( storageOffset ), FT_FRAME_END }; static const FT_Frame_Field name_record_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_NameEntryRec /* no FT_FRAME_START */ FT_FRAME_USHORT( platformID ), FT_FRAME_USHORT( encodingID ), FT_FRAME_USHORT( languageID ), FT_FRAME_USHORT( nameID ), FT_FRAME_USHORT( stringLength ), FT_FRAME_USHORT( stringOffset ), FT_FRAME_END }; table = &face->name_table; table->stream = stream; FT_TRACE2(( "Names " )); error = face->goto_table( face, TTAG_name, stream, &table_len ); if ( error ) { /* The name table is required so indicate failure. */ FT_TRACE2(( "is missing!\n" )); error = SFNT_Err_Name_Table_Missing; goto Exit; } table_pos = FT_STREAM_POS(); if ( FT_STREAM_READ_FIELDS( name_table_fields, table ) ) goto Exit; /* Some popular Asian fonts have an invalid `storageOffset' value */ /* (it should be at least "6 + 12*num_names"). However, the string */ /* offsets, computed as "storageOffset + entry->stringOffset", are */ /* valid pointers within the name table... */ /* */ /* We thus can't check `storageOffset' right now. */ /* */ storage_start = table_pos + 6 + 12*table->numNameRecords; storage_limit = table_pos + table_len; if ( storage_start > storage_limit ) { FT_ERROR(( "tt_face_load_names: invalid `name' table\n" )); error = SFNT_Err_Name_Table_Missing; goto Exit; } /* Allocate the array of name records. */ count = table->numNameRecords; table->numNameRecords = 0; if ( FT_NEW_ARRAY( table->names, count ) || FT_FRAME_ENTER( count * 12 ) ) goto Exit; /* Load the name records and determine how much storage is needed */ /* to hold the strings themselves. */ { TT_NameEntryRec* entry = table->names; for ( ; count > 0; count-- ) { if ( FT_STREAM_READ_FIELDS( name_record_fields, entry ) ) continue; /* check that the name is not empty */ if ( entry->stringLength == 0 ) continue; /* check that the name string is within the table */ entry->stringOffset += table_pos + table->storageOffset; if ( entry->stringOffset < storage_start || entry->stringOffset + entry->stringLength > storage_limit ) { /* invalid entry - ignore it */ entry->stringOffset = 0; entry->stringLength = 0; continue; } entry++; } table->numNameRecords = (FT_UInt)( entry - table->names ); } FT_FRAME_EXIT(); FT_TRACE2(( "loaded\n" )); /* everything went well, update face->num_names */ face->num_names = (FT_UShort) table->numNameRecords; Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* tt_face_free_names */ /* */ /* <Description> */ /* Frees the name records. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* */ FT_LOCAL_DEF( void ) tt_face_free_names( TT_Face face ) { FT_Memory memory = face->root.driver->root.memory; TT_NameTable table = &face->name_table; TT_NameEntry entry = table->names; FT_UInt count = table->numNameRecords; if ( table->names ) { for ( ; count > 0; count--, entry++ ) { FT_FREE( entry->string ); entry->stringLength = 0; } /* free strings table */ FT_FREE( table->names ); } table->numNameRecords = 0; table->format = 0; table->storageOffset = 0; } /*************************************************************************/ /* */ /* <Function> */ /* tt_face_load_cmap */ /* */ /* <Description> */ /* Loads the cmap directory in a face object. The cmaps itselves are */ /* loaded on demand in the `ttcmap.c' module. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* */ /* stream :: A handle to the input stream. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF( FT_Error ) tt_face_load_cmap( TT_Face face, FT_Stream stream ) { FT_Error error; error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size ); if ( error ) { FT_TRACE2(( "No `cmap' table in font !\n" )); error = SFNT_Err_CMap_Table_Missing; goto Exit; } if ( !FT_FRAME_EXTRACT( face->cmap_size, face->cmap_table ) ) FT_TRACE2(( "`cmap' table loaded\n" )); else { FT_ERROR(( "`cmap' table is too short!\n" )); face->cmap_size = 0; } Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* tt_face_load_os2 */ /* */ /* <Description> */ /* Loads the OS2 table. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* */ /* stream :: A handle to the input stream. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF( FT_Error ) tt_face_load_os2( TT_Face face, FT_Stream stream ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -