diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 895a8dea72ed..3d65bbc713f5 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -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, @@ -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) @@ -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 @@ -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 @@ -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'): @@ -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) @@ -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)