Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc43313a

Browse files
ksundenmeeseeksmachine
authored andcommitted
Backport PR#28451: Fix GTK cairo backends
1 parent560fdc4 commitc43313a

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
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()ifself.toolbar
1515
elsenullcontext()):
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

Lines 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(lambdacls: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-
ifnotself._context_is_scaled:
232-
x0,y0,w,h= (dim/self.device_pixel_ratio
233-
fordiminself._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+
fordiminself._rubberband_rect)
238232
x1=x0+w
239233
y1=y0+h
240234

‎lib/matplotlib/backends/backend_gtk4cairo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66

77
classFigureCanvasGTK4Cairo(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+
returnFalse
912

1013
defon_draw_event(self,widget,ctx):
1114
ifself._idle_draw_id:
@@ -16,15 +19,11 @@ def on_draw_event(self, widget, ctx):
1619
with (self.toolbar._wait_cursor_for_draw_cm()ifself.toolbar
1720
elsenullcontext()):
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)

[8]ページ先頭

©2009-2025 Movatter.jp