[pango/run-attributes: 5/6] test-itemize: Match PangoLayout



commit 23aca088a2c0beff648f83c9909e45ee01c597b8
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 24 15:52:26 2019 -0400

    test-itemize: Match PangoLayout
    
    Use the same logic as PangoLayout for
    filtering attributes.
    
    Update expected output to match.

 tests/itemize/two.expected | 12 +++++-----
 tests/test-itemize.c       | 60 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 7 deletions(-)
---
diff --git a/tests/itemize/two.expected b/tests/itemize/two.expected
index 57446958..ebe9757c 100644
--- a/tests/itemize/two.expected
+++ b/tests/itemize/two.expected
@@ -1,8 +1,8 @@
 <span font="Cantarell 11">one <span font_features="tnum=0">tw<u>o</u> <span 
font_features="dlig=1">two</span> </span>th<b>r</b>ee</span>
 
-Items:  one         |tw                        |o                                          |                 
         |two                                                  |                          |th          |r     
           |ee          
-Font:   Cantarell 11|Cantarell 11              |Cantarell 11                               |Cantarell 11     
         |Cantarell 11                                         |Cantarell 11              |Cantarell 
11|Cantarell Bold 11|Cantarell 11
-Script: latin       |latin                     |latin                                      |latin            
         |latin                                                |latin                     |latin       |latin 
           |latin       
-Lang:   en-us       |en-us                     |en-us                                      |en-us            
         |en-us                                                |en-us                     |en-us       |en-us 
           |en-us       
-Bidi:   0           |0                         |0                                          |0                
         |0                                                    |0                         |0           |0     
           |0           
-Attrs:              
|[4,12]font-features=tnum=0|[4,12]font-features=tnum=0,[6,7]underline=1|[4,12]font-features=tnum=0|[4,12]font-features=tnum=0,[8,11]font-features=dlig=1|[4,12]font-features=tnum=0|
            |                 |            
+Items:  one tw                    |o                                          | two th                       
                       |r                |ee          
+Font:   Cantarell 11              |Cantarell 11                               |Cantarell 11                  
                       |Cantarell Bold 11|Cantarell 11
+Script: latin                     |latin                                      |latin                         
                       |latin            |latin       
+Lang:   en-us                     |en-us                                      |en-us                         
                       |en-us            |en-us       
+Bidi:   0                         |0                                          |0                             
                       |0                |0           
+Attrs:  
[4,12]font-features=tnum=0|[6,7]underline=1,[4,12]font-features=tnum=0|[8,11]font-features=dlig=1,[4,12]font-features=tnum=0|
                 |            
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index 8ddf2ec9..d66c40d1 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -51,6 +51,59 @@ append_text (GString    *s,
     }
 }
 
+static gboolean
+affects_itemization (PangoAttribute *attr,
+                     gpointer        data)
+{
+  switch (attr->klass->type)
+    {
+    /* These affect font selection */
+    case PANGO_ATTR_LANGUAGE:
+    case PANGO_ATTR_FAMILY:
+    case PANGO_ATTR_STYLE:
+    case PANGO_ATTR_WEIGHT:
+    case PANGO_ATTR_VARIANT:
+    case PANGO_ATTR_STRETCH:
+    case PANGO_ATTR_SIZE:
+    case PANGO_ATTR_FONT_DESC:
+    case PANGO_ATTR_SCALE:
+    case PANGO_ATTR_FALLBACK:
+    case PANGO_ATTR_ABSOLUTE_SIZE:
+    case PANGO_ATTR_GRAVITY:
+    case PANGO_ATTR_GRAVITY_HINT:
+    /* These are part of ItemProperties, so need to break runs */
+    case PANGO_ATTR_SHAPE:
+    case PANGO_ATTR_RISE:
+    case PANGO_ATTR_UNDERLINE:
+    case PANGO_ATTR_STRIKETHROUGH:
+    case PANGO_ATTR_LETTER_SPACING:
+      return TRUE;
+    default:
+      return FALSE;
+    }
+}
+
+static void
+apply_attributes_to_items (GList         *items,
+                           PangoAttrList *attrs)
+{
+  GList *l;
+  PangoAttrIterator *iter;
+
+  if (!attrs)
+    return;
+
+  iter = pango_attr_list_get_iterator (attrs);
+
+  for (l = items; l; l = l->next)
+    {
+      PangoItem *item = l->data;
+      pango_item_apply_attrs (item, iter);
+    }
+
+  pango_attr_iterator_destroy (iter);
+}
+
 static void
 test_file (const gchar *filename, GString *string)
 {
@@ -61,6 +114,7 @@ test_file (const gchar *filename, GString *string)
   char *test;
   char *text;
   PangoAttrList *attrs;
+  PangoAttrList *itemize_attrs;
   GList *items, *l;
   const char *sep = "";
 
@@ -96,7 +150,11 @@ test_file (const gchar *filename, GString *string)
   if (text[length - 1] == '\n')
     length--;
 
-  items = pango_itemize (context, text, 0, length, attrs, NULL);
+  itemize_attrs = pango_attr_list_filter (attrs, affects_itemization, NULL);
+  items = pango_itemize (context, text, 0, length, itemize_attrs, NULL);
+
+  apply_attributes_to_items (items, attrs);
+  pango_attr_list_unref (itemize_attrs);
 
   for (l = items; l; l = l->next)
     {


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