summaryrefslogtreecommitdiff
path: root/gdk/gdkpango.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-07-08 22:58:06 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-07-08 22:58:06 +0000
commit1f9890c7d815cd69147c979e6555f356e7db84ba (patch)
treefd55b9dadd0aa0664321350a10f3957692e7c238 /gdk/gdkpango.c
parent2fbe2ebc9a400eff74f31254c95d5f6bc8b05454 (diff)
downloadgtk+-1f9890c7d815cd69147c979e6555f356e7db84ba.tar.gz
Fix quadratic implementation of gdk_pango_layout_get_clip_region into a
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)
Diffstat (limited to 'gdk/gdkpango.c')
-rw-r--r--gdk/gdkpango.c115
1 files changed, 64 insertions, 51 deletions
diff --git a/gdk/gdkpango.c b/gdk/gdkpango.c
index 646beb07c4..43d2a18b79 100644
--- a/gdk/gdkpango.c
+++ b/gdk/gdkpango.c
@@ -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);