Skip to content

Commit 873304f

Browse files
committed
add multi-axis, restricted and unrestricted axis range sub-spacing test
1 parent 1c27e84 commit 873304f

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/test_instanceworker.py

+71
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,77 @@ def test_instanceworker_instantiate_ttfont_and_gen_subspace_multi_axis_woff2(
759759
assert "CRSV" not in axis_tags
760760

761761

762+
def test_instanceworker_instantiate_ttfont_and_gen_restricted_and_unrestricted_subspace_multiaxis(
763+
tmpdir,
764+
):
765+
# When there are
766+
outpath = str(tmpdir.join("test.ttf"))
767+
font_model = get_font_model()
768+
769+
axis_model = DesignAxisModel()
770+
axis_model.load_font(font_model)
771+
# "MONO" axis is full range of 0.0 : 1.0
772+
# "wght" axis defined at restricted range of 200 : 400
773+
# "CRSV" axis is defined at restricted range of 0.0 : 0.5
774+
axis_model._data[0][1] = ""
775+
axis_model._data[1][1] = "0"
776+
axis_model._data[2][1] = "200:400"
777+
axis_model._data[3][1] = "0"
778+
axis_model._data[4][1] = "0:0.5"
779+
780+
name_model = FontNameModel()
781+
name_model.load_font(font_model)
782+
783+
bit_model = FontBitFlagModel(
784+
get_os2_default_dict_true(), get_head_default_dict_true()
785+
)
786+
787+
iw = InstanceWorker(
788+
outpath,
789+
font_model,
790+
axis_model,
791+
name_model,
792+
bit_model,
793+
)
794+
795+
assert iw.ttfont is None
796+
# the ttfont attribute is set with this method
797+
iw.instantiate_ttfont()
798+
assert type(iw.ttfont) is TTFont
799+
# it is a variable font and should have an fvar table
800+
assert "fvar" in iw.ttfont
801+
802+
# after instantiation of the partial, fvar should still be present
803+
iw.instantiate_variable_font()
804+
assert "fvar" in iw.ttfont
805+
axis_tags = [axis.axisTag for axis in iw.ttfont["fvar"].axes]
806+
# the font should include a variable MONO axis, all others
807+
# should have been sliced
808+
assert "MONO" in axis_tags
809+
assert "CASL" not in axis_tags
810+
assert "wght" in axis_tags
811+
assert "slnt" not in axis_tags
812+
assert "CRSV" in axis_tags
813+
814+
# get the axis data to confirm that we have a proper restricted axis range
815+
for axis in iw.ttfont["fvar"].axes:
816+
# full range vs. original
817+
if axis.axisTag == "MONO":
818+
assert axis.minValue == 0.0
819+
assert axis.maxValue == 1.0
820+
assert axis.defaultValue == 0.0
821+
# restricted range vs. original
822+
if axis.axisTag == "wght":
823+
assert axis.minValue == 200.0
824+
assert axis.maxValue == 400.0
825+
assert axis.defaultValue == 300.0
826+
# restricted range vs. original
827+
if axis.axisTag == "CRSV":
828+
assert axis.minValue == 0.0
829+
assert axis.maxValue == 0.5
830+
assert axis.defaultValue == 0.5
831+
832+
762833
def test_instanceworker_instantiate_ttfont_raises_valueerror_on_invalid_data(tmpdir):
763834
outpath = str(tmpdir.join("test.ttf"))
764835
font_model = get_font_model()

0 commit comments

Comments
 (0)