[pango/pango2: 8/168] Change color attr api




commit b2a5ca030686e61759129ecc1fde5e55baa95d4f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Feb 6 22:53:55 2022 -0500

    Change color attr api
    
    Make pango_attr_{fore,back}ground_new take a PangoColor*.
    Update all callers.

 pango/pango-attr-list.c  |  2 +-
 pango/pango-attributes.c | 60 +++++++++++++++---------------------------------
 pango/pango-attributes.h | 22 +++++-------------
 pango/pango-markup.c     | 10 ++++----
 pango/serializer.c       | 10 ++++----
 tests/testattributes.c   | 20 ++++++++--------
 tests/testmisc.c         |  2 +-
 7 files changed, 46 insertions(+), 80 deletions(-)
---
diff --git a/pango/pango-attr-list.c b/pango/pango-attr-list.c
index d5e7eeb1..4c46cbc8 100644
--- a/pango/pango-attr-list.c
+++ b/pango/pango-attr-list.c
@@ -1070,7 +1070,7 @@ pango_attr_list_from_string (const char *text)
               g_free (str); \
               goto fail; \
             } \
-          attr = pango_attr_##name##_new (color.red, color.green, color.blue); \
+          attr = pango_attr_##name##_new (&color); \
           g_free (str);
 
       switch (attr_type)
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 1424bb3f..5a514053 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -98,19 +98,15 @@ pango_attr_float_new (PangoAttrType type,
 }
 
 static inline PangoAttribute *
-pango_attr_color_new (PangoAttrType type,
-                      guint16       red,
-                      guint16       green,
-                      guint16       blue)
+pango_attr_color_new (PangoAttrType  type,
+                      PangoColor    *color)
 {
   PangoAttribute *attr;
 
   g_return_val_if_fail (PANGO_ATTR_TYPE_VALUE_TYPE (type) == PANGO_ATTR_VALUE_COLOR, NULL);
 
   attr = pango_attr_init (type);
-  attr->color_value.red = red;
-  attr->color_value.green = green;
-  attr->color_value.blue = blue;
+  attr->color_value = *color;
 
   return attr;
 }
@@ -180,9 +176,7 @@ pango_attr_language_new (PangoLanguage *language)
 
 /**
  * pango_attr_foreground_new:
- * @red: the red value (ranging from 0 to 65535)
- * @green: the green value
- * @blue: the blue value
+ * @color: the color
  *
  * Create a new foreground color attribute.
  *
@@ -191,18 +185,14 @@ pango_attr_language_new (PangoLanguage *language)
  *   [method@Pango.Attribute.destroy]
  */
 PangoAttribute *
-pango_attr_foreground_new (guint16 red,
-                           guint16 green,
-                           guint16 blue)
+pango_attr_foreground_new (PangoColor *color)
 {
-  return pango_attr_color_new (PANGO_ATTR_FOREGROUND, red, green, blue);
+  return pango_attr_color_new (PANGO_ATTR_FOREGROUND, color);
 }
 
 /**
  * pango_attr_background_new:
- * @red: the red value (ranging from 0 to 65535)
- * @green: the green value
- * @blue: the blue value
+ * @color: the color
  *
  * Create a new background color attribute.
  *
@@ -211,11 +201,9 @@ pango_attr_foreground_new (guint16 red,
  *   [method@Pango.Attribute.destroy]
  */
 PangoAttribute *
-pango_attr_background_new (guint16 red,
-                           guint16 green,
-                           guint16 blue)
+pango_attr_background_new (PangoColor *color)
 {
-  return pango_attr_color_new (PANGO_ATTR_BACKGROUND, red, green, blue);
+  return pango_attr_color_new (PANGO_ATTR_BACKGROUND, color);
 }
 
 /**
@@ -353,9 +341,7 @@ pango_attr_underline_new (PangoUnderline underline)
 
 /**
  * pango_attr_underline_color_new:
- * @red: the red value (ranging from 0 to 65535)
- * @green: the green value
- * @blue: the blue value
+ * @color: the color
  *
  * Create a new underline color attribute.
  *
@@ -369,11 +355,9 @@ pango_attr_underline_new (PangoUnderline underline)
  * Since: 1.8
  */
 PangoAttribute *
