diff options
author | Werner Lemberg <wl@gnu.org> | 2023-04-27 11:40:46 +0200 |
---|---|---|
committer | Werner Lemberg <wl@gnu.org> | 2023-05-06 18:53:50 +0200 |
commit | c8a24209d314c23632deaccd328e107888fab13a (patch) | |
tree | 77e38dbfaf82f8f23d2f86552c1fb55bb5d2c761 /src/base/ftmm.c | |
parent | 7af8fd0063f773ae3d3eb4866154b88dd4ec6542 (diff) | |
download | freetype2-c8a24209d314c23632deaccd328e107888fab13a.tar.gz |
[truetype] Fix PostScript name handling for variation fonts.
A variation font's PostScript name of a named instance is usually different
from the PostScript name of an unnamed instance. However, if a change
between a named instance and an unnamed instance with exactly the same
design axis values happened, it was possible that the PostScript name wasn't
correctly updated.
This commit reorganizes the code to handle this issue within the top-level
API functions, using a new service to trigger recomputation of the
PostScript name.
* include/freetype/internal/services/svmm.h (FT_Construct_PS_Name_Func): New
typedef.
(FT_Service_MultiMasters): New field `construct_ps_name`.
(FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.
* src/base/ftmm.c (FT_Set_Var_Design_Coordinates,
FT_Set_MM_Blend_Coordinates, FT_Set_Var_Blend_Coordinates): Call
`mm->construct_ps_name` to handle `postscript_name`.
(FT_Set_Named_Instance): Call `mm->construct_ps_name` to handle
`postscript_name`.
Use shortcut.
* src/cff/cffdrivr.c (cff_construct_ps_name): New function.
(cff_service_multi_masters): Updated.
* src/truetype/ttgxvar.c (tt_set_mm_blend): Don't handle `postscript_name`.
(TT_Set_MM_Blend): Simplify.
(TT_Set_Named_Instance): Return -1 if axis values haven't changed.
Don't set `face_index`.
(tt_construct_ps_name): New function.
* src/truetype/ttgxvar.h: Updated.
* src/truetype/ttdriver.c (tt_service_gx_multi_masters): Updated.
* src/type1/t1driver.c (t1_service_multi_masters): Updated.
* src/type1/t1load.c (T1_Set_MM_Blend): Simplify.
Diffstat (limited to 'src/base/ftmm.c')
-rw-r--r-- | src/base/ftmm.c | 82 |
1 files changed, 75 insertions, 7 deletions
diff --git a/src/base/ftmm.c b/src/base/ftmm.c index c061431a4..9e2dd7ee7 100644 --- a/src/base/ftmm.c +++ b/src/base/ftmm.c @@ -301,10 +301,26 @@ if ( !error || error == -1 ) { + FT_Bool is_variation_old = FT_IS_VARIATION( face ); + + if ( num_coords ) face->face_flags |= FT_FACE_FLAG_VARIATION; else face->face_flags &= ~FT_FACE_FLAG_VARIATION; + + if ( service_mm->construct_ps_name ) + { + if ( error == -1 ) + { + /* The PS name of a named instance and a non-named instance */ + /* usually differs, even if the axis values are identical. */ + if ( is_variation_old != FT_IS_VARIATION( face ) ) + service_mm->construct_ps_name( face ); + } + else + service_mm->construct_ps_name( face ); + } } /* internal error code -1 means `no change'; we can exit immediately */ @@ -385,10 +401,26 @@ if ( !error || error == -1 ) { + FT_Bool is_variation_old = FT_IS_VARIATION( face ); + + if ( num_coords ) face->face_flags |= FT_FACE_FLAG_VARIATION; else face->face_flags &= ~FT_FACE_FLAG_VARIATION; + + if ( service_mm->construct_ps_name ) + { + if ( error == -1 ) + { + /* The PS name of a named instance and a non-named instance */ + /* usually differs, even if the axis values are identical. */ + if ( is_variation_old != FT_IS_VARIATION( face ) ) + service_mm->construct_ps_name( face ); + } + else + service_mm->construct_ps_name( face ); + } } /* internal error code -1 means `no change'; we can exit immediately */ @@ -444,10 +476,26 @@ if ( !error || error == -1 ) { + FT_Bool is_variation_old = FT_IS_VARIATION( face ); + + if ( num_coords ) face->face_flags |= FT_FACE_FLAG_VARIATION; else face->face_flags &= ~FT_FACE_FLAG_VARIATION; + + if ( service_mm->construct_ps_name ) + { + if ( error == -1 ) + { + /* The PS name of a named instance and a non-named instance */ + /* usually differs, even if the axis values are identical. */ + if ( is_variation_old != FT_IS_VARIATION( face ) ) + service_mm->construct_ps_name( face ); + } + else + service_mm->construct_ps_name( face ); + } } /* internal error code -1 means `no change'; we can exit immediately */ @@ -577,6 +625,33 @@ error = FT_ERR( Invalid_Argument ); if ( service_mm->set_named_instance ) error = service_mm->set_named_instance( face, instance_index ); + + if ( !error || error == -1 ) + { + FT_Bool is_variation_old = FT_IS_VARIATION( face ); + + + face->face_flags &= ~FT_FACE_FLAG_VARIATION; + face->face_index = ( instance_index << 16 ) | + ( face->face_index & 0xFFFFL ); + + if ( service_mm->construct_ps_name ) + { + if ( error == -1 ) + { + /* The PS name of a named instance and a non-named instance */ + /* usually differs, even if the axis values are identical. */ + if ( is_variation_old != FT_IS_VARIATION( face ) ) + service_mm->construct_ps_name( face ); + } + else + service_mm->construct_ps_name( face ); + } + } + + /* internal error code -1 means `no change'; we can exit immediately */ + if ( error == -1 ) + return FT_Err_Ok; } if ( !error ) @@ -594,13 +669,6 @@ 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; } |