]> Pileus Git - ~andy/gtk/commitdiff
Fix quadratic implementation of gdk_pango_layout_get_clip_region into a
authorBehdad Esfahbod <behdad@gnome.org>
Sat, 8 Jul 2006 22:58:06 +0000 (22:58 +0000)
committerBehdad Esfahbod <behdad@src.gnome.org>
Sat, 8 Jul 2006 22:58:06 +0000 (22:58 +0000)
2006-07-08  Behdad Esfahbod  <behdad@gnome.org>

        * gdk/gdkpango.c (layout_iter_get_line_clip_region),
        (gdk_pango_layout_line_get_clip_region),
        (gdk_pango_layout_get_clip_region): Fix quadratic implementation of
        gdk_pango_layout_get_clip_region into a linear one. (#337910, patch
        by Priit Laes)

ChangeLog
ChangeLog.pre-2-10
gdk/gdkpango.c

index 10fe7ce72d911c4724123804271b895f92efbaa7..9789a98844ab2eab869dc6d6ec546e748faab866 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-07-08  Behdad Esfahbod  <behdad@gnome.org>
+
+       * gdk/gdkpango.c (layout_iter_get_line_clip_region),
+       (gdk_pango_layout_line_get_clip_region),
+       (gdk_pango_layout_get_clip_region): Fix quadratic implementation of
+       gdk_pango_layout_get_clip_region into a linear one. (#337910, patch
+       by Priit Laes)
+
 2006-07-07  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkevents-quartz.c: Generate a grab broken event when
index 10fe7ce72d911c4724123804271b895f92efbaa7..9789a98844ab2eab869dc6d6ec546e748faab866 100644 (file)
@@ -1,3 +1,11 @@
+2006-07-08  Behdad Esfahbod  <behdad@gnome.org>
+
+       * gdk/gdkpango.c (layout_iter_get_line_clip_region),
+       (gdk_pango_layout_line_get_clip_region),
+       (gdk_pango_layout_get_clip_region): Fix quadratic implementation of
+       gdk_pango_layout_get_clip_region into a linear one. (#337910, patch
+       by Priit Laes)
+
 2006-07-07  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkevents-quartz.c: Generate a grab broken event when
index 646beb07c467bcbb5ebd122c3114bdba3966bf5f..43d2a18b790a33282a931b4c14042aee901011ce 100644 (file)
@@ -1220,6 +1220,63 @@ gdk_pango_attr_embossed_new (gboolean embossed)
  * 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 (PangoLayoutLine *line,
                                        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;
+  clip_region = layout_iter_get_line_clip_region(iter, x_origin, y_origin, index_ranges, n_ranges);
 
-      /* 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;
-    }
+  pango_layout_iter_free (iter);
 
   return clip_region;
 }
@@ -1356,16 +1371,14 @@ gdk_pango_layout_get_clip_region (PangoLayout *layout,
       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);