Repository navigation
Fix Cairo backends on HiDPI screens - #21025
Conversation
|
So Cairo doesn't support mixed dpi screen setups? |
| fig.savefig(buf, format='png') | ||
| ratio2 = Image.open(buf) | ||
|
|
||
| assert ratio1.size == ratio2.size |
There was a problem hiding this comment.
I guess even the whole images should be the same?
There was a problem hiding this comment.
True, but they're empty figures, so I didn't bother. I thought of using check_figures_equal, but I don't know how to force a different backend with it.
There was a problem hiding this comment.
You could actually plot something, and do a plain rgba array equality check?
anntzer
left a comment
There was a problem hiding this comment.
I don't have a mixed dpi setup to test, but at least for single-screen simulated highdpi, this does what it says on the tin.
If you mean multiple screens, that's handled at the canvas level. If you mean something like PDF, I'm not sure, but I think the Agg/PDF backends are just as broken. |
|
Yeah I meant screen one is non-retina and screen two is retina, and you drag the window from one to the other. |
|
Yes, that depends on the backend supporting it, but e.g., QtCairo does support that. |
dstansby
left a comment
There was a problem hiding this comment.
Checked locally and confirmed that the fix works
Unlike the Agg renderer, the Cairo renderer exists forever and is at the DPI when the figure was created. This needs to be updated before drawing or things in physical sizes (e.g., text or line widths) will be the wrong size.
Otherwise, `FigureCanvasBase.get_width_height` returns a size scaled down by the current pixel ratio, even though the DPI is not scaled up. This causes the saved figure to be cropped.
db759fd to
9598205
Compare
…025-on-v3.5.x Backport PR #21025 on branch v3.5.x (Fix Cairo backends on HiDPI screens)
PR Summary
Since Cairo renderers exist forever, we need to ensure they are using the correct DPI, or else physical sizes are incorrect.
Fixes #21024.
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).