shithub: freetype+ttf2subf

Download patch

ref: 44bb303510725735ca2650bdd524af25abab0c71
parent: e95365b291d13000e84b8e81671bea7e762ea557
author: Werner Lemberg <[email protected]>
date: Sun Apr 25 16:15:11 EDT 2004

* src/pcf/pcfdrivr.c: Revert change from 2004-04-17.
* src/pcf/pcfutil.c: Use FT_LOCAL_DEF.
* src/pcf/pcfutil.h: Include FT_CONFIG_CONFIG_H.
Use FT_BEGIN_HEADER and FT_END_HEADER.
Use FT_LOCAL.

2004-04-24  George Williams  <[email protected]>

Add support for Apple's distortable font technology (in GX fonts).

* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_GX_VAR_SUPPORT): New macro.

* include/freetype/ftmm.h (FT_Var_Axis, FT_Var_Named_Style,
FT_MM_Var): New structures.
(FT_Get_MM_Var, FT_Set_Var_Design_Coordinates,
FT_Set_Var_Blend_Coordinates): New function declarations.

* include/freetype/internal/services/svmm.h (FT_Get_MM_Var_Func,
FT_Set_Var_Design_Func): New typedefs.
Update MultiMasters service.

* include/freetype/internal/tttypes.h
[TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include FT_MULTIPLE_MASTERS_H.
(GX_Blend) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New typedef.
(TT_Face) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New members `doblend'
and `blend'.

* include/freetype/tttags.h (TTAG_avar, TTAG_cvar, TTAG_gvar): New
macros.

* include/freetype/internal/fttrace.h: Add `ttgxvar'.

* src/base/ftmm.c (FT_Get_MM_Var, FT_Set_Var_Design_Coordinates,
FT_Set_Var_Blend_Coordinates): New functions.

* src/sfnt/sfobjs.c (sfnt_load_face)
[TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Set FT_FACE_FLAG_MULTIPLE_MASTERS
flag for GX var fonts.

* src/truetype/ttgxvar.c, src/truetype/ttgxvar.h: New files.

* src/truetype/truetype.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
ttgxvar.c.

* src/truetype/ttdriver.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
FT_MULTIPLE_MASTERS_H, FT_SERVICE_MULTIPLE_MASTERS_H, and ttgxvar.h.
(tt_service_gx_multi_masters) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]:
New service.
(tt_services) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Updated.

* src/truetype/ttgload.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
ttgxvar.h.
(TT_Process_Simple_Glyph, load_truetype_glyph)
[TT_CONFIG_OPTION_GX_VAR_SUPPORT] :Support GX var fonts.

* src/truetype/ttobjs.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
ttgxvar.h.
(tt_done_face) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Call
tt_done_blend.

* src/truetype/ttpload.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
ttgxvar.h.
(tt_face_load_cvt)  [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Call
tt_face_vary_cvt.

* src/truetype/rules.mk (TT_DRV_SRC): Add ttgxvar.c.

* src/type1/t1driver.c (t1_service_multi_masters): Add T1_Get_MM_Var
and T1_Set_Var_Design.

* src/type1/t1load.c (FT_INT_TO_FIXED, FT_FIXED_TO_INT): New macros.
(T1_Get_MM_Var, T1_Set_Var_Design): New functions.

* src/type1/t1load.h (T1_Get_MM_Var, T1_Set_Var_Design): New
function declarations.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,82 @@
+2004-04-24  Werner Lemberg  <[email protected]>
+
+	* src/pcf/pcfdrivr.c: Revert change from 2004-04-17.
+	* src/pcf/pcfutil.c: Use FT_LOCAL_DEF.
+	* src/pcf/pcfutil.h: Include FT_CONFIG_CONFIG_H.
+	Use FT_BEGIN_HEADER and FT_END_HEADER.
+	Use FT_LOCAL.
+
+2004-04-24  George Williams  <[email protected]>
+
+	Add support for Apple's distortable font technology (in GX fonts).
+
+	* devel/ftoption.h, include/freetype/config/ftoption.h
+	(TT_CONFIG_OPTION_GX_VAR_SUPPORT): New macro.
+
+	* include/freetype/ftmm.h (FT_Var_Axis, FT_Var_Named_Style,
+	FT_MM_Var): New structures.
+	(FT_Get_MM_Var, FT_Set_Var_Design_Coordinates,
+	FT_Set_Var_Blend_Coordinates): New function declarations.
+
+	* include/freetype/internal/services/svmm.h (FT_Get_MM_Var_Func,
+	FT_Set_Var_Design_Func): New typedefs.
+	Update MultiMasters service.
+
+	* include/freetype/internal/tttypes.h
+	[TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include FT_MULTIPLE_MASTERS_H.
+	(GX_Blend) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New typedef.
+	(TT_Face) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New members `doblend'
+	and `blend'.
+
+	* include/freetype/tttags.h (TTAG_avar, TTAG_cvar, TTAG_gvar): New
+	macros.
+
+	* include/freetype/internal/fttrace.h: Add `ttgxvar'.
+
+	* src/base/ftmm.c (FT_Get_MM_Var, FT_Set_Var_Design_Coordinates,
+	FT_Set_Var_Blend_Coordinates): New functions.
+
+	* src/sfnt/sfobjs.c (sfnt_load_face)
+	[TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Set FT_FACE_FLAG_MULTIPLE_MASTERS
+	flag for GX var fonts.
+
+	* src/truetype/ttgxvar.c, src/truetype/ttgxvar.h: New files.
+
+	* src/truetype/truetype.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
+	ttgxvar.c.
+
+	* src/truetype/ttdriver.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
+	FT_MULTIPLE_MASTERS_H, FT_SERVICE_MULTIPLE_MASTERS_H, and ttgxvar.h.
+	(tt_service_gx_multi_masters) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]:
+	New service.
+	(tt_services) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Updated.
+
+	* src/truetype/ttgload.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
+	ttgxvar.h.
+	(TT_Process_Simple_Glyph, load_truetype_glyph)
+	[TT_CONFIG_OPTION_GX_VAR_SUPPORT] :Support GX var fonts.
+
+	* src/truetype/ttobjs.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
+	ttgxvar.h.
+	(tt_done_face) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Call
+	tt_done_blend.
+
+	* src/truetype/ttpload.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include
+	ttgxvar.h.
+	(tt_face_load_cvt)  [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Call
+	tt_face_vary_cvt.
+
+	* src/truetype/rules.mk (TT_DRV_SRC): Add ttgxvar.c.
+
+	* src/type1/t1driver.c (t1_service_multi_masters): Add T1_Get_MM_Var
+	and T1_Set_Var_Design.
+
+	* src/type1/t1load.c (FT_INT_TO_FIXED, FT_FIXED_TO_INT): New macros.
+	(T1_Get_MM_Var, T1_Set_Var_Design): New functions.
+
+	* src/type1/t1load.h (T1_Get_MM_Var, T1_Set_Var_Design): New
+	function declarations.
+
 2004-04-23  Werner Lemberg  <[email protected]>
 
 	* include/freetype/ftcache.h (FT_Get_CharMap_Index): Rename
@@ -69,7 +148,7 @@
 	* src/bdf/bdfdrivr.c (BDF_Face_Init): Use `ft_strlen'.
 
 	* src/pcf/pcfutil.c, src/pcf/pcfutil.h: Decorate functions with
-	`static.'.
+	`static'.
 	Remove unused function `RepadBitmap'.
 	* src/pcf/pcfdrivr.c: Don't include pcfutil.h.
 
--- a/devel/ftoption.h
+++ b/devel/ftoption.h
@@ -484,6 +484,16 @@
 
 
   /*************************************************************************/
+  /*                                                                       */
+  /* Define TT_CONFIG_OPTION_GX_VAR_SUPPORT if you want to include         */
+  /* support for Apple's distortable font technology (fvar, gvar, cvar,    */
+  /* and avar tables).  This has many similarities to Type 1 Multiple      */
+  /* Masters support.                                                      */
+  /*                                                                       */
+#define TT_CONFIG_OPTION_GX_VAR_SUPPORT
+
+
+  /*************************************************************************/
   /*************************************************************************/
   /****                                                                 ****/
   /****      T Y P E 1   D R I V E R    C O N F I G U R A T I O N       ****/
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -484,6 +484,16 @@
 
 
   /*************************************************************************/
+  /*                                                                       */
+  /* Define TT_CONFIG_OPTION_GX_VAR_SUPPORT if you want to include         */
+  /* support for Apple's distortable font technology (fvar, gvar, cvar,    */
+  /* and avar tables).  This has many similarities to Type 1 Multiple      */
+  /* Masters support.                                                      */
+  /*                                                                       */
+#define TT_CONFIG_OPTION_GX_VAR_SUPPORT
+
+
+  /*************************************************************************/
   /*************************************************************************/
   /****                                                                 ****/
   /****      T Y P E 1   D R I V E R    C O N F I G U R A T I O N       ****/
--- a/include/freetype/ftmm.h
+++ b/include/freetype/ftmm.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType Multiple Master font interface (specification).             */
 /*                                                                         */
-/*  Copyright 1996-2001 by                                                 */
+/*  Copyright 1996-2001, 2003, 2004 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -43,6 +43,12 @@
   /*    Master fonts, i.e. the selection of specific design instances by   */
   /*    setting design axis coordinates.                                   */
   /*                                                                       */
+  /*    George Williams has extended this interface to make it work with   */
+  /*    both Type 1 Multiple Masters fonts, and GX distortable (var)       */
+  /*    fonts.  Some of these routines only work with MM fonts, others     */
+  /*    will work with both types.  They are similar enough that a         */
+  /*    consistent interface makes sense.                                  */
+  /*                                                                       */
   /*************************************************************************/
 
 
@@ -55,6 +61,8 @@
   /*    A simple structure used to model a given axis in design space for  */
   /*    Multiple Masters fonts.                                            */
   /*                                                                       */
+  /*    This structure can't be used for GX var fonts.                     */
+  /*                                                                       */
   /* <Fields>                                                              */
   /*    name    :: The axis's name.                                        */
   /*                                                                       */
@@ -80,6 +88,8 @@
   /*    A structure used to model the axes and space of a Multiple Masters */
   /*    font.                                                              */
   /*                                                                       */
+  /*    This structure can't be used for GX var fonts.                     */
+  /*                                                                       */
   /* <Fields>                                                              */
   /*    num_axis    :: Number of axes.  Cannot exceed 4.                   */
   /*                                                                       */
@@ -98,8 +108,118 @@
 
   } FT_Multi_Master;
 
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    FT_Var_Axis                                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A simple structure used to model a given axis in design space for  */
+  /*    Multiple Masters and GX var fonts.                                 */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    name    :: The axis's name.                                        */
+  /*               Not always meaningful for GX.                           */
+  /*                                                                       */
+  /*    minimum :: The axis's minimum design coordinate.                   */
+  /*                                                                       */
+  /*    def     :: The axis's default design coordinate.                   */
+  /*               Not meaningful for MM.                                  */
+  /*                                                                       */
+  /*    maximum :: The axis's maximum design coordinate.                   */
+  /*                                                                       */
+  /*    tag     :: The axis's tag (the GX equivalent to `name').           */
+  /*               Not meaningful for MM.                                  */
+  /*                                                                       */
+  /*    strid   :: The entry in `name' table (another GX version of        */
+  /*               `name').                                                */
+  /*               Not meaningful for MM.                                  */
+  /*                                                                       */
+  typedef struct  FT_Var_Axis_
+  {
+    FT_String*  name;
+
+    FT_Fixed    minimum;
+    FT_Fixed    def;
+    FT_Fixed    maximum;
+
+    FT_ULong    tag;
+    FT_UInt     strid;
+
+  } FT_Var_Axis;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    FT_Var_Named_Style                                                 */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A simple structure used to model a named style in a GX var font.   */
+  /*                                                                       */
+  /*    This structure can't be used for MM fonts.                         */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    coords :: The design coordinates for this style.                   */
+  /*              This is an array with one entry for each axis.           */
+  /*                                                                       */
+  /*    strid  :: The entry in `name' table identifying this style.        */
+  /*                                                                       */
+  typedef struct  FT_Var_Named_Style_
+  {
+    FT_Fixed*  coords;
+    FT_UInt    strid;
+
+  } FT_Var_Named_Style;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    FT_MM_Var                                                          */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A structure used to model the axes and space of a Multiple Masters */
+  /*    or GX var distortable font.                                        */
+  /*                                                                       */
+  /*    Some fields are specific to one format and not to the other.       */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    num_axis        :: The number of axes.  The maximum value is 4 for */
+  /*                       MM; no limit in GX.                             */
+  /*                                                                       */
+  /*    num_designs     :: The number of designs; should be normally       */
+  /*                       2^num_axis for MM fonts.  Not meaningful for GX */
+  /*                       (where every glyph could have a different       */
+  /*                       number of designs).                             */
+  /*                                                                       */
+  /*    num_namedstyles :: The number of named styles; only meaningful for */
+  /*                       GX which allows certain design coordinates to   */
+  /*                       have a string ID (in the `name' table)          */
+  /*                       associated with them.  The font can tell the    */
+  /*                       user that, for example, Weight=1.5 is `Bold'.   */
+  /*                                                                       */
+  /*    axis            :: A table of axis descriptors.                    */
+  /*                       GX fonts contain slightly more data than MM.    */
+  /*                                                                       */
+  /*    namedstyles     :: A table of named styles.                        */
+  /*                       Only meaningful with GX.                        */
+  /*                                                                       */
+  typedef struct  FT_MM_Var_
+  {
+    FT_UInt              num_axis;
+    FT_UInt              num_designs;
+    FT_UInt              num_namedstyles;
+    FT_Var_Axis*         axis;
+    FT_Var_Named_Style*  namedstyle;
+
+  } FT_MM_Var;
+
+
   /* */
 
+
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -108,6 +228,8 @@
   /* <Description>                                                         */
   /*    Retrieves the Multiple Master descriptor of a given font.          */
   /*                                                                       */
+  /*    This function can't be used with GX fonts.                         */
+  /*                                                                       */
   /* <Input>                                                               */
   /*    face    :: A handle to the source face.                            */
   /*                                                                       */
@@ -125,6 +247,30 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    FT_Get_MM_Var                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Retrieves the Multiple Master/GX var descriptor of a given font.   */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face    :: A handle to the source face.                            */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    amaster :: The Multiple Masters descriptor.                        */
+  /*               Allocates a data structure, which the user must free    */
+  /*               (a single call to FT_FREE will do it).                  */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Get_MM_Var( FT_Face      face,
+                 FT_MM_Var*  *amaster );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    FT_Set_MM_Design_Coordinates                                       */
   /*                                                                       */
   /* <Description>                                                         */
@@ -131,6 +277,8 @@
   /*    For Multiple Masters fonts, choose an interpolated font design     */
   /*    through design coordinates.                                        */
   /*                                                                       */
+  /*    This function can't be used with GX fonts.                         */
+  /*                                                                       */
   /* <InOut>                                                               */
   /*    face       :: A handle to the source face.                         */
   /*                                                                       */
@@ -152,11 +300,38 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    FT_Set_Var_Design_Coordinates                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    For Multiple Master or GX Var fonts, choose an interpolated font   */
+  /*    design through design coordinates.                                 */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: A handle to the source face.                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    num_coords :: The number of design coordinates (must be equal to   */
+  /*                  the number of axes in the font).                     */
+  /*                                                                       */
+  /*    coords     :: An array of design coordinates.                      */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Set_Var_Design_Coordinates( FT_Face    face,
+                                 FT_UInt    num_coords,
+                                 FT_Fixed*  coords );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    FT_Set_MM_Blend_Coordinates                                        */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    For Multiple Masters fonts, choose an interpolated font design     */
-  /*    through normalized blend coordinates.                              */
+  /*    For Multiple Masters and GX var fonts, choose an interpolated font */
+  /*    design through normalized blend coordinates.                       */
   /*                                                                       */
   /* <InOut>                                                               */
   /*    face       :: A handle to the source face.                         */
@@ -175,6 +350,20 @@
   FT_Set_MM_Blend_Coordinates( FT_Face    face,
                                FT_UInt    num_coords,
                                FT_Fixed*  coords );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Set_Var_Blend_Coordinates                                       */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    This is another name of @FT_Set_MM_Blend_Coordinates.              */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Set_Var_Blend_Coordinates( FT_Face    face,
+                                FT_UInt    num_coords,
+                                FT_Fixed*  coords );
 
 
   /* */
--- a/include/freetype/internal/fttrace.h
+++ b/include/freetype/internal/fttrace.h
@@ -53,6 +53,7 @@
 FT_TRACE_DEF( ttinterp )  /* bytecode interpreter    (ttinterp.c) */
 FT_TRACE_DEF( ttobjs )    /* TT objects manager      (ttobjs.c)   */
 FT_TRACE_DEF( ttpload )   /* TT data/program loader  (ttpload.c)  */
+FT_TRACE_DEF( ttgxvar )   /* TrueType GX var handler (ttgxvar.c)  */
 
 /* Type 1 driver components */
 FT_TRACE_DEF( t1driver )
--- a/include/freetype/internal/services/svmm.h
+++ b/include/freetype/internal/services/svmm.h
@@ -2,9 +2,9 @@
 /*                                                                         */
 /*  svmm.h                                                                 */
 /*                                                                         */
-/*    The FreeType Multiple Masters services (specification).              */
+/*    The FreeType Multiple Masters and GX var services (specification).   */
 /*                                                                         */
-/*  Copyright 2003 by                                                      */
+/*  Copyright 2003, 2004 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -40,11 +40,20 @@
                      FT_Multi_Master*  master );
 
   typedef FT_Error
+  (*FT_Get_MM_Var_Func)( FT_Face      face,
+                         FT_MM_Var*  *master );
+
+  typedef FT_Error
   (*FT_Set_MM_Design_Func)( FT_Face   face,
                             FT_UInt   num_coords,
                             FT_Long*  coords );
 
   typedef FT_Error
+  (*FT_Set_Var_Design_Func)( FT_Face    face,
+                             FT_UInt    num_coords,
+                             FT_Fixed*  coords );
+
+  typedef FT_Error
   (*FT_Set_MM_Blend_Func)( FT_Face   face,
                            FT_UInt   num_coords,
                            FT_Long*  coords );
@@ -52,9 +61,11 @@
 
   FT_DEFINE_SERVICE( MultiMasters )
   {
-    FT_Get_MM_Func         get_mm;
-    FT_Set_MM_Design_Func  set_mm_design;
-    FT_Set_MM_Blend_Func   set_mm_blend;
+    FT_Get_MM_Func          get_mm;
+    FT_Set_MM_Design_Func   set_mm_design;
+    FT_Set_MM_Blend_Func    set_mm_blend;
+    FT_Get_MM_Var_Func      get_mm_var;
+    FT_Set_Var_Design_Func  set_var_design;
   };
 
   /* */
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -5,7 +5,7 @@
 /*    Basic SFNT/TrueType type definitions and interface (specification    */
 /*    only).                                                               */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002 by                                           */
+/*  Copyright 1996-2001, 2002, 2004 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -25,7 +25,11 @@
 #include FT_TRUETYPE_TABLES_H
 #include FT_INTERNAL_OBJECTS_H
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include FT_MULTIPLE_MASTERS_H
+#endif
 
+
 FT_BEGIN_HEADER
 
 
@@ -823,6 +827,24 @@
   /*************************************************************************/
   /***                                                                   ***/
   /***                                                                   ***/
+  /***                    GX VARIATION TABLE SUPPORT                     ***/
+  /***                                                                   ***/
+  /***                                                                   ***/
+  /*************************************************************************/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+  typedef struct GS_BlendRec_  *GX_Blend;
+#endif
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*************************************************************************/
+  /***                                                                   ***/
+  /***                                                                   ***/
   /***                  ORIGINAL TT_FACE CLASS DEFINITION                ***/
   /***                                                                   ***/
   /***                                                                   ***/
@@ -1152,8 +1174,18 @@
   /*    unpatented_hinting   :: If true, use only unpatented methods in    */
   /*                            the bytecode interpreter.                  */
   /*                                                                       */
+  /*    doblend              :: A boolean which is set if the font should  */
+  /*                            be blended (this is for GX var).           */
+  /*                                                                       */
+  /*    blend                :: Contains the data needed to control GX     */
+  /*                            variation tables (rather like Multiple     */
+  /*                            Master data).                              */
+  /*                                                                       */
   /*    extra                :: Reserved for third-party font drivers.     */
   /*                                                                       */
+  /*    postscript_name      :: The PS name of the font.  Used by the      */
+  /*                            postscript name service.                   */
+  /*                                                                       */
   typedef struct  TT_FaceRec_
   {
     FT_FaceRec            root;
@@ -1261,6 +1293,11 @@
     FT_Bool               unpatented_hinting;
 #endif
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+    FT_Bool               doblend;
+    GX_Blend              blend;
+#endif
+    
     /***********************************************************************/
     /*                                                                     */
     /* Other tables or fields. This is used by derivative formats like     */
--- a/include/freetype/tttables.h
+++ b/include/freetype/tttables.h
@@ -5,7 +5,7 @@
 /*    Basic SFNT/TrueType tables definitions and interface                 */
 /*    (specification only).                                                */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003 by                                     */
+/*  Copyright 1996-2001, 2002, 2003, 2004 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -516,12 +516,11 @@
   /*    maxSizeOfInstructions :: The maximum number of TrueType opcodes    */
   /*                             used for glyph hinting.                   */
   /*                                                                       */
-  /*    maxComponentElements  :: An obscure value related to composite     */
-  /*                             glyphs definitions.                       */
+  /*    maxComponentElements  :: The maximum number of simple (i.e., non-  */
+  /*                             composite) glyphs in a composite glyph.   */
   /*                                                                       */
-  /*    maxComponentDepth     :: An obscure value related to composite     */
-  /*                             glyphs definitions.  Probably the maximum */
-  /*                             number of simple glyphs in a composite.   */
+  /*    maxComponentDepth     :: The maximum nesting depth of composite    */
+  /*                             glyphs.                                   */
   /*                                                                       */
   /* <Note>                                                                */
   /*    This structure is only used during font loading.                   */
--- a/include/freetype/tttags.h
+++ b/include/freetype/tttags.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Tags for TrueType tables (specification only).                       */
 /*                                                                         */
-/*  Copyright 1996-2001 by                                                 */
+/*  Copyright 1996-2001, 2004 by                                           */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -33,13 +33,15 @@
 FT_BEGIN_HEADER
 
 
+#define TTAG_avar  FT_MAKE_TAG( 'a', 'v', 'a', 'r' )
+#define TTAG_bdat  FT_MAKE_TAG( 'b', 'd', 'a', 't' )
+#define TTAG_bhed  FT_MAKE_TAG( 'b', 'h', 'e', 'd' )
+#define TTAG_bloc  FT_MAKE_TAG( 'b', 'l', 'o', 'c' )
+#define TTAG_CFF   FT_MAKE_TAG( 'C', 'F', 'F', ' ' )
 #define TTAG_cmap  FT_MAKE_TAG( 'c', 'm', 'a', 'p' )
+#define TTAG_cvar  FT_MAKE_TAG( 'c', 'v', 'a', 'r' )
 #define TTAG_cvt   FT_MAKE_TAG( 'c', 'v', 't', ' ' )
-#define TTAG_CFF   FT_MAKE_TAG( 'C', 'F', 'F', ' ' )
 #define TTAG_DSIG  FT_MAKE_TAG( 'D', 'S', 'I', 'G' )
-#define TTAG_bhed  FT_MAKE_TAG( 'b', 'h', 'e', 'd' )
-#define TTAG_bdat  FT_MAKE_TAG( 'b', 'd', 'a', 't' )
-#define TTAG_bloc  FT_MAKE_TAG( 'b', 'l', 'o', 'c' )
 #define TTAG_EBDT  FT_MAKE_TAG( 'E', 'B', 'D', 'T' )
 #define TTAG_EBLC  FT_MAKE_TAG( 'E', 'B', 'L', 'C' )
 #define TTAG_EBSC  FT_MAKE_TAG( 'E', 'B', 'S', 'C' )
@@ -48,6 +50,7 @@
 #define TTAG_gasp  FT_MAKE_TAG( 'g', 'a', 's', 'p' )
 #define TTAG_glyf  FT_MAKE_TAG( 'g', 'l', 'y', 'f' )
 #define TTAG_GSUB  FT_MAKE_TAG( 'G', 'S', 'U', 'B' )
+#define TTAG_gvar  FT_MAKE_TAG( 'g', 'v', 'a', 'r' )
 #define TTAG_hdmx  FT_MAKE_TAG( 'h', 'd', 'm', 'x' )
 #define TTAG_head  FT_MAKE_TAG( 'h', 'e', 'a', 'd' )
 #define TTAG_hhea  FT_MAKE_TAG( 'h', 'h', 'e', 'a' )
@@ -56,8 +59,8 @@
 #define TTAG_loca  FT_MAKE_TAG( 'l', 'o', 'c', 'a' )
 #define TTAG_LTSH  FT_MAKE_TAG( 'L', 'T', 'S', 'H' )
 #define TTAG_maxp  FT_MAKE_TAG( 'm', 'a', 'x', 'p' )
-#define TTAG_MMSD  FT_MAKE_TAG( 'M', 'M', 'S', 'D' )
 #define TTAG_MMFX  FT_MAKE_TAG( 'M', 'M', 'F', 'X' )
+#define TTAG_MMSD  FT_MAKE_TAG( 'M', 'M', 'S', 'D' )
 #define TTAG_name  FT_MAKE_TAG( 'n', 'a', 'm', 'e' )
 #define TTAG_OS2   FT_MAKE_TAG( 'O', 'S', '/', '2' )
 #define TTAG_OTTO  FT_MAKE_TAG( 'O', 'T', 'T', 'O' )
--- a/src/base/ftmm.c
+++ b/src/base/ftmm.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Multiple Master font support (body).                                 */
 /*                                                                         */
-/*  Copyright 1996-2001, 2003 by                                           */
+/*  Copyright 1996-2001, 2003, 2004 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -85,6 +85,28 @@
   /* documentation is in ftmm.h */
 
   FT_EXPORT_DEF( FT_Error )
+  FT_Get_MM_Var( FT_Face      face,
+                 FT_MM_Var*  *amaster )
+  {
+    FT_Error                 error;
+    FT_Service_MultiMasters  service;
+
+
+    error = ft_face_get_mm_service( face, &service );
+    if ( !error )
+    {
+      error = FT_Err_Invalid_Argument;
+      if ( service->get_mm_var )
+        error = service->get_mm_var( face, amaster );
+    }
+
+    return error;
+  }
+
+
+  /* documentation is in ftmm.h */
+
+  FT_EXPORT_DEF( FT_Error )
   FT_Set_MM_Design_Coordinates( FT_Face   face,
                                 FT_UInt   num_coords,
                                 FT_Long*  coords )
@@ -108,9 +130,58 @@
   /* documentation is in ftmm.h */
 
   FT_EXPORT_DEF( FT_Error )
+  FT_Set_Var_Design_Coordinates( FT_Face    face,
+                                 FT_UInt    num_coords,
+                                 FT_Fixed*  coords )
+  {
+    FT_Error                 error;
+    FT_Service_MultiMasters  service;
+
+
+    error = ft_face_get_mm_service( face, &service );
+    if ( !error )
+    {
+      error = FT_Err_Invalid_Argument;
+      if ( service->set_var_design )
+        error = service->set_var_design( face, num_coords, coords );
+    }
+
+    return error;
+  }
+
+
+  /* documentation is in ftmm.h */
+
+  FT_EXPORT_DEF( FT_Error )
   FT_Set_MM_Blend_Coordinates( FT_Face    face,
                                FT_UInt    num_coords,
                                FT_Fixed*  coords )
+  {
+    FT_Error                 error;
+    FT_Service_MultiMasters  service;
+
+
+    error = ft_face_get_mm_service( face, &service );
+    if ( !error )
+    {
+      error = FT_Err_Invalid_Argument;
+      if ( service->set_mm_blend )
+         error = service->set_mm_blend( face, num_coords, coords );
+    }
+
+    return error;
+  }
+
+
+  /* documentation is in ftmm.h */
+  
+  /* This is exactly the same as the previous function.  It exists for */
+  /* orthogonality.                                                    */
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Set_Var_Blend_Coordinates( FT_Face    face,
+                                FT_UInt    num_coords,
+                                FT_Fixed*  coords )
   {
     FT_Error                 error;
     FT_Service_MultiMasters  service;
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -40,6 +40,7 @@
 #include "pcfread.h"
 
 #include "pcferror.h"
+#include "pcfutil.h"
 
 #undef  FT_COMPONENT
 #define FT_COMPONENT  trace_pcfread
--- a/src/pcf/pcfutil.c
+++ b/src/pcf/pcfutil.c
@@ -74,7 +74,7 @@
    *  Invert bit order within each BYTE of an array.
    */
 
-  static void
+  FT_LOCAL_DEF( void )
   BitOrderInvert( unsigned char*  buf,
                   int             nbytes )
   {
@@ -90,7 +90,7 @@
    *  Invert byte order within each 16-bits of an array.
    */
 
-  static void
+  FT_LOCAL_DEF( void )
   TwoByteSwap( unsigned char*  buf,
                int             nbytes )
   {
@@ -109,7 +109,7 @@
    *  Invert byte order within each 32-bits of an array.
    */
 
-  static void
+  FT_LOCAL_DEF( void )
   FourByteSwap( unsigned char*  buf,
                 int             nbytes )
   {
--- a/src/pcf/pcfutil.h
+++ b/src/pcf/pcfutil.h
@@ -30,20 +30,24 @@
 
 
 #include <ft2build.h>
+#include FT_CONFIG_CONFIG_H
 
 
-  static void
+FT_BEGIN_HEADER
+
+  FT_LOCAL( void )
   BitOrderInvert( unsigned char*  buf,
-                  int             nbytes);
+                  int             nbytes );
 
-  static void
+  FT_LOCAL( void )
   TwoByteSwap( unsigned char*  buf,
-               int             nbytes);
+               int             nbytes );
 
-  static void
+  FT_LOCAL( void )
   FourByteSwap( unsigned char*  buf,
-                int             nbytes);
+                int             nbytes );
 
+FT_END_HEADER
 
 #endif /* __PCFUTIL_H__ */
 
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    SFNT object management (base).                                       */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003 by                                     */
+/*  Copyright 1996-2001, 2002, 2003, 2004 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -431,11 +431,11 @@
     /* do we have outlines in there? */
 #ifdef FT_CONFIG_OPTION_INCREMENTAL
     has_outline   = FT_BOOL( face->root.internal->incremental_interface != 0 ||
-                             tt_face_lookup_table( face, TTAG_glyf ) != 0         ||
-                             tt_face_lookup_table( face, TTAG_CFF ) != 0          );
+                             tt_face_lookup_table( face, TTAG_glyf )    != 0 ||
+                             tt_face_lookup_table( face, TTAG_CFF )     != 0 );
 #else
     has_outline   = FT_BOOL( tt_face_lookup_table( face, TTAG_glyf ) != 0 ||
-                             tt_face_lookup_table( face, TTAG_CFF ) != 0  );
+                             tt_face_lookup_table( face, TTAG_CFF )  != 0 );
 #endif
 
     is_apple_sbit = 0;
@@ -545,6 +545,15 @@
       /* kerning available ? */
       if ( face->kern_pairs )
         flags |= FT_FACE_FLAG_KERNING;
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+      /* Don't bother to load the tables unless somebody asks for them. */
+      /* No need to do work which will (probably) not be used.          */
+      if ( tt_face_lookup_table( face, TTAG_glyf ) != 0 &&
+           tt_face_lookup_table( face, TTAG_fvar ) != 0 &&
+           tt_face_lookup_table( face, TTAG_gvar ) != 0 )
+        flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;
+#endif
 
       root->face_flags = flags;
 
--- a/src/truetype/rules.mk
+++ b/src/truetype/rules.mk
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 1996-2000, 2001, 2003 by
+# Copyright 1996-2000, 2001, 2003, 2004 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -29,6 +29,7 @@
               $(TT_DIR)/ttpload.c  \
               $(TT_DIR)/ttgload.c  \
               $(TT_DIR)/ttinterp.c \
+              $(TT_DIR)/ttgxvar.c \
               $(TT_DIR)/ttdriver.c
 
 # TrueType driver headers
--- a/src/truetype/truetype.c
+++ b/src/truetype/truetype.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType TrueType driver component (body only).                      */
 /*                                                                         */
-/*  Copyright 1996-2001 by                                                 */
+/*  Copyright 1996-2001, 2004 by                                           */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -19,13 +19,17 @@
 #define FT_MAKE_OPTION_SINGLE_OBJECT
 
 #include <ft2build.h>
-#include "ttdriver.c"   /* driver interface */
-#include "ttpload.c"    /* tables loader    */
-#include "ttgload.c"    /* glyph loader     */
-#include "ttobjs.c"     /* object manager   */
+#include "ttdriver.c"   /* driver interface    */
+#include "ttpload.c"    /* tables loader       */
+#include "ttgload.c"    /* glyph loader        */
+#include "ttobjs.c"     /* object manager      */
 
 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
 #include "ttinterp.c"
+#endif
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include "ttgxvar.c"    /* gx distortable font */
 #endif
 
 
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -23,9 +23,18 @@
 #include FT_TRUETYPE_IDS_H
 #include FT_SERVICE_XFREE86_NAME_H
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include FT_MULTIPLE_MASTERS_H
+#include FT_SERVICE_MULTIPLE_MASTERS_H
+#endif
+
 #include "ttdriver.h"
 #include "ttgload.h"
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include "ttgxvar.h"
+#endif
+
 #include "tterrors.h"
 
 
@@ -345,11 +354,27 @@
   /*************************************************************************/
   /*************************************************************************/
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+  static const FT_Service_MultiMastersRec  tt_service_gx_multi_masters =
+  {
+    (FT_Get_MM_Func)        NULL,
+    (FT_Set_MM_Design_Func) NULL,
+    (FT_Set_MM_Blend_Func)  TT_Set_MM_Blend,
+    (FT_Get_MM_Var_Func)    TT_Get_MM_Var,
+    (FT_Set_Var_Design_Func)TT_Set_Var_Design
+  };
+#endif
+
+
   static const FT_ServiceDescRec  tt_services[] =
   {
-    { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE },
+    { FT_SERVICE_ID_XF86_NAME,     FT_XF86_FORMAT_TRUETYPE },
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+    { FT_SERVICE_ID_MULTI_MASTERS, &tt_service_gx_multi_masters },
+#endif
     { NULL, NULL }
   };
+
 
   static FT_Module_Interface
   tt_get_interface( TT_Driver    driver,
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -26,6 +26,10 @@
 
 #include "ttgload.h"
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include "ttgxvar.h"
+#endif
+
 #include "tterrors.h"
 
 
@@ -352,7 +356,7 @@
     FT_Short        *cont, *cont_limit;
 
 
-    /* reading the contours endpoints & number of points */
+    /* reading the contours' endpoints & number of points */
     cont       = gloader->current.outline.contours;
     cont_limit = cont + n_contours;
 
@@ -724,11 +728,38 @@
       outline->tags[n_points + 3] = 0;
     }
 
-    /* Note that we return two more points that are not */
-    /* part of the glyph outline.                       */
+    /* Note that we return four more points that are not */
+    /* part of the glyph outline.                        */
 
     n_points += 4;
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+
+    if ( ((TT_Face)load->face)->doblend )
+    {
+      /* Deltas apply to the unscaled data. */
+      FT_Vector*  deltas;
+      FT_Memory   memory = load->face->memory;
+      FT_UInt     i;
+
+
+      if ( ( error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(load->face),
+                                               load->glyph_index,
+                                               &deltas,
+                                               n_points ) ) )
+        goto Exit;
+
+      for ( i = 0; i < n_points; ++i )
+      {
+        outline->points[i].x += deltas[i].x;
+        outline->points[i].y += deltas[i].y;
+      }
+
+      FT_FREE( deltas );
+    }
+
+#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
+
     /* set up zone for hinting */
     tt_prepare_zone( zone, &gloader->current, 0, 0 );
 
@@ -803,9 +834,11 @@
       load->pp4 = zone->cur[n_points - 1];
     }
 
