-
Notifications
You must be signed in to change notification settings - Fork 252
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
Add FPDF.bezier() method exposing PaintedPath.curve_to #1174
Conversation
…d added one test.
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.
Cool new feature, thanks @awmc000!
But as always: We want more! 😁
You seem to have noticed the naming confusion yourself:
The method is called bezier()
, internally it creates a quadratic bezier, while the test file is called cubic_bezier_curve.pdf
It would actually be nice if the method could create both bezier types. After all, as far as I can tell, the only API change would be to allow point lists with three or four elements, which you can then use to select the appropriate drawing method (and check if the user has supplied a valid number of points at the same time).
The other surprise is that your code only seems to allow closed paths.
Unfortunately, a lot of the functionality in the drawing module is not explicitly documented. However, if you look at the function open_path_drawing()
in test/drawing/test_drawing.py, you'll find that you can create open paths with path.style.auto_close = False
.
You could expose that option with a closed=False
parameter (or default it to True, if you prefer).
Thank you for the helpful feedback. I'll sort out the issues you mentioned and extend it to support point lists of 3 or 4 points, closed/open paths, and either type of Bezier curves. |
Thank YOU for taking the time to contribute to @allcontributors please add @awmc000 for code. |
I've put up a pull request to add @awmc000! 🎉 |
Please check the pylint output and fix any issues it brings up. And then I have another wishlist item... |
OK, got it, so I will figure out how to convert a RenderStyle to a PathPaintRule, so that the latter represents the same settings as the former does? And thanks for reminding me about Pylint. |
It looks like the values for RenderStyle and PathPaintRule correspond but just have different names, and that PathPaintRule supports some behaviour RenderStyle doesn't, namely FILL_EVENODD, STROKE_FILL_EVENODD, DONT_PAINT (and AUTO checks PaintedPath.style?).
So it looks what I need to do is select the PathPaintRule enum value |
I tested that and it seems to work for a basic test in the shell. >>> from fpdf import FPDF
>>> pdf = FPDF()
>>> pdf.add_page()
>>> pdf.bezier([(20, 20), (20, 10), (30, 30)], style="FD")
>>> pdf.set_fill_color((200, 5, 5))
>>> pdf.bezier([(20, 120), (20, 110), (30, 130)], style="F")
>>> pdf.bezier([(20, 220), (20, 210), (30, 230)], style="D")
>>> pdf.output("stylescr2.pdf") I get a curve with a fill and stroke, one with just a fill, and one with just the stroke. |
Looks great! There's yet another thing you might want to test, though. Oh, and you should remove any |
…emove generate=True from Bezier tests; clean up point drawing function for bezier tests.
Two last little nitpicks: you need to run black on your code, it blocks the testing pipeline. And I just noticed that you still have a |
Should I be getting a debug_stream from somewhere else? Or just remove it? (Removed for now.) |
Removing it is fine, as long as you do it in the docstring as well... |
Thanks for catching that. |
There's still an unresolved conflict in CHANGELOG.md (even if github doesn't seem to detect it). |
Thanks for this helpful feature addition, @awmc000 ! merging now. |
Hi 🙂 Thank you for this contribution @awmc000 !👍 I have just been testing this new feature today, and I realized that there is minor discrepancy between the code and the docstring:
Currently the actual default behaviour seems to be "F", when no I think we should stick with "D" being the default bejaviour, What do you think @gmischler & @awmc000? |
I used the opportunity of PR #1210 to fix this 🙂 |
Begins implementing #496
Checklist:
The GitHub pipeline is OK (green),
meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.A unit test is covering the code added / modified by this PR
This PR is ready to be merged
In case of a new feature, docstrings have been added, with also some documentation in the
docs/
folderA mention of the change is present in
CHANGELOG.md
I do think this could be added as is, but since it only supports cubic Bezier curves in its current state, maybe others would disagree and say this should support any number of control points? That is my next goal.
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.