freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft-devel] Use tt_face_get_name() in sfnt_get_ps_name()?


From: mpsuzuki
Subject: [ft-devel] Use tt_face_get_name() in sfnt_get_ps_name()?
Date: Mon, 2 May 2011 03:14:45 +0900

Hi,

While I was extending sfnt_get_ps_name() to lookup
ASCII string from all possible entries, I found that
tt_face_get_name() and sfnt_get_ps_name() are quite similar.

The coverage of strings checked by tt_face_get_name()
is wider than that by sfnt_get_ps_name(). For example,
sfnt_get_ps_name() does not check non-English strings.

In addition, tt_face_get_name() just skips non-ASCII
character in the string, but sfnt_get_ps_name() replaces
non-ASCII character by `?'.

If these difference is not so important, I propose to
change sfnt_get_ps_name() to thin wrapper of tt_face_get_name().

Also it would be easy to add a switch to skip or replace,
or return a NULL string when all characters in the string
are non-ASCII.

Regards,
mpsuzuki


diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index e581af9..0d8a226 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -131,7 +131,7 @@
   /* <Return>                                                              */
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
-  static FT_Error
+  FT_LOCAL_DEF( FT_Error )
   tt_face_get_name( TT_Face      face,
                     FT_UShort    nameid,
                     FT_String**  name )
diff --git a/src/sfnt/sfobjs.h b/src/sfnt/sfobjs.h
index 6241c93..8ce93f5 100644
--- a/src/sfnt/sfobjs.h
+++ b/src/sfnt/sfobjs.h
@@ -45,6 +45,11 @@ FT_BEGIN_HEADER
   FT_LOCAL( void )
   sfnt_done_face( TT_Face  face );
 
+  FT_LOCAL( FT_Error )
+  tt_face_get_name( TT_Face      face,
+                    FT_UShort    nameid,
+                    FT_String**  name );
+
 
 FT_END_HEADER
 
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 247aa67..9c93ead 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -217,110 +217,12 @@
   static const char*
   sfnt_get_ps_name( TT_Face  face )
   {
-    FT_Int       n, found_win, found_apple;
-    const char*  result = NULL;
+    FT_String*  result;
 
 
-    /* shouldn't happen, but just in case to avoid memory leaks */
-    if ( face->postscript_name )
-      return face->postscript_name;
+    if ( !tt_face_get_name( face, TT_NAME_ID_PS_NAME, &result ) )
+      face->postscript_name = result;
 
-    /* scan the name table to see whether we have a Postscript name here, */
-    /* either in Macintosh or Windows platform encodings                  */
-    found_win   = -1;
-    found_apple = -1;
-
-    for ( n = 0; n < face->num_names; n++ )
-    {
-      TT_NameEntryRec*  name = face->name_table.names + n;
-
-
-      if ( name->nameID == 6 && name->stringLength > 0 )
-      {
-        if ( name->platformID == 3     &&
-             name->encodingID == 1     &&
-             name->languageID == 0x409 )
-          found_win = n;
-
-        if ( name->platformID == 1 &&
-             name->encodingID == 0 &&
-             name->languageID == 0 )
-          found_apple = n;
-      }
-    }
-
-    if ( found_win != -1 )
-    {
-      FT_Memory         memory = face->root.memory;
-      TT_NameEntryRec*  name   = face->name_table.names + found_win;
-      FT_UInt           len    = name->stringLength / 2;
-      FT_Error          error  = SFNT_Err_Ok;
-
-      FT_UNUSED( error );
-
-
-      if ( !FT_ALLOC( result, name->stringLength + 1 ) )
-      {
-        FT_Stream   stream = face->name_table.stream;
-        FT_String*  r      = (FT_String*)result;
-        FT_Byte*    p      = (FT_Byte*)name->string;
-
-
-        if ( FT_STREAM_SEEK( name->stringOffset ) ||
-             FT_FRAME_ENTER( name->stringLength ) )
-        {
-          FT_FREE( result );
-          name->stringLength = 0;
-          name->stringOffset = 0;
-          FT_FREE( name->string );
-
-          goto Exit;
-        }
-
-        p = (FT_Byte*)stream->cursor;
-
-        for ( ; len > 0; len--, p += 2 )
-        {
-          if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 )
-            *r++ = p[1];
-        }
-        *r = '\0';
-
-        FT_FRAME_EXIT();
-      }
-      goto Exit;
-    }
-
-    if ( found_apple != -1 )
-    {
-      FT_Memory         memory = face->root.memory;
-      TT_NameEntryRec*  name   = face->name_table.names + found_apple;
-      FT_UInt           len    = name->stringLength;
-      FT_Error          error  = SFNT_Err_Ok;
-
-      FT_UNUSED( error );
-
-
-      if ( !FT_ALLOC( result, len + 1 ) )
-      {
-        FT_Stream  stream = face->name_table.stream;
-
-
-        if ( FT_STREAM_SEEK( name->stringOffset ) ||
-             FT_STREAM_READ( result, len )        )
-        {
-          name->stringOffset = 0;
-          name->stringLength = 0;
-          FT_FREE( name->string );
-          FT_FREE( result );
-          goto Exit;
-        }
-        ((char*)result)[len] = '\0';
-      }
-    }
-
-  Exit:
-    face->postscript_name = result;
     return result;
   }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]