@@ -15,6 +15,12 @@ def bit_is_set(int_type, offset):
15
15
16
16
17
17
def get_font_model ():
18
+ # Values in this test font
19
+ # {'axisTag': 'MONO', 'axisNameID': 269, 'flags': 0, 'minValue': 0.0, 'defaultValue': 0.0, 'maxValue': 1.0}
20
+ # {'axisTag': 'CASL', 'axisNameID': 270, 'flags': 0, 'minValue': 0.0, 'defaultValue': 0.0, 'maxValue': 1.0}
21
+ # {'axisTag': 'wght', 'axisNameID': 271, 'flags': 0, 'minValue': 300.0, 'defaultValue': 300.0, 'maxValue': 1000.0}
22
+ # {'axisTag': 'slnt', 'axisNameID': 272, 'flags': 0, 'minValue': -15.0, 'defaultValue': 0.0, 'maxValue': 0.0}
23
+ # {'axisTag': 'CRSV', 'axisNameID': 273, 'flags': 0, 'minValue': 0.0, 'defaultValue': 0.5, 'maxValue': 1.0}
18
24
return FontModel (Path ("tests/assets/fonts/Recursive-VF.subset.ttf" ).resolve ())
19
25
20
26
@@ -90,7 +96,11 @@ def test_instanceworker_class_default(tmpdir):
90
96
assert iw .ttfont is None
91
97
92
98
93
- def test_instanceworker_instantiate_ttfont_and_gen_static_instance (tmpdir ):
99
+ def test_instanceworker_instantiate_ttfont_and_gen_with_no_user_axis_defs (tmpdir ):
100
+ # This should gen to the var font with the same axis ranges
101
+ # Note that this route is not executed because the application validates
102
+ # that at least one axis is defined, else there is nothing to do
103
+ # since the request is the original var font if there are no axis value defs
94
104
outpath = str (tmpdir .join ("test.ttf" ))
95
105
font_model = get_font_model ()
96
106
@@ -121,20 +131,32 @@ def test_instanceworker_instantiate_ttfont_and_gen_static_instance(tmpdir):
121
131
# it is a variable font and should have an fvar table
122
132
assert "fvar" in iw .ttfont
123
133
124
- # after instantiation of the static, fvar should be gone
134
+ # confirm that all variable axes remain
125
135
iw .instantiate_variable_font ()
126
- assert "fvar" not in iw .ttfont
136
+ assert "fvar" in iw .ttfont
137
+ # make list of axis tags
138
+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
139
+ # the font should include all variable axis tags in the original
140
+ assert "MONO" in axis_tags
141
+ assert "CASL" in axis_tags
142
+ assert "wght" in axis_tags
143
+ assert "slnt" in axis_tags
144
+ assert "CRSV" in axis_tags
127
145
128
146
129
147
def test_instanceworker_instantiate_ttfont_and_gen_partial_instance_one_axis (tmpdir ):
148
+ # When there are
130
149
outpath = str (tmpdir .join ("test.ttf" ))
131
150
font_model = get_font_model ()
132
151
133
152
axis_model = DesignAxisModel ()
134
153
axis_model .load_font (font_model )
135
- # the next step sets the user entered text to a value of "var"
136
- # on the "MONO" axis row
137
- axis_model ._data [0 ][1 ] = "var"
154
+ # "MONO" axis defined as variable (i.e., no user input)
155
+ axis_model ._data [0 ][1 ] = ""
156
+ axis_model ._data [1 ][1 ] = "0"
157
+ axis_model ._data [2 ][1 ] = "300"
158
+ axis_model ._data [3 ][1 ] = "0"
159
+ axis_model ._data [4 ][1 ] = "0.5"
138
160
139
161
name_model = FontNameModel ()
140
162
name_model .load_font (font_model )
@@ -163,7 +185,15 @@ def test_instanceworker_instantiate_ttfont_and_gen_partial_instance_one_axis(tmp
163
185
assert "fvar" in iw .ttfont
164
186
# in the test font, the "MONO" axis should still be variable
165
187
# with the variable setting that was used above
166
- assert [a .axisTag for a in iw .ttfont ["fvar" ].axes ] == ["MONO" ]
188
+ # make list of axis tags
189
+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
190
+ # the font should include a variable MONO axis, all others
191
+ # should have been sliced
192
+ assert "MONO" in axis_tags
193
+ assert "CASL" not in axis_tags
194
+ assert "wght" not in axis_tags
195
+ assert "slnt" not in axis_tags
196
+ assert "CRSV" not in axis_tags
167
197
168
198
169
199
def test_instanceworker_instantiate_ttfont_and_gen_partial_instance_multi_axis (tmpdir ):
@@ -172,10 +202,14 @@ def test_instanceworker_instantiate_ttfont_and_gen_partial_instance_multi_axis(t
172
202
173
203
axis_model = DesignAxisModel ()
174
204
axis_model .load_font (font_model )
175
- # the next step sets the user entered text to a value of "var"
176
- # and "variable" on the "MONO" and "wght" axis rows, respectively
177
- axis_model ._data [0 ][1 ] = "var"
178
- axis_model ._data [2 ][1 ] = "variable"
205
+ # the next step mocks lack of user entry in MONO and CASL axis fields
206
+ # with values defined for other fields. This should lead to a sub-space
207
+ # build with variable and wght var axes
208
+ axis_model ._data [0 ][1 ] = ""
209
+ axis_model ._data [1 ][1 ] = ""
210
+ axis_model ._data [2 ][1 ] = "300"
211
+ axis_model ._data [3 ][1 ] = "0"
212
+ axis_model ._data [4 ][1 ] = "0.5"
179
213
180
214
name_model = FontNameModel ()
181
215
name_model .load_font (font_model )
@@ -199,12 +233,17 @@ def test_instanceworker_instantiate_ttfont_and_gen_partial_instance_multi_axis(t
199
233
# it is a variable font and should have an fvar table
200
234
assert "fvar" in iw .ttfont
201
235
202
- # after instantiation of the partial , fvar should still be present
236
+ # after sub-space gen , fvar should still be present
203
237
iw .instantiate_variable_font ()
204
238
assert "fvar" in iw .ttfont
205
- # in the test font, the "MONO" axis should still be variable
206
- # with the variable setting that was used above
207
- assert [a .axisTag for a in iw .ttfont ["fvar" ].axes ] == ["MONO" , "wght" ]
239
+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
240
+ # the font should include a variable MONO and CASL axes, all others
241
+ # should have been sliced
242
+ assert "MONO" in axis_tags
243
+ assert "CASL" in axis_tags
244
+ assert "wght" not in axis_tags
245
+ assert "slnt" not in axis_tags
246
+ assert "CRSV" not in axis_tags
208
247
209
248
210
249
def test_instanceworker_instantiate_ttfont_raises_valueerror_on_invalid_data (tmpdir ):
0 commit comments