def test_custom_filters(self, FontClass): ufo1 = FontClass(getpath("TestFont.ufo")) ufo1.lib[FILTERS_KEY] = [ {"name": "transformations", "kwargs": {"OffsetX": -40}, "pre": True} ] ufo2 = FontClass(getpath("TestFont.ufo")) ufo2.lib[FILTERS_KEY] = [{"name": "transformations", "kwargs": {"OffsetY": 10}}] ufos = [ufo1, ufo2] glyphSets = TTFInterpolatablePreProcessor(ufos).process() assert (glyphSets[0]["a"][0][0].x - glyphSets[1]["a"][0][0].x) == -40 assert (glyphSets[1]["a"][0][0].y - glyphSets[0]["a"][0][0].y) == 10
def test_inplace_no_remember_curve_type(self, FontClass): ufo1 = FontClass(getpath("TestFont.ufo")) ufo2 = FontClass(getpath("TestFont.ufo")) ufos = [ufo1, ufo2] for _ in range(2): TTFInterpolatablePreProcessor(ufos, inplace=True, rememberCurveType=False).process() assert CURVE_TYPE_LIB_KEY not in ufo1.layers.defaultLayer.lib assert CURVE_TYPE_LIB_KEY not in ufo2.layers.defaultLayer.lib assert glyph_has_qcurve(ufo1, "c") assert glyph_has_qcurve(ufo2, "c")
def test_no_inplace(self, FontClass): ufo1 = FontClass(getpath("TestFont.ufo")) ufo2 = FontClass(getpath("TestFont.ufo")) ufos = [ufo1, ufo2] assert CURVE_TYPE_LIB_KEY not in ufo1.lib assert CURVE_TYPE_LIB_KEY not in ufo1.layers.defaultLayer.lib assert not glyph_has_qcurve(ufo1, "c") glyphSets = TTFInterpolatablePreProcessor(ufos, inplace=False).process() for i in range(2): assert glyph_has_qcurve(glyphSets[i], "c") assert CURVE_TYPE_LIB_KEY not in ufos[i].lib assert CURVE_TYPE_LIB_KEY not in ufos[i].layers.defaultLayer.lib
def test_inplace_remember_curve_type(self, FontClass): ufo1 = FontClass(getpath("TestFont.ufo")) ufo2 = FontClass(getpath("TestFont.ufo")) ufos = [ufo1, ufo2] assert CURVE_TYPE_LIB_KEY not in ufo1.lib assert CURVE_TYPE_LIB_KEY not in ufo1.layers.defaultLayer.lib assert not glyph_has_qcurve(ufo1, "c") TTFInterpolatablePreProcessor(ufos, inplace=True, rememberCurveType=True).process() assert ufo1.layers.defaultLayer.lib[CURVE_TYPE_LIB_KEY] == "quadratic" assert glyph_has_qcurve(ufo1, "c") assert ufo2.layers.defaultLayer.lib[CURVE_TYPE_LIB_KEY] == "quadratic" assert glyph_has_qcurve(ufo2, "c")
def test_custom_filters_as_argument(self, FontClass): ufo1 = FontClass(getpath("TestFont.ufo")) ufo2 = FontClass(getpath("TestFont.ufo")) filter1 = loadFilterFromString("RemoveOverlapsFilter(backend='pathops')") filter2 = loadFilterFromString( "TransformationsFilter(OffsetY=-200, include=['d'], pre=True)" ) filter3 = loadFilterFromString("TransformationsFilter(OffsetX=10)") ufos = [ufo1, ufo2] glyphSets = TTFInterpolatablePreProcessor( ufos, filters=[filter1, filter2, filter3], ).process() # Both UFOs have the same filters applied assert (glyphSets[0]["a"][0][0].x - glyphSets[1]["a"][0][0].x) == 0 # "a" has initially its starting point at (66, 0) assert (glyphSets[0]["a"][0][0].x, glyphSets[0]["a"][0][0].y) == (76, 0) assert (glyphSets[1]["a"][0][0].x, glyphSets[1]["a"][0][0].y) == (76, 0) # A component was shifted to overlap with another in a pre-filter # filter2, before overlaps were removed in a post-filter filter1 assert len(glyphSets[0]["d"].components) == 0