Index: gdkpango.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkpango.c,v
retrieving revision 1.56
diff -u -p -d -r1.56 gdkpango.c
--- gdkpango.c	7 Jun 2006 01:08:16 -0000	1.56
+++ gdkpango.c	8 Jul 2006 20:27:06 -0000
@@ -1220,6 +1220,63 @@ gdk_pango_attr_embossed_new (gboolean em
  * region which contains the given ranges, i.e. if you draw with the
  * region as clip, only the given ranges are drawn.
  */
+static GdkRegion*
+layout_iter_get_line_clip_region (PangoLayoutIter *iter,
+				  gint             x_origin,
+				  gint             y_origin,
+				  gint            *index_ranges,
+				  gint             n_ranges)
+{
+  PangoLayoutLine *line;
+  GdkRegion *clip_region;
+  PangoRectangle logical_rect;
+  gint baseline;
+  gint i;
+
+  line = pango_layout_iter_get_line (iter);
+
+  clip_region = gdk_region_new ();
+
+  pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
+  baseline = pango_layout_iter_get_baseline (iter);
+
+  i = 0;
+  while (i < n_ranges)
+    {  
+      gint *pixel_ranges = NULL;
+      gint n_pixel_ranges = 0;
+      gint j;
+
+      /* Note that get_x_ranges returns layout coordinates
+       */
+      if (index_ranges[i*2+1] >= line->start_index &&
+	  index_ranges[i*2] < line->start_index + line->length)
+	pango_layout_line_get_x_ranges (line,
+					index_ranges[i*2],
+					index_ranges[i*2+1],
+					&pixel_ranges, &n_pixel_ranges);
+  
+      for (j = 0; j < n_pixel_ranges; j++)
+        {
+          GdkRectangle rect;
+	  int x_off, y_off;
+          
+          x_off = PANGO_PIXELS (pixel_ranges[2*j] - logical_rect.x);
+	  y_off = PANGO_PIXELS (baseline - logical_rect.y);
+
+          rect.x = x_origin + x_off;
+          rect.y = y_origin - y_off;
+          rect.width = PANGO_PIXELS (pixel_ranges[2*j + 1] - logical_rect.x) - x_off;
+          rect.height = PANGO_PIXELS (baseline - logical_rect.y + logical_rect.height) - y_off;
+
+          gdk_region_union_with_rect (clip_region, &rect);
+        }
+
+      g_free (pixel_ranges);
+      ++i;
+    }
+  return clip_region;
+}
 
 /**
  * gdk_pango_layout_line_get_clip_region:
@@ -1254,60 +1311,18 @@ gdk_pango_layout_line_get_clip_region (P
                                        gint             n_ranges)
 {
   GdkRegion *clip_region;
-  gint i;
-  PangoRectangle logical_rect;
   PangoLayoutIter *iter;
-  gint baseline;
   
   g_return_val_if_fail (line != NULL, NULL);
   g_return_val_if_fail (index_ranges != NULL, NULL);
   
-  clip_region = gdk_region_new ();
-
   iter = pango_layout_get_iter (line->layout);
   while (pango_layout_iter_get_line (iter) != line)
     pango_layout_iter_next_line (iter);
   
-  pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
-  baseline = pango_layout_iter_get_baseline (iter);
-  
-  pango_layout_iter_free (iter);
-  
-  i = 0;
-  while (i < n_ranges)
-    {  
-      gint *pixel_ranges = NULL;
-      gint n_pixel_ranges = 0;
-      gint j;
-
-      /* Note that get_x_ranges returns layout coordinates
-       */
-      if (index_ranges[i*2+1] >= line->start_index &&
-	  index_ranges[i*2] < line->start_index + line->length)
-	pango_layout_line_get_x_ranges (line,
-					index_ranges[i*2],
-					index_ranges[i*2+1],
-					&pixel_ranges, &n_pixel_ranges);
-  
-      for (j = 0; j < n_pixel_ranges; j++)
-        {
-          GdkRectangle rect;
-	  int x_off, y_off;
-          
-          x_off = PANGO_PIXELS (pixel_ranges[2*j] - logical_rect.x);
-	  y_off = PANGO_PIXELS (baseline - logical_rect.y);
-
-          rect.x = x_origin + x_off;
-          rect.y = y_origin - y_off;
-          rect.width = PANGO_PIXELS (pixel_ranges[2*j + 1] - logical_rect.x) - x_off;
-          rect.height = PANGO_PIXELS (baseline - logical_rect.y + logical_rect.height) - y_off;
-
-          gdk_region_union_with_rect (clip_region, &rect);
-        }
+  clip_region = layout_iter_get_line_clip_region(iter, x_origin, y_origin, index_ranges, n_ranges);
 
-      g_free (pixel_ranges);
-      ++i;
-    }
+  pango_layout_iter_free (iter);
 
   return clip_region;
 }
@@ -1356,16 +1371,14 @@ gdk_pango_layout_get_clip_region (PangoL
       GdkRegion *line_region;
       gint baseline;
       
-      line = pango_layout_iter_get_line (iter);      
-
       pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
       baseline = pango_layout_iter_get_baseline (iter);      
 
-      line_region = gdk_pango_layout_line_get_clip_region (line,
-                                                           x_origin + logical_rect.x / PANGO_SCALE,
-                                                           y_origin + baseline / PANGO_SCALE,
-                                                           index_ranges,
-                                                           n_ranges);
+      line_region = layout_iter_get_line_clip_region(iter, 
+						     x_origin + logical_rect.x / PANGO_SCALE,
+						     y_origin + baseline / PANGO_SCALE,
+						     index_ranges,
+						     n_ranges);
 
       gdk_region_union (clip_region, line_region);
       gdk_region_destroy (line_region);
