forked from reingart/pyfpdf
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Refactor: Move more text processing to line_break.py & char_spacing #511
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## master #511 +/- ##
==========================================
+ Coverage 92.12% 92.23% +0.11%
==========================================
Files 23 23
Lines 6793 6855 +62
Branches 1402 1410 +8
==========================================
+ Hits 6258 6323 +65
+ Misses 304 303 -1
+ Partials 231 229 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
RedShy
reviewed
Aug 27, 2022
Lucas-C
reviewed
Sep 2, 2022
Merged! |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist:
meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.docs/
folderCHANGELOG.md
I Instrumented
Fragment()
with more font and style information. The most effective way to do this turned out to attach a (shallow) copy of the current graphics context. This may currently look a bit redundant, but it will help implement flexible text flow regions later. It already simplifies the handling of markdown text a bit.I also added the current value of
self.k
, While this is unlikely to change within a document, it is still needed for various conversions, so having it included with the fragment makes things a lot simpler.Moved all text width calculations to
Fragment()
. With the help of the added font/style info it now automatically returns the stretched and char_spaced width, so thatfpdf.py
doesn't need to worry about that anymore.Changed the API of
MultiLineBreak()
to receive and return document units instead of glyph space units. This eliminates a lot of conversions infpdf.py
. We now only need to deal with glyph space units there when we actually have to write them to the output file.Everything in
test_line_break.py
had to get adapted to that API change.Other than that, all tests are running through as before. Two PDFs needed updating, because the different sequence of unit conversions caused tiny differences in rounding (moving some text by an invisible amount).
Fixes #489
Since it has now become simpler to do, I implemented
.set_char_spacing()
as of #489. It follows the pattern ofset_stretching()
, just with an absolute value in Pica as the argument._render_styled_text_line()
will eventually need some more refactoring. Flowing text regions will want to justify text with varying fonts and varying stretching and char spacing on the same line. This means that we'll first have to loop through the fragments and do the unicode check further in. But that's a task for another PR...By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.