8000 gtk3: Fix Cairo backend · QuLogic/matplotlib@6fee86a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fee86a

Browse files
committed
gtk3: Fix Cairo backend
With GTK3, the Cairo surface we get is for the whole window, which means the automatic size inference from matplotlib#22004 gets the wrong size. For the GtkDrawingArea, the Cairo context is aligned and clipped to the widget, so nothing goes out-of-bounds. However, since the Cairo renderer flips the origin using the height in the calculation (which is, for the window, bigger than the drawing widget), everything is drawn lower than it should.
1 parent 5c55265 commit 6fee86a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/matplotlib/backends/backend_gtk3cairo.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ def on_draw_event(self, widget, ctx):
1313

1414
with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
1515
else nullcontext()):
16-
self._renderer.set_context(ctx)
17-
scale = self.device_pixel_ratio
18-
# Scale physical drawing to logical size.
19-
ctx.scale(1 / scale, 1 / scale)
2016
allocation = self.get_allocation()
17+
# Render the background before scaling, as the allocated size here is in
18+
# logical pixels.
2119
Gtk.render_background(
2220
self.get_style_context(), ctx,
23-
allocation.x, allocation.y,
24-
allocation.width, allocation.height)
21+
0, 0, allocation.width, allocation.height)
22+
scale = self.device_pixel_ratio
23+
# Scale physical drawing to logical size.
24+
ctx.scale(1 / scale, 1 / scale)
25+
self._renderer.set_context(ctx)
26+
# Set renderer to physical size so it renders in full resolution.
27+
self._renderer.width = allocation.width * scale
28+
self._renderer.height = allocation.height * scale
2529
self._renderer.dpi = self.figure.dpi
2630
self.figure.draw(self._renderer)
2731

0 commit comments

Comments
 (0)
0