Commit dd0f3609d776f3d6993e8cb90add45dd7177bade

David Turner 2006-02-20T23:50:21

* include/freetype/internal/sfnt.h, src/sfnt/sfdriver.c, src/sfnt/ttsbit.h, src/sfnt/ttsbit.c: moving the definition of 'set_sbit_strike' and 'load_sbit_metrics' to their 2.1.8 location. This is used to support binary compatibility with the X.Org server's libXfont library. note that this disables memory optimizations for the embedded bitmap loader.Sigh....

diff --git a/ChangeLog b/ChangeLog
index a59b5b2..584668a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-02-20  David Turner  <david@freetype.org>
+
+        * include/freetype/internal/sfnt.h, src/sfnt/sfdriver.c,
+        src/sfnt/ttsbit.h, src/sfnt/ttsbit.c: moving the definition
+        of 'set_sbit_strike' and 'load_sbit_metrics' to their 2.1.8
+        location. This is used to support binary compatibility with
+        the X.Org server's libXfont library.
+
+        note that this disables memory optimizations for the embedded
+        bitmap loader.Sigh....
+
+
 2006-02-17  David Turner  <david@freetype.org>
 
 	* builds/unix/unix-cc.in (LINK_LIBRARY): Don't filter out exported
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index b9d0ab9..63b421d 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -694,8 +694,21 @@ FT_BEGIN_HEADER
 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
     TT_Set_SBit_Strike_OldFunc   set_sbit_strike_stub;
     TT_Load_Table_Func           load_sbits_stub;
+
+    /* The following two fields only appeared in 2.1.8, and were placed between
+     * 'load_sbits' and 'load_sbit_image'. We support them as a special exception
+     * since they're used by libXfont within the X.Org xserver, and because the
+     * probability that other rogue clients use the other 2.1.7 fields below
+     * is _extremely_ low.
+     *
+     * Note that this forces us to disable an interesting memory-saving optimization
+     * though...
+     */
+    TT_Find_SBit_Image_Func      find_sbit_image;
+    TT_Load_SBit_Metrics_Func    load_sbit_metrics;
 #endif
 
+
     TT_Load_SBit_Image_Func      load_sbit_image;
 
 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
@@ -716,12 +729,6 @@ FT_BEGIN_HEADER
     /* this field was introduced in version 2.1.8, named `get_psname' */
     TT_Face_GetKerningFunc       get_kerning;
 
-    /* The following appeared in 2.1.8, but were placed between     */
-    /* `load_sbits' and `load_sbit_image'.  Both fields are NULL if */
-    /* FT_OPTIMIZE_MEMORY is used.                                  */
-    TT_Find_SBit_Image_Func      find_sbit_image;
-    TT_Load_SBit_Metrics_Func    load_sbit_metrics;
-
     /* new elements introduced after version 2.1.10 */
 
     /* load the font directory, i.e., the offset table and */
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 6a1658d..e394b31 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -430,12 +430,23 @@
                                 FT_UInt    y_ppem,
                                 FT_ULong*  astrike_index )
   {
-    FT_UNUSED( face );
-    FT_UNUSED( x_ppem );
-    FT_UNUSED( y_ppem );
+    /* we simply forge a FT_Size_Request and call the real function
+     * that does all the work
+     *
+     * this stub might be called by libXfont in the X.Org Xserver
+     * that was compiled against FT 2.1.8 or later.
+     */
+    FT_Size_RequestRec  req;
 
-    *astrike_index = 0x7FFFFFFFUL;    
-    return FT_Err_Unimplemented_Feature;
+    req.type           = FT_SIZE_REQUEST_TYPE_NOMINAL;
+    req.width          = (FT_F26Dot6) x_ppem;
+    req.height         = (FT_F26Dot6) y_ppem;
+    req.horiResolution = 0;
+    req.vertResolution = 0;
+
+    *astrike_index = 0x7FFFFFFFUL;
+
+    return tt_face_set_sbit_strike( face, &req, astrike_index );    
   }                                
 
 
