shithub: freetype+ttf2subf

Download patch

ref: cda2d957dc66673ac7d573e72e6aa4c02d407eb2
parent: 0d565fdc1d3a383d032a198561be26739a0c55f5
author: David Turner <[email protected]>
date: Thu Feb 16 17:45:31 EST 2006

* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
      include/freetype/ftcache.h, include/freetype/ftoutln.h,
      include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
      include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
      include/freetype/internal/ftdriver.h,
      include/freetype/internal/ftmemory.h,
      include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
      include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
      include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
      src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
      src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
      src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
      src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
      src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
      src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
      src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:

    massive changes to the internals to respect the internal object layouts
    and exported functions of FreeType 2.1.7. Note that the cache sub-system
    cannot be fully retrofitted, unfortunately.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,31 @@
+2006-02-16  David Turner  <[email protected]>
+
+    * builds/amiga/src/base/ftsystem.c, devel/ftoption.h
+      include/freetype/ftcache.h, include/freetype/ftoutln.h,
+      include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
+      include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
+      include/freetype/internal/ftdriver.h,
+      include/freetype/internal/ftmemory.h,
+      include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
+      include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
+      include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
+      src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
+      src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
+      src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
+      src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
+      src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
+      src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
+      src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
+
+    massive changes to the internals to respect the internal object layouts
+    and exported functions of FreeType 2.1.7. Note that the cache sub-system
+    cannot be fully retrofitted, unfortunately.
+
 2006-02-15  Chia-I Wu  <[email protected]>
 
 	* include/freetype/internal/ftobjs.h (FT_Face_InternalRec): Remove
 	unused `max_points' and `max_contours'.
-	
+
 	* src/cid/cidobjs.c (cid_face_init), src/type1/t1objs.c
 	(T1_Face_Init), src/type42/t42objs.c (T42_Face_Init): Update.
 
@@ -127,7 +150,7 @@
 	src/sfnt/sfdriver.c, src/sfnt/sfnt.c, src/sfnt/sfobjs.c,
 	src/sfnt/ttload.c, src/sfnt/ttload.h, src/sfnt/ttsbit.c,
 	src/sfnt/ttsbit.h, src/sfnt/ttsbit0.c: Clean up the SFNT_Interface.
-	
+
 	* src/sfnt/ttmtx.c, src/sfnt/ttmtx.h: New files.  Metrics-related
 	tables' loading and parsing code is moved to here.
 	Move `tt_face_get_metrics' here from the truetype module.  The
@@ -377,7 +400,7 @@
 2006-01-27  David Turner  <[email protected]>
 
 	* builds/unix/configure.ac: Fix build problem on Cygwin.
-	
+
 	* builds/unix/install.mk (install): Don't install the internal
 	headers, and remove existing ones if found in the target install
 	directory.
--- a/builds/amiga/src/base/ftsystem.c
+++ b/builds/amiga/src/base/ftsystem.c
@@ -116,7 +116,7 @@
   /*                                                                       */
   /* It is not necessary to do any error checking for the                  */
   /* allocation-related functions.  This will be done by the higher level  */
-  /* routines like FT_Alloc() or FT_Realloc().                             */
+  /* routines like ft_mem_alloc() or ft_mem_realloc().                             */
   /*                                                                       */
   /*************************************************************************/
 
--- a/devel/ftoption.h
+++ b/devel/ftoption.h
@@ -567,7 +567,7 @@
 
   /*
    * This temporary macro is used to control whether we are going to
-   * compile certain functions like FT_Alloc in a way that prevents recent
+   * compile certain functions like ft_mem_alloc in a way that prevents recent
    * GCC releases from emitting zillions of `strict aliasing' warning
    * messages each time a memory-management function is called.
    */
--- a/include/freetype/cache/ftccache.h
+++ b/include/freetype/cache/ftccache.h
@@ -82,6 +82,16 @@
   FTC_Node_Destroy( FTC_Node     node,
                     FTC_Manager  manager );
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+  FT_BASE( void )
+  ftc_node_destroy( FTC_Node     node,
+                    FTC_Manager  manager );
+                    
+  FT_BASE( void )
+  ftc_node_done( FTC_Node     node,
+                 FTC_Manager  manager );
+  
+#endif
 
   /*************************************************************************/
   /*************************************************************************/
--- a/include/freetype/cache/ftccmap.h
+++ b/include/freetype/cache/ftccmap.h
@@ -25,64 +25,15 @@
 
 FT_BEGIN_HEADER
 
+/* the FT 2.1.7 Charmap cache interface 
+ *
+ * unfortunately, it is not possible to implement it in later
+ * versions, since some function signature changed too significantly
+ * to do that.
+ */
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Section>                                                             */
-  /*   cache_subsystem                                                     */
-  /*                                                                       */
-  /*************************************************************************/
+#if 0
 
-  /*************************************************************************
-   *
-   * @type:
-   *   FTC_CMapCache
-   *
-   * @description:
-   *   An opaque handle used to manager a charmap cache.  This cache is to
-   *   hold character codes -> glyph indices mappings.
-   *
-   */
-  typedef struct FTC_CMapCacheRec_*  FTC_CMapCache;
-
-
-  /*************************************************************************
-   *
-   * @type:
-   *   FTC_CMapDesc
-   *
-   * @description:
-   *   A handle to an @FTC_CMapDescRec structure used to describe a given
-   *   charmap in a charmap cache.
-   *
-   *   Each @FTC_CMapDesc describes which charmap (of which @FTC_FaceID) we
-   *   want to use in @FTC_CMapCache_Lookup.
-   *
-   */
-  typedef struct FTC_CMapDescRec_*  FTC_CMapDesc;
-
-
-  /*************************************************************************
-   *
-   * @enum:
-   *   FTC_CMapType
-   *
-   * @description:
-   *   The list of valid @FTC_CMapDesc types.  They indicate how we want to
-   *   address a charmap within an @FTC_FaceID.
-   *
-   * @values:
-   *   FTC_CMAP_BY_INDEX ::
-   *     Address a charmap by its index in the corresponding @FT_Face.
-   *
-   *   FTC_CMAP_BY_ENCODING ::
-   *     Use a @FT_Face charmap that corresponds to a given encoding.
-   *
-   *   FTC_CMAP_BY_ID ::
-   *     Use an @FT_Face charmap that corresponds to a given
-   *     (platform,encoding) ID.  See @FTC_CMapIdRec.
-   *
-   */
   typedef enum  FTC_CMapType_
   {
     FTC_CMAP_BY_INDEX    = 0,
@@ -92,23 +43,6 @@
   } FTC_CMapType;
 
 
-  /*************************************************************************
-   *
-   * @struct:
-   *   FTC_CMapIdRec
-   *
-   * @description:
-   *   A short structure to identify a charmap by a (platform,encoding) pair
-   *   of values.
-   *
-   * @fields:
-   *   platform ::
-   *     The platform ID.
-   *
-   *   encoding ::
-   *     The encoding ID.
-   *
-   */
   typedef struct  FTC_CMapIdRec_
   {
     FT_UInt  platform;
@@ -117,34 +51,6 @@
   } FTC_CMapIdRec;
 
 
-  /*************************************************************************
-   *
-   * @struct:
-   *   FTC_CMapDescRec
-   *
-   * @description:
-   *   A structure to describe a given charmap to @FTC_CMapCache.
-   *
-   * @fields:
-   *   face_id ::
-   *     @FTC_FaceID of the face this charmap belongs to.
-   *
-   *    type ::
-   *      The type of charmap, see @FTC_CMapType.
-   *
-   *    u.index ::
-   *      For @FTC_CMAP_BY_INDEX types, this is the charmap index (within a
-   *      @FT_Face) we want to use.
-   *
-   *    u.encoding ::
-   *      For @FTC_CMAP_BY_ENCODING types, this is the charmap encoding we
-   *      want to use. see @FT_Encoding.
-   *
-   *    u.id ::
-   *      For @FTC_CMAP_BY_ID types, this is the (platform,encoding) pair we
-   *      want to use. see @FTC_CMapIdRec and @FT_CharMapRec.
-   *
-   */
   typedef struct  FTC_CMapDescRec_
   {
     FTC_FaceID    face_id;
@@ -158,72 +64,24 @@
 
     } u;
 
-  } FTC_CMapDescRec;
+  } FTC_CMapDescRec, *FTC_CMapDesc;
 
 
-  /*************************************************************************
-   *
-   * @function:
-   *   FTC_CMapCache_New
-   *
-   * @description:
-   *   Creates a new charmap cache.
-   *
-   * @input:
-   *   manager ::
-   *     A handle to the cache manager.
-   *
-   * @output:
-   *   acache ::
-   *     A new cache handle.  NULL in case of error.
-   *
-   * @return:
-   *   FreeType error code.  0 means success.
-   *
-   * @note:
-   *   Like all other caches, this one will be destroyed with the cache
-   *   manager.
-   *
-   */
+#if 0
   FT_EXPORT( FT_Error )
   FTC_CMapCache_New( FTC_Manager     manager,
                      FTC_CMapCache  *acache );
 
 
-  /*************************************************************************
-   *
-   * @function:
-   *   FTC_CMapCache_Lookup
-   *
-   * @description:
-   *   Translates a character code into a glyph index, using the charmap
-   *   cache.
-   *
-   * @input:
-   *   cache ::
-   *     A charmap cache handle.
-   *
-   *   cmap_desc ::
-   *     A charmap descriptor handle.
-   *
-   *   char_code ::
-   *     The character code (in the corresponding charmap).
-   *
-   * @return:
-   *   Glyph index.  0 means `no glyph'.
-   *
-   * @note:
-   *   This function doesn't return @FTC_Node handles, since there is no
-   *   real use for them with typical uses of charmaps.
-   *
-   */
   FT_EXPORT( FT_UInt )
   FTC_CMapCache_Lookup( FTC_CMapCache  cache,
                         FTC_CMapDesc   cmap_desc,
                         FT_UInt32      char_code );
+#endif
+                        
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
   /* */
-
 
 FT_END_HEADER
 
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -583,12 +583,17 @@
 
   /*
    * This temporary macro is used to control whether we are going to
-   * compile certain functions like FT_Alloc in a way that prevents recent
+   * compile certain functions like ft_mem_alloc in a way that prevents recent
    * GCC releases from emitting zillions of `strict aliasing' warning
    * messages each time a memory-management function is called.
    */
 #define  FT_STRICT_ALIASING
 
+/* define this variable if you want to keep the layout of internal structures
+ * that was used prior to FreeType 2.2. This also compiles in a few obsolete
+ * functions to avoid linking problems on typical Unix distributions
+ */
+#define  FT_CONFIG_OPTION_OLD_INTERNALS
 
 FT_END_HEADER
 
--- a/include/freetype/ftcache.h
+++ b/include/freetype/ftcache.h
@@ -829,6 +829,23 @@
 
  /* */
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+
+  FT_EXPORT( FT_Error )
+  FTC_Manager_Lookup_Face( FTC_Manager  manager,
+                           FTC_FaceID   face_id,
+                           FT_Face     *aface );
+
+  FT_EXPORT( FT_Error )
+  FTC_Manager_Lookup_Size( FTC_Manager  manager,
+                           FTC_Font     font,
+                           FT_Face     *aface,
+                           FT_Size     *asize );
+
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
+
+ /* */
+
 FT_END_HEADER
 
 #endif /* __FTCACHE_H__ */
--- a/include/freetype/ftoutln.h
+++ b/include/freetype/ftoutln.h
@@ -176,7 +176,7 @@
   /*    descriptor will be released.                                       */
   /*                                                                       */
   /*    The reason why this function takes an `library' parameter is       */
-  /*    simply to use FT_Free().                                           */
+  /*    simply to use ft_mem_free().                                           */
   /*                                                                       */
   FT_EXPORT( FT_Error )
   FT_Outline_Done( FT_Library   library,
--- a/include/freetype/internal/ftcalc.h
+++ b/include/freetype/internal/ftcalc.h
@@ -48,7 +48,7 @@
   FT_SqrtFixed( FT_Int32  x );
 
 
-#if 0
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
 
   /*************************************************************************/
   /*                                                                       */
@@ -68,7 +68,7 @@
   FT_EXPORT( FT_Int32 )
   FT_Sqrt32( FT_Int32  x );
 
-#endif /* 0 */
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 
   /*************************************************************************/
--- a/include/freetype/internal/ftdriver.h
+++ b/include/freetype/internal/ftdriver.h
@@ -59,8 +59,21 @@
   typedef FT_Error
   (*FT_Size_SelectFunc)( FT_Size   size,
                          FT_ULong  size_index );
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+  typedef FT_Error
+  (*FT_Size_ResetPointsFunc)( FT_Size     size,
+                              FT_F26Dot6  char_width,
+                              FT_F26Dot6  char_height,
+                              FT_UInt     horz_resolution,
+                              FT_UInt     vert_resolution );
 
   typedef FT_Error
+  (*FT_Size_ResetPixelsFunc)( FT_Size  size,
+                              FT_UInt  pixel_width,
+                              FT_UInt  pixel_height );
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
+
+  typedef FT_Error
   (*FT_Slot_LoadFunc)( FT_GlyphSlot  slot,
                        FT_Size       size,
                        FT_UInt       glyph_index,
@@ -125,16 +138,7 @@
   /*                                                                       */
   /*    done_slot        :: The format-specific slot destructor.           */
   /*                                                                       */
-  /*    request_size     :: A handle to a function used to request the new */
-  /*                        character size.  Can be set to 0 if the        */
-  /*                        scaling done in the base layer suffices.       */
   /*                                                                       */
-  /*    select_size      :: A handle to a function used to select a new    */
-  /*                        fixed size.  It is used only if                */
-  /*                        @FT_FACE_FLAG_FIXED_SIZES is set.  Can be set  */
-  /*                        to 0 if the scaling done in the base layer     */
-  /*                        suffices.                                      */
-  /*                                                                       */
   /*    load_glyph       :: A function handle to load a glyph to a slot.   */
   /*                        This field is mandatory!                       */
   /*                                                                       */
@@ -163,6 +167,15 @@
   /*                        device-independent text layout without loading */
   /*                        a single glyph image.                          */
   /*                                                                       */
+  /*    request_size     :: A handle to a function used to request the new */
+  /*                        character size.  Can be set to 0 if the        */
+  /*                        scaling done in the base layer suffices.       */
+  /*                                                                       */
+  /*    select_size      :: A handle to a function used to select a new    */
+  /*                        fixed size.  It is used only if                */
+  /*                        @FT_FACE_FLAG_FIXED_SIZES is set.  Can be set  */
+  /*                        to 0 if the scaling done in the base layer     */
+  /*                        suffices.                                      */
   /* <Note>                                                                */
   /*    Most function pointers, with the exception of `load_glyph' and     */
   /*    `get_char_index' can be set to 0 to indicate a default behaviour.  */
@@ -184,8 +197,10 @@
     FT_Slot_InitFunc          init_slot;
     FT_Slot_DoneFunc          done_slot;
 
-    FT_Size_RequestFunc       request_size;
-    FT_Size_SelectFunc        select_size;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    FT_Size_ResetPointsFunc   set_char_sizes;
+    FT_Size_ResetPixelsFunc   set_pixel_sizes;
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
     FT_Slot_LoadFunc          load_glyph;
 
@@ -193,8 +208,32 @@
     FT_Face_AttachFunc        attach_file;
     FT_Face_GetAdvancesFunc   get_advances;
 
+    /* since FT 2.2. */
+    FT_Size_RequestFunc       request_size;
+    FT_Size_SelectFunc        select_size;
+
   } FT_Driver_ClassRec, *FT_Driver_Class;
 
+
+/* the following are used as stubs for 'set_char_sizes'
+ * and 'set_pixel_sizes'. their implementation uses
+ * 'request_size' and 'select_size' functions instead
+ *
+ * implementation is in src/base/ftobjs.c
+ */
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+  FT_BASE( FT_Error )
+  ft_stub_set_char_sizes( FT_Size     size,
+                          FT_F26Dot6  width,
+                          FT_F26Dot6  height,
+                          FT_UInt     horz_res,
+                          FT_UInt     vert_res );
+
+  FT_BASE( FT_Error )
+  ft_stub_set_pixel_sizes( FT_Size   size,
+                           FT_UInt   width,
+                           FT_UInt   height );
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 FT_END_HEADER
 
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -67,32 +67,32 @@
    */
 
   FT_BASE( FT_Pointer )
-  FT_Alloc( FT_Memory  memory,
-            FT_Long    size,
-            FT_Error  *p_error );
+  ft_mem_alloc( FT_Memory  memory,
+                FT_Long    size,
+                FT_Error  *p_error );
 
   FT_BASE( FT_Pointer )
-  FT_QAlloc( FT_Memory  memory,
-             FT_Long    size,
-             FT_Error  *p_error );
+  ft_mem_qalloc( FT_Memory  memory,
+                 FT_Long    size,
+                 FT_Error  *p_error );
 
   FT_BASE( FT_Pointer )
-  FT_Realloc( FT_Memory  memory,
-              FT_Long    current,
-              FT_Long    size,
-              void*      block,
-              FT_Error  *p_error );
+  ft_mem_realloc( FT_Memory  memory,
+                  FT_Long    current,
+                  FT_Long    size,
+                  void*      block,
+                  FT_Error  *p_error );
 
   FT_BASE( FT_Pointer )
-  FT_QRealloc( FT_Memory  memory,
-               FT_Long    current,
-               FT_Long    size,
-               void*      block,
-               FT_Error  *p_error );
+  ft_mem_qrealloc( FT_Memory  memory,
+                   FT_Long    current,
+                   FT_Long    size,
+                   void*      block,
+                   FT_Error  *p_error );
 
   FT_BASE( void )
-  FT_Free( FT_Memory    memory,
-           const void*  P );
+  ft_mem_free( FT_Memory    memory,
+               const void*  P );
 
 
 #ifdef FT_DEBUG_MEMORY
@@ -99,58 +99,58 @@
 
 
   FT_BASE( FT_Pointer )
-  FT_Alloc_Debug( FT_Memory    memory,
-                  FT_Long      size,
-                  FT_Error    *p_error,
-                  const char*  file_name,
-                  FT_Long      line_no );
+  ft_mem_alloc_debug( FT_Memory    memory,
+                      FT_Long      size,
+                      FT_Error    *p_error,
+                      const char*  file_name,
+                      FT_Long      line_no );
 
   FT_BASE( FT_Pointer )
-  FT_QAlloc_Debug( FT_Memory    memory,
-                   FT_Long      size,
-                   FT_Error    *p_error,
-                   const char*  file_name,
-                   FT_Long      line_no );
+  ft_mem_qalloc_debug( FT_Memory    memory,
+                       FT_Long      size,
+                       FT_Error    *p_error,
+                       const char*  file_name,
+                       FT_Long      line_no );
 
   FT_BASE( FT_Pointer )
-  FT_Realloc_Debug( FT_Memory    memory,
-                    FT_Long      current,
-                    FT_Long      size,
-                    void*        P,
-                    FT_Error    *p_error,
-                    const char*  file_name,
-                    FT_Long      line_no );
+  ft_mem_realloc_debug( FT_Memory    memory,
+                        FT_Long      current,
+                        FT_Long      size,
+                        void*        P,
+                        FT_Error    *p_error,
+                        const char*  file_name,
+                        FT_Long      line_no );
 
   FT_BASE( FT_Pointer )
-  FT_QRealloc_Debug( FT_Memory    memory,
-                     FT_Long      current,
-                     FT_Long      size,
-                     void*        P,
-                     FT_Error    *p_error,
+  ft_mem_qrealloc_debug( FT_Memory    memory,
+                         FT_Long      current,
+                         FT_Long      size,
+                         void*        P,
+                         FT_Error    *p_error,
+                         const char*  file_name,
+                         FT_Long      line_no );
+
+  FT_BASE( void )
+  ft_mem_free_debug( FT_Memory    memory,
+                     const void  *P,
                      const char*  file_name,
                      FT_Long      line_no );
 
-  FT_BASE( void )
-  FT_Free_Debug( FT_Memory    memory,
-                 const void  *P,
-                 const char*  file_name,
-                 FT_Long      line_no );
-
 #define FT_MEM_ALLOC( _pointer_, _size_ )                       \
-          (_pointer_) = FT_Alloc_Debug( memory, _size_, &error, \
+          (_pointer_) = ft_mem_alloc_debug( memory, _size_, &error, \
                           __FILE__, __LINE__ )
 
 #define FT_MEM_REALLOC( _pointer_, _current_, _size_ )               \
-          (_pointer_) = FT_Realloc_Debug( memory, _current_, _size_, \
+          (_pointer_) = ft_mem_realloc_debug( memory, _current_, _size_, \
                           (_pointer_), &error,                       \
                           __FILE__, __LINE__ )
 
 #define FT_MEM_QALLOC( _pointer_, _size_ )                       \
-          (_pointer_) = FT_QAlloc_Debug( memory, _size_, &error, \
+          (_pointer_) = ft_mem_qalloc_debug( memory, _size_, &error, \
                           __FILE__, __LINE__ )
 
 #define FT_MEM_QREALLOC( _pointer_, _current_, _size_ )               \
-          (_pointer_) = FT_QRealloc_Debug( memory, _current_, _size_, \
+          (_pointer_) = ft_mem_qrealloc_debug( memory, _current_, _size_, \
                           (_pointer_), &error,                        \
                           __FILE__, __LINE__ )
 
@@ -158,7 +158,7 @@
           FT_BEGIN_STMNT                                                \
             if ( _pointer_ )                                            \
             {                                                           \
-              FT_Free_Debug( memory, (_pointer_), __FILE__, __LINE__ ); \
+              ft_mem_free_debug( memory, (_pointer_), __FILE__, __LINE__ ); \
               (_pointer_) = NULL;                                       \
             }                                                           \
           FT_END_STMNT
@@ -168,26 +168,26 @@
 
 
 #define FT_MEM_ALLOC( _pointer_, _size_ )                  \
-          (_pointer_) = FT_Alloc( memory, _size_, &error )
+          (_pointer_) = ft_mem_alloc( memory, _size_, &error )
 
 #define FT_MEM_FREE( _pointer_ )              \
           FT_BEGIN_STMNT                      \
             if ( (_pointer_) )                \
             {                                 \
-              FT_Free( memory, (_pointer_) ); \
+              ft_mem_free( memory, (_pointer_) ); \
               (_pointer_) = NULL;             \
             }                                 \
           FT_END_STMNT
 
 #define FT_MEM_REALLOC( _pointer_, _current_, _size_ )         \
-          (_pointer_) = FT_Realloc( memory, _current_, _size_, \
+          (_pointer_) = ft_mem_realloc( memory, _current_, _size_, \
                                     (_pointer_), &error )
 
 #define FT_MEM_QALLOC( _pointer_, _size_ )                  \
-          (_pointer_) = FT_QAlloc( memory, _size_, &error )
+          (_pointer_) = ft_mem_qalloc( memory, _size_, &error )
 
 #define FT_MEM_QREALLOC( _pointer_, _current_, _size_ )         \
-          (_pointer_) = FT_QRealloc( memory, _current_, _size_, \
+          (_pointer_) = ft_mem_qrealloc( memory, _current_, _size_, \
                                      (_pointer_), &error )
 
 #endif /* !FT_DEBUG_MEMORY */
@@ -203,42 +203,42 @@
 
 
   FT_BASE( FT_Error )
-  FT_Alloc_Debug( FT_Memory    memory,
-                  FT_Long      size,
-                  void*       *P,
-                  const char*  file_name,
-                  FT_Long      line_no );
+  ft_mem_alloc_debug( FT_Memory    memory,
+                      FT_Long      size,
+                      void*       *P,
+                      const char*  file_name,
+                      FT_Long      line_no );
 
   FT_BASE( FT_Error )
-  FT_QAlloc_Debug( FT_Memory    memory,
-                   FT_Long      size,
-                   void*       *P,
-                   const char*  file_name,
-                   FT_Long      line_no );
+  ft_mem_qalloc_debug( FT_Memory    memory,
+                       FT_Long      size,
+                       void*       *P,
+                       const char*  file_name,
+                       FT_Long      line_no );
 
   FT_BASE( FT_Error )
-  FT_Realloc_Debug( FT_Memory    memory,
-                    FT_Long      current,
-                    FT_Long      size,
-                    void*       *P,
-                    const char*  file_name,
-                    FT_Long      line_no );
+  ft_mem_realloc_debug( FT_Memory    memory,
+                        FT_Long      current,
+                        FT_Long      size,
+                        void*       *P,
+                        const char*  file_name,
+                        FT_Long      line_no );
 
   FT_BASE( FT_Error )
-  FT_QRealloc_Debug( FT_Memory    memory,
-                     FT_Long      current,
-                     FT_Long      size,
-                     void*       *P,
+  ft_mem_qrealloc_debug( FT_Memory    memory,
+                         FT_Long      current,
+                         FT_Long      size,
+                         void*       *P,
+                         const char*  file_name,
+                         FT_Long      line_no );
+
+  FT_BASE( void )
+  ft_mem_free_debug( FT_Memory    memory,
+                     FT_Pointer   block,
                      const char*  file_name,
                      FT_Long      line_no );
 
-  FT_BASE( void )
-  FT_Free_Debug( FT_Memory    memory,
-                 FT_Pointer   block,
-                 const char*  file_name,
-                 FT_Long      line_no );
 
-
 #endif /* FT_DEBUG_MEMORY */
 
 
@@ -245,7 +245,7 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FT_Alloc                                                           */
+  /*    ft_mem_alloc                                                           */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Allocates a new block of memory.  The returned area is always      */
@@ -265,15 +265,15 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   FT_BASE( FT_Error )
-  FT_Alloc( FT_Memory  memory,
-            FT_Long    size,
-            void*     *P );
+  ft_mem_alloc( FT_Memory  memory,
+                FT_Long    size,
+                void*     *P );
 
 
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FT_QAlloc                                                          */
+  /*    ft_mem_qalloc                                                      */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Allocates a new block of memory.  The returned area is *not*       */
@@ -293,15 +293,15 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   FT_BASE( FT_Error )
-  FT_QAlloc( FT_Memory  memory,
-             FT_Long    size,
-             void*     *p );
+  ft_mem_qalloc( FT_Memory  memory,
+                 FT_Long    size,
+                 void*     *p );
 
 
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FT_Realloc                                                         */
+  /*    ft_mem_realloc                                                     */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Reallocates a block of memory pointed to by `*P' to `Size' bytes   */
@@ -324,20 +324,20 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   /* <Note>                                                                */
-  /*    All callers of FT_Realloc() _must_ provide the current block size  */
-  /*    as well as the new one.                                            */
+  /*    All callers of ft_mem_realloc() _must_ provide the current block   */
+  /*    size as well as the new one.                                       */
   /*                                                                       */
   FT_BASE( FT_Error )
-  FT_Realloc( FT_Memory  memory,
-              FT_Long    current,
-              FT_Long    size,
-              void*     *P );
+  ft_mem_realloc( FT_Memory  memory,
+                  FT_Long    current,
+                  FT_Long    size,
+                  void*     *P );
 
 
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FT_QRealloc                                                        */
+  /*    ft_mem_qrealloc                                                    */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Reallocates a block of memory pointed to by `*P' to `Size' bytes   */
@@ -360,23 +360,23 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   /* <Note>                                                                */
-  /*    All callers of FT_Realloc() _must_ provide the current block size  */
-  /*    as well as the new one.                                            */
+  /*    All callers of ft_mem_realloc() _must_ provide the current block   */
+  /*    size as well as the new one.                                       */
   /*                                                                       */
   FT_BASE( FT_Error )
-  FT_QRealloc( FT_Memory  memory,
-               FT_Long    current,
-               FT_Long    size,
-               void*     *p );
+  ft_mem_qrealloc( FT_Memory  memory,
+                   FT_Long    current,
+                   FT_Long    size,
+                   void*     *p );
 
 
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FT_Free                                                            */
+  /*    ft_mem_free                                                        */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Releases a given block of memory allocated through FT_Alloc().     */
+  /*    Releases a given block of memory allocated through ft_mem_alloc(). */
   /*                                                                       */
   /* <Input>                                                               */
   /*    memory :: A handle to a given `memory object' which handles        */
@@ -391,8 +391,8 @@
   /*    drivers.                                                           */
   /*                                                                       */
   FT_BASE( void )
-  FT_Free( FT_Memory  memory,
-           void*     *P );
+  ft_mem_free( FT_Memory  memory,
+               void*     *P );
 
 
 #ifdef FT_DEBUG_MEMORY
@@ -399,27 +399,27 @@
 
 
 #define FT_MEM_ALLOC( _pointer_, _size_ )              \
-          FT_Alloc_Debug( memory, _size_,              \
+          ft_mem_alloc_debug( memory, _size_,              \
                           (void**)(void*)&(_pointer_), \
                           __FILE__, __LINE__ )
 
 #define FT_MEM_REALLOC( _pointer_, _current_, _size_ )   \
-          FT_Realloc_Debug( memory, _current_, _size_,   \
+          ft_mem_realloc_debug( memory, _current_, _size_,   \
                             (void**)(void*)&(_pointer_), \
                             __FILE__, __LINE__ )
 
 #define FT_MEM_QALLOC( _pointer_, _size_ )              \
-          FT_QAlloc_Debug( memory, _size_,              \
+          ft_mem_qalloc_debug( memory, _size_,              \
                            (void**)(void*)&(_pointer_), \
                            __FILE__, __LINE__ )
 
 #define FT_MEM_QREALLOC( _pointer_, _current_, _size_ )   \
-          FT_QRealloc_Debug( memory, _current_, _size_,   \
+          ft_mem_qrealloc_debug( memory, _current_, _size_,   \
                              (void**)(void*)&(_pointer_), \
                              __FILE__, __LINE__ )
 
 #define FT_MEM_FREE( _pointer_ )                              \
-          FT_Free_Debug( memory, (void**)(void*)&(_pointer_), \
+          ft_mem_free_debug( memory, (void**)(void*)&(_pointer_), \
                          __FILE__, __LINE__ )
 
 
@@ -427,23 +427,23 @@
 
 
 #define FT_MEM_ALLOC( _pointer_, _size_ )         \
-          FT_Alloc( memory, _size_,               \
+          ft_mem_alloc( memory, _size_,               \
                     (void**)(void*)&(_pointer_) )
 
 #define FT_MEM_FREE( _pointer_ )                 \
-          FT_Free( memory,                       \
+          ft_mem_free( memory,                       \
                    (void**)(void*)&(_pointer_) )
 
 #define FT_MEM_REALLOC( _pointer_, _current_, _size_ ) \
-          FT_Realloc( memory, _current_, _size_,       \
+          ft_mem_realloc( memory, _current_, _size_,       \
                       (void**)(void*)&(_pointer_) )
 
 #define FT_MEM_QALLOC( _pointer_, _size_ )         \
-          FT_QAlloc( memory, _size_,               \
+          ft_mem_qalloc( memory, _size_,               \
                      (void**)(void*)&(_pointer_) )
 
 #define FT_MEM_QREALLOC( _pointer_, _current_, _size_ ) \
-          FT_QRealloc( memory, _current_, _size_,       \
+          ft_mem_qrealloc( memory, _current_, _size_,       \
           (void**)(void*)&(_pointer_) )
 
 
@@ -578,6 +578,36 @@
 #define FT_REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ )    \
           FT_REALLOC( _pointer_, (_old_) * sizeof ( _type_ ),  \
                                  (_new_) * sizeof ( _type_ ) )
+
+
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+
+  FT_BASE( FT_Error )
+  FT_Alloc( FT_Memory  memory,
+            FT_Long    size,
+            void*     *P );
+
+  FT_BASE( FT_Error )
+  FT_QAlloc( FT_Memory  memory,
+             FT_Long    size,
+             void*     *p );
+
+  FT_BASE( FT_Error )
+  FT_Realloc( FT_Memory  memory,
+              FT_Long    current,
+              FT_Long    size,
+              void*     *P );
+
+  FT_BASE( FT_Error )
+  FT_QRealloc( FT_Memory  memory,
+               FT_Long    current,
+               FT_Long    size,
+               void*     *p );
+  FT_BASE( void )
+  FT_Free( FT_Memory  memory,
+           void*     *P );
+
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 
  /* */
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -213,6 +213,10 @@
   /*                                                                       */
   typedef struct  FT_Face_InternalRec_
   {
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    FT_UShort           reserved1;
+    FT_Short            reserved2;
+#endif
     FT_Matrix           transform_matrix;
     FT_Vector           transform_delta;
     FT_Int              transform_flags;
--- a/include/freetype/internal/ftrfork.h
+++ b/include/freetype/internal/ftrfork.h
@@ -154,7 +154,7 @@
   /*    offsets ::                                                         */
   /*      The stream offsets for the resource data specified by `tag'.     */
   /*      This array is allocated by the function, so you have to call     */
-  /*      @FT_Free after use.                                              */
+  /*      @ft_mem_free after use.                                              */
   /*                                                                       */
   /*    count ::                                                           */
   /*      The length of offsets array.                                     */
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -784,7 +784,6 @@
     const PS_Parser_FuncsRec*   ps_parser_funcs;
     const T1_Builder_FuncsRec*  t1_builder_funcs;
     const T1_Decoder_FuncsRec*  t1_decoder_funcs;
-    const AFM_Parser_FuncsRec*  afm_parser_funcs;
 
     void
     (*t1_decrypt)( FT_Byte*   buffer,
@@ -792,6 +791,9 @@
                    FT_UShort  seed );
 
     T1_CMap_Classes  t1_cmap_classes;
+
+    /* fields from here were added after 2.1.10 */
+    const AFM_Parser_FuncsRec*  afm_parser_funcs;
 
   } PSAux_ServiceRec, *PSAux_Service;
 
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -125,9 +125,78 @@
   (*TT_Done_Face_Func)( TT_Face  face );
 
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
   /*************************************************************************/
   /*                                                                       */
   /* <FuncType>                                                            */
+  /*    TT_Load_SFNT_HeaderRec_Func                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Loads the header of a SFNT font file.  Supports collections.       */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face       :: A handle to the target face object.                  */
+  /*                                                                       */
+  /*    stream     :: The input stream.                                    */
+  /*                                                                       */
+  /*    face_index :: The index of the TrueType font, if we are opening a  */
+  /*                  collection.                                          */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    sfnt       :: The SFNT header.                                     */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The stream cursor must be at the font file's origin.               */
+  /*                                                                       */
+  /*    This function recognizes fonts embedded in a `TrueType             */
+  /*    collection'.                                                       */
+  /*                                                                       */
+  /*    This function checks that the header is valid by looking at the    */
+  /*    values of `search_range', `entry_selector', and `range_shift'.     */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_Load_SFNT_HeaderRec_Func)( TT_Face      face,
+                                  FT_Stream    stream,
+                                  FT_Long      face_index,
+                                  SFNT_Header  sfnt );
+
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Load_Directory_Func                                             */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Loads the table directory into a face object.                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face      :: A handle to the target face object.                   */
+  /*                                                                       */
+  /*    stream    :: The input stream.                                     */
+  /*                                                                       */
+  /*    sfnt      :: The SFNT header.                                      */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The stream cursor must be on the first byte after the 4-byte font  */
+  /*    format tag.  This is the case just after a call to                 */
+  /*    TT_Load_Format_Tag().                                              */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_Load_Directory_Func)( TT_Face      face,
+                             FT_Stream    stream,
+                             SFNT_Header  sfnt );
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
   /*    TT_Load_Any_Func                                                   */
   /*                                                                       */
   /* <Description>                                                         */
@@ -292,9 +361,88 @@
                               TT_SBit_MetricsRec  *ametrics );
 
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
   /*************************************************************************/
   /*                                                                       */
   /* <FuncType>                                                            */
+  /*    TT_Set_SBit_Strike_OldFunc                                         */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Select an sbit strike for a given size request.                    */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face          :: The target face object.                           */
+  /*                                                                       */
+  /*    req           :: The size request.                                 */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    astrike_index :: The index of the sbit strike.                     */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.  Returns an error if no     */
+  /*    sbit strike exists for the selected ppem values.                   */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_Set_SBit_Strike_OldFunc)( TT_Face    face,
+                                 FT_UInt    x_ppem,
+                                 FT_UInt    y_ppem,
+                                 FT_ULong*  astrike_index );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_CharMap_Load_Func                                               */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Loads a given TrueType character map into memory.                  */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face   :: A handle to the parent face object.                      */
+  /*                                                                       */
+  /*    stream :: A handle to the current stream object.                   */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    cmap   :: A pointer to a cmap object.                              */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The function assumes that the stream is already in use (i.e.,      */
+  /*    opened).  In case of error, all partially allocated tables are     */
+  /*    released.                                                          */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_CharMap_Load_Func)( TT_Face       face,
+                           void*         cmap,
+                           FT_Stream     input );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_CharMap_Free_Func                                               */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Destroys a character mapping table.                                */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face :: A handle to the parent face object.                        */
+  /*                                                                       */
+  /*    cmap :: A handle to a cmap object.                                 */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  typedef FT_Error
+  (*TT_CharMap_Free_Func)( TT_Face       face,
+                           void*         cmap );
+
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
   /*    TT_Set_SBit_Strike_Func                                            */
   /*                                                                       */
   /* <Description>                                                         */
@@ -503,49 +651,80 @@
     FT_Module_Requester          get_interface;
 
     TT_Load_Any_Func             load_any;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    TT_Load_SFNT_HeaderRec_Func  load_sfnt_header;
+    TT_Load_Directory_Func       load_directory;
+#endif
 
-    /* load the font directory, i.e., the offset table and */
-    /* the table directory                                 */
-    TT_Load_Table_Func           load_font_dir;
-
     /* these functions are called by `load_face' but they can also  */
     /* be called from external modules, if there is a need to do so */
     TT_Load_Table_Func           load_head;
     TT_Load_Metrics_Func         load_hhea;
-    TT_Load_Metrics_Func         load_hmtx;
     TT_Load_Table_Func           load_cmap;
     TT_Load_Table_Func           load_maxp;
     TT_Load_Table_Func           load_os2;
     TT_Load_Table_Func           load_post;
+
     TT_Load_Table_Func           load_name;
     TT_Free_Table_Func           free_name;
 
     /* optional tables */
-    TT_Load_Table_Func           load_kern;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    TT_Load_Table_Func           load_hdmx_stub;
+    TT_Free_Table_Func           free_hdmx_stub;
+#endif
+    TT_Load_Table_Func           load_kern;  /* a.k.a load_kerning <= 2.1.10 */
+
     TT_Load_Table_Func           load_gasp;
     TT_Load_Table_Func           load_pclt;
 
     /* see `ttload.h' */
-    TT_Load_Table_Func           load_bhed;
+    TT_Load_Table_Func           load_bhed;  /* a.k.a load_bitmap_header <= 2.1.10 */
 
     /* see `ttsbit.h' */
-    TT_Load_Table_Func           load_eblc;
-    TT_Free_Table_Func           free_eblc;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    TT_Set_SBit_Strike_OldFunc   set_sbit_strike_stub;
+    TT_Load_Table_Func           load_sbits_stub;
+#endif
 
-    TT_Set_SBit_Strike_Func      set_sbit_strike;
-    TT_Load_Strike_Metrics_Func  load_strike_metrics;
-    TT_Find_SBit_Image_Func      find_sbit_image;
-    TT_Load_SBit_Metrics_Func    load_sbit_metrics;
     TT_Load_SBit_Image_Func      load_sbit_image;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    TT_Free_Table_Func           free_sbits_stub;
+#endif
 
-    /* see `ttkern.h' */
-    TT_Face_GetKerningFunc       get_kerning;
-    
-    TT_Get_Metrics_Func          get_metrics;
-
     /* see `ttpost.h' */
     TT_Get_PS_Name_Func          get_psname;
     TT_Free_Table_Func           free_psnames;
+
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS  /* the following disappeared in 2.1.8, but were there before */
+    TT_CharMap_Load_Func         load_charmap_stub;
+    TT_CharMap_Free_Func         free_charmap_stub;
+#endif
+
+    /* from here, the structure differs from 2.1.7 */
+
+    /* since FT 2.1.8, but appeared before 'get_psname' */
+    TT_Face_GetKerningFunc       get_kerning;
+
+   /* the following appeared in 2.1.8, but were placed
+    * between 'load_sbits' and 'load_sbit_image'. BOOOOH
+    */
+    TT_Find_SBit_Image_Func      find_sbit_image;    /* NULL if FT_OPTIMIZE_MEMORY */
+    TT_Load_SBit_Metrics_Func    load_sbit_metrics;  /* NULL if FT_OPTIMIZE_MEMORY */
+
+    /* since FreeType 2.2 */
+    /* load the font directory, i.e., the offset table and */
+    /* the table directory                                 */
+    TT_Load_Table_Func           load_font_dir;
+    TT_Load_Metrics_Func         load_hmtx;
+    
+    TT_Load_Table_Func           load_eblc;
+    TT_Free_Table_Func           free_eblc;
+    
+    TT_Set_SBit_Strike_Func      set_sbit_strike;
+    TT_Load_Strike_Metrics_Func  load_strike_metrics;
+    
+    TT_Get_Metrics_Func          get_metrics;
 
   } SFNT_Interface;
 
--- a/include/freetype/internal/t1types.h
+++ b/include/freetype/internal/t1types.h
@@ -200,7 +200,9 @@
     const void*     afm_data;
     FT_CharMapRec   charmaprecs[2];
     FT_CharMap      charmaps[2];
-    PS_UnicodesRec  unicode_map;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    PS_Unicodes     unicode_map;  /* apparently unused, keep for old internals */
+#endif    
 
     /* support for Multiple Masters fonts */
     PS_Blend        blend;
@@ -218,12 +220,14 @@
     void*            psaux;
     CID_FaceInfoRec  cid;
     void*            afm_data;
-    FT_Byte*         binary_data; /* used if hex data has been converted */
-    FT_Stream        cid_stream;
     CID_Subrs        subrs;
 
     /* since FT 2.1 - interface to PostScript hinter */
     void*            pshinter;
+
+    /* since FT 2.1.8, but was originally after 'afm_data' */
+    FT_Byte*         binary_data; /* used if hex data has been converted */
+    FT_Stream        cid_stream;
 
   } CID_FaceRec;
 
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -311,7 +311,7 @@
   } TT_GaspRec;
 
 
-#ifndef FT_OPTIMIZE_MEMORY
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
 
   /*************************************************************************/
   /*                                                                       */
@@ -389,7 +389,7 @@
 
   } TT_Kern0_PairRec, *TT_Kern0_Pair;
 
-#endif /* !OPTIMIZE_MEMORY */
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 
   /*************************************************************************/
@@ -1267,19 +1267,14 @@
 
     TT_Header             header;       /* TrueType header table          */
     TT_HoriHeader         horizontal;   /* TrueType horizontal header     */
-#ifdef FT_OPTIMIZE_MEMORY
-    FT_Byte*              horz_metrics;
-    FT_ULong              horz_metrics_size;
-#endif
 
     TT_MaxProfile         max_profile;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    FT_ULong              max_components;  /* stubbed to 0 */
+#endif
 
     FT_Bool               vertical_info;
     TT_VertHeader         vertical;     /* TT Vertical header, if present */
-#ifdef FT_OPTIMIZE_MEMORY
-    FT_Byte*              vert_metrics;
-    FT_ULong              vert_metrics_size;
-#endif
 
     FT_UShort             num_names;    /* number of name records  */
     TT_NameTableRec       name_table;   /* name table              */
@@ -1314,13 +1309,7 @@
     /***********************************************************************/
 
     /* horizontal device metrics */
-#ifdef FT_OPTIMIZE_MEMORY
-    FT_Byte*              hdmx_table;
-    FT_ULong              hdmx_table_size;
-    FT_UInt               hdmx_record_count;
-    FT_ULong              hdmx_record_size;
-    FT_Byte*              hdmx_record_sizes;
-#else
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
     TT_HdmxRec            hdmx;
 #endif
 
@@ -1331,11 +1320,7 @@
     TT_PCLT               pclt;
 
     /* embedded bitmaps support */
-#ifdef FT_OPTIMIZE_MEMORY
-    FT_Byte*              sbit_table;
-    FT_ULong              sbit_table_size;
-    FT_UInt               sbit_num_strikes;
-#else
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
     FT_ULong              num_sbit_strikes;
     TT_SBit_Strike        sbit_strikes;
 #endif
@@ -1354,16 +1339,11 @@
     /***********************************************************************/
 
     /* the glyph locations */
-#ifdef FT_OPTIMIZE_MEMORY
-    FT_UInt               num_locations;
-    FT_Byte*              glyph_locations;
-#else
-    FT_UShort             num_locations;
-    FT_Long*              glyph_locations;
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    FT_UShort             num_locations_stub;
+    FT_Long*              glyph_locations_stub;
 #endif
 
-    FT_ULong              glyf_len;
-
     /* the font program, if any */
     FT_ULong              font_program_size;
     FT_Byte*              font_program;
@@ -1376,13 +1356,7 @@
     FT_ULong              cvt_size;
     FT_Short*             cvt;
 
-#ifdef FT_OPTIMIZE_MEMORY
-    FT_Byte*              kern_table;
-    FT_ULong              kern_table_size;
-    FT_UInt               num_kern_tables;
-    FT_UInt32             kern_avail_bits;
-    FT_UInt32             kern_order_bits;
-#else
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
     /* the format 0 kerning table, if any */
     FT_Int                num_kern_pairs;
     FT_Int                kern_table_index;
@@ -1398,15 +1372,6 @@
     FT_Bool               unpatented_hinting;
 #endif
 
-#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
-    FT_Bool               doblend;
-    GX_Blend              blend;
-#endif
-
-#ifdef TT_CONFIG_OPTION_BDF
-    TT_BDFRec             bdf;
-#endif /* TT_CONFIG_OPTION_BDF */
-
     /***********************************************************************/
     /*                                                                     */
     /* Other tables or fields. This is used by derivative formats like     */
@@ -1418,6 +1383,48 @@
 
     const char*           postscript_name;
 
+    /* since FreeType 2.1.8, but was originally placed after 'glyph_locations_stub' */
+    FT_ULong              glyf_len;
+
+    /* since FreeType 2.1.8, but was originally placed before 'extra' */
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+    FT_Bool               doblend;
+    GX_Blend              blend;
+#endif
+
+    /* since FreeType 2.2 */
+
+#ifdef FT_OPTIMIZE_MEMORY
+    FT_Byte*              horz_metrics;
+    FT_ULong              horz_metrics_size;
+
+    FT_Byte*              vert_metrics;
+    FT_ULong              vert_metrics_size;
+
+    FT_UInt               num_locations;
+    FT_Byte*              glyph_locations;
+
+    FT_Byte*              hdmx_table;
+    FT_ULong              hdmx_table_size;
+    FT_UInt               hdmx_record_count;
+    FT_ULong              hdmx_record_size;
+    FT_Byte*              hdmx_record_sizes;
+
+    FT_Byte*              sbit_table;
+    FT_ULong              sbit_table_size;
+    FT_UInt               sbit_num_strikes;
+
+    FT_Byte*              kern_table;
+    FT_ULong              kern_table_size;
+    FT_UInt               num_kern_tables;
+    FT_UInt32             kern_avail_bits;
+    FT_UInt32             kern_order_bits;
+#endif
+
+#ifdef TT_CONFIG_OPTION_BDF
+    TT_BDFRec             bdf;
+#endif /* TT_CONFIG_OPTION_BDF */
+
   } TT_FaceRec;
 
 
@@ -1488,15 +1495,11 @@
     FT_BBox          bbox;
     FT_Int           left_bearing;
     FT_Int           advance;
-    FT_Int           top_bearing;
-    FT_Int           vadvance;
     FT_Int           linear;
     FT_Bool          linear_def;
     FT_Bool          preserve_pps;
     FT_Vector        pp1;
     FT_Vector        pp2;
-    FT_Vector        pp3;
-    FT_Vector        pp4;
 
     FT_ULong         glyf_offset;
 
@@ -1510,6 +1513,12 @@
 
     /* for possible extensibility in other formats */
     void*            other;
+
+    /* since FT 2.1.8 */
+    FT_Int           top_bearing;
+    FT_Int           vadvance;
+    FT_Vector        pp3;
+    FT_Vector        pp4;
 
   } TT_LoaderRec;
 
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -99,7 +99,7 @@
   }
 
 
-#if 0
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
 
   /* documentation is in ftcalc.h */
 
@@ -130,7 +130,7 @@
     return root;
   }
 
-#endif /* 0 */
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 
 #ifdef FT_LONG64
--- a/src/base/ftdbgmem.c
+++ b/src/base/ftdbgmem.c
@@ -891,7 +891,7 @@
 
 
   FT_BASE_DEF( FT_Pointer )
-  FT_Alloc_Debug( FT_Memory    memory,
+  ft_mem_alloc_debug( FT_Memory    memory,
                   FT_Long      size,
                   FT_Error    *p_error,
                   const char*  file_name,
@@ -906,12 +906,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_Alloc( memory, size, p_error );
+    return ft_mem_alloc( memory, size, p_error );
   }
 
 
   FT_BASE_DEF( FT_Pointer )
-  FT_Realloc_Debug( FT_Memory    memory,
+  ft_mem_realloc_debug( FT_Memory    memory,
                     FT_Long      current,
                     FT_Long      size,
                     void*        block,
@@ -928,12 +928,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_Realloc( memory, current, size, block, p_error );
+    return ft_mem_realloc( memory, current, size, block, p_error );
   }
 
 
   FT_BASE_DEF( FT_Pointer )
-  FT_QAlloc_Debug( FT_Memory    memory,
+  ft_mem_qalloc_debug( FT_Memory    memory,
                    FT_Long      size,
                    FT_Error    *p_error,
                    const char*  file_name,
@@ -948,12 +948,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_QAlloc( memory, size, p_error );
+    return ft_mem_qalloc( memory, size, p_error );
   }
 
 
   FT_BASE_DEF( FT_Pointer )
-  FT_QRealloc_Debug( FT_Memory    memory,
+  ft_mem_qrealloc_debug( FT_Memory    memory,
                      FT_Long      current,
                      FT_Long      size,
                      void*        block,
@@ -970,12 +970,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_QRealloc( memory, current, size, block, p_error );
+    return ft_mem_qrealloc( memory, current, size, block, p_error );
   }
 
 
   FT_BASE_DEF( void )
-  FT_Free_Debug( FT_Memory    memory,
+  ft_mem_free_debug( FT_Memory    memory,
                  const void  *P,
                  const char*  file_name,
                  FT_Long      line_no )
@@ -989,7 +989,7 @@
       table->line_no   = line_no;
     }
 
-    FT_Free( memory, (void *)P );
+    ft_mem_free( memory, (void *)P );
   }
 
 
@@ -997,7 +997,7 @@
 
 
   FT_BASE_DEF( FT_Error )
-  FT_Alloc_Debug( FT_Memory    memory,
+  ft_mem_alloc_debug( FT_Memory    memory,
                   FT_Long      size,
                   void*       *P,
                   const char*  file_name,
@@ -1012,12 +1012,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_Alloc( memory, size, P );
+    return ft_mem_alloc( memory, size, P );
   }
 
 
   FT_BASE_DEF( FT_Error )
-  FT_Realloc_Debug( FT_Memory    memory,
+  ft_mem_realloc_debug( FT_Memory    memory,
                     FT_Long      current,
                     FT_Long      size,
                     void*       *P,
@@ -1033,12 +1033,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_Realloc( memory, current, size, P );
+    return ft_mem_realloc( memory, current, size, P );
   }
 
 
   FT_BASE_DEF( FT_Error )
-  FT_QAlloc_Debug( FT_Memory    memory,
+  ft_mem_qalloc_debug( FT_Memory    memory,
                    FT_Long      size,
                    void*       *P,
                    const char*  file_name,
@@ -1053,12 +1053,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_QAlloc( memory, size, P );
+    return ft_mem_qalloc( memory, size, P );
   }
 
 
   FT_BASE_DEF( FT_Error )
-  FT_QRealloc_Debug( FT_Memory    memory,
+  ft_mem_qrealloc_debug( FT_Memory    memory,
                      FT_Long      current,
                      FT_Long      size,
                      void*       *P,
@@ -1074,12 +1074,12 @@
       table->line_no   = line_no;
     }
 
-    return FT_QRealloc( memory, current, size, P );
+    return ft_mem_qrealloc( memory, current, size, P );
   }
 
 
   FT_BASE_DEF( void )
-  FT_Free_Debug( FT_Memory    memory,
+  ft_mem_free_debug( FT_Memory    memory,
                  FT_Pointer   block,
                  const char*  file_name,
                  FT_Long      line_no )
@@ -1093,7 +1093,7 @@
       table->line_no   = line_no;
     }
 
-    FT_Free( memory, (void **)block );
+    ft_mem_free( memory, (void **)block );
   }
 
 
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1734,7 +1734,7 @@
     {
       FT_Int  i;
 
-      
+
       for ( i = 0; i < face->num_fixed_sizes; i++ )
       {
         FT_Bitmap_Size*  bsize = face->available_sizes + i;
@@ -3674,5 +3674,61 @@
       library->debug_hooks[hook_index] = debug_hook;
   }
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+  FT_BASE_DEF( FT_Error )
+  ft_stub_set_char_sizes( FT_Size     size,
+                          FT_F26Dot6  width,
+                          FT_F26Dot6  height,
+                          FT_UInt     horz_res,
+                          FT_UInt     vert_res )
+  {
+    FT_Size_RequestRec  req;
+    FT_Driver           driver = size->face->driver;
+
+    if ( driver->clazz->request_size )
+    {
+      req.type   = FT_SIZE_REQUEST_TYPE_NOMINAL;
+      req.width  = width;
+      req.height = height;
+
+      if ( horz_res == 0 )
+        horz_res = vert_res;
+
+      if ( vert_res == 0 )
+        vert_res = horz_res;
+
+      if ( horz_res == 0 )
+        horz_res = vert_res = 72;
+
+      req.horiResolution = horz_res;
+      req.vertResolution = vert_res;
+
+      return driver->clazz->request_size( size, &req );
+    }
+    return 0;
+  }
+
+
+  FT_BASE_DEF( FT_Error )
+  ft_stub_set_pixel_sizes( FT_Size   size,
+                           FT_UInt   width,
+                           FT_UInt   height )
+  {
+    FT_Size_RequestRec  req;
+    FT_Driver           driver = size->face->driver;
+
+    if ( driver->clazz->request_size )
+    {
+      req.type           = FT_SIZE_REQUEST_TYPE_NOMINAL;
+      req.width          = width << 6;
+      req.height         = height << 6;
+      req.horiResolution = 0;
+      req.vertResolution = 0;
+
+      return driver->clazz->request_size( size, &req );
+    }
+    return 0;
+  }
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 /* END */
--- a/src/base/ftsystem.c
+++ b/src/base/ftsystem.c
@@ -46,7 +46,7 @@
   /*                                                                       */
   /* It is not necessary to do any error checking for the                  */
   /* allocation-related functions.  This will be done by the higher level  */
-  /* routines like FT_Alloc() or FT_Realloc().                             */
+  /* routines like ft_mem_alloc() or ft_mem_realloc().                             */
   /*                                                                       */
   /*************************************************************************/
 
--- a/src/base/ftutil.c
+++ b/src/base/ftutil.c
@@ -50,14 +50,14 @@
 
 
   FT_BASE_DEF( FT_Pointer )
-  FT_Alloc( FT_Memory  memory,
+  ft_mem_alloc( FT_Memory  memory,
             FT_Long    size,
             FT_Error  *p_error )
   {
     FT_Error    error = FT_Err_Ok;
     FT_Pointer  block = NULL;
-    
 
+
     if ( size > 0 )
     {
       block = memory->alloc( memory, size );
@@ -70,17 +70,17 @@
     *p_error = error;
     return block;
   }
-              
 
+
   FT_BASE_DEF( FT_Pointer )
-  FT_QAlloc( FT_Memory  memory,
+  ft_mem_qalloc( FT_Memory  memory,
              FT_Long    size,
              FT_Error  *p_error )
   {
     FT_Error    error = FT_Err_Ok;
     FT_Pointer  block = NULL;
-    
 
+
     if ( size > 0 )
     {
       block = memory->alloc( memory, size );
@@ -91,10 +91,10 @@
     *p_error = error;
     return block;
   }
-               
 
+
   FT_BASE_DEF( FT_Pointer )
-  FT_Realloc( FT_Memory  memory,
+  ft_mem_realloc( FT_Memory  memory,
               FT_Long    current,
               FT_Long    size,
               void*      block,
@@ -101,18 +101,18 @@
               FT_Error  *p_error )
   {
     FT_Error  error = FT_Err_Ok;
-    
 
+
     if ( size <= 0 )
     {
-      FT_Free( memory, block );
+      ft_mem_free( memory, block );
       block = NULL;
     }
     else if ( current <= 0 )
     {
       FT_ASSERT( block == NULL );
-      
-      block = FT_Alloc( memory, size, &error );
+
+      block = ft_mem_alloc( memory, size, &error );
     }
     else
     {
@@ -133,10 +133,10 @@
     *p_error = error;
     return block;
   }
-                
+
 
   FT_BASE_DEF( FT_Pointer )
-  FT_QRealloc( FT_Memory  memory,
+  ft_mem_qrealloc( FT_Memory  memory,
                FT_Long    current,
                FT_Long    size,
                void*      block,
@@ -143,18 +143,18 @@
                FT_Error  *p_error )
   {
     FT_Error  error = FT_Err_Ok;
-    
 
+
     if ( size <= 0 )
     {
-      FT_Free( memory, block );
+      ft_mem_free( memory, block );
       block = NULL;
     }
     else if ( current <= 0 )
     {
       FT_ASSERT( block == NULL );
-      
-      block = FT_QAlloc( memory, size, &error );
+
+      block = ft_mem_qalloc( memory, size, &error );
     }
     else
     {
@@ -170,15 +170,15 @@
 
     *p_error = error;
     return block;
-  }               
+  }
 
   FT_BASE_DEF( void )
-  FT_Free( FT_Memory   memory,
+  ft_mem_free( FT_Memory   memory,
            const void *P )
   {
     if ( P )
       memory->free( memory, (void*)P );
-  }           
+  }
 
 
 #else /* !FT_STRICT_ALIASING */
@@ -187,7 +187,7 @@
   /* documentation is in ftmemory.h */
 
   FT_BASE_DEF( FT_Error )
-  FT_Alloc( FT_Memory  memory,
+  ft_mem_alloc( FT_Memory  memory,
             FT_Long    size,
             void*     *P )
   {
@@ -198,7 +198,7 @@
       *P = memory->alloc( memory, size );
       if ( !*P )
       {
-        FT_ERROR(( "FT_Alloc:" ));
+        FT_ERROR(( "ft_mem_alloc:" ));
         FT_ERROR(( " Out of memory? (%ld requested)\n",
                    size ));
 
@@ -209,7 +209,7 @@
     else
       *P = NULL;
 
-    FT_TRACE7(( "FT_Alloc:" ));
+    FT_TRACE7(( "ft_mem_alloc:" ));
     FT_TRACE7(( " size = %ld, block = 0x%08p, ref = 0x%08p\n",
                 size, *P, P ));
 
@@ -220,7 +220,7 @@
   /* documentation is in ftmemory.h */
 
   FT_BASE_DEF( FT_Error )
-  FT_QAlloc( FT_Memory  memory,
+  ft_mem_qalloc( FT_Memory  memory,
              FT_Long    size,
              void*     *P )
   {
@@ -231,7 +231,7 @@
       *P = memory->alloc( memory, size );
       if ( !*P )
       {
-        FT_ERROR(( "FT_QAlloc:" ));
+        FT_ERROR(( "ft_mem_qalloc:" ));
         FT_ERROR(( " Out of memory? (%ld requested)\n",
                    size ));
 
@@ -241,7 +241,7 @@
     else
       *P = NULL;
 
-    FT_TRACE7(( "FT_QAlloc:" ));
+    FT_TRACE7(( "ft_mem_qalloc:" ));
     FT_TRACE7(( " size = %ld, block = 0x%08p, ref = 0x%08p\n",
                 size, *P, P ));
 
@@ -252,7 +252,7 @@
   /* documentation is in ftmemory.h */
 
   FT_BASE_DEF( FT_Error )
-  FT_Realloc( FT_Memory  memory,
+  ft_mem_realloc( FT_Memory  memory,
               FT_Long    current,
               FT_Long    size,
               void**     P )
@@ -262,14 +262,14 @@
 
     FT_ASSERT( P != 0 );
 
-    /* if the original pointer is NULL, call FT_Alloc() */
+    /* if the original pointer is NULL, call ft_mem_alloc() */
     if ( !*P )
-      return FT_Alloc( memory, size, P );
+      return ft_mem_alloc( memory, size, P );
 
     /* if the new block if zero-sized, clear the current one */
     if ( size <= 0 )
     {
-      FT_Free( memory, P );
+      ft_mem_free( memory, P );
       return FT_Err_Ok;
     }
 
@@ -284,7 +284,7 @@
     return FT_Err_Ok;
 
   Fail:
-    FT_ERROR(( "FT_Realloc:" ));
+    FT_ERROR(( "ft_mem_realloc:" ));
     FT_ERROR(( " Failed (current %ld, requested %ld)\n",
                current, size ));
     return FT_Err_Out_Of_Memory;
@@ -294,7 +294,7 @@
   /* documentation is in ftmemory.h */
 
   FT_BASE_DEF( FT_Error )
-  FT_QRealloc( FT_Memory  memory,
+  ft_mem_qrealloc( FT_Memory  memory,
                FT_Long    current,
                FT_Long    size,
                void**     P )
@@ -304,14 +304,14 @@
 
     FT_ASSERT( P != 0 );
 
-    /* if the original pointer is NULL, call FT_QAlloc() */
+    /* if the original pointer is NULL, call ft_mem_qalloc() */
     if ( !*P )
-      return FT_QAlloc( memory, size, P );
+      return ft_mem_qalloc( memory, size, P );
 
     /* if the new block if zero-sized, clear the current one */
     if ( size <= 0 )
     {
-      FT_Free( memory, P );
+      ft_mem_free( memory, P );
       return FT_Err_Ok;
     }
 
@@ -323,7 +323,7 @@
     return FT_Err_Ok;
 
   Fail:
-    FT_ERROR(( "FT_QRealloc:" ));
+    FT_ERROR(( "ft_mem_qrealloc:" ));
     FT_ERROR(( " Failed (current %ld, requested %ld)\n",
                current, size ));
     return FT_Err_Out_Of_Memory;
@@ -333,10 +333,10 @@
   /* documentation is in ftmemory.h */
 
   FT_BASE_DEF( void )
-  FT_Free( FT_Memory  memory,
+  ft_mem_free( FT_Memory  memory,
            void**     P )
   {
-    FT_TRACE7(( "FT_Free:" ));
+    FT_TRACE7(( "ft_mem_free:" ));
     FT_TRACE7(( " Freeing block 0x%08p, ref 0x%08p\n",
                 P, P ? *P : (void*)0 ));
 
@@ -561,5 +561,66 @@
     return value;
   }
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+
+  FT_BASE_DEF( FT_Error )
+  FT_Alloc( FT_Memory  memory,
+            FT_Long    size,
+            void*     *P )
+  {
+    FT_Error  error;
+
+    (void)FT_ALLOC( *P, size );
+    return error;
+  }
+
+  FT_BASE_DEF( FT_Error )
+  FT_QAlloc( FT_Memory  memory,
+             FT_Long    size,
+             void*     *p )
+  {
+    FT_Error  error;
+
+    (void)FT_QALLOC( *p, size );
+    return error;
+  }
+
+  FT_BASE_DEF( FT_Error )
+  FT_Realloc( FT_Memory  memory,
+              FT_Long    current,
+              FT_Long    size,
+              void*     *P )
+  {
+    FT_Error  error;
+
+    (void)FT_REALLOC( *P, current, size );
+    return error;
+  }
+
+
+  FT_BASE_DEF( FT_Error )
+  FT_QRealloc( FT_Memory  memory,
+               FT_Long    current,
+               FT_Long    size,
+               void*     *p )
+  {
+    FT_Error  error;
+
+    (void)FT_QREALLOC( *p, current, size );
+    return error;
+  }
+
+  FT_BASE_DEF( void )
+  FT_Free( FT_Memory  memory,
+           void*     *P )
+  {
+    if ( *P )
+    {
+      ft_mem_free( memory, *P );
+      *P = NULL;
+    }
+  }
+
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 /* END */
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -251,7 +251,7 @@
     {
       if ( FT_ALLOC( face->style_name, ft_strlen( "Regular" ) + 1 ) )
         return error;
-        
+
       ft_strcpy( face->style_name, "Regular" );
     }
     else
@@ -475,7 +475,7 @@
           (face->en_table[n]).enc = cur[n].encoding;
           FT_TRACE4(( "idx %d, val 0x%lX\n", n, cur[n].encoding ));
           (face->en_table[n]).glyph = (FT_Short)n;
-  
+
           if ( cur[n].encoding == font->default_char )
             face->default_glyph = n;
         }
@@ -639,6 +639,7 @@
   }
 
 
+
   FT_CALLBACK_DEF( FT_Error )
   BDF_Glyph_Load( FT_GlyphSlot  slot,
                   FT_Size       size,
@@ -704,7 +705,7 @@
     slot->metrics.width        = bitmap->width << 6;
     slot->metrics.height       = bitmap->rows << 6;
 
-    /* 
+    /*
      * XXX DWIDTH1 and VVECTOR should be parsed and
      * used here, provided such fonts do exist.
      */
@@ -837,14 +838,18 @@
     0,                          /* FT_Slot_InitFunc */
     0,                          /* FT_Slot_DoneFunc */
 
-    BDF_Size_Request,
-    BDF_Size_Select,
-
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     BDF_Glyph_Load,
 
     0,                          /* FT_Face_GetKerningFunc   */
     0,                          /* FT_Face_AttachFunc       */
     0,                          /* FT_Face_GetAdvancesFunc  */
+
+    BDF_Size_Request,
+    BDF_Size_Select
   };
 
 
--- a/src/cache/ftccache.c
+++ b/src/cache/ftccache.c
@@ -256,7 +256,7 @@
 
 
   /* remove a node from the cache manager */
-  FT_LOCAL_DEF( void )
+  FT_BASE_DEF( void )
   ftc_node_destroy( FTC_Node     node,
                     FTC_Manager  manager )
   {
--- a/src/cache/ftccback.h
+++ b/src/cache/ftccback.h
@@ -79,11 +79,11 @@
   FT_LOCAL( void )
   ftc_cache_done( FTC_Cache  cache );
 
-
+#ifndef FT_CONFIG_OPTION_OLD_INTERNALS
   FT_LOCAL( void )
   ftc_node_destroy( FTC_Node     node,
                     FTC_Manager  manager );
-
+#endif
 
 #endif /* __FTCCBACK_H__ */
 
--- a/src/cache/ftccmap.c
+++ b/src/cache/ftccmap.c
@@ -300,4 +300,5 @@
   }
 
 
+
 /* END */
--- a/src/cache/ftcmanag.c
+++ b/src/cache/ftcmanag.c
@@ -677,5 +677,48 @@
       node->ref_count--;
   }
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_Manager_Lookup_Face( FTC_Manager  manager,
+                           FTC_FaceID   face_id,
+                           FT_Face     *aface )
+  {
+    return FTC_Manager_LookupFace( manager, face_id, aface );
+  }
+
+
+  FT_EXPORT( FT_Error )
+  FTC_Manager_Lookup_Size( FTC_Manager  manager,
+                           FTC_Font     font,
+                           FT_Face     *aface,
+                           FT_Size     *asize )
+  {
+    FTC_ScalerRec  scaler;
+    FT_Error       error;
+    FT_Size        size;
+
+    scaler.face_id = font->face_id;
+    scaler.width   = font->pix_width;
+    scaler.height  = font->pix_height;
+    scaler.pixel   = TRUE;
+    scaler.x_res   = 0;
+    scaler.y_res   = 0;
+
+    error = FTC_Manager_LookupSize( manager, &scaler, &size );
+    if ( error )
+    {
+      *aface = NULL;
+      *asize = NULL;
+    }
+    else
+    {
+      *aface = size->face;
+      *asize = size;
+    }
+    return  error;
+  }
+
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
 
 /* END */
--- a/src/cff/cffdrivr.c
+++ b/src/cff/cffdrivr.c
@@ -313,8 +313,8 @@
   /*
    * TT CMAP INFO
    *
-   * If the charmap is a synthetic Unicode encoding cmap or 
-   * a Type 1 standard (or expert) encoding cmap, hide TT CMAP INFO 
+   * If the charmap is a synthetic Unicode encoding cmap or
+   * a Type 1 standard (or expert) encoding cmap, hide TT CMAP INFO
    * service defined in SFNT module.
    *
    * Otherwise call the service function in the sfnt module.
@@ -330,7 +330,7 @@
 
     cmap_info->language = 0;
 
-    if ( cmap->clazz != &cff_cmap_encoding_class_rec && 
+    if ( cmap->clazz != &cff_cmap_encoding_class_rec &&
          cmap->clazz != &cff_cmap_unicode_class_rec  )
     {
       FT_Face             face    = FT_CMAP_FACE( cmap );
@@ -433,19 +433,24 @@
     cff_slot_init,
     cff_slot_done,
 
-    cff_size_request,
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
 
-#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
-    cff_size_select,
-#else
-    0,                      /* FT_Size_SelectFunc      */
-#endif 
-
     Load_Glyph,
 
     cff_get_kerning,
     0,                      /* FT_Face_AttachFunc      */
-    0                       /* FT_Face_GetAdvancesFunc */
+    0,                      /* FT_Face_GetAdvancesFunc */
+
+    cff_size_request,
+
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+    cff_size_select
+#else
+    0                       /* FT_Size_SelectFunc      */
+#endif
   };
 
 
--- a/src/cid/cidriver.c
+++ b/src/cid/cidriver.c
@@ -143,8 +143,10 @@
     cid_slot_init,
     cid_slot_done,
 
-    cid_size_request,
-    0,                      /* FT_Size_SelectFunc      */
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
 
     cid_slot_load_glyph,
 
@@ -151,7 +153,10 @@
     0,                      /* FT_Face_GetKerningFunc  */
     0,                      /* FT_Face_AttachFunc      */
 
-    0                       /* FT_Face_GetAdvancesFunc */
+    0,                      /* FT_Face_GetAdvancesFunc */
+
+    cid_size_request,
+    0                       /* FT_Size_SelectFunc      */
   };
 
 
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -643,14 +643,18 @@
     0,                      /* FT_Slot_InitFunc */
     0,                      /* FT_Slot_DoneFunc */
 
-    PCF_Size_Request,
-    PCF_Size_Select,
-
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     PCF_Glyph_Load,
 
     0,                      /* FT_Face_GetKerningFunc  */
     0,                      /* FT_Face_AttachFunc      */
-    0                       /* FT_Face_GetAdvancesFunc */
+    0,                      /* FT_Face_GetAdvancesFunc */
+
+    PCF_Size_Request,
+    PCF_Size_Select
   };
 
 
--- a/src/pfr/pfrdrivr.c
+++ b/src/pfr/pfrdrivr.c
@@ -190,13 +190,17 @@
     pfr_slot_init,
     pfr_slot_done,
 
-    0,                  /* FT_Size_RequestFunc */
-    0,                  /* FT_Size_SelectFunc  */
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     pfr_slot_load,
 
     pfr_get_kerning,
     0,                  /* FT_Face_AttachFunc      */
-    0                   /* FT_Face_GetAdvancesFunc */
+    0,                   /* FT_Face_GetAdvancesFunc */
+    0,                  /* FT_Size_RequestFunc */
+    0,                  /* FT_Size_SelectFunc  */
   };
 
 
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -107,15 +107,15 @@
     &ps_parser_funcs,
     &t1_builder_funcs,
     &t1_decoder_funcs,
+    t1_decrypt,
+
+    (const T1_CMap_ClassesRec*) &t1_cmap_classes,
+
 #ifndef T1_CONFIG_OPTION_NO_AFM
     &afm_parser_funcs,
 #else
     0,
 #endif
-
-    t1_decrypt,
-    
-    (const T1_CMap_ClassesRec*) &t1_cmap_classes,
   };
 
 
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -312,7 +312,7 @@
 
     /* XXX: I don't know whether this is correct, since
      *      tt_face_find_bdf_prop only returns something correct if we have
-     *      previously selected a size that is listed in the BDF table. 
+     *      previously selected a size that is listed in the BDF table.
      *      Should we change the BDF table format to include single offsets
      *      for `CHARSET_REGISTRY' and `CHARSET_ENCODING'?
      */
@@ -376,6 +376,112 @@
   }
 
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_load_sfnt_header_stub( TT_Face      face,
+                                 FT_Stream    stream,
+                                 FT_Long      face_index,
+                                 SFNT_Header  header )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( stream );
+    FT_UNUSED( face_index );
+    FT_UNUSED( header );
+
+    return FT_Err_Unimplemented_Feature;
+  }
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_load_directory_stub( TT_Face      face,
+                               FT_Stream    stream,
+                               SFNT_Header  header )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( stream );
+    FT_UNUSED( header );
+
+    return FT_Err_Unimplemented_Feature;
+  }
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_load_hdmx_stub( TT_Face    face,
+                          FT_Stream  stream )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( stream );
+    
+    return FT_Err_Unimplemented_Feature;
+  }                          
+
+
+  FT_CALLBACK_DEF( void )
+  tt_face_free_hdmx_stub( TT_Face   face )
+  {
+    FT_UNUSED( face );
+  }
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_set_sbit_strike_stub( TT_Face    face,
+                                FT_UInt    x_ppem,
+                                FT_UInt    y_ppem,
+                                FT_ULong*  astrike_index )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( x_ppem );
+    FT_UNUSED( y_ppem );
+
+    *astrike_index = 0x7FFFFFFFUL;    
+    return FT_Err_Unimplemented_Feature;
+  }                                
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_load_sbit_stub( TT_Face    face,
+                          FT_Stream  stream )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( stream );
+    
+    return FT_Err_Unimplemented_Feature;
+  }                          
+
+
+  FT_CALLBACK_DEF( void )
+  tt_face_free_sbit_stub( TT_Face  face )
+  {
+    FT_UNUSED( face );
+  }
+  
+  
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_load_charmap_stub( TT_Face       face,
+                             void*         cmap,
+                             FT_Stream     input )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( cmap );
+    FT_UNUSED( input );
+    
+    return FT_Err_Unimplemented_Feature;
+  }                             
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  tt_face_free_charmap_stub( TT_Face   face,
+                             void*     cmap )
+  {
+    FT_UNUSED( face );
+    FT_UNUSED( cmap );
+    
+    return 0;
+  }                             
+  
+#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
+
   static
   const SFNT_Interface  sfnt_interface =
   {
@@ -387,11 +493,14 @@
     sfnt_get_interface,
 
     tt_face_load_any,
-    tt_face_load_font_dir,
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    tt_face_load_sfnt_header_stub,
+    tt_face_load_directory_stub,
+#endif
+
     tt_face_load_head,
     tt_face_load_hhea,
-    tt_face_load_hmtx,
     tt_face_load_cmap,
     tt_face_load_maxp,
     tt_face_load_os2,
@@ -400,62 +509,82 @@
     tt_face_load_name,
     tt_face_free_name,
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    tt_face_load_hdmx_stub,
+    tt_face_free_hdmx_stub,
+#endif
+
     tt_face_load_kern,
     tt_face_load_gasp,
     tt_face_load_pclt,
 
 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
-
     /* see `ttload.h' */
     tt_face_load_bhed,
-
-
-    /* see `ttsbit.h' and `sfnt.h' */
-    tt_face_load_eblc,
-    tt_face_free_eblc,
-
-    tt_face_set_sbit_strike,
-    tt_face_load_strike_metrics,
-#ifdef FT_OPTIMIZE_MEMORY
-    0,
-    0,
 #else
-    tt_find_sbit_image,
-    tt_load_sbit_metrics,
+    0,
 #endif
-    tt_face_load_sbit_image,
 
-#else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    tt_face_set_sbit_strike_stub,
+    tt_face_load_sbit_stub,
+#endif
 
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+    tt_face_load_sbit_image,
+#else /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
     0,
-    0,
-    0,
-    0,
-    0,
-    0,
-    0,
-    0,
+#endif /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
 
-#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    tt_face_free_sbit_stub,
+#endif
 
-    /* see `ttkern.h' */
-    tt_face_get_kerning,
-
-    tt_face_get_metrics,
-
 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
-
     /* see `ttpost.h' */
     tt_face_get_ps_name,
     tt_face_free_ps_names,
-
 #else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
+    0,
+    0,
+#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
 
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    tt_face_load_charmap_stub,
+    tt_face_free_charmap_stub,
+#endif
+
+    /* since FT 2.1.8 */
+
+    tt_face_get_kerning,
+
+#  ifndef FT_OPTIMIZE_MEMORY
+    tt_find_sbit_image,
+    tt_load_sbit_metrics,
+#  else
     0,
     0,
+#  endif    
 
-#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
+    /* since FT 2.2 */
+    tt_face_load_font_dir,
+    tt_face_load_hmtx,
 
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+    /* see `ttsbit.h' and `sfnt.h' */
+    tt_face_load_eblc,
+    tt_face_free_eblc,
+
+    tt_face_set_sbit_strike,
+    tt_face_load_strike_metrics,
+#else
+    0,
+    0,
+    0,
+    0,
+#endif    
+
+    tt_face_get_metrics
   };
 
 
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -113,7 +113,7 @@
 
     if ( sfnt )
       kerning->x = sfnt->get_kerning( face, left_glyph, right_glyph );
-      
+
     return 0;
   }
 
@@ -365,18 +365,22 @@
     tt_slot_init,
     0,                      /* FT_Slot_DoneFunc */
 
-    tt_size_request,
-#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
-    tt_size_select,
-#else
-    0,                      /* FT_Size_SelectFunc      */
-#endif 
-
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     Load_Glyph,
 
     tt_get_kerning,
     0,                      /* FT_Face_AttachFunc      */
-    0                       /* FT_Face_GetAdvancesFunc */
+    0,                      /* FT_Face_GetAdvancesFunc */
+
+    tt_size_request,
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+    tt_size_select
+#else
+    0                       /* FT_Size_SelectFunc      */
+#endif
   };
 
 
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -306,8 +306,10 @@
     (FT_Slot_InitFunc)        T1_GlyphSlot_Init,
     (FT_Slot_DoneFunc)        T1_GlyphSlot_Done,
 
-    (FT_Size_RequestFunc)     T1_Size_Request,
-    (FT_Size_SelectFunc)      0,
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     (FT_Slot_LoadFunc)        T1_Load_Glyph,
 
 #ifdef T1_CONFIG_OPTION_NO_AFM
@@ -317,7 +319,9 @@
     (FT_Face_GetKerningFunc)  Get_Kerning,
     (FT_Face_AttachFunc)      T1_Read_Metrics,
 #endif
-    (FT_Face_GetAdvancesFunc) 0
+    (FT_Face_GetAdvancesFunc) 0,
+    (FT_Size_RequestFunc)     T1_Size_Request,
+    (FT_Size_SelectFunc)      0
   };
 
 
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -115,8 +115,8 @@
                    FT_Size_Request  req )
   {
     PSH_Globals_Funcs  funcs = T1_Size_Get_Globals_Funcs( size );
-    
-    
+
+
     FT_Request_Metrics( size->root.face, req );
 
     if ( funcs )
@@ -240,8 +240,11 @@
 #endif
 
       /* release unicode map, if any */
-      FT_FREE( face->unicode_map.maps );
-      face->unicode_map.num_maps = 0;
+#if 0
+      FT_FREE( face->unicode_map_rec.maps );
+      face->unicode_map_rec.num_maps = 0;
+      face->unicode_map              = NULL;
+#endif
 
       face->root.family_name = 0;
       face->root.style_name  = 0;
--- a/src/type42/t42drivr.c
+++ b/src/type42/t42drivr.c
@@ -229,14 +229,18 @@
     (FT_Slot_InitFunc)        T42_GlyphSlot_Init,
     (FT_Slot_DoneFunc)        T42_GlyphSlot_Done,
 
-    (FT_Size_RequestFunc)     T42_Size_Request,
-    (FT_Size_SelectFunc)      T42_Size_Select,
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     (FT_Slot_LoadFunc)        T42_GlyphSlot_Load,
 
     (FT_Face_GetKerningFunc)  0,
     (FT_Face_AttachFunc)      0,
 
-    (FT_Face_GetAdvancesFunc) 0
+    (FT_Face_GetAdvancesFunc) 0,
+    (FT_Size_RequestFunc)     T42_Size_Request,
+    (FT_Size_SelectFunc)      T42_Size_Select
   };
 
 
--- a/src/winfonts/winfnt.c
+++ b/src/winfonts/winfnt.c
@@ -479,7 +479,7 @@
         bsize->y_ppem = FT_MulDiv( bsize->size, y_res, 72 );
         bsize->y_ppem = FT_PIX_ROUND( bsize->y_ppem );
 
-        /* 
+        /*
          * this reads:
          *
          * the nominal height is larger than the bbox's height
@@ -801,13 +801,18 @@
     (FT_Slot_InitFunc)        0,
     (FT_Slot_DoneFunc)        0,
 
-    (FT_Size_RequestFunc)     FNT_Size_Request,
-    (FT_Size_SelectFunc)      FNT_Size_Select,
+#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
+    ft_stub_set_char_sizes,
+    ft_stub_set_pixel_sizes,
+#endif
     (FT_Slot_LoadFunc)        FNT_Load_Glyph,
 
     (FT_Face_GetKerningFunc)  0,
     (FT_Face_AttachFunc)      0,
-    (FT_Face_GetAdvancesFunc) 0
+    (FT_Face_GetAdvancesFunc) 0,
+
+    (FT_Size_RequestFunc)     FNT_Size_Request,
+    (FT_Size_SelectFunc)      FNT_Size_Select
   };