summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2017-10-14 08:48:43 +0200
committerMatthias Clasen <mclasen@redhat.com>2017-10-27 16:29:14 -0400
commit7721b0bed57038b342655220ad9bc32f4599f174 (patch)
treeddcd5f849c116b189142b3d7e379658f47ab7738
parent0d14052d719274e586176280b3c98dd54fcf8764 (diff)
downloadpango-7721b0bed57038b342655220ad9bc32f4599f174.tar.gz
PangoLayout: Optimize pango_layout_get_baseline
The baseline is the baseline of the first line of text in the layout, so we can simply _get_extents_internal and use the extents of the first line we get from that. This is not a perfect solution (e.g. gtk+ calls pango_layout_get_extents before a pango_layout_get_baseline call and the former calls get_extents_internal anyway, so we compute the extents twice...) but it improves the situation pointed out by the comment in pango_layout_get_baseline. https://bugzilla.gnome.org/show_bug.cgi?id=788643
-rw-r--r--pango/pango-layout.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index de2dc87d..7129a9d0 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -2829,12 +2829,13 @@ int
pango_layout_get_baseline (PangoLayout *layout)
{
int baseline;
- PangoLayoutIter iter;
+ Extents *extents = NULL;
- /* XXX this is so inefficient */
- _pango_layout_get_iter (layout, &iter);
- baseline = pango_layout_iter_get_baseline (&iter);
- _pango_layout_iter_destroy (&iter);
+ /* XXX this is kinda inefficient */
+ pango_layout_get_extents_internal (layout, NULL, NULL, &extents);
+ baseline = extents ? extents[0].baseline : 0;
+
+ g_free (extents);
return baseline;
}