-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fill hatch in PDF backend #29392
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
base: main
Are you sure you want to change the base?
Fill hatch in PDF backend #29392
Conversation
Yeah, there is something strange going on, see, e.g., #24263 which has a similar problem. For the PR, I think it makes sense, but wouldn't it be possible to conditionally execute the added line based on which hatch is created? Or am I missing the point of the for-loop? |
I think this isn't possible, because of certain cases where the |
6000941
to
c42ea46
Compare
c42ea46
to
c54d7a5
Compare
Looks like the baseline images were changed in #29908, so this is no longer the case. The linewidth has been set to 1 since #28048, so you shouldn't see this difference any longer. The reason that linewidths of 0 and 1 look similar when compared is probably because we do the rasterising without antialiasing (something like the |
This causes various line-based hatches to look thicker, depending a little on the renderer used. The hatches have always been rendered in PDF with a fill+stroke operation, but now that there is a fill color in all hatches, the lines get "filled" which adds some pixels. Would this cause hatch patterns |
It doesn't! The circle paths are drawn forward and backward when the circles are not meant to be filled, presumably for this exact reason. That leaves the "filled" lines which get extra pixels. This is only a problem at low resolution and don't seem to be an issue when viewing with a PDF viewer, so perhaps not worth fixing. The fix would likely involve changing hatch.py to return multiple paths along with "stroke" and "stroke+fill" data, instead of the current single noncontiguous path that gets stroked and filled. |
If we add antialiasing and increase the resolution, only |
c54d7a5
to
9ef3128
Compare
PR summary
closes #10034
Summary
Adresses an issue specific to the pdf backend, where hatches such as stars and circles were not filled, which is unlike the other backends such as Agg or svg.
Proposed Fix
Although
Op.fill_stroke
is used for the hatch path (which should make the hatch path filled) the non-stroking color is not equal to the hatch_color (which previously, was only applied as the stroking color)This PR fixes this by setting the non-stroking color as the hatch_color.
Changes to Baseline PDFs
I have updated the baseline PDFs for the tests that are failing, although I am not sure what exactly is causing the tests other than
test_artist.py::test_clipping[pdf]
to fail. The expected and generated PDFs are identical, but the corresponding PNGs are not. It looks like the lines are thicker in the corresponding PNGs.Additional Info
Essentially the fix should apply to only hatches that need filling (like stars and circles) which would result in changing only one baseline PDF, i.e.
test_artist.py::test_clipping[pdf]
.We unfortunately cannot do this, because path for drawing all the hatches are generated in advance and we need to draw all of them together.
As for the other tests, Filling lines may seem like there should be no difference, but the PDF backend does some shady stuff by thickening them in the corresponding PNG. This needs to be investigated upon.
test_artist.py::test_clipping
test_legend.py::test_hatching
PDFtest_legend.py::test_hatching
Corresponding PNGDiff for the last row:
PR checklist