freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master 747fdc5 1/4: Universal hinting engine switch.


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master 747fdc5 1/4: Universal hinting engine switch.
Date: Fri, 13 Nov 2020 14:44:08 -0500 (EST)

branch: master
commit 747fdc5502473ffbba4c9d6cb8373d6dfbfadc6e
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    Universal hinting engine switch.
    
    * src/ftcommon.[ch] (FTDemo_Hinting_Engine_Change): Implement it.
    (FTDemo_Get_Info): Minor.
---
 ChangeLog      |  7 +++++
 src/ftcommon.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ftcommon.h |  5 ++++
 3 files changed, 103 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 732b5c7..382aef6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-11-13  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+       Universal hinting engine switch.
+
+       * src/ftcommon.[ch] (FTDemo_Hinting_Engine_Change): Implement it.
+       (FTDemo_Get_Info): Minor.
+
 2020-11-12  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
        * src/ftcommon.c (FTDemo_Get_Info): Simplify the code.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index f005655..038b6e6 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -1040,6 +1040,95 @@
   }
 
 
+  /* switch to a different engine if possible, including warping */
+  int
+  FTDemo_Hinting_Engine_Change( FTDemo_Handle*  handle )
+  {
+    FT_Library        library = handle->library;
+    FT_Face           face;
+    const FT_String*  module_name;
+    FT_UInt           prop = 0;
+
+
+    error = FTC_Manager_LookupFace( handle->cache_manager,
+                                    handle->scaler.face_id, &face );
+
+    if ( error                                       ||
+         !FT_IS_SCALABLE( face )                     ||
+         !handle->hinted                             ||
+         handle->lcd_mode == LCD_MODE_LIGHT          ||
+         handle->lcd_mode == LCD_MODE_LIGHT_SUBPIXEL )
+      return 0;  /* do nothing */
+
+    module_name = (*(FT_Module_Class**)(face->driver))->module_name;
+
+    if ( handle->autohint )
+    {
+      FT_Bool  warp;
+
+
+      FT_Property_Get( library, "autofitter", "warping", &warp );
+      warp = !warp;
+      FT_Property_Set( library, "autofitter", "warping", &warp );
+    }
+
+    else if ( !FT_Property_Get( library, module_name,
+                                         "interpreter-version", &prop ) )
+    {
+      switch ( prop )
+      {
+      S1:
+      case TT_INTERPRETER_VERSION_35:
+        prop = TT_INTERPRETER_VERSION_38;
+        if ( !FT_Property_Set( library, module_name,
+                                        "interpreter-version", &prop ) )
+          break;
+        /* fall through */
+      case TT_INTERPRETER_VERSION_38:
+        prop = TT_INTERPRETER_VERSION_40;
+        if ( !FT_Property_Set( library, module_name,
+                                        "interpreter-version", &prop ) )
+          break;
+        /* fall through */
+      case TT_INTERPRETER_VERSION_40:
+        prop = TT_INTERPRETER_VERSION_35;
+        if ( !FT_Property_Set( library, module_name,
+                                        "interpreter-version", &prop ) )
+          break;
+        goto S1;
+      }
+    }
+
+    else if ( !FT_Property_Get( library, module_name,
+                                         "hinting-engine", &prop ) )
+    {
+      switch ( prop )
+      {
+      S2:
+      case FT_HINTING_FREETYPE:
+        prop = FT_HINTING_ADOBE;
+        if ( !FT_Property_Set( library, module_name,
+                                        "hinting-engine", &prop ) )
+          break;
+        /* fall through */
+      case FT_HINTING_ADOBE:
+        prop = FT_HINTING_FREETYPE;
+        if ( !FT_Property_Set( library, module_name,
+                                        "hinting-engine", &prop ) )
+          break;
+        goto S2;
+      }
+    }
+
+    /* Resetting the cache is perhaps a bit harsh, but I'm too  */
+    /* lazy to walk over all loaded fonts to check whether they */
+    /* are of appropriate type, then unloading them explicitly. */
+    FTC_Manager_Reset( handle->cache_manager );
+
+    return 1;
+  }
+
+
   static FT_Error
   FTDemo_Get_Info( FTDemo_Handle*  handle,
                    StrBuf*         buf )
@@ -1130,6 +1219,8 @@
       lcd_mode = "  mono";
     }
 
+    strbuf_add( buf, module_name );
+    strbuf_add( buf, " ");
     strbuf_add( buf, hinting_engine );
     strbuf_add( buf,  " \032 " );
     strbuf_add( buf, lcd_mode );
diff --git a/src/ftcommon.h b/src/ftcommon.h
index 39ced9e..6751d9f 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -293,6 +293,11 @@
                    FT_Size*        asize );
 
 
+  /* switch to a different engine if possible, including warping */
+  int
+  FTDemo_Hinting_Engine_Change( FTDemo_Handle*  handle );
+
+
   /* draw common header */
   void
   FTDemo_Draw_Header( FTDemo_Handle*   handle,



reply via email to

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