Skip to content

Cairo rendering for Qt5 #8771

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

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
Fix vector output from cairo.
Vector surfaces do not report their extents, so we need to pass them in
manually.
  • Loading branch information
anntzer committed Jan 9, 2018
commit 89a87d0be2064a42d8809f45dae131e5cca3663b
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def __init__(self, dpi):

def set_ctx_from_surface(self, surface):
self.gc.ctx = cairo.Context(surface)
self.set_width_height(surface.get_width(), surface.get_height())
# 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
Expand Down Expand Up @@ -441,9 +444,9 @@ def print_png(self, fobj, *args, **kwargs):
width, height = self.get_width_height()

renderer = RendererCairo(self.figure.dpi)
renderer.set_width_height(width, height)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
renderer.set_ctx_from_surface(surface)
renderer.set_width_height(width, height)

self.figure.draw(renderer)
surface.write_to_png(fobj)
Expand Down Expand Up @@ -500,6 +503,7 @@ def _save(self, fo, fmt, **kwargs):
# surface.set_dpi() can be used
renderer = RendererCairo(self.figure.dpi)
renderer.set_ctx_from_surface(surface)
renderer.set_width_height(width_in_points, height_in_points)
ctx = renderer.gc.ctx

if orientation == 'landscape':
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_qt5cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def paintEvent(self, event):
surface = backend_cairo.cairo.ImageSurface(
backend_cairo.cairo.FORMAT_ARGB32, width, height)
self._renderer.set_ctx_from_surface(surface)
self._renderer.set_width_height(width, height)
self.figure.draw(self._renderer)
buf = surface.get_data()
qimage = QtGui.QImage(buf, width, height,
Expand Down