From 87bdb63cd75036eed3e71cc375c22de9dc47f3ef Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 27 Jan 2014 13:30:50 -0500 Subject: [PATCH 1/2] Handle alpha on images in Cairo backend. --- lib/matplotlib/backends/backend_cairo.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index dd9098edbffc..2c5514dd6ee5 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -177,7 +177,10 @@ def draw_image(self, gc, x, y, im): ctx.save() ctx.set_source_surface (surface, x, y) - ctx.paint() + if gc.get_alpha() != 1.0: + ctx.paint_with_alpha(gc.get_alpha()) + else: + ctx.paint() ctx.restore() im.flipud_out() From b81313a437fce21a583bafac4dd7a5f3b4e6361d Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 27 Jan 2014 13:31:00 -0500 Subject: [PATCH 2/2] Update code to use cairocffi/pycairo compatible API to determine if PDF/PS/SVG backends are available. --- lib/matplotlib/backends/backend_cairo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 2c5514dd6ee5..8c46277bbcb9 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -468,17 +468,17 @@ def _save (self, fo, format, **kwargs): width_in_points) if format == 'ps': - if not cairo.HAS_PS_SURFACE: + if not hasattr(cairo, 'PSSurface'): raise RuntimeError ('cairo has not been compiled with PS ' 'support enabled') surface = cairo.PSSurface (fo, width_in_points, height_in_points) elif format == 'pdf': - if not cairo.HAS_PDF_SURFACE: + if not hasattr(cairo, 'PDFSurface'): raise RuntimeError ('cairo has not been compiled with PDF ' 'support enabled') surface = cairo.PDFSurface (fo, width_in_points, height_in_points) elif format in ('svg', 'svgz'): - if not cairo.HAS_SVG_SURFACE: + if not hasattr(cairo, 'SVGSurface'): raise RuntimeError ('cairo has not been compiled with SVG ' 'support enabled') if format == 'svgz':