Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clip_to_viewbox parsing error #274

Open
yisibl opened this issue Aug 1, 2022 · 5 comments
Open

clip_to_viewbox parsing error #274

yisibl opened this issue Aug 1, 2022 · 5 comments

Comments

@yisibl
Copy link
Contributor

yisibl commented Aug 1, 2022

picosvg --clip_to_viewbox test.svg

Traceback (most recent call last):
  File "/Users/yisi/works/picosvg/venv/bin/picosvg", line 33, in <module>
    sys.exit(load_entry_point('picosvg', 'console_scripts', 'picosvg')())
  File "/Users/yisi/works/picosvg/src/picosvg/picosvg.py", line 61, in main
    app.run(_run, argv=argv)
  File "/Users/yisi/works/picosvg/venv/lib/python3.9/site-packages/absl/app.py", line 308, in run
    _run_main(main, args)
  File "/Users/yisi/works/picosvg/venv/lib/python3.9/site-packages/absl/app.py", line 254, in _run_main
    sys.exit(main(argv))
  File "/Users/yisi/works/picosvg/src/picosvg/picosvg.py", line 48, in _run
    svg.clip_to_viewbox(inplace=True)
  File "/Users/yisi/works/picosvg/src/picosvg/svg.py", line 868, in clip_to_viewbox
    intersection(
  File "/Users/yisi/works/picosvg/src/picosvg/svg_types.py", line 1004, in intersection
    return svg_pathops.intersection([s.as_cmd_seq() for s in shapes], fill_rules)
  File "/Users/yisi/works/picosvg/src/picosvg/svg_pathops.py", line 129, in intersection
    return _do_pathop(pathops.PathOp.INTERSECTION, svg_cmd_seqs, fill_rules)
  File "/Users/yisi/works/picosvg/src/picosvg/svg_pathops.py", line 114, in _do_pathop
    sk_path = pathops.op(sk_path, sk_path2, op, fix_winding=True)
  File "src/python/pathops/_pathops.pyx", line 1455, in pathops._pathops.op
  File "src/python/pathops/_pathops.pyx", line 1468, in pathops._pathops.op
pathops._pathops.PathOpsError: operation did not succeed
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <path d="M379.593697 791.645091h-151.893333a80.570182 80.570182 0 0 0 75.946666 54.194424c34.148848 0 64.589576-21.721212 75.946667-54.194424zM303.64703 899.878788c-63.767273 0-118.75297-45.242182-131.537454-108.233697H119.404606c-32.721455 0-57.344-29.168485-57.344-63.146667v-192.387879c0-17.795879 6.795636-35.002182 19.037091-47.057454l162.288485-160.054303a82.276848 82.276848 0 0 1 57.793939-24.467394h47.197091v-38.353455c0-77.467152 53.589333-142.056727 122.30594-142.056727h382.882909c73.309091 0 121.157818 59.345455 121.157818 136.905697V764.586667c0 14.941091-12.024242 27.058424-26.841212 27.058424h-11.636364C923.461818 854.636606 868.491636 899.878788 804.708848 899.878788c-63.767273 0-118.75297-45.242182-131.521939-108.233697h-238.002424C422.384485 854.636606 367.414303 899.878788 303.631515 899.878788z m44.730182-541.230546h-47.197091a28.951273 28.951273 0 0 0-20.262788 9.029819L118.613333 527.732364a12.148364 12.148364 0 0 0-2.901333 8.378181v192.387879c0 5.849212 2.684121 9.014303 3.646061 9.014303h229.003636a11565444957.509817 11565444957.509817 0 0 1 0.015515-378.864485z m380.38497 432.996849a80.570182 80.570182 0 0 0 75.946666 54.194424c34.148848 0 64.589576-21.721212 75.946667-54.194424h-151.893333z m192.263757-54.132364V271.32897a93.090909 93.090909 0 0 0-93.090909-93.090909H470.667636c-36.708848 0-68.592485 38.43103-68.592484 87.970909v471.303757H921.025939z"></path>
</svg>
@anthrotype
Copy link
Member

Thanks for the issue report. skia-pathops (python bindings to Skia PathOps module) is used to do boolean path intersection to clip shapes to the viewbox rectangle. Sometimes PathOps reports an error as in this case, unfortunately it doesn't tell us what exactly was wrong.. It's currently a bit of a black box for us.
We have had similar issues (e.g. fonttools/fonttools#2363) which we have reported upstream (see https://bugs.chromium.org/p/skia/issues/detail?id=11958).
Maybe this is another example of the same issue, or a new one altogether.

This is how your SVG looks like, looks quite plain to me (I don't see how pathops would fail on it):

clip-to-viewbox-test

We could try to reproduce the error by only using Skia C++ API and write an interactive "fiddle" like this https://fiddle.skia.org/c/897a5a7d11e721faac930f67d7598557

and then send a bug to upstream skia and hope it'll get fixed.

@anthrotype
Copy link
Member

anthrotype commented Aug 26, 2022

@yisibl I get the same PathOpsError: operation did not succeed if I try to run picosvg --clip_to_viewbox using the latest Skia that includes the bug fix from https://bugs.chromium.org/p/skia/issues/detail?id=11958#c16

@yisibl
Copy link
Contributor Author

yisibl commented Aug 26, 2022

Sad, let's continue to wait for the improvement upstream.

@yisibl
Copy link
Contributor Author

yisibl commented Aug 26, 2022

I imported this SVG into Glyphs 3 and it does have a strange anchor segment at the top.

image

Exporting the ttf font from Glyphs shows up in Chrome as follows:

image

Adobe Illustrator automatically corrects the top anchor point:

image

@anthrotype
Copy link
Member

hm, that's maybe what is tripping pathops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants