From dd8539ef823d21337cd31894b1072808c297574f Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sat, 7 Oct 2017 11:40:03 +0200 Subject: [PATCH] New function `FT_Set_Named_Instance'. No effect yet. * src/base/ftmm.c (FT_Set_Named_Instance): New function. * include/freetype/ftmm.h: Updated. --- ChangeLog | 10 +++++++++ include/freetype/ftmm.h | 37 +++++++++++++++++++++++++++++++ src/base/ftmm.c | 48 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5f21f6766..0d8d0069d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2017-10-07 Werner Lemberg + + 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 Add macros for checking whether a font variation is active. diff --git a/include/freetype/ftmm.h b/include/freetype/ftmm.h index c08119933..fe66f2d6c 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 ); + + /*************************************************************************/ + /* */ + /* */ + /* FT_Set_Named_Instance */ + /* */ + /* */ + /* Set or change the current named instance. */ + /* */ + /* */ + /* 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. */ + /* */ + /* */ + /* FreeType error code. 0~means success. */ + /* */ + /* */ + /* 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. */ + /* */ + /* */ + /* 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 43877ece4..e0131ece3 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 */