-#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+#if defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER ) || \
+    defined( TT_CONFIG_OPTION_GX_VAR_SUPPORT )
   Exit:
 #endif
+
     return error;
   }
 
@@ -844,7 +877,11 @@
     FT_Bool               glyph_data_loaded = 0;
 #endif
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+    FT_Vector      *deltas;
+#endif
 
+
     if ( recurse_count >= TT_MAX_COMPOSITE_RECURSE )
     {
       error = TT_Err_Invalid_Composite;
@@ -997,6 +1034,28 @@
       loader->pp3.y = 0;
       loader->pp4.y = loader->pp3.y-loader->vadvance;
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+      if ( ((TT_Face)(loader->face))->doblend )
+      {
+        /* this must be done before scaling */
+        FT_Memory  memory = loader->face->memory;
+
+
+        if ( (error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face),
+                                                glyph_index,
+                                                &deltas,
+                                                4 ) ) )
+          goto Exit;
+
+        loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y;
+        loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y;
+        loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y;
+        loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y;
+
+        FT_FREE( deltas );
+      }
+#endif
+
       if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
       {
         loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
@@ -1044,14 +1103,6 @@
     loader->pp4.x = 0;
     loader->pp4.y = loader->pp3.y - loader->vadvance;
 
-    if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
-    {
-      loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
-      loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
-      loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale );
-      loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale );
-    }
-
     /***********************************************************************/
     /***********************************************************************/
     /***********************************************************************/
