shithub: freetype+ttf2subf

Download patch

ref: d42c68e85593db7dc925c5cc6f831a1f94e9a48a
parent: 76bbd5793fcd04f7dd8b6ccdf3e0ce8561cc80e4
author: David Turner <[email protected]>
date: Thu Jan 27 08:56:02 EST 2000

many new small, but important, changes there:

  - modified the interface of the "sfnt" module. There is now a function
    called "load_format_tag", and another called "load_directory".

    The first one is in charge of returning the 4-byte tag located at
    the beginning of a given font file. It understand TrueType collections
    and parses them automatically

    The second loads the table directory that is located just after
    the format tag.

    This is useful, because the "SFNT" storage scheme can be used by
    several distinct formats, each with its own format tag.

    The TrueType driver now checks the format tag in "src/truetype/ttobjs.c"

  - made some changes to "src/shared/t1types.h" to clearly separate the
    Type 1 font content from the rest of the T1_Face structure. This
    will be useful when adding the CFF/Type2 driver that will be able
    to reuse the "T1_Font" structure within a "TT_Font" one (which
    really describes a SFNT-based font file).

    Some changes in "src/type1" were thus performed to reflect this.
    Note that the current type1 driver will be discontinued in a
    distant future. More on this later..

git/fs: mount .git/fs: mount/attach disallowed
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1340,6 +1340,8 @@
     FT_Driver            driver;
     FT_Memory            memory;
     FT_DriverInterface*  interface;
+    FT_Size_Metrics*     metrics = &face->size->metrics;
+    FT_Long              dim_x, dim_y;
 
     if ( !face || !face->size || !face->driver)
       return FT_Err_Invalid_Face_Handle;
@@ -1360,6 +1362,25 @@
     interface = &driver->interface;
     memory    = driver->memory;
 
+    /* default processing - this can be overriden by the driver */
+    if ( char_width  < 1*64 ) char_width  = 1*64;
+    if ( char_height < 1*64 ) char_height = 1*64;
+
+    /* Compute pixel sizes in 26.6 units */
+    dim_x = (((char_width  * horz_resolution) / 72) + 32) & -64;
+    dim_y = (((char_height * vert_resolution) / 72) + 32) & -64;
+
+    metrics->x_ppem    = (FT_UShort)(dim_x >> 6);
+    metrics->y_ppem    = (FT_UShort)(dim_y >> 6);
+
+    metrics->x_scale = 0x10000;
+    metrics->y_scale = 0x10000;
+    if ( face->face_flags & FT_FACE_FLAG_SCALABLE)
+    {
+      metrics->x_scale = FT_DivFix( dim_x, face->units_per_EM );
+      metrics->y_scale = FT_DivFix( dim_y, face->units_per_EM );
+    }
+
     error = interface->set_char_sizes( face->size,
                                        char_width,
                                        char_height,
@@ -1395,6 +1416,7 @@
     FT_Driver            driver;
     FT_Memory            memory;
     FT_DriverInterface*  interface;
+    FT_Size_Metrics*     metrics = &face->size->metrics;
 
     if ( !face || !face->size || !face->driver )
       return FT_Err_Invalid_Face_Handle;
@@ -1403,8 +1425,25 @@
     interface = &driver->interface;
     memory    = driver->memory;
 
-    error = interface->set_pixel_sizes( face->size, pixel_width, pixel_height );
+    /* default processing - this can be overriden by the driver */
+    if ( pixel_width  < 1 ) pixel_width  = 1;
+    if ( pixel_height < 1 ) pixel_height = 1;
 
+    metrics->x_ppem = pixel_width;
+    metrics->y_ppem = pixel_height;
+
+    if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
+    {
+      metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
+                                    face->units_per_EM );
+
+      metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
+                                    face->units_per_EM );
+    }
+
+    error = interface->set_pixel_sizes( face->size, 
+                                        pixel_width,
+                                        pixel_height );
     return error;
   }
 
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -11,6 +11,7 @@
     TT_Goto_Table,
     
     TT_Load_Any,
+    TT_Load_Format_Tag,
     TT_Load_Directory,
 
     TT_Load_Header,
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -115,11 +115,12 @@
 
   /*************************************************************************/
   /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Directory                                                  */
+  /* <FuncType>                                                            */
+  /*    TT_Load_Format_Tag                                                 */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Loads the table directory into a face object.                      */
+  /*    Loads the first 4 bytes of the font file. This is a tag that       */
+  /*    identifies the font format used.                                   */
   /*                                                                       */
   /* <Input>                                                               */
   /*    face      :: A handle to the target face object.                   */
@@ -126,6 +127,8 @@
   /*    stream    :: The input stream.                                     */
   /*    faceIndex :: The index of the TrueType font, if we're opening a    */
   /*                 collection.                                           */
+  /* <Output>                                                              */
+  /*    format_tag :: a 4-byte font format tag                             */
   /*                                                                       */
   /* <Return>                                                              */
   /*    TrueType error code.  0 means success.                             */
@@ -132,22 +135,18 @@
   /*                                                                       */
   /* <Note>                                                                */
   /*    The stream cursor must be at the font file's origin                */
+  /*    This function recognizes fonts embedded in a "TrueType collection" */
   /*                                                                       */
   LOCAL_FUNC
-  TT_Error  TT_Load_Directory( TT_Face    face,
-                               FT_Stream  stream,
-                               TT_Long    faceIndex )
+  TT_Error  TT_Load_Format_Tag( TT_Face    face,
+                                FT_Stream  stream,
+                                TT_Long    faceIndex,
+                                TT_ULong  *format_tag )
   {
     TT_Error   error;
     FT_Memory  memory = stream->memory;
 
-    TT_TableDir  tableDir;
-    TT_ULong     tag;
-
-    TT_Table *entry, *limit;
-
-
-    FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",
+    FT_TRACE2(( "TT_Load_Format_Tag(%08lx, %ld )\n",
               (TT_Long)face, faceIndex ));
 
     face->ttc_header.Tag      = 0;
@@ -157,26 +156,24 @@
     face->num_tables = 0;
 
     /* first of all, read the  first 4 bytes. If it's `ttcf', then the */
-    /* file is a TrueType collection, otherwise it must be a normal    */
-    /* TrueType file..                                                 */
+    /* file is a TrueType collection, otherwise it can be any other    */
+    /* kind of font..                                                  */
+    if ( READ_ULong(*format_tag) ) goto Exit;
 
-    if ( READ_ULong(tag) )
-      goto Exit;
-
-    if ( tag == TTAG_ttcf )
+    if ( *format_tag == TTAG_ttcf )
     {
       TT_Int  n;
     
-      FT_TRACE4(( "TT_Load_Directory: file is a collection\n" ));
+      FT_TRACE4(( "TT_Load_Format_Tag: file is a collection\n" ));
       
       /* it's a TrueType collection, i.e. a file containing several */
       /* font files. Read the font directory now                    */
       /*                                                            */
       if ( ACCESS_Frame( 8 ) ) goto Exit;   
-        
+
       face->ttc_header.version  = GET_Long();
       face->ttc_header.DirCount = GET_Long();
-           
+
       FORGET_Frame();
 
       /* now read the offsets of each font in the file         */
@@ -205,28 +202,54 @@
         
       /* seek to the appropriate TrueType file, then read tag */
       if ( FILE_Skip( face->ttc_header.TableDirectory[faceIndex] - 12 ) ||
-           READ_Long( tableDir.version )                                )
+           READ_Long( *format_tag )                                     )
         goto Exit;
     }
-    else
-    {
-      FT_TRACE6(( "TT_Load_Directory: file is not a collection\n" ));
-      /* the file isn't a collection, exit if we're asking for a */
-      /* collected font..                                        */
-      if (faceIndex > 0)
-      {
-        error = TT_Err_File_Is_Not_Collection;
-        goto Exit;
-      }
-      
-      tableDir.version = tag;
-    }
 
-    if ( ACCESS_Frame( 8L ) )
-      goto Exit;
+  Exit:
+    return error;
+  }
 
-    tableDir.numTables = GET_UShort();
 
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    TT_Load_Directory                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Loads the table directory into a face object.                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face      :: A handle to the target face object.                   */
+  /*    stream    :: The input stream.                                     */
+  /*    faceIndex :: The index of the TrueType font, if we're opening a    */
+  /*                 collection.                                           */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    TrueType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The stream cursor must be at the font file's origin                */
+  /*                                                                       */
+  LOCAL_FUNC
+  TT_Error  TT_Load_Directory( TT_Face    face,
+                               FT_Stream  stream,
+                               TT_Long    faceIndex )
+  {
+    TT_Error   error;
+    FT_Memory  memory = stream->memory;
+
+    TT_TableDir  tableDir;
+
+    TT_Table *entry, *limit;
+
+
+    FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",
+              (TT_Long)face, faceIndex ));
+
+    if ( ACCESS_Frame( 8L ) ) goto Exit;
+
+    tableDir.numTables     = GET_UShort();
     tableDir.searchRange   = GET_UShort();
     tableDir.entrySelector = GET_UShort();
     tableDir.rangeShift    = GET_UShort();
@@ -236,23 +259,6 @@
     FT_TRACE2(( "-- Tables count   : %12u\n",  tableDir.numTables ));
     FT_TRACE2(( "-- Format version : %08lx\n", tableDir.version ));
 
-    /* Check that we have a `sfnt' format there                        */
-    /* We must also be able to accept Mac/GX fonts, as well as OT ones */
-
-    if ( tableDir.version != 0x00010000 &&    /* MS fonts          */
-         tableDir.version != TTAG_true  &&    /* Mac fonts         */
-         tableDir.version != TTAG_OTTO  )    /* OT-Type2 fonts    */
-    {
-      FT_TRACE2(( "[not a valid TTF or OTF font]" ));
-      error = TT_Err_Invalid_File_Format;
-      goto Exit;
-    }
-
-    /* if we're performing a font format check, exit immediately */
-    /* with success                                              */
-    if ( faceIndex < 0 )
-      goto Exit;
-
     face->num_tables = tableDir.numTables;
 
     if ( ALLOC_ARRAY( face->dir_tables,
@@ -267,7 +273,7 @@
     limit = entry + face->num_tables;
 
     for ( ; entry < limit; entry++ )
-    {                      /* loop through the tables and get all entries */
+    {                    /* loop through the tables and get all entries */
       entry->Tag      = GET_Tag4();
       entry->CheckSum = GET_ULong();
       entry->Offset   = GET_Long();
--- a/src/sfnt/ttload.h
+++ b/src/sfnt/ttload.h
@@ -32,43 +32,11 @@
 #endif
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_LookUp_Table                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Looks for a TrueType table by name.                                */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face :: A face object handle.                                      */
-  /*    tag  :: The  searched tag.                                         */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    pointer to table directory entry. 0 if not found..                 */
-  /*                                                                       */
   EXPORT_DEF
   TT_Table*  TT_LookUp_Table( TT_Face   face,
                               TT_ULong  tag );
 
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Goto_Table                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Looks for a TrueType table by name, then seek a stream to it.      */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: a face object handle.                                    */
-  /*    tag    :: the  searched tag.                                       */
-  /*    stream :: the stream to seek when the table is found               */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    pointer to table directory entry. 0 if not found..                 */
-  /*                                                                       */
-  EXPORT_DEF
+  LOCAL_DEF
   TT_Error   TT_Goto_Table( TT_Face    face,
                             TT_ULong   tag,
                             FT_Stream  stream,
@@ -75,73 +43,18 @@
                             TT_ULong  *length );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Directory                                                  */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the table directory into a face object.                      */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face      :: A handle to the target face object.                   */
-  /*    stream    :: The input stream.                                     */
-  /*    faceIndex :: The index of the TrueType font, if we're opening a    */
-  /*                 collection.                                           */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    The stream cursor must be at the font file's origin                */
-  /*                                                                       */
   LOCAL_DEF
+  TT_Error  TT_Load_Format_Tag( TT_Face    face,
+                                FT_Stream  stream,
+                                TT_Long    faceIndex,
+                                TT_ULong  *format_tag );
+
+  LOCAL_DEF
   TT_Error  TT_Load_Directory( TT_Face    face,
                                FT_Stream  stream,
                                TT_Long    faceIndex );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Any                                                        */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads any font table into client memory.  Used by the              */
-  /*    TT_Get_Font_Data() API function.                                   */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: The face object to look for.                             */
-  /*                                                                       */
-  /*    tag    :: The tag of table to load.  Use the value 0 if you  want  */
-  /*              to access the whole font file, else set this parameter   */
-  /*              to a valid TrueType table tag that you can forge with    */
-  /*              the MAKE_TT_TAG macro.                                   */
-  /*                                                                       */
-  /*    offset :: The starting offset in the table (or the file if         */
-  /*              tag == 0).                                               */
-  /*                                                                       */
-  /*    length :: The address of the decision variable:                    */
-  /*                                                                       */
-  /*                If length == NULL:                                     */
-  /*                  Loads the whole table.  Returns an error if          */
-  /*                  `offset' == 0!                                       */
-  /*                                                                       */
-  /*                If *length == 0:                                       */
-  /*                  Exits immediately; returning the length of the given */
-  /*                  table or of the font file, depending on the value of */
-  /*                  `tag'.                                               */
-  /*                                                                       */
-  /*                If *length != 0:                                       */
-  /*                  Loads the next `length' bytes of table or font,      */
-  /*                  starting at offset `offset' (in table or font too).  */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    buffer :: The address of target buffer.                            */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Any( TT_Face   face,
                          TT_ULong  tag,
@@ -150,42 +63,11 @@
                          TT_Long*  length );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Header                                                     */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the TrueType font header.                                    */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: The input stream.                                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Header( TT_Face    face,
                             FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Metrics_Header                                             */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the horizontal or vertical header in a face object.          */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face     :: A handle to the target face object.                    */
-  /*    stream   :: The input stream.                                      */
-  /*    vertical :: A boolean flag.  If set, load vertical metrics.        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Metrics_Header( TT_Face    face,
                                     FT_Stream  stream,
@@ -197,180 +79,44 @@
                           FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_MaxProfile                                                 */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the maximum profile into a face object.                      */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: The input stream.                                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_MaxProfile( TT_Face    face,
                                 FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Names                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the name records.                                            */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: The input stream.                                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Names( TT_Face    face,
                            FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_OS2                                                        */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the OS2 table.                                               */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: A handle to the input stream.                            */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_OS2( TT_Face    face,
                          FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Postscript                                                 */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the Postscript table.                                        */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: A handle to the input stream.                            */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_PostScript( TT_Face    face,
                                 FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Hdmx                                                       */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the horizontal device metrics table.                         */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: A handle to the input stream.                            */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Hdmx( TT_Face    face,
                           FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Free_Names                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Frees the name records.                                            */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face :: A handle to the target face object.                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   void  TT_Free_Names( TT_Face  face );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Free_Hdmx                                                       */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Frees the horizontal device metrics table.                         */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face :: A handle to the target face object.                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   void  TT_Free_Hdmx ( TT_Face  face );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Kern                                                       */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the first kerning table with format 0 in the font.  Only     */
-  /*    accepts the first horizontal kerning table.  Developers should use */
-  /*    the `ftxkern' extension to access other kerning tables in the font */
-  /*    file, if they really want to.                                      */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: The input stream.                                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Kern( TT_Face    face,
                           FT_Stream  stream );
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Load_Gasp                                                       */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Loads the `GASP' table into a face object.                         */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the target face object.                      */
-  /*    stream :: The input stream.                                        */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    TrueType error code.  0 means success.                             */
-  /*                                                                       */
   LOCAL_DEF
   TT_Error  TT_Load_Gasp( TT_Face    face,
                           FT_Stream  stream );
--- a/src/shared/sfnt.h
+++ b/src/shared/sfnt.h
@@ -26,6 +26,36 @@
   /*************************************************************************/
   /*                                                                       */
   /* <FuncType>                                                            */
+  /*    TT_Load_Format_Tag                                                 */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Loads the first 4 bytes of the font file. This is a tag that       */
+  /*    identifies the font format used.                                   */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face      :: A handle to the target face object.                   */
+  /*    stream    :: The input stream.                                     */
+  /*    faceIndex :: The index of the TrueType font, if we're opening a    */
+  /*                 collection.                                           */
+  /* <Output>                                                              */
+  /*    format_tag :: a 4-byte tag                                         */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    TrueType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The stream cursor must be at the font file's origin                */
+  /*    This function recognizes fonts embedded in a "TrueType collection" */
+  /*                                                                       */
+  typedef
+  TT_Error  (*TT_Load_Format_Tag_Func)( TT_Face    face,
+                                        FT_Stream  stream,
+                                        TT_Long    faceIndex,
+                                        TT_ULong  *format_tag );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
   /*    TT_Load_Directory_Func                                             */
   /*                                                                       */
   /* <Description>                                                         */
@@ -41,7 +71,9 @@
   /*    TrueType error code.  0 means success.                             */
   /*                                                                       */
   /* <Note>                                                                */
-  /*    The stream cursor must be at the font file's origin                */
+  /*    The stream cursor must be on the first byte after the 4-byte       */
+  /*    font format tag. This is the case just after a call to             */
+  /*    TT_Load_Format_Tag                                                 */
   /*                                                                       */
   typedef
   TT_Error  (*TT_Load_Directory_Func)( TT_Face    face,
@@ -306,6 +338,7 @@
     TT_Goto_Table_Func      goto_table;
   
     TT_Load_Any_Func        load_any;
+    TT_Load_Format_Tag_Func load_format_tag;
     TT_Load_Directory_Func  load_directory;
 
     TT_Load_Table_Func      load_header;
--- a/src/shared/t1types.h
+++ b/src/shared/t1types.h
@@ -270,24 +270,47 @@
 
   /***********************************************************************/
   /*                                                                     */
-  /* <Struct> T1_FontInfo                                                */
+  /* <Struct> T1_Encoding                                                */
   /*                                                                     */
   /* <Description>                                                       */
-  /*    The FontInfo dictionary structure.                               */
+  /*    A structure modeling a custom encoding                           */
   /*                                                                     */
   /* <Fields>                                                            */
-  /*    version             ::                                           */
-  /*    notice              ::                                           */
-  /*    full_name           ::                                           */
-  /*    family_name         ::                                           */
-  /*    weight              ::                                           */
-  /*    italic_angle        ::                                           */
-  /*    is_fixed_pitch      ::                                           */
-  /*    underline_position  ::                                           */
-  /*    underline_thickness ::                                           */
+  /*    num_chars   :: number of char codes in encoding. Usually 256     */
+  /*    code_first  :: lower char code in encoding                       */
+  /*    code_last   :: higher char code in encoding                      */
   /*                                                                     */
-  typedef struct T1_FontInfo_
+  /*    char_code   :: array of character codes                          */
+  /*    char_index  :: array of correpsonding glyph indices              */
+  /*    char_name   :: array of correpsonding glyph names                */
+  /*                                                                     */
+  typedef struct T1_Encoding_
   {
+    T1_Int      num_chars;
+    T1_Int      code_first;
+    T1_Int      code_last;
+
+    T1_Short*   char_index;
+    T1_String** char_name;
+
+  } T1_Encoding;
+
+
+  typedef enum T1_EncodingType_
+  {
+	t1_encoding_none = 0,
+	t1_encoding_array,
+	t1_encoding_standard,
+	t1_encoding_expert
+
+  } T1_EncodingType;
+
+
+  typedef struct T1_Font_
+  {
+
+ /* font info dictionary */
+ 
     T1_String*     version;
     T1_String*     notice;
     T1_String*     full_name;
@@ -298,53 +321,8 @@
     T1_Short       underline_position;
     T1_UShort      underline_thickness;
 
-  } T1_FontInfo;
+ /* private dictionary */
 
-
-  /***********************************************************************/
-  /*                                                                     */
-  /* <Struct> T1_Private                                                 */
-  /*                                                                     */
-  /* <Description>                                                       */
-  /*    The Private dictionary structure.                                */
-  /*                                                                     */
-  /* <Fields>                                                            */
-  /*    unique_id :: the font's unique id                                */
-  /*    lenIV     :: length of decrypt padding                           */
-  /*                                                                     */
-  /*    num_blues              :: number of blue values                  */
-  /*    num_other_blues        :: number of other blue values            */
-  /*    num_family_blues       :: number of family blue values           */
-  /*    num_family_other_blues :: number of family other blue values     */
-  /*                                                                     */
-  /*    blue_values        :: array of blue values                       */
-  /*    other_blues        :: array of other blue values                 */
-  /*    family_blues       :: array of family blue values                */
-  /*    family_other_blues :: array of family other blue values          */
-  /*                                                                     */
-  /*    blue_scale         ::                                            */
-  /*    blue_shift         ::                                            */
-  /*    blue_scale         ::                                            */
-  /*                                                                     */
-  /*    standard_width     ::                                            */
-  /*    standard_height    ::                                            */
-  /*                                                                     */
-  /*    num_snap_widths    ::                                            */
-  /*    num_snap_heights   ::                                            */
-  /*    force_bold         ::                                            */
-  /*    round_stem_up      ::                                            */
-  /*                                                                     */
-  /*    stem_snap_widths   ::                                            */
-  /*    stem_snap_heights  ::                                            */
-  /*                                                                     */
-  /*    language_group     ::                                            */
-  /*    password           ::                                            */
-  /*                                                                     */
-  /*    min_feature        ::                                            */
-  /*                                                                     */
-  /*                                                                     */
-  typedef struct T1_Private_
-  {
     T1_Int       unique_id;
     T1_Int       lenIV;
 
@@ -379,37 +357,36 @@
 
     T1_Short     min_feature[2];
 
-  } T1_Private;
+ /* top-level dictionary */
+ 
+    FT_String*   font_name;
 
+    T1_EncodingType  encoding_type;
+    T1_Encoding      encoding;
 
+    T1_Byte*     subrs_block;
+    T1_Byte*     charstrings_block;
+    T1_Byte*     glyph_names_block;
 
-  /***********************************************************************/
-  /*                                                                     */
-  /* <Struct> T1_Private                                                 */
-  /*                                                                     */
-  /* <Description>                                                       */
-  /*    The Private dictionary structure.                                */
-  /*                                                                     */
-  /* <Fields>                                                            */
-  /*    num_chars   :: number of char codes in encoding. Usually 256     */
-  /*    code_first  :: lower char code in encoding                       */
-  /*    code_last   :: higher char code in encoding                      */
-  /*                                                                     */
-  /*    char_code   :: array of character codes                          */
-  /*    char_index  :: array of correpsonding glyph indices              */
-  /*    char_name   :: array of correpsonding glyph names                */
-  /*                                                                     */
-  typedef struct T1_Encoding_
-  {
-    T1_Int      num_chars;
-    T1_Int      code_first;
-    T1_Int      code_last;
+    T1_Int       num_subrs;
+    T1_Byte**    subrs;
+    T1_Int*      subrs_len;
 
-    T1_Short*   char_index;
-    T1_String** char_name;
+    T1_Int       num_glyphs;
+    T1_String**  glyph_names;       /* array of glyph names       */
+    T1_Byte**    charstrings;       /* array of glyph charstrings */
+    T1_Int*      charstrings_len;
 
-  } T1_Encoding;
+    T1_Byte      paint_type;
+    T1_Byte      font_type;
+    T1_Matrix    font_matrix;
+    T1_BBox      font_bbox;
+    T1_Long      font_id;
 
+    T1_Int       stroke_width;
+  
+  } T1_Font;
+  
 
 
 /*************************************************************************/
@@ -417,7 +394,7 @@
 /*************************************************************************/
 /***                                                                   ***/
 /***                                                                   ***/
-/***                  ORIGINAL TT_FACE CLASS DEFINITION                ***/
+/***                  ORIGINAL T1_FACE CLASS DEFINITION                ***/
 /***                                                                   ***/
 /***                                                                   ***/
 /*************************************************************************/
@@ -451,33 +428,7 @@
   typedef struct T1_FaceRec_
   {
     FT_FaceRec      root;
-
-    T1_FontInfo     font_info;
-    FT_String*      font_name;
-
-    T1_Encoding     encoding;
-
-    T1_Byte*        subrs_block;
-    T1_Byte*        charstrings_block;
-
-    T1_Int          num_subrs;
-    T1_Byte**       subrs;
-    T1_Int*         subrs_len;
-
-    T1_Int          num_glyphs;
-    T1_String**     glyph_names;       /* array of glyph names       */
-    T1_Byte**       charstrings;       /* array of glyph charstrings */
-    T1_Int*         charstrings_len;
-
-    T1_Byte         paint_type;
-    T1_Byte         font_type;
-    T1_Matrix       font_matrix;
-    T1_BBox         font_bbox;
-    T1_Long         unique_id;
-    T1_Long         font_id;
-
-    T1_Int          stroke_width;
-    T1_Private      private_dict;
+    T1_Font         type1;
 
   } T1_FaceRec;
 
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -29,81 +29,10 @@
 #define FT_COMPONENT  trace_ttdriver
 
 
-  static
-  TT_Bool  string_compare( const TT_String*  s1,
-                           const TT_String*  s2 )
-  {
-    int  tries;
 
-
-    for ( tries = 128; tries > 0; tries-- )
-    {
-      if ( !*s1 )
-        return !*s2;
-
-      if ( *s1 != *s2 )
-        return 0;
-
-      s1++;
-      s2++;
-    }
-
-    return 0;
-  }
-
-
   /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    Get_Interface                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Some drivers can be compiled with extensions, special code used    */
-  /*    only for specific purposes (usually for system-specific uses).     */
-  /*    Each extension is registered through a simple name (e.g. `sfnt',   */
-  /*    `post_names', etc).                                                */
-  /*                                                                       */
-  /*    This function is used to return an extension's interface (i.e.,    */
-  /*    a table of pointers) when it is present in the driver.             */
-  /*                                                                       */
-  /*    If the driver wasn't compiled with the requested extension, it     */
-  /*    should return NULL.                                                */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    driver    :: A handle to the driver object.                        */
-  /*                                                                       */
-  /*    interface :: The interface's name string.                          */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    A typeless pointer to the extension's interface (normally a table  */
-  /*    of function pointers).  Returns NULL when the requested extension  */
-  /*    isn't available (i.e., wasn't compiled in the driver at build      */
-  /*    time).                                                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    Note that unlike format-specific methods returned by               */
-  /*    getFormatInterface(), extensions can be format-independent.        */
-  /*                                                                       */
-  static
-  void*  Get_Interface( TT_Driver         driver,
-                        const TT_String*  interface )
-  {
-    /* `sfnt' returns a vtable of functions used to access the tables */
-    /* of a TrueType or OpenType font resource.                       */
-    if ( string_compare( interface, "sfnt" ) )
-      return (void*)NULL;
-
-    /* XXXX : For now, there is no extension support there */
-    UNUSED( driver );
-    UNUSED( interface );
-
-    return NULL;
-  }
-
-
   /*************************************************************************/
   /*************************************************************************/
-  /*************************************************************************/
   /****                                                                 ****/
   /****                                                                 ****/
   /****                          F A C E S                              ****/
@@ -500,34 +429,27 @@
     TT_Face           face    = (TT_Face)size->root.face;
     TT_Long           dim_x, dim_y;
 
-
-    if ( char_width  < 1*64 ) char_width = 1*64;
-    if ( char_height < 1*64 ) char_height = 1*64;
-
-    /* Compute pixel sizes in 26.6 units */
-    dim_x = (char_width * horz_resolution) / 72;
-    dim_y = (char_height * vert_resolution) / 72;
-
-    /* Truncate to integer pixels if required by font - nearly all  */
-    /* TrueType fonts have this bit set, as hinting can really work */
-    /* with integer pixel sizes.                                    */
-    if ( face->header.Flags & 8 )
+    /* This bit flag, when set, indicates that the pixel size must be */
+    /* truncated to an integer. Nearly all TrueType fonts have this   */
+    /* bit set, as hinting won't work really well otherwise.          */
+    /*                                                                */
+    /* However, for those rare fonts who do not set it, we override   */
+    /* the default computations performed by the base layer. I really */
+    /* don't know if this is useful, but hey, that's the spec :-)     */
+    /*                                                                */
+    if ( (face->header.Flags & 8) == 0 )
     {
-      dim_x = (dim_x + 32) & -64;
-      dim_y = (dim_y + 32) & -64;
-    }
+      /* Compute pixel sizes in 26.6 units */
+      dim_x = (char_width * horz_resolution) / 72;
+      dim_y = (char_height * vert_resolution) / 72;
 
-    metrics->x_scale = FT_MulDiv( dim_x,
-                                  0x10000L,
-                                  face->root.units_per_EM );
+      metrics->x_scale = FT_DivFix( dim_x, face->root.units_per_EM );
+      metrics->y_scale = FT_DivFix( dim_y, face->root.units_per_EM );
 
-    metrics->y_scale = FT_MulDiv( dim_y,
-                                  0x10000L,
-                                  face->root.units_per_EM );
-
-    metrics->x_ppem    = (TT_UShort)(dim_x >> 6);
-    metrics->y_ppem    = (TT_UShort)(dim_y >> 6);
-
+      metrics->x_ppem    = (TT_UShort)(dim_x >> 6);
+      metrics->y_ppem    = (TT_UShort)(dim_y >> 6);
+    }
+    
     size->ttmetrics.valid = FALSE;
 
     return TT_Reset_Size( size );
@@ -559,24 +481,11 @@
                              TT_UInt  pixel_width,
                              TT_UInt  pixel_height )
   {
-    FT_Size_Metrics*  metrics = &size->root.metrics;
-    TT_Face           face    = (TT_Face)size->root.face;
+    (void) pixel_width;
+    (void) pixel_height;
 
+    /* many things were pre-computed by the base layer */
 
-    if ( pixel_width  < 1 ) pixel_width  = 1;
-    if ( pixel_height < 1 ) pixel_height = 1;
-
-    metrics->x_ppem = pixel_width;
-    metrics->y_ppem = pixel_height;
-
-    metrics->x_scale = FT_MulDiv( metrics->x_ppem << 6,
-                                  0x10000L,
-                                  face->root.units_per_EM );
-
-    metrics->y_scale = FT_MulDiv( metrics->y_ppem << 6,
-                                  0x10000L,
-                                  face->root.units_per_EM );
-
     size->ttmetrics.valid = FALSE;
 
     return TT_Reset_Size( size );
@@ -722,15 +631,15 @@
     sizeof ( TT_SizeRec ),
     sizeof ( FT_GlyphSlotRec ),
 
-    "truetype",     /* driver name                         */
-    1,              /* driver version                      */
-    2,              /* driver requires FreeType 2 or above */
+    "truetype",      /* driver name                           */
+    100,             /* driver version == 1.0                 */
+    200,             /* driver requires FreeType 2.0 or above */
 
     (void*)0,
 
     (FTDriver_initDriver)        TT_Init_Driver,
     (FTDriver_doneDriver)        TT_Done_Driver,
-    (FTDriver_getInterface)      Get_Interface,
+    (FTDriver_getInterface)      0,     /* now extra interface for now */
 
     (FTDriver_initFace)          Init_Face,
     (FTDriver_doneFace)          TT_Done_Face,
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -31,6 +31,8 @@
 #undef  FT_COMPONENT
 #define FT_COMPONENT      trace_ttinterp
 
+#undef  NO_APPLE_PATENT
+#define APPLE_THRESHOLD  0x4000000
 
   /*************************************************************************/
   /*                                                                       */
@@ -1432,10 +1434,14 @@
 
     if ( v != 0 )
     {
+#ifdef NO_APPLE_PATENT
+      if ( ABS(CUR.F_dot_P) > APPLE_THRESHOLD )
+        zone->cur[point].x += distance;
+#else
       zone->cur[point].x += TT_MULDIV( distance,
                                        v * 0x10000L,
                                        CUR.F_dot_P );
-
+#endif
       zone->touch[point] |= FT_Curve_Tag_Touch_X;
     }
 
@@ -1443,10 +1449,14 @@
 
     if ( v != 0 )
     {
+#ifdef NO_APPLE_PATENT
+      if ( ABS(CUR.F_dot_P) > APPLE_THRESHOLD )
+        zone->cur[point].y += distance;
+#else
       zone->cur[point].y += TT_MULDIV( distance,
                                        v * 0x10000L,
                                        CUR.F_dot_P );
-
+#endif
       zone->touch[point] |= FT_Curve_Tag_Touch_Y;
     }
   }
@@ -4940,6 +4950,10 @@
 
     d = CUR_Func_project( zp.cur + p, zp.org + p );
 
+#ifdef NO_APPLE_PATENT
+    *x = TT_MULDIV( d, CUR.GS.freeVector.x, 0x4000 );
+    *y = TT_MULDIV( d, CUR.GS.freeVector.y, 0x4000 );
+#else
     *x = TT_MULDIV( d,
                     (TT_Long)CUR.GS.freeVector.x * 0x10000L,
                     CUR.F_dot_P );
@@ -4946,7 +4960,7 @@
     *y = TT_MULDIV( d,
                     (TT_Long)CUR.GS.freeVector.y * 0x10000L,
                     CUR.F_dot_P );
-
+#endif
     return SUCCESS;
   }
 
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -222,6 +222,7 @@
                           TT_Face    face )
   {
     TT_Error         error;
+    TT_ULong         format_tag;
     SFNT_Interface*  sfnt;
 
     sfnt = (SFNT_Interface*)face->sfnt;
@@ -246,7 +247,20 @@
     if ( FILE_Seek(0) )
       goto Exit;
 
-    /* Load collection directory if present, then font directory */
+    /* check that we have a valid TrueType file */
+    error = sfnt->load_format_tag( face, stream, face_index, &format_tag );
+    if (error) goto Exit;
+    
+    /* We must also be able to accept Mac/GX fonts, as well as OT ones */
+    if ( format_tag != 0x00010000 &&    /* MS fonts  */
+         format_tag != TTAG_true  )     /* Mac fonts */
+    {
+      FT_TRACE2(( "[not a valid TTF font]" ));
+      error = TT_Err_Invalid_File_Format;
+      goto Exit;
+    }
+
+    /* Load font directory */
     error = sfnt->load_directory( face, stream, face_index );
     if ( error ) goto Exit;