[libgxps] Support Opacity for SolidColorBrush elements
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgxps] Support Opacity for SolidColorBrush elements
- Date: Thu, 10 Nov 2011 18:42:43 +0000 (UTC)
commit 61908681df73373f2b39e68d8f4e5e35a27e6062
Author: Jason Crain <jason aquaticape us>
Date: Tue Nov 8 02:21:32 2011 -0600
Support Opacity for SolidColorBrush elements
https://bugzilla.gnome.org/show_bug.cgi?id=663472
libgxps/gxps-page.c | 42 +++++++++++++++++++++++++++++++++---------
1 files changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/libgxps/gxps-page.c b/libgxps/gxps-page.c
index e8ce12f..72f6c4f 100644
--- a/libgxps/gxps-page.c
+++ b/libgxps/gxps-page.c
@@ -966,7 +966,7 @@ gxps_color_parse (const gchar *color,
}
static cairo_pattern_t *
-gxps_create_solid_color_pattern (const gchar *color)
+gxps_create_solid_color_pattern_with_alpha (const gchar *color, gdouble alpha)
{
cairo_pattern_t *pattern;
gdouble a, r, g, b;
@@ -974,7 +974,7 @@ gxps_create_solid_color_pattern (const gchar *color)
if (!gxps_color_parse (color, &a, &r, &g, &b))
return NULL;
- pattern = cairo_pattern_create_rgba (r, g, b, a);
+ pattern = cairo_pattern_create_rgba (r, g, b, a * alpha);
if (cairo_pattern_status (pattern)) {
cairo_pattern_destroy (pattern);
return NULL;
@@ -983,6 +983,12 @@ gxps_create_solid_color_pattern (const gchar *color)
return pattern;
}
+static cairo_pattern_t *
+gxps_create_solid_color_pattern (const gchar *color)
+{
+ return gxps_create_solid_color_pattern_with_alpha (color, 1.0);
+}
+
static gboolean
gxps_boolean_parse (const gchar *value)
{
@@ -1429,27 +1435,45 @@ brush_start_element (GMarkupParseContext *context,
GXPSBrush *brush = (GXPSBrush *)user_data;
if (strcmp (element_name, "SolidColorBrush") == 0) {
+ const gchar *color_str = NULL;
gint i;
for (i = 0; names[i] != NULL; i++) {
if (strcmp (names[i], "Color") == 0) {
-
- brush->pattern = gxps_create_solid_color_pattern (values[i]);
- GXPS_DEBUG (g_message ("set_fill_pattern (solid)"));
- if (!brush->pattern) {
+ color_str = values[i];
+ } else if (strcmp (names[i], "Opacity") == 0) {
+ if (!gxps_value_get_double (values[i], &brush->opacity)) {
gxps_parse_error (context,
brush->ctx->page->priv->source,
G_MARKUP_ERROR_INVALID_CONTENT,
- "SolidColorBrush", "Color",
+ "SolidColorBrush", "Opacity",
values[i], error);
return;
}
- } else if (strcmp (names[i], "Opacity") == 0) {
- /* TODO */
} else if (strcmp (names[i], "X:Key") == 0) {
/* TODO */
}
}
+
+ if (!color_str) {
+ gxps_parse_error (context,
+ brush->ctx->page->priv->source,
+ G_MARKUP_ERROR_MISSING_ATTRIBUTE,
+ "SolidColorBrush", "Color",
+ NULL, error);
+ return;
+ }
+
+ brush->pattern = gxps_create_solid_color_pattern_with_alpha (color_str, brush->opacity);
+ GXPS_DEBUG (g_message ("set_fill_pattern (solid)"));
+ if (!brush->pattern) {
+ gxps_parse_error (context,
+ brush->ctx->page->priv->source,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ "SolidColorBrush", "Color",
+ color_str, error);
+ return;
+ }
} else if (strcmp (element_name, "ImageBrush") == 0) {
GXPSBrushImage *image;
gchar *image_source = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]