Commit df430e1a20c4ecc2727834cd345b7509faf51c13

David Turner 2006-10-01T00:09:35

* include/freetype/internal/ftobjs.h, src/base/ftobjs.c, src/truetype/ttobjs.c: fixes related to the unpatented hinter

diff --git a/ChangeLog b/ChangeLog
index 664f18b..04d82a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2006-09-30  Werner Lemberg  <wl@gnu.org>
-
+	* include/freetype/internal/ftobjs.h, src/base/ftobjs.c,
+	src/truetype/ttobjs.c: fixes related to the unpatented hinter
+	
 	* src/base/rules.mk (BASE_SRC): Remove `ftapi.c' (which is no longer
 	in use).
 
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index e1c1c1a..e13ff27 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -211,11 +211,11 @@ FT_BEGIN_HEADER
   /*      this data when first opened.  This field exists only if          */
   /*      @FT_CONFIG_OPTION_INCREMENTAL is defined.                        */
   /*                                                                       */
-  /*    unpatented_hinting ::                                              */
-  /*      This boolean flag instructs the glyph loader that this font      */
-  /*      can only be loaded through the unpatented bytecode interpreter.  */
-  /*      In that case, the auto-hinter is never called for it, except if  */
-  /*      you use FT_LOAD_FORCE_AUTOHINT.                                  */
+  /*    ignore_unpatented_hinter ::                                        */
+  /*      This boolean flag instructs the glyph loader to ignore           */
+  /*      the native font hinter, if one is found. This is exclusively     */
+  /*      used in the case when the unpatented hinter is compiled within   */
+  /*      the library.                                                    */
   /*                                                                       */
   typedef struct  FT_Face_InternalRec_
   {
@@ -233,7 +233,7 @@ FT_BEGIN_HEADER
     FT_Incremental_InterfaceRec*  incremental_interface;
 #endif
 
-    FT_Bool             unpatented_hinting;
+    FT_Bool             ignore_unpatented_hinter;
 
   } FT_Face_InternalRec;
 
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 3022cbd..958e4b2 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -573,23 +573,45 @@
       load_flags &= ~FT_LOAD_RENDER;
     }
 
-    if ( FT_LOAD_TARGET_MODE( load_flags ) == FT_RENDER_MODE_LIGHT )
-      load_flags |= FT_LOAD_FORCE_AUTOHINT;
-
-    /* auto-hinter is preferred and should be used */
-    if ( ( !FT_DRIVER_HAS_HINTER( driver )         ||
-           ( load_flags & FT_LOAD_FORCE_AUTOHINT ) ) &&
-         !( load_flags & FT_LOAD_NO_HINTING )        &&
-         !( load_flags & FT_LOAD_NO_AUTOHINT )       )
-    {
-      /* check whether it works for this face */
-      autohint =
-        FT_BOOL( hinter                                   &&
-                 FT_DRIVER_IS_SCALABLE( driver )          &&
-                 FT_DRIVER_USES_OUTLINES( driver )        &&
-                 face->internal->transform_matrix.yy > 0  &&
-                 face->internal->transform_matrix.yx == 0 &&
-                 !face->internal->unpatented_hinting      );
+    /* determine wether we need to auto-hint or not
+    * the general rules are:
+    *
+    * - only auto-hint if we have a hinter module, a
+    *   scalable font format dealing with outlines,
+    *   no transforms except simple slants
+    *
+    * - then, autohint if FT_LOAD_FORCE_AUTOHINT is set
+    *   or if we don't have a native font hinter
+    *
+    * - otherwise, autohint for LIGHT hinting mode
+    *
+    * - except if the font requires the unpatented
+    *   bytecode interpreter to load properly
+    */
+
+    autohint = 0;
+    if ( hinter &&
+         (load_flags & FT_LOAD_NO_HINTING) == 0   &&
+         (load_flags & FT_LOAD_NO_AUTOHINT) == 0  &&
+         FT_DRIVER_IS_SCALABLE( driver )          &&
+         FT_DRIVER_USES_OUTLINES( driver )        &&
+         face->internal->transform_matrix.yy > 0  &&
+         face->internal->transform_matrix.yx == 0 )
+    {
+      if ( (load_flags & FT_LOAD_FORCE_AUTOHINT) != 0 ||
+           !FT_DRIVER_HAS_HINTER( driver ) )
+        autohint = 1;
+
+      else
+      {
+        FT_Render_Mode  mode = FT_LOAD_TARGET_MODE(load_flags);
+
+        if ( mode == FT_RENDER_MODE_LIGHT             ||
+             face->internal->ignore_unpatented_hinter )
+        {
+          autohint = 1;
+        }
+      }
     }
 
     if ( autohint )
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index 4bc4ba8..0226029 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -246,51 +246,53 @@
 
     }
 
-#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
-
-    /* Determine whether unpatented hinting is to be used for this face. */
-    face->unpatented_hinting = FT_BOOL
-       ( library->debug_hooks[ FT_DEBUG_HOOK_UNPATENTED_HINTING ] != NULL );
+#if defined(TT_CONFIG_OPTION_UNPATENTED_HINTING) && \
+    !defined(TT_CONFIG_OPTION_BYTECODE_INTERPRETER)
 
     {
-      int  i;
+      FT_Bool  unpatented_hinting;
+      int      i;
 
+      /* Determine whether unpatented hinting is to be used for this face. */
+      unpatented_hinting = FT_BOOL
+       ( library->debug_hooks[ FT_DEBUG_HOOK_UNPATENTED_HINTING ] != NULL );
 
       for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
         if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
-          face->unpatented_hinting = TRUE;
-    }
+          unpatented_hinting = TRUE;
 
-    /* Compare the face with a list of well-known `tricky' fonts. */
-    /* This list shall be expanded as we find more of them.       */
-    if ( !face->unpatented_hinting )
-    {
-      static const char* const  trick_names[] =
-      {
-        "DFKaiSho-SB",     /* dfkaisb.ttf */
-        "DFKai-SB",        /* kaiu.ttf */
-        "HuaTianSongTi?",  /* htst3.ttf */
-        "MingLiU",         /* mingliu.ttf & mingliu.ttc */
-        "PMingLiU",        /* mingliu.ttc */
-        "MingLi43",        /* mingli.ttf */
-        NULL
-      };
-      int  nn;
-
-
-      /* Note that we only check the face name at the moment; it might */
-      /* be worth to do more checks for a few special cases.           */
-      for ( nn = 0; trick_names[nn] != NULL; nn++ )
+      /* Compare the face with a list of well-known `tricky' fonts. */
+      /* This list shall be expanded as we find more of them.       */
+      if ( !unpatented_hinting )
       {
-        if ( ft_strcmp( ttface->family_name, trick_names[nn] ) == 0 )
+        static const char* const  trick_names[] =
         {
-          face->unpatented_hinting = 1;
-          break;
+          "DFKaiSho-SB",     /* dfkaisb.ttf */
+          "DFKai-SB",        /* kaiu.ttf */
+          "HuaTianSongTi?",  /* htst3.ttf */
+          "MingLiU",         /* mingliu.ttf & mingliu.ttc */
+          "PMingLiU",        /* mingliu.ttc */
+          "MingLi43",        /* mingli.ttf */
+          NULL
+        };
+        int  nn;
+
+
+        /* Note that we only check the face name at the moment; it might */
+        /* be worth to do more checks for a few special cases.           */
+        for ( nn = 0; trick_names[nn] != NULL; nn++ )
+        {
+          if ( ft_strcmp( ttface->family_name, trick_names[nn] ) == 0 )
+          {
+            unpatented_hinting = 1;
+            break;
+          }
         }
       }
+
+      ttface->internal->ignore_unpatented_hinter = !unpatented_hinting;
     }
 
-    ttface->internal->unpatented_hinting = face->unpatented_hinting;
 #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING */
 
     /* initialize standard glyph loading routines */