From 23bcde193e64dfae54a1c51dacad2a86d7a5f028 Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 17 Oct 2001 13:48:10 +0000 Subject: [PATCH] implementing a new function named "FT_Get_Postscript_Name" to retrieve a face's "unique" Postscript name --- ChangeLog | 8 +++-- include/freetype/freetype.h | 24 ++++++++++++++ include/freetype/internal/ftobjs.h | 17 +++++++--- src/base/ftobjs.c | 42 +++++++++++++++++++++++-- src/cid/cidriver.c | 12 +++++++ src/sfnt/sfdriver.c | 50 ++++++++++++++++++++++++++++++ src/type1/t1driver.c | 10 ++++++ 7 files changed, 153 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 717ecee5c..4a769a773 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,11 @@ 2001-10-17 David Turner >david@freetype.org> - Tagging files with VER-2-0-5 for upcoming 2.0.5 release - Testing new CVS-mail script (thanks Just !) + * include/freetype/freetype.h, include/internal/ftobjs.h, + src/base/ftobjs.c, src/sfnt/sfdriver.c, type1/t1driver.c, + cid/cidriver.c: Adding a new function named 'FT_Get_Postscript_Name' to + retrieve the Postscript name of a given font. Should work with all + formats except pure CFF/CEF fonts (this will be added soon). + 2001-10-08 David Turner diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index 2524f8b64..41d6f609e 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -2286,6 +2286,30 @@ FT_BEGIN_HEADER FT_UInt buffer_max ); + /*************************************************************************/ + /* */ + /* */ + /* FT_Get_Postscript_Name */ + /* */ + /* */ + /* Retrieves the ASCII Postscript name of a given face, when */ + /* available. This should only work with Postscript and TrueType */ + /* fonts.. */ + /* */ + /* */ + /* face :: handle to source face object. */ + /* */ + /* */ + /* pointer to face's Postscript name. NULL when un-available */ + /* */ + /* */ + /* The returned pointer is owned by the face and will be destroyed */ + /* with it. */ + /* */ + FT_EXPORT( const char* ) + FT_Get_Postscript_Name( FT_Face face ); + + /*************************************************************************/ /* */ /* */ diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index f316efe08..9608ace28 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -129,14 +129,18 @@ FT_BEGIN_HEADER /* transform_flags :: Some flags used to classify the transform. */ /* Only used by the convenience functions. */ /* */ + /* postscript_name :: Postscript font name for this face. */ + /* */ typedef struct FT_Face_InternalRec_ { - FT_UShort max_points; - FT_Short max_contours; + FT_UShort max_points; + FT_Short max_contours; - FT_Matrix transform_matrix; - FT_Vector transform_delta; - FT_Int transform_flags; + FT_Matrix transform_matrix; + FT_Vector transform_delta; + FT_Int transform_flags; + + const char* postscript_name; } FT_Face_InternalRec; @@ -628,6 +632,9 @@ FT_BEGIN_HEADER FT_GlyphSlot slot, FT_UInt render_mode ); + typedef const char* + (*FT_PSName_Requester)( FT_Face face ); + typedef FT_Error (*FT_Glyph_Name_Requester)( FT_Face face, FT_UInt glyph_index, diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 226a7c8f5..b4ec9b6d1 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -1011,8 +1011,8 @@ if ( face->autohint.finalizer ) face->autohint.finalizer( face->autohint.data ); - /* Discard glyph slots for this face */ - /* Beware! FT_Done_GlyphSlot() changes the field `face->slot' */ + /* Discard glyph slots for this face */ + /* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */ while ( face->glyph ) FT_Done_GlyphSlot( face->glyph ); @@ -1037,7 +1037,11 @@ ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 ); /* get rid of it */ - FREE( face->internal ); + if ( face->internal ) + { + FREE( face->internal->postscript_name ); + FREE( face->internal ); + } FREE( face ); } @@ -1906,6 +1910,38 @@ } + /* documentation is in freetype.h */ + + FT_EXPORT_DEF( const char* ) + FT_Get_Postscript_Name( FT_Face face ) + { + const char* result = NULL; + + if ( !face ) + goto Exit; + + result = face->internal->postscript_name; + if ( !result ) + { + /* now, lookup for glyph name */ + FT_Driver driver = face->driver; + FT_Module_Class* clazz = FT_MODULE_CLASS( driver ); + + if ( clazz->get_interface ) + { + FT_PSName_Requester requester; + + requester = (FT_PSName_Requester)clazz->get_interface( + FT_MODULE( driver ), "postscript_name" ); + if ( requester ) + result = requester( face ); + } + } + Exit: + return result; + } + + /* documentation is in tttables.h */ FT_EXPORT_DEF( void* ) diff --git a/src/cid/cidriver.c b/src/cid/cidriver.c index 33a39d81b..8de7852b1 100644 --- a/src/cid/cidriver.c +++ b/src/cid/cidriver.c @@ -38,6 +38,14 @@ #define FT_COMPONENT trace_ciddriver + + static const char* + cid_get_postscript_name( CID_Face face ) + { + return (const char*)face->cid.cid_font_name; + } + + static FT_Module_Interface CID_Get_Interface( FT_Driver driver, const FT_String* interface ) @@ -45,6 +53,9 @@ FT_UNUSED( driver ); FT_UNUSED( interface ); + if ( strcmp( (const char*)interface, "postscript_name" ) == 0 ) + return (FT_Module_Interface)cid_get_postscript_name; + return 0; } @@ -174,6 +185,7 @@ } + FT_CALLBACK_TABLE_DEF const FT_Driver_Class t1cid_driver_class = { diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index 086bcccc4..31045640f 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -111,6 +111,52 @@ } + static const char* + get_sfnt_postscript_name( TT_Face face ) + { + FT_Int n; + + /* shouldn't happen, but just in case to avoid memory leaks */ + if ( face->root.internal->postscript_name ) + return face->root.internal->postscript_name; + + /* scan the name table to see if we have a Postscript name here, either */ + /* in Macintosh or Windows platform encodings.. */ + for ( n = 0; n < face->num_names; n++ ) + { + TT_NameRec* name = face->name_table.names + n; + + if ( name->nameID == 6 ) + { + if ( ( name->platformID == 3 && + name->encodingID == 1 && + name->languageID == 0x409 ) || + + ( name->platformID == 1 && + name->encodingID == 0 && + name->languageID == 0 ) ) + { + FT_UInt len = name->stringLength; + FT_Error error; + FT_Memory memory = face->root.memory; + FT_String* result; + + if ( !ALLOC( result, len+1 ) ) + { + memcpy( result, name->string, len ); + result[len] = '\0'; + + face->root.internal->postscript_name = result; + } + return result; + } + } + } + + return NULL; + } + + #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ @@ -127,6 +173,10 @@ if ( strcmp( interface, "glyph_name" ) == 0 ) return (FT_Module_Interface)get_sfnt_glyph_name; #endif + + if ( strcmp( interface, "postscript_name" ) == 0 ) + return (FT_Module_Interface)get_sfnt_postscript_name; + return 0; } diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c index 40a1d38d3..49be9f64f 100644 --- a/src/type1/t1driver.c +++ b/src/type1/t1driver.c @@ -108,6 +108,13 @@ } + static const char* + t1_get_ps_name( T1_Face face ) + { + return (const char*) face->type1.font_name; + } + + /*************************************************************************/ /* */ /* */ @@ -148,6 +155,9 @@ if ( strcmp( (const char*)interface, "name_index" ) == 0 ) return (FT_Module_Interface)t1_get_name_index; + if ( strcmp( (const char*)interface, "postscript_name" ) == 0 ) + return (FT_Module_Interface)t1_get_ps_name; + #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT if ( strcmp( (const char*)interface, "get_mm" ) == 0 ) return (FT_Module_Interface)T1_Get_Multi_Master;