@@ -127,6 +127,7 @@ def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2):
127127
128128
129129 def draw_image (self , x , y , im , origin , bbox ):
130+ # bbox - not currently used
130131 if _debug : print '%s.%s()' % (self .__class__ .__name__ , _fn_name ())
131132
132133 if numx .which [0 ] == "numarray" :
@@ -139,10 +140,8 @@ def draw_image(self, x, y, im, origin, bbox):
139140 "draw_image()" )
140141 return
141142
142- # bbox - not currently used
143- flipud = origin == 'lower' # not currently used
144-
145- #rows, cols, s = im.as_str(flipud) # gtk method, for RGBA
143+ #flipud = origin=='lower' # gtk method (uses RGBA)
144+ #rows, cols, s = im.as_str(flipud)
146145 rows , cols , buf = im .buffer_argb32 () # ARGB32, but colors still wrong
147146 X = numx .fromstring (buf , numx .UInt8 )
148147 X .shape = rows , cols , 4
@@ -151,6 +150,7 @@ def draw_image(self, x, y, im, origin, bbox):
151150 ctx = cairo .Context (self .surface )
152151 surface = cairo .ImageSurface .create_for_array (X )
153152 ctx .set_source_surface (surface , x , y )
153+ ctx .paint ()
154154
155155
156156 def draw_line (self , gc , x1 , y1 , x2 , y2 ):
@@ -316,7 +316,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
316316 return
317317
318318 if not HAVE_CAIRO_NUMPY :
319- warnings .warn ("cairo.numpy module required for _draw_mathtext()" )
319+ warnings .warn ("cairo with Numeric support is required for "
320+ "_draw_mathtext()" )
320321 return
321322
322323 size = prop .get_size_in_points ()
@@ -354,10 +355,10 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
354355 pa [:,:,3 ] = Xs
355356
356357 # works for numpy pa, not a numarray pa
357- surface = cairo .numpy . surface_create_for_array (pa )
358- gc .ctx .translate ( x , y )
359- gc .ctx .show_surface ( surface , imw , imh )
360- # should really restore state before translate?
358+ surface = cairo .ImageSurface . create_for_array (pa )
359+ gc .ctx .set_source_surface ( surface , x , y )
360+ gc .ctx .paint ( )
361+ #gc.ctx.show_surface (surface, imw, imh)
361362
362363
363364 def flipy (self ):
@@ -523,7 +524,8 @@ def new_figure_manager(num, *args, **kwargs): # called by backends/__init__.py
523524
524525def print_figure_fn (figure , filename , dpi = 150 , facecolor = 'w' , edgecolor = 'w' ,
525526 orientation = 'portrait' ):
526- if _debug : print '%s.%s()' % (self .__class__ .__name__ , _fn_name ())
527+ #if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
528+ if _debug : print _fn_name ()
527529
528530 # settings for printing
529531 figure .dpi .set (dpi )
@@ -550,8 +552,9 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
550552
551553 #if ext == 'png': _save_png (figure, fileObject)
552554 if ext == 'png' : _save_png (figure , filename )
553- else : _save_ps_pdf (figure , fileObject , ext ,
554- orientation )
555+ #else: _save_ps_pdf (figure, fileObject, ext,
556+ # orientation)
557+ else : _save_ps_pdf (figure , filename , ext , orientation )
555558 #fileObject.close()
556559
557560 elif ext in ('eps' , 'svg' ): # backend_svg/ps
@@ -567,41 +570,41 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
567570 (ext , ', ' .join (IMAGE_FORMAT )))
568571
569572
570- def _save_png (figure , fileObject ):
573+ def _save_png (figure , filename ):
571574 width , height = figure .get_width_height ()
572575 width , height = int (width ), int (height )
573576
574577 surface = cairo .ImageSurface (cairo .FORMAT_ARGB32 , width , height )
575- ctx = cairo .Context (surface )
578+ ctx = cairo .Context (surface )
576579
577580 renderer = RendererCairo (figure .dpi )
578- renderer ._set_width_height (width , height )
581+ renderer ._set_width_height (width , height )
579582 renderer .surface = ctx .get_target ()
580- figure .draw (renderer )
581- surface .write_to_png ( fileObject )
583+ figure .draw (renderer )
584+ surface .write_to_png ( filename )
582585
583586
584- def _save_ps_pdf (figure , fileObject , ext , orientation ):
587+ def _save_ps_pdf (figure , filename , ext , orientation ):
585588 # Cairo produces PostScript Level 3
586589 # 'ggv' can't read cairo ps files, but 'gv' can
587590
588- ppi = 200.0
591+ ppi = 200.0 # not currently used
589592 #figure.dpi.set(72)
590593 figure .dpi .set (96 ) # Cairo uses 96 dpi
591594
592595 w_in , h_in = figure .get_size_inches ()
593596 width , height = figure .get_width_height ()
594597
595- ctx = cairo .Context ()
596-
597598 if orientation == 'landscape' :
598599 w_in , h_in = h_in , w_in
600+ # TODO - change width, height
599601
600602 if ext == 'ps' :
601- ctx . set_target_ps ( fileObject , w_in , h_in , ppi , ppi )
603+ surface = cairo . PSSurface ( filename , width , height )
602604 else : # pdf
603- ctx .set_target_pdf (fileObject , w_in , h_in , ppi , ppi )
604-
605+ surface = cairo .PDFSurface (filename , width , height )
606+ ctx = cairo .Context (surface )
607+
605608 if orientation == 'landscape' :
606609 ctx .rotate (numx .pi / 2 )
607610 ctx .translate (0 , - height )
@@ -614,7 +617,7 @@ def _save_ps_pdf (figure, fileObject, ext, orientation):
614617
615618 renderer = RendererCairo (figure .dpi )
616619 renderer ._set_width_height (width , height )
617- renderer .surface = ctx .target_surface
620+ renderer .surface = ctx .get_target ()
618621 figure .draw (renderer )
619622
620623 show_fig_border = False # for testing figure orientation and scaling
@@ -626,7 +629,7 @@ def _save_ps_pdf (figure, fileObject, ext, orientation):
626629 ctx .stroke ()
627630 ctx .move_to (30 ,30 )
628631 ctx .select_font_face ('sans-serif' )
629- ctx .scale_font (20 )
632+ ctx .set_font_size (20 )
630633 ctx .show_text ('Origin corner' )
631634
632635 ctx .show_page ()
0 commit comments