|
1 | 1 | """ |
2 | 2 | A Cairo backend for matplotlib |
3 | | -Author: Steve Chaplin |
4 | | -
|
5 | | -Cairo is a vector graphics library with cross-device output support. |
6 | | -Features of Cairo: |
7 | | - * anti-aliasing |
8 | | - * alpha channel |
9 | | - * saves image files as PNG, PostScript, PDF |
10 | | -
|
11 | | -http://cairographics.org |
12 | | -Requires (in order, all available from Cairo website): |
13 | | - cairo, pycairo |
14 | | -
|
15 | | -Naming Conventions |
16 | | - * classes MixedUpperCase |
17 | | - * varables lowerUpper |
18 | | - * functions underscore_separated |
| 3 | +============================== |
| 4 | +:Author: Steve Chaplin and others |
| 5 | +
|
| 6 | +This backend depends on `cairo <http://cairographics.org>`_, and either on |
| 7 | +cairocffi, or (Python 2 only) on pycairo. |
19 | 8 | """ |
20 | 9 |
|
21 | 10 | from __future__ import (absolute_import, division, print_function, |
|
29 | 18 |
|
30 | 19 | import numpy as np |
31 | 20 |
|
| 21 | +# cairocffi is more widely compatible than pycairo (in particular pgi only |
| 22 | +# works with cairocffi) so try it first. |
32 | 23 | try: |
33 | 24 | import cairocffi as cairo |
34 | 25 | except ImportError: |
35 | 26 | try: |
36 | 27 | import cairo |
37 | 28 | except ImportError: |
38 | | - raise ImportError("Cairo backend requires that cairocffi or pycairo " |
39 | | - "is installed.") |
| 29 | + raise ImportError("cairo backend requires that cairocffi or pycairo " |
| 30 | + "is installed") |
40 | 31 | else: |
41 | 32 | HAS_CAIRO_CFFI = False |
42 | 33 | else: |
43 | 34 | HAS_CAIRO_CFFI = True |
44 | 35 |
|
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)) |
| 36 | +if cairo.version_info < (1, 4, 0): |
| 37 | + raise ImportError("cairo {} is installed; " |
| 38 | + "cairo>=1.4.0 is required".format(cairo.version)) |
50 | 39 | backend_version = cairo.version |
51 | | -del _version_required |
52 | 40 |
|
53 | 41 | from matplotlib.backend_bases import ( |
54 | 42 | _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, |
@@ -113,14 +101,14 @@ def __init__(self, dpi): |
113 | 101 |
|
114 | 102 | def set_ctx_from_surface(self, surface): |
115 | 103 | self.gc.ctx = cairo.Context(surface) |
| 104 | + # Although it may appear natural to automatically call |
| 105 | + # `self.set_width_height(surface.get_width(), surface.get_height())` |
| 106 | + # here (instead of having the caller do so separately), this would fail |
| 107 | + # for PDF/PS/SVG surfaces, which have no way to report their extents. |
116 | 108 |
|
117 | 109 | def set_width_height(self, width, height): |
118 | 110 | self.width = width |
119 | 111 | 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 | 112 |
|
125 | 113 | def _fill_and_stroke(self, ctx, fill_c, alpha, alpha_overrides): |
126 | 114 | if fill_c is not None: |
@@ -314,11 +302,6 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle): |
314 | 302 |
|
315 | 303 | ctx.restore() |
316 | 304 |
|
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 | 305 | def get_canvas_width_height(self): |
323 | 306 | return self.width, self.height |
324 | 307 |
|
|
0 commit comments