freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 9c45ac3: Add `FT_Get_{MM, Var}_Blend_Coordinates' fun


From: Werner LEMBERG
Subject: [freetype2] master 9c45ac3: Add `FT_Get_{MM, Var}_Blend_Coordinates' functions.
Date: Wed, 26 Oct 2016 14:00:48 +0000 (UTC)

branch: master
commit 9c45ac39661af69119e95d25e4d4dc09c6467d43
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    Add `FT_Get_{MM,Var}_Blend_Coordinates' functions.
    
    * include/freetype/ftmm.h: Declare.
    
    * include/freetype/internal/services/svmm.h (FT_Get_MM_Blend_Func):
    New typedef.
    (MultiMasters): New MM service function `get_mm_blend'.
    (FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.
    Update all callers.
    
    * src/base/ftmm.c (FT_Get_MM_Blend_Coordinates,
    FT_Get_Var_Blend_Coordinates): Implement.
    
    * src/truetype/ttdriver.c: Updated.
    
    * src/truetype/ttgxvar.c (TT_Get_MM_Blend): New function to handle
    `get_mm_blend' service.
    * src/truetype/ttgxvar.h: Updated.
    
    * src/type1/t1driver.c: Updated.
    
    * src/type1/t1load.c (T1_Get_MM_Blend): New function to handle
    `get_mm_blend' service.
    * src/type1/t1load.h: Updated.
    
    * docs/CHANGES: Document.
---
 ChangeLog                                 |   29 ++++++++++++++
 docs/CHANGES                              |    5 +++
 include/freetype/ftmm.h                   |   46 +++++++++++++++++++++-
 include/freetype/internal/services/svmm.h |   60 ++++++++++++++++++-----------
 src/base/ftmm.c                           |   59 ++++++++++++++++++++++++++++
 src/truetype/ttdriver.c                   |    1 +
 src/truetype/ttgxvar.c                    |   58 ++++++++++++++++++++++++++++
 src/truetype/ttgxvar.h                    |    5 +++
 src/type1/t1driver.c                      |    1 +
 src/type1/t1load.c                        |   35 +++++++++++++++++
 src/type1/t1load.h                        |    5 +++
 11 files changed, 280 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1cd94bb..54bc4e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,34 @@
 2016-10-26  Werner Lemberg  <address@hidden>
 
+       Add `FT_Get_{MM,Var}_Blend_Coordinates' functions.
+
+       * include/freetype/ftmm.h: Declare.
+
+       * include/freetype/internal/services/svmm.h (FT_Get_MM_Blend_Func):
+       New typedef.
+       (MultiMasters): New MM service function `get_mm_blend'.
+       (FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.
+       Update all callers.
+
+       * src/base/ftmm.c (FT_Get_MM_Blend_Coordinates,
+       FT_Get_Var_Blend_Coordinates): Implement.
+
+       * src/truetype/ttdriver.c: Updated.
+
+       * src/truetype/ttgxvar.c (TT_Get_MM_Blend): New function to handle
+       `get_mm_blend' service.
+       * src/truetype/ttgxvar.h: Updated.
+
+       * src/type1/t1driver.c: Updated.
+
+       * src/type1/t1load.c (T1_Get_MM_Blend): New function to handle
+       `get_mm_blend' service.
+       * src/type1/t1load.h: Updated.
+
+       * docs/CHANGES: Document.
+
+2016-10-26  Werner Lemberg  <address@hidden>
+
        * src/type1/t1load.c (parse_subrs): Fix limit check.
 
        Reported as
diff --git a/docs/CHANGES b/docs/CHANGES
index f0eddc5..25e2740 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -32,6 +32,11 @@ CHANGES BETWEEN 2.7 and 2.7.1
       For example,  you no longer get `Fixed' but  rather `Sony Fixed'
       or `Misc Fixed Wide'.
 
+    - A new  function `FT_Get_Var_Blend_Coordinates'  (with its  alias
+      name  `FT_Get_MM_Blend_Coordinates') to retrieve the  normalized
+      blend  coordinates of the currently  selected variation instance
+      has been added to the Multiple Masters interface.
+
 
 ======================================================================
 
diff --git a/include/freetype/ftmm.h b/include/freetype/ftmm.h
index b5d6858..c05d3b6 100644
--- a/include/freetype/ftmm.h
+++ b/include/freetype/ftmm.h
@@ -353,7 +353,8 @@ FT_BEGIN_HEADER
   /*                  use default values for the remaining axes.           */
   /*                                                                       */
   /*    coords     :: The design coordinates array (each element must be   */
-  /*                  between 0 and 1.0).                                  */
+  /*                  between 0 and 1.0 for MM fonts, and between -1.0 and */
+  /*                  1.0 for GX var fonts).                               */
   /*                                                                       */
   /* <Return>                                                              */
   /*    FreeType error code.  0~means success.                             */
@@ -367,6 +368,35 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    FT_Get_MM_Blend_Coordinates                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    For Multiple Masters and GX var fonts, get the normalized blend    */
+  /*    coordinates of the currently selected interpolated font.           */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: A handle to the source face.                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    num_coords :: The number of design coordinates to retrieve.  If it */
+  /*                  is larger than the number of axes, set the excess    */
+  /*                  values to 0.5 for MM fonts, and to 0 for GX var      */
+  /*                  fonts.                                               */
+  /*                                                                       */
+  /*    coords     :: The design coordinates array.                        */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0~means success.                             */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Get_MM_Blend_Coordinates( FT_Face    face,
+                               FT_UInt    num_coords,
+                               FT_Fixed*  coords );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    FT_Set_Var_Blend_Coordinates                                       */
   /*                                                                       */
   /* <Description>                                                         */
@@ -377,6 +407,20 @@ FT_BEGIN_HEADER
                                 FT_UInt    num_coords,
                                 FT_Fixed*  coords );
 
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Get_Var_Blend_Coordinates                                       */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    This is another name of @FT_Get_MM_Blend_Coordinates.              */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Get_Var_Blend_Coordinates( FT_Face    face,
+                                FT_UInt    num_coords,
+                                FT_Fixed*  coords );
+
   /* */
 
 
diff --git a/include/freetype/internal/services/svmm.h 
b/include/freetype/internal/services/svmm.h
index b78a19f..8092358 100644
--- a/include/freetype/internal/services/svmm.h
+++ b/include/freetype/internal/services/svmm.h
@@ -58,12 +58,18 @@ FT_BEGIN_HEADER
                            FT_UInt   num_coords,
                            FT_Long*  coords );
 
+  typedef FT_Error
+  (*FT_Get_MM_Blend_Func)( FT_Face   face,
+                           FT_UInt   num_coords,
+                           FT_Long*  coords );
+
 
   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_Blend_Func    get_mm_blend;
     FT_Get_MM_Var_Func      get_mm_var;
     FT_Set_Var_Design_Func  set_var_design;
   };
@@ -71,33 +77,41 @@ FT_BEGIN_HEADER
 
 #ifndef FT_CONFIG_OPTION_PIC
 
-#define FT_DEFINE_SERVICE_MULTIMASTERSREC( class_,                          \
-                                           get_mm_,                         \
-                                           set_mm_design_,                  \
-                                           set_mm_blend_,                   \
-                                           get_mm_var_,                     \
-                                           set_var_design_ )                \
-  static const FT_Service_MultiMastersRec  class_ =                         \
-  {                                                                         \
-    get_mm_, set_mm_design_, set_mm_blend_, get_mm_var_, set_var_design_    \
+#define FT_DEFINE_SERVICE_MULTIMASTERSREC( class_,           \
+                                           get_mm_,          \
+                                           set_mm_design_,   \
+                                           set_mm_blend_,    \
+                                           get_mm_blend_,    \
+                                           get_mm_var_,      \
+                                           set_var_design_ ) \
+  static const FT_Service_MultiMastersRec  class_ =          \
+  {                                                          \
+    get_mm_,                                                 \
+    set_mm_design_,                                          \
+    set_mm_blend_,                                           \
+    get_mm_blend_,                                           \
+    get_mm_var_,                                             \
+    set_var_design_                                          \
   };
 
 #else /* FT_CONFIG_OPTION_PIC */
 
-#define FT_DEFINE_SERVICE_MULTIMASTERSREC( class_,                          \
-                                           get_mm_,                         \
-                                           set_mm_design_,                  \
-                                           set_mm_blend_,                   \
-                                           get_mm_var_,                     \
-                                           set_var_design_ )                \
-  void                                                                      \
-  FT_Init_Class_ ## class_( FT_Service_MultiMastersRec*  clazz )            \
-  {                                                                         \
-    clazz->get_mm         = get_mm_;                                        \
-    clazz->set_mm_design  = set_mm_design_;                                 \
-    clazz->set_mm_blend   = set_mm_blend_;                                  \
-    clazz->get_mm_var     = get_mm_var_;                                    \
-    clazz->set_var_design = set_var_design_;                                \
+#define FT_DEFINE_SERVICE_MULTIMASTERSREC( class_,               \
+                                           get_mm_,              \
+                                           set_mm_design_,       \
+                                           set_mm_blend_,        \
+                                           get_mm_blend_,        \
+                                           get_mm_var_,          \
+                                           set_var_design_ )     \
+  void                                                           \
+  FT_Init_Class_ ## class_( FT_Service_MultiMastersRec*  clazz ) \
+  {                                                              \
+    clazz->get_mm         = get_mm_;                             \
+    clazz->set_mm_design  = set_mm_design_;                      \
+    clazz->set_mm_blend   = set_mm_blend_;                       \
+    clazz->get_mm_blend   = get_mm_blend_;                       \
+    clazz->get_mm_var     = get_mm_var_;                         \
+    clazz->set_var_design = set_var_design_;                     \
   }
 
 #endif /* FT_CONFIG_OPTION_PIC */
diff --git a/src/base/ftmm.c b/src/base/ftmm.c
index 6b759ca..138515e 100644
--- a/src/base/ftmm.c
+++ b/src/base/ftmm.c
@@ -231,4 +231,63 @@
   }
 
 
+  /* documentation is in ftmm.h */
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Get_MM_Blend_Coordinates( FT_Face    face,
+                               FT_UInt    num_coords,
+                               FT_Fixed*  coords )
+  {
+    FT_Error                 error;
+    FT_Service_MultiMasters  service;
+
+
+    /* check of `face' delayed to `ft_face_get_mm_service' */
+
+    if ( !coords )
+      return FT_THROW( Invalid_Argument );
+
+    error = ft_face_get_mm_service( face, &service );
+    if ( !error )
+    {
+      error = FT_ERR( Invalid_Argument );
+      if ( service->get_mm_blend )
+         error = service->get_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_Get_Var_Blend_Coordinates( FT_Face    face,
+                                FT_UInt    num_coords,
+                                FT_Fixed*  coords )
+  {
+    FT_Error                 error;
+    FT_Service_MultiMasters  service;
+
+
+    /* check of `face' delayed to `ft_face_get_mm_service' */
+
+    if ( !coords )
+      return FT_THROW( Invalid_Argument );
+
+    error = ft_face_get_mm_service( face, &service );
+    if ( !error )
+    {
+      error = FT_ERR( Invalid_Argument );
+      if ( service->get_mm_blend )
+         error = service->get_mm_blend( face, num_coords, coords );
+    }
+
+    return error;
+  }
+
+
 /* END */
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index db8c63b..1c4b617 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -470,6 +470,7 @@
     (FT_Get_MM_Func)        NULL,                   /* get_mm         */
     (FT_Set_MM_Design_Func) NULL,                   /* set_mm_design  */
     (FT_Set_MM_Blend_Func)  TT_Set_MM_Blend,        /* set_mm_blend   */
+    (FT_Get_MM_Blend_Func)  TT_Get_MM_Blend,        /* get_mm_blend   */
     (FT_Get_MM_Var_Func)    TT_Get_MM_Var,          /* get_mm_var     */
     (FT_Set_Var_Design_Func)TT_Set_Var_Design       /* set_var_design */
   )
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 11b2908..fd00ca4 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -1186,6 +1186,64 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    TT_Get_MM_Blend                                                    */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Get the blend (normalized) coordinates for this instance of the    */
+  /*    font.                                                              */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: The font.                                            */
+  /*                  Initialize the blend structure with `gvar' data.     */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    num_coords :: The number of available coordinates.  If it is       */
+  /*                  larger than the number of axes, set the excess       */
+  /*                  values to 0.                                         */
+  /*                                                                       */
+  /*    coords     :: An array of `num_coords', each between [-1,1].       */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  TT_Get_MM_Blend( TT_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords )
+  {
+    FT_Error  error = FT_Err_Ok;
+    GX_Blend  blend;
+    FT_UInt   i, nc;
+
+
+    if ( face->blend == NULL )
+    {
+      if ( ( error = TT_Get_MM_Var( face, NULL ) ) != 0 )
+        return error;
+    }
+
+    blend = face->blend;
+
+    nc = num_coords;
+    if ( num_coords > blend->num_axis )
+    {
+      FT_TRACE2(( "TT_Get_MM_Blend: only using first %d of %d coordinates\n",
+                  blend->num_axis, num_coords ));
+      nc = blend->num_axis;
+    }
+
+    for ( i = 0; i < nc; ++i )
+      coords[i] = blend->normalizedcoords[i];
+    for ( ; i < num_coords; i++ )
+      coords[i] = 0;
+
+    return FT_Err_Ok;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    TT_Set_Var_Design                                                  */
   /*                                                                       */
   /* <Description>                                                         */
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index aa8f6ea..408de71 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -149,6 +149,11 @@ FT_BEGIN_HEADER
                    FT_Fixed*  coords );
 
   FT_LOCAL( FT_Error )
+  TT_Get_MM_Blend( TT_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords );
+
+  FT_LOCAL( FT_Error )
   TT_Set_Var_Design( TT_Face    face,
                      FT_UInt    num_coords,
                      FT_Fixed*  coords );
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index c8a87d5..e5fb701 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -122,6 +122,7 @@
     (FT_Get_MM_Func)        T1_Get_Multi_Master,   /* get_mm         */
     (FT_Set_MM_Design_Func) T1_Set_MM_Design,      /* set_mm_design  */
     (FT_Set_MM_Blend_Func)  T1_Set_MM_Blend,       /* set_mm_blend   */
+    (FT_Get_MM_Blend_Func)  T1_Get_MM_Blend,       /* get_mm_blend   */
     (FT_Get_MM_Var_Func)    T1_Get_MM_Var,         /* get_mm_var     */
     (FT_Set_Var_Design_Func)T1_Set_Var_Design      /* set_var_design */
   };
diff --git a/src/type1/t1load.c b/src/type1/t1load.c
index c573a46..a785c6e 100644
--- a/src/type1/t1load.c
+++ b/src/type1/t1load.c
@@ -413,6 +413,41 @@
 
 
   FT_LOCAL_DEF( FT_Error )
+  T1_Get_MM_Blend( T1_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords )
+  {
+    PS_Blend  blend = face->blend;
+
+    FT_Fixed  axiscoords[4];
+    FT_UInt   i, nc;
+
+
+    if ( !blend )
+      return FT_THROW( Invalid_Argument );
+
+    mm_weights_unmap( blend->weight_vector,
+                      axiscoords,
+                      blend->num_axis );
+
+    nc = num_coords;
+    if ( num_coords > blend->num_axis )
+    {
+      FT_TRACE2(( "T1_Get_MM_Blend: only using first %d of %d coordinates\n",
+                  blend->num_axis, num_coords ));
+      nc = blend->num_axis;
+    }
+
+    for ( i = 0; i < nc; ++i )
+      coords[i] = axiscoords[i];
+    for ( ; i < num_coords; i++ )
+      coords[i] = 0x8000;
+
+    return FT_Err_Ok;
+  }
+
+
+  FT_LOCAL_DEF( FT_Error )
   T1_Set_MM_Design( T1_Face   face,
                     FT_UInt   num_coords,
                     FT_Long*  coords )
diff --git a/src/type1/t1load.h b/src/type1/t1load.h
index b96fe5a..1fbd0b4 100644
--- a/src/type1/t1load.h
+++ b/src/type1/t1load.h
@@ -80,6 +80,11 @@ FT_BEGIN_HEADER
                    FT_Fixed*  coords );
 
   FT_LOCAL( FT_Error )
+  T1_Get_MM_Blend( T1_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords );
+
+  FT_LOCAL( FT_Error )
   T1_Set_MM_Design( T1_Face   face,
                     FT_UInt   num_coords,
                     FT_Long*  coords );



reply via email to

[Prev in Thread] Current Thread [Next in Thread]