Revision: 4527
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4527&view=rev
Author: mdboom
Date: 2007-11-30 08:16:34 -0800 (Fri, 30 Nov 2007)
Log Message:
-----------
Fix Cairo alpha-blending.
Modified Paths:
--------------
branches/transforms/lib/matplotlib/backend_bases.py
branches/transforms/lib/matplotlib/backends/backend_cairo.py
Modified: branches/transforms/lib/matplotlib/backend_bases.py
===================================================================
--- branches/transforms/lib/matplotlib/backend_bases.py 2007-11-30 16:08:52 UTC
(rev 4526)
+++ branches/transforms/lib/matplotlib/backend_bases.py 2007-11-30 16:16:34 UTC
(rev 4527)
@@ -27,7 +27,7 @@
The following methods *should* be implemented in the backend for
optimization reasons:
-
+
draw_markers
draw_path_collection
draw_quad_mesh
@@ -73,7 +73,7 @@
self.draw_path(gc, marker_path,
marker_trans + transforms.Affine2D().translate(x,
y),
rgbFace)
-
+
def draw_path_collection(self, master_transform, cliprect, clippath,
clippath_trans, paths, all_transforms, offsets,
offsetTrans, facecolors, edgecolors, linewidths,
@@ -126,12 +126,12 @@
else:
edgecolors = facecolors
linewidths = npy.array([1.0], npy.float_)
-
+
return self.draw_path_collection(
master_transform, cliprect, clippath, clippath_trans,
paths, [], offsets, offsetTrans, facecolors, edgecolors,
linewidths, [], [antialiased])
-
+
def _iter_collection_raw_paths(self, master_transform, paths,
all_transforms):
"""
This is a helper method (along with _iter_collection) to make
@@ -203,20 +203,20 @@
return
if Noffsets:
toffsets = offsetTrans.transform(offsets)
-
+
gc = self.new_gc()
gc.set_clip_rectangle(cliprect)
if clippath is not None:
clippath = transforms.TransformedPath(clippath, clippath_trans)
gc.set_clip_path(clippath)
-
+
if Nfacecolors == 0:
rgbFace = None
if Nedgecolors == 0:
gc.set_linewidth(0.0)
-
+
xo, yo = 0, 0
for i in xrange(N):
path_id = path_ids[i % Npaths]
@@ -233,7 +233,7 @@
gc.set_antialiased(antialiaseds[i % Naa])
yield xo, yo, path_id, gc, rgbFace
-
+
def get_image_magnification(self):
"""
Get the factor by which to magnify images passed to draw_image.
@@ -282,7 +282,7 @@
your text.
"""
raise NotImplementedError
-
+
def flipy(self):
"""return true if y small numbers are top for renderer
Is used for drawing text (text.py) and images (image.py) only
@@ -334,8 +334,8 @@
def stop_rasterizing(self):
pass
-
+
class GraphicsContextBase:
"""An abstract base class that provides color, line styles, etc...
"""
@@ -380,8 +380,6 @@
Return the alpha value used for blending - not supported on
all backends
"""
- if len(self._rgb) == 4:
- return self._rgb[3]
return self._alpha
def get_antialiased(self):
@@ -795,7 +793,7 @@
# can't delete the artist
while h:
print "Removing",h
- if h.remove():
+ if h.remove():
self.draw_idle()
break
parent = None
@@ -804,7 +802,7 @@
parent = p
break
h = parent
-
+
def onHilite(self, ev):
"""
Mouse event processor which highlights the artists
@@ -980,7 +978,7 @@
# a) otherwise we'd have cyclical imports, since all of these
# classes inherit from FigureCanvasBase
# b) so we don't import a bunch of stuff the user may never use
-
+
def print_emf(self, *args, **kwargs):
from backends.backend_emf import FigureCanvasEMF # lazy import
emf = self.switch_backends(FigureCanvasEMF)
@@ -990,7 +988,7 @@
from backends.backend_ps import FigureCanvasPS # lazy import
ps = self.switch_backends(FigureCanvasPS)
return ps.print_eps(*args, **kwargs)
-
+
def print_pdf(self, *args, **kwargs):
from backends.backend_pdf import FigureCanvasPdf # lazy import
pdf = self.switch_backends(FigureCanvasPdf)
@@ -1000,7 +998,7 @@
from backends.backend_agg import FigureCanvasAgg # lazy import
agg = self.switch_backends(FigureCanvasAgg)
return agg.print_png(*args, **kwargs)
-
+
def print_ps(self, *args, **kwargs):
from backends.backend_ps import FigureCanvasPS # lazy import
ps = self.switch_backends(FigureCanvasPS)
@@ -1016,12 +1014,12 @@
from backends.backend_svg import FigureCanvasSVG # lazy import
svg = self.switch_backends(FigureCanvasSVG)
return svg.print_svg(*args, **kwargs)
-
+
def print_svgz(self, *args, **kwargs):
from backends.backend_svg import FigureCanvasSVG # lazy import
svg = self.switch_backends(FigureCanvasSVG)
return svg.print_svgz(*args, **kwargs)
-
+
def get_supported_filetypes(self):
return self.filetypes
@@ -1031,7 +1029,7 @@
groupings.setdefault(name, []).append(ext)
groupings[name].sort()
return groupings
-
+
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', format=None, **kwargs):
"""
@@ -1069,7 +1067,7 @@
if dpi is None:
dpi = rcParams['savefig.dpi']
-
+
origDPI = self.figure.dpi
origfacecolor = self.figure.get_facecolor()
origedgecolor = self.figure.get_edgecolor()
@@ -1092,12 +1090,12 @@
self.figure.set_edgecolor(origedgecolor)
self.figure.set_canvas(self)
self.figure.canvas.draw()
-
+
return result
def get_default_filetype(self):
raise NotImplementedError
-
+
def set_window_title(self, title):
"""
Set the title text of the window containing the figure. Note that
Modified: branches/transforms/lib/matplotlib/backends/backend_cairo.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_cairo.py
2007-11-30 16:08:52 UTC (rev 4526)
+++ branches/transforms/lib/matplotlib/backends/backend_cairo.py
2007-11-30 16:16:34 UTC (rev 4527)
@@ -94,8 +94,8 @@
def set_ctx_from_surface (self, surface):
self.ctx = cairo.Context (surface)
self.ctx.save() # restore, save - when call new_gc()
-
+
def set_width_height(self, width, height):
self.width = width
self.height = height
@@ -111,12 +111,12 @@
if len(fill_c) == 3:
ctx.set_source_rgba (fill_c[0], fill_c[1], fill_c[2], alpha)
else:
- ctx.set_source_rgba (*fill_c)
+ ctx.set_source_rgba (fill_c[0], fill_c[1], fill_c[2],
alpha*fill_c[3])
ctx.fill_preserve()
ctx.restore()
ctx.stroke()
-
+
[EMAIL PROTECTED]
def convert_path(ctx, tpath):
for points, code in tpath.iter_segments():
@@ -134,7 +134,7 @@
ctx.close_path()
convert_path = staticmethod(convert_path)
-
+
def draw_path(self, gc, path, transform, rgbFace=None):
if len(path.vertices) > 18980:
raise ValueError("The Cairo backend can not draw paths longer than
18980 points.")
@@ -143,7 +143,7 @@
transform = transform + \
Affine2D().scale(1.0, -1.0).translate(0, self.height)
tpath = transform.transform_path(path)
-
+
ctx.new_path()
self.convert_path(ctx, tpath)
@@ -203,11 +203,11 @@
ctx.translate(x, y)
if angle:
ctx.rotate (-angle * npy.pi / 180)
-
+
for font, fontsize, s, ox, oy in glyphs:
ctx.new_path()
ctx.move_to(ox, oy)
-
+
fontProp = ttfFontProperty(font)
ctx.save()
ctx.select_font_face (fontProp.name,
@@ -228,7 +228,7 @@
ctx.restore()
-
+
def flipy(self):
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
return True
@@ -281,8 +281,8 @@
def points_to_pixels(self, points):
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
return points/72.0 * self.dpi
-
-
+
+
class GraphicsContextCairo(GraphicsContextBase):
_joind = {
'bevel' : cairo.LINE_JOIN_BEVEL,
@@ -323,6 +323,8 @@
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
@@ -345,7 +347,7 @@
RendererCairo.convert_path(ctx, tpath)
ctx.clip()
-
+
def set_dashes(self, offset, dashes):
self._dashes = offset, dashes
if dashes == None:
@@ -382,7 +384,7 @@
self._linewidth = w
self.ctx.set_line_width (self.renderer.points_to_pixels(w))
-
+
def new_figure_manager(num, *args, **kwargs): # called by backends/__init__.py
"""
Create a new figure manager instance
@@ -406,7 +408,7 @@
self.figure.draw (renderer)
surface.write_to_png (fobj)
-
+
def print_pdf(self, fobj, *args, **kwargs):
return self._save(fobj, 'pdf', *args, **kwargs)
@@ -418,16 +420,16 @@
def print_svgz(self, fobj, *args, **kwargs):
return self._save(fobj, 'svgz', *args, **kwargs)
-
+
def get_default_filetype(self):
return rcParams['cairo.format']
-
+
def _save (self, fo, format, **kwargs):
# save PDF/PS/SVG
orientation = kwargs.get('orientation', 'portrait')
dpi = 72
- self.figure.dpi.set (dpi)
+ self.figure.dpi = dpi
w_in, h_in = self.figure.get_size_inches()
width_in_points, height_in_points = w_in * dpi, h_in * dpi
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins