📄 ttload.c
字号:
/* <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_Load_PCLT( TT_Face face, FT_Stream stream ) { static const FT_Frame_Field pclt_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_PCLT FT_FRAME_START( 54 ), FT_FRAME_ULONG ( Version ), FT_FRAME_ULONG ( FontNumber ), FT_FRAME_USHORT( Pitch ), FT_FRAME_USHORT( xHeight ), FT_FRAME_USHORT( Style ), FT_FRAME_USHORT( TypeFamily ), FT_FRAME_USHORT( CapHeight ), FT_FRAME_BYTES ( TypeFace, 16 ), FT_FRAME_BYTES ( CharacterComplement, 8 ), FT_FRAME_BYTES ( FileName, 6 ), FT_FRAME_CHAR ( StrokeWeight ), FT_FRAME_CHAR ( WidthType ), FT_FRAME_BYTE ( SerifStyle ), FT_FRAME_BYTE ( Reserved ), FT_FRAME_END }; FT_Error error; TT_PCLT* pclt = &face->pclt; FT_TRACE2(( "PCLT " )); /* optional table */ error = face->goto_table( face, TTAG_PCLT, stream, 0 ); if ( error ) { FT_TRACE2(( "missing (optional)\n" )); pclt->Version = 0; return TT_Err_Ok; } if ( READ_Fields( pclt_fields, pclt ) ) goto Exit; FT_TRACE2(( "loaded\n" )); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Gasp */ /* */ /* <Description> */ /* Loads the `gasp' table 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_Gasp( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_UInt j,num_ranges; TT_GaspRange* gaspranges; FT_TRACE2(( "TT_Load_Gasp: %08p\n", face )); /* the gasp table is optional */ error = face->goto_table( face, TTAG_gasp, stream, 0 ); if ( error ) return TT_Err_Ok; if ( ACCESS_Frame( 4L ) ) goto Exit; face->gasp.version = GET_UShort(); face->gasp.numRanges = GET_UShort(); FORGET_Frame(); num_ranges = face->gasp.numRanges; FT_TRACE3(( "number of ranges = %d\n", num_ranges )); if ( ALLOC_ARRAY( gaspranges, num_ranges, TT_GaspRange ) || ACCESS_Frame( num_ranges * 4L ) ) goto Exit; face->gasp.gaspRanges = gaspranges; for ( j = 0; j < num_ranges; j++ ) { gaspranges[j].maxPPEM = GET_UShort(); gaspranges[j].gaspFlag = GET_UShort(); FT_TRACE3(( " [max:%d flag:%d]", gaspranges[j].maxPPEM, gaspranges[j].gaspFlag )); } FT_TRACE3(( "\n" )); FORGET_Frame(); FT_TRACE2(( "GASP loaded\n" )); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Kern */ /* */ /* <Description> */ /* Loads the first kerning table with format 0 in the font. Only */ /* accepts the first horizontal kerning table. Developers should use */ /* the `ftxkern' extension to access other kerning tables in the font */ /* file, if they really want to. */ /* */ /* <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_Kern( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_UInt n, num_tables, version; /* the kern table is optional; exit silently if it is missing */ error = face->goto_table( face, TTAG_kern, stream, 0 ); if ( error ) return TT_Err_Ok; if ( ACCESS_Frame( 4L ) ) goto Exit; version = GET_UShort(); num_tables = GET_UShort(); FORGET_Frame(); for ( n = 0; n < num_tables; n++ ) { FT_UInt coverage; FT_UInt length; if ( ACCESS_Frame( 6L ) ) goto Exit; version = GET_UShort(); /* version */ length = GET_UShort() - 6; /* substract header length */ coverage = GET_UShort(); FORGET_Frame(); if ( coverage == 0x0001 ) { FT_UInt num_pairs; TT_Kern_0_Pair* pair; TT_Kern_0_Pair* limit; /* found a horizontal format 0 kerning table! */ if ( ACCESS_Frame( 8L ) ) goto Exit; num_pairs = GET_UShort(); /* skip the rest */ FORGET_Frame(); /* allocate array of kerning pairs */ if ( ALLOC_ARRAY( face->kern_pairs, num_pairs, TT_Kern_0_Pair ) || ACCESS_Frame( 6L * num_pairs ) ) goto Exit; pair = face->kern_pairs; limit = pair + num_pairs; for ( ; pair < limit; pair++ ) { pair->left = GET_UShort(); pair->right = GET_UShort(); pair->value = GET_UShort(); } FORGET_Frame(); face->num_kern_pairs = num_pairs; face->kern_table_index = n; goto Exit; } if ( FILE_Skip( length ) ) goto Exit; } /* no kern table found -- doesn't matter */ face->kern_table_index = -1; face->num_kern_pairs = 0; face->kern_pairs = NULL; Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Hdmx */ /* */ /* <Description> */ /* Loads the horizontal device metrics 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_Load_Hdmx( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; TT_Hdmx* hdmx = &face->hdmx; FT_Long num_glyphs; FT_Long record_size; hdmx->version = 0; hdmx->num_records = 0; hdmx->records = 0; /* this table is optional */ error = face->goto_table( face, TTAG_hdmx, stream, 0 ); if ( error ) return TT_Err_Ok; if ( ACCESS_Frame( 8L ) ) goto Exit; hdmx->version = GET_UShort(); hdmx->num_records = GET_Short(); record_size = GET_Long(); FORGET_Frame(); /* Only recognize format 0 */ if ( hdmx->version != 0 ) goto Exit; if ( ALLOC_ARRAY( hdmx->records, hdmx->num_records, TT_HdmxRec ) ) goto Exit; num_glyphs = face->root.num_glyphs; record_size -= num_glyphs + 2; { TT_HdmxRec* cur = hdmx->records; TT_HdmxRec* limit = cur + hdmx->num_records; for ( ; cur < limit; cur++ ) { /* read record */ if ( READ_Byte( cur->ppem ) || READ_Byte( cur->max_width ) ) goto Exit; if ( ALLOC( cur->widths, num_glyphs ) || FILE_Read( cur->widths, num_glyphs ) ) goto Exit; /* skip padding bytes */ if ( record_size > 0 && FILE_Skip( record_size ) ) goto Exit; } } Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Free_Hdmx */ /* */ /* <Description> */ /* Frees the horizontal device metrics table. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* */ FT_LOCAL_DEF void TT_Free_Hdmx( TT_Face face ) { if ( face ) { FT_Int n; FT_Memory memory = face->root.driver->root.memory; for ( n = 0; n < face->hdmx.num_records; n++ ) FREE( face->hdmx.records[n].widths ); FREE( face->hdmx.records ); face->hdmx.num_records = 0; } }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -