From e3349ae6431ee133587410a4f9b2f0191ed63fdc Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 7 Nov 2024 10:30:39 +0100 Subject: [PATCH] Re-fix renderers outliving underlying streams. e.g. `figure(layout="constrained"); imshow([[0, 1]], rasterized=True); savefig("/tmp/test.pdf")` --- src/mplcairo/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mplcairo/base.py b/src/mplcairo/base.py index 60d9f45c..b5fe7685 100644 --- a/src/mplcairo/base.py +++ b/src/mplcairo/base.py @@ -286,7 +286,8 @@ def _print_vector(self, renderer_factory, self.figure.draw(renderer) except Exception as exc: draw_raises_done = type(exc).__name__ == "Done" - raise + if not draw_raises_done: # Else, will be re-raised below. + raise finally: # _finish() corresponds finalize() in Matplotlib's PDF and SVG # backends; it is inlined in Matplotlib's PS backend. It must @@ -302,7 +303,7 @@ def _print_vector(self, renderer_factory, if draw_raises_done: renderer = renderer_factory(None, *self.figure.bbox.size, dpi) with _LOCK: - self.figure.draw(renderer) + self.figure.draw(renderer) # Should raise Done(). print_pdf = partialmethod( _print_vector, GraphicsContextRendererCairo._for_pdf_output)