Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup backend_cairo. #10204

Merged
merged 1 commit into from Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 11 additions & 17 deletions lib/matplotlib/backends/backend_cairo.py
Expand Up @@ -29,26 +29,25 @@

import numpy as np

# cairocffi is more widely compatible than pycairo (in particular pgi only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note should prob end up in some docs if it hasn't already...

# 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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down