Example #1
0
    def test_incompatible_fonts(self):
        font1 = ufoLib2.Font()
        font1.info.unitsPerEm = 1000
        glyph1 = font1.newGlyph("a")
        pen1 = glyph1.getPen()
        for operator, args in [("moveTo", ((0, 0),)),
                               ("lineTo", ((1, 1),)),
                               ("endPath", ())]:
            getattr(pen1, operator)(*args)

        font2 = ufoLib2.Font()
        font2.info.unitsPerEm = 1000
        glyph2 = font2.newGlyph("a")
        pen2 = glyph2.getPen()
        for operator, args in [("moveTo", ((0, 0),)),
                               ("curveTo", ((1, 1), (2, 2), (3, 3))),
                               ("endPath", ())]:
            getattr(pen2, operator)(*args)

        with pytest.raises(IncompatibleFontsError) as excinfo:
            fonts_to_quadratic([font1, font2])
        assert excinfo.match("fonts contains incompatible glyphs: 'a'")

        assert hasattr(excinfo.value, "glyph_errors")
        error = excinfo.value.glyph_errors['a']
        assert isinstance(error, IncompatibleSegmentTypesError)
        assert error.segments == {1: ["line", "curve"]}
 def makeMasterGlyphsQuadractic(self):
     """
     Optimize and convert all master ufo to quad curves.
     """
     masters = self.masters.values()
     # use cu2qu to optimize all masters
     fonts_to_quadratic(masters)
     for master in masters:
         master.font.segmentType = "qcurve"
Example #3
0
 def test_both_max_err_and_max_err_em(self, fonts):
     with pytest.raises(TypeError, match="Only one .* can be specified"):
         fonts_to_quadratic(fonts, max_err=1.000, max_err_em=0.001)
Example #4
0
 def test_max_err_list(self, fonts):
     stats = {}
     fonts_to_quadratic(fonts, max_err=[4.096, 4.096], stats=stats)
     assert stats == {'1': 5, '2': 193, '3': 14}
Example #5
0
 def test_max_err_em_list(self, fonts):
     stats = {}
     fonts_to_quadratic(fonts, max_err_em=[0.002, 0.002], stats=stats)
     assert stats == {'1': 5, '2': 193, '3': 14}
Example #6
0
 def test_different_glyphsets(self, fonts):
     del fonts[0]['a']
     assert 'a' not in fonts[0]
     assert 'a' in fonts[1]
     assert fonts_to_quadratic(fonts)
Example #7
0
 def test_no_remember_curve_type(self, fonts):
     assert CURVE_TYPE_LIB_KEY not in fonts[0].lib
     fonts_to_quadratic(fonts, remember_curve_type=False)
     assert CURVE_TYPE_LIB_KEY not in fonts[0].lib
Example #8
0
 def test_remember_curve_type(self, fonts):
     fonts_to_quadratic(fonts, remember_curve_type=True)
     assert fonts[0].lib[CURVE_TYPE_LIB_KEY] == "quadratic"
     with CapturingLogHandler(logger, "INFO") as captor:
         fonts_to_quadratic(fonts, remember_curve_type=True)
     assert captor.assertRegex("already converted")
Example #9
0
 def test_dump_stats(self, fonts):
     with CapturingLogHandler(logger, "INFO") as captor:
         fonts_to_quadratic(fonts, dump_stats=True)
     assert captor.assertRegex("New spline lengths:")
Example #10
0
 def test_stats(self, fonts):
     stats = {}
     fonts_to_quadratic(fonts, stats=stats)
     assert stats == {'1': 1, '2': 79, '3': 130, '4': 2}
Example #11
0
 def test_modified(self, fonts):
     modified = fonts_to_quadratic(fonts)
     assert modified