Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c535a7c

Browse files
committed
Cleanup backend_cairo.
Split out of the qt5cairo PR. - Update to cairo 1.4.0 as minimal version (it introduced Context.clip_extents, which we use; https://pycairo.readthedocs.io/en/latest/changelog.html#id26) - matrix_flipy is unused. - flipy() is already True in the base class.
1 parent 1f3699c commit c535a7c

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,25 @@
2929

3030
import numpy as np
3131

32+
# cairocffi is more widely compatible than pycairo (in particular pgi only
33+
# works with cairocffi) so try it first.
3234
try:
3335
import cairocffi as cairo
3436
except ImportError:
3537
try:
3638
import cairo
3739
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")
4042
else:
4143
HAS_CAIRO_CFFI = False
4244
else:
4345
HAS_CAIRO_CFFI = True
4446

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))
5050
backend_version = cairo.version
51-
del _version_required
5251

5352
from matplotlib.backend_bases import (
5453
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
@@ -113,14 +112,14 @@ def __init__(self, dpi):
113112

114113
def set_ctx_from_surface(self, surface):
115114
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.
116119

117120
def set_width_height(self, width, height):
118121
self.width = width
119122
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?
124123

125124
def _fill_and_stroke(self, ctx, fill_c, alpha, alpha_overrides):
126125
if fill_c is not None:
@@ -314,11 +313,6 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
314313

315314
ctx.restore()
316315

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-
322316
def get_canvas_width_height(self):
323317
return self.width, self.height
324318

0 commit comments

Comments
 (0)