-
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
Text regions layout management #897
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #897 +/- ##
==========================================
+ Coverage 93.42% 93.56% +0.14%
==========================================
Files 27 28 +1
Lines 7851 8209 +358
Branches 1433 1500 +67
==========================================
+ Hits 7335 7681 +346
- Misses 322 326 +4
- Partials 194 202 +8
☔ View full report in Codecov by Sentry. |
This seems very promising! 😊 |
I think that for text regions to become a successfull addition to Hence, maybe "plugging" text regions in tables would be a good way to check that the design you crafted for text regions is sound, and integrates well with the existing lib? |
I think you made an excellent work overall to design this feature |
Only the table cells will need to be converted to text regions, the rest of the table classes can largely remain the same. In that context: All the legacy text generation methods use the parameter spelling "txt", only table cells currently use "text". |
Yes, this was reported recently in #853 |
Why?!?
I'm not very good with decorators. Can you come up with one that does the conversion if necessary, and prevents the use of both together? Then we don't have to clutter the functional code with this weirdness. |
I guess I would be something like this: def deprecated_txt(func):
def inner(*args, **kwargs):
override_kwargs = {}
for k in kwargs:
if k == "txt":
LOGGER.warning("The argument 'txt' has been deprecated. Please use 'text'.")
override_kwargs["text"] = kwargs[k]
continue
override_kwargs[k] = kwargs[k]
return func(*args, **override_kwargs)
return inner |
Sorry, I meant NOT deliberate 😅
I opened #903 to do that, could you please review it? |
3bb29d4
to
ac4335c
Compare
7c7f77e
to
184c809
Compare
Progress report: I refactored html.py to use Among other things, this change allows formatting changes within paragraphs without any extra line breaks, fixing #151, #640, and #930 (and improving on #91). The other visible change is that the spacing between paragraphs, as well as above and below headings, is slightly different. I had worried about this for a while, but got it surprisingly close in the end. I actually think it is mor more consistent in relation to font size now. The extra empty line at the top of many pages has also gone. When consolidating with the recent padding changes, I stumbled over some incongruencies. Some of the general changes I had to make to enable this was that text color and the total line width are now always taken from the Fragments. The different handling of text color results in a (semantically inconsequential) different sequence of commands in the PDF, making it necessary to replace many test files. MultiLineBreak now also receives a set of clearance margins, so it can apply them without affecting the maximum_width returned with the TextLine. |
Time for a little poll: |
Ready for real life? With the HTML milestone reached, I think this would be a good time to merge the current state (after 2.7.6 is released). Since I had to make significant changes to quite a few other parts of the code base, that would also reduce potential conflicts with upcoming changes and fixes by others in those areas. The next milestone will be to turn table cells into text regions. In preparation for that, I'll have to come up with a good way to add images. I think the simplest way is to just treat them like a type of paragraph. With a little luck, that may get finished before releasing 2.7.7 as well. Shaped text regions will have to wait until after that. |
a1cebdc
to
42efea2
Compare
Thank you for the progress report @gmischler!
I agree with you, and I don't really see the point of having both methods, we should probably only keep
Agreed! Reviewing 100 file changes is bit intimidating 😅 |
Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com>
Ok, I am happy (and a bit exhausted...) |
Good job @gmischler! |
This is the basic start of advanced text layout functionality for fpdf2, as outlined in #339.
Checklist:
meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.docs/
folderCHANGELOG.md
Some ripples caused in the rest of the code base:
_render_styled_text_line()
has lost its "align" parameter._preload_font_styles()
will need to accept a "link" argument (it probably needs a different name too, since it does a lot more then loading fonts).MultiLineBreak()
now has a "width" parameter, which can either be a fixed width or a callback function, so that the caller can dynamically specify the text width depending on (among other things) the current line height. Consequently,get_line_of_current_width()
has morphed into simplyget_line()
.General remarks:
Further tasks:
UpdateDone, except for tables.write_html()
to use text regions, in order to allow for smoother formatting.Use the "text" parameter of table cells for all text regions.Done.By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.