add support for opacity with svgs in pattern symbolizers - refs #1010

This commit is contained in:
Dane Springmeyer 2014-08-05 13:48:40 -07:00
parent 0c2e1d6166
commit 2a7fc29e42
18 changed files with 215 additions and 8 deletions

View file

@ -37,7 +37,10 @@ namespace mapnik {
struct rasterizer;
class marker;
std::shared_ptr<image_data_32> render_pattern(rasterizer & ras, marker const& marker, agg::trans_affine const& tr);
std::shared_ptr<image_data_32> render_pattern(rasterizer & ras,
marker const& marker,
agg::trans_affine const& tr,
double opacity);
} // namespace mapnik

View file

@ -106,6 +106,8 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
boost::optional<mapnik::marker_ptr> marker_ptr = marker_cache::instance().find(filename, true);
if (!marker_ptr || !(*marker_ptr)) return;
boost::optional<image_ptr> pat;
// TODO - re-implement at renderer level like polygon_pattern symbolizer
double opacity = get<value_double>(sym, keys::opacity, feature, common_.vars_,1.0);
if ((*marker_ptr)->is_bitmap())
{
pat = (*marker_ptr)->get_bitmap_data();
@ -115,13 +117,12 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
if (image_transform) evaluate_transform(image_tr, feature, common_.vars_, *image_transform);
pat = render_pattern(*ras_ptr, **marker_ptr, image_tr);
pat = render_pattern(*ras_ptr, **marker_ptr, image_tr, opacity);
}
if (!pat) return;
bool clip = get<value_bool>(sym, keys::clip, feature, common_.vars_, false);
//double opacity = get<value_double>(sym,keys::stroke_opacity,feature, 1.0); TODO
double offset = get<value_double>(sym, keys::offset, feature, common_.vars_, 0.0);
double simplify_tolerance = get<value_double>(sym, keys::simplify_tolerance, feature, common_.vars_, 0.0);
double smooth = get<value_double>(sym, keys::smooth, feature, common_.vars_, false);

View file

@ -74,7 +74,7 @@ void agg_renderer<T0,T1>::process(polygon_pattern_symbolizer const& sym,
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
if (image_transform) evaluate_transform(image_tr, feature, common_.vars_, *image_transform);
pat = render_pattern(*ras_ptr, **marker_ptr, image_tr);
pat = render_pattern(*ras_ptr, **marker_ptr, image_tr, 1.0);
}
if (!pat) return;

View file

