Simplify and fix dpi handling in tight_bbox #2621
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Being based on PR #2588, this PR is now able to (again) fix
tight_bbox.adjust_bbox
handling of PGF figures.The problem with that function is its dependence on a figure's dpi, which it naturally takes from the figure instance. This behaviour was implemented in
adjust_bbox_png()
. Whenadjust_bbox()
is called fromFigureCanvas.print_figure()
this dpi value might be incorrect, since backends like svg and pdf use a fixed value of 72dpi and override the figure dpi later when calling theirprint_()
methods. The solution was to predict this setting from the file format and use the 72dpi implementation calledadjust_bbox_pdf()
. This fails because the mapping from file types to backends is ambiguous.I fixed this by moving all per-backend information from
tight_bbox.py
to the backends. The code duplication inadjust_bbox()
is gone. The function instead provides a parameter for setting a custom dpi, which a backend/FigureCanvas announces if necessary.The second commit adds a missing clip rectangle in backend_pgf (reported in #2586) and an appropriate test.