xref: /aosp_15_r20/external/fonttools/Tests/varLib/instancer/names_test.py (revision e1fe3e4ad2793916b15cccdc4a7da52a7e1dd0e9)
1*e1fe3e4aSElliott Hughesfrom fontTools.ttLib.tables import otTables
2*e1fe3e4aSElliott Hughesfrom fontTools.otlLib.builder import buildStatTable
3*e1fe3e4aSElliott Hughesfrom fontTools.varLib import instancer
4*e1fe3e4aSElliott Hughes
5*e1fe3e4aSElliott Hughesimport pytest
6*e1fe3e4aSElliott Hughes
7*e1fe3e4aSElliott Hughes
8*e1fe3e4aSElliott Hughesdef test_pruningUnusedNames(varfont):
9*e1fe3e4aSElliott Hughes    varNameIDs = instancer.names.getVariationNameIDs(varfont)
10*e1fe3e4aSElliott Hughes
11*e1fe3e4aSElliott Hughes    assert varNameIDs == set(range(256, 297 + 1))
12*e1fe3e4aSElliott Hughes
13*e1fe3e4aSElliott Hughes    fvar = varfont["fvar"]
14*e1fe3e4aSElliott Hughes    stat = varfont["STAT"].table
15*e1fe3e4aSElliott Hughes
16*e1fe3e4aSElliott Hughes    with instancer.names.pruningUnusedNames(varfont):
17*e1fe3e4aSElliott Hughes        del fvar.axes[0]  # Weight (nameID=256)
18*e1fe3e4aSElliott Hughes        del fvar.instances[0]  # Thin (nameID=258)
19*e1fe3e4aSElliott Hughes        del stat.DesignAxisRecord.Axis[0]  # Weight (nameID=256)
20*e1fe3e4aSElliott Hughes        del stat.AxisValueArray.AxisValue[0]  # Thin (nameID=258)
21*e1fe3e4aSElliott Hughes
22*e1fe3e4aSElliott Hughes    assert not any(n for n in varfont["name"].names if n.nameID in {256, 258})
23*e1fe3e4aSElliott Hughes
24*e1fe3e4aSElliott Hughes    with instancer.names.pruningUnusedNames(varfont):
25*e1fe3e4aSElliott Hughes        del varfont["fvar"]
26*e1fe3e4aSElliott Hughes        del varfont["STAT"]
27*e1fe3e4aSElliott Hughes
28*e1fe3e4aSElliott Hughes    assert not any(n for n in varfont["name"].names if n.nameID in varNameIDs)
29*e1fe3e4aSElliott Hughes    assert "ltag" not in varfont
30*e1fe3e4aSElliott Hughes
31*e1fe3e4aSElliott Hughes
32*e1fe3e4aSElliott Hughesdef _test_name_records(varfont, expected, isNonRIBBI, platforms=[0x409]):
33*e1fe3e4aSElliott Hughes    nametable = varfont["name"]
34*e1fe3e4aSElliott Hughes    font_names = {
35*e1fe3e4aSElliott Hughes        (r.nameID, r.platformID, r.platEncID, r.langID): r.toUnicode()
36*e1fe3e4aSElliott Hughes        for r in nametable.names
37*e1fe3e4aSElliott Hughes    }
38*e1fe3e4aSElliott Hughes    for k in expected:
39*e1fe3e4aSElliott Hughes        if k[-1] not in platforms:
40*e1fe3e4aSElliott Hughes            continue
41*e1fe3e4aSElliott Hughes        assert font_names[k] == expected[k]
42*e1fe3e4aSElliott Hughes
43*e1fe3e4aSElliott Hughes    font_nameids = set(i[0] for i in font_names)
44*e1fe3e4aSElliott Hughes    if isNonRIBBI:
45*e1fe3e4aSElliott Hughes        assert 16 in font_nameids
46*e1fe3e4aSElliott Hughes        assert 17 in font_nameids
47*e1fe3e4aSElliott Hughes
48*e1fe3e4aSElliott Hughes    if "fvar" not in varfont:
49*e1fe3e4aSElliott Hughes        assert 25 not in font_nameids
50*e1fe3e4aSElliott Hughes
51*e1fe3e4aSElliott Hughes
52*e1fe3e4aSElliott Hughes@pytest.mark.parametrize(
53*e1fe3e4aSElliott Hughes    "limits, expected, isNonRIBBI",
54*e1fe3e4aSElliott Hughes    [
55*e1fe3e4aSElliott Hughes        # Regular
56*e1fe3e4aSElliott Hughes        (
57*e1fe3e4aSElliott Hughes            {"wght": 400},
58*e1fe3e4aSElliott Hughes            {
59*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font",
60*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
61*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-Regular",
62*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Regular",
63*e1fe3e4aSElliott Hughes            },
64*e1fe3e4aSElliott Hughes            False,
65*e1fe3e4aSElliott Hughes        ),
66*e1fe3e4aSElliott Hughes        # Regular Normal (width axis Normal isn't included since it is elided)
67*e1fe3e4aSElliott Hughes        (
68*e1fe3e4aSElliott Hughes            {"wght": 400, "wdth": 100},
69*e1fe3e4aSElliott Hughes            {
70*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font",
71*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
72*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-Regular",
73*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Regular",
74*e1fe3e4aSElliott Hughes            },
75*e1fe3e4aSElliott Hughes            False,
76*e1fe3e4aSElliott Hughes        ),
77*e1fe3e4aSElliott Hughes        # Black
78*e1fe3e4aSElliott Hughes        (
79*e1fe3e4aSElliott Hughes            {"wght": 900},
80*e1fe3e4aSElliott Hughes            {
81*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Black",
82*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
83*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-Black",
84*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Black",
85*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
86*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Black",
87*e1fe3e4aSElliott Hughes            },
88*e1fe3e4aSElliott Hughes            True,
89*e1fe3e4aSElliott Hughes        ),
90*e1fe3e4aSElliott Hughes        # Thin
91*e1fe3e4aSElliott Hughes        (
92*e1fe3e4aSElliott Hughes            {"wght": 100},
93*e1fe3e4aSElliott Hughes            {
94*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Thin",
95*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
96*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-Thin",
97*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Thin",
98*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
99*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Thin",
100*e1fe3e4aSElliott Hughes            },
101*e1fe3e4aSElliott Hughes            True,
102*e1fe3e4aSElliott Hughes        ),
103*e1fe3e4aSElliott Hughes        # Thin Condensed
104*e1fe3e4aSElliott Hughes        (
105*e1fe3e4aSElliott Hughes            {"wght": 100, "wdth": 79},
106*e1fe3e4aSElliott Hughes            {
107*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Thin Condensed",
108*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
109*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-ThinCondensed",
110*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-ThinCondensed",
111*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
112*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Thin Condensed",
113*e1fe3e4aSElliott Hughes            },
114*e1fe3e4aSElliott Hughes            True,
115*e1fe3e4aSElliott Hughes        ),
116*e1fe3e4aSElliott Hughes        # Condensed with unpinned weights
117*e1fe3e4aSElliott Hughes        (
118*e1fe3e4aSElliott Hughes            {"wdth": 79, "wght": (400, 900)},
119*e1fe3e4aSElliott Hughes            {
120*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Condensed",
121*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
122*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-Condensed",
123*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Condensed",
124*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
125*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Condensed",
126*e1fe3e4aSElliott Hughes            },
127*e1fe3e4aSElliott Hughes            True,
128*e1fe3e4aSElliott Hughes        ),
129*e1fe3e4aSElliott Hughes        # Restrict weight and move default, new minimum (500) > old default (400)
130*e1fe3e4aSElliott Hughes        (
131*e1fe3e4aSElliott Hughes            {"wght": (500, 900)},
132*e1fe3e4aSElliott Hughes            {
133*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Medium",
134*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Regular",
135*e1fe3e4aSElliott Hughes                (3, 3, 1, 0x409): "2.001;GOOG;TestVariableFont-Medium",
136*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Medium",
137*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
138*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Medium",
139*e1fe3e4aSElliott Hughes            },
140*e1fe3e4aSElliott Hughes            True,
141*e1fe3e4aSElliott Hughes        ),
142*e1fe3e4aSElliott Hughes    ],
143*e1fe3e4aSElliott Hughes)
144*e1fe3e4aSElliott Hughesdef test_updateNameTable_with_registered_axes_ribbi(
145*e1fe3e4aSElliott Hughes    varfont, limits, expected, isNonRIBBI
146*e1fe3e4aSElliott Hughes):
147*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, limits)
148*e1fe3e4aSElliott Hughes    _test_name_records(varfont, expected, isNonRIBBI)
149*e1fe3e4aSElliott Hughes
150*e1fe3e4aSElliott Hughes
151*e1fe3e4aSElliott Hughesdef test_updatetNameTable_axis_order(varfont):
152*e1fe3e4aSElliott Hughes    axes = [
153*e1fe3e4aSElliott Hughes        dict(
154*e1fe3e4aSElliott Hughes            tag="wght",
155*e1fe3e4aSElliott Hughes            name="Weight",
156*e1fe3e4aSElliott Hughes            values=[
157*e1fe3e4aSElliott Hughes                dict(value=400, name="Regular"),
158*e1fe3e4aSElliott Hughes            ],
159*e1fe3e4aSElliott Hughes        ),
160*e1fe3e4aSElliott Hughes        dict(
161*e1fe3e4aSElliott Hughes            tag="wdth",
162*e1fe3e4aSElliott Hughes            name="Width",
163*e1fe3e4aSElliott Hughes            values=[
164*e1fe3e4aSElliott Hughes                dict(value=75, name="Condensed"),
165*e1fe3e4aSElliott Hughes            ],
166*e1fe3e4aSElliott Hughes        ),
167*e1fe3e4aSElliott Hughes    ]
168*e1fe3e4aSElliott Hughes    nametable = varfont["name"]
169*e1fe3e4aSElliott Hughes    buildStatTable(varfont, axes)
170*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, {"wdth": 75, "wght": 400})
171*e1fe3e4aSElliott Hughes    assert nametable.getName(17, 3, 1, 0x409).toUnicode() == "Regular Condensed"
172*e1fe3e4aSElliott Hughes
173*e1fe3e4aSElliott Hughes    # Swap the axes so the names get swapped
174*e1fe3e4aSElliott Hughes    axes[0], axes[1] = axes[1], axes[0]
175*e1fe3e4aSElliott Hughes
176*e1fe3e4aSElliott Hughes    buildStatTable(varfont, axes)
177*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, {"wdth": 75, "wght": 400})
178*e1fe3e4aSElliott Hughes    assert nametable.getName(17, 3, 1, 0x409).toUnicode() == "Condensed Regular"
179*e1fe3e4aSElliott Hughes
180*e1fe3e4aSElliott Hughes
181*e1fe3e4aSElliott Hughes@pytest.mark.parametrize(
182*e1fe3e4aSElliott Hughes    "limits, expected, isNonRIBBI",
183*e1fe3e4aSElliott Hughes    [
184*e1fe3e4aSElliott Hughes        # Regular | Normal
185*e1fe3e4aSElliott Hughes        (
186*e1fe3e4aSElliott Hughes            {"wght": 400},
187*e1fe3e4aSElliott Hughes            {
188*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font",
189*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Normal",
190*e1fe3e4aSElliott Hughes            },
191*e1fe3e4aSElliott Hughes            False,
192*e1fe3e4aSElliott Hughes        ),
193*e1fe3e4aSElliott Hughes        # Black | Negreta
194*e1fe3e4aSElliott Hughes        (
195*e1fe3e4aSElliott Hughes            {"wght": 900},
196*e1fe3e4aSElliott Hughes            {
197*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Negreta",
198*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Normal",
199*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
200*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Negreta",
201*e1fe3e4aSElliott Hughes            },
202*e1fe3e4aSElliott Hughes            True,
203*e1fe3e4aSElliott Hughes        ),
204*e1fe3e4aSElliott Hughes        # Black Condensed | Negreta Zhuštěné
205*e1fe3e4aSElliott Hughes        (
206*e1fe3e4aSElliott Hughes            {"wght": 900, "wdth": 79},
207*e1fe3e4aSElliott Hughes            {
208*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Negreta Zhuštěné",
209*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Normal",
210*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
211*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Negreta Zhuštěné",
212*e1fe3e4aSElliott Hughes            },
213*e1fe3e4aSElliott Hughes            True,
214*e1fe3e4aSElliott Hughes        ),
215*e1fe3e4aSElliott Hughes    ],
216*e1fe3e4aSElliott Hughes)
217*e1fe3e4aSElliott Hughesdef test_updateNameTable_with_multilingual_names(varfont, limits, expected, isNonRIBBI):
218*e1fe3e4aSElliott Hughes    name = varfont["name"]
219*e1fe3e4aSElliott Hughes    # langID 0x405 is the Czech Windows langID
220*e1fe3e4aSElliott Hughes    name.setName("Test Variable Font", 1, 3, 1, 0x405)
221*e1fe3e4aSElliott Hughes    name.setName("Normal", 2, 3, 1, 0x405)
222*e1fe3e4aSElliott Hughes    name.setName("Normal", 261, 3, 1, 0x405)  # nameID 261=Regular STAT entry
223*e1fe3e4aSElliott Hughes    name.setName("Negreta", 266, 3, 1, 0x405)  # nameID 266=Black STAT entry
224*e1fe3e4aSElliott Hughes    name.setName("Zhuštěné", 279, 3, 1, 0x405)  # nameID 279=Condensed STAT entry
225*e1fe3e4aSElliott Hughes
226*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, limits)
227*e1fe3e4aSElliott Hughes    _test_name_records(varfont, expected, isNonRIBBI, platforms=[0x405])
228*e1fe3e4aSElliott Hughes
229*e1fe3e4aSElliott Hughes
230*e1fe3e4aSElliott Hughesdef test_updateNameTable_missing_axisValues(varfont):
231*e1fe3e4aSElliott Hughes    with pytest.raises(ValueError, match="Cannot find Axis Values {'wght': 200}"):
232*e1fe3e4aSElliott Hughes        instancer.names.updateNameTable(varfont, {"wght": 200})
233*e1fe3e4aSElliott Hughes
234*e1fe3e4aSElliott Hughes
235*e1fe3e4aSElliott Hughesdef test_updateNameTable_missing_stat(varfont):
236*e1fe3e4aSElliott Hughes    del varfont["STAT"]
237*e1fe3e4aSElliott Hughes    with pytest.raises(
238*e1fe3e4aSElliott Hughes        ValueError, match="Cannot update name table since there is no STAT table."
239*e1fe3e4aSElliott Hughes    ):
240*e1fe3e4aSElliott Hughes        instancer.names.updateNameTable(varfont, {"wght": 400})
241*e1fe3e4aSElliott Hughes
242*e1fe3e4aSElliott Hughes
243*e1fe3e4aSElliott Hughes@pytest.mark.parametrize(
244*e1fe3e4aSElliott Hughes    "limits, expected, isNonRIBBI",
245*e1fe3e4aSElliott Hughes    [
246*e1fe3e4aSElliott Hughes        # Regular | Normal
247*e1fe3e4aSElliott Hughes        (
248*e1fe3e4aSElliott Hughes            {"wght": 400},
249*e1fe3e4aSElliott Hughes            {
250*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font",
251*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Italic",
252*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-Italic",
253*e1fe3e4aSElliott Hughes            },
254*e1fe3e4aSElliott Hughes            False,
255*e1fe3e4aSElliott Hughes        ),
256*e1fe3e4aSElliott Hughes        # Black Condensed Italic
257*e1fe3e4aSElliott Hughes        (
258*e1fe3e4aSElliott Hughes            {"wght": 900, "wdth": 79},
259*e1fe3e4aSElliott Hughes            {
260*e1fe3e4aSElliott Hughes                (1, 3, 1, 0x409): "Test Variable Font Black Condensed",
261*e1fe3e4aSElliott Hughes                (2, 3, 1, 0x409): "Italic",
262*e1fe3e4aSElliott Hughes                (6, 3, 1, 0x409): "TestVariableFont-BlackCondensedItalic",
263*e1fe3e4aSElliott Hughes                (16, 3, 1, 0x409): "Test Variable Font",
264*e1fe3e4aSElliott Hughes                (17, 3, 1, 0x409): "Black Condensed Italic",
265*e1fe3e4aSElliott Hughes            },
266*e1fe3e4aSElliott Hughes            True,
267*e1fe3e4aSElliott Hughes        ),
268*e1fe3e4aSElliott Hughes    ],
269*e1fe3e4aSElliott Hughes)
270*e1fe3e4aSElliott Hughesdef test_updateNameTable_vf_with_italic_attribute(
271*e1fe3e4aSElliott Hughes    varfont, limits, expected, isNonRIBBI
272*e1fe3e4aSElliott Hughes):
273*e1fe3e4aSElliott Hughes    font_link_axisValue = varfont["STAT"].table.AxisValueArray.AxisValue[5]
274*e1fe3e4aSElliott Hughes    # Unset ELIDABLE_AXIS_VALUE_NAME flag
275*e1fe3e4aSElliott Hughes    font_link_axisValue.Flags &= ~instancer.names.ELIDABLE_AXIS_VALUE_NAME
276*e1fe3e4aSElliott Hughes    font_link_axisValue.ValueNameID = 294  # Roman --> Italic
277*e1fe3e4aSElliott Hughes
278*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, limits)
279*e1fe3e4aSElliott Hughes    _test_name_records(varfont, expected, isNonRIBBI)
280*e1fe3e4aSElliott Hughes
281*e1fe3e4aSElliott Hughes
282*e1fe3e4aSElliott Hughesdef test_updateNameTable_format4_axisValues(varfont):
283*e1fe3e4aSElliott Hughes    # format 4 axisValues should dominate the other axisValues
284*e1fe3e4aSElliott Hughes    stat = varfont["STAT"].table
285*e1fe3e4aSElliott Hughes
286*e1fe3e4aSElliott Hughes    axisValue = otTables.AxisValue()
287*e1fe3e4aSElliott Hughes    axisValue.Format = 4
288*e1fe3e4aSElliott Hughes    axisValue.Flags = 0
289*e1fe3e4aSElliott Hughes    varfont["name"].setName("Dominant Value", 297, 3, 1, 0x409)
290*e1fe3e4aSElliott Hughes    axisValue.ValueNameID = 297
291*e1fe3e4aSElliott Hughes    axisValue.AxisValueRecord = []
292*e1fe3e4aSElliott Hughes    for tag, value in (("wght", 900), ("wdth", 79)):
293*e1fe3e4aSElliott Hughes        rec = otTables.AxisValueRecord()
294*e1fe3e4aSElliott Hughes        rec.AxisIndex = next(
295*e1fe3e4aSElliott Hughes            i for i, a in enumerate(stat.DesignAxisRecord.Axis) if a.AxisTag == tag
296*e1fe3e4aSElliott Hughes        )
297*e1fe3e4aSElliott Hughes        rec.Value = value
298*e1fe3e4aSElliott Hughes        axisValue.AxisValueRecord.append(rec)
299*e1fe3e4aSElliott Hughes    stat.AxisValueArray.AxisValue.append(axisValue)
300*e1fe3e4aSElliott Hughes
301*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, {"wdth": 79, "wght": 900})
302*e1fe3e4aSElliott Hughes    expected = {
303*e1fe3e4aSElliott Hughes        (1, 3, 1, 0x409): "Test Variable Font Dominant Value",
304*e1fe3e4aSElliott Hughes        (2, 3, 1, 0x409): "Regular",
305*e1fe3e4aSElliott Hughes        (16, 3, 1, 0x409): "Test Variable Font",
306*e1fe3e4aSElliott Hughes        (17, 3, 1, 0x409): "Dominant Value",
307*e1fe3e4aSElliott Hughes    }
308*e1fe3e4aSElliott Hughes    _test_name_records(varfont, expected, isNonRIBBI=True)
309*e1fe3e4aSElliott Hughes
310*e1fe3e4aSElliott Hughes
311*e1fe3e4aSElliott Hughesdef test_updateNameTable_elided_axisValues(varfont):
312*e1fe3e4aSElliott Hughes    stat = varfont["STAT"].table
313*e1fe3e4aSElliott Hughes    # set ELIDABLE_AXIS_VALUE_NAME flag for all axisValues
314*e1fe3e4aSElliott Hughes    for axisValue in stat.AxisValueArray.AxisValue:
315*e1fe3e4aSElliott Hughes        axisValue.Flags |= instancer.names.ELIDABLE_AXIS_VALUE_NAME
316*e1fe3e4aSElliott Hughes
317*e1fe3e4aSElliott Hughes    stat.ElidedFallbackNameID = 266  # Regular --> Black
318*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, {"wght": 400})
319*e1fe3e4aSElliott Hughes    # Since all axis values are elided, the elided fallback name
320*e1fe3e4aSElliott Hughes    # must be used to construct the style names. Since we
321*e1fe3e4aSElliott Hughes    # changed it to Black, we need both a typoSubFamilyName and
322*e1fe3e4aSElliott Hughes    # the subFamilyName set so it conforms to the RIBBI model.
323*e1fe3e4aSElliott Hughes    expected = {(2, 3, 1, 0x409): "Regular", (17, 3, 1, 0x409): "Black"}
324*e1fe3e4aSElliott Hughes    _test_name_records(varfont, expected, isNonRIBBI=True)
325*e1fe3e4aSElliott Hughes
326*e1fe3e4aSElliott Hughes
327*e1fe3e4aSElliott Hughesdef test_updateNameTable_existing_subfamily_name_is_not_regular(varfont):
328*e1fe3e4aSElliott Hughes    # Check the subFamily name will be set to Regular when we update a name
329*e1fe3e4aSElliott Hughes    # table to a non-RIBBI style and the current subFamily name is a RIBBI
330*e1fe3e4aSElliott Hughes    # style which isn't Regular.
331*e1fe3e4aSElliott Hughes    varfont["name"].setName("Bold", 2, 3, 1, 0x409)  # subFamily Regular --> Bold
332*e1fe3e4aSElliott Hughes
333*e1fe3e4aSElliott Hughes    instancer.names.updateNameTable(varfont, {"wght": 100})
334*e1fe3e4aSElliott Hughes    expected = {(2, 3, 1, 0x409): "Regular", (17, 3, 1, 0x409): "Thin"}
335*e1fe3e4aSElliott Hughes    _test_name_records(varfont, expected, isNonRIBBI=True)
336*e1fe3e4aSElliott Hughes
337*e1fe3e4aSElliott Hughes
338*e1fe3e4aSElliott Hughesdef test_name_irrelevant_axes(varfont):
339*e1fe3e4aSElliott Hughes    # Cannot update name table if not on a named axis value location
340*e1fe3e4aSElliott Hughes    with pytest.raises(ValueError) as excinfo:
341*e1fe3e4aSElliott Hughes        location = {"wght": 400, "wdth": 90}
342*e1fe3e4aSElliott Hughes        instance = instancer.instantiateVariableFont(
343*e1fe3e4aSElliott Hughes            varfont, location, updateFontNames=True
344*e1fe3e4aSElliott Hughes        )
345*e1fe3e4aSElliott Hughes    assert "Cannot find Axis Values" in str(excinfo.value)
346*e1fe3e4aSElliott Hughes
347*e1fe3e4aSElliott Hughes    # Now let's make the wdth axis "irrelevant" to naming (no axis values)
348*e1fe3e4aSElliott Hughes    varfont["STAT"].table.AxisValueArray.AxisValue.pop(6)
349*e1fe3e4aSElliott Hughes    varfont["STAT"].table.AxisValueArray.AxisValue.pop(4)
350*e1fe3e4aSElliott Hughes    location = {"wght": 400, "wdth": 90}
351*e1fe3e4aSElliott Hughes    instance = instancer.instantiateVariableFont(
352*e1fe3e4aSElliott Hughes        varfont, location, updateFontNames=True
353*e1fe3e4aSElliott Hughes    )
354