@ -631,6 +631,8 @@ void cairo_renderer_base::process(line_pattern_symbolizer const& sym,
context_.set_operator(comp_op);
std::shared_ptr<cairo_pattern> pattern;
image_ptr image = nullptr;
// TODO - re-implement at renderer level like polygon_pattern symbolizer
double opacity = get<value_double>(sym, keys::opacity, feature, common_.vars_,1.0);
if ((*marker)->is_bitmap())
{
pattern = std::make_unique<cairo_pattern>(**((*marker)->get_bitmap_data()));
@ -642,7 +644,7 @@ void cairo_renderer_base::process(line_pattern_symbolizer const& sym,
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
if (image_transform) evaluate_transform(image_tr, feature, common_.vars_, *image_transform);
image = render_pattern(ras, **marker, image_tr);
image = render_pattern(ras, **marker, image_tr, opacity);
pattern = std::make_unique<cairo_pattern>(*image);
width = image->width();
height = image->height();
@ -745,7 +747,8 @@ void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym,
else
{
mapnik::rasterizer ras;
image_ptr image = render_pattern(ras, **marker, image_tr);
double opacity = get<double>(sym,keys::opacity, feature, common_.vars_, 1.0);
image_ptr image = render_pattern(ras, **marker, image_tr, opacity);
cairo_pattern pattern(*image);
pattern.set_extend(CAIRO_EXTEND_REPEAT);
pattern.set_origin(offset_x, offset_y);

View file

@ -1014,6 +1014,7 @@ void map_parser::parse_line_pattern_symbolizer(rule & rule, xml_node const & nod
line_pattern_symbolizer symbol;
parse_symbolizer_base(symbol, node);
put(symbol, keys::file, parse_path(file));
set_symbolizer_property<line_pattern_symbolizer,double>(symbol, keys::opacity, node);
// offset value
optional<double> offset = node.get_opt_attr<double>("offset");

View file

@ -35,7 +35,10 @@
namespace mapnik {
std::shared_ptr<image_data_32> render_pattern(rasterizer & ras, marker const& marker, agg::trans_affine const& tr)
std::shared_ptr<image_data_32> render_pattern(rasterizer & ras,
marker const& marker,
agg::trans_affine const& tr,
double opacity)
{
using pixfmt = agg::pixfmt_rgba32_pre;
using renderer_base = agg::renderer_base<pixfmt>;
@ -61,7 +64,7 @@ std::shared_ptr<image_data_32> render_pattern(rasterizer & ras, marker const& ma
agg::pixfmt_rgba32_pre > svg_renderer(svg_path,
(*marker.get_vector_data())->attributes());
svg_renderer.render(ras, sl, renb, mtx, 1.0, bbox);
svg_renderer.render(ras, sl, renb, mtx, opacity, bbox);
return image;
}

View file

@ -0,0 +1,34 @@
{
"keys": [
"",
"1"
],
"data": {},
"grid": [
" !! ! !! !!!!!!!!! !!!!!!!!! !! !!! ",
" !! !! !!!!!!!! !! !!!!! !!!!! !! !! ",
" !! !!!!!! !!! !!! !!!! !! !! ",
" !! ! !!!! !!! !!!!!!!! !!!! !! !! ",
" !! !! !!! !!!!!!!!!!!!!!! !!! !!! !! ",
" !! !!!!!! !!!!!!! !!!! !!! !!! !! !!! ",
" !! !!!!! !!!! !!!! !! !!!! !! !! ",
" !! !!!!!! !!!!!! !!!! !!!! !! !!!! !! ! ",
" !! !!!!!! !! !!! !!!!!!!!!!! !!!!!!!!!! ",
" !! !!!!! !! !!!!!!!! !! !! !! !!!! ",
" ! !! !!!!!! !! !! ! !! !! !! !!!! ! ",
" !!!!!!!! !! !!!!!!!! !!!!! !!! !! !! !! ",
" !!!! !!!!! !!!! ! !! !!! !!! !!! !! !! ",
" !!! !!!!! !!! !!!!!! !! !!!! !!! !! !! ",
" !! !!!!!!!! !! !!!!!! !!!!!!!!! !! ",
" !! !!! !! !!!! !!!! !! ! ",
" !! !!! !!!!! !!!! !!!! !! !! ",
" !! !!! !!! !!!!!! !! !!!! !! ",
" ! !!! !!!!!!!!!!! !! !!!! !! ",
" !! !!!!!!!!!!!!!!!!! !! !! ",
" ! !!!!! !!!!!! !!!! !! ",
" !!!!! !!! !! !! ! !! !! ",
" !! !!!!!!! ! !! !!!! ",
" !! !! !!!! ! !!!! !! ",
" !! !! !!!!! !! !! "
]
}

View file

@ -0,0 +1,137 @@
{
"keys": [
"",
"1"
],
"data": {},
"grid": [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" !!! !! ",
" !!!!!!!!! !!!!!!!! ",
" !!! !!!! !!!! !!! ",
" !!! !!!!! !!! !!! !!!!! !! ",
" !! !!!!!!!! !!! !!! !!!!!!!! !! ",
" !!!!! ! !! !! !!! !! !! !!! !! ",
" !! !! !!!!! !! !! !! !! !!!!! !!!!!! ",
" !! ! !!! !!!!! !! !! !! !!! !! !! !!! ",
" !! !! !!!!!!! !!!! !! !! !!!!!!!!! !! !! ",
" !! !!!!!!! !! !! !! !! !!!!!!!!!!!!!! !! !! ",
" !!!! !!!! !! ! !! !!!!!!!!! !!!!!! !! ",
" !! !! !!! !! !!!! !! !!!!! !!!!!!!!! ",
" !! ! !!! !!!!! ! !! !!!!!!!!!!!!!! !!!!! !!! ",
" !! !! !!! !!!!!!! !! !!!!!!!!!!! !!!!! !!!!! !! ",
" !! !!!!! !!!!!! !!!! !! !!!!!! !!!!!!!!! !! ",
" !!!! !! !! !!! !!!! !! !!!!! !!!! !!!!!!!! !! ",
" !! !! !! !! !!!!! !! !! !!!!! !!!!!!!!!! !!!! !!!!!! ",
" !! !!!! !!! !!! ! !! !!!!!!!!! !!! !!!! !!!! !! !!! ",
" !! !!!!! !! !!! !!!! !!! !!!!! !!! !!!! !!!!!! !! ",
" !! !!!! !! !! !!!!! !! !!! !!!!! !! !!! !!!!!!! !! ",
" !!!! !! !!! !!!! !!!!! !!! !!!! !!!!!!!! !!! !!!!!!! !! ",
" !! !!!!! !! !!! !!!!! !! !!!!!!! !!!!!!!!! !!! !!! !!!!!! ",
" !! !!!! !! !! !!!!! !! !! !!! !! !! !!! !!!!!! !!! ",
" !! !!!!! !! !! !! !!!!! !!! !!!!! !! !!!!!! !! ",
" !! !!!!!!! !!! !!!!! !! !!!! !!!!!! !! !!!!!!! !! ",
" !!!! !! !! !! !!!!! !!!!!!!! !!! !! !! !!!!!!! !! ",
" !! !!!!!!! !! !!!!!! !!!!! !!!!!! !!! !!!!!!!!!!",
" !! !!!! !! !!! ! !!! !!!! !! !! !!!!!!! !!",
" !! !! !!!! !! !!!!!! !!!! !! !! !!!!!!! !",
" !! !!!!!!! !! !!!! !!!!!!!!!!!!!!! !!!!!!!! !! ",
" !!!! !!!! !! !! !! !!!!!! !! !! !! !!!!!!!!",
" !! !! !!!! !! !!!! !! !! !!!!!!! !!",
" !! !!!! !! !! !! !! !!! !!! !! !! !! !",
" !! !! !!!! !! !! !!!! !!!!!!!! !! !!!!! ",
" !! !! !!!! !! !!!!!!!!!!! !! !! !! !!!",
" !! ! !! !! !! !! !! !!! !! !!!! !!!",
" !! !! !!!! !! !!!!!!!! !! !! !! !!",
" !! !! !!!! !! !!! !!! !! !!!! !!",
" ! !! !!!!! !! !!!! !!! !! !!!!",
" !! !! !!!! !! !!!!!! !!!! !",
" !! !! !!!! !! !! !!!",
" !! !! !!!!! !! !! !! ",
" !! !! !!!! !! !!!! ",
" ! !! !!!!! !! !! ",
" !! !! !!!!! !! ",
" !! !! !!!!!!! ",
" !! !! !!!!! !! ",
" !! !! !!!!! !! ",
" ! !! !!!!!!!! ",
" !! !! !!!!! !! ",
" !! !! !!!!! !! ",
" !! !! !!!!!!!! ",
" !!!!!!!! !! !! !!!!! !! ",
" !!!! !!!!! ! !! !!!!!! !! ",
" !!! !!!! !!!! !! !! !!!!!! ! ",
" !! !!!!!!!! !!!! !! !! ! !!! !! ",
" !! !!! !!!! !!!! !! !! !!!!!! !! ",
" !! !!! !!!!! !!!! !!!! !! !! !!!!!! ! ",
" !! !!! !!! !!!! !!!! !!!! !! !! !! !!!!!! ",
" !! !!! !! !!!!!!!! !!!! !!!! !! !! !!!!!! !! ",
" !! !!! !!!!!!!!!!!!!! !!!! !!! !!!! !! !!!! !! ",
"!! !!! !!!!! !!!!! !!!! !!! !! !! !! ! !!!! ",
"! !!! !!!! !!!!!!! !!!!!! !!! !! !! !! !!!!!! !! ",
" !!! !!! !!!!!!!!!! !!!!!! !! !!! !! !! !!!! !! ",
"!!! !!! !!!! !!! !! !!! !!!!! !! !!!! !!!! ",
"!! !!! !!! !!!!! !! !! !! !! !!!! !! !!!! !! ",
"! !!!! !! !!!!!!!! !! !! ! !! ! !! !! !!!! ! ",
" !!!! !! !!! !!! !! !!!!!! ! !!!! !! ! !! ",
"!!!! !! !!! !!! !! !!!!!! !! !! !!!! !! ",
"!!! !!! !! !!! !!!!!! !! !!!! !! !!!! ",
" !! !! !! !! !!!!!! !!!! !! !!!! !! ",
"!! !! !! !! !!!! !!!!! !!!! !! !! ",
"!!!! !!! !! !!!! !! !! !! !!!! ",
" !! !! !! !! !!!!! !!!!! !! !! ",
" ! !! !!!!!!! !!!!!! !!!!! ! ",
" !! !! !!!!! !!!!! !! ",
" ! !! !!!!! !!!!! !! ",
" !! !!!!!!!!!!! !!! ",
" !! !!!!!!!!! !!! ",
" !! !!! !!! !!! ",
" !! !!!!! !!! ",
" !! !!! ",
" !!!!!!! ",
" !!!! ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Map background-color="white">
<Style name="style">
<Rule>
<LineSymbolizer stroke="yellow" stroke-width="6" offset="30" smooth="1"/>
<LineSymbolizer stroke="orange" stroke-width="6" offset="20" smooth="1"/>
<LineSymbolizer stroke="red" stroke-width="6" offset="10" smooth="1"/>
<LineSymbolizer stroke="green" stroke-width="6" offset="0" smooth="1"/>
<LineSymbolizer stroke="blue" stroke-width="6" offset="-10" smooth="1"/>
<LineSymbolizer stroke="purple" stroke-width="6" offset="-20" smooth="1"/>
<LinePatternSymbolizer file="../../data/svg/octocat.svg" opacity=".1" comp-op="multiply" transform="scale(.05)" offset="30" smooth="1"/>
<LinePatternSymbolizer file="../../data/svg/octocat.svg" opacity=".1" comp-op="multiply" transform="scale(.05) rotate(90)" offset="-20" smooth="1"/>
</Rule>
</Style>
<Layer name="layer">
<StyleName>style</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">../data/line.shp</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -257,6 +257,7 @@ files = {
'text-halo-opacity':{'sizes':[(512,512)]},
# https://github.com/mapnik/mapnik/issues/2202
'line-smooth-and-offset':{'sizes':[(512,512)]},
'line-pattern-smooth-and-offset':{'sizes':[(512,512)]},
'halo-comp-op-on-satellite':{'sizes':[(450,450)]},
'marker-whole-multi-polygon':{'sizes':[(512,512)]}
}