Commit 994d7747fb075447818af6cfdd40e1a493257c5a

David Turner 2000-06-25T04:49:19

various hacks to the TrueType driver that I cannot explain now, but they'll be very useful in the near future :-)

diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index 8ad78e4..7b209f4 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -1053,6 +1053,8 @@
   /* a function type used for the truetype bytecode interpreter hooks */
   typedef FT_Error  (*TT_Interpreter)( void*  exec_context );
 
+  /* forward declaration */
+  typedef struct TT_Loader_  TT_Loader;
 
   /*************************************************************************/
   /*                                                                       */
@@ -1084,6 +1086,70 @@
 
   /*************************************************************************/
   /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Access_Glyph_Frame                                              */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Seeks a stream to the start of a given glyph element, and          */
+  /*    opens a frame for it..                                             */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    loader      :: the current TrueType glyph loader object            */
+  /*    glyph index :: index of glyph to access                            */
+  /*    offset      :: offset of glyph according to locations table        */
+  /*    byte_count  :: size of frame in bytes                              */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    TrueType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    This function is normally equivalent to FILE_Seek(offset)          */
+  /*    followed by ACCESS_Frame(byte_count) with the loader's stream      */
+  /*    but alternative formats (compressed ones) might use something      */
+  /*    different..                                                        */
+  /*                                                                       */
+  typedef
+  FT_Error  (*TT_Access_Glyph_Frame_Func)( TT_Loader*  loader,
+                                           FT_UInt     glyph_index,
+                                           FT_ULong    offset,
+                                           FT_UInt     byte_count );
+  
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Load_Glyph_Element                                              */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Reads one glyph element (its header, a simple glyph, or a          */
+  /*    composite) from the loader's current stream frame..                */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    loader      :: the current TrueType glyph loader object            */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    TrueType error code.  0 means success.                             */
+  /*                                                                       */
+  typedef
+  FT_Error  (*TT_Load_Glyph_Element_Func)( TT_Loader*  loader );
+  
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Forget_Frame_Element                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Closes the current loader stream frame for the glyph..             */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    loader      :: the current TrueType glyph loader object            */
+  /*                                                                       */
+  typedef
+  void      (*TT_Forget_Glyph_Frame_Func)( TT_Loader*  loader );
+
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /*                         TrueType Face Type                            */
   /*                                                                       */
   /* <Struct>                                                              */
@@ -1276,6 +1342,12 @@
     /* might need something different, e.g. Type 42 fonts              */
     TT_Goto_Table_Func       goto_table;
 
+    TT_Access_Glyph_Frame_Func  access_glyph_frame;
+    TT_Load_Glyph_Element_Func  read_glyph_header;
+    TT_Load_Glyph_Element_Func  read_simple_glyph;
+    TT_Load_Glyph_Element_Func  read_composite_glyph;
+    TT_Forget_Glyph_Frame_Func  forget_glyph_frame;
+
     /* a typeless pointer to the SFNT_Interface table used to load     */
     /* the basic TrueType tables in the face object                    */
     void*              sfnt;
@@ -1347,7 +1419,7 @@
     /*                                                                     */
     /***********************************************************************/
 
-    void*              other;
+    FT_Generic      extra;
 
   } TT_FaceRec;
 
@@ -1397,7 +1469,7 @@
   typedef struct TT_ExecContextRec_*  TT_ExecContext;
 
  /* glyph loader structure */
-  typedef struct  TT_Loader_
+  struct  TT_Loader_
   {
     FT_Face         face;
     FT_Size         size;
@@ -1427,8 +1499,11 @@
     TT_ExecContext  exec;
     FT_Byte*        instructions;
     FT_ULong        ins_pos;
+    
+    /* for possible extensibility in other formats */
+    void*           other;
 
-  } TT_Loader;
+  };
 
 
 
diff --git a/src/cff/t2gload.c b/src/cff/t2gload.c
index 31b7c93..b877eae 100644
--- a/src/cff/t2gload.c
+++ b/src/cff/t2gload.c
@@ -333,7 +333,7 @@
                          T2_Size      size,
                          T2_GlyphSlot slot )
   {
-    CFF_Font*  cff = (CFF_Font*)face->other;
+    CFF_Font*  cff = (CFF_Font*)face->extra.data;
 
 
     /* clear everything */
@@ -1608,7 +1608,7 @@
     T2_Decoder  decoder;
     TT_Face     face = (TT_Face)glyph->root.face;
     FT_Bool     hinting;
-    CFF_Font*   cff = (CFF_Font*)face->other;
+    CFF_Font*   cff = (CFF_Font*)face->extra.data;
 
 
     if ( load_flags & FT_LOAD_NO_RECURSE )
diff --git a/src/cff/t2objs.c b/src/cff/t2objs.c
index e59952d..14a880d 100644
--- a/src/cff/t2objs.c
+++ b/src/cff/t2objs.c
@@ -122,7 +122,7 @@
       if ( ALLOC( cff, sizeof ( *cff ) ) )
         goto Exit;
 
-      face->other = cff;
+      face->extra.data = cff;
       error = T2_Load_CFF_Font( stream, face_index, cff );
       if ( error )
         goto Exit;
@@ -164,13 +164,13 @@
       sfnt->done_face( face );
 
     {
-      CFF_Font*  cff = (CFF_Font*)face->other;
+      CFF_Font*  cff = (CFF_Font*)face->extra.data;
 
 
       if ( cff )
       {
         T2_Done_CFF_Font( cff );
-        FREE( face->other );
+        FREE( face->extra.data );
       }
     }
   }
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 15d7183..f671a7a 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -250,12 +250,12 @@
 
 
   static
