]> Pileus Git - ~andy/gtk/commitdiff
Bug 337603 – Possible off-by-one in
authorBehdad Esfahbod <behdad@gnome.org>
Wed, 7 Jun 2006 01:07:20 +0000 (01:07 +0000)
committerBehdad Esfahbod <behdad@src.gnome.org>
Wed, 7 Jun 2006 01:07:20 +0000 (01:07 +0000)
2006-06-06  Behdad Esfahbod  <behdad@gnome.org>

        Bug 337603 – Possible off-by-one in
        gdk_pango_layout_line_get_clip_region

        * gdk/gdkpango.c (gdk_pango_layout_line_get_clip_region): Correct
        rounding of rect members.  Improved docs.

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

index 3c423ca4d6edb5fde2154d5126370d4c29b4917a..fdfaf9d3543a12552a45dfd5c1ee19923f6472d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-06-06  Behdad Esfahbod  <behdad@gnome.org>
+
+       Bug 337603 – Possible off-by-one in
+       gdk_pango_layout_line_get_clip_region
+
+       * gdk/gdkpango.c (gdk_pango_layout_line_get_clip_region): Correct
+       rounding of rect members.  Improved docs.
+
 2006-06-06  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkicontheme.c: Small optimization
index 3c423ca4d6edb5fde2154d5126370d4c29b4917a..fdfaf9d3543a12552a45dfd5c1ee19923f6472d6 100644 (file)
@@ -1,3 +1,11 @@
+2006-06-06  Behdad Esfahbod  <behdad@gnome.org>
+
+       Bug 337603 – Possible off-by-one in
+       gdk_pango_layout_line_get_clip_region
+
+       * gdk/gdkpango.c (gdk_pango_layout_line_get_clip_region): Correct
+       rounding of rect members.  Improved docs.
+
 2006-06-06  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkicontheme.c: Small optimization
index 34df537f1b3d234ffd057621348381139c55bb75..d054de271744ae618c560a34ca5b92d18bd739e5 100644 (file)
@@ -1238,6 +1238,11 @@ gdk_pango_attr_embossed_new (gboolean embossed)
  * contained inside the line. This is to draw the selection all the way
  * to the side of the layout. However, the clip region is in line coordinates,
  * not layout coordinates.
+ *
+ * Note that the regions returned correspond to logical extents of the text
+ * ranges, not ink extents. So the drawn line may in fact touch areas out of
+ * the clip region.  The clip region is mainly useful for highlightling parts
+ * of text, such as when text is selected.
  * 
  * Return value: a clip region containing the given ranges
  **/
@@ -1287,12 +1292,16 @@ gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line,
       for (j = 0; j < n_pixel_ranges; j++)
         {
           GdkRectangle rect;
+         int x_off, y_off;
           
-          rect.x = x_origin + pixel_ranges[2*j] / PANGO_SCALE - logical_rect.x / PANGO_SCALE;
-          rect.y = y_origin - (baseline / PANGO_SCALE - logical_rect.y / PANGO_SCALE);
-          rect.width = (pixel_ranges[2*j + 1] - pixel_ranges[2*j]) / PANGO_SCALE;
-          rect.height = logical_rect.height / PANGO_SCALE;
-          
+          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);
         }
 
@@ -1316,6 +1325,11 @@ gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line,
  * you would pass to gdk_draw_layout_line(). @index_ranges should contain
  * ranges of bytes in the layout's text.
  * 
+ * Note that the regions returned correspond to logical extents of the text
+ * ranges, not ink extents. So the drawn line may in fact touch areas out of
+ * the clip region.  The clip region is mainly useful for highlightling parts
+ * of text, such as when text is selected.
+ * 
  * Return value: a clip region containing the given ranges
  **/
 GdkRegion*