[pango/better-ellipsize] ellipsize: Try harder to find the right font




commit 071a266ce1d03de05a9ba8be46282580863606c4
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 21 21:37:17 2021 -0400

    ellipsize: Try harder to find the right font
    
    When ellipsizing, we were using pango_attr_iterator_get_attrs
    to reconstitute the attribute list for the ellipsized range,
    but this does not merge font description attributes like we
    do when we shape the text without ellipsization. So, use
    pango_attr_iterator_get_font to obtain a merged font
    description, and use that instead.
    
    Fixes: #575

 pango/ellipsize.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index e05277f6..cb002059 100644
--- a/pango/ellipsize.c
+++ b/pango/ellipsize.c
@@ -309,6 +309,7 @@ shape_ellipsis (EllipsizeState *state)
   const char *ellipsis_text;
   int len;
   int i;
+  PangoFontDescription *desc;
 
   _pango_attr_list_init (&attrs);
 
@@ -329,7 +330,16 @@ shape_ellipsis (EllipsizeState *state)
 
   /* Create an attribute list
    */
-  run_attrs = pango_attr_iterator_get_attrs (state->gap_start_attr);
+  desc = pango_font_description_new ();
+  pango_attr_iterator_get_font (state->gap_start_attr, desc, NULL, &run_attrs);
+  if (pango_font_description_get_set_fields (desc) != 0)
+    {
+      PangoAttribute *attr = pango_attr_font_desc_new (desc);
+      attr->start_index = 0;
+      attr->end_index = G_MAXINT;
+
+      pango_attr_list_insert (&attrs, attr);
+    }
   for (l = run_attrs; l; l = l->next)
     {
       PangoAttribute *attr = l->data;
@@ -338,6 +348,7 @@ shape_ellipsis (EllipsizeState *state)
 
       pango_attr_list_insert (&attrs, attr);
     }
+  pango_font_description_free (desc);
 
   g_slist_free (run_attrs);
 


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