xref: /aosp_15_r20/external/fonttools/Tests/ttLib/removeOverlaps_test.py (revision e1fe3e4ad2793916b15cccdc4a7da52a7e1dd0e9)
1*e1fe3e4aSElliott Hughesimport logging
2*e1fe3e4aSElliott Hughesimport pytest
3*e1fe3e4aSElliott Hughes
4*e1fe3e4aSElliott Hughespathops = pytest.importorskip("pathops")
5*e1fe3e4aSElliott Hughes
6*e1fe3e4aSElliott Hughesfrom fontTools.ttLib.removeOverlaps import _simplify, _round_path
7*e1fe3e4aSElliott Hughes
8*e1fe3e4aSElliott Hughes
9*e1fe3e4aSElliott Hughesdef test_pathops_simplify_bug_workaround(caplog):
10*e1fe3e4aSElliott Hughes    # Paths extracted from Noto Sans Ethiopic instance that fails skia-pathops
11*e1fe3e4aSElliott Hughes    # https://github.com/google/fonts/issues/3365
12*e1fe3e4aSElliott Hughes    # https://bugs.chromium.org/p/skia/issues/detail?id=11958
13*e1fe3e4aSElliott Hughes    path = pathops.Path()
14*e1fe3e4aSElliott Hughes    path.moveTo(550.461, 0)
15*e1fe3e4aSElliott Hughes    path.lineTo(550.461, 366.308)
16*e1fe3e4aSElliott Hughes    path.lineTo(713.229, 366.308)
17*e1fe3e4aSElliott Hughes    path.lineTo(713.229, 0)
18*e1fe3e4aSElliott Hughes    path.close()
19*e1fe3e4aSElliott Hughes    path.moveTo(574.46, 0)
20*e1fe3e4aSElliott Hughes    path.lineTo(574.46, 276.231)
21*e1fe3e4aSElliott Hughes    path.lineTo(737.768, 276.231)
22*e1fe3e4aSElliott Hughes    path.quadTo(820.075, 276.231, 859.806, 242.654)
23*e1fe3e4aSElliott Hughes    path.quadTo(899.537, 209.077, 899.537, 144.154)
24*e1fe3e4aSElliott Hughes    path.quadTo(899.537, 79, 853.46, 39.5)
25*e1fe3e4aSElliott Hughes    path.quadTo(807.383, 0, 712.383, 0)
26*e1fe3e4aSElliott Hughes    path.close()
27*e1fe3e4aSElliott Hughes
28*e1fe3e4aSElliott Hughes    # check that it fails without workaround
29*e1fe3e4aSElliott Hughes    with pytest.raises(pathops.PathOpsError):
30*e1fe3e4aSElliott Hughes        pathops.simplify(path)
31*e1fe3e4aSElliott Hughes
32*e1fe3e4aSElliott Hughes    # check our workaround works (but with a warning)
33*e1fe3e4aSElliott Hughes    with caplog.at_level(logging.DEBUG, logger="fontTools.ttLib.removeOverlaps"):
34*e1fe3e4aSElliott Hughes        result = _simplify(path, debugGlyphName="a")
35*e1fe3e4aSElliott Hughes
36*e1fe3e4aSElliott Hughes    assert "skia-pathops failed to simplify 'a' with float coordinates" in caplog.text
37*e1fe3e4aSElliott Hughes
38*e1fe3e4aSElliott Hughes    expected = pathops.Path()
39*e1fe3e4aSElliott Hughes    expected.moveTo(550, 0)
40*e1fe3e4aSElliott Hughes    expected.lineTo(550, 366)
41*e1fe3e4aSElliott Hughes    expected.lineTo(713, 366)
42*e1fe3e4aSElliott Hughes    expected.lineTo(713, 276)
43*e1fe3e4aSElliott Hughes    expected.lineTo(738, 276)
44*e1fe3e4aSElliott Hughes    expected.quadTo(820, 276, 860, 243)
45*e1fe3e4aSElliott Hughes    expected.quadTo(900, 209, 900, 144)
46*e1fe3e4aSElliott Hughes    expected.quadTo(900, 79, 853, 40)
47*e1fe3e4aSElliott Hughes    expected.quadTo(807.242, 0.211, 713, 0.001)
48*e1fe3e4aSElliott Hughes    expected.lineTo(713, 0)
49*e1fe3e4aSElliott Hughes    expected.close()
50*e1fe3e4aSElliott Hughes
51*e1fe3e4aSElliott Hughes    assert expected == _round_path(result, round=lambda v: round(v, 3))
52