@@ -34,6 +34,7 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
3434backend_version = cairo .version
3535del _version_required
3636
37+ from matplotlib import agg
3738from matplotlib .backend_bases import RendererBase , GraphicsContextBase ,\
3839 FigureManagerBase , FigureCanvasBase
3940from matplotlib .cbook import enumerate , izip , is_string_like
@@ -124,6 +125,34 @@ def _fill_and_stroke (self, ctx, fill_c):
124125
125126 #_.ctx.restore() # revert to the default attributes
126127
128+ def draw_path (self , gc , rgbFace , path ):
129+ ctx = gc .ctx
130+ ctx .new_path ()
131+
132+ while 1 :
133+ code , xp , yp = path .vertex ()
134+ yp = self .height - yp
135+
136+ if code == agg .path_cmd_stop :
137+ ctx .close_path ()
138+ break
139+ elif code == agg .path_cmd_move_to :
140+ ctx .move_to (xp , yp )
141+ elif code == agg .path_cmd_line_to :
142+ ctx .line_to (xp , yp )
143+ elif code == agg .path_cmd_curve3 :
144+ _ , xp1 , yp1 = path .vertex ()
145+ yp1 = self .height - yp1
146+ ctx .curve_to (xp , yp , xp , yp , xp1 , yp1 )
147+ elif code == agg .path_cmd_curve4 :
148+ _ , xp1 , yp1 = path .vertex ()
149+ yp1 = self .height - yp1
150+ _ , xp2 , yp2 = path .vertex ()
151+ yp2 = self .height - yp2
152+ ctx .curve_to (xp , yp , xp1 , yp1 , xp2 , yp2 )
153+ elif code == agg .path_cmd_end_poly :
154+ ctx .close_path ()
155+ self ._fill_and_stroke (ctx , rgbFace )
127156
128157 def draw_arc (self , gc , rgbFace , x , y , width , height , angle1 , angle2 ,
129158 rotation ):
@@ -307,11 +336,11 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
307336 ctx .translate (x , y )
308337 if angle :
309338 ctx .rotate (- angle * npy .pi / 180 )
310-
339+
311340 for font , fontsize , s , ox , oy in glyphs :
312341 ctx .new_path ()
313342 ctx .move_to (ox , oy )
314-
343+
315344 fontProp = ttfFontProperty (font )
316345 ctx .save ()
317346 ctx .select_font_face (fontProp .name ,
@@ -332,7 +361,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
332361
333362 ctx .restore ()
334363
335-
364+
336365 def flipy (self ):
337366 if _debug : print '%s.%s()' % (self .__class__ .__name__ , _fn_name ())
338367 return True
@@ -494,7 +523,7 @@ def print_png(self, fobj, *args, **kwargs):
494523
495524 self .figure .draw (renderer )
496525 surface .write_to_png (fobj )
497-
526+
498527 def print_pdf (self , fobj , * args , ** kwargs ):
499528 return self ._save (fobj , 'pdf' , * args , ** kwargs )
500529
@@ -506,10 +535,10 @@ def print_svg(self, fobj, *args, **kwargs):
506535
507536 def print_svgz (self , fobj , * args , ** kwargs ):
508537 return self ._save (fobj , 'svgz' , * args , ** kwargs )
509-
538+
510539 def get_default_filetype (self ):
511540 return rcParams ['cairo.format' ]
512-
541+
513542 def _save (self , fo , format , ** kwargs ):
514543 # save PDF/PS/SVG
515544 orientation = kwargs .get ('orientation' , 'portrait' )
0 commit comments