matplotlib/matplotlib — pull request #2621 by pwuertz (2013-11-28 12:03:17+00:00)
Title: Simplify and fix dpi handling in tight_bbox

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()`. When `adjust_bbox()` is called from `FigureCanvas.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 their `print_()` methods. The solution was to predict this setting from the file format and use the 72dpi implementation called `adjust_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 in `adjust_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.