[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.
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
diff --git a/ChangeLog b/ChangeLog
index d1003b3..af5b343 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 22297df..50da2ea 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -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:
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index e431983..c59d528 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -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;