-  FT_Error  TT_Load_Simple_Glyph( TT_Loader*  load,
-                                  FT_Int      n_contours )
+  FT_Error  TT_Load_Simple_Glyph( TT_Loader*  load )
   {
     FT_Error         error;
-    FT_Stream        stream  = load->stream;
-    FT_GlyphLoader*  gloader = load->gloader;
+    FT_Stream        stream     = load->stream;
+    FT_GlyphLoader*  gloader    = load->gloader;
+    FT_Int           n_contours = load->n_contours;
     FT_Outline*      outline;
     TT_Face          face    = (TT_Face)load->face;
     TT_GlyphSlot     slot    = (TT_GlyphSlot)load->glyph;
@@ -405,8 +405,7 @@
 
 
   static
-  FT_Error  TT_Load_Composite_Glyph( TT_Loader*  loader,
-                                     FT_UInt     byte_count )
+  FT_Error  TT_Load_Composite_Glyph( TT_Loader*  loader )
   {
     FT_Error         error;
     FT_Stream        stream = loader->stream;
@@ -490,6 +489,16 @@
   }
 
 
+  LOCAL_FUNC
+  void  TT_Init_Glyph_Loading( TT_Face  face )
+  {
+    face->access_glyph_frame   = TT_Access_Glyph_Frame;
+    face->read_glyph_header    = TT_Load_Glyph_Header;
+    face->read_simple_glyph    = TT_Load_Simple_Glyph;
+    face->read_composite_glyph = TT_Load_Composite_Glyph;
+    face->forget_glyph_frame   = TT_Forget_Glyph_Frame;
+  }
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -708,13 +717,13 @@
     offset = loader->glyf_offset + offset;
 
     /* access glyph frame */
-    error = TT_Access_Glyph_Frame( loader, glyph_index, offset, count );
+    error = face->access_glyph_frame( loader, glyph_index, offset, count );
     if (error) goto Exit;
 
     opened_frame = 1;
 
     /* read first glyph header */
-    error = TT_Load_Glyph_Header( loader );
+    error = face->read_glyph_header( loader );
     if (error) goto Fail;
 
     contours_count = loader->n_contours;
@@ -744,7 +753,7 @@
       error = FT_GlyphLoader_Check_Points( gloader, 0, contours_count );
       if (error) goto Fail;
 
-      error = TT_Load_Simple_Glyph( loader, contours_count );
+      error = face->read_simple_glyph( loader );
       if (error) goto Fail;
       
 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
@@ -779,10 +788,10 @@
       start_contour = gloader->base.outline.n_contours;
     
       
-      error = TT_Load_Composite_Glyph( loader, count );
+      error = face->read_composite_glyph( loader );
       if (error) goto Fail;
 
-      TT_Forget_Glyph_Frame( loader );
+      face->forget_glyph_frame( loader );
       opened_frame = 0;
 
       /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */
@@ -1031,7 +1040,7 @@
 
   Fail:
     if (opened_frame)
-      TT_Forget_Glyph_Frame( loader );
+      face->forget_glyph_frame( loader );
 
   Exit:
     return error;
diff --git a/src/truetype/ttgload.h b/src/truetype/ttgload.h
index a559f87..d703921 100644
--- a/src/truetype/ttgload.h
+++ b/src/truetype/ttgload.h
@@ -36,6 +36,10 @@
                         FT_Short*       bearing,
                         FT_UShort*      advance );
 
+
+  LOCAL_DEF
+  void  TT_Init_Glyph_Loading( TT_Face  face );
+
   LOCAL_DEF
   FT_Error  TT_Load_Glyph( TT_Size       size,
                            TT_GlyphSlot  glyph,
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index f160fd2..f167ec4 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -27,6 +27,7 @@
 #include <ttobjs.h>
 
 #include <ttpload.h>
+#include <ttgload.h>
 #include <freetype/internal/tterrors.h>
 
 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
@@ -189,6 +190,9 @@
             TT_Load_CVT      ( face, stream ) ||
             TT_Load_Programs ( face, stream );
 
+    /* initialise standard glyph loading routines */
+    TT_Init_Glyph_Loading( face );
+
   Exit:
     return error;
      
@@ -217,6 +221,9 @@
 
     SFNT_Interface*  sfnt = face->sfnt;
 
+    /* for "extended TrueType formats" (i.e. compressed versions) */
+    if (face->extra.finalizer)
+      face->extra.finalizer( face->extra.data );
 
     if ( sfnt )
       sfnt->done_face( face );