コード例 #1
0
    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}}]

        glyphSets0 = TTFPreProcessor(ufo1).process()
        glyphSets1 = TTFPreProcessor(ufo2).process()

        assert (glyphSets0["a"][0][0].x - glyphSets1["a"][0][0].x) == -40
        assert (glyphSets1["a"][0][0].y - glyphSets0["a"][0][0].y) == 10
コード例 #2
0
ファイル: preProcessor_test.py プロジェクト: silnrsi/ufo2ft
    def test_no_inplace(self, FontClass):
        ufo = FontClass(getpath("TestFont.ufo"))

        glyphSet = TTFPreProcessor(ufo, inplace=False).process()

        assert not glyph_has_qcurve(ufo, "c")
        assert glyph_has_qcurve(glyphSet, "c")
        assert CURVE_TYPE_LIB_KEY not in ufo.layers.defaultLayer.lib
コード例 #3
0
    def test_inplace_no_remember_curve_type(self, FontClass):
        ufo = FontClass(getpath("TestFont.ufo"))

        assert CURVE_TYPE_LIB_KEY not in ufo.lib
        assert CURVE_TYPE_LIB_KEY not in ufo.layers.defaultLayer.lib

        for _ in range(2):
            TTFPreProcessor(ufo, inplace=True, rememberCurveType=False).process()

            assert CURVE_TYPE_LIB_KEY not in ufo.lib
            assert CURVE_TYPE_LIB_KEY not in ufo.layers.defaultLayer.lib
            assert glyph_has_qcurve(ufo, "c")
コード例 #4
0
    def test_inplace_remember_curve_type(self, FontClass, caplog):
        caplog.set_level(logging.ERROR)

        ufo = FontClass(getpath("TestFont.ufo"))

        assert CURVE_TYPE_LIB_KEY not in ufo.lib
        assert CURVE_TYPE_LIB_KEY not in ufo.layers.defaultLayer.lib
        assert not glyph_has_qcurve(ufo, "c")

        TTFPreProcessor(ufo, inplace=True, rememberCurveType=True).process()

        assert CURVE_TYPE_LIB_KEY not in ufo.lib
        assert ufo.layers.defaultLayer.lib[CURVE_TYPE_LIB_KEY] == "quadratic"
        assert glyph_has_qcurve(ufo, "c")

        logger = "ufo2ft.filters.cubicToQuadratic"
        with caplog.at_level(logging.INFO, logger=logger):
            TTFPreProcessor(ufo, inplace=True, rememberCurveType=True).process()

        assert len(caplog.records) == 1
        assert "Curves already converted to quadratic" in caplog.text
        assert glyph_has_qcurve(ufo, "c")
コード例 #5
0
    def test_custom_filters_as_argument(self, FontClass):
        from ufo2ft.filters import RemoveOverlapsFilter, TransformationsFilter

        ufo1 = FontClass(getpath("TestFont.ufo"))
        ufo2 = FontClass(getpath("TestFont.ufo"))
        filter1 = RemoveOverlapsFilter(backend="pathops")
        filter2 = TransformationsFilter(include=["d"], pre=True, OffsetY=-200)
        filter3 = TransformationsFilter(OffsetX=10)

        glyphSets0 = TTFPreProcessor(
            ufo1, filters=[filter1, filter2, filter3]
        ).process()
        glyphSets1 = TTFPreProcessor(
            ufo2, filters=[filter1, filter2, filter3]
        ).process()

        # Both UFOs have the same filters applied
        assert (glyphSets0["a"][0][0].x - glyphSets1["a"][0][0].x) == 0
        # "a" has initially its starting point at (66, 0)
        assert (glyphSets0["a"][0][0].x, glyphSets0["a"][0][0].y) == (76, 0)
        assert (glyphSets1["a"][0][0].x, glyphSets1["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(glyphSets0["d"].components) == 0