Commit 87c81f0460fad3af38fbfebcd7ee03ca1a41e4b6

Werner Lemberg 2015-08-30T10:35:21

[autofit] Make glyph style array use 16bit values. * include/freetype/ftautoh.h (FT_Prop_GlyphToScriptMap): Use `FT_UShort' for `map' field. * src/autofit/afglobal.c (af_face_globals_compute_style_coverage, af_face_globals_new), src/autofit/hbshim.c, src/autofit/hbshim.h (af_get_coverage): Use FT_UShort for `glyph_styles' array. * src/autofit/afglobal.h (AF_STYLE_UNASSIGNED, AF_DIGIT): Extend to 16 bits. (AF_FaceGlobalsRec): Use `FT_UShort' for `glyph_styles' field.

diff --git a/ChangeLog b/ChangeLog
index 659cfc9..5d27489 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2015-08-30  Werner Lemberg  <wl@gnu.org>
+
+	[autofit] Make glyph style array use 16bit values.
+
+	* include/freetype/ftautoh.h (FT_Prop_GlyphToScriptMap): Use
+	`FT_UShort' for `map' field.
+
+	* src/autofit/afglobal.c (af_face_globals_compute_style_coverage,
+	af_face_globals_new), src/autofit/hbshim.c, src/autofit/hbshim.h
+	(af_get_coverage): Use FT_UShort for `glyph_styles' array.
+
+	* src/autofit/afglobal.h (AF_STYLE_UNASSIGNED, AF_DIGIT): Extend to
+	16 bits.
+	(AF_FaceGlobalsRec): Use `FT_UShort' for `glyph_styles' field.
+
 2015-08-26  Werner Lemberg  <wl@gnu.org>
 
 	* builds/unix/configure.raw: Need harfbuzz >= 0.9.21 (#45828).
diff --git a/include/freetype/ftautoh.h b/include/freetype/ftautoh.h
index cf7b76f..ab39c21 100644
--- a/include/freetype/ftautoh.h
+++ b/include/freetype/ftautoh.h
@@ -247,8 +247,8 @@ FT_BEGIN_HEADER
    */
   typedef struct  FT_Prop_GlyphToScriptMap_
   {
-    FT_Face   face;
-    FT_Byte*  map;
+    FT_Face     face;
+    FT_UShort*  map;
 
   } FT_Prop_GlyphToScriptMap;
 
diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c
index 64b9293..d908370 100644
--- a/src/autofit/afglobal.c
+++ b/src/autofit/afglobal.c
@@ -135,16 +135,15 @@
     FT_Error    error;
     FT_Face     face        = globals->face;
     FT_CharMap  old_charmap = face->charmap;
-    FT_Byte*    gstyles     = globals->glyph_styles;
+    FT_UShort*  gstyles     = globals->glyph_styles;
     FT_UInt     ss;
     FT_UInt     i;
     FT_UInt     dflt        = ~0U; /* a non-valid value */
 
 
     /* the value AF_STYLE_UNASSIGNED means `uncovered glyph' */
-    FT_MEM_SET( globals->glyph_styles,
-                AF_STYLE_UNASSIGNED,
-                globals->glyph_count );
+    for ( i = 0; i < (FT_UInt)globals->glyph_count; i++ )
+      gstyles[i] = AF_STYLE_UNASSIGNED;
 
     error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
     if ( error )
@@ -193,7 +192,7 @@
           if ( gindex != 0                             &&
                gindex < (FT_ULong)globals->glyph_count &&
                gstyles[gindex] == AF_STYLE_UNASSIGNED  )
-            gstyles[gindex] = (FT_Byte)ss;
+            gstyles[gindex] = (FT_UShort)ss;
 
           for (;;)
           {
@@ -204,7 +203,7 @@
 
             if ( gindex < (FT_ULong)globals->glyph_count &&
                  gstyles[gindex] == AF_STYLE_UNASSIGNED  )
-              gstyles[gindex] = (FT_Byte)ss;
+              gstyles[gindex] = (FT_UShort)ss;
           }
         }
       }
@@ -314,14 +313,17 @@
 
     memory = face->memory;
 
+    /* we allocate an AF_FaceGlobals structure together */
+    /* with the glyph_styles array                      */
     if ( FT_ALLOC( globals,
                    sizeof ( *globals ) +
-                     (FT_ULong)face->num_glyphs * sizeof ( FT_Byte ) ) )
+                     (FT_ULong)face->num_glyphs * sizeof ( FT_UShort ) ) )
       goto Exit;
 
     globals->face         = face;
     globals->glyph_count  = face->num_glyphs;
-    globals->glyph_styles = (FT_Byte*)( globals + 1 );
+    /* right after the globals structure come the glyph styles */
+    globals->glyph_styles = (FT_UShort*)( globals + 1 );
     globals->module       = module;
 
 #ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
diff --git a/src/autofit/afglobal.h b/src/autofit/afglobal.h
index 9bbb687..6cacd69 100644
--- a/src/autofit/afglobal.h
+++ b/src/autofit/afglobal.h
@@ -73,9 +73,9 @@ FT_BEGIN_HEADER
   /* default script for OpenType; ignored if HarfBuzz isn't used */
 #define AF_SCRIPT_DEFAULT    AF_SCRIPT_LATN
   /* a bit mask indicating an uncovered glyph        */
-#define AF_STYLE_UNASSIGNED  0x7F
+#define AF_STYLE_UNASSIGNED  0x7FFF
   /* if this flag is set, we have an ASCII digit     */
-#define AF_DIGIT             0x80
+#define AF_DIGIT             0x8000U
 
   /* `increase-x-height' property */
 #define AF_PROP_INCREASE_X_HEIGHT_MIN  6
@@ -100,7 +100,7 @@ FT_BEGIN_HEADER
   {
     FT_Face          face;
     FT_Long          glyph_count;    /* same as face->num_glyphs */
-    FT_Byte*         glyph_styles;
+    FT_UShort*       glyph_styles;
 
 #ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
     hb_font_t*       hb_font;
diff --git a/src/autofit/hbshim.c b/src/autofit/hbshim.c
index c9c1db0..692671e 100644
--- a/src/autofit/hbshim.c
+++ b/src/autofit/hbshim.c
@@ -98,7 +98,7 @@
   FT_Error
   af_get_coverage( AF_FaceGlobals  globals,
                    AF_StyleClass   style_class,
-                   FT_Byte*        gstyles )
+                   FT_UShort*      gstyles )
   {
     hb_face_t*  face;
 
@@ -363,7 +363,7 @@
         continue;
 
       if ( gstyles[idx] == AF_STYLE_UNASSIGNED )
-        gstyles[idx] = (FT_Byte)style_class->style;
+        gstyles[idx] = (FT_UShort)style_class->style;
 #ifdef FT_DEBUG_LEVEL_TRACE
       else
         FT_TRACE4(( "*" ));
diff --git a/src/autofit/hbshim.h b/src/autofit/hbshim.h
index 5636ca6..3824941 100644
--- a/src/autofit/hbshim.h
+++ b/src/autofit/hbshim.h
@@ -38,7 +38,7 @@ FT_BEGIN_HEADER
   FT_Error
   af_get_coverage( AF_FaceGlobals  globals,
                    AF_StyleClass   style_class,
-                   FT_Byte*        gstyles );
+                   FT_UShort*      gstyles );
 
   FT_Error
   af_get_char_index( AF_StyleMetrics  metrics,