From 01585e5cbe07a9cf59a25fc9b509ec06b9f03e71 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 26 Mar 2002 12:51:49 +0000 Subject: * src/sfnt/sfobjs.c (Get_Name): improved the routine in charge of retrieving the english name of a font --- ChangeLog | 5 ++ src/sfnt/sfobjs.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) diff --git a/ChangeLog b/ChangeLog index 015aead33..903d74eed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-03-26 David Turner + + * src/sfnt/sfobjs.c (Get_Name): improved the routine in charge of + retrieving the english name of a font + 2002-03-25 David Turner * src/base/fttrigon.c, src/truetype/ttinterp.c: fixing the TrueType diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 9d54b7690..5108877b3 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -37,6 +37,233 @@ #define FT_COMPONENT trace_sfobjs +#if 1 + + /* convert a UTF-16 name entry to ASCII */ + static FT_String* + tt_name_entry_ascii_from_utf16( TT_NameRec* entry, + FT_Memory memory ) + { + FT_String* string; + FT_UInt len, code, n; + FT_Byte* read = (FT_Byte*) entry->string; + FT_Error error; + + len = (FT_UInt) entry->stringLength/2; + + if ( ALLOC( string, len+1 ) ) + return NULL; + + for ( n = 0; n < len; n++ ) + { + code = NEXT_UShort(read); + if ( code < 32 || code > 127 ) + code = '?'; + + string[n] = (char)code; + } + + string[len] = 0; + + return string; + } + + + /* convert a UCS-4 name entry to ASCII */ + static FT_String* + tt_name_entry_ascii_from_ucs4( TT_NameRec* entry, + FT_Memory memory ) + { + FT_String* string; + FT_UInt len, code, n; + FT_Byte* read = (FT_Byte*) entry->string; + FT_Error error; + + len = (FT_UInt) entry->stringLength/4; + + if ( ALLOC( string, len+1 ) ) + return NULL; + + for ( n = 0; n < len; n++ ) + { + code = NEXT_ULong(read); + if ( code < 32 || code > 127 ) + code = '?'; + + string[n] = (char)code; + } + + string[len] = 0; + + return string; + } + + + /* convert an Apple Roman or symbol name entry to ASCII */ + static FT_String* + tt_name_entry_ascii_from_other( TT_NameRec* entry, + FT_Memory memory ) + { + FT_String* string; + FT_UInt len, code, n; + FT_Byte* read = (FT_Byte*) entry->string; + FT_Error error; + + len = (FT_UInt) entry->stringLength; + + if ( ALLOC( string, len+1 ) ) + return NULL; + + for ( n = 0; n < len; n++ ) + { + code = *read++; + if ( code < 32 || code > 127 ) + code = '?'; + + string[n] = (char)code; + } + + string[len] = 0; + + return string; + } + + + /*************************************************************************/ + /* */ + /* */ + /* tt_face_get_name */ + /* */ + /* */ + /* Returns a given ENGLISH name record in ASCII. */ + /* */ + /* */ + /* face :: A handle to the source face object. */ + /* */ + /* nameid :: The name id of the name record to return. */ + /* */ + /* */ + /* Character string. NULL if no name is present. */ + /* */ + static FT_String* + Get_Name( TT_Face face, + FT_UShort nameid ) + { + FT_Memory memory = face->root.memory; + FT_String* result = NULL; + FT_UShort n; + TT_NameRec* rec; + FT_Int found_apple = -1; + FT_Int found_win = -1; + FT_Int found_unicode = -1; + + + rec = face->name_table.names; + for ( n = 0; n < face->name_table.numNameRecords; n++, rec++ ) + { + /* according to the OpenType 1.3 specification, only Microsoft of */ + /* Apple platform ids might be used in the 'name' table. The */ + /* 'Unicode' platform is reserved for the 'cmap' table, and */ + /* the 'Iso' one is deprecated */ + + /* however the Apple TrueType specification doesn't says the same */ + /* thing and goes to suggest that all Unicode 'name' table entries */ + /* should be coded in UTF-16 (in big-endian format I suppose) */ + /* */ + if ( rec->nameID == nameid && rec->string ) + { + switch ( rec->platformID ) + { + + case TT_PLATFORM_APPLE_UNICODE: + case TT_PLATFORM_ISO: + { + /* there is 'languageID' to check there. We should use this */ + /* field only as a last solution when nothing else is */ + /* available.. */ + /* */ + found_unicode = n; + break; + } + + case TT_PLATFORM_MACINTOSH: + { + if ( rec->languageID == TT_MAC_LANGID_ENGLISH ) + found_apple = n; + + break; + } + + case TT_PLATFORM_MICROSOFT: + { + if ( (rec->languageID & 0x3FF) == 0x009 ) + { + switch ( rec->encodingID ) + { + case TT_MS_ID_SYMBOL_CS: + case TT_MS_ID_UNICODE_CS: + case TT_MS_ID_UCS_4: + found_win = n; + break; + + default: + ; + } + } + break; + } + + default: + ; + } + } + } + + /* some fonts contain invalid Unicode or Macintosh formatted entries */ + /* we will thus favor name encoded in Windows formats when they're */ + /* available.. */ + /* */ + if ( found_win >= 0 ) + { + rec = face->name_table.names + found_win; + switch ( rec->encodingID ) + { + case TT_MS_ID_UNICODE_CS: + { + result = tt_name_entry_ascii_from_utf16( rec, memory ); + break; + } + + case TT_MS_ID_SYMBOL_CS: + { + result = tt_name_entry_ascii_from_other( rec, memory ); + break; + } + + case TT_MS_ID_UCS_4: + { + result = tt_name_entry_ascii_from_ucs4( rec, memory ); + break; + } + } + } + else if ( found_apple >= 0 ) + { + rec = face->name_table.names + found_apple; + result = tt_name_entry_ascii_from_other( rec, memory ); + } + else if ( found_unicode >= 0 ) + { + rec = face->name_table.names + found_unicode; + result = tt_name_entry_ascii_from_utf16( rec, memory ); + } + + return result; + } + + +#else /* 0 */ + /*************************************************************************/ /* */ /* */ @@ -153,6 +380,8 @@ return NULL; } +#endif /* 0 */ + static FT_Encoding find_encoding( int platform_id, -- cgit v1.2.1