summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-07-08 17:29:54 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-07-08 17:29:54 +0000
commitb935a4bd82366ca770be6ce6f64f2aefce8e1a65 (patch)
treeaf9e23f1c1652478e1f4c63185d63175febad7ed
parent35a7c23baabda073fea6da3a593fb718c9ac8c89 (diff)
downloadpango-b935a4bd82366ca770be6ce6f64f2aefce8e1a65.tar.gz
Part of Bug 135683 – Cache glyphstring extents
2006-07-08 Behdad Esfahbod <behdad@gnome.org> Part of Bug 135683 – Cache glyphstring extents * docs/pango-sections.txt: * docs/tmpl/glyphs.sgml: * pango/pango.def: * pango/pango-glyph.h: * pango/glyphstring.c (pango_glyph_string_get_width): New function. Much faster than calling pango_glyph_string_extents and using logical_rect.width. * pango/pango-renderer.c (add_underline), (add_strikethrough), (pango_renderer_draw_layout_line): Use the new function for optimization.
-rw-r--r--ChangeLog16
-rw-r--r--docs/pango-sections.txt1
-rw-r--r--docs/tmpl/glyphs.sgml10
-rw-r--r--pango/fonts.c2
-rw-r--r--pango/glyphstring.c27
-rw-r--r--pango/pango-glyph.h2
-rw-r--r--pango/pango-renderer.c30
-rw-r--r--pango/pango.def1
8 files changed, 71 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index d87e0754..18ad502f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2006-07-08 Behdad Esfahbod <behdad@gnome.org>
+
+ Part of Bug 135683 – Cache glyphstring extents
+
+ * docs/pango-sections.txt:
+ * docs/tmpl/glyphs.sgml:
+ * pango/pango.def:
+ * pango/pango-glyph.h:
+ * pango/glyphstring.c (pango_glyph_string_get_width): New function.
+ Much faster than calling pango_glyph_string_extents and using
+ logical_rect.width.
+
+ * pango/pango-renderer.c (add_underline), (add_strikethrough),
+ (pango_renderer_draw_layout_line): Use the new function for
+ optimization.
+
2006-07-07 Behdad Esfahbod <behdad@gnome.org>
Bug 344766 – Memory leak in get_ruleset() in modules/basic/basic-fc.c
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 9911c811..c27f8fd4 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -98,6 +98,7 @@ pango_glyph_string_set_size
pango_glyph_string_free
pango_glyph_string_extents
pango_glyph_string_extents_range
+pango_glyph_string_get_width
pango_glyph_string_index_to_x
pango_glyph_string_x_to_index
pango_glyph_string_get_logical_widths
diff --git a/docs/tmpl/glyphs.sgml b/docs/tmpl/glyphs.sgml
index b43cbb6a..8292c688 100644
--- a/docs/tmpl/glyphs.sgml
+++ b/docs/tmpl/glyphs.sgml
@@ -382,6 +382,16 @@ The #GObject type for #PangoGlyphString.
@logical_rect:
+<!-- ##### FUNCTION pango_glyph_string_get_width ##### -->
+<para>
+
+</para>
+
+@glyphs:
+@font:
+@Returns:
+
+
<!-- ##### FUNCTION pango_glyph_string_index_to_x ##### -->
<para>
diff --git a/pango/fonts.c b/pango/fonts.c
index bbc70106..392da566 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1210,7 +1210,7 @@ pango_font_get_glyph_extents (PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
- if (G_UNLIKELY (!PANGO_IS_FONT (font)))
+ if (G_UNLIKELY (!font))
{
if (!_pango_warning_history.get_glyph_extents)
diff --git a/pango/glyphstring.c b/pango/glyphstring.c
index c4c5c8cd..82770349 100644
--- a/pango/glyphstring.c
+++ b/pango/glyphstring.c
@@ -264,6 +264,33 @@ pango_glyph_string_extents (PangoGlyphString *glyphs,
}
/**
+ * pango_glyph_string_get_width:
+ * @glyphs: a #PangoGlyphString
+ * @font: a #PangoFont
+ *
+ * Computes the logical width of the glyph string as can also be computed
+ * using pango_glyph_string_extents(). However, since this only computes the
+ * width, it's much faster. This is in fact only a convenience function that
+ * computes the sum of geometry.width for each glyph in the @glyphs.
+ *
+ * Return value: the logical width of the glyph string.
+ *
+ * Since: 1.14
+ */
+int
+pango_glyph_string_get_width (PangoGlyphString *glyphs,
+ PangoFont *font)
+{
+ int i;
+ int width = 0;
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ width += &glyphs->glyphs[i].geometry.width;
+
+ return width;
+}
+
+/**
* pango_glyph_string_get_logical_widths:
* @glyphs: a #PangoGlyphString
* @text: the text corresponding to the glyphs
diff --git a/pango/pango-glyph.h b/pango/pango-glyph.h
index 1195f135..71b6911e 100644
--- a/pango/pango-glyph.h
+++ b/pango/pango-glyph.h
@@ -91,6 +91,8 @@ void pango_glyph_string_extents (PangoGlyphString *glyphs,
PangoFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect);
+int pango_glyph_string_get_width(PangoGlyphString *glyphs,
+ PangoFont *font);
void pango_glyph_string_extents_range (PangoGlyphString *glyphs,
int start,
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index 7f26a950..4c96972a 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -289,8 +289,7 @@ add_underline (PangoRenderer *renderer,
PangoFontMetrics *metrics,
int base_x,
int base_y,
- PangoRectangle *ink_rect,
- PangoRectangle *logical_rect)
+ PangoRectangle *ink_rect)
{
PangoRectangle *current_rect = &state->underline_rect;
PangoRectangle new_rect;
@@ -341,8 +340,7 @@ add_strikethrough (PangoRenderer *renderer,
PangoFontMetrics *metrics,
int base_x,
int base_y,
- PangoRectangle *ink_rect,
- PangoRectangle *logical_rect)
+ PangoRectangle *ink_rect)
{
PangoRectangle *current_rect = &state->strikethrough_rect;
PangoRectangle new_rect;
@@ -450,6 +448,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
int y)
{
int x_off = 0;
+ int glyph_string_width;
LineState state;
GSList *l;
gboolean got_overall = FALSE;
@@ -480,7 +479,6 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
gint rise;
PangoLayoutRun *run = l->data;
PangoAttrShape *shape_attr;
- PangoRectangle logical_rect;
PangoRectangle ink_rect;
pango_renderer_prepare_run (renderer, run);
@@ -490,20 +488,18 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
if (shape_attr)
{
ink_rect = shape_attr->ink_rect;
- logical_rect = shape_attr->logical_rect;
+ glyph_string_width = shape_attr->logical_rect.width;
}
else
{
if (renderer->underline != PANGO_UNDERLINE_NONE ||
renderer->strikethrough)
- pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
- &ink_rect, &logical_rect);
- else
- pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
- NULL, &logical_rect);
+ pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
+ &ink_rect, NULL);
+ glyph_string_width = pango_glyph_string_get_width (run->glyphs, run->item->analysis.font);
}
- state.logical_rect_end = x + x_off + logical_rect.x + logical_rect.width;
+ state.logical_rect_end = x + x_off + glyph_string_width;
if (renderer->priv->color_set[PANGO_RENDER_PART_BACKGROUND])
{
@@ -515,9 +511,9 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
pango_renderer_draw_rectangle (renderer,
PANGO_RENDER_PART_BACKGROUND,
- x + x_off + logical_rect.x,
+ x + x_off,
y - rise + overall_rect.y,
- logical_rect.width,
+ glyph_string_width,
overall_rect.height);
}
@@ -541,12 +537,12 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
if (renderer->underline != PANGO_UNDERLINE_NONE)
add_underline (renderer, &state,metrics,
x + x_off, y - rise,
- &ink_rect, &logical_rect);
+ &ink_rect);
if (renderer->strikethrough)
add_strikethrough (renderer, &state, metrics,
x + x_off, y - rise,
- &ink_rect, &logical_rect);
+ &ink_rect);
pango_font_metrics_unref (metrics);
}
@@ -558,7 +554,7 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer,
if (!renderer->strikethrough && state.strikethrough)
draw_strikethrough (renderer, &state);
- x_off += logical_rect.width;
+ x_off += glyph_string_width;
}
/* Finish off any remaining underlines
diff --git a/pango/pango.def b/pango/pango.def
index 4733905e..bb1a7e60 100644
--- a/pango/pango.def
+++ b/pango/pango.def
@@ -172,6 +172,7 @@ EXPORTS
pango_glyph_string_free
pango_glyph_string_get_logical_widths
pango_glyph_string_get_type
+ pango_glyph_string_get_width
pango_glyph_string_index_to_x
pango_glyph_string_new
pango_glyph_string_set_size