Skip to content

Commit

Permalink
Re-fix renderers outliving underlying streams.
Browse files Browse the repository at this point in the history
e.g. `figure(layout="constrained"); imshow([[0, 1]], rasterized=True); savefig("/tmp/test.pdf")`
  • Loading branch information
anntzer committed Nov 7, 2024
1 parent 925e068 commit e3349ae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/mplcairo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e3349ae

Please sign in to comment.