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

Skip to content

Commit a9f4a19

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 a9f4a19

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
"""
22
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.
198
"""
209

2110
from __future__ import (absolute_import, division, print_function,
@@ -29,26 +18,25 @@
2918

3019
import numpy as np
3120

21+
# cairocffi is more widely compatible than pycairo (in particular pgi only
22+
# works with cairocffi) so try it first.
3223
try:
3324
import cairocffi as cairo
3425
except ImportError:
3526
try:
3627
import cairo
3728
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")
4031
else:
4132
HAS_CAIRO_CFFI = False
4233
else:
4334
HAS_CAIRO_CFFI = True
4435

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

5341
from matplotlib.backend_bases import (
5442
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
@@ -113,14 +101,14 @@ def __init__(self, dpi):
113101

114102
def set_ctx_from_surface(self, surface):
115103
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.
116108

117109
def set_width_height(self, width, height):
118110
self.width = width
119111
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?
124112

125113
def _fill_and_stroke(self, ctx, fill_c, alpha, alpha_overrides):
126114
if fill_c is not None:
@@ -314,11 +302,6 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
314302

315303
ctx.restore()
316304

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-
322305
def get_canvas_width_height(self):
323306
return self.width, self.height
324307

0 commit comments

Comments
 (0)