|
29 | 29 |
|
30 | 30 | import numpy as np |
31 | 31 |
|
| 32 | +# cairocffi is more widely compatible than pycairo (in particular pgi only |
| 33 | +# works with cairocffi) so try it first. |
32 | 34 | try: |
33 | 35 | import cairocffi as cairo |
34 | 36 | except ImportError: |
35 | 37 | try: |
36 | 38 | import cairo |
37 | 39 | except ImportError: |
38 | | - raise ImportError("Cairo backend requires that cairocffi or pycairo " |
39 | | - "is installed.") |
| 40 | + raise ImportError("cairo backend requires that cairocffi or pycairo " |
| 41 | + "is installed") |
40 | 42 | else: |
41 | 43 | HAS_CAIRO_CFFI = False |
42 | 44 | else: |
43 | 45 | HAS_CAIRO_CFFI = True |
44 | 46 |
|
45 | | -_version_required = (1, 2, 0) |
46 | | -if cairo.version_info < _version_required: |
47 | | - raise ImportError("Pycairo %d.%d.%d is installed\n" |
48 | | - "Pycairo %d.%d.%d or later is required" |
49 | | - % (cairo.version_info + _version_required)) |
| 47 | +if cairo.version_info < (1, 4, 0): |
| 48 | + raise ImportError("cairo {} is installed; " |
| 49 | + "cairo>=1.4.0 is required".format(cairo.version)) |
50 | 50 | backend_version = cairo.version |
51 | | -del _version_required |
52 | 51 |
|
53 | 52 | from matplotlib.backend_bases import ( |
54 | 53 | _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, |
@@ -113,14 +112,14 @@ def __init__(self, dpi): |
113 | 112 |
|
114 | 113 | def set_ctx_from_surface(self, surface): |
115 | 114 | self.gc.ctx = cairo.Context(surface) |
| 115 | + # Although it may appear natural to automatically call |
| 116 | + # `self.set_width_height(surface.get_width(), surface.get_height())` |
| 117 | + # here (instead of having the caller do so separately), this would fail |
| 118 | + # for PDF/PS/SVG surfaces, which have no way to report their extents. |
116 | 119 |
|
117 | 120 | def set_width_height(self, width, height): |
118 | 121 | self.width = width |
119 | 122 | self.height = height |
120 | | - self.matrix_flipy = cairo.Matrix(yy=-1, y0=self.height) |
121 | | - # use matrix_flipy for ALL rendering? |
122 | | - # - problem with text? - will need to switch matrix_flipy off, or do a |
123 | | - # font transform? |
124 | 123 |
|
125 | 124 | def _fill_and_stroke(self, ctx, fill_c, alpha, alpha_overrides): |
126 | 125 | if fill_c is not None: |
@@ -314,11 +313,6 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle): |
314 | 313 |
|
315 | 314 | ctx.restore() |
316 | 315 |
|
317 | | - def flipy(self): |
318 | | - return True |
319 | | - #return False # tried - all draw objects ok except text (and images?) |
320 | | - # which comes out mirrored! |
321 | | - |
322 | 316 | def get_canvas_width_height(self): |
323 | 317 | return self.width, self.height |
324 | 318 |
|
|
0 commit comments