freetype-devel
[Top][All Lists]
Advanced

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

[Devel] Patch submission: further enhancement to ft2demo/ftdump.


From: Hin-Tak Leung
Subject: [Devel] Patch submission: further enhancement to ft2demo/ftdump.
Date: Fri, 29 Aug 2003 21:31:24 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624

a further enhancement to ft2demo/ftdump to my last patch.
The previous enhancement was to dump the localised sfnt info.
This improves on that - I found oto
(http://sourceforge.net/projects/oto/) does a better job
for dumping that localised info, and I looked at the source
code to work out why it does things better (basically microsoft
uses the lower byte of a widechar for GB/BIG5/ascii, but
uses both for unicode as UTF-16BE - but this is
particularly undesirable because big endian utf16 doesn't
mix well with ascii, and the other cases requires dropping
the higher byte - so one needs to do some conversions to get
the info "readable"); this further enhancement is the result
(diff against my previous patched version, and accumulated
diff against the stock unmodified version.

The previous patch was completely portable - this
further enhancement uses <iconv.h> to achieve the UTF-16BE to
utf8 conversion - it might be better to bundle a small
UTF-16BE to utf8 routine (quite trivial, I would think)
for better portabity; else make configure auto-detect
the presence of iconv(or glibc).

(I am starting to think I might want to subscribe to the list if
I keep on getting delays for the submission of patches, etc
- how heavy is the traffic? Alternatively, I suppose I can
just e-mail Werner the patch... :-)
--- ftdump.c.mod1       2003-08-29 20:23:15.000000000 +0100
+++ ftdump.c    2003-08-29 20:23:05.000000000 +0100
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+/* international conversion, in glibc */
+#include <iconv.h>
 
   FT_Error  error;
 
@@ -130,9 +132,59 @@
                     oeid = aname.encoding_id;
                     olid = aname.language_id; 
                 }
+                if ((aname.platform_id == 3) && (aname.encoding_id == 1))
+                {
+                    /* According to the source code of OpenType Organizer,
+                       Microsoft Unicode stores name strings in 
+                       UTF16-BE, whereas Apple Unicode does it in UTF8.
+                       Attempt to print converted version also. */
+                    iconv_t cd = iconv_open("UTF-8", "UTF-16BE");
+                    if (cd != (iconv_t)-1) 
+                    {
+                        int utf8bytes;
+                        char *utf8; 
+                        size_t inbytesleft, outbytesleft;
+                        char *inbuf = aname.string;
+                        char *outbuf;
+                        utf8bytes = aname.string_len *6;
+                        utf8 = (char *)calloc(utf8bytes, 1);
+                        outbuf = utf8;
+                        inbytesleft = aname.string_len;
+                        outbytesleft = utf8bytes;
+                        iconv(cd, &inbuf, &inbytesleft, &outbuf, 
&outbytesleft);
+                        if (inbytesleft == 0)
+                        {
+                            printf("            %du:", aname.name_id);
+                            fwrite(utf8, 1, utf8bytes - outbytesleft, stdout);
+                            printf("\n");
+                        }                        
+                    }
+                }
+                else if (aname.platform_id == 3)
+                {
+                    /* According to the source code of OpenType Organizer,
+                       Microsoft stores big5 and GB strings in the lower byte
+                       of a bigendian widechar. Strip 0x00 whenever Microsoft. 
*/
+                        int i = 0, count = 0;
+                        char *stripped; 
+                        stripped = (char *)calloc(aname.string_len, 1);
+                        for (i = 0; i < aname.string_len; i++) {
+                            if (aname.string[i] != 0x00) {
+                                stripped[count] = aname.string[i];
+                                count++;
+                            }
+                        }
+
+                        printf("            %ds:", aname.name_id);
+                        fwrite(stripped, 1, count, stdout);
+                        printf("\n");                    
+                }
+                else
+                {
                 printf("            %d:", aname.name_id);
                 fwrite(aname.string, 1, aname.string_len, stdout);
                 printf("\n");
+                }
             }
             else
             {
--- ftdump.c.orig       2003-08-29 20:23:24.000000000 +0100
+++ ftdump.c    2003-08-29 20:23:05.000000000 +0100
@@ -18,6 +18,7 @@
 #include FT_MODULE_H
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_DRIVER_H
+#include FT_SFNT_NAMES_H
 
 #include "common.h"
 
@@ -25,12 +26,15 @@
 #include <stdlib.h>
 #include <string.h>
 
+/* international conversion, in glibc */
+#include <iconv.h>
 
   FT_Error  error;
 
   int  comma_flag  = 0;
   int  debug       = 0;
   int  trace_level = 0;
+  int  need_localized_info = 0; 
 
 
   /* PanicZ */
@@ -103,6 +107,92 @@
     printf( "   sfnt wrapped:    %s\n",
             FT_IS_SFNT( face ) ? (char *)"yes" : (char *)"no" );
 
+    if(FT_IS_SFNT( face ) && need_localized_info)
+    {
+        int idx;
+        /* need impossible previous values here */ 
+        int opid = 999, oeid = 999, olid = 999;
+ 
+        FT_UInt name_count = FT_Get_Sfnt_Name_Count( face );
+        printf("      Localized name count = %d\n", name_count);
+        for (idx = 0 ; idx < name_count ; idx++)
+        {
+            FT_SfntName aname;
+            if (!FT_Get_Sfnt_Name( face, idx, &aname ))
+            {
+                if ((aname.platform_id != opid)
+                    || (aname.encoding_id != oeid)
+                    || (aname.language_id != olid))
+                {
+                    printf("        PID=%5.5d, EID=%5.5d, 
LID=%5.5d(0x%04x):\n",
+                           aname.platform_id,
+                           aname.encoding_id,
+                           aname.language_id, aname.language_id);
+                    opid = aname.platform_id;
+                    oeid = aname.encoding_id;
+                    olid = aname.language_id; 
+                }
+                if ((aname.platform_id == 3) && (aname.encoding_id == 1))
+                {
+                    /* According to the source code of OpenType Organizer,
+                       Microsoft Unicode stores name strings in 
+                       UTF16-BE, whereas Apple Unicode does it in UTF8.
+                       Attempt to print converted version also. */
+                    iconv_t cd = iconv_open("UTF-8", "UTF-16BE");
+                    if (cd != (iconv_t)-1) 
+                    {
+                        int utf8bytes;
+                        char *utf8; 
+                        size_t inbytesleft, outbytesleft;
+                        char *inbuf = aname.string;
+                        char *outbuf;
+                        utf8bytes = aname.string_len *6;
+                        utf8 = (char *)calloc(utf8bytes, 1);
+                        outbuf = utf8;
+                        inbytesleft = aname.string_len;
+                        outbytesleft = utf8bytes;
+                        iconv(cd, &inbuf, &inbytesleft, &outbuf, 
&outbytesleft);
+                        if (inbytesleft == 0)
+                        {
+                            printf("            %du:", aname.name_id);
+                            fwrite(utf8, 1, utf8bytes - outbytesleft, stdout);
+                            printf("\n");
+                        }                        
+                    }
+                }
+                else if (aname.platform_id == 3)
+                {
+                    /* According to the source code of OpenType Organizer,
+                       Microsoft stores big5 and GB strings in the lower byte
+                       of a bigendian widechar. Strip 0x00 whenever Microsoft. 
*/
+                        int i = 0, count = 0;
+                        char *stripped; 
+                        stripped = (char *)calloc(aname.string_len, 1);
+                        for (i = 0; i < aname.string_len; i++) {
+                            if (aname.string[i] != 0x00) {
+                                stripped[count] = aname.string[i];
+                                count++;
+                            }
+                        }
+
+                        printf("            %ds:", aname.name_id);
+                        fwrite(stripped, 1, count, stdout);
+                        printf("\n");                    
+                }
+                else
+                {
+                printf("            %d:", aname.name_id);
+                fwrite(aname.string, 1, aname.string_len, stdout);
+                printf("\n");
+                }
+            }
+            else
+            {
+                printf("FT_Get_Sfnt_Name failed for idx %d\n", idx);
+            }
+        }
+    }
+
     /* isScalable? */
     comma_flag = 0;
     printf( "   type:            " );
@@ -208,7 +298,7 @@
 
     while ( 1 )
     {
-      option = getopt( argc, argv, "dl:" );
+      option = getopt( argc, argv, "dul:" );
 
       if ( option == -1 )
         break;
@@ -219,6 +309,10 @@
         debug = 1;
         break;
 
+      case 'u':
+        need_localized_info = 1;
+        break;
+
       case 'l':
         trace_level = atoi( optarg );
         if ( trace_level < 1 || trace_level > 7 )
@@ -299,6 +393,7 @@
       PanicZ( "Could not open face." );
 
   Success:
+    printf( "File %s loaded successfully...\n", filename);
     num_faces = face->num_faces;
     FT_Done_Face( face );
 

reply via email to

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