-pango_attr_underline_color_new (guint16 red,
-                                guint16 green,
-                                guint16 blue)
+pango_attr_underline_color_new (PangoColor *color)
 {
-  return pango_attr_color_new (PANGO_ATTR_UNDERLINE_COLOR, red, green, blue);
+  return pango_attr_color_new (PANGO_ATTR_UNDERLINE_COLOR, color);
 }
 
 /**
@@ -394,9 +378,7 @@ pango_attr_strikethrough_new (gboolean strikethrough)
 
 /**
  * pango_attr_strikethrough_color_new:
- * @red: the red value (ranging from 0 to 65535)
- * @green: the green value
- * @blue: the blue value
+ * @color: the color
  *
  * Create a new strikethrough color attribute.
  *
@@ -410,11 +392,9 @@ pango_attr_strikethrough_new (gboolean strikethrough)
  * Since: 1.8
  */
 PangoAttribute *
-pango_attr_strikethrough_color_new (guint16 red,
-                                    guint16 green,
-                                    guint16 blue)
+pango_attr_strikethrough_color_new (PangoColor *color)
 {
-  return pango_attr_color_new (PANGO_ATTR_STRIKETHROUGH_COLOR, red, green, blue);
+  return pango_attr_color_new (PANGO_ATTR_STRIKETHROUGH_COLOR, color);
 }
 
 /**
@@ -786,9 +766,7 @@ pango_attr_overline_new (PangoOverline overline)
 
 /**
  * pango_attr_overline_color_new:
- * @red: the red value (ranging from 0 to 65535)
- * @green: the green value
- * @blue: the blue value
+ * @color: the color
  *
  * Create a new overline color attribute.
  *
@@ -802,11 +780,9 @@ pango_attr_overline_new (PangoOverline overline)
  * Since: 1.46
  */
 PangoAttribute *
