Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ad8ee1

Browse filesBrowse files
authored
Merge pull request #28451 from QuLogic/gtk-cairo-hidpi
Fix GTK cairo backends
2 parents 651e910 + 6fee86a commit 0ad8ee1
Copy full SHA for 0ad8ee1

File tree

Expand file treeCollapse file tree

3 files changed

+16
-19
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-19
lines changed

‎lib/matplotlib/backends/backend_gtk3cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3cairo.py
+10-6Lines 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

‎lib/matplotlib/backends/backend_gtk4.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk4.py
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class FigureCanvasGTK4(_FigureCanvasGTK, Gtk.DrawingArea):
3434
required_interactive_framework = "gtk4"
3535
supports_blit = False
3636
manager_class = _api.classproperty(lambda cls: FigureManagerGTK4)
37-
_context_is_scaled = False
3837

3938
def __init__(self, figure=None):
4039
super().__init__(figure=figure)
@@ -228,13 +227,8 @@ def _post_draw(self, widget, ctx):
228227

229228
lw = 1
230229
dash = 3
231-
if not self._context_is_scaled:
232-
x0, y0, w, h = (dim / self.device_pixel_ratio
233-
for dim in self._rubberband_rect)
234-
else:
235-
x0, y0, w, h = self._rubberband_rect
236-
lw *= self.device_pixel_ratio
237-
dash *= self.device_pixel_ratio
230+
x0, y0, w, h = (dim / self.device_pixel_ratio
231+
for dim in self._rubberband_rect)
238232
x1 = x0 + w
239233
y1 = y0 + h
240234

‎lib/matplotlib/backends/backend_gtk4cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk4cairo.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66

77
class FigureCanvasGTK4Cairo(FigureCanvasCairo, FigureCanvasGTK4):
8-
_context_is_scaled = True
8+
def _set_device_pixel_ratio(self, ratio):
9+
# Cairo in GTK4 always uses logical pixels, so we don't need to do anything for
10+
# changes to the device pixel ratio.
11+
return False
912

1013
def on_draw_event(self, widget, ctx):
1114
if self._idle_draw_id:
@@ -16,15 +19,11 @@ def on_draw_event(self, widget, ctx):
1619
with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
1720
else nullcontext()):
1821
self._renderer.set_context(ctx)
19-
scale = self.device_pixel_ratio
20-
# Scale physical drawing to logical size.
21-
ctx.scale(1 / scale, 1 / scale)
2222
allocation = self.get_allocation()
2323
Gtk.render_background(
2424
self.get_style_context(), ctx,
2525
allocation.x, allocation.y,
2626
allocation.width, allocation.height)
27-
self._renderer.dpi = self.figure.dpi
2827
self.figure.draw(self._renderer)
2928

3029

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.