freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] plan to support sfnt-wrapped CID-keyed font


From: mpsuzuki
Subject: Re: [ft-devel] plan to support sfnt-wrapped CID-keyed font
Date: Thu, 18 Sep 2008 19:44:01 +0900

Dear all,

I revised my experimental patch to load sfnt-wrapped CID and
sfnt-wrapped Type1 font by FreeType2.

The detection of the format is moved out of TrueType driver,
and inserted to the MacOS resource fork accessor. I've checked
this patch enables FreeType2 to load sfnt-wrapped CID-keyed font
(Japanese Heisei families in Adobe ValuePack CD for Macintosh).
But this patch does not work when CID or TYP1 table is included
in naked sfnt font file, because the detection of the format
is inserted into MacOS resource forke accessor.

Also I've tested sfnt-wrapped Type1 font, but yet it doesn't
work. The sample sfnt-wrapped Type1 fonts (thank you for kind
contributors!) include TYP1 table but the contents are slightly
different from simple PFA/PFB, they are similar to Type1 font
program described by full-featured PostScript language, aslike
some Type1 fonts bundled to ghostscript, .gsf.
Even if I make a naked Type1 font by removing other tables
(and binary header in TYP1 table), FreeType2 cannot load it.

Regards,
mpsuzuki


Index: ChangeLog
===================================================================
RCS file: /sources/freetype/freetype2/ChangeLog,v
retrieving revision 1.1795
diff -u -r1.1795 ChangeLog
--- ChangeLog   18 Sep 2008 04:36:56 -0000      1.1795
+++ ChangeLog   18 Sep 2008 10:43:51 -0000
@@ -1,5 +1,13 @@
 2008-09-18  suzuki toshiya  <address@hidden>
 
+       * src/base/ftobjs.c (Mac_Read_sfnt_Resource): Add support for
+       sfnt-wrapped Type1 and sfnt-wrapped CID-keyed font.
+       (Mac_Lookup_PS_in_sfnt): New function to lookup 'CID ' or 'TYP1'
+       table in sfnt table directory. It is used before loading TrueType
+       font driver.
+
+2008-09-18  suzuki toshiya  <address@hidden>
+
        * src/cff/cffobjs.c (cff_face_init): Use TTAG_OTTO defined
        in ttags.h instead of numerical value 0x4F54544FL.
 
Index: src/base/ftobjs.c
===================================================================
RCS file: /sources/freetype/freetype2/src/base/ftobjs.c,v
retrieving revision 1.292
diff -u -r1.292 ftobjs.c
--- src/base/ftobjs.c   19 Aug 2008 15:35:44 -0000      1.292
+++ src/base/ftobjs.c   18 Sep 2008 10:44:00 -0000
@@ -1409,6 +1409,64 @@
   }
 
 
+  /* Lookup 'TYP1' or 'CID ' table from sfnt table directory. */
+  /* offset & length must exclude the binary header in tables */
+
+  /* XXX: Check sfnt-wrapped includes 'TYP1' or 'CID ' table */
+  /* For proper support, PS Type1 driver and CID-keyed font  */
+  /* driver should recognized sfnt-wrapped format. Here yet  */
+  /* sfnt directory parser is not loaded, we must parse by   */
+  /* by ourselves. We only care the name of table and offset */
+
+  static FT_Error
+  Mac_Lookup_PS_in_sfnt( FT_Byte*   sfnt,
+                         FT_ULong*  offset,
+                         FT_ULong*  length,
+                         FT_Bool*   is_sfnt_cid )
+  {
+
+    /* parse table directory header */
+    FT_Byte*   p = sfnt + 4; /* skip version 'typ1' */
+    FT_UShort  numTables = FT_NEXT_USHORT( p );
+    p += ( 2 * 3 ); /* skip binary search header */
+
+    for ( ; numTables > 0 ; numTables -- )
+    {
+      /* parse table directory entry */
+      FT_ULong  tag, checkSum;
+
+      tag      = FT_NEXT_ULONG( p );
+      checkSum = FT_NEXT_ULONG( p );
+      *offset  = FT_NEXT_ULONG( p );
+      *length  = FT_NEXT_ULONG( p );
+
+      FT_UNUSED( checkSum );
+
+      /* see Adobe TN# 5180 for binary header in CID table */
+      if ( tag == FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) )
+      {
+        *offset += 22;
+        *length -= 22;
+       *is_sfnt_cid = TRUE;
+       return FT_Err_Ok;
+      }
+
+      /* see Apple "The Type 1 GX Font Format" */
+      if ( tag == FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) )
+      {
+        *offset += 24;
+        *length -= 24;
+       *is_sfnt_cid = FALSE;
+       return FT_Err_Ok;
+      }
+    }
+
+    *offset = 0;
+    *length = 0;
+    return FT_Err_Invalid_Table;
+  }
+
+
   /* The resource header says we've got resource_cnt `sfnt'      */
   /* (TrueType/OpenType) resources in this file.  Look through   */
   /* them for the one indicated by face_index, load it into mem, */
@@ -1428,6 +1486,7 @@
     FT_Long    flag_offset;
     FT_Long    rlen;
     int        is_cff;
+    int        is_sfnt_ps;
     FT_Long    face_index_in_resource = 0;
 
 
@@ -1452,11 +1511,43 @@
     if ( error )
       goto Exit;
 
-    is_cff = rlen > 4 && sfnt_data[0] == 'O' &&
-                         sfnt_data[1] == 'T' &&
-                         sfnt_data[2] == 'T' &&
-                         sfnt_data[3] == 'O';
+    is_cff     = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4);
+    is_sfnt_ps = rlen > 4 && !ft_memcmp( sfnt_data, "typ1", 4);
+
+    if ( is_sfnt_ps )
+    {
+      FT_ULong  offset, length;
+      FT_Bool   is_sfnt_cid;
+      FT_Byte*  sfnt_ps;
+
+      
+      error = Mac_Lookup_PS_in_sfnt( sfnt_data,
+                                     &offset,
+                                     &length,
+                                     &is_sfnt_cid );
+      if ( error )
+        goto Try_CFFOrTrueType;
+
 
+      if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
+        return error;
+      ft_memcpy( sfnt_ps, sfnt_data + offset, length );
+
+      error = open_face_from_buffer( library,
+                                     sfnt_ps,
+                                     length,
+                                     face_index_in_resource,
+                                     is_sfnt_cid ? "cid" : "type1",
+                                     aface );
+      if ( !error )
+      {
+        FT_FREE( sfnt_data );
+        goto Exit;
+      }
+
+      FT_FREE( sfnt_ps );
+    }
+  Try_CFFOrTrueType:
     error = open_face_from_buffer( library,
                                    sfnt_data,
                                    rlen,




reply via email to

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