Commit d4ec0075414a63b6d1850cc801af30e0ef246d92

Werner Lemberg 2012-09-15T18:26:28

[autofit] Implement `fallback-script' property. * src/autofit/afglobal.c: s/default_script/fallback_script/. * src/autofit/afglobal.h: s/AF_SCRIPT_DEFAULT/AF_SCRIPT_FALLBACK/. * src/autofit/afmodule.c: s/default_script/fallback_script/. (af_property_set, af_property_get): Implement `fallback-script'. * src/autofit/afmodule.h: s/default_script/fallback_script/. * include/freetype/ftautoh.h: Document it.

diff --git a/ChangeLog b/ChangeLog
index 5081c33..9df283a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-09-15  Werner Lemberg  <wl@gnu.org>
 
+	[autofit] Implement `fallback-script' property.
+
+	* src/autofit/afglobal.c: s/default_script/fallback_script/.
+	* src/autofit/afglobal.h: s/AF_SCRIPT_DEFAULT/AF_SCRIPT_FALLBACK/.
+
+	* src/autofit/afmodule.c: s/default_script/fallback_script/.
+	(af_property_set, af_property_get): Implement `fallback-script'.
+	* src/autofit/afmodule.h: s/default_script/fallback_script/.
+
+	* include/freetype/ftautoh.h: Document it.
+
+2012-09-15  Werner Lemberg  <wl@gnu.org>
+
 	[autofit] Correct previous Unicode 6.1.0 change.
 
 	The auto-hinter's latin module only handles latin ligatures in the
diff --git a/include/freetype/ftautoh.h b/include/freetype/ftautoh.h
index b04f8fc..88a65bc 100644
--- a/include/freetype/ftautoh.h
+++ b/include/freetype/ftautoh.h
@@ -246,6 +246,44 @@ FT_BEGIN_HEADER
 
    } FT_Prop_GlyphToScriptMap;
 
+
+  /**************************************************************************
+   *
+   * @property:
+   *   fallback-script
+   *
+   * @description:
+   *   If no auto-hinter script module can be assigned to a glyph, a
+   *   fallback script gets assigned to it (see also the
+   *   @glyph-to-script-map property).  By default, this is
+   *   @FT_AUTOHINTER_SCRIPT_CJK.  Using the `fallback-script' property,
+   *   this fallback value can be changed.
+   *
+   *   {
+   *     FT_Library  library;
+   *     FT_UInt     fallback_script = FT_AUTOHINTER_SCRIPT_NONE;
+   *
+   *
+   *     FT_Init_FreeType( &library );
+   *
+   *     FT_Property_Set( library, "autofitter",
+   *                               "fallback-script", &fallback_script );
+   *   }
+   *
+   * @note:
+   *   This property can be used with @FT_Property_Get also.
+   *
+   *   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.
+   *
+   */
+
+
  /* */
 
 FT_END_HEADER
diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c
index 464e6d5..6a1d286 100644
--- a/src/autofit/afglobal.c
+++ b/src/autofit/afglobal.c
@@ -54,7 +54,7 @@
 
   static FT_Error
   af_face_globals_compute_script_coverage( AF_FaceGlobals  globals,
-                                           FT_UInt         default_script )
+                                           FT_UInt         fallback_script )
   {
     FT_Error    error       = AF_Err_Ok;
     FT_Face     face        = globals->face;
@@ -73,7 +73,7 @@
     if ( error )
     {
      /*
-      *  Ignore this error; we simply use the default script.
+      *  Ignore this error; we simply use the fallback script.
       *  XXX: Shouldn't we rather disable hinting?
       */
       error = AF_Err_Ok;
@@ -133,7 +133,7 @@
 
   Exit:
     /*
-     *  By default, all uncovered glyphs are set to the latin script.
+     *  By default, all uncovered glyphs are set to the fallback script.
      *  XXX: Shouldn't we disable hinting or do something similar?
      */
     {
@@ -145,7 +145,7 @@
         if ( ( gscripts[nn] & ~AF_DIGIT ) == AF_SCRIPT_NONE )
         {
           gscripts[nn] &= ~AF_SCRIPT_NONE;
-          gscripts[nn] |= default_script;
+          gscripts[nn] |= fallback_script;
         }
       }
     }
@@ -158,7 +158,7 @@
   FT_LOCAL_DEF( FT_Error )
   af_face_globals_new( FT_Face          face,
                        AF_FaceGlobals  *aglobals,
-                       FT_UInt          default_script )
+                       FT_UInt          fallback_script )
   {
     FT_Error        error;
     FT_Memory       memory;
@@ -176,7 +176,7 @@
     globals->glyph_scripts = (FT_Byte*)( globals + 1 );
 
     error = af_face_globals_compute_script_coverage( globals,
-                                                     default_script );
+                                                     fallback_script );
     if ( error )
     {
       af_face_globals_free( globals );
diff --git a/src/autofit/afglobal.h b/src/autofit/afglobal.h
index 3dec6d0..27c9251 100644
--- a/src/autofit/afglobal.h
+++ b/src/autofit/afglobal.h
@@ -36,12 +36,12 @@ FT_BEGIN_HEADER
   /************************************************************************/
 
 
-  /* index of default script in `af_script_classes' */
-#define AF_SCRIPT_DEFAULT  2
-  /* a bit mask indicating an uncovered glyph       */
-#define AF_SCRIPT_NONE     0x7F
-  /* if this flag is set, we have an ASCII digit    */
-#define AF_DIGIT           0x80
+  /* index of fallback script in `af_script_classes' */
+#define AF_SCRIPT_FALLBACK  2
+  /* a bit mask indicating an uncovered glyph        */
+#define AF_SCRIPT_NONE      0x7F
+  /* if this flag is set, we have an ASCII digit     */
+#define AF_DIGIT            0x80
 
 
   /*
@@ -70,7 +70,7 @@ FT_BEGIN_HEADER
   FT_LOCAL( FT_Error )
   af_face_globals_new( FT_Face          face,
                        AF_FaceGlobals  *aglobals,
-                       FT_UInt          default_script );
+                       FT_UInt          fallback_script );
 
   FT_LOCAL( FT_Error )
   af_face_globals_get_metrics( AF_FaceGlobals     globals,
diff --git a/src/autofit/afloader.c b/src/autofit/afloader.c
index 98824dc..975947e 100644
--- a/src/autofit/afloader.c
+++ b/src/autofit/afloader.c
@@ -60,7 +60,7 @@
     if ( loader->globals == NULL )
     {
       error = af_face_globals_new( face, &loader->globals,
-                                   module->default_script );
+                                   module->fallback_script );
       if ( !error )
       {
         face->autohint.data =
diff --git a/src/autofit/afmodule.c b/src/autofit/afmodule.c
index f07ed3c..d4347f0 100644
--- a/src/autofit/afmodule.c
+++ b/src/autofit/afmodule.c
@@ -48,8 +48,18 @@
                    const char*  property_name,
                    const void*  value )
   {
-    FT_UNUSED( module );
-    FT_UNUSED( value );
+    FT_Error  error = AF_Err_Ok;
+
+
+    if ( !ft_strcmp( property_name, "fallback-script" ) )
+    {
+      FT_UInt*  fallback_script = (FT_UInt*)value;
+
+
+      ((AF_Module)module)->fallback_script = *fallback_script;
+
+      return error;
+    }
 
     FT_TRACE0(( "af_property_get: missing property `%s'\n",
                 property_name ));
@@ -62,8 +72,8 @@
                    const char*  property_name,
                    void*        value )
   {
-    FT_Error  error          = AF_Err_Ok;
-    FT_UInt   default_script = ((AF_Module)module)->default_script;
+    FT_Error  error           = AF_Err_Ok;
+    FT_UInt   fallback_script = ((AF_Module)module)->fallback_script;
 
 
     if ( !ft_strcmp( property_name, "glyph-to-script-map" ) )
@@ -80,7 +90,7 @@
       {
         /* trigger computation of the global script data */
         /* in case it hasn't been done yet               */
-        error = af_face_globals_new( prop->face, &globals, default_script );
+        error = af_face_globals_new( prop->face, &globals, fallback_script );
         if ( !error )
         {
           prop->face->autohint.data =
@@ -95,6 +105,15 @@
 
       return error;
     }
+    else if ( !ft_strcmp( property_name, "fallback-script" ) )
+    {
+      FT_UInt*  val = (FT_UInt*)value;
+
+
+      *val = fallback_script;
+
+      return error;
+    }
 
     FT_TRACE0(( "af_property_get: missing property `%s'\n",
                 property_name ));
@@ -138,7 +157,7 @@
   FT_CALLBACK_DEF( FT_Error )
   af_autofitter_init( AF_Module  module )
   {
-    module->default_script = AF_SCRIPT_DEFAULT;
+    module->fallback_script = AF_SCRIPT_FALLBACK;
 
     return af_loader_init( module );
   }
diff --git a/src/autofit/afmodule.h b/src/autofit/afmodule.h
index 8948c1b..c4e8f8f 100644
--- a/src/autofit/afmodule.h
+++ b/src/autofit/afmodule.h
@@ -40,7 +40,7 @@ FT_BEGIN_HEADER
   {
     FT_ModuleRec  root;
 
-    FT_UInt       default_script;
+    FT_UInt       fallback_script;
 
     AF_LoaderRec  loader[1];