8000 Minor cleanups to the cairo backend. by anntzer · Pull Request #10092 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Minor cleanups to the cairo backend. #10092

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

Merged
merged 1 commit into from
Dec 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ def draw_image(self, gc, x, y, im):
# the array.array functionality here to get cross version support.
imbuffer = ArrayWrapper(im.flatten())
else:
# py2cairo uses PyObject_AsWriteBuffer
# to get a pointer to the numpy array this works correctly
# on a regular numpy array but not on a memory view.
# At the time of writing the latest release version of
# py3cairo still does not support create_for_data
# pycairo uses PyObject_AsWriteBuffer to get a pointer to the
# numpy array; this works correctly on a regular numpy array but
# not on a py2 memoryview.
imbuffer = im.flatten()
surface = cairo.ImageSurface.create_for_data(
imbuffer, cairo.FORMAT_ARGB32,
Expand Down Expand Up @@ -277,7 +275,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if not isinstance(s, six.text_type):
s = six.text_type(s)
else:
if not six.PY3 and isinstance(s, six.text_type):
if six.PY2 and isinstance(s, six.text_type):
s = s.encode("utf-8")

ctx.show_text(s)
Expand Down Expand Up @@ -328,8 +326,8 @@ def get_canvas_width_height(self):

def get_text_width_height_descent(self, s, prop, ismath):
if ismath:
width, height, descent, fonts, used_characters = self.mathtext_parser.parse(
s, self.dpi, prop)
width, height, descent, fonts, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop)
return width, height, descent

ctx = self.text_ctx
Expand All @@ -354,7 +352,7 @@ def get_text_width_height_descent(self, s, prop, ismath):

def new_gc(self):
self.gc.ctx.save()
self.gc._alpha = 1.0
self.gc._alpha = 1
self.gc._forced_alpha = False # if True, _alpha overrides A from RGBA
return self.gc

Expand Down Expand Up @@ -391,8 +389,9 @@ def set_alpha(self, alpha):
else:
self.ctx.set_source_rgba(rgb[0], rgb[1], rgb[2], rgb[3])

#def set_antialiased(self, b):
# enable/disable anti-aliasing is not (yet) supported by Cairo
# def set_antialiased(self, b):
# cairo has many antialiasing modes, we need to pick one for True and
# one for False.

def set_capstyle(self, cs):
if cs in ('butt', 'round', 'projecting'):
Expand All @@ -404,9 +403,7 @@ def set_capstyle(self, cs):
def set_clip_rectangle(self, rectangle):
if not rectangle:
return
x, y, w, h = rectangle.bounds
# pixel-aligned clip-regions are faster
x,y,w,h = np.round(x), np.round(y), np.round(w), np.round(h)
x, y, w, h = np.round(rectangle.bounds)
ctx = self.ctx
ctx.new_path()
ctx.rectangle(x, self.renderer.height - h - y, w, h)
Expand Down Expand Up @@ -522,14 +519,9 @@ def _save(self, fo, fmt, **kwargs):
ctx = renderer.gc.ctx

if orientation == 'landscape':
ctx.rotate(np.pi/2)
ctx.rotate(np.pi / 2)
ctx.translate(0, -height_in_points)
# cairo/src/cairo_ps_surface.c
# '%%Orientation: Portrait' is always written to the file header
# '%%Orientation: Landscape' would possibly cause problems
# since some printers would rotate again ?
# TODO:
# add portrait/landscape checkbox to FileChooser
# Perhaps add an '%%Orientation: Landscape' comment?

self.figure.draw(renderer)

Expand Down
0