[dia] Bug #591525 - Opacity support for SVG import and custom shapes
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Bug #591525 - Opacity support for SVG import and custom shapes
- Date: Sun, 3 Apr 2011 16:42:48 +0000 (UTC)
commit 17d335bc76e8fe4453b6ebd6409ae82a2d924b25
Author: Hans Breuer <hans breuer org>
Date: Sat Aug 22 12:18:14 2009 +0200
Bug #591525 - Opacity support for SVG import and custom shapes
doc/custom-shapes | 2 ++
lib/dia_svg.c | 20 ++++++++++++++++++++
lib/dia_svg.h | 2 ++
objects/custom/custom_object.c | 10 +++++-----
objects/custom/shape_info.c | 2 +-
plug-ins/svg/svg-import.c | 14 +++++++-------
6 files changed, 37 insertions(+), 13 deletions(-)
---
diff --git a/doc/custom-shapes b/doc/custom-shapes
index 3c46532..324c518 100644
--- a/doc/custom-shapes
+++ b/doc/custom-shapes
@@ -140,6 +140,8 @@ Currently only the following style attributes are understood:
stroke-dashlength - The length of the dashes in the dash pattern, in
relation to the user selected value (default is a
synonym for 1.0).
+ stroke-opacity - alpha value between 0..1.0
+ fill-opacity - alpha value between 0..1.0
stroke - The stroke colour. You can use one of the symbolic
names foreground, fg, default, background, bg inverse,
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index 4a10c9e..5451498 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -40,10 +40,12 @@ dia_svg_style_init(DiaSvgStyle *gs, DiaSvgStyle *parent_style)
{
g_return_if_fail (gs);
gs->stroke = parent_style ? parent_style->stroke : DIA_SVG_COLOUR_NONE;
+ gs->stroke_opacity = parent_style ? parent_style->stroke_opacity : 1.0;
gs->line_width = parent_style ? parent_style->line_width : 0.0;
gs->linestyle = parent_style ? parent_style->linestyle : LINESTYLE_SOLID;
gs->dashlength = parent_style ? parent_style->dashlength : 1;
gs->fill = parent_style ? parent_style->fill : DIA_SVG_COLOUR_NONE;
+ gs->fill_opacity = parent_style ? parent_style->fill_opacity : 1.0;
gs->linecap = parent_style ? parent_style->linecap : DIA_SVG_LINECAPS_DEFAULT;
gs->linejoin = parent_style ? parent_style->linejoin : DIA_SVG_LINEJOIN_DEFAULT;
gs->linestyle = parent_style ? parent_style->linestyle : DIA_SVG_LINESTYLE_DEFAULT;
@@ -62,10 +64,12 @@ dia_svg_style_copy(DiaSvgStyle *dest, DiaSvgStyle *src)
g_return_if_fail (dest && src);
dest->stroke = src->stroke;
+ dest->stroke_opacity = src->stroke_opacity;
dest->line_width = src->line_width;
dest->linestyle = src->linestyle;
dest->dashlength = src->dashlength;
dest->fill = src->fill;
+ dest->fill_opacity = src->fill_opacity;
if (dest->font)
dia_font_unref (dest->font);
dest->font = src->font ? dia_font_ref(src->font) : NULL;
@@ -251,12 +255,18 @@ dia_svg_parse_style(xmlNodePtr node, DiaSvgStyle *s, real user_scale)
if (ptr[0] == '\0') break;
_parse_color (&s->stroke, ptr);
+ } else if (!strncmp("stroke-opacity:", ptr, 15)) {
+ ptr += 15;
+ s->stroke_opacity = g_ascii_strtod(ptr, &ptr);
} else if (!strncmp("fill:", ptr, 5)) {
ptr += 5;
while (ptr[0] != '\0' && g_ascii_isspace(ptr[0])) ptr++;
if (ptr[0] == '\0') break;
_parse_color (&s->fill, ptr);
+ } else if (!strncmp("fill-opacity:", ptr, 13)) {
+ ptr += 13;
+ s->fill_opacity = g_ascii_strtod(ptr, &ptr);
} else if (!strncmp("stroke-linecap:", ptr, 15)) {
ptr += 15;
while (ptr[0] != '\0' && g_ascii_isspace(ptr[0])) ptr++;
@@ -347,11 +357,21 @@ dia_svg_parse_style(xmlNodePtr node, DiaSvgStyle *s, real user_scale)
_parse_color (&s->fill, (char *) str);
xmlFree(str);
}
+ str = xmlGetProp(node, (const xmlChar *)"fill-opacity");
+ if (str) {
+ s->fill_opacity = g_ascii_strtod((char *) str, NULL);
+ xmlFree(str);
+ }
str = xmlGetProp(node, (const xmlChar *)"stroke");
if (str) {
_parse_color (&s->stroke, (char *) str);
xmlFree(str);
}
+ str = xmlGetProp(node, (const xmlChar *)"stroke-opacity");
+ if (str) {
+ s->stroke_opacity = g_ascii_strtod((char *) str, NULL);
+ xmlFree(str);
+ }
str = xmlGetProp(node, (const xmlChar *)"stroke-width");
if (str) {
s->line_width = g_ascii_strtod((char *) str, NULL);
diff --git a/lib/dia_svg.h b/lib/dia_svg.h
index 71193a2..4588201 100644
--- a/lib/dia_svg.h
+++ b/lib/dia_svg.h
@@ -43,7 +43,9 @@ typedef struct _DiaSvgStyle DiaSvgStyle;
struct _DiaSvgStyle {
real line_width;
gint32 stroke;
+ real stroke_opacity;
gint32 fill;
+ real fill_opacity;
LineCaps linecap;
LineJoin linejoin;
diff --git a/objects/custom/custom_object.c b/objects/custom/custom_object.c
index 061f83a..37a75d5 100644
--- a/objects/custom/custom_object.c
+++ b/objects/custom/custom_object.c
@@ -818,7 +818,7 @@ custom_move(Custom *custom, Point *to)
}
static void
-get_colour(Custom *custom, Color *colour, gint32 c)
+get_colour(Custom *custom, Color *colour, gint32 c, real opacity)
{
switch (c) {
case DIA_SVG_COLOUR_NONE:
@@ -833,7 +833,7 @@ get_colour(Custom *custom, Color *colour, gint32 c)
*colour = custom->text->color;
break;
default:
- colour->alpha = ((c & 0xff000000) >> 24) / 255.0;
+ colour->alpha = opacity;
colour->red = ((c & 0x00ff0000) >> 16) / 255.0;
colour->green = ((c & 0x0000ff00) >> 8) / 255.0;
colour->blue = (c & 0x000000ff) / 255.0;
@@ -941,8 +941,8 @@ custom_draw_element(GraphicElement* el, Custom *custom, DiaRenderer *renderer,
}
(*cur_line) = el->any.s.line_width;
- get_colour(custom, fg, el->any.s.stroke);
- get_colour(custom, bg, el->any.s.fill);
+ get_colour(custom, fg, el->any.s.stroke, el->any.s.stroke_opacity);
+ get_colour(custom, bg, el->any.s.fill, el->any.s.fill_opacity);
switch (el->type) {
case GE_LINE:
transform_coord(custom, &el->line.p1, &p1);
@@ -995,7 +995,7 @@ custom_draw_element(GraphicElement* el, Custom *custom, DiaRenderer *renderer,
case GE_TEXT:
text_set_height (el->text.object, transform_length (custom, el->text.s.font_height));
custom_reposition_text(custom, &el->text);
- get_colour(custom, &el->text.object->color, el->any.s.fill);
+ get_colour(custom, &el->text.object->color, el->any.s.fill, el->any.s.fill_opacity);
text_draw(el->text.object, renderer);
text_set_position(el->text.object, &el->text.anchor);
break;
diff --git a/objects/custom/shape_info.c b/objects/custom/shape_info.c
index f588a70..e17005c 100644
--- a/objects/custom/shape_info.c
+++ b/objects/custom/shape_info.c
@@ -843,7 +843,7 @@ load_shape_info(const gchar *filename, ShapeInfo *preload)
xmlFree(tmp);
} else if (node->ns == svg_ns && !xmlStrcmp(node->name, (const xmlChar *)"svg")) {
DiaSvgStyle s = {
- 1.0, DIA_SVG_COLOUR_FOREGROUND, DIA_SVG_COLOUR_NONE,
+ 1.0, DIA_SVG_COLOUR_FOREGROUND, 1.0, DIA_SVG_COLOUR_NONE, 1.0,
DIA_SVG_LINECAPS_DEFAULT, DIA_SVG_LINEJOIN_DEFAULT, DIA_SVG_LINESTYLE_DEFAULT, 1.0
};
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 5df4abb..3b2cf31 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -61,13 +61,13 @@ static GPtrArray *make_element_props(real xpos, real ypos, real width, real heig
/* TODO: use existing implementation in dia source */
static Color
-get_colour(gint32 c)
+get_colour(gint32 c, real opacity)
{
Color colour;
colour.red = ((c & 0xff0000) >> 16) / 255.0;
colour.green = ((c & 0x00ff00) >> 8) / 255.0;
colour.blue = (c & 0x0000ff) / 255.0;
- colour.alpha = 1.0;
+ colour.alpha = opacity;
return colour;
}
@@ -205,12 +205,12 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style)
cprop = g_ptr_array_index(props,0);
if(gs->stroke != (-1)) {
- cprop->color_data = get_colour(gs->stroke);
+ cprop->color_data = get_colour(gs->stroke, gs->stroke_opacity);
} else {
if(gs->fill == DIA_SVG_COLOUR_NONE) {
- cprop->color_data = get_colour(0x000000);
+ cprop->color_data = get_colour(0x000000, 1.0);
} else {
- cprop->color_data = get_colour(gs->fill);
+ cprop->color_data = get_colour(gs->fill, gs->fill_opacity);
}
}
rprop = g_ptr_array_index(props,1);
@@ -221,7 +221,7 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style)
lsprop->dash = gs->dashlength;
cprop = g_ptr_array_index(props,3);
- cprop->color_data = get_colour(gs->fill);
+ cprop->color_data = get_colour(gs->fill, gs->fill_opacity);
bprop = g_ptr_array_index(props,4);
if(gs->fill == (-1)) {
@@ -402,7 +402,7 @@ read_text_svg(xmlNodePtr node, DiaSvgStyle *parent_style, GList *list)
prop->attr.color = attributes_get_background();
break;
default :
- prop->attr.color = get_colour (gs->fill);
+ prop->attr.color = get_colour (gs->fill, gs->fill_opacity);
break;
}
new_obj->ops->set_props(new_obj, props);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]