freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] ewaldhew-cleaned e2ca0a4 04/41: [psaux, cff] Create new PSAu


From: Hew Yih Shiuan Ewald
Subject: [freetype2] ewaldhew-cleaned e2ca0a4 04/41: [psaux, cff] Create new PSAux service interface entries
Date: Mon, 21 Aug 2017 02:19:54 -0400 (EDT)

branch: ewaldhew-cleaned
commit e2ca0a446f619b2c6113c15f132984d34572c7f2
Author: Ewald Hew <address@hidden>
Commit: Ewald Hew <address@hidden>

    [psaux, cff] Create new PSAux service interface entries
    
    NOTE: Does not compile!
    
    * include/freetype/internal/psaux.h: Add declarations for new function 
tables.
    Minor fix for forward declaration of CFF_Builder.
    * src/psaux/psauxmod.c: Update the interface.
    
    * include/freetype/internal/tttypes.h (TT_FaceRec): Add service interface 
to CFF_Face(TT_Face).
    
    * src/cff/cffgload.c, src/cff/cffobjs.c, src/cff/cffparse.c: Update 
function calls to use psaux service.
---
 include/freetype/internal/psaux.h   | 99 ++++++++++++++++++++++++++++++++++++-
 include/freetype/internal/tttypes.h |  3 ++
 src/cff/cffgload.c                  | 48 +++++++++---------
 src/cff/cffobjs.c                   | 13 +++++
 src/cff/cffparse.c                  | 20 ++++++--
 src/psaux/psauxmod.c                | 33 +++++++++++++
 6 files changed, 187 insertions(+), 29 deletions(-)

diff --git a/include/freetype/internal/psaux.h 
b/include/freetype/internal/psaux.h
index 933d052..e29d452 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -25,6 +25,7 @@
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_TYPE1_TYPES_H
 #include FT_INTERNAL_HASH_H
+#include FT_INTERNAL_TRUETYPE_TYPES_H
 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
 
 
@@ -704,6 +705,67 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*************************************************************************/
+  /*****                                                               *****/
+  /*****                        CFF BUILDER                            *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  typedef struct  CFF_Builder_ CFF_Builder;
+
+
+  typedef FT_Error
+  (*CFF_Builder_Check_Points_Func)( CFF_Builder*  builder,
+                                    FT_Int        count );
+
+  typedef void
+  (*CFF_Builder_Add_Point_Func)( CFF_Builder*  builder,
+                                 FT_Pos        x,
+                                 FT_Pos        y,
+                                 FT_Byte       flag );
+  typedef FT_Error
+  (*CFF_Builder_Add_Point1_Func)( CFF_Builder*  builder,
+                                  FT_Pos        x,
+                                  FT_Pos        y );
+  typedef FT_Error
+  (*CFF_Builder_Start_Point_Func)( CFF_Builder*  builder,
+                                   FT_Pos        x,
+                                   FT_Pos        y );
+  typedef void
+  (*CFF_Builder_Close_Contour_Func)( CFF_Builder*  builder );
+
+  /* static */
+  typedef FT_Error
+  (*CFF_Builder_Add_Contour_Func)( CFF_Builder*  builder );
+
+  typedef const struct CFF_Builder_FuncsRec_*  CFF_Builder_Funcs;
+
+  typedef struct  CFF_Builder_FuncsRec_
+  {
+    /* static */
+    void
+    (*init)( CFF_Builder*   builder,
+             TT_Face        face,
+             CFF_Size       size,
+             CFF_GlyphSlot  glyph,
+             FT_Bool        hinting );
+
+    /* static */
+    void
+    (*done)( CFF_Builder*  builder );
+
+    CFF_Builder_Check_Points_Func   check_points;
+    CFF_Builder_Add_Point_Func      add_point;
+    CFF_Builder_Add_Point1_Func     add_point1;
+    CFF_Builder_Add_Contour_Func    add_contour;
+    CFF_Builder_Start_Point_Func    start_point;
+    CFF_Builder_Close_Contour_Func  close_contour;
+
+  } CFF_Builder_FuncsRec;
+
+
+  /*************************************************************************/
   /*                                                                       */
   /* <Structure>                                                           */
   /*    CFF_Builder                                                        */
@@ -748,7 +810,7 @@ FT_BEGIN_HEADER
   /*                                                                       */
   /*    hints_globals :: Auxiliary pointer for hinting.                    */
   /*                                                                       */
-  typedef struct  CFF_Builder_
+  struct  CFF_Builder_
   {
     FT_Memory       memory;
     TT_Face         face;
@@ -772,7 +834,10 @@ FT_BEGIN_HEADER
 
     void*           hints_funcs;    /* hinter-specific */
     void*           hints_globals;  /* hinter-specific */
-  } CFF_Builder;
+
+    CFF_Builder_FuncsRec  funcs;
+
+  };
 
 
   /*************************************************************************/
@@ -846,6 +911,34 @@ FT_BEGIN_HEADER
 
   } CFF_Decoder;
 
+  typedef const struct CFF_Decoder_FuncsRec_*  CFF_Decoder_Funcs;
+
+  typedef struct  CFF_Decoder_FuncsRec_
+  {
+    void
+    (*init)( CFF_Decoder*    decoder,
+             TT_Face         face,
+             CFF_Size        size,
+             CFF_GlyphSlot   slot,
+             FT_Bool         hinting,
+             FT_Render_Mode  hint_mode );
+
+    FT_Error
+    (*prepare)( CFF_Decoder*  decoder,
+                CFF_Size      size,
+                FT_UInt       glyph_index );
+
+    FT_Error
+    (*parse_charstrings)( CFF_Decoder*  decoder,
+                          FT_Byte*      charstring_base,
+                          FT_ULong      charstring_len
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+/*TODO(ewaldhew): seems hacky, is there a better way to do this?*/
+                         ,FT_Bool       in_dict
+#endif
+                          );
+
+  } CFF_Decoder_FuncsRec;
 
   /*************************************************************************/
   /*************************************************************************/
@@ -959,6 +1052,8 @@ FT_BEGIN_HEADER
     /* fields after this comment line were added after version 2.1.10 */
     const AFM_Parser_FuncsRec*  afm_parser_funcs;
 
+    const CFF_Decoder_FuncsRec*  cff_decoder_funcs;
+
   } PSAux_ServiceRec, *PSAux_Service;
 
   /* backward compatible type definition */
diff --git a/include/freetype/internal/tttypes.h 
b/include/freetype/internal/tttypes.h
index c0758e2..0fcc6b0 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -1445,6 +1445,9 @@ FT_BEGIN_HEADER
     void*                 var;
 #endif
 
+    /* a typeless pointer to the PostScript Aux service */
+    void*                 psaux;
+
 
     /***********************************************************************/
     /*                                                                     */
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 79a5d81..a5fde87 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -21,6 +21,7 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_SFNT_H
 #include FT_INTERNAL_CALC_H
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
 #include FT_OUTLINE_H
 #include FT_CFF_DRIVER_H
 
@@ -41,8 +42,6 @@
 #define FT_COMPONENT  trace_cffgload
 
 
-
-
   FT_LOCAL_DEF( FT_Error )
   cff_get_glyph_data( TT_Face    face,
                       FT_UInt    glyph_index,
@@ -144,11 +143,13 @@
     FT_Int       glyph_index;
     CFF_Font     cff = (CFF_Font)face->other;
 
+    PSAux_Service            psaux         = (PSAux_Service)face->psaux;
+    const CFF_Decoder_Funcs  decoder_funcs = psaux->cff_decoder_funcs;
 
     *max_advance = 0;
 
     /* Initialize load decoder */
-    cff_decoder_init( &decoder, face, 0, 0, 0, 0 );
+    decoder_funcs->init( &decoder, face, 0, 0, 0, 0 );
 
     decoder.builder.metrics_only = 1;
     decoder.builder.load_points  = 0;
@@ -167,12 +168,12 @@
                                   &charstring, &charstring_len );
       if ( !error )
       {
-        error = cff_decoder_prepare( &decoder, size, glyph_index );
+        error = decoder_funcs->prepare( &decoder, size, glyph_index );
         if ( !error )
-          error = cff_decoder_parse_charstrings( &decoder,
-                                                 charstring,
-                                                 charstring_len,
-                                                 0 );
+          error = decoder_funcs->parse_charstrings( &decoder,
+                                                    charstring,
+                                                    charstring_len,
+                                                    0 );
 
         cff_free_glyph_data( face, &charstring, &charstring_len );
       }
@@ -202,6 +203,9 @@
     FT_Bool      hinting, scaled, force_scaling;
     CFF_Font     cff  = (CFF_Font)face->extra.data;
 
+    PSAux_Service            psaux         = (PSAux_Service)face->psaux;
+    const CFF_Decoder_Funcs  decoder_funcs = psaux->cff_decoder_funcs;
+
     FT_Matrix    font_matrix;
     FT_Vector    font_offset;
 
@@ -399,8 +403,8 @@
       FT_ULong  charstring_len;
 
 
-      cff_decoder_init( &decoder, face, size, glyph, hinting,
-                        FT_LOAD_TARGET_MODE( load_flags ) );
+      decoder_funcs->init( &decoder, face, size, glyph, hinting,
+                           FT_LOAD_TARGET_MODE( load_flags ) );
 
       /* this is for pure CFFs */
       if ( load_flags & FT_LOAD_ADVANCE_ONLY )
@@ -415,23 +419,23 @@
       if ( error )
         goto Glyph_Build_Finished;
 
-      error = cff_decoder_prepare( &decoder, size, glyph_index );
+      error = decoder_funcs->prepare( &decoder, size, glyph_index );
       if ( error )
         goto Glyph_Build_Finished;
 
 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
       /* choose which CFF renderer to use */
       if ( driver->hinting_engine == FT_CFF_HINTING_FREETYPE )
-        error = cff_decoder_parse_charstrings( &decoder,
-                                               charstring,
-                                               charstring_len,
-                                               0 );
+        error = decoder_funcs->parse_charstrings( &decoder,
+                                                  charstring,
+                                                  charstring_len,
+                                                  0 );
       else
 #endif
       {
-        error = cf2_decoder_parse_charstrings( &decoder,
-                                               charstring,
-                                               charstring_len );
+        error = decoder_funcs->parse_charstrings( &decoder,
+                                                  charstring,
+                                                  charstring_len );
 
         /* Adobe's engine uses 16.16 numbers everywhere;              */
         /* as a consequence, glyphs larger than 2000ppem get rejected */
@@ -444,9 +448,9 @@
           force_scaling = TRUE;
           glyph->hint   = hinting;
 
-          error = cf2_decoder_parse_charstrings( &decoder,
-                                                 charstring,
-                                                 charstring_len );
+          error = decoder_funcs->parse_charstrings( &decoder,
+                                                    charstring,
+                                                    charstring_len );
         }
       }
 
@@ -484,7 +488,7 @@
   Glyph_Build_Finished:
       /* save new glyph tables, if no error */
       if ( !error )
-        cff_builder_done( &decoder.builder );
+        decoder.builder.funcs.done( &decoder.builder );
       /* XXX: anything to do for broken glyph entry? */
     }
 
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index 6161393..de97f50 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -39,6 +39,8 @@
 
 #include "cfferrs.h"
 
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -493,6 +495,7 @@
     SFNT_Service        sfnt;
     FT_Service_PsCMaps  psnames;
     PSHinter_Service    pshinter;
+    PSAux_Service       psaux;
     FT_Bool             pure_cff    = 1;
     FT_Bool             cff2        = 0;
     FT_Bool             sfnt_format = 0;
@@ -513,6 +516,16 @@
     pshinter = (PSHinter_Service)FT_Get_Module_Interface(
                  library, "pshinter" );
 
+    psaux = (PSAux_Service)FT_Get_Module_Interface(
+              library, "psaux" );
+    if ( !psaux )
+    {
+      FT_ERROR(( "cff_face_init: cannot access `psaux' module\n" ));
+      error = FT_THROW( Missing_Module );
+      goto Exit;
+    }
+    face->psaux = psaux;
+
     FT_TRACE2(( "CFF driver\n" ));
 
     /* create input stream from resource */
diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c
index 9d7bf6d..63f20a1 100644
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -21,10 +21,10 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_CALC_H
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
 
 #include "cfferrs.h"
 #include "cffpic.h"
-#include "cffgload.h"
 #include "cffload.h"
 
 
@@ -1305,6 +1305,7 @@
     FT_UNUSED( library );
 
 
+
     parser->top    = parser->stack;
     parser->start  = start;
     parser->limit  = limit;
@@ -1388,10 +1389,19 @@
         cff_rec.top_font.font_dict.num_axes    = parser->num_axes;
         decoder.cff                            = &cff_rec;
 
-        error = cff_decoder_parse_charstrings( &decoder,
-                                               charstring_base,
-                                               charstring_len,
-                                               1 );
+        psaux = (PSAux_Service)FT_Get_Module_Interface(
+                  library, "psaux" );
+        if ( !psaux )
+        {
+          FT_ERROR(( "cff_parser_run: cannot access `psaux' module\n" ));
+          error = FT_THROW( Missing_Module );
+          goto Exit;
+        }
+        
+        error = psaux->cff_decoder_funcs->parse_charstrings( &decoder,
+                                                             charstring_base,
+                                                             charstring_len,
+                                                             1 );
 
         /* Now copy the stack data in the temporary decoder object,    */
         /* converting it back to charstring number representations     */
diff --git a/src/psaux/psauxmod.c b/src/psaux/psauxmod.c
index 1f589ce..cd9f525 100644
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -21,6 +21,8 @@
 #include "psobjs.h"
 #include "t1decode.h"
 #include "t1cmap.h"
+#include "cf2ft.h"
+#include "cffdecode.h"
 
 #ifndef T1_CONFIG_OPTION_NO_AFM
 #include "afmparse.h"
@@ -104,6 +106,35 @@
   };
 
 
+  FT_CALLBACK_TABLE_DEF
+  const CFF_Builder_FuncsRec  cff_builder_funcs =
+  {
+    cff_builder_init,          /* init */
+    cff_builder_done,          /* done */
+
+    cff_check_points,          /* check_points  */
+    cff_builder_add_point,     /* add_point     */
+    cff_builder_add_point1,    /* add_point1    */
+    cff_builder_add_contour,   /* add_contour   */
+    cff_builder_start_point,   /* start_point   */
+    cff_builder_close_contour  /* close_contour */
+  };
+
+
+  FT_CALLBACK_TABLE_DEF
+  const CFF_Decoder_FuncsRec  cff_decoder_funcs =
+  {
+    cff_decoder_init,              /* init              */
+    cff_decoder_prepare,           /* prepare           */
+
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+    cff_decoder_parse_charstrings  /* parse_charstrings */
+#else
+    cf2_decoder_parse_charstrings
+#endif
+  };
+
+
   static
   const PSAux_Interface  psaux_interface =
   {
@@ -120,6 +151,8 @@
 #else
     0,
 #endif
+
+    &cff_decoder_funcs,
   };
 
 



reply via email to

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