@@ -1124,6 +1175,56 @@
 #endif
       face->forget_glyph_frame( loader );
       opened_frame = 0;
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+
+      if ( face->doblend )
+      {
+        FT_Int       i, limit;
+        FT_SubGlyph  subglyph;
+        FT_Memory    memory = face->root.memory;
+
+
+        /* this provides additional offsets */
+        /* for each component's translation */
+
+        if ( (error = TT_Vary_Get_Glyph_Deltas(
+                        face,
+                        glyph_index,
+                        &deltas,
+                        gloader->current.num_subglyphs + 4 ) ) )
+          goto Exit;
+
+        /* Note: No subglyph reallocation here, our pointers are stable. */
+        subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs;
+        limit    = gloader->current.num_subglyphs;
+
+        for ( i = 0; i < limit; ++i, ++subglyph )
+        {
+          if ( subglyph->flags & ARGS_ARE_XY_VALUES )
+          {
+            subglyph->arg1 += deltas[i].x;
+            subglyph->arg2 += deltas[i].y;
+          }
+        }
+
+        loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y;
+        loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y;
+        loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y;
+        loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y;
+
+        FT_FREE( deltas );
+      }
+
+#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
+
+      if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
+      {
+        loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
+        loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
+        loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale );
+        loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale );
+      }
 
       /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */
       /* `as is' in the glyph slot (the client application will be     */
