shithub: freetype+ttf2subf

Download patch

ref: 23bcde193e64dfae54a1c51dacad2a86d7a5f028
parent: 40d006af7c6a79147fa09245a6b13c7c721176eb
author: David Turner <[email protected]>
date: Wed Oct 17 09:48:10 EDT 2001

implementing a new function named "FT_Get_Postscript_Name" to
retrieve a face's "unique" Postscript name

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
 2001-10-17  David Turner  >[email protected]>
 
-	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  <[email protected]>
 
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -2289,6 +2289,30 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    FT_Get_Postscript_Name                                             */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Retrieves the ASCII Postscript name of a given face, when          */
+  /*    available. This should only work with Postscript and TrueType      */
+  /*    fonts..                                                            */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face :: handle to source face object.                              */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    pointer to face's Postscript name. NULL when un-available          */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    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 );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    FT_Select_Charmap                                                  */
   /*                                                                       */
   /* <Description>                                                         */
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -129,15 +129,19 @@
   /*    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;
 
 
@@ -627,6 +631,9 @@
   FT_Render_Glyph_Internal( FT_Library    library,
                             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,
--- 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 );
   }
 
@@ -1903,6 +1907,38 @@
     }
 
     return error;
+  }
+
+
+  /* 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;
   }
 
 
--- 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;
   }
 
@@ -172,6 +183,7 @@
   Exit:
     return result;
   }
+
 
 
   FT_CALLBACK_TABLE_DEF
--- 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;
   }
 
--- 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;
+  }
+
+
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -147,6 +154,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 )