freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] ewaldhew-wip 03c2a16 38/52: Make PS objects copy over values


From: Hew Yih Shiuan Ewald
Subject: [freetype2] ewaldhew-wip 03c2a16 38/52: Make PS objects copy over values on init
Date: Mon, 10 Jul 2017 05:10:19 -0400 (EDT)

branch: ewaldhew-wip
commit 03c2a16430ea27d9454fc9ee64d39d53dc814dde
Author: Ewald Hew <address@hidden>
Commit: Ewald Hew <address@hidden>

    Make PS objects copy over values on init
---
 include/freetype/internal/psaux.h |  69 ++++++++---------
 src/psaux/psauxmod.c              |  10 +++
 src/psaux/psdecode.c              | 152 ++++++++++----------------------------
 src/psaux/psdecode.h              |  11 ++-
 src/psaux/psobjs.c                |  80 +++++++++++---------
 src/psaux/psobjs.h                |   8 +-
 6 files changed, 138 insertions(+), 192 deletions(-)

diff --git a/include/freetype/internal/psaux.h 
b/include/freetype/internal/psaux.h
index 0c9cf23..cbc3895 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -485,22 +485,20 @@ FT_BEGIN_HEADER
   typedef struct  PS_Builder_FuncsRec_
   {
     void
-    (*init)( PS_Builder    builder,
-             FT_Face       face,
-             FT_Size       size,
-             FT_GlyphSlot  slot,
-             FT_Bool       hinting );
+    (*init)( void*        builder,
+             FT_Bool      is_t1,
+             PS_Builder*  ps_builder );
 
     void
-    (*done)( PS_Builder   builder );
-
+    (*done)( PS_Builder*   builder );
+/*
     PS_Builder_Check_Points_Func   check_points;
     PS_Builder_Add_Point_Func      add_point;
     PS_Builder_Add_Point1_Func     add_point1;
     PS_Builder_Add_Contour_Func    add_contour;
     PS_Builder_Start_Point_Func    start_point;
     PS_Builder_Close_Contour_Func  close_contour;
-
+*/
   } PS_Builder_FuncsRec;
 
 
@@ -556,22 +554,19 @@ FT_BEGIN_HEADER
     FT_Outline*     base;
     FT_Outline*     current;
 
-    FT_Pos          pos_x;
-    FT_Pos          pos_y;
+    FT_Pos*         pos_x;
+    FT_Pos*         pos_y;
 
-    FT_Vector       left_bearing;
-    FT_Vector       advance;
+    FT_Vector*      left_bearing;
+    FT_Vector*      advance;
 
-    FT_BBox         bbox;          /* bounding box */
+    FT_BBox*        bbox;          /* bounding box */
     FT_Bool         path_begun;
     FT_Bool         load_points;
     FT_Bool         no_recurse;
 
     FT_Bool         metrics_only;
 
-    void*           hints_funcs;    /* hinter-specific */
-    void*           hints_globals;  /* hinter-specific */
-
     FT_Bool         is_t1;
 
     PS_Builder_FuncsRec  funcs;
@@ -607,15 +602,16 @@ FT_BEGIN_HEADER
 
 
   typedef FT_Error
-  (*PS_Decoder_Get_Glyph_Callback)( TT_Face    face,
-                                    FT_UInt    glyph_index,
-                                    FT_Byte**  pointer,
-                                    FT_ULong*  length );
+  (*CFF_Decoder_Get_Glyph_Callback)( TT_Face    face,
+                                     FT_UInt    glyph_index,
+                                     FT_Byte**  pointer,
+                                     FT_ULong*  length );
 
   typedef void
-  (*PS_Decoder_Free_Glyph_Callback)( TT_Face    face,
-                                     FT_Byte**  pointer,
-                                     FT_ULong   length );
+  (*CFF_Decoder_Free_Glyph_Callback)( TT_Face    face,
+                                      FT_Byte**  pointer,
+                                      FT_ULong   length );
+
 
   typedef struct  PS_Decoder_
   {
@@ -657,8 +653,8 @@ FT_BEGIN_HEADER
 
     FT_Bool            seac;
 
-    PS_Decoder_Get_Glyph_Callback   get_glyph_callback;
-    PS_Decoder_Free_Glyph_Callback  free_glyph_callback;
+    CFF_Decoder_Get_Glyph_Callback   get_glyph_callback;
+    CFF_Decoder_Free_Glyph_Callback  free_glyph_callback;
     
     /* Type 1 stuff */
     FT_Service_PsCMaps   psnames;      /* for seac */
@@ -675,6 +671,8 @@ FT_BEGIN_HEADER
     FT_Long*             buildchar;
     FT_UInt              len_buildchar;
 
+    void*                t1_parse_callback;
+
   } PS_Decoder;
 
   typedef const struct PS_Decoder_FuncsRec_*  PS_Decoder_Funcs;
@@ -683,9 +681,9 @@ FT_BEGIN_HEADER
   {
     void
     (*init)( PS_Decoder*     decoder,
-             FT_Face         face,
+             TT_Face         face,
              FT_Size         size,
-             FT_GlyphSlot    slot,
+             CFF_GlyphSlot   slot,
              FT_Byte**       glyph_names,
              PS_Blend        blend,
              FT_Bool         hinting,
@@ -1132,18 +1130,6 @@ FT_BEGIN_HEADER
   } CFF_Decoder_Zone;
 
 
-  typedef FT_Error
-  (*CFF_Decoder_Get_Glyph_Callback)( TT_Face    face,
-                                     FT_UInt    glyph_index,
-                                     FT_Byte**  pointer,
-                                     FT_ULong*  length );
-
-  typedef void
-  (*CFF_Decoder_Free_Glyph_Callback)( TT_Face    face,
-                                      FT_Byte**  pointer,
-                                      FT_ULong   length );
-
-
   typedef struct  CFF_Decoder_
   {
     CFF_Builder        builder;
@@ -1335,6 +1321,11 @@ FT_BEGIN_HEADER
     FT_UInt32
     (*cff_random)( FT_UInt32  r );
 
+    void
+    (*ps_decoder_init)( void*        decoder,
+                        FT_Bool      is_t1,
+                        PS_Decoder*  ps_decoder );
+
 
     T1_CMap_Classes  t1_cmap_classes;
 
diff --git a/src/psaux/psauxmod.c b/src/psaux/psauxmod.c
index eb94d54..d7223e2 100644
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -23,6 +23,7 @@
 #include "t1cmap.h"
 #include "psft.h"
 #include "cffdecode.h"
+#include "psdecode.h"
 
 #ifndef T1_CONFIG_OPTION_NO_AFM
 #include "afmparse.h"
@@ -62,6 +63,14 @@
 
 
   FT_CALLBACK_TABLE_DEF
+  const PS_Builder_FuncsRec  ps_builder_funcs =
+  {
+    ps_builder_init,          /* init */
+    ps_builder_done           /* done */
+  };
+
+
+  FT_CALLBACK_TABLE_DEF
   const T1_Builder_FuncsRec  t1_builder_funcs =
   {
     t1_builder_init,          /* init */
@@ -144,6 +153,7 @@
     &t1_decoder_funcs,
     t1_decrypt,
     cff_random,
+    ps_decoder_init,
 
     (const T1_CMap_ClassesRec*) &t1_cmap_classes,
 
diff --git a/src/psaux/psdecode.c b/src/psaux/psdecode.c
index 92d4326..8884415 100644
--- a/src/psaux/psdecode.c
+++ b/src/psaux/psdecode.c
@@ -2,7 +2,6 @@
 
 #include <ft2build.h>
 #include FT_INTERNAL_SERVICE_H
-#include FT_SERVICE_CFF_TABLE_LOAD_H
 
 #include "psdecode.h"
 #include "psobjs.h"
@@ -16,143 +15,74 @@
   /*    ps_decoder_init                                                    */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Initializes a given glyph decoder.                                 */
+  /*    Creates a decoder for the combined Type 1 / CFF interpreter.       */
   /*                                                                       */
   /* <InOut>                                                               */
   /*    decoder :: A pointer to the glyph builder to initialize.           */
   /*                                                                       */
   /* <Input>                                                               */
-  /*    face      :: The current face object.                              */
   /*                                                                       */
-  /*    size      :: The current size object.                              */
   /*                                                                       */
-  /*    slot      :: The current glyph object.                             */
   /*                                                                       */
-  /*    hinting   :: Whether hinting is active.                            */
   /*                                                                       */
-  /*    hint_mode :: The hinting mode.                                     */
   /*                                                                       */
   FT_LOCAL_DEF( void )
-  ps_decoder_init( PS_Decoder*     decoder,
-                   TT_Face         face,
-                   FT_Size         size,
-                   CFF_GlyphSlot   slot,
-                   FT_Byte**       glyph_names,
-                   PS_Blend        blend,
-                   FT_Bool         hinting,
-                   FT_Render_Mode  hint_mode,
-                   PS_Decoder_Get_Glyph_Callback   get_callback,
-                   PS_Decoder_Free_Glyph_Callback  free_callback )
+  ps_decoder_init( void*        decoder,
+                   FT_Bool      is_t1,
+                   PS_Decoder*  ps_decoder )
   {
-    CFF_Font  cff = (CFF_Font)face->extra.data;
+    FT_ZERO( ps_decoder );
 
-
-    /* clear everything */
-    FT_ZERO( decoder );
-
-    /* initialize builder */
-    ps_builder_init( &decoder->builder, face, size, slot, hinting );
-
-    if ( face->is_t1 )
+    if ( is_t1 )
     {
-      /* retrieve PSNames interface from list of current modules */
-      {
-        FT_Service_PsCMaps  psnames;
+      T1_Decoder  t1_decoder = (T1_Decoder)decoder;
 
+      ps_builder_init( &t1_decoder->builder,
+                       is_t1,
+                       &ps_decoder->builder );
 
-        FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
-        if ( !psnames )
-        {
-          FT_ERROR(( "ps_decoder_init:"
-                     " the `psnames' module is not available\n" ));
-          return FT_THROW( Unimplemented_Feature );
-        }
+      ps_decoder->psnames            =  t1_decoder->psnames;
 
-        decoder->psnames = psnames;
-      }
+      ps_decoder->num_glyphs         =  t1_decoder->num_glyphs;
+      ps_decoder->glyph_names        =  t1_decoder->glyph_names;
+      ps_decoder->hint_mode          =  t1_decoder->hint_mode;
+      ps_decoder->blend              =  t1_decoder->blend;
+      /* ps_decoder->t1_parse_callback  =  t1_decoder->parse_callback; */
 
-      /* decoder->buildchar and decoder->len_buildchar have to be  */
-      /* initialized by the caller since we cannot know the length */
-      /* of the BuildCharArray                                     */
+      ps_decoder->num_locals         =  t1_decoder->num_subrs;
+      ps_decoder->locals             =  t1_decoder->subrs;
+      ps_decoder->locals_len         =  t1_decoder->subrs_len;
+      ps_decoder->locals_hash        =  t1_decoder->subrs_hash;
 
-      decoder->num_glyphs     = (FT_UInt)face->root.num_glyphs;
-      decoder->glyph_names    = glyph_names;
-      decoder->blend          = blend;
+      ps_decoder->buildchar          =  t1_decoder->buildchar;
+      ps_decoder->len_buildchar      =  t1_decoder->len_buildchar;
     }
     else
     {
-      /* initialize Type2 decoder */
-      decoder->cff          = cff;
-      decoder->num_globals  = cff->global_subrs_index.count;
-      decoder->globals      = cff->global_subrs;
-      decoder->globals_bias = cff_compute_bias(
-                                cff->top_font.font_dict.charstring_type,
-                                decoder->num_globals );
-    }
-
-    decoder->hint_mode    = hint_mode;
-
-    decoder->get_glyph_callback  = get_callback;
-    decoder->free_glyph_callback = free_callback;
-  }
-
-
-  /* this function is used to select the subfont */
-  /* and the locals subrs array                  */
-  FT_LOCAL_DEF( FT_Error )
-  ps_decoder_prepare( PS_Decoder*  decoder,
-                      FT_Size      size,
-                      FT_UInt      glyph_index )
-  {
-    PS_Builder   *builder = &decoder->builder;
-    FT_Error      error   = FT_Err_Ok;
-
-    if ( !builder->face->is_t1 )
-    {
-      CFF_Font      cff     = (CFF_Font)builder->face->extra.data;
-      CFF_SubFont   sub     = &cff->top_font;
-
-      FT_Service_CFFLoad  cffload = (FT_Service_CFFLoad)cff->cffload;
-
-      /* manage CID fonts */
-      if ( cff->num_subfonts )
-      {
-        FT_Byte  fd_index = cffload->fd_select_get( &cff->fd_select, 
glyph_index );
-
+      CFF_Decoder*  cff_decoder = (CFF_Decoder*)decoder;
 
-        if ( fd_index >= cff->num_subfonts )
-        {
-          FT_TRACE4(( "cff_decoder_prepare: invalid CID subfont index\n" ));
-          error = FT_THROW( Invalid_File_Format );
-          goto Exit;
-        }
+      ps_builder_init( &cff_decoder->builder,
+                       is_t1,
+                       &ps_decoder->builder );
 
-        FT_TRACE3(( "  in subfont %d:\n", fd_index ));
+      ps_decoder->cff                 =  cff_decoder->cff;
+      ps_decoder->current_subfont     =  cff_decoder->current_subfont;
 
-        sub = cff->subfonts[fd_index];
+      ps_decoder->num_globals         =  cff_decoder->num_globals;
+      ps_decoder->globals             =  cff_decoder->globals;
+      ps_decoder->globals_bias        =  cff_decoder->globals_bias;
+      ps_decoder->num_locals          =  cff_decoder->num_locals;
+      ps_decoder->locals              =  cff_decoder->locals;
+      ps_decoder->locals_bias         =  cff_decoder->locals_bias;
 
-        if ( builder->hints_funcs && size )
-        {
-          CFF_Internal  internal = (CFF_Internal)size->internal->module_data;
+      ps_decoder->glyph_width         =  cff_decoder->glyph_width;
+      ps_decoder->nominal_width       =  cff_decoder->nominal_width;
+      ps_decoder->width_only          =  cff_decoder->width_only;
 
+      ps_decoder->hint_mode           =  cff_decoder->hint_mode;
 
-          /* for CFFs without subfonts, this value has already been set */
-          builder->hints_globals = (void *)internal->subfonts[fd_index];
-        }
-
-        decoder->num_locals    = sub->local_subrs_index.count;
-        decoder->locals        = sub->local_subrs;
-        decoder->locals_bias   = cff_compute_bias(
-                                   
decoder->cff->top_font.font_dict.charstring_type,
-                                   decoder->num_locals );
-
-        decoder->glyph_width   = sub->private_dict.default_width;
-        decoder->nominal_width = sub->private_dict.nominal_width;
-
-        decoder->current_subfont = sub;
-      }
+      ps_decoder->get_glyph_callback  =  cff_decoder->get_glyph_callback;
+      ps_decoder->free_glyph_callback =  cff_decoder->free_glyph_callback;
     }
-
-  Exit:
-    return error;
   }
+
diff --git a/src/psaux/psdecode.h b/src/psaux/psdecode.h
index 2a53065..dd7e6f2 100644
--- a/src/psaux/psdecode.h
+++ b/src/psaux/psdecode.h
@@ -5,9 +5,16 @@
 #include <ft2build.h>
 #include FT_INTERNAL_POSTSCRIPT_AUX_H
 
-#include "cffdecode.h"
-#include "t1decode.h"
 
+FT_BEGIN_HEADER
 
+  FT_LOCAL( void )
+  ps_decoder_init( void*        decoder,
+                   FT_Bool      is_t1,
+                   PS_Decoder*  ps_decoder );
+
+
+FT_END_HEADER
 
 #endif
+
diff --git a/src/psaux/psobjs.c b/src/psaux/psobjs.c
index b009dba..a4dd448 100644
--- a/src/psaux/psobjs.c
+++ b/src/psaux/psobjs.c
@@ -2052,53 +2052,63 @@
   /*    hinting :: Whether hinting should be applied.                      */
   /*                                                                       */
   FT_LOCAL_DEF( void )
-  ps_builder_init( PS_Builder*    builder,
-                   TT_Face        face,
-                   FT_Size        size,
-                   CFF_GlyphSlot  glyph,
-                   FT_Bool        hinting )
+  ps_builder_init( void*        builder,
+                   FT_Bool      is_t1,
+                   PS_Builder*  ps_builder )
   {
-    builder->path_begun  = 0;
-    builder->load_points = 1;
+    FT_ZERO( ps_builder );
 
-    builder->face   = face;
-    builder->glyph  = glyph;
-    builder->memory = face->root.memory;
-
-    if ( glyph )
+    if ( is_t1 )
     {
-      FT_GlyphLoader  loader = glyph->root.internal->loader;
+      T1_Builder  t1builder = (T1_Builder)builder;
 
+      ps_builder->face           = (TT_Face)t1builder->face;
+      ps_builder->glyph          = t1builder->glyph;
+      ps_builder->memory         =  t1builder->memory;
+      ps_builder->loader         =  t1builder->loader;
+      ps_builder->base           =  t1builder->base;
+      ps_builder->current        =  t1builder->current;
 
-      builder->loader  = loader;
-      builder->base    = &loader->base.outline;
-      builder->current = &loader->current.outline;
-      FT_GlyphLoader_Rewind( loader );
+      ps_builder->pos_x          = &t1builder->pos_x;
+      ps_builder->pos_y          = &t1builder->pos_y;
 
-      builder->hints_globals = NULL;
-      builder->hints_funcs   = NULL;
+      ps_builder->left_bearing   = &t1builder->left_bearing;
+      ps_builder->advance        = &t1builder->advance;
 
-      if ( hinting && size )
-      {
-        CFF_Internal  internal = (CFF_Internal)size->internal->module_data;
+      ps_builder->bbox           = &t1builder->bbox;
+      ps_builder->path_begun     =  0;
+      ps_builder->load_points    =  t1builder->load_points;
+      ps_builder->no_recurse     =  t1builder->no_recurse;
 
-        if ( internal )
-        {
-          builder->hints_globals = (void *)internal->topfont;
-          builder->hints_funcs   = glyph->root.internal->glyph_hints;
-        }
-      }
+      ps_builder->metrics_only   =  t1builder->metrics_only;
     }
+    else
+    {
+      CFF_Builder*  cffbuilder = (CFF_Builder*)builder;
 
-    builder->pos_x = 0;
-    builder->pos_y = 0;
+      ps_builder->face           = cffbuilder->face;
+      ps_builder->memory         =  cffbuilder->memory;
+      ps_builder->glyph          =  cffbuilder->glyph;
+      ps_builder->loader         =  cffbuilder->loader;
+      ps_builder->base           =  cffbuilder->base;
+      ps_builder->current        =  cffbuilder->current;
 
-    builder->left_bearing.x = 0;
-    builder->left_bearing.y = 0;
-    builder->advance.x      = 0;
-    builder->advance.y      = 0;
+      ps_builder->pos_x          = &cffbuilder->pos_x;
+      ps_builder->pos_y          = &cffbuilder->pos_y;
+
+      ps_builder->left_bearing   = &cffbuilder->left_bearing;
+      ps_builder->advance        = &cffbuilder->advance;
+
+      ps_builder->bbox           = &cffbuilder->bbox;
+      ps_builder->path_begun     =  cffbuilder->path_begun;
+      ps_builder->load_points    =  cffbuilder->load_points;
+      ps_builder->no_recurse     =  cffbuilder->no_recurse;
+
+      ps_builder->metrics_only   =  cffbuilder->metrics_only;
+    }
 
-    /* builder->funcs = ps_builder_funcs; */
+    ps_builder->is_t1            = is_t1;
+    ps_builder->funcs            = ps_builder_funcs;
   }
 
 
diff --git a/src/psaux/psobjs.h b/src/psaux/psobjs.h
index 64e85c5..1f68419 100644
--- a/src/psaux/psobjs.h
+++ b/src/psaux/psobjs.h
@@ -242,11 +242,9 @@ FT_BEGIN_HEADER
   /*************************************************************************/
 
   FT_LOCAL( void )
-  ps_builder_init( PS_Builder*    builder,
-                   TT_Face        face,
-                   FT_Size        size,
-                   CFF_GlyphSlot  glyph,
-                   FT_Bool        hinting );
+  ps_builder_init( void*        builder,
+                   FT_Bool      is_t1,
+                   PS_Builder*  ps_builder );
 
   FT_LOCAL( void )
   ps_builder_done( PS_Builder*  builder );



reply via email to

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