pango: make merge_attrs return the merged list
authorPaolo Borelli <pborelli@gnome.org>
Sun, 5 Jul 2015 22:20:08 +0000 (00:20 +0200)
committerPaolo Borelli <pborelli@gnome.org>
Sun, 5 Jul 2015 22:31:56 +0000 (00:31 +0200)
This simplifies all the callers

gtk/gtkentry.c
gtk/gtklabel.c
gtk/gtkpango.c
gtk/gtkpango.h

index af876dbca4c28162f416607df2c4d58951836bb8..9d768c40ccf673aa61c4a125543eb504c80d302a 100644 (file)
@@ -6253,7 +6253,6 @@ gtk_entry_create_layout (GtkEntry *entry,
   GtkWidget *widget = GTK_WIDGET (entry);
   GtkStyleContext *context;
   PangoLayout *layout;
-  PangoAttrList *style_attrs;
   PangoAttrList *tmp_attrs;
   gboolean placeholder_layout;
 
@@ -6269,13 +6268,10 @@ gtk_entry_create_layout (GtkEntry *entry,
   layout = gtk_widget_create_pango_layout (widget, NULL);
   pango_layout_set_single_paragraph_mode (layout, TRUE);
 
-  style_attrs = _gtk_style_context_get_pango_attributes (context);
-  tmp_attrs = style_attrs ? style_attrs : pango_attr_list_new ();
-
-  if (priv->attrs)
-    {
-      _gtk_pango_attr_list_merge (tmp_attrs, priv->attrs);
-    }
+  tmp_attrs = _gtk_style_context_get_pango_attributes (context);
+  tmp_attrs = _gtk_pango_attr_list_merge (tmp_attrs, priv->attrs);
+  if (!tmp_attrs)
+    tmp_attrs = pango_attr_list_new ();
 
   placeholder_layout = show_placeholder_text (entry);
   if (placeholder_layout)
index 92b8ee9e8e3bb4e1c00cbc9d36ab86f93f807938..fd8da418660530833da9f758b03145224187289d 100644 (file)
@@ -3465,36 +3465,17 @@ gtk_label_update_layout_attributes (GtkLabel *label)
     attrs = NULL;
 
   style_attrs = _gtk_style_context_get_pango_attributes (context);
-  if (style_attrs)
-    {
-      if (attrs)
-        _gtk_pango_attr_list_merge (attrs, style_attrs);
-      else
-        attrs = pango_attr_list_ref (style_attrs);
 
-      pango_attr_list_unref (style_attrs);
-    }
-
-  if (priv->markup_attrs)
-    {
-      if (attrs)
-        _gtk_pango_attr_list_merge (attrs, priv->markup_attrs);
-      else
-        attrs = pango_attr_list_ref (priv->markup_attrs);
-    }
-
-  if (priv->attrs)
-    {
-      if (attrs)
-        _gtk_pango_attr_list_merge (attrs, priv->attrs);
-      else
-        attrs = pango_attr_list_ref (priv->attrs);
-    }
+  attrs = _gtk_pango_attr_list_merge (attrs, style_attrs);
+  attrs = _gtk_pango_attr_list_merge (attrs, priv->markup_attrs);
+  attrs = _gtk_pango_attr_list_merge (attrs, priv->attrs);
 
   pango_layout_set_attributes (priv->layout, attrs);
 
   if (attrs)
     pango_attr_list_unref (attrs);
+  if (style_attrs)
+    pango_attr_list_unref (style_attrs);
 }
 
 static void
index 261fac7c3d060b6aae536754b725307a5153309b..63d445f385c2db926157ef093dfd0f0f629017b9 100644 (file)
@@ -1300,14 +1300,24 @@ attr_list_merge_filter (PangoAttribute *attribute,
 
 /*
  * _gtk_pango_attr_list_merge:
- * @into: a #PangoAttrList where attributes are merged.
- * @from: a #PangoAttrList with the attributes to merge
+ * @into: a #PangoAttrList where attributes are merged or %NULL
+ * @from: a #PangoAttrList with the attributes to merge or %NULL
  *
  * Merges attributes from @from into @into.
+ *
+ * Returns: the merged list.
  */
-void
+PangoAttrList *
 _gtk_pango_attr_list_merge (PangoAttrList *into,
                             PangoAttrList *from)
 {
-  pango_attr_list_filter (from, attr_list_merge_filter, into);
+  if (from)
+    {
+      if (into)
+        pango_attr_list_filter (from, attr_list_merge_filter, into);
+      else
+       return pango_attr_list_ref (from);
+    }
+
+  return into;
 }
index f5383372a58687be480dea58fcfa3b870fdd422b..0d6e6c00d02320c941490f35de76f27e8b3dd48f 100644 (file)
@@ -79,8 +79,8 @@ gchar *_gtk_pango_get_text_after  (PangoLayout     *layout,
                                    gint            *start_offset,
                                    gint            *end_offset);
 
-void _gtk_pango_attr_list_merge   (PangoAttrList *into,
-                                   PangoAttrList *from);
+PangoAttrList *_gtk_pango_attr_list_merge (PangoAttrList *into,
+                                           PangoAttrList *from);
 
 G_END_DECLS