summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-02-06 22:53:55 -0500
committerMatthias Clasen <mclasen@redhat.com>2022-02-13 14:28:05 -0600
commit007ef3907e2a2b1410201fc7bc7364968a4343d2 (patch)
tree1596d4254f55f02930d0cfb2488919a359e63483
parentef993ae59bc2e448e26d59e1543c7fea2483d175 (diff)
downloadpango-007ef3907e2a2b1410201fc7bc7364968a4343d2.tar.gz
Change color attr api
Make pango_attr_{fore,back}ground_new take a PangoColor*. Update all callers.
-rw-r--r--pango/pango-attr-list.c2
-rw-r--r--pango/pango-attributes.c60
-rw-r--r--pango/pango-attributes.h22
-rw-r--r--pango/pango-markup.c10
-rw-r--r--pango/serializer.c10
-rw-r--r--tests/testattributes.c20
-rw-r--r--tests/testmisc.c2
7 files changed, 46 insertions, 80 deletions
diff --git a/pango/pango-attr-list.c b/pango/pango-attr-list.c
index 2615ddf1..88e5921d 100644
--- a/pango/pango-attr-list.c
+++ b/pango/pango-attr-list.c
@@ -1064,7 +1064,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 8e8e1746..6568fbf1 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);
}
/**
@@ -767,9 +747,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.
*
@@ -783,11 +761,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 3c102118..c7e9287a 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -123,13 +123,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
@@ -191,15 +187,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);
@@ -287,11 +279,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 9a3bde55..6f7a2a67 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 773ab3d3..19a3bb2c 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -997,12 +997,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:
@@ -1031,12 +1031,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:
@@ -1083,7 +1083,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 971045fb..ba2ec180 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 e708d1bb..fcc6bd48 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -276,7 +276,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;