Revision: 6997
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6997&view=rev
Author: mdboom
Date: 2009-03-19 13:15:00 +0000 (Thu, 19 Mar 2009)
Log Message:
-----------
Fix bug in Cairo backend related to clipping -- thanks Nathaniel Smith
Modified Paths:
--------------
branches/v0_98_5_maint/lib/matplotlib/backends/backend_cairo.py
Modified: branches/v0_98_5_maint/lib/matplotlib/backends/backend_cairo.py
===================================================================
--- branches/v0_98_5_maint/lib/matplotlib/backends/backend_cairo.py
2009-03-19 12:55:07 UTC (rev 6996)
+++ branches/v0_98_5_maint/lib/matplotlib/backends/backend_cairo.py
2009-03-19 13:15:00 UTC (rev 6997)
@@ -109,6 +109,23 @@
# font transform?
+ def _do_clip(self, ctx, cliprect, clippath):
+ if cliprect is not None:
+ x,y,w,h = cliprect.bounds
+ # pixel-aligned clip-regions are faster
+ x,y,w,h = round(x), round(y), round(w), round(h)
+ ctx.new_path()
+ ctx.rectangle (x, self.height - h - y, w, h)
+ ctx.clip ()
+
+ if clippath is not None:
+ tpath, affine = clippath.get_transformed_path_and_affine()
+ ctx.new_path()
+ affine = affine + Affine2D().scale(1.0, -1.0).translate(0.0,
self.height)
+ tpath = affine.transform_path(tpath)
+ RendererCairo.convert_path(ctx, tpath)
+ ctx.clip()
+
def _fill_and_stroke (self, ctx, fill_c, alpha):
if fill_c is not None:
ctx.save()
@@ -120,7 +137,6 @@
ctx.restore()
ctx.stroke()
-
#...@staticmethod
def convert_path(ctx, tpath):
for points, code in tpath.iter_segments():
@@ -144,6 +160,9 @@
raise ValueError("The Cairo backend can not draw paths longer than
18980 points.")
ctx = gc.ctx
+ ctx.save()
+ self._do_clip(ctx, gc._cliprect, gc._clippath)
+
transform = transform + \
Affine2D().scale(1.0, -1.0).translate(0, self.height)
tpath = transform.transform_path(path)
@@ -152,6 +171,7 @@
self.convert_path(ctx, tpath)
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha())
+ ctx.restore()
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
# bbox - not currently used
@@ -164,9 +184,16 @@
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
# function does not pass a 'gc' so use renderer.ctx
ctx = self.ctx
+ ctx.save()
+ if clippath is not None:
+ tpath = clippath_trans.transform_path(clippath)
+ ctx.new_path()
+ RendererCairo.convert_path(ctx, tpath)
+ ctx.clip()
y = self.height - y - rows
ctx.set_source_surface (surface, x, y)
ctx.paint()
+ ctx.restore()
im.flipud_out()
@@ -324,31 +351,10 @@
def set_clip_rectangle(self, rectangle):
self._cliprect = rectangle
- if rectangle is None:
- return
- x,y,w,h = rectangle.bounds
- # pixel-aligned clip-regions are faster
- x,y,w,h = round(x), round(y), round(w), round(h)
- ctx = self.ctx
- ctx.new_path()
- ctx.rectangle (x, self.renderer.height - h - y, w, h)
- ctx.clip ()
- # Alternative: just set _cliprect here and actually set cairo clip rect
- # in fill_and_stroke() inside ctx.save() ... ctx.restore()
-
-
def set_clip_path(self, path):
- if path is not None:
- tpath, affine = path.get_transformed_path_and_affine()
- ctx = self.ctx
- ctx.new_path()
- affine = affine + Affine2D().scale(1.0, -1.0).translate(0.0,
self.renderer.height)
- tpath = affine.transform_path(tpath)
- RendererCairo.convert_path(ctx, tpath)
- ctx.clip()
+ self._clippath = path
-
def set_dashes(self, offset, dashes):
self._dashes = offset, dashes
if dashes == None:
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins