Refactor mechanism for saving files. #2588
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.
I was trying to fix
bbox_inchessupport for backend_pgf (issue #2586). However, I can't do this properly sincetight_bboxneeds to know if a backend uses figure.dpi or fixed 72dpi. Right now it derives this information from the file-type, which doesn't really work since different backends may be used for the same type. To fix this problem I need to know which backend is used when saving files inFigureCanvasBase.print_figure().This required some major changes. I'll break them down to the following steps:
FigureCanvasBaseand thus a lot of code duplication. Movedprint_jpegandprint_tiffto the Agg backend where they are actually implemented.backend_basesand made it the default reference for finding an appropriate FigureCanvas for a given file type. FigureCanvas is now a canonical alias in each backend. Deferred imports of those are now handled centrally inget_registered_canvas_class().register_backend(). This is also reflected in the save dialogues of graphical user interfaces.The
print_figure()method now works in the following way:Most code parts I modified came from @mdboom and @leejjoon, so I humbly ask you for your opinions.