Commit 33655a96474888d9fd46da351944d89635207293

Werner Lemberg 2013-08-26T09:58:50

[autofit] Fix script selection. * src/autofit/afglobal.c (af_face_globals_get_metrics): Use `AF_SCRIPT_DFLT', not value 0. Simplify code. * src/autofit/afscript.h: Sort by script name.

diff --git a/ChangeLog b/ChangeLog
index 9c3693d..232a206 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2013-08-26  Werner Lemberg  <wl@gnu.org>
 
+	[autofit] Fix script selection.
+
+	* src/autofit/afglobal.c (af_face_globals_get_metrics): Use
+	`AF_SCRIPT_DFLT', not value 0.
+	Simplify code.
+
+	* src/autofit/afscript.h: Sort by script name.
+
+2013-08-26  Werner Lemberg  <wl@gnu.org>
+
 	[autofit] Make `dummy' hinter work as expected.
 
 	* src/autofit/afdummy.c (af_dummy_hints_init): Properly set scaling
diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c
index 1133ffc..e026c1c 100644
--- a/src/autofit/afglobal.c
+++ b/src/autofit/afglobal.c
@@ -246,15 +246,12 @@
                                AF_ScriptMetrics  *ametrics )
   {
     AF_ScriptMetrics  metrics = NULL;
-    FT_UInt           gidx;
 
+    AF_Script              script = options & 15;
     AF_WritingSystemClass  writing_system_class;
     AF_ScriptClass         script_class;
 
-    FT_UInt          script     = options & 15;
-    const FT_Offset  script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) /
-                                    sizeof ( AF_SCRIPT_CLASSES_GET[0] );
-    FT_Error         error      = FT_Err_Ok;
+    FT_Error  error = FT_Err_Ok;
 
 
     if ( gindex >= (FT_ULong)globals->glyph_count )
@@ -263,17 +260,16 @@
       goto Exit;
     }
 
-    gidx = script;
-    if ( gidx == 0 || gidx + 1 >= script_max )
-      gidx = globals->glyph_scripts[gindex] & AF_SCRIPT_NONE;
+    /* if we have a forced script (via `options'), use it, */
+    /* otherwise look into `glyph_scripts' array           */
+    if ( script == AF_SCRIPT_DFLT || script + 1 >= AF_SCRIPT_MAX )
+      script = globals->glyph_scripts[gindex] & AF_SCRIPT_NONE;
 
-    script_class         = AF_SCRIPT_CLASSES_GET[gidx];
+    script_class         = AF_SCRIPT_CLASSES_GET[script];
     writing_system_class = AF_WRITING_SYSTEM_CLASSES_GET
                              [script_class->writing_system];
-    if ( script == 0 )
-      script = script_class->script;
 
-    metrics = globals->metrics[script_class->script];
+    metrics = globals->metrics[script];
     if ( metrics == NULL )
     {
       /* create the global metrics object if necessary */
@@ -300,7 +296,7 @@
         }
       }
 
-      globals->metrics[script_class->script] = metrics;
+      globals->metrics[script] = metrics;
     }
 
   Exit:
diff --git a/src/autofit/afscript.h b/src/autofit/afscript.h
index e3170ae..4e4567f 100644
--- a/src/autofit/afscript.h
+++ b/src/autofit/afscript.h
@@ -22,10 +22,10 @@
 
   /* Add new scripts here. */
 
+  SCRIPT( deva, DEVA )
   SCRIPT( dflt, DFLT )
-  SCRIPT( latn, LATN )
   SCRIPT( hani, HANI )
-  SCRIPT( deva, DEVA )
+  SCRIPT( latn, LATN )
 #ifdef FT_OPTION_AUTOFIT2
   SCRIPT( ltn2, LTN2 )
 #endif