Index: gdk/gdkpango.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkpango.c,v
retrieving revision 1.50
diff -u -w -p -r1.50 gdkpango.c
--- gdk/gdkpango.c	20 Feb 2006 17:17:09 -0000	1.50
+++ gdk/gdkpango.c	22 Mar 2006 19:47:30 -0000
@@ -852,6 +852,55 @@ release_renderer (PangoRenderer *rendere
   gdk_pango_renderer_set_gc (gdk_renderer, NULL);
 }
 
+/* Gets the bounds of a layout in device coordinates. Note cut-and-paste
+ * between here and gtklabel.c */
+static void
+get_rotated_layout_line_bounds (PangoLayoutLine *line,
+				GdkRectangle	*rect)
+{
+  PangoContext *context = pango_layout_get_context (layout->line);
+  const PangoMatrix *matrix = pango_context_get_matrix (context);
+  gdouble x_min = 0, x_max = 0, y_min = 0, y_max = 0; /* quiet gcc */
+  PangoRectangle logical_rect;
+  gint i, j;
+
+  pango_layout_line_get_extents (line, NULL, &logical_rect);
+  
+  for (i = 0; i < 2; i++)
+    {
+      gdouble x = (i == 0) ? logical_rect.x : logical_rect.x + logical_rect.width;
+      for (j = 0; j < 2; j++)
+	{
+	  gdouble y = (j == 0) ? logical_rect.y : logical_rect.y + logical_rect.height;
+	  
+	  gdouble xt = (x * matrix->xx + y * matrix->xy) / PANGO_SCALE + matrix->x0;
+	  gdouble yt = (x * matrix->yx + y * matrix->yy) / PANGO_SCALE + matrix->y0;
+	  
+	  if (i == 0 && j == 0)
+	    {
+	      x_min = x_max = xt;
+	      y_min = y_max = yt;
+	    }
+	  else
+	    {
+	      if (xt < x_min)
+		x_min = xt;
+	      if (yt < y_min)
+		y_min = yt;
+	      if (xt > x_max)
+		x_max = xt;
+	      if (yt > y_max)
+		y_max = yt;
+	    }
+	}
+    }
+  
+  rect->x = floor (x_min);
+  rect->width = ceil (x_max) - rect->x;
+  rect->y = floor (y_min);
+  rect->height = floor (y_max) - rect->y;
+}
+
 /**
  * gdk_draw_layout_line_with_colors:
  * @drawable:  the drawable on which to draw the line
@@ -898,15 +947,29 @@ gdk_draw_layout_line_with_colors (GdkDra
   if (matrix)
     {
       PangoMatrix tmp_matrix;
+      GdkRectangle rect;
+
+      get_rotated_layout_line_bounds (line, &rect);
       
       tmp_matrix = *matrix;
-      tmp_matrix.x0 = x;
-      tmp_matrix.y0 = y;
+      tmp_matrix.x0 += x - rect.x;
+      tmp_matrix.y0 += y - rect.y;
       pango_renderer_set_matrix (renderer, &tmp_matrix);
 
       x = 0;
       y = 0;
     }
+  /* Fall back to introduce a matrix if the coords would scale out of range */
+  else if (y >= PANGO_PIXELS (G_MAXINT - PANGO_SCALE/2) ||
+	   x >= PANGO_PIXELS (G_MAXINT - PANGO_SCALE/2))
+    {
+      PangoMatrix tmp_matrix = PANGO_MATRIX_INIT;
+      tmp_matrix.x0 += x;
+      tmp_matrix.y0 += y;
+      pango_renderer_set_matrix (renderer, &tmp_matrix);
+      x = 0;
+      y = 0;
+    }
   else
     pango_renderer_set_matrix (renderer, NULL);
 
@@ -1021,6 +1084,17 @@ gdk_draw_layout_with_colors (GdkDrawable
       tmp_matrix.y0 += y - rect.y;
       pango_renderer_set_matrix (renderer, &tmp_matrix);
       
+      x = 0;
+      y = 0;
+    }
+  /* Fall back to introduce a matrix if the coords would scale out of range */
+  else if (y >= PANGO_PIXELS (G_MAXINT - PANGO_SCALE/2) ||
+	   x >= PANGO_PIXELS (G_MAXINT - PANGO_SCALE/2))
+    {
+      PangoMatrix tmp_matrix = PANGO_MATRIX_INIT;
+      tmp_matrix.x0 += x;
+      tmp_matrix.y0 += y;
+      pango_renderer_set_matrix (renderer, &tmp_matrix);
       x = 0;
       y = 0;
     }
Index: gdk/gdkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.c,v
retrieving revision 1.181
diff -u -w -p -r1.181 gdkwindow.c
--- gdk/gdkwindow.c	3 Feb 2006 21:17:34 -0000	1.181
+++ gdk/gdkwindow.c	22 Mar 2006 19:47:31 -0000
@@ -1711,6 +1711,14 @@ gdk_window_draw_glyphs_transformed (GdkD
 	  tmp_matrix.y0 -= y_offset;
 	  matrix = &tmp_matrix;
 	}
+      else if (y_offset >= PANGO_PIXELS (G_MAXINT - PANGO_SCALE/2) ||
+	       x_offset >= PANGO_PIXELS (G_MAXINT - PANGO_SCALE/2))
+	{
+	  tmp_matrix = PANGO_MATRIX_INIT;
+	  tmp_matrix.x0 -= x_offset;
+	  tmp_matrix.y0 -= y_offset;
+	  matrix = &tmp_matrix;
+	}
       else
 	{
 	  x -= x_offset * PANGO_SCALE;
