@@ -106,7 +106,10 @@ def __init__(self, dpi):
106
106
107
107
def set_ctx_from_surface (self , surface ):
108
108
self .gc .ctx = cairo .Context (surface )
109
- self .set_width_height (surface .get_width (), surface .get_height ())
109
+ # Although it may appear natural to automatically call
110
+ # `self.set_width_height(surface.get_width(), surface.get_height())`
111
+ # here (instead of having the caller do so separately), this would fail
112
+ # for PDF/PS/SVG surfaces, which have no way to report their extents.
110
113
111
114
def set_width_height (self , width , height ):
112
115
self .width = width
@@ -441,9 +444,9 @@ def print_png(self, fobj, *args, **kwargs):
441
444
width , height = self .get_width_height ()
442
445
443
446
renderer = RendererCairo (self .figure .dpi )
444
- renderer .set_width_height (width , height )
445
447
surface = cairo .ImageSurface (cairo .FORMAT_ARGB32 , width , height )
446
448
renderer .set_ctx_from_surface (surface )
449
+ renderer .set_width_height (width , height )
447
450
448
451
self .figure .draw (renderer )
449
452
surface .write_to_png (fobj )
@@ -500,6 +503,7 @@ def _save(self, fo, fmt, **kwargs):
500
503
# surface.set_dpi() can be used
501
504
renderer = RendererCairo (self .figure .dpi )
502
505
renderer .set_ctx_from_surface (surface )
506
+ renderer .set_width_height (width_in_points , height_in_points )
503
507
ctx = renderer .gc .ctx
504
508
505
509
if orientation == 'landscape' :
0 commit comments