--- /dev/null
+++ b/src/truetype/ttgxvar.c
@@ -1,0 +1,1513 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ttgxvar.c                                                              */
+/*                                                                         */
+/*    TrueType GX Font Variation loader                                    */
+/*                                                                         */
+/*  Copyright 2004 by                                                      */
+/*  David Turner, Robert Wilhelm, Werner Lemberg, and George Williams.     */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+/***************************************************************************/
+/*                                                                         */
+/* Apple documents the `fvar', `gvar', `cvar', and `avar' tables at        */
+/*                                                                         */
+/*   http://developer.apple.com/fonts/TTRefMan/RM06/Chap6[fgca]var.html    */
+/*                                                                         */
+/* The documentation for `fvar' is inconsistant.  At one point it says     */
+/* that `countSizePairs' should be 3, at another point 2.  It should be 2. */
+/*                                                                         */
+/* The documentation for `gvar' is not intelligible; `cvar' refers you to  */
+/* `gvar' and is thus also incomprehensible.                               */
+/*                                                                         */
+/* The documentation for `avar' appears correct, but Apple has no fonts    */
+/* with an `avar' table, so it is hard to test.                            */
+/*                                                                         */
+/* Many thanks to John Jenkins (at Apple) in figuring this out.            */
+/*                                                                         */
+/*                                                                         */
+/* Apple's `kern' table has some references to tuple indices, but as there */
+/* is no indication where these indices are defined, nor how to            */
+/* interpolate the kerning values (different tuples have different         */
+/* classes) this issue is ignored.                                         */
+/*                                                                         */
+/***************************************************************************/
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_DEBUG_H
+#include FT_CONFIG_CONFIG_H
+#include FT_INTERNAL_STREAM_H
+#include FT_INTERNAL_SFNT_H
+#include FT_TRUETYPE_IDS_H
+#include FT_TRUETYPE_TAGS_H
+#include FT_MULTIPLE_MASTERS_H
+
+#include "ttdriver.h"
+#include "ttpload.h"
+#include "ttgxvar.h"
+
+#include "tterrors.h"
+
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+
+
+#define FT_Stream_FTell( stream )  \
+          ( (stream)->cursor - (stream)->base )
+#define FT_Stream_SeekSet( stream, off ) \
+              ( (stream)->cursor = (stream)->base+(off) )
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
+  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
+  /* messages during execution.                                            */
+  /*                                                                       */
+#undef  FT_COMPONENT
+#define FT_COMPONENT  trace_ttgxvar
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                       Internal Routines                       *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* The macro ALL_POINTS is used in `ft_var_readpackedpoints'.  It        */
+  /* indicates that there is a delta for every point without needing to    */
+  /* enumerate all of them.                                                */
+  /*                                                                       */
+#define ALL_POINTS  (FT_UShort*)(-1)
+
+
+  enum
+  {
+    GX_PT_POINTS_ARE_WORDS     = 0x80,
+    GX_PT_POINT_RUN_COUNT_MASK = 0x7F
+  };
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    ft_var_readpackedpoints                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Read a set of points to which the following deltas will apply.     */
+  /*    Points are packed with a run length encoding.                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream    :: The data stream.                                      */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    point_cnt :: The number of points read.  A zero value means that   */
+  /*                 all points in the glyph will be affected, without     */
+  /*                 enumerating them individually.                        */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    An array of FT_UShort containing the affected points or the        */
+  /*    special value ALL_POINTS.                                          */
+  /*                                                                       */
+  static FT_UShort*
+  ft_var_readpackedpoints( FT_Stream  stream,
+                           FT_UInt   *point_cnt )
+  {
+    FT_UShort *points;
+    FT_Int     n;
+    FT_Int     runcnt;
+    FT_Int     i;
+    FT_Int     j;
+    FT_Int     first;
+    FT_Memory  memory = stream->memory;
+    FT_Error   error;
+
+
+    *point_cnt = n = FT_GET_BYTE();
+    if ( n == 0 )
+      return ALL_POINTS;
+
+    if ( n & GX_PT_POINTS_ARE_WORDS )
+      n = FT_GET_BYTE() | ( ( n & GX_PT_POINT_RUN_COUNT_MASK ) << 8 );
+
+    if ( FT_NEW_ARRAY( points, n ) )
+      return NULL;
+
+    i = 0;
+    while ( i < n )
+    {
+      runcnt = FT_GET_BYTE();
+      if ( runcnt & GX_PT_POINTS_ARE_WORDS )
+      {
+        runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK;
+        points[i++] = first = FT_GET_USHORT();
+
+        /* first point not included in runcount */
+        for ( j = 0; j < runcnt; ++j )
+          points[i++] = ( first += FT_GET_USHORT() );
+      }
+      else
+      {
+        points[i++] = first = FT_GET_BYTE();
+
+        for ( j = 0; j < runcnt; ++j )
+          points[i++] = ( first += FT_GET_BYTE() );
+      }
+    }
+
+    return points;
+  }
+
+
+  enum
+  {
+    GX_DT_DELTAS_ARE_ZERO      = 0x80,
+    GX_DT_DELTAS_ARE_WORDS     = 0x40,
+    GX_DT_DELTA_RUN_COUNT_MASK = 0x3F
+  };
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    ft_var_readpackeddeltas                                            */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Read a set of deltas.  These are packed slightly differently than  */
+  /*    points.  In particular there is no overall count.                  */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream    :: The data stream.                                      */
+  /*                                                                       */
+  /*    delta_cnt :: The number of to be read.                             */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    An array of FT_Short containing the deltas for the affected        */
+  /*    points.  (This only gets the deltas for one dimension.  It will    */
+  /*    generally be called twice, once for x, once for y.  When used in   */
+  /*    cvt table, it will only be called once.)                           */
+  /*                                                                       */
+  static FT_Short*
+  ft_var_readpackeddeltas( FT_Stream  stream,
+                           FT_Int     delta_cnt )
+  {
+    FT_Short  *deltas;
+    FT_Int     runcnt;
+    FT_Int     i;
+    FT_Int     j;
+    FT_Memory  memory = stream->memory;
+    FT_Error   error;
+
+
+    if ( FT_NEW_ARRAY( deltas, delta_cnt ) )
+      return NULL;
+
+    i = 0;
+    while ( i < delta_cnt )
+    {
+      runcnt = FT_GET_BYTE();
+      if ( runcnt & GX_DT_DELTAS_ARE_ZERO )
+      {
+        /* runcnt zeroes get added */
+        for ( j = 0;
+              j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt;
+              ++j )
+          deltas[i++] = 0;
+      }
+      else if ( runcnt & GX_DT_DELTAS_ARE_WORDS )
+      {
+        /* runcnt shorts from the stack */
+        for ( j = 0;
+              j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt;
+              ++j )
+          deltas[i++] = FT_GET_SHORT();
+      }
+      else
+      {
+        /* runcnt signed bytes from the stack */
+        for ( j = 0;
+              j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt;
+              ++j )
+          deltas[i++] = FT_GET_CHAR();
+      }
+
+      if ( j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) )
+      {
+        /* Bad format */
+        FT_FREE( deltas );
+        return NULL;
+      }
+    }
+
+    return deltas;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    ft_var_load_avar                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Parse the `avar' table if present.  It need not be, so we return   */
+  /*    nothing.                                                           */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face :: The font face.                                             */
+  /*                                                                       */
+  static void
+  ft_var_load_avar( TT_Face  face )
+  {
+    FT_Stream       stream = FT_FACE_STREAM(face);
+    FT_Memory       memory = stream->memory;
+    GX_Blend        blend  = face->blend;
+    GX_AVarSegment  segment;
+    FT_Error        error;
+    FT_ULong        version;
+    FT_Long         axisCount;
+    FT_Int          i, j;
+    FT_ULong        table_len;
+
+
+    blend->avar_checked = TRUE;
+    if ( ( error = face->goto_table( face, TTAG_avar, stream, &table_len ) ) )
+      return;
+    if ( FT_FRAME_ENTER( table_len ) )
+      return;
+
+    version   = FT_GET_LONG();
+    axisCount = FT_GET_LONG();
+
+    if ( version != 0x00010000L                       ||
+         axisCount != (FT_Long)blend->mmvar->num_axis )
+      return;
+
+    if ( FT_NEW_ARRAY( blend->avar_segment, axisCount ) )
+      goto Exit;
+
+    segment = &blend->avar_segment[0];
+    for ( i = 0; i < axisCount; ++i, ++segment )
+    {
+      segment->pairCount = FT_GET_USHORT();
+      if ( FT_NEW_ARRAY( segment->correspondence, segment->pairCount ) )
+      {
+        /* Failure.  Free everything we have done so far. */
+
+        for ( j = i - 1; j >= 0; --j )
+          FT_FREE( blend->avar_segment[j].correspondence );
+
+        FT_FREE( blend->avar_segment );
+        goto Exit;
+      }
+
+      for ( j = 0; j < segment->pairCount; ++j )
+      {
+        segment->correspondence[j].fromCoord =
+          FT_GET_SHORT() << 2;    /* convert to Fixed */
+        segment->correspondence[j].toCoord =
+          FT_GET_SHORT()<<2;    /* convert to Fixed */
+      }
+    }
+
+  Exit:
+    FT_FRAME_EXIT();
+  }
+
+
+  typedef struct  GX_GVar_Head_ {
+    FT_Long    version;
+    FT_UShort  axisCount;
+    FT_UShort  globalCoordCount;
+    FT_ULong   offsetToCoord;
+    FT_UShort  glyphCount;
+    FT_UShort  flags;
+    FT_ULong   offsetToData;
+
+  } GX_GVar_Head;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    ft_var_load_gvar                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Parses the `gvar' table if present.  If `fvar' is there, `gvar'    */
+  /*    had better be there too.                                           */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face :: The font face.                                             */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  static FT_Error
+  ft_var_load_gvar( TT_Face  face )
+  {
+    FT_Stream     stream = face->root.stream;
+    FT_Memory     memory = stream->memory;
+    GX_Blend      blend  = face->blend;
+    FT_Error      error;
+    FT_UInt       i, j;
+    FT_ULong      table_len;
+    FT_ULong      gvar_start;
+    FT_ULong      OffsetToData;
+    GX_GVar_Head  gvar_head;
+
+    static const FT_Frame_Field  gvar_fields[] =
+    {
+
+#undef  FT_STRUCTURE
+#define FT_STRUCTURE  GX_GVar_Head
+
+      FT_FRAME_START( 20 ),
+        FT_FRAME_LONG  ( version ),
+        FT_FRAME_USHORT( axisCount ),
+        FT_FRAME_USHORT( globalCoordCount ),
+        FT_FRAME_ULONG ( offsetToCoord ),
+        FT_FRAME_USHORT( glyphCount ),
+        FT_FRAME_USHORT( flags ),
+        FT_FRAME_ULONG ( offsetToData ),
+      FT_FRAME_END
+    };
+
+    if ( ( error = face->goto_table( face, TTAG_gvar, stream, &table_len ) ) )
+      goto Exit;
+
+    gvar_start = FT_STREAM_POS( );
+    if ( FT_STREAM_READ_FIELDS( gvar_fields, &gvar_head ) )
+      goto Exit;
+
+    blend->tuplecount  = gvar_head.globalCoordCount;
+    blend->gv_glyphcnt = gvar_head.glyphCount;
+    OffsetToData       = gvar_start + gvar_head.offsetToData;
+    
+    if ( gvar_head.version != 0x00010000L              ||
+         gvar_head.axisCount != blend->mmvar->num_axis )
+    {
+      error = TT_Err_Invalid_Table;
+      goto Exit;
+    }
+
+    if ( FT_NEW_ARRAY( blend->glyphoffsets, blend->gv_glyphcnt + 1 ) )
+      goto Exit;
+
+    if ( gvar_head.flags & 1 )
+    {
+      /* long offsets (one more offset than glyph, to mark size of last) */
+      if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 4L ) )
+        goto Exit;
+    
+      for ( i = 0; i <= blend->gv_glyphcnt; ++i )
+        blend->glyphoffsets[i] = OffsetToData + FT_GET_LONG();
+
+      FT_FRAME_EXIT();
+    }
+    else
+    {
+      /* short offsets (one more offset than glyph, to mark size of last) */
+      if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 2L ) )
+        goto Exit;
+      for ( i = 0; i <= blend->gv_glyphcnt; ++i )
+        blend->glyphoffsets[i] = OffsetToData + FT_GET_USHORT() * 2;
+                                              /* XXX: Undocumented: `*2'! */
+
+      FT_FRAME_EXIT();
+    }
+
+    if ( blend->tuplecount != 0 )
+    {
+      if ( FT_NEW_ARRAY( blend->tuplecoords,
+                         gvar_head.axisCount * blend->tuplecount ) )
+        goto Exit;
+
+      if ( FT_STREAM_SEEK( gvar_start + gvar_head.offsetToCoord ) ||
+           FT_FRAME_ENTER( blend->tuplecount
+                           * gvar_head.axisCount
+                           * sizeof ( short ) )                   )
+        goto Exit;
+      
+      for ( i = 0; i < blend->tuplecount; ++i )
+        for ( j = 0 ; j < gvar_head.axisCount; ++j )
+          blend->tuplecoords[i * gvar_head.axisCount + j] =
+            FT_GET_SHORT() << 2;                /* convert to FT_Fixed */
+
+      FT_FRAME_EXIT();
+    }
+
+  Exit:
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    ft_var_apply_tuple                                                 */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Figure out whether a given tuple (design) applies to the current   */
+  /*    blend, and if so, what is the scaling factor.                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    blend           :: The current blend of the font.                  */
+  /*                                                                       */
+  /*    tupleIndex      :: A flag saying whether this is an intermediate   */
+  /*                       tuple or not.                                   */
+  /*                                                                       */
+  /*    tuple_coords    :: The coordiates of the tuple in normalized axis  */
+  /*                       units.                                          */
+  /*                                                                       */
+  /*    im_start_coords :: The initial coordinatess where this tuple       */
+  /*                       starts to apply (for intermediate coordinates). */
+  /*                                                                       */
+  /*    im_end_coords   :: The final coordinates after which this tuple no */
+  /*                       longer applies (for intermediate coordinates).  */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    An FT_Fixed value containing the scaling factor.                   */
+  /*                                                                       */
+  static FT_Fixed
+  ft_var_apply_tuple( GX_Blend   blend,
+                      FT_UShort  tupleIndex,
+                      FT_Fixed*  tuple_coords,
+                      FT_Fixed*  im_start_coords,
+                      FT_Fixed*  im_end_coords )
+  {
+    FT_UInt   i;
+    FT_Fixed  apply;
+    FT_Fixed  temp;
+                     
+
+    apply = 0x10000L;
+    for ( i = 0; i < blend->num_axis; ++i )
+    {
+      if ( tuple_coords[i] == 0 )
+        /* It's not clear why (for intermediate tuples) we don't need     */
+        /* to check against start/end -- the documentation says we don't. */
+        /* Similarly, it's unclear why we don't need to scale along the   */
+        /* axis.                                                          */
+        continue;
+
+      else if ( blend->normalizedcoords[i] == 0                           ||
+                ( blend->normalizedcoords[i] < 0 && tuple_coords[i] > 0 ) ||
+                ( blend->normalizedcoords[i] > 0 && tuple_coords[i] < 0 ) )
+      {
+        apply = 0;
+        break;
+      }
+
+      else if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) )
+        /* not an intermediate tuple */
+        apply = FT_MulDiv( apply,
+                           blend->normalizedcoords[i] > 0
+                             ? blend->normalizedcoords[i]
+                             : blend->normalizedcoords[i],
+                           0x10000L );
+
+      else if ( blend->normalizedcoords[i] <= im_start_coords[i] ||
+                blend->normalizedcoords[i] >= im_end_coords[i]   )
+      {
+        apply = 0;
+        break;
+      } 
+
+      else if ( blend->normalizedcoords[i] < tuple_coords[i] )
+      {
+        temp = FT_MulDiv( blend->normalizedcoords[i] - im_start_coords[i],
+                          0x10000L,
+                          tuple_coords[i] - im_start_coords[i]);
+        apply = FT_MulDiv( apply, temp, 0x10000L );
+      }
+
+      else
+      {
+        temp = FT_MulDiv( im_end_coords[i] - blend->normalizedcoords[i],
+                          0x10000L,
+                          im_end_coords[i] - tuple_coords[i] );
+        apply = FT_MulDiv( apply, temp, 0x10000L );
+      }
+    }
+
+    return apply;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****               MULTIPLE MASTERS SERVICE FUNCTIONS              *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  typedef struct  GX_FVar_Head_ {
+    FT_Long    version;
+    FT_UShort  offsetToData;
+    FT_UShort  countSizePairs;
+    FT_UShort  axisCount;
+    FT_UShort  axisSize;
+    FT_UShort  instanceCount;
+    FT_UShort  instanceSize;
+
+  } GX_FVar_Head;
+
+
+  typedef struct  fvar_axis {
+    FT_ULong   axisTag;
+    FT_ULong   minValue;
+    FT_ULong   defaultValue;
+    FT_ULong   maxValue;
+    FT_UShort  flags;
+    FT_UShort  nameID;
+
+  } GX_FVar_Axis;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    TT_Get_MM_Var                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Check that the font's `fvar' table is valid, parse it, and return  */
+  /*    those data.                                                        */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face   :: The font face.                                           */
+  /*              TT_Get_MM_Var initializes the blend structure.           */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    master :: The `fvar' data (must be freed by caller).               */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  TT_Get_MM_Var( TT_Face      face,
+                 FT_MM_Var*  *master )
+  {
+    FT_Stream            stream = face->root.stream;
+    FT_Memory            memory = face->root.memory;
+    FT_ULong             table_len;
+    FT_Error             error  = TT_Err_Ok;
+    FT_ULong             fvar_start;
+    FT_Int               i, j;
+    FT_MM_Var*           mmvar;
+    FT_Fixed*            next_coords;
+    FT_String*           next_name;
+    FT_Var_Axis*         a;
+    FT_Var_Named_Style*  ns;
+    GX_FVar_Head         fvar_head;
+
+    static const FT_Frame_Field  fvar_fields[] =
+    {
+
+#undef  FT_STRUCTURE
+#define FT_STRUCTURE  GX_FVar_Head
+
+      FT_FRAME_START( 14 ),
+        FT_FRAME_LONG  ( version ),
+        FT_FRAME_USHORT( offsetToData ),
+        FT_FRAME_USHORT( countSizePairs ),
+        FT_FRAME_USHORT( axisCount ),
+        FT_FRAME_USHORT( axisSize ),
+        FT_FRAME_USHORT( instanceCount ),
+        FT_FRAME_USHORT( instanceSize ),
+      FT_FRAME_END
+    };
+
+    static const FT_Frame_Field  fvaraxis_fields[] =
+    {
+
+#undef  FT_STRUCTURE
+#define FT_STRUCTURE  GX_FVar_Axis
+
+      FT_FRAME_START( 20 ),
+        FT_FRAME_ULONG ( axisTag ),
+        FT_FRAME_ULONG ( minValue ),
+        FT_FRAME_ULONG ( defaultValue ),
+        FT_FRAME_ULONG ( maxValue ),
+        FT_FRAME_USHORT( flags ),
+        FT_FRAME_USHORT( nameID ),
+      FT_FRAME_END
+    };
+
+
+    if ( face->blend == NULL )
+    {
+      /* both `fvar' and `gvar' must be present */
+      if ( ( error = face->goto_table( face, TTAG_gvar,
+                                       stream, &table_len ) ) )
+        goto Exit;
+      if ( ( error = face->goto_table( face, TTAG_fvar,
+                                       stream, &table_len ) ) )
+        goto Exit;
+
+      fvar_start = FT_STREAM_POS( );
+      
+      if ( FT_STREAM_READ_FIELDS( fvar_fields, &fvar_head ) )
+        goto Exit;
+
+      if ( fvar_head.version != 0x00010000UL                              ||
+           fvar_head.countSizePairs != 2                                  ||
+           fvar_head.axisSize != 20                                       ||
+           fvar_head.instanceSize != 4 + 4 * fvar_head.axisCount          ||
+           fvar_head.offsetToData + fvar_head.axisCount * 20U +
+             fvar_head.instanceCount * fvar_head.instanceSize > table_len )
+      {
+        error = TT_Err_Invalid_Table;
+        goto Exit;
+      }
+
+      if ( FT_ALLOC( face->blend, sizeof ( GX_BlendRec ) ) )
+        goto Exit;
+
+      face->blend->mmvar_len =
+        sizeof ( FT_MM_Var ) +
+        fvar_head.axisCount * sizeof ( FT_Var_Axis ) +
+        fvar_head.instanceCount * sizeof ( FT_Var_Named_Style ) +
+        fvar_head.instanceCount * fvar_head.axisCount * sizeof ( FT_Fixed ) +
+        5 * fvar_head.axisCount;
+      if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) )
+        goto Exit;
+      face->blend->mmvar = mmvar;
+
+      mmvar->num_axis =
+        fvar_head.axisCount;
+      mmvar->num_designs =
+        (FT_UInt)-1;           /* meaningless in this context; each glyph */
+                               /* may have a different number of designs  */
+                               /* (or tuples, as called by Apple)         */
+      mmvar->num_namedstyles =
+        fvar_head.instanceCount;
+      mmvar->axis =
+        (FT_Var_Axis*)&(mmvar[1]);
+      mmvar->namedstyle =
+        (FT_Var_Named_Style*)&(mmvar->axis[fvar_head.axisCount]);
+
+      next_coords =
+        (FT_Fixed*)&(mmvar->namedstyle[fvar_head.instanceCount]);
+      for ( i = 0; i < fvar_head.instanceCount; ++i )
+      {
+        mmvar->namedstyle[i].coords  = next_coords;
+        next_coords                 += fvar_head.axisCount;
+      }
+
+      next_name = (FT_String*)next_coords;
+      for ( i = 0; i < fvar_head.axisCount; ++i )
+      {
+        mmvar->axis[i].name  = next_name;
+        next_name           += 5;
+      }
+
+      if ( FT_STREAM_SEEK( fvar_start + fvar_head.offsetToData ) )
+        goto Exit;
+
+      a = mmvar->axis;
+      for ( i = 0; i < fvar_head.axisCount; ++i )
+      {
+        GX_FVar_Axis  axis_rec;
+
+
+        if ( FT_STREAM_READ_FIELDS( fvaraxis_fields, &axis_rec ) )
+          goto Exit;
+        a->tag     = axis_rec.axisTag;
+        a->minimum = axis_rec.minValue;     /* A Fixed */
+        a->def     = axis_rec.defaultValue; /* A Fixed */
+        a->maximum = axis_rec.maxValue;     /* A Fixed */
+        a->strid   = axis_rec.nameID;
+
+        a->name[0] =   a->tag >> 24;
+        a->name[1] = ( a->tag >> 16 ) & 0xFF;
+        a->name[2] = ( a->tag >>  8 ) & 0xFF;
+        a->name[3] = ( a->tag       ) & 0xFF;
+        a->name[4] = 0;
+
+        ++a;
+      }
+
+      ns = mmvar->namedstyle;
+      for ( i = 0; i < fvar_head.instanceCount; ++i )
+      {
+        if ( FT_FRAME_ENTER( 4 + 4 * fvar_head.axisCount ) )
+          goto Exit;
+
+        ns->strid       =    FT_GET_USHORT();
+        (void) /* flags = */ FT_GET_USHORT();
+
+        for ( j = 0; j < fvar_head.axisCount; ++j )
+          ns->coords[j] = FT_GET_ULONG();     /* A Fixed */
+
+        FT_FRAME_EXIT();
+      }
+    }
+
+    if ( master != NULL )
+    {
+      FT_UInt  n;
+
+
+      if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) )
+        goto Exit;
+      FT_MEM_COPY( mmvar, face->blend->mmvar, face->blend->mmvar_len );
+
+      mmvar->axis =
+        (FT_Var_Axis*)&(mmvar[1]);
+      mmvar->namedstyle =
+        (FT_Var_Named_Style*)&(mmvar->axis[mmvar->num_axis]);
+      next_coords =
+        (FT_Fixed*)&(mmvar->namedstyle[mmvar->num_namedstyles]);
+
+      for ( n = 0; n < mmvar->num_namedstyles; ++n )
+      {
+        mmvar->namedstyle[n].coords  = next_coords;
+        next_coords                 += mmvar->num_axis;
+      }
+
+      a = mmvar->axis;
+      next_name = (FT_String*)next_coords;
+      for ( n = 0; n < mmvar->num_axis; ++n )
+      {
+        a->name = next_name;
+
+        /* standard PostScript names for some standard apple tags */
+        if ( a->tag == TTAG_wght )
+          a->name = (char *)"Weight";
+        else if ( a->tag == TTAG_wdth )
+          a->name = (char *)"Width";
+        else if ( a->tag == TTAG_opsz )
+          a->name = (char *)"OpticalSize";
+        else if ( a->tag == TTAG_slnt )
+          a->name = (char *)"Slant";
+
+        next_name += 5;
+        ++a;
+      }
+
+      *master = mmvar;
+    }
+
+  Exit:
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    TT_Set_MM_Blend                                                    */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Set the blend (normalized) coordinates for this instance of the    */
+  /*    font.  Check that the `gvar' table is reasonable and does some     */
+  /*    initial preparation.                                               */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: The font.                                            */
+  /*                  Initialize the blend structure with `gvar' data.     */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    num_coords :: Must be the axis count of the font.                  */
+  /*                                                                       */
+  /*    coords     :: An array of num_coords, each between [-1,1].         */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  TT_Set_MM_Blend( TT_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords )
+  {
+    FT_Error    error = TT_Err_Ok;
+    GX_Blend    blend;
+    FT_MM_Var*  mmvar;
+    FT_UInt     i;
+    FT_Memory   memory = face->root.memory;
+
+    enum
+    {
+      mcvt_retain,
+      mcvt_modify,
+      mcvt_load
+
+    } manageCvt;
+
+
+    face->doblend = FALSE;
+
+    if ( face->blend == NULL )
+    {
+      if ( ( error = TT_Get_MM_Var( face, NULL) ) )
+        goto Exit;
+    }
+
+    blend = face->blend;
+    mmvar = blend->mmvar;
+
+    if ( num_coords != mmvar->num_axis )
+    {
+      error = TT_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    for ( i = 0; i < num_coords; ++i )
+      if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L )
+      {
+        error = TT_Err_Invalid_Argument;
+        goto Exit;
+      }
+
+    if ( blend->glyphoffsets == NULL )
+      if ( ( error = ft_var_load_gvar( face ) ) )
+        goto Exit;
+
+    if ( blend->normalizedcoords == NULL )
+    {
+      if ( FT_NEW_ARRAY( blend->normalizedcoords, num_coords ) )
+        goto Exit;
+
+      manageCvt = mcvt_modify;
+
+      /* If we have not set the blend coordinates before this, then the  */
+      /* cvt table will still be what we read from the `cvt ' table and  */
+      /* we don't need to reload it.  We may need to change it though... */
+    }
+    else
+    {
+      for ( i = 0;
+            i < num_coords && blend->normalizedcoords[i] == coords[i];
+            ++i );
+        if ( i == num_coords )
+          manageCvt = mcvt_retain;
+        else
+          manageCvt = mcvt_load;
+
+      /* If we don't change the blend coords then we don't need to do  */
+      /* anything to the cvt table.  It will be correct.  Otherwise we */
+      /* no longer have the original cvt (it was modified when we set  */
+      /* the blend last time), so we must reload and then modify it.   */
+    }
+
+    blend->num_axis = num_coords;
+    FT_MEM_COPY( blend->normalizedcoords,
+                 coords,
+                 num_coords * sizeof ( FT_Fixed ) );
+
+    face->doblend = TRUE;
+
+    if ( face->cvt != NULL )
+    {
+      switch ( manageCvt )
+      {
+      case mcvt_load:
+        /* The cvt table has been loaded already; every time we change the */
+        /* blend we may need to reload and remodify the cvt table.         */
+        FT_FREE( face->cvt );
+        face->cvt = NULL;
+
+        tt_face_load_cvt( face, face->root.stream );
+        break;
+
+      case mcvt_modify:
+        /* The original cvt table is in memory.  All we need to do is */
+        /* apply the `cvar' table (if any).                           */
+        tt_face_vary_cvt( face, face->root.stream );
+        break;
+
+      case mcvt_retain:
+        /* The cvt table is correct for this set of coordinates. */
+        break;
+      }
+    }
+
+  Exit:
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    TT_Set_Var_Design                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Set the coordinates for the instance, measured in the user         */
+  /*    coordinate system.  Parse the `avar' table (if present) to convert */
+  /*    from user to normalized coordinates.                               */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: The font face.                                       */
+  /*                  Initialize the blend struct with `gvar' data.        */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    num_coords :: This must be the axis count of the font.             */
+  /*                                                                       */
+  /*    coords     :: A coordinate array with `num_coords' elements.       */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  TT_Set_Var_Design( TT_Face    face,
+                     FT_UInt    num_coords,
+                     FT_Fixed*  coords )
+  {
+    FT_Error        error      = TT_Err_Ok;
+    FT_Fixed*       normalized = NULL;
+    GX_Blend        blend;
+    FT_MM_Var*      mmvar;
+    FT_UInt         i, j;
+    FT_Var_Axis*    a;
+    GX_AVarSegment  av;
+    FT_Memory       memory = face->root.memory;
+
+
+    if ( face->blend == NULL )
+    {
+      if ( ( error = TT_Get_MM_Var( face, NULL ) ) )
+        goto Exit;
+    }
+
+    blend = face->blend;
+    mmvar = blend->mmvar;
+
+    if ( num_coords != mmvar->num_axis )
+    {
+      error = TT_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    /* Axis normalization is a two stage process.  First we normalize */
+    /* based on the [min,def,max] values for the axis to be [-1,0,1]. */
+    /* Then, if there's an `avar' table, we renormalize this range.   */
+
+    if ( FT_NEW_ARRAY( normalized, mmvar->num_axis ) )
+      goto Exit;
+
+    a = mmvar->axis;
+    for ( i = 0; i < mmvar->num_axis; ++i, ++a )
+    {
+      if ( coords[i] > a->maximum || coords[i] < a->minimum )
+      {
+        error = TT_Err_Invalid_Argument;
+        goto Exit;
+      }
+
+      if ( coords[i] < a->def )
+      {
+        normalized[i] = -FT_MulDiv( coords[i] - a->def,
+                                    0x10000L,
+                                    a->minimum - a->def );
+      }
+      else if ( a->maximum == a->def )
+        normalized[i] = 0;
+      else
+      {
+        normalized[i] = FT_MulDiv( coords[i] - a->def,
+                                   0x10000L,
+                                   a->maximum - a->def );
+      }
+    }
+
+    if ( !blend->avar_checked )
+      ft_var_load_avar( face );
+
+    if ( blend->avar_segment != NULL )
+    {
+      av = blend->avar_segment;
+      for ( i = 0; i < mmvar->num_axis; ++i, ++av )
+      {
+        for ( j = 1; j < av->pairCount; ++j )
+          if ( normalized[i] < av->correspondence[j].fromCoord )
+          {
+            normalized[i] =
+              FT_MulDiv(
+                FT_MulDiv(
+                  normalized[i] - av->correspondence[j - 1].fromCoord,
+                  0x10000L,
+                  av->correspondence[j].fromCoord - 
+                    av->correspondence[j - 1].fromCoord ),
+                av->correspondence[j].toCoord -
+                  av->correspondence[j - 1].toCoord,
+                0x10000L ) +
+              av->correspondence[j - 1].toCoord;
+            break;
+          }
+      }
+    }
+
+    error = TT_Set_MM_Blend( face, num_coords, normalized );
+
+  Exit:
+    FT_FREE( normalized );
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                     GX VAR PARSING ROUTINES                   *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    tt_face_vary_cvt                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Modify the loaded cvt table according to the `cvar' table and the  */
+  /*    font's blend.                                                      */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face   :: A handle to the target face object.                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream :: A handle to the input stream.                            */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /*    Most errors are ignored.  It is perfectly valid not to have a      */
+  /*    `cvar' table even if there is a `gvar' and `fvar' table.           */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  tt_face_vary_cvt( TT_Face    face,
+                    FT_Stream  stream )
+  {
+    FT_Error    error;
+    FT_Memory   memory = stream->memory;
+    FT_ULong    table_start;
+    FT_ULong    table_len;
+    FT_UInt     tupleCount;
+    FT_ULong    OffsetToData;
+    FT_ULong    here;
+    FT_UInt     i, j;
+    FT_Fixed*   tuple_coords    = NULL;
+    FT_Fixed*   im_start_coords = NULL;
+    FT_Fixed*   im_end_coords   = NULL;
+    GX_Blend    blend           = face->blend;
+    FT_UInt     point_count;
+    FT_UShort*  localpoints;
+    FT_Short*   deltas;
+
+
+    FT_TRACE2(( "CVAR " ));
+
+    if ( blend == NULL )
+    {
+      FT_TRACE2(( "no blend specified!\n" ));
+
+      error = TT_Err_Ok;
+      goto Exit;
+    }
+
+    if ( face->cvt == NULL )
+    {
+      FT_TRACE2(( "no `cvt ' table!\n" ));
+
+      error = TT_Err_Ok;
+      goto Exit;
+    }
+
+    error = face->goto_table( face, TTAG_cvar, stream, &table_len );
+    if ( error )
+    {
+      FT_TRACE2(( "is missing!\n" ));
+
+      error = TT_Err_Ok;
+      goto Exit;
+    }
+
+    if ( FT_FRAME_ENTER( table_len ) )
+    {
+      error = TT_Err_Ok;
+      goto Exit;
+    }
+
+    table_start = FT_Stream_FTell( stream );
+    if ( FT_GET_LONG() != 0x00010000L )
+    {
+      FT_TRACE2(( "bad table version!\n" ));
+
+      error = TT_Err_Ok;
+      goto FExit;
+    }
+
+    if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis )    ||
+         FT_NEW_ARRAY( im_start_coords, blend->num_axis ) ||
+         FT_NEW_ARRAY( im_end_coords, blend->num_axis )   )
+      goto FExit;
+
+    tupleCount   = FT_GET_USHORT();
+    OffsetToData = table_start + FT_GET_USHORT();
+
+    /* The documentation implies there are flags packed into the        */
+    /* tuplecount, but John Jenkins says that shared points don't apply */
+    /* to `cvar', and no other flags are defined.                       */
+
+    for ( i = 0; i < ( tupleCount & 0xFFF ); ++i )
+    {
+      FT_UInt   tupleDataSize;
+      FT_UInt   tupleIndex;
+      FT_Fixed  apply;
+
+
+      tupleDataSize = FT_GET_USHORT();
+      tupleIndex    = FT_GET_USHORT();
+
+      /* There is no provision here for a global tuple coordinate section, */
+      /* so John says.  There are no tuple indices, just embedded tuples.  */
+
+      if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD )
+      {
+        for ( j = 0; j < blend->num_axis; ++j )
+          tuple_coords[j] = FT_GET_SHORT() << 2; /* convert from        */
+                                                 /* short frac to fixed */
+      }
+      else
+      {
+        /* skip this tuple; it makes no sense */
+
+        if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE )
+          for ( j = 0; j < 2 * blend->num_axis; ++j )
+            (void)FT_GET_SHORT();
+
+        OffsetToData += tupleDataSize;
+        continue;
+      }
+
+      if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE )
+      {
+        for ( j = 0; j < blend->num_axis; ++j )
+          im_start_coords[j] = FT_GET_SHORT() << 2;
+        for ( j = 0; j < blend->num_axis; ++j )
+          im_end_coords[j] = FT_GET_SHORT() << 2;
+      }
+
+      apply = ft_var_apply_tuple( blend,
+                                  tupleIndex,
+                                  tuple_coords,
+                                  im_start_coords,
+                                  im_end_coords );
+      if ( /* tuple isn't active for our blend */
+           apply == 0                                    ||
+           /* global points not allowed,           */
+           /* if they aren't local, makes no sense */
+           !( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) )
+      {
+        OffsetToData += tupleDataSize;
+        continue;
+      }
+
+      here = FT_Stream_FTell( stream );
+
+      FT_Stream_SeekSet( stream, OffsetToData );
+
+      localpoints = ft_var_readpackedpoints( stream, &point_count );
+      deltas      = ft_var_readpackeddeltas( stream,
+                                             point_count == 0 ? face->cvt_size
+                                                              : point_count );
+      if ( localpoints == NULL || deltas == NULL )
+        /* failure, ignore it */;
+
+      else if ( localpoints == ALL_POINTS )
+      {
+        /* this means that there are deltas for every entry in cvt */
+        for ( j = 0; j < face->cvt_size; ++j )
+          face->cvt[j] += FT_MulFix( deltas[j], apply );
+      }
+
+      else
+      {
+        for ( j = 0; j < point_count; ++j )
+          face->cvt[localpoints[j]] += FT_MulFix( deltas[j], apply );
+      }
+
+      if ( localpoints != ALL_POINTS )
+        FT_FREE( localpoints );
+      FT_FREE( deltas );
+
+      OffsetToData += tupleDataSize;
+
+      FT_Stream_SeekSet( stream, here );
+    }
+
+  FExit:
+    FT_FRAME_EXIT();
+
+  Exit:
+    FT_FREE( tuple_coords );
+    FT_FREE( im_start_coords );
+    FT_FREE( im_end_coords );
+
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    TT_Vary_Get_Glyph_Deltas                                           */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Load the appropriate deltas for the current glyph.                 */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face        :: A handle to the target face object.                 */
+  /*                                                                       */
+  /*    glyph_index :: The index of the glyph being modified.              */
+  /*                                                                       */
+  /*    n_points    :: The number of the points in the glyph, including    */
+  /*                   phantom points.                                     */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    deltas      :: The array of points to change.                      */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  TT_Vary_Get_Glyph_Deltas( TT_Face      face,
+                            FT_UInt      glyph_index,
+                            FT_Vector*  *deltas,
+                            FT_UInt      n_points )
+  {
+    FT_Stream   stream = face->root.stream;
+    FT_Memory   memory = stream->memory;
+    GX_Blend    blend  = face->blend;
+    FT_Vector*  delta_xy;
+
+    FT_Error    error;
+    FT_ULong    glyph_start;
+    FT_UInt     tupleCount;
+    FT_ULong    OffsetToData;
+    FT_ULong    here;
+    FT_UInt     i, j;
+    FT_Fixed*   tuple_coords = NULL;
+    FT_Fixed*   im_start_coords = NULL;
+    FT_Fixed*   im_end_coords = NULL;
+    FT_UInt     point_count, spoint_count = 0;
+    FT_UShort*  sharedpoints = NULL;
+    FT_UShort*  localpoints;
+    FT_UShort*  points;
+    FT_Short    *deltas_x, *deltas_y;
+
+
+    if ( !face->doblend || blend == NULL )
+      return TT_Err_Invalid_Argument;
+
+    if ( ( error = FT_NEW_ARRAY( delta_xy, n_points ) ) )
+      goto Fail;
+    *deltas = delta_xy;
+
+    if ( glyph_index >= blend->gv_glyphcnt      ||
+         blend->glyphoffsets[glyph_index] ==
+           blend->glyphoffsets[glyph_index + 1] )
+      return TT_Err_Ok;               /* no variation data for this glyph */
+
+    if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] )   ||
+         FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] -
+                           blend->glyphoffsets[glyph_index] ) )
+      goto Fail;
+
+    glyph_start = FT_Stream_FTell( stream );
+
+    /* each set of glyph variation data is formatted similarly to `cvar' */
+    /* (except we get shared points and global tuples)                   */
+
+    if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis )    ||
+         FT_NEW_ARRAY( im_start_coords, blend->num_axis ) ||
+         FT_NEW_ARRAY( im_end_coords, blend->num_axis )   )
+      goto Exit;
+
+    tupleCount   = FT_GET_USHORT();
+    OffsetToData = glyph_start + FT_GET_USHORT();
+
+    if ( tupleCount & GX_TC_TUPLES_SHARE_POINT_NUMBERS )
+    {
+      here = FT_Stream_FTell( stream );
+
+      FT_Stream_SeekSet( stream, OffsetToData );
+
+      sharedpoints = ft_var_readpackedpoints( stream, &spoint_count );
+      OffsetToData = FT_Stream_FTell( stream );
+
+      FT_Stream_SeekSet( stream, here );
+    }
+
+    for ( i = 0; i < ( tupleCount & GX_TC_TUPLE_COUNT_MASK ); ++i )
+    {
+      FT_UInt   tupleDataSize;
+      FT_UInt   tupleIndex;
+      FT_Fixed  apply;
+
+
+      tupleDataSize = FT_GET_USHORT();
+      tupleIndex    = FT_GET_USHORT();
+
+      if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD )
+      {
+        for ( j = 0; j < blend->num_axis; ++j )
+          tuple_coords[j] = FT_GET_SHORT() << 2;  /* convert from        */
+                                                  /* short frac to fixed */
+      }
+      else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount )
+      {
+        error = TT_Err_Invalid_Table;
+        goto Fail;
+      }
+      else
+      {
+        FT_MEM_COPY(
+          tuple_coords,
+          &blend->tuplecoords[(tupleIndex & 0xFFF) * blend->num_axis],
+          blend->num_axis * sizeof ( FT_Fixed ) );
+      }
+
+      if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE )
+      {
+        for ( j = 0; j < blend->num_axis; ++j )
+          im_start_coords[j] = FT_GET_SHORT() << 2;
+        for ( j = 0; j < blend->num_axis; ++j )
+          im_end_coords[j] = FT_GET_SHORT() << 2;
+      }
+
+      apply = ft_var_apply_tuple( blend,
+                                  tupleIndex,
+                                  tuple_coords,
+                                  im_start_coords,
+                                  im_end_coords );
+
+      if ( apply == 0 )              /* tuple isn't active for our blend */
+      {
+        OffsetToData += tupleDataSize;
+        continue;
+      }
+
+      here = FT_Stream_FTell( stream );
+
+      if ( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS )
+      {
+        FT_Stream_SeekSet( stream, OffsetToData );
+
+        localpoints = ft_var_readpackedpoints( stream, &point_count );
+        points      = localpoints;
+      }
+      else
+      {
+        points      = sharedpoints;
+        point_count = spoint_count;
+      }
+
+      deltas_x = ft_var_readpackeddeltas( stream,
+                                          point_count == 0 ? n_points
+                                                           : point_count );
+      deltas_y = ft_var_readpackeddeltas( stream,
+                                          point_count == 0 ? n_points
+                                                           : point_count );
+
+      if ( points == NULL || deltas_y == NULL || deltas_x == NULL )
+        /* failure, ignore it */;
+
+      else if ( points == ALL_POINTS )
+      {
+        /* this means that there are deltas for every point in the glyph */
+        for ( j = 0; j < n_points; ++j )
+        {
+          delta_xy[j].x += FT_MulFix( deltas_x[j], apply );
+          delta_xy[j].y += FT_MulFix( deltas_y[j], apply );
+        }
+      }
+
+      else
+      {
+        for ( j = 0; j < point_count; ++j )
+        {
+          delta_xy[localpoints[j]].x += FT_MulFix( deltas_x[j], apply );
+          delta_xy[localpoints[j]].y += FT_MulFix( deltas_y[j], apply );
+        }
+      }
+
+      if ( localpoints != ALL_POINTS )
+        FT_FREE( localpoints );
+      FT_FREE( deltas_x );
+      FT_FREE( deltas_y );
+
+      OffsetToData += tupleDataSize;
+
+      FT_Stream_SeekSet( stream, here );
+    }
+
+    goto Exit;
+
+  Fail:
+    FT_FREE( delta_xy );
+    *deltas = NULL;
+
+  Exit:
+    FT_FREE( tuple_coords );
+    FT_FREE( im_start_coords );
+    FT_FREE( im_end_coords );
+
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    tt_done_blend                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Frees the blend internal data structure.                           */
+  /*                                                                       */
+  FT_LOCAL_DEF( void )
+  tt_done_blend( FT_Memory  memory,
+                 GX_Blend   blend )
+  {
+    if ( blend != NULL )
+    {
+      FT_UInt  i;
+
+
+      FT_FREE( blend->normalizedcoords );
+      FT_FREE( blend->mmvar );
+
+      if ( blend->avar_segment != NULL )
+      {
+        for ( i = 0; i < blend->num_axis; ++i )
+          FT_FREE( blend->avar_segment[i].correspondence );
+        FT_FREE( blend->avar_segment );
+      }
+
+      FT_FREE( blend->tuplecoords );
+      FT_FREE( blend->glyphoffsets );
+      FT_FREE( blend );
+    }
+  }
+
+#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
+
+
+/* END */
--- /dev/null
+++ b/src/truetype/ttgxvar.h
@@ -1,0 +1,182 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ttgxvar.h                                                              */
+/*                                                                         */
+/*    TrueType GX Font Variation loader (specification)                    */
+/*                                                                         */
+/*  Copyright 2004 by                                                      */
+/*  David Turner, Robert Wilhelm, Werner Lemberg and George Williams.      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#ifndef __TTGXVAR_H__
+#define __TTGXVAR_H__
+
+
+#include <ft2build.h>
+#include "ttobjs.h"
+
+
+FT_BEGIN_HEADER
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    GX_AVarCorrespondenceRec                                           */
+  /*                                                                       */
+  /* <Description>                                                         */  
+  /*    A data structure representing `shortFracCorrespondence' in `avar'  */
+  /*    table according to the specifications from Apple.                  */
+  /*                                                                       */
+  typedef struct  GX_AVarCorrespondenceRec_
+  {
+    FT_Fixed  fromCoord;
+    FT_Fixed  toCoord;
+
+  } GX_AVarCorrespondenceRec_, *GX_AVarCorrespondence;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    GX_AVarRec                                                         */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Data from the segment field of `avar' table.                       */
+  /*    There is one of these for each axis.                               */
+  /*                                                                       */
+  typedef struct  GX_AVarSegmentRec_
+  {
+    FT_UShort              pairCount;
+    GX_AVarCorrespondence  correspondence; /* array with pairCount entries */
+
+  } GX_AVarSegmentRec, *GX_AVarSegment;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    GX_BlendRec                                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Data for interpolating a font from a distortable font specified    */
+  /*    by the GX *var tables ([fgca]var).                                 */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    num_axis         :: The number of axes along which interpolation   */
+  /*                         may happen                                    */
+  /*                                                                       */
+  /*    normalizedcoords :: A normalized value (between [-1,1]) indicating */
+  /*                        the contribution along each axis to the final  */
+  /*                        interpolated font.                             */
+  /*                                                                       */
+  typedef struct  GS_BlendRec_
+  {
+    FT_UInt         num_axis;
+    FT_Fixed*       normalizedcoords;
+
+    FT_MM_Var*      mmvar;
+    FT_Int          mmvar_len;
+
+    FT_Bool         avar_checked;
+    GX_AVarSegment  avar_segment;
+
+    FT_UInt         tuplecount;      /* shared tuples in `gvar'           */
+    FT_Fixed*       tuplecoords;     /* tuplecoords[tuplecount][num_axis] */
+
+    FT_UInt         gv_glyphcnt;
+    FT_ULong*       glyphoffsets;
+    
+  } GX_BlendRec;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <enum>                                                                */
+  /*    GX_TupleCountFlags                                                 */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Flags used within the `TupleCount' field of the `gvar' table.      */
+  /*                                                                       */
+  typedef enum  GX_TupleCountFlags_
+  {
+    GX_TC_TUPLES_SHARE_POINT_NUMBERS = 0x8000,
+    GX_TC_RESERVED_TUPLE_FLAGS       = 0x7000,
+    GX_TC_TUPLE_COUNT_MASK           = 0x0FFF
+
+  } GX_TupleCountFlags;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <enum>                                                                */
+  /*    GX_TupleIndexFlags                                                 */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Flags used within the `TupleIndex' field of the `gvar' and `cvar'  */
+  /*    tables.                                                            */
+  /*                                                                       */
+  typedef enum  GX_TupleIndexFlags_
+  {
+    GX_TI_EMBEDDED_TUPLE_COORD  = 0x8000,
+    GX_TI_INTERMEDIATE_TUPLE    = 0x4000,
+    GX_TI_PRIVATE_POINT_NUMBERS = 0x2000,
+    GX_TI_RESERVED_TUPLE_FLAG   = 0x1000,
+    GX_TI_TUPLE_INDEX_MASK      = 0x0FFF
+
+  } GX_TupleIndexFlags;
+
+
+#define TTAG_wght  FT_MAKE_TAG( 'w', 'g', 'h', 't' )
+#define TTAG_wdth  FT_MAKE_TAG( 'w', 'd', 't', 'h' )
+#define TTAG_opsz  FT_MAKE_TAG( 'o', 'p', 's', 'z' )
+#define TTAG_slnt  FT_MAKE_TAG( 's', 'l', 'n', 't' )
+
+
+  FT_LOCAL_DEF( FT_Error )
+  TT_Set_MM_Blend( TT_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords );
+
+  FT_LOCAL_DEF( FT_Error )
+  TT_Set_Var_Design( TT_Face    face,
+                     FT_UInt    num_coords,
+                     FT_Fixed*  coords );
+
+  FT_LOCAL_DEF( FT_Error )
+  TT_Get_MM_Var( TT_Face      face,
+                 FT_MM_Var*  *master );
+
+
+  FT_LOCAL_DEF( FT_Error )
+  tt_face_vary_cvt( TT_Face    face,
+                    FT_Stream  stream );
+
+
+  FT_LOCAL_DEF( FT_Error )
+  TT_Vary_Get_Glyph_Deltas( TT_Face      face,
+                            FT_UInt      glyph_index,
+                            FT_Vector*  *deltas,
+                            FT_UInt      n_points );
+
+
+  FT_LOCAL_DEF( void )
+  tt_done_blend( FT_Memory  memory,
+                 GX_Blend   blend );
+
+
+FT_END_HEADER
+
+
+#endif /* __TTGXVAR_H__ */
+
+
+/* END */
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Objects manager (body).                                              */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003 by                                     */
+/*  Copyright 1996-2001, 2002, 2003, 2004 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -37,6 +37,10 @@
 #include FT_TRUETYPE_UNPATENTED_H
 #endif
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include "ttgxvar.h"
+#endif
+
   /*************************************************************************/
   /*                                                                       */
   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
@@ -293,6 +297,11 @@
     FT_FRAME_RELEASE( face->cvt_program );
     face->font_program_size = 0;
     face->cvt_program_size  = 0;
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+    tt_done_blend( memory, face->blend );
+    face->blend = NULL;
+#endif
   }
 
 
--- a/src/truetype/ttpload.c
+++ b/src/truetype/ttpload.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    TrueType glyph data/program tables loader (body).                    */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002 by                                           */
+/*  Copyright 1996-2001, 2002, 2004 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -24,6 +24,10 @@
 
 #include "ttpload.h"
 
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+#include "ttgxvar.h"
+#endif
+
 #include "tterrors.h"
 
 
@@ -185,6 +189,11 @@
 
     FT_FRAME_EXIT();
     FT_TRACE2(( "loaded\n" ));
+
+#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
+    if ( face->doblend )
+      error = tt_face_vary_cvt( face, stream );
+#endif
 
   Exit:
     return error;
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Type 1 driver interface (body).                                      */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003 by                                     */
+/*  Copyright 1996-2001, 2002, 2003, 2004 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -129,9 +129,11 @@
 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
   static const FT_Service_MultiMastersRec  t1_service_multi_masters =
   {
-    (FT_Get_MM_Func)       T1_Get_Multi_Master,
-    (FT_Set_MM_Design_Func)T1_Set_MM_Design,
-    (FT_Set_MM_Blend_Func) T1_Set_MM_Blend
+    (FT_Get_MM_Func)        T1_Get_Multi_Master,
+    (FT_Set_MM_Design_Func) T1_Set_MM_Design,
+    (FT_Set_MM_Blend_Func)  T1_Set_MM_Blend,
+    (FT_Get_MM_Var_Func)    T1_Get_MM_Var,
+    (FT_Set_Var_Design_Func)T1_Set_Var_Design
   };
 #endif
 
--- a/src/type1/t1load.c
+++ b/src/type1/t1load.c
@@ -211,7 +211,61 @@
   }
 
 
+#define FT_INT_TO_FIXED( a )  ( (a) << 16 )
+#define FT_FIXED_TO_INT( a )  ( FT_RoundFix( a ) >> 16 )
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* Just a wrapper around T1_Get_Multi_Master to support the different    */
+  /*  arguments needed by the GX var distortable fonts.                    */
+  /*                                                                       */
   FT_LOCAL_DEF( FT_Error )