-pango_attr_overline_color_new (guint16 red,
-                               guint16 green,
-                               guint16 blue)
+pango_attr_overline_color_new (PangoColor *color)
 {
-  return pango_attr_color_new (PANGO_ATTR_OVERLINE_COLOR, red, green, blue);
+  return pango_attr_color_new (PANGO_ATTR_OVERLINE_COLOR, color);
 }
 
 /**
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index 908cc194..954cda83 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -128,13 +128,9 @@ PangoAttribute *        pango_attr_language_new                 (PangoLanguage
 PANGO_AVAILABLE_IN_ALL
 PangoAttribute *        pango_attr_family_new                   (const char                 *family);
 PANGO_AVAILABLE_IN_ALL
-PangoAttribute *        pango_attr_foreground_new               (guint16                     red,
-                                                                 guint16                     green,
-                                                                 guint16                     blue);
+PangoAttribute *        pango_attr_foreground_new               (PangoColor                 *color);
 PANGO_AVAILABLE_IN_ALL
-PangoAttribute *        pango_attr_background_new               (guint16                     red,
-                                                                 guint16                     green,
-                                                                 guint16                     blue);
+PangoAttribute *        pango_attr_background_new               (PangoColor                 *color);
 PANGO_AVAILABLE_IN_ALL
 PangoAttribute *        pango_attr_size_new                     (int                         size);
 PANGO_AVAILABLE_IN_1_8
@@ -196,15 +192,11 @@ typedef enum {
 PANGO_AVAILABLE_IN_ALL
 PangoAttribute *        pango_attr_underline_new                (PangoUnderline              underline);
 PANGO_AVAILABLE_IN_1_8
-PangoAttribute *        pango_attr_underline_color_new          (guint16                     red,
-                                                                 guint16                     green,
-                                                                 guint16                     blue);
+PangoAttribute *        pango_attr_underline_color_new          (PangoColor                 *color);
 PANGO_AVAILABLE_IN_ALL
 PangoAttribute *        pango_attr_strikethrough_new            (gboolean                    strikethrough);
 PANGO_AVAILABLE_IN_1_8
-PangoAttribute *        pango_attr_strikethrough_color_new      (guint16                     red,
-                                                                 guint16                     green,
-                                                                 guint16                     blue);
+PangoAttribute *        pango_attr_strikethrough_color_new      (PangoColor                 *color);
 PANGO_AVAILABLE_IN_ALL
 PangoAttribute *        pango_attr_rise_new                     (int                         rise);
 
@@ -295,11 +287,9 @@ typedef enum {
 } PangoOverline;
 
 PANGO_AVAILABLE_IN_1_46
-PangoAttribute *        pango_attr_overline_new                 (PangoOverline                overline);
+PangoAttribute *        pango_attr_overline_new                 (PangoOverline               overline);
 PANGO_AVAILABLE_IN_1_46
-PangoAttribute *        pango_attr_overline_color_new           (guint16                      red,
-                                                                 guint16                      green,
-                                                                 guint16                      blue);
+PangoAttribute *        pango_attr_overline_color_new           (PangoColor                 *color);
 
 /**
  * PangoShowFlags:
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 7caf86f5..b84a0cad 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -1499,7 +1499,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       if (!span_parse_color ("foreground", foreground, &color, &alpha, line_number, error))
        goto error;
 
-      add_attribute (tag, pango_attr_foreground_new (color.red, color.green, color.blue));
+      add_attribute (tag, pango_attr_foreground_new (&color));
       if (alpha != 0xffff)
         add_attribute (tag, pango_attr_foreground_alpha_new (alpha));
     }
@@ -1512,7 +1512,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       if (!span_parse_color ("background", background, &color, &alpha, line_number, error))
        goto error;
 
-      add_attribute (tag, pango_attr_background_new (color.red, color.green, color.blue));
+      add_attribute (tag, pango_attr_background_new (&color));
       if (alpha != 0xffff)
         add_attribute (tag, pango_attr_background_alpha_new (alpha));
     }
@@ -1554,7 +1554,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       if (!span_parse_color ("underline_color", underline_color, &color, NULL, line_number, error))
        goto error;
 
-      add_attribute (tag, pango_attr_underline_color_new (color.red, color.green, color.blue));
+      add_attribute (tag, pango_attr_underline_color_new (&color));
     }
 
   if (G_UNLIKELY (overline))
@@ -1574,7 +1574,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       if (!span_parse_color ("overline_color", overline_color, &color, NULL, line_number, error))
        goto error;
 
-      add_attribute (tag, pango_attr_overline_color_new (color.red, color.green, color.blue));
+      add_attribute (tag, pango_attr_overline_color_new (&color));
     }
 
   if (G_UNLIKELY (gravity))
@@ -1627,7 +1627,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       if (!span_parse_color ("strikethrough_color", strikethrough_color, &color, NULL, line_number, error))
        goto error;
 
-      add_attribute (tag, pango_attr_strikethrough_color_new (color.red, color.green, color.blue));
+      add_attribute (tag, pango_attr_strikethrough_color_new (&color));
     }
 
   if (G_UNLIKELY (fallback))
diff --git a/pango/serializer.c b/pango/serializer.c
index 43897b95..c37744f9 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -986,12 +986,12 @@ attr_for_type (GtkJsonParser *parser,
 
     case PANGO_ATTR_FOREGROUND:
       parser_get_color (parser, &color);
-      attr = pango_attr_foreground_new (color.red, color.green, color.blue);
+      attr = pango_attr_foreground_new (&color);
       break;
 
     case PANGO_ATTR_BACKGROUND:
       parser_get_color (parser, &color);
-      attr = pango_attr_background_new (color.red, color.green, color.blue);
+      attr = pango_attr_background_new (&color);
       break;
 
     case PANGO_ATTR_UNDERLINE:
@@ -1020,12 +1020,12 @@ attr_for_type (GtkJsonParser *parser,
 
     case PANGO_ATTR_UNDERLINE_COLOR:
       parser_get_color (parser, &color);
-      attr = pango_attr_underline_color_new (color.red, color.green, color.blue);
+      attr = pango_attr_underline_color_new (&color);
       break;
 
     case PANGO_ATTR_STRIKETHROUGH_COLOR:
       parser_get_color (parser, &color);
-      attr = pango_attr_strikethrough_color_new (color.red, color.green, color.blue);
+      attr = pango_attr_strikethrough_color_new (&color);
       break;
 
     case PANGO_ATTR_ABSOLUTE_SIZE:
@@ -1072,7 +1072,7 @@ attr_for_type (GtkJsonParser *parser,
 
     case PANGO_ATTR_OVERLINE_COLOR:
       parser_get_color (parser, &color);
-      attr = pango_attr_overline_color_new (color.red, color.green, color.blue);
+      attr = pango_attr_overline_color_new (&color);
       break;
 
     case PANGO_ATTR_LINE_HEIGHT:
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 9f970294..6c46f156 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -39,8 +39,8 @@ test_attributes_basic (void)
 
   test_copy (pango_attr_language_new (pango_language_from_string ("ja-JP")));
   test_copy (pango_attr_family_new ("Times"));
-  test_copy (pango_attr_foreground_new (100, 200, 300));
-  test_copy (pango_attr_background_new (100, 200, 300));
+  test_copy (pango_attr_foreground_new (&(PangoColor){100, 200, 300}));
+  test_copy (pango_attr_background_new (&(PangoColor){100, 200, 300}));
   test_copy (pango_attr_size_new (1024));
   test_copy (pango_attr_size_new_absolute (1024));
   test_copy (pango_attr_style_new (PANGO_STYLE_ITALIC));
@@ -52,11 +52,11 @@ test_attributes_basic (void)
   pango_font_description_free (desc);
   test_copy (pango_attr_underline_new (PANGO_UNDERLINE_LOW));
   test_copy (pango_attr_underline_new (PANGO_UNDERLINE_ERROR_LINE));
-  test_copy (pango_attr_underline_color_new (100, 200, 300));
+  test_copy (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
   test_copy (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
-  test_copy (pango_attr_overline_color_new (100, 200, 300));
+  test_copy (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));
   test_copy (pango_attr_strikethrough_new (TRUE));
-  test_copy (pango_attr_strikethrough_color_new (100, 200, 300));
+  test_copy (pango_attr_strikethrough_color_new (&(PangoColor){100, 200, 300}));
   test_copy (pango_attr_rise_new (256));
   test_copy (pango_attr_scale_new (2.56));
   test_copy (pango_attr_fallback_new (FALSE));
@@ -219,8 +219,8 @@ test_binding_helpers (void)
 
   test_binding (pango_attr_language_new (pango_language_from_string ("ja-JP")));
   test_binding (pango_attr_family_new ("Times"));
-  test_binding (pango_attr_foreground_new (100, 200, 300));
-  test_binding (pango_attr_background_new (100, 200, 300));
+  test_binding (pango_attr_foreground_new (&(PangoColor){100, 200, 300}));
+  test_binding (pango_attr_background_new (&(PangoColor){100, 200, 300}));
   test_binding (pango_attr_size_new (1024));
   test_binding (pango_attr_size_new_absolute (1024));
   test_binding (pango_attr_style_new (PANGO_STYLE_ITALIC));
@@ -232,11 +232,11 @@ test_binding_helpers (void)
   pango_font_description_free (desc);
   test_binding (pango_attr_underline_new (PANGO_UNDERLINE_LOW));
   test_binding (pango_attr_underline_new (PANGO_UNDERLINE_ERROR_LINE));
-  test_binding (pango_attr_underline_color_new (100, 200, 300));
+  test_binding (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
   test_binding (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
-  test_binding (pango_attr_overline_color_new (100, 200, 300));
+  test_binding (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));
   test_binding (pango_attr_strikethrough_new (TRUE));
-  test_binding (pango_attr_strikethrough_color_new (100, 200, 300));
+  test_binding (pango_attr_strikethrough_color_new (&(PangoColor){100, 200, 300}));
   test_binding (pango_attr_rise_new (256));
   test_binding (pango_attr_scale_new (2.56));
   test_binding (pango_attr_fallback_new (FALSE));
diff --git a/tests/testmisc.c b/tests/testmisc.c
index 5af958ba..15c65ee6 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -257,7 +257,7 @@ test_attr_list_update (void)
   weight_attr->start_index = 4;
   weight_attr->end_index = 6;
 
-  fg_attr = pango_attr_foreground_new (0, 0, 65535);
+  fg_attr = pango_attr_foreground_new (&(PangoColor){0, 0, 65535});
   fg_attr->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
   fg_attr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END;
 


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