From a329dcd8c78f697b68f1a693a4c374b7890b7f20 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 11 Jun 2012 08:35:50 -0400 Subject: [PATCH 1/2] Fix crash in _draw_rotated_text in Gdk backend. --- lib/matplotlib/backends/backend_gdk.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/backends/backend_gdk.py b/lib/matplotlib/backends/backend_gdk.py index a67ab23a008b..7a1173f00205 100644 --- a/lib/matplotlib/backends/backend_gdk.py +++ b/lib/matplotlib/backends/backend_gdk.py @@ -228,6 +228,9 @@ def _draw_rotated_text(self, gc, x, y, s, prop, angle): if x < 0 or y < 0: # window has shrunk and text is off the edge return + if x + w > self.width or y + h > self.height: + return + key = (x,y,s,angle,hash(prop)) imageVert = self.rotated.get(key) if imageVert != None: From a988fb0845a5e4156348aa2dbed81b8f82a5504c Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 12 Jun 2012 10:11:18 -0400 Subject: [PATCH 2/2] Add fix to Gdk backend's draw_text to prevent crashing when drawing off the edge of the image. --- lib/matplotlib/backends/backend_gdk.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/backends/backend_gdk.py b/lib/matplotlib/backends/backend_gdk.py index 7a1173f00205..33529d6cb2b3 100644 --- a/lib/matplotlib/backends/backend_gdk.py +++ b/lib/matplotlib/backends/backend_gdk.py @@ -142,7 +142,7 @@ def draw_image(self, gc, x, y, im): def draw_text(self, gc, x, y, s, prop, angle, ismath): x, y = int(x), int(y) - if x <0 or y <0: # window has shrunk and text is off the edge + if x < 0 or y < 0: # window has shrunk and text is off the edge return if angle not in (0,90): @@ -157,6 +157,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath): else: layout, inkRect, logicalRect = self._get_pango_layout(s, prop) l, b, w, h = inkRect + if (x + w > self.width or y + h > self.height): + return + self.gdkDrawable.draw_layout(gc.gdkGC, x, y-h-b, layout) @@ -225,10 +228,8 @@ def _draw_rotated_text(self, gc, x, y, s, prop, angle): x = int(x-h) y = int(y-w) - if x < 0 or y < 0: # window has shrunk and text is off the edge - return - - if x + w > self.width or y + h > self.height: + if (x < 0 or y < 0 or: # window has shrunk and text is off the edge + x + w > self.width or y + h > self.height): return key = (x,y,s,angle,hash(prop))