[pango/redo-attrs: 25/25] Add alpha to PangoColor
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/redo-attrs: 25/25] Add alpha to PangoColor
- Date: Sun, 13 Feb 2022 20:31:45 +0000 (UTC)
commit 5b4d403b325afef41db811ce21f541933541b56a
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Feb 8 14:08:25 2022 -0500
Add alpha to PangoColor
Adapt all users. This drops the alpha attributes
and alpha in markup, and adds alpha support to
underlines, overlines and strikethroughs.
docs/pango_markup.md | 18 +-------
pango/pango-attr-list.c | 8 ----
pango/pango-attr.c | 2 -
pango/pango-attributes.c | 36 ---------------
pango/pango-attributes.h | 8 ----
pango/pango-color.c | 72 +++++++++++++----------------
pango/pango-color.h | 14 +++---
pango/pango-markup.c | 95 +++-----------------------------------
pango/pango-renderer.c | 79 +-------------------------------
pango/pango-renderer.h | 8 ----
pango/pangocairo-render.c | 8 +---
pango/serializer.c | 8 ----
tests/testattributes.c | 4 --
tests/testcolor.c | 114 ++++++++++++++++++----------------------------
14 files changed, 95 insertions(+), 379 deletions(-)
---
diff --git a/docs/pango_markup.md b/docs/pango_markup.md
index 6a6cc3c2..2376dd8a 100644
--- a/docs/pango_markup.md
+++ b/docs/pango_markup.md
@@ -115,25 +115,11 @@ font_features
foreground
fgcolor
color
-: An RGB color specification such as '#00FF00' or a color name such as 'red'.
- Since 1.38, an RGBA color specification such as '#00FF007F' will be interpreted
- as specifying both a foreground color and foreground alpha.
+: An RGBA color specification such as '#00FF007F' or a color name such as 'red'.
background
bgcolor
-: An RGB color specification such as '#00FF00' or a color name such as 'red'.
- Since 1.38, an RGBA color specification such as '#00FF007F' will be interpreted
- as specifying both a background color and background alpha.
-
-alpha
-fgalpha
-: An alpha value for the foreground color, either a plain integer between 1 and
- 65536 or a percentage value like '50%'.
-
-background_alpha
-bgalpha
-: An alpha value for the background color, either a plain integer between 1 and
- 65536 or a percentage value like '50%'.
+: An RGBA color specification such as '#00FF007F' or a color name such as 'red'.
underline
: One of 'none', 'single', 'double', 'low', 'error'.
diff --git a/pango/pango-attr-list.c b/pango/pango-attr-list.c
index ca82fd60..bcd02fb2 100644
--- a/pango/pango-attr-list.c
+++ b/pango/pango-attr-list.c
@@ -1196,14 +1196,6 @@ pango_attr_list_from_string (const char *text)
ENUM_ATTR(gravity_hint, PangoGravityHint, PANGO_GRAVITY_HINT_NATURAL, PANGO_GRAVITY_HINT_LINE);
break;
- case PANGO_ATTR_FOREGROUND_ALPHA:
- INT_ATTR(foreground_alpha, int);
- break;
-
- case PANGO_ATTR_BACKGROUND_ALPHA:
- INT_ATTR(background_alpha, int);
- break;
-
case PANGO_ATTR_ALLOW_BREAKS:
BOOLEAN_ATTR(allow_breaks, gboolean);
break;
diff --git a/pango/pango-attr.c b/pango/pango-attr.c
index 5794e7c7..cc8f7101 100644
--- a/pango/pango-attr.c
+++ b/pango/pango-attr.c
@@ -86,8 +86,6 @@ is_valid_attr_type (guint type)
case PANGO_ATTR_GRAVITY:
case PANGO_ATTR_GRAVITY_HINT:
case PANGO_ATTR_FONT_FEATURES:
- case PANGO_ATTR_FOREGROUND_ALPHA:
- case PANGO_ATTR_BACKGROUND_ALPHA:
case PANGO_ATTR_ALLOW_BREAKS:
case PANGO_ATTR_SHOW:
case PANGO_ATTR_INSERT_HYPHENS:
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 5d40e5c8..6e965983 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -593,42 +593,6 @@ pango_attr_font_features_new (const char *features)
return pango_attr_string_new (PANGO_ATTR_FONT_FEATURES, features);
}
-/**
- * pango_attr_foreground_alpha_new:
- * @alpha: the alpha value, between 1 and 65536
- *
- * Create a new foreground alpha attribute.
- *
- * Return value: (transfer full): the newly allocated
- * `PangoAttribute`, which should be freed with
- * [method@Pango.Attribute.destroy]
- *
- * Since: 1.38
- */
-PangoAttribute *
-pango_attr_foreground_alpha_new (guint16 alpha)
-{
- return pango_attr_int_new (PANGO_ATTR_FOREGROUND_ALPHA, (int)alpha);
-}
-
-/**
- * pango_attr_background_alpha_new:
- * @alpha: the alpha value, between 1 and 65536
- *
- * Create a new background alpha attribute.
- *
- * Return value: (transfer full): the newly allocated
- * `PangoAttribute`, which should be freed with
- * [method@Pango.Attribute.destroy]
- *
- * Since: 1.38
- */
-PangoAttribute *
-pango_attr_background_alpha_new (guint16 alpha)
-{
- return pango_attr_int_new (PANGO_ATTR_BACKGROUND_ALPHA, (int)alpha);
-}
-
/**
* pango_attr_allow_breaks_new:
* @allow_breaks: %TRUE if we line breaks are allowed
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index 317d3e67..f415a9ea 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -43,9 +43,7 @@ G_BEGIN_DECLS
* @PANGO_ATTR_SCALE: font size scale factor
* @PANGO_ATTR_FONT_DESC: font description
* @PANGO_ATTR_FOREGROUND: foreground color
- * @PANGO_ATTR_FOREGROUND_ALPHA: foreground alpha
* @PANGO_ATTR_BACKGROUND: background color
- * @PANGO_ATTR_BACKGROUND_ALPHA: background alpha
* @PANGO_ATTR_UNDERLINE: underline style
* @PANGO_ATTR_UNDERLINE_POSITION: underline position
* @PANGO_ATTR_UNDERLINE_COLOR: underline color
@@ -90,9 +88,7 @@ typedef enum
PANGO_ATTR_SCALE = PANGO_ATTR_TYPE (FLOAT, ITEMIZATION, OVERRIDES),
PANGO_ATTR_FONT_DESC = PANGO_ATTR_TYPE (FONT_DESC, ITEMIZATION, ACCUMULATES),
PANGO_ATTR_FOREGROUND = PANGO_ATTR_TYPE (COLOR, RENDERING, OVERRIDES),
- PANGO_ATTR_FOREGROUND_ALPHA = PANGO_ATTR_TYPE (INT, RENDERING, OVERRIDES),
PANGO_ATTR_BACKGROUND = PANGO_ATTR_TYPE (COLOR, RENDERING, OVERRIDES),
- PANGO_ATTR_BACKGROUND_ALPHA = PANGO_ATTR_TYPE (INT, RENDERING, OVERRIDES),
PANGO_ATTR_UNDERLINE = PANGO_ATTR_TYPE (INT, RENDERING, OVERRIDES),
PANGO_ATTR_UNDERLINE_POSITION = PANGO_ATTR_TYPE (INT, RENDERING, OVERRIDES),
PANGO_ATTR_UNDERLINE_COLOR = PANGO_ATTR_TYPE (COLOR, RENDERING, OVERRIDES),
@@ -240,10 +236,6 @@ PANGO_AVAILABLE_IN_1_16
PangoAttribute * pango_attr_gravity_hint_new (PangoGravityHint hint);
PANGO_AVAILABLE_IN_1_38
PangoAttribute * pango_attr_font_features_new (const char *features);
-PANGO_AVAILABLE_IN_1_38
-PangoAttribute * pango_attr_foreground_alpha_new (guint16 alpha);
-PANGO_AVAILABLE_IN_1_38
-PangoAttribute * pango_attr_background_alpha_new (guint16 alpha);
PANGO_AVAILABLE_IN_1_44
PangoAttribute * pango_attr_allow_breaks_new (gboolean allow_breaks);
PANGO_AVAILABLE_IN_1_50
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
@@ -76,15 +76,36 @@ pango_color_free (PangoColor *color)
g_slice_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);
-}
diff --git a/pango/pango-color.h b/pango/pango-color.h
index 675d8e82..cedcddaf 100644
--- a/pango/pango-color.h
+++ b/pango/pango-color.h
@@ -35,15 +35,18 @@ typedef struct _PangoColor PangoColor;
* @red: value of red component
* @green: value of green component
* @blue: value of blue component
+ * @alpha: value of the alpha component
*
* The `PangoColor` structure is used to
- * represent a color in an uncalibrated RGB color-space.
+ * represent a color in an uncalibrated RGB color-space
+ * with alpha.
*/
struct _PangoColor
{
guint16 red;
guint16 green;
guint16 blue;
+ guint16 alpha;
};
#define PANGO_TYPE_COLOR (pango_color_get_type ())
@@ -58,12 +61,11 @@ PANGO_AVAILABLE_IN_ALL
void pango_color_free (PangoColor *color);
PANGO_AVAILABLE_IN_ALL
-gboolean pango_color_parse (PangoColor *color,
- const char *spec);
+gboolean pango_color_equal (const PangoColor *color1,
+ const PangoColor *color2);
-PANGO_AVAILABLE_IN_1_46
-gboolean pango_color_parse_with_alpha (PangoColor *color,
- guint16 *alpha,
+PANGO_AVAILABLE_IN_ALL
+gboolean pango_color_parse (PangoColor *color,
const char *spec);
PANGO_AVAILABLE_IN_1_16
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index f8fa495a..98d19e33 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -1047,11 +1047,10 @@ static gboolean
span_parse_color (const char *attr_name,
const char *attr_val,
PangoColor *color,
- guint16 *alpha,
int line_number,
GError **error)
{
- if (!pango_color_parse_with_alpha (color, alpha, attr_val))
+ if (!pango_color_parse (color, attr_val))
{
g_set_error (error,
G_MARKUP_ERROR,
@@ -1066,56 +1065,6 @@ span_parse_color (const char *attr_name,
return TRUE;
}
-static gboolean
-span_parse_alpha (const char *attr_name,
- const char *attr_val,
- guint16 *val,
- int line_number,
- GError **error)
-{
- const char *end = attr_val;
- int int_val;
-
- if (_pango_scan_int (&end, &int_val))
- {
- if (*end == '\0' && int_val > 0 && int_val <= 0xffff)
- {
- *val = (guint16)int_val;
- return TRUE;
- }
- else if (*end == '%' && int_val > 0 && int_val <= 100)
- {
- *val = (guint16)(int_val * 0xffff / 100);
- return TRUE;
- }
- else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of '%s' attribute on <span> tag "
- "on line %d could not be parsed; "
- "should be between 0 and 65536 or a "
- "percentage, not '%s'"),
- attr_name, line_number, attr_val);
- return FALSE;
- }
- }
- else
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of '%s' attribute on <span> tag "
- "on line %d could not be parsed; "
- "should be an integer, not '%s'"),
- attr_name, line_number, attr_val);
- return FALSE;
- }
-
- return TRUE;
-}
-
static gboolean
span_parse_enum (const char *attr_name,
const char *attr_val,
@@ -1232,8 +1181,6 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
const char *gravity = NULL;
const char *gravity_hint = NULL;
const char *font_features = NULL;
- const char *alpha = NULL;
- const char *background_alpha = NULL;
const char *allow_breaks = NULL;
const char *insert_hyphens = NULL;
const char *show = NULL;
@@ -1271,13 +1218,10 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
switch (names[i][0]) {
case 'a':
CHECK_ATTRIBUTE (allow_breaks);
- CHECK_ATTRIBUTE (alpha);
break;
case 'b':
CHECK_ATTRIBUTE (background);
CHECK_ATTRIBUTE2(background, "bgcolor");
- CHECK_ATTRIBUTE (background_alpha);
- CHECK_ATTRIBUTE2(background_alpha, "bgalpha");
CHECK_ATTRIBUTE(baseline_shift);
break;
case 'c':
@@ -1299,7 +1243,6 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
CHECK_ATTRIBUTE (foreground);
CHECK_ATTRIBUTE2(foreground, "fgcolor");
- CHECK_ATTRIBUTE2(alpha, "fgalpha");
CHECK_ATTRIBUTE (font_features);
break;
@@ -1503,47 +1446,21 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
if (G_UNLIKELY (foreground))
{
PangoColor color;
- guint16 alpha;
- if (!span_parse_color ("foreground", foreground, &color, &alpha, line_number, error))
+ if (!span_parse_color ("foreground", foreground, &color, line_number, error))
goto error;
add_attribute (tag, pango_attr_foreground_new (&color));
- if (alpha != 0xffff)
- add_attribute (tag, pango_attr_foreground_alpha_new (alpha));
}
if (G_UNLIKELY (background))
{
PangoColor color;
- guint16 alpha;
- if (!span_parse_color ("background", background, &color, &alpha, line_number, error))
+ if (!span_parse_color ("background", background, &color, line_number, error))
goto error;
add_attribute (tag, pango_attr_background_new (&color));
- if (alpha != 0xffff)
- add_attribute (tag, pango_attr_background_alpha_new (alpha));
- }
-
- if (G_UNLIKELY (alpha))
- {
- guint16 val;
-
- if (!span_parse_alpha ("alpha", alpha, &val, line_number, error))
- goto error;
-
- add_attribute (tag, pango_attr_foreground_alpha_new (val));
- }
-
- if (G_UNLIKELY (background_alpha))
- {
- guint16 val;
-
- if (!span_parse_alpha ("background_alpha", background_alpha, &val, line_number, error))
- goto error;
-
- add_attribute (tag, pango_attr_background_alpha_new (val));
}
if (G_UNLIKELY (underline))
@@ -1570,7 +1487,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
{
PangoColor color;
- if (!span_parse_color ("underline_color", underline_color, &color, NULL, line_number, error))
+ if (!span_parse_color ("underline_color", underline_color, &color, line_number, error))
goto error;
add_attribute (tag, pango_attr_underline_color_new (&color));
@@ -1590,7 +1507,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
{
PangoColor color;
- if (!span_parse_color ("overline_color", overline_color, &color, NULL, line_number, error))
+ if (!span_parse_color ("overline_color", overline_color, &color, line_number, error))
goto error;
add_attribute (tag, pango_attr_overline_color_new (&color));
@@ -1643,7 +1560,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
{
PangoColor color;
- if (!span_parse_color ("strikethrough_color", strikethrough_color, &color, NULL, line_number, error))
+ if (!span_parse_color ("strikethrough_color", strikethrough_color, &color, line_number, error))
goto error;
add_attribute (tag, pango_attr_strikethrough_color_new (&color));
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index 1a50eaa0..512a7bbe 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -59,7 +59,6 @@ struct _PangoRendererPrivate
{
PangoColor color[N_RENDER_PARTS];
gboolean color_set[N_RENDER_PARTS];
- guint16 alpha[N_RENDER_PARTS];
PangoLayoutLine *line;
LineState *line_state;
@@ -1243,8 +1242,6 @@ pango_renderer_deactivate (PangoRenderer *renderer)
*
* Sets the color for part of the rendering.
*
- * Also see [method@Pango.Renderer.set_alpha].
- *
* Since: 1.8
*/
void
@@ -1255,11 +1252,9 @@ pango_renderer_set_color (PangoRenderer *renderer,
g_return_if_fail (PANGO_IS_RENDERER_FAST (renderer));
g_return_if_fail (IS_VALID_PART (part));
- if ((!color && !renderer->priv->color_set[part]) ||
+ if (!color && !renderer->priv->color_set[part] ||
(color && renderer->priv->color_set[part] &&
- renderer->priv->color[part].red == color->red &&
- renderer->priv->color[part].green == color->green &&
- renderer->priv->color[part].blue == color->blue))
+ pango_color_equal (color, &renderer->priv->color[part])))
return;
pango_renderer_part_changed (renderer, part);
@@ -1301,60 +1296,6 @@ pango_renderer_get_color (PangoRenderer *renderer,
return NULL;
}
-/**
- * pango_renderer_set_alpha:
- * @renderer: a `PangoRenderer`
- * @part: the part to set the alpha for
- * @alpha: an alpha value between 1 and 65536, or 0 to unset the alpha
- *
- * Sets the alpha for part of the rendering.
- *
- * Note that the alpha may only be used if a color is
- * specified for @part as well.
- *
- * Since: 1.38
- */
-void
-pango_renderer_set_alpha (PangoRenderer *renderer,
- PangoRenderPart part,
- guint16 alpha)
-{
- g_return_if_fail (PANGO_IS_RENDERER_FAST (renderer));
- g_return_if_fail (IS_VALID_PART (part));
-
- if ((!alpha && !renderer->priv->alpha[part]) ||
- (alpha && renderer->priv->alpha[part] &&
- renderer->priv->alpha[part] == alpha))
- return;
-
- pango_renderer_part_changed (renderer, part);
-
- renderer->priv->alpha[part] = alpha;
-}
-
-/**
- * pango_renderer_get_alpha:
- * @renderer: a `PangoRenderer`
- * @part: the part to get the alpha for
- *
- * Gets the current alpha for the specified part.
- *
- * Return value: the alpha for the specified part,
- * or 0 if it hasn't been set and should be
- * inherited from the environment.
- *
- * Since: 1.38
- */
-guint16
-pango_renderer_get_alpha (PangoRenderer *renderer,
- PangoRenderPart part)
-{
- g_return_val_if_fail (PANGO_IS_RENDERER_FAST (renderer), 0);
- g_return_val_if_fail (IS_VALID_PART (part), 0);
-
- return renderer->priv->alpha[part];
-}
-
/**
* pango_renderer_part_changed:
* @renderer: a `PangoRenderer`
@@ -1419,8 +1360,6 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
PangoColor *underline_color = NULL;
PangoColor *overline_color = NULL;
PangoColor *strikethrough_color = NULL;
- guint16 fg_alpha = 0;
- guint16 bg_alpha = 0;
GSList *l;
renderer->underline = PANGO_LINE_STYLE_NONE;
@@ -1470,14 +1409,6 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
strikethrough_color = &attr->color_value;
break;
- case PANGO_ATTR_FOREGROUND_ALPHA:
- fg_alpha = attr->int_value;
- break;
-
- case PANGO_ATTR_BACKGROUND_ALPHA:
- bg_alpha = attr->int_value;
- break;
-
default:
break;
}
@@ -1497,12 +1428,6 @@ pango_renderer_default_prepare_run (PangoRenderer *renderer,
pango_renderer_set_color (renderer, PANGO_RENDER_PART_UNDERLINE, underline_color);
pango_renderer_set_color (renderer, PANGO_RENDER_PART_STRIKETHROUGH, strikethrough_color);
pango_renderer_set_color (renderer, PANGO_RENDER_PART_OVERLINE, overline_color);
-
- pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_FOREGROUND, fg_alpha);
- pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_BACKGROUND, bg_alpha);
- pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_UNDERLINE, fg_alpha);
- pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_STRIKETHROUGH, fg_alpha);
- pango_renderer_set_alpha (renderer, PANGO_RENDER_PART_OVERLINE, fg_alpha);
}
/**
diff --git a/pango/pango-renderer.h b/pango/pango-renderer.h
index ae0b23ed..63c56a78 100644
--- a/pango/pango-renderer.h
+++ b/pango/pango-renderer.h
@@ -260,14 +260,6 @@ PANGO_AVAILABLE_IN_1_8
PangoColor *pango_renderer_get_color (PangoRenderer *renderer,
PangoRenderPart part);
-PANGO_AVAILABLE_IN_1_38
-void pango_renderer_set_alpha (PangoRenderer *renderer,
- PangoRenderPart part,
- guint16 alpha);
-PANGO_AVAILABLE_IN_1_38
-guint16 pango_renderer_get_alpha (PangoRenderer *renderer,
- PangoRenderPart part);
-
PANGO_AVAILABLE_IN_1_8
void pango_renderer_set_matrix (PangoRenderer *renderer,
const PangoMatrix *matrix);
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index de38489a..3470ab2c 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -61,10 +61,9 @@ set_color (PangoCairoRenderer *crenderer,
PangoRenderPart part)
{
PangoColor *color = pango_renderer_get_color ((PangoRenderer *) (crenderer), part);
- guint16 a = pango_renderer_get_alpha ((PangoRenderer *) (crenderer), part);
gdouble red, green, blue, alpha;
- if (!a && !color)
+ if (!color)
return;
if (color)
@@ -72,7 +71,7 @@ set_color (PangoCairoRenderer *crenderer,
red = color->red / 65535.;
green = color->green / 65535.;
blue = color->blue / 65535.;
- alpha = 1.;
+ alpha = color->alpha / 65535.;
}
else
{
@@ -89,9 +88,6 @@ set_color (PangoCairoRenderer *crenderer,
}
}
- if (a)
- alpha = a / 65535.;
-
cairo_set_source_rgba (crenderer->cr, red, green, blue, alpha);
}
diff --git a/pango/serializer.c b/pango/serializer.c
index 4e88351d..0b2ef762 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -1059,14 +1059,6 @@ attr_for_type (GtkJsonParser *parser,
g_free (str);
break;
- case PANGO_ATTR_FOREGROUND_ALPHA:
- attr = pango_attr_foreground_alpha_new ((int) gtk_json_parser_get_number (parser));
- break;
-
- case PANGO_ATTR_BACKGROUND_ALPHA:
- attr = pango_attr_background_alpha_new ((int) gtk_json_parser_get_number (parser));
- break;
-
case PANGO_ATTR_ALLOW_BREAKS:
attr = pango_attr_allow_breaks_new (gtk_json_parser_get_boolean (parser));
break;
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 71144821..1bcaadcb 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -64,8 +64,6 @@ test_attributes_basic (void)
test_copy (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
test_copy (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
test_copy (pango_attr_font_features_new ("csc=1"));
- test_copy (pango_attr_foreground_alpha_new (8000));
- test_copy (pango_attr_background_alpha_new (8000));
test_copy (pango_attr_allow_breaks_new (FALSE));
test_copy (pango_attr_show_new (PANGO_SHOW_SPACES));
test_copy (pango_attr_insert_hyphens_new (FALSE));
@@ -244,8 +242,6 @@ test_binding_helpers (void)
test_binding (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
test_binding (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
test_binding (pango_attr_font_features_new ("csc=1"));
- test_binding (pango_attr_foreground_alpha_new (8000));
- test_binding (pango_attr_background_alpha_new (8000));
test_binding (pango_attr_allow_breaks_new (FALSE));
test_binding (pango_attr_show_new (PANGO_SHOW_SPACES));
test_binding (pango_attr_insert_hyphens_new (FALSE));
diff --git a/tests/testcolor.c b/tests/testcolor.c
index b32eb6ee..26b4412f 100644
--- a/tests/testcolor.c
+++ b/tests/testcolor.c
@@ -25,92 +25,65 @@
typedef struct _ColorSpec {
const gchar *spec;
gboolean valid;
- int color_or_alpha;
guint16 red;
guint16 green;
guint16 blue;
guint16 alpha;
} ColorSpec;
-#define COLOR 1
-#define ALPHA 2
-#define BOTH 3
-
static void
test_one_color (ColorSpec *spec)
{
PangoColor color;
gboolean accepted;
- guint16 alpha;
- if (spec->color_or_alpha & COLOR)
+ accepted = pango_color_parse (&color, spec->spec);
+
+ if (!spec->valid)
{
- accepted = pango_color_parse (&color, spec->spec);
-
- if (!spec->valid)
- {
- g_assert_false (accepted);
- }
- else
- {
- g_assert_true (accepted);
- g_assert_cmpuint (color.red, ==, spec->red);
- g_assert_cmpuint (color.green, ==, spec->green);
- g_assert_cmpuint (color.blue, ==, spec->blue);
- }
+ g_assert_false (accepted);
}
-
- if (spec->color_or_alpha & ALPHA)
+ else
{
- accepted = pango_color_parse_with_alpha (&color, &alpha, spec->spec);
-
- if (!spec->valid)
- {
- g_assert_false (accepted);
- }
- else
- {
- g_assert_true (accepted);
- g_assert_cmpuint (color.red, ==, spec->red);
- g_assert_cmpuint (color.green, ==, spec->green);
- g_assert_cmpuint (color.blue, ==, spec->blue);
- g_assert_cmpuint (alpha, ==, spec->alpha);
- }
+ g_assert_true (accepted);
+ g_assert_cmpuint (color.red, ==, spec->red);
+ g_assert_cmpuint (color.green, ==, spec->green);
+ g_assert_cmpuint (color.blue, ==, spec->blue);
+ g_assert_cmpuint (color.alpha, ==, spec->alpha);
}
}
ColorSpec specs [] = {
- { "#abc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
- { "#aabbcc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
- { "#aaabbbccc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
- { "#100100100", 1, BOTH, 0x1001, 0x1001, 0x1001, 0xffff },
- { "#aaaabbbbcccc", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
- { "#fff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff },
- { "#ffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff },
- { "#fffffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff },
- { "#ffffffffffff", 1, COLOR, 0xffff, 0xffff, 0xffff, 0xffff },
- { "#000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff },
- { "#000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff },
- { "#000000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff },
- { "#000000000000", 1, COLOR, 0x0000, 0x0000, 0x0000, 0xffff },
- { "#AAAABBBBCCCC", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
- { "#aa bb cc ", 0, BOTH, 0, 0, 0, 0 },
- { "#aa bb ccc", 0, BOTH, 0, 0, 0, 0 },
- { "#ab", 0, BOTH, 0, 0, 0, 0 },
- { "#aabb", 0, COLOR, 0, 0, 0, 0 },
- { "#aaabb", 0, BOTH, 0, 0, 0, 0 },
- { "aaabb", 0, BOTH, 0, 0, 0, 0 },
- { "", 0, BOTH, 0, 0, 0, 0 },
- { "#", 0, BOTH, 0, 0, 0, 0 },
- { "##fff", 0, BOTH, 0, 0, 0, 0 },
- { "#0000ff+", 0, BOTH, 0, 0, 0, 0 },
- { "#0000f+", 0, BOTH, 0, 0, 0, 0 },
- { "#0x00x10x2", 0, BOTH, 0, 0, 0, 0 },
- { "#abcd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd },
- { "#aabbccdd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd },
- { "#aaaabbbbccccdddd",
- 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd },
- { NULL, 0, BOTH, 0, 0, 0, 0 }
+ { "#abc", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
+ { "#aabbcc", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
+ { "#aaabbbccc", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
+ { "#100100100", 1, 0x1001, 0x1001, 0x1001, 0xffff },
+ { "#aaaabbbbcccc", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
+ { "#fff", 1, 0xffff, 0xffff, 0xffff, 0xffff },
+ { "#ffffff", 1, 0xffff, 0xffff, 0xffff, 0xffff },
+ { "#fffffffff", 1, 0xffff, 0xffff, 0xffff, 0xffff },
+ { "#ffffffffffff", 1, 0xffff, 0xffff, 0xffff, 0xffff },
+ { "#000", 1, 0x0000, 0x0000, 0x0000, 0xffff },
+ { "#000000", 1, 0x0000, 0x0000, 0x0000, 0xffff },
+ { "#000000000", 1, 0x0000, 0x0000, 0x0000, 0xffff },
+ { "#000000000000", 1, 0x0000, 0x0000, 0x0000, 0xffff },
+ { "#AAAABBBBCCCC", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xffff },
+ { "#aa bb cc ", 0, 0, 0, 0, 0 },
+ { "#aa bb ccc", 0, 0, 0, 0, 0 },
+ { "#ab", 0, 0, 0, 0, 0 },
+ { "#aabb", 1, 0xaaaa, 0xaaaa, 0xbbbb, 0xbbbb },
+ { "#aaabb", 0, 0, 0, 0, 0 },
+ { "aaabb", 0, 0, 0, 0, 0 },
+ { "", 0, 0, 0, 0, 0 },
+ { "#", 0, 0, 0, 0, 0 },
+ { "##fff", 0, 0, 0, 0, 0 },
+ { "#0000ff+", 0, 0, 0, 0, 0 },
+ { "#0000f+", 0, 0, 0, 0, 0 },
+ { "#0x00x10x2", 0, 0, 0, 0, 0 },
+ { "#abcd", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd },
+ { "#aabbccdd", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd },
+ { "#aaaabbbbccccdddd", 1, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd },
+ { NULL, 0, 0, 0, 0, 0 }
};
static void
@@ -125,7 +98,7 @@ test_color (void)
static void
test_color_copy (void)
{
- PangoColor orig = { 0, 200, 5000 };
+ PangoColor orig = { 0, 200, 5000, 666 };
PangoColor *copy;
copy = pango_color_copy (&orig);
@@ -133,6 +106,7 @@ test_color_copy (void)
g_assert_cmpint (orig.red, ==, copy->red);
g_assert_cmpint (orig.green, ==, copy->green);
g_assert_cmpint (orig.blue, ==, copy->blue);
+ g_assert_cmpint (orig.alpha, ==, copy->alpha);
pango_color_free (copy);
}
@@ -140,12 +114,12 @@ test_color_copy (void)
static void
test_color_serialize (void)
{
- PangoColor orig = { 0, 200, 5000 };
+ PangoColor orig = { 0, 200, 5000, 666 };
char *string;
string = pango_color_to_string (&orig);
- g_assert_cmpstr (string, ==, "#000000c81388");
+ g_assert_cmpstr (string, ==, "#000000c81388029a");
g_free (string);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]