-
Notifications
You must be signed in to change notification settings - Fork 253
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
Switch SVG path parsing to fonttools #545
Conversation
Codecov ReportBase: 94.12% // Head: 93.94% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #545 +/- ##
==========================================
- Coverage 94.12% 93.94% -0.18%
==========================================
Files 22 22
Lines 6225 5999 -226
Branches 1271 1213 -58
==========================================
- Hits 5859 5636 -223
+ Misses 191 189 -2
+ Partials 175 174 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
Nice code shrinking here, thank you @gmischler!
By the way, don't hesitate to ping me by email whenever you want to get the role of a maintainer on this project, I still think fpdf2
would benefit from it and you clearly deserve it
|
To me, this looks ready to be merged 😊 |
5a670f0
to
56218b6
Compare
56218b6
to
75a6e13
Compare
e.g. Fixes #525
Checklist:
meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.docs/
folderCHANGELOG.md
The nice part is that the new parser resolves everything to absolute coordinates, and it does so in a very simple and elegant way. For us this means that many class definitions dealing with relative movements have become redundant. After removing them, sgv.py is now significantly shorter.
At first, I couldn't get the "exponentated numbers" to parse correctly. Then I found that my copy of fonttools was slightly outdated, and they had just recently fixed a bug quite similar to our own #376. I have now pinned fonttools to the current release 4.37.2 or newer as well to make sure we have this fix available.
Previously, the "comma seperation" test converted "M0,1l2,3" into
[M(0, 1), L2, 3)]
. I don't think this was correct, since a relative line_to should end up at absolute (2,4). I didn't analyze if this was our own bug or one in "svg.path", but now it's gone anyway.When a path gets closed with "Z/z", the fonttools parser adds an explicit extra "L" back to the start point. They may need this internally, but it has no purpose for us. I had to add methods to
drawing._graphics_context()
anddrawing.PaintedPath()
for removing the last element of a path again to eliminate this.I had to replace a few of the reference PDFs. They all looked identical visually, but the new ones were consistently a bit smaller.
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.