+  T1_Get_MM_Var( T1_Face      face,
+                 FT_MM_Var*  *master )
+  {
+    FT_Memory        memory = face->root.memory;
+    FT_MM_Var       *mmvar;
+    FT_Multi_Master  mmaster;
+    FT_Error         error;
+    FT_UInt          i;
+
+
+    error = T1_Get_Multi_Master( face, &mmaster );
+    if ( error )
+      goto Exit;
+    if ( FT_ALLOC( mmvar,
+                   sizeof ( FT_MM_Var ) +
+                     mmaster.num_axis * sizeof ( FT_Var_Axis ) ) )
+      goto Exit;
+
+    mmvar->num_axis        = mmaster.num_axis;
+    mmvar->num_designs     = mmaster.num_designs;
+    mmvar->num_namedstyles = (FT_UInt)-1;                /* Does not apply */
+    mmvar->axis            = (FT_Var_Axis*)&mmvar[1];
+                                      /* Point to axes after MM_Var struct */
+    mmvar->namedstyle      = NULL;
+
+    for ( i = 0 ; i < mmaster.num_axis; ++i )
+    {
+      mmvar->axis[i].name    = mmaster.axis[i].name;
+      mmvar->axis[i].minimum = FT_INT_TO_FIXED( mmaster.axis[i].minimum);
+      mmvar->axis[i].maximum = FT_INT_TO_FIXED( mmaster.axis[i].maximum);
+      mmvar->axis[i].def     = ( mmvar->axis[i].minimum +
+                                   mmvar->axis[i].maximum ) / 2;
+                            /* Does not apply.  But this value is in range */
+      mmvar->axis[i].tag     = 0xFFFFFFFFLU;   /* Does not apply */
+      mmvar->axis[i].strid   = 0xFFFFFFFFLU;   /* Does not apply */
+    }
+
+    *master = mmvar;
+
+  Exit:
+    return error;
+  }
+
+
+  FT_LOCAL_DEF( FT_Error )
   T1_Set_MM_Blend( T1_Face    face,
                    FT_UInt    num_coords,
                    FT_Fixed*  coords )
