[truetype] Make `TT_Set_MM_Blend' set named instance index.

* src/truetype/ttgxvar.h (GX_Blend): New array
`normalized_stylecoords'.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Allocate and fill
`normalized_stylecoords'.
(TT_Set_MM_Blend): Check instance tuple and adjust `face_index'
accordingly.
This commit is contained in:
Werner Lemberg 2017-03-04 11:04:24 +01:00
parent 4717696c12
commit 588e38e070
3 changed files with 62 additions and 3 deletions

View File

@ -1,3 +1,15 @@
2017-03-04 Werner Lemberg <wl@gnu.org>
[truetype] Make `TT_Set_MM_Blend' set named instance index.
* src/truetype/ttgxvar.h (GX_Blend): New array
`normalized_stylecoords'.
* src/truetype/ttgxvar.c (TT_Get_MM_Var): Allocate and fill
`normalized_stylecoords'.
(TT_Set_MM_Blend): Check instance tuple and adjust `face_index'
accordingly.
2017-03-02 Werner Lemberg <wl@gnu.org>
[truetype] Split off designer/normalized conversion routines.

View File

@ -1933,6 +1933,7 @@
FT_Int i, j;
FT_MM_Var* mmvar = NULL;
FT_Fixed* next_coords;
FT_Fixed* nsc;
FT_String* next_name;
FT_Var_Axis* a;
FT_Var_Named_Style* ns;
@ -2018,7 +2019,7 @@
if ( FT_NEW( face->blend ) )
goto Exit;
/* cannot overflow 32-bit arithmetic because of limits above */
/* cannot overflow 32-bit arithmetic because of the validity check */
face->blend->mmvar_len =
sizeof ( FT_MM_Var ) +
fvar_head.axisCount * sizeof ( FT_Var_Axis ) +
@ -2108,7 +2109,20 @@
FT_TRACE5(( "\n" ));
ns = mmvar->namedstyle;
if ( fvar_head.instanceCount )
{
/* named instance coordinates are stored as design coordinates; */
/* we have to convert them to normalized coordinates also */
if ( FT_NEW_ARRAY( face->blend->normalized_stylecoords,
fvar_head.axisCount * fvar_head.instanceCount ) )
goto Exit;
if ( !face->blend->avar_checked )
ft_var_load_avar( face );
}
ns = mmvar->namedstyle;
nsc = face->blend->normalized_stylecoords;
for ( i = 0; i < fvar_head.instanceCount; i++, ns++ )
{
/* PostScript names add 2 bytes to the instance record size */
@ -2125,6 +2139,12 @@
if ( usePsName )
ns->psid = FT_GET_USHORT();
ft_var_to_normalized( face,
fvar_head.axisCount,
ns->coords,
nsc );
nsc += fvar_head.axisCount;
FT_FRAME_EXIT();
}
@ -2216,7 +2236,7 @@
FT_Error error = FT_Err_Ok;
GX_Blend blend;
FT_MM_Var* mmvar;
FT_UInt i;
FT_UInt i, j;
FT_Bool is_default_instance = 1;
FT_Memory memory = face->root.memory;
@ -2342,6 +2362,30 @@
}
}
/* check whether the current variation tuple coincides */
/* with a named instance */
for ( i = 0; i < blend->mmvar->num_namedstyles; i++ )
{
FT_Fixed* nsc = blend->normalized_stylecoords + i * blend->num_axis;
FT_Fixed* ns = blend->normalizedcoords;
for ( j = 0; j < blend->num_axis; j++, nsc++, ns++ )
{
if ( *nsc != *ns )
break;
}
if ( j == blend->num_axis )
break;
}
/* adjust named instance index */
face->root.face_index &= 0xFFFF;
if ( i < blend->mmvar->num_namedstyles )
face->root.face_index |= ( i + 1 ) << 16;
face->is_default_instance = is_default_instance;
Exit:

View File

@ -232,6 +232,9 @@ FT_BEGIN_HEADER
FT_MM_Var* mmvar;
FT_Offset mmvar_len;
FT_Fixed* normalized_stylecoords;
/* normalized_stylecoords[num_namedstyles][num_axis] */
FT_Bool avar_checked;
GX_AVarSegment avar_segment;