Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Fix the misplacement of rasterized object inDrawingArea
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 ourterms of service andprivacy 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?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -42,6 +42,20 @@ | ||
DEBUG = False | ||
def _is_vector_renderer(renderer): | ||
# 1. Check the renderer name | ||
vector_bases = {'RendererPdf', 'RendererSVG', 'RendererPS'} | ||
# If it's MixedModeRenderer, get the actual renderer recursively | ||
actual_renderer = renderer | ||
while type(actual_renderer).__name__ == 'MixedModeRenderer': | ||
actual_renderer = getattr(actual_renderer, '_renderer', actual_renderer) | ||
renderer_name = type(actual_renderer).__name__ | ||
Comment on lines +50 to +52 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This approach feels quite hacky. The functionality should live in a method | ||
if renderer_name in vector_bases: | ||
return True | ||
# 3. For unknown renderers, assume they are not vector | ||
return False | ||
def _compat_get_offset(meth): | ||
""" | ||
Decorator for the get_offset method of OffsetBox and subclasses, that | ||
@@ -689,18 +703,33 @@ | ||
self.dpi_transform.clear() | ||
self.dpi_transform.scale(dpi_cor) | ||
tpath = mtransforms.TransformedPath( | ||
mpath.Path([[0, 0], [0, self.height], | ||
[self.width, self.height], | ||
[self.width, 0]]), | ||
self.get_transform()) | ||
for c in self._children: | ||
is_rasterized = getattr(c, 'get_rasterized', lambda: False)() | ||
if is_rasterized and _is_vector_renderer(renderer): | ||
# PDF/SVG backend uses 72 dpi in display units, | ||
# so we need to scale the rasterized content accordingly | ||
target_dpi = getattr(renderer, 'dpi', 72) or 72 | ||
dpi_correction = target_dpi / 72 | ||
# New transform to apply the dpi correction | ||
corrected_transform = self.get_transform() \ | ||
+ mtransforms.Affine2D().scale(dpi_correction) | ||
orig_transform = c.get_transform() \ | ||
if hasattr(c, 'get_transform') else None | ||
c.set_transform(corrected_transform) | ||
if self._clip_children and not (c.clipbox or c._clippath): | ||
c.set_clip_path(tpath) | ||
c.draw(renderer) | ||
if orig_transform is not None: | ||
c.set_transform(orig_transform) | ||
else: | ||
if self._clip_children and not (c.clipbox or c._clippath): | ||
c.set_clip_path(tpath) | ||
c.draw(renderer) | ||
_bbox_artist(self, renderer, fill=False, props=dict(pad=0.)) | ||
self.stale = False | ||
Uh oh!
There was an error while loading.Please reload this page.