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

Restructure processing of clip, transform, and group #223

Merged
merged 5 commits into from
Jun 30, 2021
Merged

Conversation

rsheeter
Copy link
Collaborator

@rsheeter rsheeter commented May 20, 2021

Try to correctly handle a somewhat wider range of scenarios. Causes groups to be retained when opacity cannot simply be pushed down. Generate transformed gradients somewhat more correctly.

Do not submit until nanoemoji is ready to handle groups.

Fixes #78. Fixes #200. Fixes #110.

@rsheeter rsheeter force-pushed the ungroup branch 5 times, most recently from 00e1dd1 to d2eabf3 Compare May 20, 2021 06:31
@rsheeter rsheeter force-pushed the ungroup branch 4 times, most recently from 1b3c035 to b217ca2 Compare May 20, 2021 23:06
@rsheeter rsheeter marked this pull request as ready for review May 20, 2021 23:07
@rsheeter rsheeter requested a review from anthrotype May 20, 2021 23:07
@rsheeter rsheeter force-pushed the ungroup branch 2 times, most recently from 578c26e to a32f943 Compare May 22, 2021 20:33
Copy link
Member

@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice! I only started reviewing this, but I can already tell it's improving things a lot. E.g. the examples in #110 both work with this patch

src/picosvg/svg.py Outdated Show resolved Hide resolved
src/picosvg/svg.py Outdated Show resolved Hide resolved
src/picosvg/svg.py Outdated Show resolved Hide resolved
tests/transform-linear-before.svg Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@rsheeter rsheeter force-pushed the ungroup branch 2 times, most recently from 7523b03 to 69f069d Compare May 25, 2021 04:22
@rsheeter
Copy link
Collaborator Author

the examples in #110 both work with this patch

Ty, added a unit test to prove it and marked PR as fixing #110

@rsheeter rsheeter force-pushed the ungroup branch 2 times, most recently from 93e94ef to 3c8a1bc Compare May 25, 2021 05:48
@rsheeter
Copy link
Collaborator Author

For now I have commented out objectBoundingBox tests. I do think we should support them.

src/picosvg/svg.py Show resolved Hide resolved
src/picosvg/svg.py Show resolved Hide resolved
src/picosvg/svg.py Outdated Show resolved Hide resolved
@rsheeter rsheeter force-pushed the ungroup branch 3 times, most recently from 2601ae5 to 0f6fa0f Compare May 25, 2021 21:09
Copy link
Member

@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, in one go it fixes three of the last big outstanding issues in picosvg! 👏

Left some minor comments below

src/picosvg/svg.py Outdated Show resolved Hide resolved
paths = list(self._stroke(paths[0]))

if context.transform != Affine2D.identity():
paths = [p.apply_transform(context.transform) for p in paths]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're applying the transforms on the paths and then you are intersecting them with the similarly transformed clip-paths. It might be simpler (and will produce the same result) if instead you intersect the untransformed clip-paths with the untransformed paths, and then transform the result of the intersection.

src/picosvg/svg.py Outdated Show resolved Hide resolved
src/picosvg/svg.py Outdated Show resolved Hide resolved
src/picosvg/svg.py Outdated Show resolved Hide resolved
keep_group = len(el) > 1 and opacity > 0.0 and opacity < 1.0

if keep_group:
el.attrib.clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear() can be dangerous, we might have forgotten something, how about you just assert that the only attribute left on <g> is opacity?

does perhaps _inherit_attrib already do the all checking for us?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't actually clear them off but as opacity being the only acceptable group attribute in picosvg output I think clear is right?

src/picosvg/svg.py Show resolved Hide resolved
src/picosvg/svg.py Show resolved Hide resolved
@google-cla
Copy link

google-cla bot commented Jun 1, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@anthrotype
Copy link
Member

@googlebot I consent.

@anthrotype
Copy link
Member

anthrotype commented Jun 1, 2021

Hm.. looks like dataclasses backport for Python 3.6 does not like when attributes are NamedTuples (like Affine2D) and one uses dataclasses.asdict() on them:

ericvsmith/dataclasses#141
ericvsmith/dataclasses#158

see CI failure here: https:/googlefonts/picosvg/pull/223/checks?check_run_id=2720877391

how about we kill python 3.6 support? :)

@anthrotype
Copy link
Member

(the reason I didn't catch this problem in #230 is because the base branch there was not main and CI is configured to only run tests on main or on PRs that merge into main)

in this case, calling asdict was not actually needed.
By replacing that with a simple getattr() we fix error with python3.6.
Hopefully the dataclasses backport will one day fix the bug
#223 (comment)
@rsheeter
Copy link
Collaborator Author

how about we kill python 3.6 support? :)

+1

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