📄 ttload.c
字号:
/*************************************************************************/ /* */ /* <Function> */ /* TT_Free_Names */ /* */ /* <Description> */ /* Frees the name records. */ /* */ /* <Input> */ /* face :: A handle to the target face object. */ /* */ FT_LOCAL_DEF( void ) TT_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; 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_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. */ /* */#ifdef FT_CONFIG_OPTION_USE_CMAPS FT_LOCAL_DEF( FT_Error ) TT_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; }#else /* !FT_CONFIG_OPTION_USE_CMAPS */ FT_LOCAL_DEF( FT_Error ) TT_Load_CMap( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_Long table_start; TT_CMapDirRec cmap_dir; const FT_Frame_Field cmap_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_CMapDirRec FT_FRAME_START( 4 ), FT_FRAME_USHORT( tableVersionNumber ), FT_FRAME_USHORT( numCMaps ), FT_FRAME_END }; const FT_Frame_Field cmap_rec_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_CMapTableRec FT_FRAME_START( 4 ), FT_FRAME_USHORT( format ), FT_FRAME_USHORT( length ), FT_FRAME_END }; FT_TRACE2(( "CMaps " )); error = face->goto_table( face, TTAG_cmap, stream, 0 ); if ( error ) { error = SFNT_Err_CMap_Table_Missing; goto Exit; } table_start = FT_STREAM_POS(); if ( FT_STREAM_READ_FIELDS( cmap_fields, &cmap_dir ) ) goto Exit; /* reserve space in face table for cmap tables */ if ( FT_NEW_ARRAY( face->charmaps, cmap_dir.numCMaps ) ) goto Exit; face->num_charmaps = cmap_dir.numCMaps; { TT_CharMap charmap = face->charmaps; TT_CharMap limit = charmap + face->num_charmaps; /* read the header of each charmap first */ if ( FT_FRAME_ENTER( face->num_charmaps * 8L ) ) goto Exit; for ( ; charmap < limit; charmap++ ) { TT_CMapTable cmap; charmap->root.face = (FT_Face)face; cmap = &charmap->cmap; cmap->loaded = FALSE; cmap->platformID = FT_GET_USHORT(); cmap->platformEncodingID = FT_GET_USHORT(); cmap->offset = (FT_ULong)FT_GET_LONG(); } FT_FRAME_EXIT(); /* now read the rest of each table */ for ( charmap = face->charmaps; charmap < limit; charmap++ ) { TT_CMapTable cmap = &charmap->cmap; if ( FT_STREAM_SEEK( table_start + (FT_Long)cmap->offset ) || FT_STREAM_READ_FIELDS( cmap_rec_fields, cmap ) ) goto Exit; cmap->offset = FT_STREAM_POS(); } } FT_TRACE2(( "loaded\n" )); Exit: return error; }#endif /* !FT_CONFIG_OPTION_USE_CMAPS */ /*************************************************************************/ /* */ /* <Function> */ /* TT_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_Load_OS2( TT_Face face, FT_Stream stream ) { FT_Error error; TT_OS2* os2; const FT_Frame_Field os2_fields[] = {#undef FT_STRUCTURE#define FT_STRUCTURE TT_OS2 FT_FRAME_START( 78 ), FT_FRAME_USHORT( version ), FT_FRAME_SHORT ( xAvgCharWidth ), FT_FRAME_USHORT( usWeightClass ), FT_FRAME_USHORT( usWidthClass ), FT_FRAME_SHORT ( fsType ), FT_FRAME_SHORT ( ySubscriptXSize ), FT_FRAME_SHORT ( ySubscriptYSize ), FT_FRAME_SHORT ( ySubscriptXOffset ), FT_FRAME_SHORT ( ySubscriptYOffset ), FT_FRAME_SHORT ( ySuperscriptXSize ), FT_FRAME_SHORT ( ySuperscriptYSize ), FT_FRAME_SHORT ( ySuperscriptXOffset ), FT_FRAME_SHORT ( ySuperscriptYOffset ), FT_FRAME_SHORT ( yStrikeoutSize ), FT_FRAME_SHORT ( yStrikeoutPosition ), FT_FRAME_SHORT ( sFamilyClass ), FT_FRAME_BYTE ( panose[0] ), FT_FRAME_BYTE ( panose[1] ), FT_FRAME_BYTE ( panose[2] ), FT_FRAME_BYTE ( panose[3] ), FT_FRAME_BYTE ( panose[4] ), FT_FRAME_BYTE ( panose[5] ), FT_FRAME_BYTE ( panose[6] ), FT_FRAME_BYTE ( panose[7] ), FT_FRAME_BYTE ( panose[8] ), FT_FRAME_BYTE ( panose[9] ), FT_FRAME_ULONG ( ulUnicodeRange1 ), FT_FRAME_ULONG ( ulUnicodeRange2 ), FT_FRAME_ULONG ( ulUnicodeRange3 ), FT_FRAME_ULONG ( ulUnicodeRange4 ), FT_FRAME_BYTE ( achVendID[0] ), FT_FRAME_BYTE ( achVendID[1] ), FT_FRAME_BYTE ( achVendID[2] ), FT_FRAME_BYTE ( achVendID[3] ), FT_FRAME_USHORT( fsSelection ), FT_FRAME_USHORT( usFirstCharIndex ), FT_FRAME_USHORT( usLastCharIndex ), FT_FRAME_SHORT ( sTypoAscender ), FT_FRAME_SHORT ( sTypoDescender ), FT_FRAME_SHORT ( sTypoLineGap ), FT_FRAME_USHORT( usWinAscent ), FT_FRAME_USHORT( usWinDescent ), FT_FRAME_END }; const FT_Frame_Field os2_fields_extra[] = { FT_FRAME_START( 8 ), FT_FRAME_ULONG( ulCodePageRange1 ), FT_FRAME_ULONG( ulCodePageRange2 ), FT_FRAME_END }; const FT_Frame_Field os2_fields_extra2[] = { FT_FRAME_START( 10 ), FT_FRAME_SHORT ( sxHeight ), FT_FRAME_SHORT ( sCapHeight ), FT_FRAME_USHORT( usDefaultChar ), FT_FRAME_USHORT( usBreakChar ), FT_FRAME_USHORT( usMaxContext ), FT_FRAME_END }; FT_TRACE2(( "OS/2 Table " )); /* We now support old Mac fonts where the OS/2 table doesn't */ /* exist. Simply put, we set the `version' field to 0xFFFF */ /* and test this value each time we need to access the table. */ error = face->goto_table( face, TTAG_OS2, stream, 0 ); if ( error ) { FT_TRACE2(( "is missing!\n" )); face->os2.version = 0xFFFFU; error = SFNT_Err_Ok; goto Exit; } os2 = &face->os2; if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) ) goto Exit; os2->ulCodePageRange1 = 0; os2->ulCodePageRange2 = 0; os2->sxHeight = 0; os2->sCapHeight = 0; os2->usDefaultChar = 0; os2->usBreakChar = 0; os2->usMaxContext = 0; if ( os2->version >= 0x0001 ) { /* only version 1 tables */ if ( FT_STREAM_READ_FIELDS( os2_fields_extra, os2 ) ) goto Exit; if ( os2->version >= 0x0002 ) { /* only version 2 tables */ if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) ) goto Exit; } } FT_TRACE2(( "loaded\n" )); Exit: return error; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Load_Postscript */ /* */ /* <Description> */ /* Loads the Postscript 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_PostScript( TT_Face face, FT_Stream stream ) { FT_Error error; TT_Postscript* post = &face->postscript; static const FT_Frame_Field post_fields[] =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -