freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] ewaldhew-wip 0d754a7 32/36: add hinting engine modes type1


From: Hew Yih Shiuan Ewald
Subject: [freetype2] ewaldhew-wip 0d754a7 32/36: add hinting engine modes type1
Date: Tue, 4 Jul 2017 06:47:13 -0400 (EDT)

branch: ewaldhew-wip
commit 0d754a7c842dbaaa105aaaa54fad814c36a3f860
Author: Ewald Hew <address@hidden>
Commit: Ewald Hew <address@hidden>

    add hinting engine modes type1
---
 include/freetype/internal/psaux.h | 28 ++++++++++++++---------
 src/base/ftobjs.c                 |  1 +
 src/cff/cffgload.c                | 16 ++++++-------
 src/cff/cffparse.c                | 13 +++++++----
 src/psaux/psauxmod.c              | 10 +++++----
 src/psaux/psobjs.c                | 12 ++++++++--
 src/psaux/t1decode.c              |  6 +++++
 src/psaux/t1decode.h              |  2 ++
 src/type1/t1gload.c               | 47 ++++++++++++++++++++++++++++++++++++---
 9 files changed, 104 insertions(+), 31 deletions(-)

diff --git a/include/freetype/internal/psaux.h 
b/include/freetype/internal/psaux.h
index 78fc7e7..c989d78 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -919,10 +919,18 @@ FT_BEGIN_HEADER
     void
     (*done)( T1_Decoder  decoder );
 
+#ifdef T1_CONFIG_OPTION_OLD_ENGINE
     FT_Error
-    (*parse_charstrings)( T1_Decoder  decoder,
-                          FT_Byte*    base,
-                          FT_UInt     len );
+    (*parse_charstrings_old)( T1_Decoder  decoder,
+                              FT_Byte*    base,
+                              FT_UInt     len );
+#endif
+
+    FT_Error
+    (*parse_charstrings)( PS_Decoder*  decoder,
+                          FT_Byte*     charstring_base,
+                          FT_ULong     charstring_len );
+
 
   } T1_Decoder_FuncsRec;
 
@@ -1197,16 +1205,16 @@ FT_BEGIN_HEADER
 
 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
     FT_Error
-    (*parse_charstrings)( CFF_Decoder*  decoder,
-                          FT_Byte*      charstring_base,
-                          FT_ULong      charstring_len,
-                          FT_Bool       in_dict );
-#else
+    (*parse_charstrings_old)( CFF_Decoder*  decoder,
+                              FT_Byte*      charstring_base,
+                              FT_ULong      charstring_len,
+                              FT_Bool       in_dict );
+#endif
+
     FT_Error
     (*parse_charstrings)( PS_Decoder*  decoder,
                           FT_Byte*     charstring_base,
-                          FT_ULong     charstring_len );    
-#endif
+                          FT_ULong     charstring_len );
 
   } CFF_Decoder_FuncsRec;
 
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index e190de3..eac2158 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -39,6 +39,7 @@
 
 #include FT_AUTOHINTER_H
 #include FT_CFF_DRIVER_H
+#include FT_TYPE1_DRIVER_H
 
 #ifdef FT_CONFIG_OPTION_MAC_FONTS
 #include "ftbase.h"
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 90fcb8a..311ab46 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -169,10 +169,10 @@
       {
         error = decoder_funcs->prepare( &decoder, size, glyph_index );
         if ( !error )
-          error = decoder_funcs->parse_charstrings( &decoder,
-                                                    charstring,
-                                                    charstring_len,
-                                                    0 );
+          error = decoder_funcs->parse_charstrings_old( &decoder,
+                                                        charstring,
+                                                        charstring_len,
+                                                        0 );
 
         cff_free_glyph_data( face, &charstring, &charstring_len );
       }
@@ -428,10 +428,10 @@
 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
       /* choose which CFF renderer to use */
       if ( driver->hinting_engine == FT_CFF_HINTING_FREETYPE )
-        error = decoder_funcs->parse_charstrings( &decoder,
-                                                  charstring,
-                                                  charstring_len,
-                                                  0 );
+        error = decoder_funcs->parse_charstrings_old( &decoder,
+                                                      charstring,
+                                                      charstring_len,
+                                                      0 );
       else
 #endif
       {
diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c
index 94082f1..428f37d 100644
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -1299,6 +1299,11 @@
                   FT_Byte*    start,
                   FT_Byte*    limit )
   {
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+    PSAux_Service  psaux;
+#endif
+
+
     FT_Byte*    p       = start;
     FT_Error    error   = FT_Err_Ok;
     FT_Library  library = parser->library;
@@ -1398,10 +1403,10 @@
           goto Exit;
         }
         
-        error = psaux->cff_decoder_funcs->parse_charstrings( &decoder,
-                                                             charstring_base,
-                                                             charstring_len,
-                                                             1 );
+        error = psaux->cff_decoder_funcs->parse_charstrings_old( &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 d7223e2..3a79113 100644
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -90,7 +90,10 @@
   {
     t1_decoder_init,              /* init              */
     t1_decoder_done,              /* done              */
-    t1_decoder_parse_charstrings  /* parse_charstrings */
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+    t1_decoder_parse_charstrings, /* parse_charstrings_old */
+#endif
+    cf2_decoder_parse_charstrings /* parse_charstrings */
   };
 
 
@@ -137,10 +140,9 @@
     cff_decoder_prepare,           /* prepare           */
 
 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
-    cff_decoder_parse_charstrings  /* parse_charstrings */
-#else
-    cf2_decoder_parse_charstrings
+    cff_decoder_parse_charstrings, /* parse_charstrings_old */
 #endif
+    cf2_decoder_parse_charstrings  /* parse_charstrings */
   };
 
 
diff --git a/src/psaux/psobjs.c b/src/psaux/psobjs.c
index 27f912d..66a14f4 100644
--- a/src/psaux/psobjs.c
+++ b/src/psaux/psobjs.c
@@ -20,6 +20,8 @@
 #include FT_INTERNAL_POSTSCRIPT_AUX_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_CALC_H
+#include FT_CFF_DRIVER_H
+#include FT_TYPE1_DRIVER_H
 
 #include "psobjs.h"
 #include "psconv.h"
@@ -2164,15 +2166,21 @@
       CFF_Driver  driver  = (CFF_Driver)FT_FACE_DRIVER( builder->face );
 
 
-      if ( driver->hinting_engine == FT_CFF_HINTING_FREETYPE )
+      if ( !builder->is_t1 &&
+           driver->hinting_engine == FT_CFF_HINTING_FREETYPE )
       {
         point->x = x >> 16;
         point->y = y >> 16;
       }
       else
 #endif
+
 #ifdef T1_CONFIG_OPTION_OLD_ENGINE
-      if ( builder->face->is_t1 )
+#ifndef CFF_CONFIG_OPTION_OLD_ENGINE
+      CFF_Driver  driver  = (CFF_Driver)FT_FACE_DRIVER( builder->face );
+#endif
+      if ( builder->is_t1 &&
+           driver->hinting_engine == FT_T1_HINTING_FREETYPE )
       {
         point->x = FIXED_TO_INT( x );
         point->y = FIXED_TO_INT( y );
diff --git a/src/psaux/t1decode.c b/src/psaux/t1decode.c
index c898734..221c25b 100644
--- a/src/psaux/t1decode.c
+++ b/src/psaux/t1decode.c
@@ -40,6 +40,7 @@
 #undef  FT_COMPONENT
 #define FT_COMPONENT  trace_t1decode
 
+#ifdef T1_CONFIG_OPTION_OLD_ENGINE
 
   typedef enum  T1_Operator_
   {
@@ -108,6 +109,8 @@
     2  /* opcode 15 (undocumented and obsolete) */
   };
 
+#endif /* T1_CONFIG_OPTION_OLD_ENGINE */
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -340,6 +343,7 @@
   }
 
 
+#ifdef T1_CONFIG_OPTION_OLD_ENGINE
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -1579,6 +1583,8 @@
     return FT_THROW( Stack_Underflow );
   }
 
+#endif /* T1_CONFIG_OPTION_OLD_ENGINE */
+
 
   /* parse a single Type 1 glyph */
   FT_LOCAL_DEF( FT_Error )
diff --git a/src/psaux/t1decode.h b/src/psaux/t1decode.h
index be56d9a..691faa3 100644
--- a/src/psaux/t1decode.h
+++ b/src/psaux/t1decode.h
@@ -43,10 +43,12 @@ FT_BEGIN_HEADER
   t1_decoder_parse_glyph( T1_Decoder  decoder,
                           FT_UInt     glyph_index );
 
+#ifdef T1_CONFIG_OPTION_OLD_ENGINE
   FT_LOCAL( FT_Error )
   t1_decoder_parse_charstrings( T1_Decoder  decoder,
                                 FT_Byte*    base,
                                 FT_UInt     len );
+#endif
 
   FT_LOCAL( FT_Error )
   t1_decoder_init( T1_Decoder           decoder,
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index aaf19b6..1a85b44 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -23,6 +23,7 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_OUTLINE_H
 #include FT_INTERNAL_POSTSCRIPT_AUX_H
+#include FT_TYPE1_DRIVER_H
 
 #include "t1errors.h"
 
@@ -63,11 +64,18 @@
     T1_Font   type1 = &face->type1;
     FT_Error  error = FT_Err_Ok;
 
+    PSAux_Service            psaux         = (PSAux_Service)face->psaux;
+    const T1_Decoder_Funcs   decoder_funcs = psaux->t1_decoder_funcs;
+    PS_Decoder               psdecoder;
+
 #ifdef FT_CONFIG_OPTION_INCREMENTAL
     FT_Incremental_InterfaceRec *inc =
                       face->root.internal->incremental_interface;
 #endif
 
+#ifdef T1_CONFIG_OPTION_OLD_ENGINE
+    CFF_Driver  driver = (CFF_Driver)FT_FACE_DRIVER( face );
+#endif
 
     decoder->font_matrix = type1->font_matrix;
     decoder->font_offset = type1->font_offset;
@@ -90,9 +98,42 @@
     }
 
     if ( !error )
-      error = decoder->funcs.parse_charstrings(
-                decoder, (FT_Byte*)char_string->pointer,
-                (FT_UInt)char_string->length );
+    {
+#ifdef T1_CONFIG_OPTION_OLD_ENGINE
+      /* choose which renderer to use */
+      if ( driver->hinting_engine == FT_T1_HINTING_FREETYPE )
+        error = decoder_funcs->parse_charstrings_old( decoder,
+                                                      
(FT_Byte*)char_string->pointer,
+                                                      
(FT_UInt)char_string->length );
+      else
+#endif
+      {
+        psaux->ps_decoder_init( decoder, TRUE, &psdecoder );
+
+        error = decoder_funcs->parse_charstrings( &psdecoder,
+                                                  
(FT_Byte*)char_string->pointer,
+                                                  
(FT_ULong)char_string->length );
+
+#if 0 /* TODO(ewaldhew) */
+        /* Adobe's engine uses 16.16 numbers everywhere;              */
+        /* as a consequence, glyphs larger than 2000ppem get rejected */
+        if ( FT_ERR_EQ( error, Glyph_Too_Big ) )
+        {
+          /* this time, we retry unhinted and scale up the glyph later on */
+          /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */
+          /* 0x400 for both `x_scale' and `y_scale' in this case)         */
+          hinting       = FALSE;
+          force_scaling = TRUE;
+          glyph->hint   = hinting;
+
+          error = decoder_funcs->parse_charstrings( &psdecoder,
+                                                    
(FT_Byte*)char_string->pointer,
+                                                    
(FT_ULong)char_string->length );
+        }
+#endif
+      }
+
+    }
 
 #ifdef FT_CONFIG_OPTION_INCREMENTAL
 



reply via email to

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