[pango] PangoLayout: Optimize pango_layout_get_baseline



commit 7721b0bed57038b342655220ad9bc32f4599f174
Author: Timm Bäder <mail baedert org>
Date:   Sat Oct 14 08:48:43 2017 +0200

    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

 pango/pango-layout.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index de2dc87..7129a9d 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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]