@@ -836,6 +836,160 @@ def test_instanceworker_instantiate_ttfont_and_gen_restricted_and_unrestricted_s
836836 assert tested_axes == ["MONO" , "wght" , "CRSV" ]
837837
838838
839+ def test_instanceworker_instantiate_ttfont_and_gen_restricted_and_unrestricted_subspace_multiaxis_woff (
840+ tmpdir ,
841+ ):
842+ # When there are
843+ outpath = str (tmpdir .join ("test.ttf" ))
844+ font_model = get_font_model_woff ()
845+
846+ axis_model = DesignAxisModel ()
847+ axis_model .load_font (font_model )
848+ # "MONO" axis is full range of 0.0 : 1.0
849+ # "wght" axis defined at restricted range of 200 : 400
850+ # "CRSV" axis is defined at restricted range of 0.0 : 0.5
851+ axis_model ._data [0 ][1 ] = ""
852+ axis_model ._data [1 ][1 ] = "0"
853+ axis_model ._data [2 ][1 ] = "200:400"
854+ axis_model ._data [3 ][1 ] = "0"
855+ axis_model ._data [4 ][1 ] = "0:0.5"
856+
857+ name_model = FontNameModel ()
858+ name_model .load_font (font_model )
859+
860+ bit_model = FontBitFlagModel (
861+ get_os2_default_dict_true (), get_head_default_dict_true ()
862+ )
863+
864+ iw = InstanceWorker (
865+ outpath ,
866+ font_model ,
867+ axis_model ,
868+ name_model ,
869+ bit_model ,
870+ )
871+
872+ assert iw .ttfont is None
873+ # the ttfont attribute is set with this method
874+ iw .instantiate_ttfont ()
875+ assert type (iw .ttfont ) is TTFont
876+ # it is a variable font and should have an fvar table
877+ assert "fvar" in iw .ttfont
878+
879+ # after instantiation of the partial, fvar should still be present
880+ iw .instantiate_variable_font ()
881+ assert "fvar" in iw .ttfont
882+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
883+ # the font should include a variable MONO axis, all others
884+ # should have been sliced
885+ assert "MONO" in axis_tags
886+ assert "CASL" not in axis_tags
887+ assert "wght" in axis_tags
888+ assert "slnt" not in axis_tags
889+ assert "CRSV" in axis_tags
890+
891+ # get the axis data to confirm that we have a proper restricted axis range
892+ tested_axes = []
893+ for axis in iw .ttfont ["fvar" ].axes :
894+ # full range vs. original
895+ if axis .axisTag == "MONO" :
896+ assert axis .minValue == 0.0
897+ assert axis .maxValue == 1.0
898+ assert axis .defaultValue == 0.0
899+ tested_axes .append ("MONO" )
900+ # restricted range vs. original
901+ if axis .axisTag == "wght" :
902+ assert axis .minValue == 200.0
903+ assert axis .maxValue == 400.0
904+ assert axis .defaultValue == 300.0
905+ tested_axes .append ("wght" )
906+ # restricted range vs. original
907+ if axis .axisTag == "CRSV" :
908+ assert axis .minValue == 0.0
909+ assert axis .maxValue == 0.5
910+ assert axis .defaultValue == 0.5
911+ tested_axes .append ("CRSV" )
912+
913+ assert tested_axes == ["MONO" , "wght" , "CRSV" ]
914+
915+
916+ def test_instanceworker_instantiate_ttfont_and_gen_restricted_and_unrestricted_subspace_multiaxis_woff2 (
917+ tmpdir ,
918+ ):
919+ # When there are
920+ outpath = str (tmpdir .join ("test.ttf" ))
921+ font_model = get_font_model_woff2 ()
922+
923+ axis_model = DesignAxisModel ()
924+ axis_model .load_font (font_model )
925+ # "MONO" axis is full range of 0.0 : 1.0
926+ # "wght" axis defined at restricted range of 200 : 400
927+ # "CRSV" axis is defined at restricted range of 0.0 : 0.5
928+ axis_model ._data [0 ][1 ] = ""
929+ axis_model ._data [1 ][1 ] = "0"
930+ axis_model ._data [2 ][1 ] = "200:400"
931+ axis_model ._data [3 ][1 ] = "0"
932+ axis_model ._data [4 ][1 ] = "0:0.5"
933+
934+ name_model = FontNameModel ()
935+ name_model .load_font (font_model )
936+
937+ bit_model = FontBitFlagModel (
938+ get_os2_default_dict_true (), get_head_default_dict_true ()
939+ )
940+
941+ iw = InstanceWorker (
942+ outpath ,
943+ font_model ,
944+ axis_model ,
945+ name_model ,
946+ bit_model ,
947+ )
948+
949+ assert iw .ttfont is None
950+ # the ttfont attribute is set with this method
951+ iw .instantiate_ttfont ()
952+ assert type (iw .ttfont ) is TTFont
953+ # it is a variable font and should have an fvar table
954+ assert "fvar" in iw .ttfont
955+
956+ # after instantiation of the partial, fvar should still be present
957+ iw .instantiate_variable_font ()
958+ assert "fvar" in iw .ttfont
959+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
960+ # the font should include a variable MONO axis, all others
961+ # should have been sliced
962+ assert "MONO" in axis_tags
963+ assert "CASL" not in axis_tags
964+ assert "wght" in axis_tags
965+ assert "slnt" not in axis_tags
966+ assert "CRSV" in axis_tags
967+
968+ # get the axis data to confirm that we have a proper restricted axis range
969+ tested_axes = []
970+ for axis in iw .ttfont ["fvar" ].axes :
971+ # full range vs. original
972+ if axis .axisTag == "MONO" :
973+ assert axis .minValue == 0.0
974+ assert axis .maxValue == 1.0
975+ assert axis .defaultValue == 0.0
976+ tested_axes .append ("MONO" )
977+ # restricted range vs. original
978+ if axis .axisTag == "wght" :
979+ assert axis .minValue == 200.0
980+ assert axis .maxValue == 400.0
981+ assert axis .defaultValue == 300.0
982+ tested_axes .append ("wght" )
983+ # restricted range vs. original
984+ if axis .axisTag == "CRSV" :
985+ assert axis .minValue == 0.0
986+ assert axis .maxValue == 0.5
987+ assert axis .defaultValue == 0.5
988+ tested_axes .append ("CRSV" )
989+
990+ assert tested_axes == ["MONO" , "wght" , "CRSV" ]
991+
992+
839993def test_instanceworker_instantiate_ttfont_raises_valueerror_on_invalid_data (tmpdir ):
840994 outpath = str (tmpdir .join ("test.ttf" ))
841995 font_model = get_font_model ()
0 commit comments