shithub: freetype+ttf2subf

Download patch

ref: 3683fb55c98eb7f2973b4f3c71c35847e1fc1b27
parent: d180ac70fca55c75272d9668b9ed1418dc9e22f9
author: Werner Lemberg <[email protected]>
date: Tue Sep 18 19:31:05 EDT 2012

[autofit] Implement `increase-x-height' property.

* include/freetype/ftautoh.h (FT_Prop_IncreaseXHeight): New
structure.

* include/autofit/afmodule.c (af_property_get_face_globals): New
function, re-using code from `af_property_get'.
(af_property_set, af_property_get): Handle `increase-x-height'.
Updated.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2012-09-18  Werner Lemberg  <[email protected]>
 
+	[autofit] Implement `increase-x-height' property.
+
+	* include/freetype/ftautoh.h (FT_Prop_IncreaseXHeight): New
+	structure.
+
+	* include/autofit/afmodule.c (af_property_get_face_globals): New
+	function, re-using code from `af_property_get'.
+	(af_property_set, af_property_get): Handle `increase-x-height'.
+	Updated.
+
+2012-09-18  Werner Lemberg  <[email protected]>
+
 	[autofit] Implement Infinality's `increase glyph heights'.
 
 	This is an improved version of a similar fix contained in the
--- a/include/freetype/ftautoh.h
+++ b/include/freetype/ftautoh.h
@@ -275,13 +275,68 @@
    *
    *   It's important to use the right timing for changing this value: The
    *   creation of the glyph-to-script map which eventually uses the
-   *   fallback script value gets triggered either by accessing the
-   *   @glyph-to-script-map property of a face, or by auto-hinting any glyph
-   *   from that face.  In particular, if you have already created an
-   *   @FT_Face structure but not loaded any glyph (using the auto-hinter),
-   *   a change of the fallback glyph will affect this face.
+   *   fallback script value gets triggered either by setting or reading a
+   *   face-specific property like @glyph-to-script-map, or by auto-hinting
+   *   any glyph from that face.  In particular, if you have already created
+   *   an @FT_Face structure but not loaded any glyph (using the
+   *   auto-hinter), a change of the fallback glyph will affect this face.
    *
    */
+
+
+  /**************************************************************************
+   *
+   * @property:
+   *   increase-x-height
+   *
+   * @description:
+   *   For ppem values in the range 6~<= ppem <= `increase-x-height', round
+   *   up the font's x~height much more often than normally.  If the value
+   *   is set to~0, which is the default, this feature is switched off.  Use
+   *   this property to improve the legibility of small font sizes if
+   *   necessary.
+   *
+   *   {
+   *     FT_Library               library;
+   *     FT_Face                  face;
+   *     FT_Prop_IncreaseXHeight  prop;
+   *
+   *
+   *     FT_Init_FreeType( &library );
+   *     FT_New_Face( library, "foo.ttf", 0, &face );
+   *     FT_Set_Char_Size( face, 10 * 64, 0, 72, 0 );
+   *
+   *     prop.face  = face;
+   *     prop.limit = 14;
+   *
+   *     FT_Property_Set( library, "autofitter",
+   *                               "increase-x-height", &prop );
+   *   }
+   *
+   * @note:
+   *   This property can be used with @FT_Property_Get also.
+   *
+   *   Set this value right after calling @FT_Set_Char_Size, but before
+   *   loading any glyph (using the auto-hinter).
+   *
+   */
+
+
+  /**************************************************************************
+   *
+   * @struct:
+   *   FT_Prop_IncreaseXHeight
+   *
+   * @description:
+   *   The data exchange structure for the @increase-x-height property.
+   *
+   */
+   typedef struct  FT_Prop_IncreaseXHeight_
+   {
+     FT_Face  face;
+     FT_UInt  limit;
+
+   } FT_Prop_IncreaseXHeight;
 
 
  /* */
--- a/src/autofit/afmodule.c
+++ b/src/autofit/afmodule.c
@@ -44,6 +44,40 @@
 
 
   FT_Error
+  af_property_get_face_globals( FT_Face          face,
+                                AF_FaceGlobals*  aglobals,
+                                AF_Module        module )
+  {
+    FT_Error        error = AF_Err_Ok;
+    AF_FaceGlobals  globals;
+
+
+    if ( !face )
+      return AF_Err_Invalid_Argument;
+
+    globals = (AF_FaceGlobals)face->autohint.data;
+    if ( !globals )
+    {
+      /* trigger computation of the global script data */
+      /* in case it hasn't been done yet               */
+      error = af_face_globals_new( face, &globals, module );
+      if ( !error )
+      {
+        face->autohint.data =
+          (FT_Pointer)globals;
+        face->autohint.finalizer =
+          (FT_Generic_Finalizer)af_face_globals_free;
+      }
+    }
+
+    if ( !error )
+      *aglobals = globals;
+
+    return error;
+  }
+
+
+  FT_Error
   af_property_set( FT_Module    ft_module,
                    const char*  property_name,
                    const void*  value )
@@ -61,7 +95,19 @@
 
       return error;
     }
+    else if ( !ft_strcmp( property_name, "increase-x-height" ) )
+    {
+      FT_Prop_IncreaseXHeight*  prop = (FT_Prop_IncreaseXHeight*)value;
+      AF_FaceGlobals            globals;
 
+
+      error = af_property_get_face_globals( prop->face, &globals, module );
+      if ( !error )
+        globals->increase_x_height = prop->limit;
+
+      return error;
+    }
+
     FT_TRACE0(( "af_property_get: missing property `%s'\n",
                 property_name ));
     return AF_Err_Missing_Property;
@@ -84,24 +130,7 @@
       AF_FaceGlobals             globals;
 
 
-      if ( !prop->face )
-        return AF_Err_Invalid_Argument;
-
-      globals = (AF_FaceGlobals)prop->face->autohint.data;
-      if ( !globals )
-      {
-        /* trigger computation of the global script data */
-        /* in case it hasn't been done yet               */
-        error = af_face_globals_new( prop->face, &globals, module );
-        if ( !error )
-        {
-          prop->face->autohint.data =
-            (FT_Pointer)globals;
-          prop->face->autohint.finalizer =
-            (FT_Generic_Finalizer)af_face_globals_free;
-        }
-      }
-
+      error = af_property_get_face_globals( prop->face, &globals, module );
       if ( !error )
         prop->map = globals->glyph_scripts;
 
@@ -116,6 +145,19 @@
 
       return error;
     }
+    else if ( !ft_strcmp( property_name, "increase-x-height" ) )
+    {
+      FT_Prop_IncreaseXHeight*  prop = (FT_Prop_IncreaseXHeight*)value;
+      AF_FaceGlobals            globals;
+
+
+      error = af_property_get_face_globals( prop->face, &globals, module );
+      if ( !error )
+        prop->limit = globals->increase_x_height;
+
+      return error;
+    }
+
 
     FT_TRACE0(( "af_property_get: missing property `%s'\n",
                 property_name ));