Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix the misplacement of rasterized object in DrawingArea in the vectorized backends #30171

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Mr-Milk
Copy link
Contributor

@Mr-Milk Mr-Milk commented Jun 13, 2025

PR summary

This PR is trying to fix a bug when rendering rasterized Artists in DrawingArea, they will be misplaced in the vectorized backend. closes #28549

The fix is done by enforcing correct DPI transformation during rasterization, specifically in the vectorized backends

There is no API change or documentation change associated with this PR.

PR checklist

@Mr-Milk Mr-Milk changed the title Enhance the renderer support of the DrawingArea class by adding DPI correction for rasterized content Fix the misplacement of rasterized object in DrawingArea in the vectorized backends Jun 13, 2025
@Mr-Milk Mr-Milk marked this pull request as ready for review June 13, 2025 12:40
@Mr-Milk
Copy link
Contributor Author

Mr-Milk commented Jun 17, 2025

Hi all, just a gentle follow-up on this PR. I'd appreciate any feedback when time permits. Let me know if there's anything I can improve or clarify. Thanks!

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, review capacity is currently quite limited.

Do you have an idea how to test this?

@Mr-Milk
Copy link
Contributor Author

Mr-Milk commented Jun 18, 2025

Thanks for the feedback! I think we can test this using image comparison—by generating a target image and validating output against it.

On a related note, I'm not entirely confident that my current method for checking whether the renderer is a vectorized backend is the most robust or appropriate approach. I'd really appreciate any input or suggestions on improving that part of the implementation.

Comment on lines +50 to +52
while type(actual_renderer).__name__ == 'MixedModeRenderer':
actual_renderer = getattr(actual_renderer, '_renderer', actual_renderer)
renderer_name = type(actual_renderer).__name__
Copy link
Member

@timhoffm timhoffm Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach feels quite hacky. The functionality should live in a method MxedModeRenderer.is_vector_renderer(). Possibly that function should be made a core feature Renderer so that the whole _is_vector_renderer can go away. Though I'm not sure whether there are implications for third party renders. @anntzer what do you as a backend implementer think?

@anntzer
Copy link
Contributor

anntzer commented Jun 18, 2025

I suspect whether the backend has vector output is not actually the right test here; indeed, mplcairo doesn't exhibit the #28549 bug even for vector output. Rather, the bug likely resides either in backend_{pdf,ps,svg}, or, more likely (just my guess), in MixedModeRenderer.
Therefore, I think I'd prefer if we could figure out what's wrong in MixedModeRenderer (if anything) and directly fix it there, or, if not, at least just directly test whether the renderer is a MixedModeRenderer (_is_mixedmode_renderer) and run the extra code in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Rasterized Artists in DrawingArea will be misplaced in the vectorized backend
3 participants