[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
diff --git a/include/freetype/internal/services/svmm.h b/include/freetype/internal/services/svmm.h
index 59910f2..982bb47 100644
--- a/include/freetype/internal/services/svmm.h
+++ b/include/freetype/internal/services/svmm.h
@@ -102,6 +102,9 @@ FT_BEGIN_HEADER
FT_UInt* len,
FT_Fixed* weight_vector );
+ typedef void
+ (*FT_Construct_PS_Name_Func)( FT_Face face );
+
typedef FT_Error
(*FT_Var_Load_Delta_Set_Idx_Map_Func)( FT_Face face,
FT_ULong offset,
@@ -144,6 +147,7 @@ FT_BEGIN_HEADER
FT_Get_MM_WeightVector_Func get_mm_weightvector;
/* for internal use; only needed for code sharing between modules */
+ FT_Construct_PS_Name_Func construct_ps_name;
FT_Var_Load_Delta_Set_Idx_Map_Func load_delta_set_idx_map;
FT_Var_Load_Item_Var_Store_Func load_item_var_store;
FT_Var_Get_Item_Delta_Func get_item_delta;
@@ -166,6 +170,8 @@ FT_BEGIN_HEADER
get_default_named_instance_, \
set_mm_weightvector_, \
get_mm_weightvector_, \
+ \
+ construct_ps_name_, \
load_delta_set_idx_map_, \
load_item_var_store_, \
get_item_delta_, \
@@ -186,6 +192,8 @@ FT_BEGIN_HEADER
get_default_named_instance_, \
set_mm_weightvector_, \
get_mm_weightvector_, \
+ \
+ construct_ps_name_, \
load_delta_set_idx_map_, \
load_item_var_store_, \
get_item_delta_, \
diff --git a/src/base/ftmm.c b/src/base/ftmm.c
index c061431..9e2dd7e 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;
}
diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c
index 29f2a2b..6d96e4a 100644
--- a/src/cff/cffdrivr.c
+++ b/src/cff/cffdrivr.c
@@ -896,6 +896,16 @@
}
+ static void
+ cff_construct_ps_name( CFF_Face face )
+ {
+ FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm;
+
+
+ mm->construct_ps_name( FT_FACE( face ) );
+ }
+
+
static FT_Error
cff_get_mm_var( CFF_Face face,
FT_MM_Var* *master )
@@ -1039,6 +1049,10 @@
(FT_Get_MM_WeightVector_Func)
cff_get_mm_weightvector,
/* get_mm_weightvector */
+
+ (FT_Construct_PS_Name_Func)
+ cff_construct_ps_name,
+ /* construct_ps_name */
(FT_Var_Load_Delta_Set_Idx_Map_Func)
cff_load_delta_set_index_mapping,
/* load_delta_set_idx_map */
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index 54ad932..8bde30f 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -533,6 +533,9 @@
NULL, /* set_mm_weightvector */
(FT_Get_MM_WeightVector_Func)
NULL, /* get_mm_weightvector */
+
+ (FT_Construct_PS_Name_Func)
+ tt_construct_ps_name, /* construct_ps_name */
(FT_Var_Load_Delta_Set_Idx_Map_Func)
tt_var_load_delta_set_index_mapping,
/* load_delta_set_idx_map */
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 4448362..aec43c8 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -2936,9 +2936,6 @@
}
}
- /* enforce recomputation of the PostScript name; */
- FT_FREE( face->postscript_name );
-
Exit:
return error;
}
@@ -2978,14 +2975,7 @@
FT_UInt num_coords,
FT_Fixed* coords )
{
- FT_Error error;
-
-
- error = tt_set_mm_blend( face, num_coords, coords, 1 );
- if ( error )
- return error;
-
- return FT_Err_Ok;
+ return tt_set_mm_blend( face, num_coords, coords, 1 );
}
@@ -3305,7 +3295,8 @@
* Value 0 indicates to not use an instance.
*
* @Return:
- * FreeType error code. 0~means success.
+ * FreeType error code. 0~means success, -1 means success and unchanged
+ * axis values.
*/
FT_LOCAL_DEF( FT_Error )
TT_Set_Named_Instance( TT_Face face,
@@ -3361,20 +3352,10 @@
error = TT_Set_Var_Design( face,
mmvar->num_axis,
named_style->coords );
- if ( error )
- {
- /* internal error code -1 means `no change' */
- if ( error == -1 )
- error = FT_Err_Ok;
- goto Exit;
- }
}
else
error = TT_Set_Var_Design( face, 0, NULL );
- face->root.face_index = ( instance_index << 16 ) |
- ( face->root.face_index & 0xFFFFL );
-
Exit:
return error;
}
@@ -3419,6 +3400,19 @@
}
+ /* This function triggers (lazy) recomputation of the `postscript_name` */
+ /* field in `TT_Face`. */
+
+ FT_LOCAL_DEF( void )
+ tt_construct_ps_name( TT_Face face )
+ {
+ FT_Memory memory = face->root.memory;
+
+
+ FT_FREE( face->postscript_name );
+ }
+
+
/*************************************************************************/
/*************************************************************************/
/***** *****/
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index 0c096f7..4de772c 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -378,6 +378,9 @@ FT_BEGIN_HEADER
TT_Get_Default_Named_Instance( TT_Face face,
FT_UInt *instance_index );
+ FT_LOCAL( void )
+ tt_construct_ps_name( TT_Face face );
+
FT_LOCAL( FT_Error )
tt_face_vary_cvt( TT_Face face,
FT_Stream stream );
@@ -401,7 +404,6 @@ FT_BEGIN_HEADER
FT_LOCAL( void )
tt_apply_mvar( TT_Face face );
-
FT_LOCAL( FT_Error )
tt_var_load_item_variation_store( TT_Face face,
FT_ULong offset,
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index 4239d86..4abcef1 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -136,6 +136,9 @@
T1_Set_MM_WeightVector, /* set_mm_weightvector */
(FT_Get_MM_WeightVector_Func)
T1_Get_MM_WeightVector, /* get_mm_weightvector */
+
+ (FT_Construct_PS_Name_Func)
+ NULL, /* construct_ps_name */
(FT_Var_Load_Delta_Set_Idx_Map_Func)
NULL, /* load_delta_set_idx_map */
(FT_Var_Load_Item_Var_Store_Func)
diff --git a/src/type1/t1load.c b/src/type1/t1load.c
index a3b2810..ee52bf2 100644
--- a/src/type1/t1load.c
+++ b/src/type1/t1load.c
@@ -442,14 +442,7 @@
FT_UInt num_coords,
FT_Fixed* coords )
{
- FT_Error error;
-
-
- error = t1_set_mm_blend( face, num_coords, coords );
- if ( error )
- return error;
-
- return FT_Err_Ok;
+ return t1_set_mm_blend( face, num_coords, coords );
}