@@ -446,6 +457,11 @@
     FT_UNUSED( face );
     FT_UNUSED( stream );
     
+   /* this function was originally implemented to load the sbit
+    * table. However, it has been replaced by 'tt_face_load_eblc'
+    * and this stub is only there for crazy rogue clients who
+    * would want to call it directly (which would be stupid)
+    */
     return FT_Err_Unimplemented_Feature;
   }                          
 
@@ -453,6 +469,7 @@
   FT_CALLBACK_DEF( void )
   tt_face_free_sbit_stub( TT_Face  face )
   {
+    /* nothing to do in this stub */
     FT_UNUSED( face );
   }
   
@@ -529,6 +546,9 @@
 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
     tt_face_set_sbit_strike_stub,
     tt_face_load_sbit_stub,
+
+    tt_find_sbit_image,
+    tt_load_sbit_metrics,
 #endif
 
 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
@@ -559,14 +579,6 @@
 
     tt_face_get_kerning,
 
-#ifndef FT_OPTIMIZE_MEMORY
-    tt_find_sbit_image,
-    tt_load_sbit_metrics,
-#else
-    0,
-    0,
-#endif    
-
     /* since version 2.2 */
 
     tt_face_load_font_dir,
diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c
index 9e7a91e..fc050cc 100644
--- a/src/sfnt/ttsbit.c
+++ b/src/sfnt/ttsbit.c
@@ -20,9 +20,12 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_TRUETYPE_TAGS_H
 
-#ifdef FT_OPTIMIZE_MEMORY
+/* Alas, the memory-optimized sbit loader can't be used when implementing
+ * the 'old internals' hack !!
+ */
+#if defined FT_OPTIMIZE_MEMORY && !defined FT_CONFIG_OPTION_OLD_INTERNALS
 #include "ttsbit0.c"
-#else /* !OPTIMIZE_MEMORY */
+#else /* !OPTIMIZE_MEMORY || OLD_INTERNALS */
 
 #include <ft2build.h>
 #include FT_INTERNAL_DEBUG_H
@@ -886,7 +889,7 @@
       {
         TT_SBit_SmallMetricsRec  smetrics;
 
-        const FT_Frame_Field  sbit_small_metrics_fields[] =
+        static const FT_Frame_Field  sbit_small_metrics_fields[] =
         {
 #undef  FT_STRUCTURE
 #define FT_STRUCTURE  TT_SBit_SmallMetricsRec
@@ -1489,7 +1492,7 @@
     return error;
   }
 
-#endif /* !OPTIMIZE_MEMORY */
+#endif /* !OPTIMIZE_MEMORY || OLD_INTERNALS */
 
 
 /* END */
diff --git a/src/sfnt/ttsbit.h b/src/sfnt/ttsbit.h
index 1e8f3d5..af52742 100644
--- a/src/sfnt/ttsbit.h
+++ b/src/sfnt/ttsbit.h
@@ -45,7 +45,7 @@ FT_BEGIN_HEADER
                                FT_ULong          strike_index,
                                FT_Size_Metrics*  metrics );
 
-#ifndef FT_OPTIMIZE_MEMORY
+#if !defined FT_OPTIMIZE_MEMORY || defined FT_CONFIG_OPTION_OLD_INTERNALS
   FT_LOCAL( FT_Error )
   tt_find_sbit_image( TT_Face          face,
                       FT_UInt          glyph_index,
@@ -58,7 +58,8 @@ FT_BEGIN_HEADER
   tt_load_sbit_metrics( FT_Stream        stream,
                         TT_SBit_Range    range,
                         TT_SBit_Metrics  metrics );
-#endif /* !FT_OPTIMIZE_MEMORY */
+
+#endif /* !FT_OPTIMIZE_MEMORY || FT_CONFIG_OPTION_OLD_INTERNALS */
 
   FT_LOCAL( FT_Error )
   tt_face_load_sbit_image( TT_Face              face,