diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 0c4c89ae2c4f..e4979c5ec8d5 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -29,26 +29,25 @@ import numpy as np +# cairocffi is more widely compatible than pycairo (in particular pgi only +# works with cairocffi) so try it first. try: import cairocffi as cairo except ImportError: try: import cairo except ImportError: - raise ImportError("Cairo backend requires that cairocffi or pycairo " - "is installed.") + raise ImportError("cairo backend requires that cairocffi or pycairo " + "is installed") else: HAS_CAIRO_CFFI = False else: HAS_CAIRO_CFFI = True -_version_required = (1, 2, 0) -if cairo.version_info < _version_required: - raise ImportError("Pycairo %d.%d.%d is installed\n" - "Pycairo %d.%d.%d or later is required" - % (cairo.version_info + _version_required)) +if cairo.version_info < (1, 4, 0): + raise ImportError("cairo {} is installed; " + "cairo>=1.4.0 is required".format(cairo.version)) backend_version = cairo.version -del _version_required from matplotlib.backend_bases import ( _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, @@ -113,14 +112,14 @@ def __init__(self, dpi): def set_ctx_from_surface(self, surface): self.gc.ctx = cairo.Context(surface) + # Although it may appear natural to automatically call + # `self.set_width_height(surface.get_width(), surface.get_height())` + # here (instead of having the caller do so separately), this would fail + # for PDF/PS/SVG surfaces, which have no way to report their extents. def set_width_height(self, width, height): self.width = width self.height = height - self.matrix_flipy = cairo.Matrix(yy=-1, y0=self.height) - # use matrix_flipy for ALL rendering? - # - problem with text? - will need to switch matrix_flipy off, or do a - # font transform? def _fill_and_stroke(self, ctx, fill_c, alpha, alpha_overrides): if fill_c is not None: @@ -314,11 +313,6 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle): ctx.restore() - def flipy(self): - return True - #return False # tried - all draw objects ok except text (and images?) - # which comes out mirrored! - def get_canvas_width_height(self): return self.width, self.height