From 29ce3b1c7505e21e4dd942b1b9fc7f89114c9e10 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 11 Mar 2013 14:56:00 -0700 Subject: [PATCH] fix handling of svg opacity, which should be applied to fill/stroke opacity at render time - closes #1744 --- include/mapnik/svg/svg_converter.hpp | 4 ++-- include/mapnik/svg/svg_path_attributes.hpp | 4 ++++ include/mapnik/svg/svg_renderer_agg.hpp | 8 ++++---- src/svg/svg_parser.cpp | 3 +-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/mapnik/svg/svg_converter.hpp b/include/mapnik/svg/svg_converter.hpp index d0e7dfcb5..2ccf9da56 100644 --- a/include/mapnik/svg/svg_converter.hpp +++ b/include/mapnik/svg/svg_converter.hpp @@ -264,6 +264,7 @@ public: { cur_attr().fill_opacity = op; } + void stroke_opacity(double op) { cur_attr().stroke_opacity = op; @@ -271,8 +272,7 @@ public: void opacity(double op) { - cur_attr().stroke_opacity = op; - cur_attr().fill_opacity = op; + cur_attr().opacity = op; } void line_join(agg::line_join_e join) diff --git a/include/mapnik/svg/svg_path_attributes.hpp b/include/mapnik/svg/svg_path_attributes.hpp index db14ccc28..3a09e8e6b 100644 --- a/include/mapnik/svg/svg_path_attributes.hpp +++ b/include/mapnik/svg/svg_path_attributes.hpp @@ -38,6 +38,7 @@ namespace svg { struct path_attributes { unsigned index; + double opacity; agg::rgba8 fill_color; double fill_opacity; agg::rgba8 stroke_color; @@ -58,6 +59,7 @@ struct path_attributes // Empty constructor path_attributes() : index(0), + opacity(1.0), fill_color(agg::rgba(0,0,0)), fill_opacity(1.0), stroke_color(agg::rgba(0,0,0)), @@ -80,6 +82,7 @@ struct path_attributes // Copy constructor path_attributes(const path_attributes& attr) : index(attr.index), + opacity(attr.opacity), fill_color(attr.fill_color), fill_opacity(attr.fill_opacity), stroke_color(attr.stroke_color), @@ -101,6 +104,7 @@ struct path_attributes // Copy constructor with new index value path_attributes(path_attributes const& attr, unsigned idx) : index(idx), + opacity(attr.opacity), fill_color(attr.fill_color), fill_opacity(attr.fill_opacity), stroke_color(attr.stroke_color), diff --git a/include/mapnik/svg/svg_renderer_agg.hpp b/include/mapnik/svg/svg_renderer_agg.hpp index 5d0032e9b..778e726ca 100644 --- a/include/mapnik/svg/svg_renderer_agg.hpp +++ b/include/mapnik/svg/svg_renderer_agg.hpp @@ -290,13 +290,13 @@ public: if(attr.fill_gradient.get_gradient_type() != NO_GRADIENT) { - render_gradient(ras, sl, ren, attr.fill_gradient, transform, attr.fill_opacity * opacity, symbol_bbox, path_bbox); + render_gradient(ras, sl, ren, attr.fill_gradient, transform, attr.fill_opacity * attr.opacity * opacity, symbol_bbox, path_bbox); } else { ras.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero); color = attr.fill_color; - color.opacity(color.opacity() * attr.fill_opacity * opacity); + color.opacity(color.opacity() * attr.fill_opacity * attr.opacity * opacity); ScanlineRenderer ren_s(ren); color.premultiply(); ren_s.color(color); @@ -326,13 +326,13 @@ public: if(attr.stroke_gradient.get_gradient_type() != NO_GRADIENT) { - render_gradient(ras, sl, ren, attr.stroke_gradient, transform, attr.stroke_opacity * opacity, symbol_bbox, path_bbox); + render_gradient(ras, sl, ren, attr.stroke_gradient, transform, attr.stroke_opacity * attr.opacity * opacity, symbol_bbox, path_bbox); } else { ras.filling_rule(fill_non_zero); color = attr.stroke_color; - color.opacity(color.opacity() * attr.stroke_opacity * opacity); + color.opacity(color.opacity() * attr.stroke_opacity * attr.opacity * opacity); ScanlineRenderer ren_s(ren); color.premultiply(); ren_s.color(color); diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index ed6b23979..eae0d54a1 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -411,8 +411,7 @@ void svg_parser::parse_attr(const xmlChar * name, const xmlChar * value ) else if(xmlStrEqual(name, BAD_CAST "opacity")) { double opacity = parse_double((const char*)value); - path_.stroke_opacity(opacity); - path_.fill_opacity(opacity); + path_.opacity(opacity); } else if (xmlStrEqual(name, BAD_CAST "visibility")) {