Skip to content

Commit

Permalink
fix handling of svg opacity, which should be applied to fill/stroke o…
Browse files Browse the repository at this point in the history
…pacity at render time - closes #1744
  • Loading branch information
Dane Springmeyer committed Mar 11, 2013
1 parent 3b834b4 commit 29ce3b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/mapnik/svg/svg_converter.hpp
Expand Up @@ -264,15 +264,15 @@ class svg_converter : mapnik::noncopyable
{
cur_attr().fill_opacity = op;
}

void stroke_opacity(double op)
{
cur_attr().stroke_opacity = op;
}

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)
Expand Down
4 changes: 4 additions & 0 deletions include/mapnik/svg/svg_path_attributes.hpp
Expand Up @@ -38,6 +38,7 @@ namespace svg {
struct path_attributes
{
unsigned index;
double opacity;
agg::rgba8 fill_color;
double fill_opacity;
agg::rgba8 stroke_color;
Expand All @@ -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)),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions include/mapnik/svg/svg_renderer_agg.hpp
Expand Up @@ -290,13 +290,13 @@ class svg_renderer_agg : mapnik::noncopyable

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);
Expand Down Expand Up @@ -326,13 +326,13 @@ class svg_renderer_agg : mapnik::noncopyable

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);
Expand Down
3 changes: 1 addition & 2 deletions src/svg/svg_parser.cpp
Expand Up @@ -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"))
{
Expand Down

0 comments on commit 29ce3b1

Please sign in to comment.