Commit dd8539ef823d21337cd31894b1072808c297574f

Werner Lemberg 2017-10-07T11:40:03

New function `FT_Set_Named_Instance'. No effect yet. * src/base/ftmm.c (FT_Set_Named_Instance): New function. * include/freetype/ftmm.h: Updated.

diff --git a/ChangeLog b/ChangeLog
index 5f21f67..0d8d006 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-10-07  Werner Lemberg  <wl@gnu.org>
 
+	New function `FT_Set_Named_Instance'.
+
+	No effect yet.
+
+	* src/base/ftmm.c (FT_Set_Named_Instance): New function.
+
+	* include/freetype/ftmm.h: Updated.
+
+2017-10-07  Werner Lemberg  <wl@gnu.org>
+
 	Add macros for checking whether a font variation is active.
 
 	* include/freetype/freetype.h (FT_FACE_FLAG_VARIATION,
diff --git a/include/freetype/ftmm.h b/include/freetype/ftmm.h
index c081199..fe66f2d 100644
--- a/include/freetype/ftmm.h
+++ b/include/freetype/ftmm.h
@@ -551,6 +551,43 @@ FT_BEGIN_HEADER
                          FT_UInt     axis_index,
                          FT_UInt*    flags );
 
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Set_Named_Instance                                              */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Set or change the current named instance.                          */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face           :: A handle to the source face.                     */
+  /*                                                                       */
+  /*    instance_index :: The index of the requested instance, starting    */
+  /*                      with value 1.  If set to value 0, FreeType       */
+  /*                      switches to font access without a named          */
+  /*                      instance.                                        */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0~means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The function uses the value of `instance_index' to set bits 16-30  */
+  /*    of the face's `face_index' field.  It also resets any variation    */
+  /*    applied to the font, and the @FT_FACE_FLAG_VARIATION bit of the    */
+  /*    face's `face_flags' field gets reset to zero (i.e.,                */
+  /*    @FT_IS_VARIATION will return false).                               */
+  /*                                                                       */
+  /*    For Adobe MM fonts (which don't have named instances) this         */
+  /*    function simply resets the current face to the default instance.   */
+  /*                                                                       */
+  /* <Since>                                                               */
+  /*    2.8.2                                                              */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Set_Named_Instance( FT_Face  face,
+                         FT_UInt  instance_index );
+
   /* */
 
 
diff --git a/src/base/ftmm.c b/src/base/ftmm.c
index 43877ec..e0131ec 100644
--- a/src/base/ftmm.c
+++ b/src/base/ftmm.c
@@ -426,4 +426,52 @@
   }
 
 
+  /* documentation is in ftmm.h */
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Set_Named_Instance( FT_Face  face,
+                         FT_UInt  instance_index )
+  {
+    FT_Error  error;
+
+    FT_Service_MultiMasters       service_mm   = NULL;
+    FT_Service_MetricsVariations  service_mvar = NULL;
+
+
+    /* check of `face' delayed to `ft_face_get_mm_service' */
+
+    error = ft_face_get_mm_service( face, &service_mm );
+    if ( !error )
+    {
+      error = FT_ERR( Invalid_Argument );
+      if ( service_mm->set_instance )
+        error = service_mm->set_instance( face, instance_index );
+    }
+
+    if ( !error )
+    {
+      (void)ft_face_get_mvar_service( face, &service_mvar );
+
+      if ( service_mvar && service_mvar->metrics_adjust )
+        service_mvar->metrics_adjust( face );
+    }
+
+    /* enforce recomputation of auto-hinting data */
+    if ( !error && face->autohint.finalizer )
+    {
+      face->autohint.finalizer( face->autohint.data );
+      face->autohint.data = NULL;
+    }
+
+    if ( !error )
+    {
+      face->face_index  = ( instance_index << 16 )        |
+                          ( face->face_index & 0xFFFFL );
+      face->face_flags &= ~FT_FACE_FLAG_VARIATION;
+    }
+
+    return error;
+  }
+
+
 /* END */