Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3499bc

Browse files
committed
Merge pull request matplotlib#128 from mdboom/gtk-hexbin-crash
hexbin_demo.py crashes with gtk backend
2 parents f763cd1 + a988fb0 commit e3499bc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/backends/backend_gdk.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def draw_image(self, gc, x, y, im):
142142
def draw_text(self, gc, x, y, s, prop, angle, ismath):
143143
x, y = int(x), int(y)
144144

145-
if x <0 or y <0: # window has shrunk and text is off the edge
145+
if x < 0 or y < 0: # window has shrunk and text is off the edge
146146
return
147147

148148
if angle not in (0,90):
@@ -157,6 +157,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
157157
else:
158158
layout, inkRect, logicalRect = self._get_pango_layout(s, prop)
159159
l, b, w, h = inkRect
160+
if (x + w > self.width or y + h > self.height):
161+
return
162+
160163
self.gdkDrawable.draw_layout(gc.gdkGC, x, y-h-b, layout)
161164

162165

@@ -225,7 +228,8 @@ def _draw_rotated_text(self, gc, x, y, s, prop, angle):
225228
x = int(x-h)
226229
y = int(y-w)
227230

228-
if x < 0 or y < 0: # window has shrunk and text is off the edge
231+
if (x < 0 or y < 0 or: # window has shrunk and text is off the edge
232+
x + w > self.width or y + h > self.height):
229233
return
230234

231235
key = (x,y,s,angle,hash(prop))

0 commit comments

Comments
 (0)