@@ -326,6 +380,33 @@
     }
 
     return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* Just a wrapper around T1_Set_MM_Design to support the different       */
+  /* arguments needed by the GX var distortable fonts.                     */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  T1_Set_Var_Design( T1_Face    face,
+                     FT_UInt    num_coords,
+                     FT_Fixed*  coords )
+  {
+     FT_Long   lcoords[4];          /* maximum axis count is 4 */
+     FT_UInt   i;
+     FT_Error  error;
+
+
+     error = T1_Err_Invalid_Argument;
+     if ( num_coords <= 4 && num_coords > 0 )
+     {
+       for ( i = 0; i < num_coords; ++i )
+         lcoords[i] = FT_FIXED_TO_INT( coords[i] );
+       error = T1_Set_MM_Design( face, num_coords, lcoords );
+     }
+
+     return error;
   }
 
 
--- a/src/type1/t1load.h
+++ b/src/type1/t1load.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Type 1 font loader (specification).                                  */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002 by                                           */
+/*  Copyright 1996-2001, 2002, 2004 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -60,6 +60,10 @@
   T1_Get_Multi_Master( T1_Face           face,
                        FT_Multi_Master*  master );
 
+  FT_LOCAL_DEF( FT_Error )
+  T1_Get_MM_Var( T1_Face      face,
+                 FT_MM_Var*  *master );
+
   FT_LOCAL( FT_Error )
   T1_Set_MM_Blend( T1_Face    face,
                    FT_UInt    num_coords,
@@ -69,6 +73,11 @@
   T1_Set_MM_Design( T1_Face   face,
                     FT_UInt   num_coords,
                     FT_Long*  coords );
+
+  FT_LOCAL_DEF( FT_Error )
+  T1_Set_Var_Design( T1_Face    face,
+                     FT_UInt    num_coords,
+                     FT_Fixed*  coords );
 
   FT_LOCAL( void )
   T1_Done_Blend( T1_Face  face );