diff options
Diffstat (limited to 'pango/pango-color.c')
-rw-r--r-- | pango/pango-color.c | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/pango/pango-color.c b/pango/pango-color.c index 7e7c4a24..a5a8a141 100644 --- a/pango/pango-color.c +++ b/pango/pango-color.c @@ -77,14 +77,35 @@ pango_color_free (PangoColor *color) } /** + * pango_color_equal: + * @color1: (nullable): a `PangoColor` + * @color2: (nullable): another `PangoColor` + * + * Compares two colors for quality. + * + * Returns: `TRUE` if the colors are equal + */ +gboolean +pango_color_equal (const PangoColor *color1, + const PangoColor *color2) +{ + return color1 == color2 || + (color1 && color2 && + color1->red == color2->red && + color1->green == color2->green && + color1->blue == color2->blue && + color1->alpha == color2->alpha); +} + +/** * pango_color_to_string: * @color: a `PangoColor` * * Returns a textual specification of @color. * - * The string is in the hexadecimal form `#rrrrggggbbbb`, - * where `r`, `g` and `b` are hex digits representing the - * red, green, and blue components respectively. + * The string is in the hexadecimal form `#rrrrggggbbbbaaaa`, + * where `r`, `g`, `b` and `a` are hex digits representing the + * red, green, blue and alpha components respectively. * * Return value: a newly-allocated text string that must * be freed with g_free(). @@ -96,7 +117,7 @@ pango_color_to_string (const PangoColor *color) { g_return_val_if_fail (color != NULL, NULL); - return g_strdup_printf ("#%04x%04x%04x", color->red, color->green, color->blue); + return g_strdup_printf ("#%04x%04x%04x%04x", color->red, color->green, color->blue, color->alpha); } /* Color parsing @@ -211,10 +232,9 @@ hex (const char *spec, /** - * pango_color_parse_with_alpha: + * pango_color_parse: * @color: (nullable): a `PangoColor` structure in which * to store the result - * @alpha: (out) (optional): return location for alpha * @spec: a string specifying the new color * * Fill in the fields of a color from a string specification. @@ -239,14 +259,12 @@ hex (const char *spec, * Since: 1.46 */ gboolean -pango_color_parse_with_alpha (PangoColor *color, - guint16 *alpha, - const char *spec) +pango_color_parse (PangoColor *color, + const char *spec) { g_return_val_if_fail (spec != NULL, FALSE); - if (alpha) - *alpha = 0xffff; + color->alpha = 0xffff; if (spec[0] == '#') { @@ -268,8 +286,6 @@ pango_color_parse_with_alpha (PangoColor *color, case 4: case 8: case 16: - if (!alpha) - return FALSE; len /= 4; has_alpha = TRUE; break; @@ -301,7 +317,7 @@ pango_color_parse_with_alpha (PangoColor *color, color->blue = b; } - if (alpha && has_alpha) + if (has_alpha) { int bits = len * 4; a <<= 16 - bits; @@ -310,7 +326,7 @@ pango_color_parse_with_alpha (PangoColor *color, a |= (a >> bits); bits *= 2; } - *alpha = a; + color->alpha = a; } } else @@ -320,29 +336,3 @@ pango_color_parse_with_alpha (PangoColor *color, } return TRUE; } - -/** - * pango_color_parse: - * @color: (nullable): a `PangoColor` structure in which - * to store the result - * @spec: a string specifying the new color - * - * Fill in the fields of a color from a string specification. - * - * The string can either one of a large set of standard names. - * (Taken from the CSS Color [specification](https://www.w3.org/TR/css-color-4/#named-colors), - * or it can be a value in the form `#rgb`, `#rrggbb`, - * `#rrrgggbbb` or `#rrrrggggbbbb`, where `r`, `g` and `b` - * are hex digits of the red, green, and blue components - * of the color, respectively. (White in the four forms is - * `#fff`, `#ffffff`, `#fffffffff` and `#ffffffffffff`.) - * - * Return value: %TRUE if parsing of the specifier succeeded, - * otherwise %FALSE - */ -gboolean -pango_color_parse (PangoColor *color, - const char *spec) -{ - return pango_color_parse_with_alpha (color, NULL, spec); -} |