📄 ttpost.c
字号:
Fail: FREE( name_strings ); FREE( glyph_indices ); Exit: return error; } static FT_Error Load_Format_25( TT_Face face, FT_Stream stream ) { FT_Memory memory = stream->memory; FT_Error error; FT_Int num_glyphs; FT_Char* offset_table = 0; /* UNDOCUMENTED! This value appears only in the Apple TT specs. */ if ( READ_UShort( num_glyphs ) ) goto Exit; /* check the number of glyphs */ if ( num_glyphs > face->root.num_glyphs || num_glyphs > 258 ) { error = TT_Err_Invalid_File_Format; goto Exit; } if ( ALLOC ( offset_table, num_glyphs ) || FILE_Read( offset_table, num_glyphs ) ) goto Fail; /* now check the offset table */ { FT_Int n; for ( n = 0; n < num_glyphs; n++ ) { FT_Long index = (FT_Long)n + offset_table[n]; if ( index < 0 || index > num_glyphs ) { error = TT_Err_Invalid_File_Format; goto Fail; } } } /* OK, set table fields and exit successfuly */ { TT_Post_25* table = &face->postscript_names.names.format_25; table->num_glyphs = num_glyphs; table->offsets = offset_table; } return TT_Err_Ok; Fail: FREE( offset_table ); Exit: return error; } static FT_Error Load_Post_Names( TT_Face face ) { FT_Stream stream; FT_Error error; FT_Fixed format; /* get a stream for the face's resource */ stream = face->root.stream; /* seek to the beginning of the PS names table */ error = face->goto_table( face, TTAG_post, stream, 0 ); if ( error ) goto Exit; format = face->postscript.FormatType; /* go to beginning of subtable */ if ( FILE_Skip( 32 ) ) goto Exit; /* now read postscript table */ switch ( format ) { case 0x00020000L: error = Load_Format_20( face, stream ); break; case 0x00028000L: error = Load_Format_25( face, stream ); break; default: error = TT_Err_Invalid_File_Format; } face->postscript_names.loaded = 1; Exit: return error; } FT_LOCAL_DEF void TT_Free_Post_Names( TT_Face face ) { FT_Memory memory = face->root.memory; TT_Post_Names* names = &face->postscript_names; if ( names->loaded ) { switch ( face->postscript.FormatType ) { case 0x00020000L: { TT_Post_20* table = &names->names.format_20; FT_UShort n; FREE( table->glyph_indices ); table->num_glyphs = 0; for ( n = 0; n < table->num_names; n++ ) FREE( table->glyph_names[n] ); FREE( table->glyph_names ); table->num_names = 0; } break; case 0x00028000L: { TT_Post_25* table = &names->names.format_25; FREE( table->offsets ); table->num_glyphs = 0; } break; } } names->loaded = 0; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Get_PS_Name */ /* */ /* <Description> */ /* Gets the PostScript glyph name of a glyph. */ /* */ /* <Input> */ /* face :: A handle to the parent face. */ /* */ /* index :: The glyph index. */ /* */ /* PSname :: The address of a string pointer. Will be NULL in case */ /* of error, otherwise it is a pointer to the glyph name. */ /* */ /* You must not modify the returned string! */ /* */ /* <Output> */ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF FT_Error TT_Get_PS_Name( TT_Face face, FT_UInt index, FT_String** PSname ) { FT_Error error; TT_Post_Names* names;#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES PSNames_Interface* psnames;#endif if ( !face ) return TT_Err_Invalid_Face_Handle; if ( index >= (FT_UInt)face->root.num_glyphs ) return TT_Err_Invalid_Glyph_Index;#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES psnames = (PSNames_Interface*)face->psnames; if ( !psnames ) return TT_Err_Unimplemented_Feature;#endif names = &face->postscript_names; /* `.notdef' by default */ *PSname = MAC_NAME( 0 ); switch ( face->postscript.FormatType ) { case 0x00010000L: if ( index < 258 ) /* paranoid checking */ *PSname = MAC_NAME( index ); break; case 0x00020000L: { TT_Post_20* table = &names->names.format_20; if ( !names->loaded ) { error = Load_Post_Names( face ); if ( error ) break; } if ( index < (FT_UInt)table->num_glyphs ) { FT_UShort name_index = table->glyph_indices[index]; if ( name_index < 258 ) *PSname = MAC_NAME( name_index ); else *PSname = (FT_String*)table->glyph_names[name_index - 258]; } } break; case 0x00028000L: { TT_Post_25* table = &names->names.format_25; if ( !names->loaded ) { error = Load_Post_Names( face ); if ( error ) break; } if ( index < (FT_UInt)table->num_glyphs ) /* paranoid checking */ { index += table->offsets[index]; *PSname = MAC_NAME( index ); } } break; case 0x00030000L: break; /* nothing to do */ } return TT_Err_Ok; }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -