SVG group renderer implementation (WIP) [skip ci]

This commit is contained in:
Artem Pavlenko 2022-11-18 15:17:58 +00:00
parent a65d65a5ab
commit d4ae5ac653
24 changed files with 764 additions and 429 deletions

View file

@ -56,7 +56,7 @@ struct vector_markers_dispatch : util::noncopyable
{
vector_markers_dispatch(svg_path_ptr const& src,
svg_path_adapter& path,
svg_attribute_type const& attrs,
svg::group const& group_attrs,
agg::trans_affine const& marker_trans,
symbolizer_base const& sym,
Detector& detector,
@ -69,7 +69,7 @@ struct vector_markers_dispatch : util::noncopyable
, renderer_context_(renderer_context)
, src_(src)
, path_(path)
, attrs_(attrs)
, group_attrs_(group_attrs)
, detector_(detector)
{}
@ -86,7 +86,7 @@ struct vector_markers_dispatch : util::noncopyable
agg::trans_affine matrix = params_.placement_params.tr;
matrix.rotate(angle);
matrix.translate(x, y);
renderer_context_.render_marker(src_, path_, attrs_, params_, matrix);
renderer_context_.render_marker(src_, path_, group_attrs_, params_, matrix);
}
}
@ -101,7 +101,7 @@ struct vector_markers_dispatch : util::noncopyable
markers_renderer_context& renderer_context_;
svg_path_ptr const& src_;
svg_path_adapter& path_;
svg_attribute_type const& attrs_;
svg::group const& group_attrs_;
Detector& detector_;
};
@ -152,8 +152,8 @@ void build_ellipse(symbolizer_base const& sym,
svg_storage_type& marker_ellipse,
svg::svg_path_adapter& svg_path);
bool push_explicit_style(svg_attribute_type const& src,
svg_attribute_type& dst,
bool push_explicit_style(svg::group const& src,
svg::group& dst,
symbolizer_base const& sym,
feature_impl& feature,
attributes const& vars);

View file

@ -58,7 +58,7 @@ struct markers_renderer_context : util::noncopyable
virtual void render_marker(svg_path_ptr const& src,
svg_path_adapter& path,
svg_attribute_type const& attrs,
svg::group const& group_attrs,
markers_dispatch_params const& params,
agg::trans_affine const& marker_tr) = 0;
};

View file

@ -44,20 +44,20 @@ namespace mapnik {
struct vector_marker_render_thunk : util::movable
{
svg_path_ptr src_;
svg_attribute_type attrs_;
svg::group group_attrs_;
agg::trans_affine tr_;
double opacity_;
composite_mode_e comp_op_;
bool snap_to_pixels_;
vector_marker_render_thunk(svg_path_ptr const& src,
svg_attribute_type const& attrs,
svg::group const& group_attrs,
agg::trans_affine const& marker_trans,
double opacity,
composite_mode_e comp_op,
bool snap_to_pixels)
: src_(src)
, attrs_(attrs)
, group_attrs_(group_attrs)
, tr_(marker_trans)
, opacity_(opacity)
, comp_op_(comp_op)

View file

@ -0,0 +1,104 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2021 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_SVG_BOUNDING_BOX_HPP
#define MAPNIK_SVG_BOUNDING_BOX_HPP
#include <mapnik/svg/svg_group.hpp>
#include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore_agg.hpp>
#include "agg_basics.h"
MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
namespace svg {
namespace detail {
template <typename VertexSource>
struct bounding_box
{
bounding_box(VertexSource& vs, double& x1, double& y1, double& x2, double& y2, bool& first)
: vs_(vs), x1_(x1), y1_(y1), x2_(x2), y2_(y2), first_(first) {}
void operator() (group const& g) const
{
for (auto const& elem : g.elements)
{
mapbox::util::apply_visitor(bounding_box(vs_, x1_, y1_, x2_, y2_, first_), elem);
}
}
void operator() (path_attributes const& attr) const
{
vs_.rewind(attr.index);
vs_.transformer(const_cast<agg::trans_affine&>(attr.transform));
unsigned cmd;
double x;
double y;
while(!is_stop(cmd = vs_.vertex(&x, &y)))
{
if(is_vertex(cmd))
{
if (first_)
{
x1_ = x;
y1_ = y;
x2_ = x;
y2_ = y;
first_ = false;
}
else
{
if (x < x1_) x1_ = x;
if (y < y1_) y1_ = y;
if (x > x2_) x2_ = x;
if (y > y2_) y2_ = y;
}
}
}
}
VertexSource& vs_;
double& x1_;
double& y1_;
double& x2_;
double& y2_;
bool& first_;
};
} // detail
template <typename VertexSource>
void bounding_box(VertexSource& vs, group const& g, double& x1, double& y1, double& x2, double& y2)
{
bool first = true;
x1 = 1.0;
y1 = 1.0;
x2 = 0.0;
y2 = 0.0; // ^^ FIXME: AGG specific "invalid bbox" logic
for (auto const& elem : g.elements)
{
mapbox::util::apply_visitor(detail::bounding_box<VertexSource>(vs, x1, y1, x2, y2, first), elem);
}
}
} // svg
} // mapnik
#endif //MAPNIK_SVG_BOUNDING_BOX_HPP

View file

@ -26,6 +26,7 @@
// mapnik
#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/svg/svg_path_adapter.hpp>
#include <mapnik/svg/svg_bounding_box.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/safe_cast.hpp>
@ -38,13 +39,16 @@ MAPNIK_DISABLE_WARNING_PUSH
#include "agg_conv_contour.h"
#include "agg_conv_curve.h"
#include "agg_color_rgba.h"
#include "agg_bounding_rect.h"
MAPNIK_DISABLE_WARNING_POP
// stl
#include <vector>
#include <deque>
#include <stdexcept>
#include <mapbox/variant.hpp>
#include <mapnik/svg/svg_group.hpp>
namespace mapnik {
namespace svg {
@ -53,30 +57,42 @@ class svg_converter : util::noncopyable
{
public:
svg_converter(VertexSource& source, AttributeSource& attributes)
: source_(source)
, attributes_(attributes)
, attr_stack_()
, svg_width_(0.0)
, svg_height_(0.0)
svg_converter(VertexSource& source, group& svg_group)
: source_(source),
svg_group_(svg_group),
attr_stack_(),
svg_width_(0.0),
svg_height_(0.0)
{}
void begin_group()
{
current_group_->elements.emplace_back(group {cur_attr().opacity, {}, current_group_});
current_group_ = &current_group_->elements.back().get<group>();
}
void end_group()
{
current_group_ = current_group_->parent;
}
void begin_path()
{
std::size_t idx = source_.start_new_path();
attributes_.emplace_back(cur_attr(), safe_cast<unsigned>(idx));
current_group_->elements.emplace_back(path_attributes {cur_attr(), safe_cast<unsigned>(idx)});
}
void end_path()
{
if (attributes_.empty())
if (current_group_->elements.empty())
{
throw std::runtime_error("end_path : The path was not begun");
}
path_attributes& attr = attributes_.back();
unsigned idx = attr.index;
attr = cur_attr();
attr.index = idx;
//auto& elem = current_group_->elements.back();
//auto& attr = elem.get<path_attributes>();
//unsigned index = attr.index;
//attr = cur_attr();
//attr.index = index;
}
void move_to(double x, double y, bool rel = false) // M, m
@ -295,17 +311,10 @@ class svg_converter : util::noncopyable
// Make all polygons CCW-oriented
void arrange_orientations() { source_.arrange_orientations_all_paths(agg::path_flags_ccw); }
// FIXME!!!!
unsigned operator[](unsigned idx)
{
transform_ = attributes_[idx].transform;
return attributes_[idx].index;
}
void bounding_rect(double* x1, double* y1, double* x2, double* y2)
{
agg::conv_transform<mapnik::svg::svg_path_adapter> trans(source_, transform_);
agg::bounding_rect(trans, *this, 0, attributes_.size(), x1, y1, x2, y2);
agg::conv_transform<mapnik::svg::svg_path_adapter> path(source_, transform_);
bounding_box(path, svg_group_, *x1, *y1, *x2, *y2);
}
void set_dimensions(double w, double h)
@ -334,7 +343,8 @@ class svg_converter : util::noncopyable
private:
VertexSource& source_;
AttributeSource& attributes_;
group& svg_group_;
group* current_group_ = &svg_group_;
AttributeSource attr_stack_;
agg::trans_affine transform_;
double svg_width_;

View file

@ -0,0 +1,49 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2021 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_SVG_GROUP_HPP
#define MAPNIK_SVG_GROUP_HPP
#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/svg/svg_path_adapter.hpp>
#include <mapbox/variant.hpp>
#include <vector>
namespace mapnik {
namespace svg {
struct group;
using group_element = mapbox::util::variant<path_attributes, group>;
struct group
{
double opacity = 1.0;
std::vector<group_element> elements;
group* parent = nullptr;
};
} // svg
} // mapnik
#endif //MAPNIK_SVG_GROUP_HPP

View file

@ -25,6 +25,7 @@
// mapnik
#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/svg/svg_converter.hpp>
#include <mapnik/gradient.hpp>
#include <mapnik/geometry/box2d.hpp>
#include <mapnik/value/types.hpp>
@ -41,6 +42,7 @@ MAPNIK_DISABLE_WARNING_POP
#include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore_agg.hpp>
#include "agg_pixfmt_rgba.h"
#include "agg_path_storage.h"
#include "agg_conv_transform.h"
#include "agg_conv_stroke.h"
@ -124,16 +126,51 @@ class renderer_agg : util::noncopyable
using vertex_source_type = VertexSource;
using attribute_source_type = AttributeSource;
renderer_agg(VertexSource& source, AttributeSource const& attributes)
// mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, agg::pixfmt_rgba32_pre
renderer_agg(VertexSource& source, group const& svg_group)
: source_(source)
, curved_(source_)
, curved_dashed_(curved_)
, curved_stroked_(curved_)
, curved_dashed_stroked_(curved_dashed_)
, attributes_(attributes)
, svg_group_(svg_group)
{}
template<typename Rasterizer, typename Scanline, typename Renderer>
void render(Rasterizer& ras,
Scanline& sl,
Renderer& ren,
agg::trans_affine const& mtx,
double opacity,
box2d<double> const& symbol_bbox)
{
for (auto const& elem : svg_group_.elements)
{
mapbox::util::apply_visitor(group_renderer<Rasterizer, Scanline, Renderer>
(*this, ras, sl, ren, mtx, opacity, symbol_bbox, true), elem);
}
}
template<typename Rasterizer, typename Scanline, typename Renderer>
struct group_renderer
{
group_renderer(renderer_agg& renderer,
Rasterizer & ras, Scanline& sl, Renderer& ren,
agg::trans_affine const& mtx,
double opacity,
box2d<double> const& symbol_bbox,
bool first = false)
: renderer_(renderer),
ras_(ras),
sl_(sl),
ren_(ren),
mtx_(mtx),
opacity_(opacity),
symbol_bbox_(symbol_bbox),
first_(first)
{}
void render_gradient(Rasterizer& ras,
Scanline& sl,
Renderer& ren,
@ -142,7 +179,7 @@ class renderer_agg : util::noncopyable
double opacity,
box2d<double> const& symbol_bbox,
curved_trans_type& curved_trans,
unsigned path_id)
unsigned path_id) const
{
using gamma_lut_type = agg::gamma_lut<agg::int8u, agg::int8u>;
using color_func_type = agg::gradient_lut<agg::color_interpolator<agg::rgba8>, 1024>;
@ -209,6 +246,7 @@ class renderer_agg : util::noncopyable
y2 *= scaleup;
transform.scale(scaleup, scaleup);
interpolator_type span_interpolator(transform);
gradient_adaptor_type gradient_adaptor(radius, (x1 - x2), (y1 - y2));
@ -240,76 +278,91 @@ class renderer_agg : util::noncopyable
}
}
template<typename Rasterizer, typename Scanline, typename Renderer>
void render(Rasterizer& ras,
Scanline& sl,
Renderer& ren,
agg::trans_affine const& mtx,
double opacity,
box2d<double> const& symbol_bbox)
void operator() (group const& g) const
{
double opacity = g.opacity;
if (first_) opacity *= opacity_; // adjust top level opacity
if (opacity < 1.0)
{
mapnik::image_rgba8 im(ren_.width(), ren_.height(), true, true);
agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size());
PixelFormat pixf(buf);
Renderer ren(pixf);
for (auto const& elem : g.elements)
{
mapbox::util::apply_visitor(
group_renderer(renderer_, ras_, sl_, ren, mtx_, opacity_, symbol_bbox_), elem);
}
ren_.blend_from(ren.ren(), 0, 0, 0, unsigned(g.opacity * 255));
}
else
{
for (auto const& elem : g.elements)
{
mapbox::util::apply_visitor(
group_renderer(renderer_, ras_, sl_, ren_, mtx_, opacity_, symbol_bbox_), elem);
}
}
}
void operator() (path_attributes const& attr) const
{
using namespace agg;
trans_affine transform;
curved_stroked_trans_type curved_stroked_trans(curved_stroked_, transform);
curved_dashed_stroked_trans_type curved_dashed_stroked_trans(curved_dashed_stroked_, transform);
curved_trans_type curved_trans(curved_, transform);
curved_stroked_trans_type curved_stroked_trans(renderer_.curved_stroked_, transform);
curved_dashed_stroked_trans_type curved_dashed_stroked_trans(renderer_.curved_dashed_stroked_, transform);
curved_trans_type curved_trans(renderer_.curved_, transform);
curved_trans_contour_type curved_trans_contour(curved_trans);
curved_trans_contour.auto_detect_orientation(true);
for (unsigned i = 0; i < attributes_.size(); ++i)
{
mapnik::svg::path_attributes const& attr = attributes_[i];
if (!attr.visibility_flag)
continue;
if (!attr.visibility_flag) return;
transform = attr.transform;
transform *= mtx;
transform *= mtx_;
double scl = transform.scale();
// curved_.approximation_method(curve_inc);
curved_.approximation_scale(scl);
curved_.angle_tolerance(0.0);
// renderer_.curved_.approximation_method(curve_inc);
renderer_.curved_.approximation_scale(scl);
renderer_.curved_.angle_tolerance(0.0);
typename PixelFormat::color_type color;
if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
{
ras.reset();
ras_.reset();
// https://github.com/mapnik/mapnik/issues/1129
if (std::fabs(curved_trans_contour.width()) <= 1)
{
ras.add_path(curved_trans, attr.index);
ras_.add_path(curved_trans, attr.index);
}
else
{
curved_trans_contour.miter_limit(attr.miter_limit);
ras.add_path(curved_trans_contour, attr.index);
ras_.add_path(curved_trans_contour, attr.index);
}
if (attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
{
render_gradient(ras,
sl,
ren,
render_gradient(ras_,
sl_,
ren_,
attr.fill_gradient,
transform,
attr.fill_opacity * attr.opacity * opacity,
symbol_bbox,
attr.fill_opacity,
symbol_bbox_,
curved_trans,
attr.index);
}
else
{
ras.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero);
ras_.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero);
color = attr.fill_color;
color.opacity(color.opacity() * attr.fill_opacity * attr.opacity * opacity);
ScanlineRenderer ren_s(ren);
color.opacity(color.opacity() * attr.fill_opacity);
ScanlineRenderer ren_s(ren_);
color.premultiply();
ren_s.color(color);
render_scanlines(ras, sl, ren_s);
render_scanlines(ras_, sl_, ren_s);
}
}
@ -317,97 +370,205 @@ class renderer_agg : util::noncopyable
{
if (attr.dash.size() > 0)
{
curved_dashed_stroked_.width(attr.stroke_width);
curved_dashed_stroked_.line_join(attr.line_join);
curved_dashed_stroked_.line_cap(attr.line_cap);
curved_dashed_stroked_.miter_limit(attr.miter_limit);
curved_dashed_stroked_.inner_join(inner_round);
curved_dashed_stroked_.approximation_scale(scl);
renderer_.curved_dashed_stroked_.width(attr.stroke_width);
renderer_.curved_dashed_stroked_.line_join(attr.line_join);
renderer_.curved_dashed_stroked_.line_cap(attr.line_cap);
renderer_.curved_dashed_stroked_.miter_limit(attr.miter_limit);
renderer_.curved_dashed_stroked_.inner_join(inner_round);
renderer_.curved_dashed_stroked_.approximation_scale(scl);
// If the *visual* line width is considerable we
// turn on processing of curve cups.
//---------------------
if (attr.stroke_width * scl > 1.0)
{
curved_.angle_tolerance(0.2);
renderer_.curved_.angle_tolerance(0.2);
}
ras.reset();
curved_dashed_.remove_all_dashes();
ras_.reset();
renderer_.curved_dashed_.remove_all_dashes();
for (auto d : attr.dash)
{
curved_dashed_.add_dash(std::get<0>(d), std::get<1>(d));
renderer_.curved_dashed_.add_dash(std::get<0>(d), std::get<1>(d));
}
curved_dashed_.dash_start(attr.dash_offset);
ras.add_path(curved_dashed_stroked_trans, attr.index);
renderer_.curved_dashed_.dash_start(attr.dash_offset);
ras_.add_path(curved_dashed_stroked_trans, attr.index);
if (attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
{
render_gradient(ras,
sl,
ren,
render_gradient(ras_,
sl_,
ren_,
attr.stroke_gradient,
transform,
attr.stroke_opacity * attr.opacity * opacity,
symbol_bbox,
attr.stroke_opacity,
symbol_bbox_,
curved_trans,
attr.index);
}
else
{
ras.filling_rule(fill_non_zero);
ras_.filling_rule(fill_non_zero);
color = attr.stroke_color;
color.opacity(color.opacity() * attr.stroke_opacity * attr.opacity * opacity);
ScanlineRenderer ren_s(ren);
color.opacity(color.opacity() * attr.stroke_opacity);
ScanlineRenderer ren_s(ren_);
color.premultiply();
ren_s.color(color);
render_scanlines(ras, sl, ren_s);
render_scanlines(ras_, sl_, ren_s);
}
}
else
{
curved_stroked_.width(attr.stroke_width);
curved_stroked_.line_join(attr.line_join);
curved_stroked_.line_cap(attr.line_cap);
curved_stroked_.miter_limit(attr.miter_limit);
curved_stroked_.inner_join(inner_round);
curved_stroked_.approximation_scale(scl);
renderer_.curved_stroked_.width(attr.stroke_width);
renderer_.curved_stroked_.line_join(attr.line_join);
renderer_.curved_stroked_.line_cap(attr.line_cap);
renderer_.curved_stroked_.miter_limit(attr.miter_limit);
renderer_.curved_stroked_.inner_join(inner_round);
renderer_.curved_stroked_.approximation_scale(scl);
// If the *visual* line width is considerable we
// turn on processing of curve cups.
//---------------------
if (attr.stroke_width * scl > 1.0)
{
curved_.angle_tolerance(0.2);
renderer_.curved_.angle_tolerance(0.2);
}
ras.reset();
ras.add_path(curved_stroked_trans, attr.index);
ras_.reset();
ras_.add_path(curved_stroked_trans, attr.index);
if (attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
{
render_gradient(ras,
sl,
ren,
render_gradient(ras_,
sl_,
ren_,
attr.stroke_gradient,
transform,
attr.stroke_opacity * attr.opacity * opacity,
symbol_bbox,
attr.stroke_opacity,
symbol_bbox_,
curved_trans,
attr.index);
}
else
{
ras.filling_rule(fill_non_zero);
ras_.filling_rule(fill_non_zero);
color = attr.stroke_color;
color.opacity(color.opacity() * attr.stroke_opacity * attr.opacity * opacity);
ScanlineRenderer ren_s(ren);
color.opacity(color.opacity() * attr.stroke_opacity);
ScanlineRenderer ren_s(ren_);
color.premultiply();
ren_s.color(color);
render_scanlines(ras, sl, ren_s);
render_scanlines(ras_, sl_, ren_s);
}
}
}
}
renderer_agg& renderer_;
Rasterizer& ras_;
Scanline& sl_;
Renderer& ren_;
agg::trans_affine const& mtx_;
double opacity_;
box2d<double> const& symbol_bbox_;
bool first_;
};
#if defined(GRID_RENDERER)
template<typename Rasterizer, typename Scanline, typename Renderer>
struct grid_renderer
{
grid_renderer(renderer_agg& renderer,
Rasterizer& ras, Scanline& sl, Renderer& ren,
agg::trans_affine const& mtx)
: renderer_(renderer),
ras_(ras),
sl_(sl),
ren_(ren),
mtx_(mtx)
{}
void operator() (group const& g) const
{
for (auto const& elem : g.elements)
{
mapbox::util::apply_visitor(
grid_renderer(renderer_, ras_, sl_, ren_, mtx_), elem);
}
}
void operator() (path_attributes const& attr) const
{
using namespace agg;
trans_affine transform;
curved_stroked_trans_type curved_stroked_trans(renderer_.curved_stroked_, transform);
curved_trans_type curved_trans(renderer_.curved_, transform);
curved_trans_contour_type curved_trans_contour(curved_trans);
curved_trans_contour.auto_detect_orientation(true);
if (!attr.visibility_flag)
return;
transform = attr.transform;
transform *= mtx_;
double scl = transform.scale();
// renderer_.curved_.approximation_method(curve_inc);
renderer_.curved_.approximation_scale(scl);
renderer_.curved_.angle_tolerance(0.0);
typename PixelFormat::color_type color{0};
if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
{
ras_.reset();
if (std::fabs(curved_trans_contour.width()) <= 1)
{
ras_.add_path(curved_trans, attr.index);
}
else
{
curved_trans_contour.miter_limit(attr.miter_limit);
ras_.add_path(curved_trans_contour, attr.index);
}
ras_.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero);
ScanlineRenderer ren_s(ren_);
ren_s.color(color);
render_scanlines(ras_, sl_, ren_s);
}
if (attr.stroke_flag || attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
{
renderer_.curved_stroked_.width(attr.stroke_width);
// m_curved_stroked.line_join((attr.line_join == miter_join) ? miter_join_round : attr.line_join);
renderer_.curved_stroked_.line_join(attr.line_join);
renderer_.curved_stroked_.line_cap(attr.line_cap);
renderer_.curved_stroked_.miter_limit(attr.miter_limit);
renderer_.curved_stroked_.inner_join(inner_round);
renderer_.curved_stroked_.approximation_scale(scl);
// If the *visual* line width is considerable we
// turn on processing of curve cusps.
//---------------------
if (attr.stroke_width * scl > 1.0)
{
renderer_.curved_.angle_tolerance(0.2);
}
ras_.reset();
ras_.add_path(curved_stroked_trans, attr.index);
ras_.filling_rule(fill_non_zero);
ScanlineRenderer ren_s(ren_);
ren_s.color(color);
render_scanlines(ras_, sl_, ren_s);
}
}
#if defined(GRID_RENDERER)
renderer_agg& renderer_;
Rasterizer& ras_;
Scanline& sl_;
Renderer& ren_;
agg::trans_affine const& mtx_;
};
template<typename Rasterizer, typename Scanline, typename Renderer>
void render_id(Rasterizer& ras,
Scanline& sl,
@ -418,76 +579,10 @@ class renderer_agg : util::noncopyable
box2d<double> const& /*symbol_bbox*/)
{
using namespace agg;
trans_affine transform;
curved_stroked_trans_type curved_stroked_trans(curved_stroked_, transform);
curved_trans_type curved_trans(curved_, transform);
curved_trans_contour_type curved_trans_contour(curved_trans);
curved_trans_contour.auto_detect_orientation(true);
for (unsigned i = 0; i < attributes_.size(); ++i)
for (auto const& elem : svg_group_.elements)
{
mapnik::svg::path_attributes const& attr = attributes_[i];
if (!attr.visibility_flag)
continue;
transform = attr.transform;
transform *= mtx;
double scl = transform.scale();
// curved_.approximation_method(curve_inc);
curved_.approximation_scale(scl);
curved_.angle_tolerance(0.0);
typename PixelFormat::color_type color(feature_id);
if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
{
ras.reset();
if (std::fabs(curved_trans_contour.width()) <= 1)
{
ras.add_path(curved_trans, attr.index);
}
else
{
curved_trans_contour.miter_limit(attr.miter_limit);
ras.add_path(curved_trans_contour, attr.index);
}
ras.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero);
ScanlineRenderer ren_s(ren);
ren_s.color(color);
render_scanlines(ras, sl, ren_s);
}
if (attr.stroke_flag || attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
{
curved_stroked_.width(attr.stroke_width);
// m_curved_stroked.line_join((attr.line_join == miter_join) ? miter_join_round : attr.line_join);
curved_stroked_.line_join(attr.line_join);
curved_stroked_.line_cap(attr.line_cap);
curved_stroked_.miter_limit(attr.miter_limit);
curved_stroked_.inner_join(inner_round);
curved_stroked_.approximation_scale(scl);
// If the *visual* line width is considerable we
// turn on processing of curve cusps.
//---------------------
if (attr.stroke_width * scl > 1.0)
{
curved_.angle_tolerance(0.2);
}
ras.reset();
ras.add_path(curved_stroked_trans, attr.index);
ras.filling_rule(fill_non_zero);
ScanlineRenderer ren_s(ren);
ren_s.color(color);
render_scanlines(ras, sl, ren_s);
}
mapbox::util::apply_visitor(grid_renderer<Rasterizer, Scanline, Renderer>
(*this, ras, sl, ren, mtx), elem);
}
}
#endif
@ -496,9 +591,10 @@ class renderer_agg : util::noncopyable
{
return source_;
}
inline AttributeSource const& attributes() const
inline group const& svg_group() const
{
return attributes_;
return svg_group_;
}
private:
@ -508,7 +604,7 @@ class renderer_agg : util::noncopyable
curved_dashed_type curved_dashed_;
curved_stroked_type curved_stroked_;
curved_dashed_stroked_type curved_dashed_stroked_;
AttributeSource const& attributes_;
group const& svg_group_;
};
} // namespace svg

View file

@ -26,6 +26,7 @@
// mapnik
#include <mapnik/geometry/box2d.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/svg/svg_group.hpp>
namespace mapnik {
namespace svg {
@ -39,15 +40,9 @@ class svg_storage : util::noncopyable
, svg_height_(0)
{}
VertexSource& source() // FIXME!! make const
{
return source_;
}
VertexSource& source() { return source_;}
AttributeSource& attributes() // FIXME!! make const
{
return attributes_;
}
svg::group& svg_group() { return svg_group_; }
void set_bounding_box(box2d<double> const& b) { bounding_box_ = b; }
@ -68,7 +63,7 @@ class svg_storage : util::noncopyable
private:
VertexSource source_;
AttributeSource attributes_;
svg::group svg_group_;
box2d<double> bounding_box_;
double svg_width_;
double svg_height_;

View file

@ -433,7 +433,7 @@ struct agg_render_marker_visitor
svg_path_adapter svg_path(stl_storage);
svg::renderer_agg<svg_path_adapter, svg_attribute_type, renderer_type, pixfmt_comp_type> svg_renderer(
svg_path,
marker.get_data()->attributes());
marker.get_data()->svg_group());
// https://github.com/mapnik/mapnik/issues/1316
// https://github.com/mapnik/mapnik/issues/1866

View file

@ -87,7 +87,7 @@ struct thunk_renderer<image_rgba8> : render_thunk_list_dispatch
renderer_base renb(pixf);
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(thunk.src_->source());
svg_path_adapter svg_path(stl_storage);
svg_renderer_type svg_renderer(svg_path, thunk.attrs_);
svg_renderer_type svg_renderer(svg_path, thunk.group_attrs_);
agg::trans_affine offset_tr = thunk.tr_;
offset_tr.translate(offset_.x, offset_.y);

View file

@ -75,11 +75,11 @@ struct agg_markers_renderer_context : markers_renderer_context
virtual void render_marker(svg_path_ptr const& src,
svg_path_adapter& path,
svg_attribute_type const& attrs,
svg::group const& group_attrs,
markers_dispatch_params const& params,
agg::trans_affine const& marker_tr)
{
SvgRenderer svg_renderer(path, attrs);
SvgRenderer svg_renderer(path, group_attrs);
render_vector_marker(svg_renderer,
ras_,
renb_,
@ -89,8 +89,7 @@ struct agg_markers_renderer_context : markers_renderer_context
params.snap_to_pixels);
}
virtual void
render_marker(image_rgba8 const& src, markers_dispatch_params const& params, agg::trans_affine const& marker_tr)
virtual void render_marker(image_rgba8 const& src, markers_dispatch_params const& params, agg::trans_affine const& marker_tr)
{
// In the long term this should be a visitor pattern based on the type of
// render src provided that converts the destination pixel type required.

View file

@ -184,7 +184,7 @@ struct grid_render_marker_visitor
svg_path_adapter svg_path(stl_storage);
svg::renderer_agg<svg_path_adapter, svg_attribute_type, renderer_type, pixfmt_type> svg_renderer(
svg_path,
marker.get_data()->attributes());
marker.get_data()->svg_group());
svg_renderer.render_id(*ras_ptr_, sl, renb, feature_.id(), mtx, opacity_, bbox);
}

View file

@ -84,7 +84,7 @@ struct thunk_renderer : render_thunk_list_dispatch
renderer_type ren(renb);
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(thunk.src_->source());
svg_path_adapter svg_path(stl_storage);
svg_renderer_type svg_renderer(svg_path, thunk.attrs_);
svg_renderer_type svg_renderer(svg_path, thunk.group_attrs_);
agg::trans_affine offset_tr = thunk.tr_;
offset_tr.translate(offset_.x, offset_.y);
agg::scanline_bin sl;

View file

@ -91,11 +91,11 @@ struct grid_markers_renderer_context : markers_renderer_context
virtual void render_marker(svg_path_ptr const& src,
svg_path_adapter& path,
svg_attribute_type const& attrs,
svg::group const& svg_group,
markers_dispatch_params const& params,
agg::trans_affine const& marker_tr)
{
SvgRenderer svg_renderer_(path, attrs);
SvgRenderer svg_renderer_(path, svg_group);
agg::scanline_bin sl_;
svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), marker_tr, params.opacity, src->bounding_box());
place_feature();
@ -153,6 +153,7 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
}
template void grid_renderer<grid>::process(markers_symbolizer const&, mapnik::feature_impl&, proj_transform const&);
} // namespace mapnik
#endif
#endif // GRID_RENDEDER

View file

@ -170,7 +170,7 @@ std::shared_ptr<mapnik::marker const> marker_cache::find(std::string const& uri,
svg_path_ptr marker_path(std::make_shared<svg_storage_type>());
vertex_stl_adapter<svg_path_storage> stl_storage(marker_path->source());
svg_path_adapter svg_path(stl_storage);
svg_converter_type svg(svg_path, marker_path->attributes());
svg_converter_type svg(svg_path, marker_path->svg_group());
svg_parser p(svg, strict);
p.parse_from_string(known_svg_string);
@ -211,7 +211,7 @@ std::shared_ptr<mapnik::marker const> marker_cache::find(std::string const& uri,
svg_path_ptr marker_path(std::make_shared<svg_storage_type>());
vertex_stl_adapter<svg_path_storage> stl_storage(marker_path->source());
svg_path_adapter svg_path(stl_storage);
svg_converter_type svg(svg_path, marker_path->attributes());
svg_converter_type svg(svg_path, marker_path->svg_group());
svg_parser p(svg, strict);
p.parse(uri);

View file

@ -60,7 +60,7 @@ void build_ellipse(symbolizer_base const& sym,
{
half_stroke_width = get<double>(sym, keys::stroke_width, feature, vars, 0.0) / 2.0;
}
svg::svg_converter_type styled_svg(svg_path, marker_ellipse.attributes());
svg::svg_converter_type styled_svg(svg_path, marker_ellipse.svg_group());
styled_svg.push_attr();
styled_svg.begin_path();
agg::ellipse c(0, 0, width / 2.0, height / 2.0);
@ -78,8 +78,101 @@ void build_ellipse(symbolizer_base const& sym,
marker_ellipse.set_bounding_box(lox, loy, hix, hiy);
}
bool push_explicit_style(svg_attribute_type const& src,
svg_attribute_type& dst,
namespace detail {
struct push_explicit_style
{
push_explicit_style(svg::group& dst,
boost::optional<color> const& fill_color,
boost::optional<double> const& fill_opacity,
boost::optional<color> const& stroke_color,
boost::optional<double> const& stroke_width,
boost::optional<double> const& stroke_opacity)
: current_group_(&dst),
fill_color_(fill_color),
fill_opacity_(fill_opacity),
stroke_color_(stroke_color),
stroke_width_(stroke_width),
stroke_opacity_(stroke_opacity)
{}
void operator() (svg::group const& g) const
{
current_group_->elements.emplace_back(svg::group{g.opacity, {}, current_group_});
current_group_ = &current_group_->elements.back().get<svg::group>();
for (auto const& elem : g.elements)
{
mapbox::util::apply_visitor
(push_explicit_style(*current_group_,
fill_color_,
fill_opacity_,
stroke_color_,
stroke_width_,
stroke_opacity_), elem);
}
current_group_ = current_group_->parent;
}
void operator() (svg::path_attributes const& attr) const
{
svg::path_attributes new_attr{attr, attr.index};
if (!attr.visibility_flag)
return;
if (!attr.stroke_none)
{
if (stroke_width_)
{
new_attr.stroke_width = *stroke_width_;
new_attr.stroke_flag = true;
}
if (stroke_color_)
{
color const& s_color = *stroke_color_;
new_attr.stroke_color = agg::rgba(s_color.red() / 255.0,
s_color.green() / 255.0,
s_color.blue() / 255.0,
s_color.alpha() / 255.0);
new_attr.stroke_flag = true;
}
if (stroke_opacity_)
{
new_attr.stroke_opacity = *stroke_opacity_;
new_attr.stroke_flag = true;
}
}
if (!attr.fill_none)
{
if (fill_color_)
{
color const& f_color = *fill_color_;
new_attr.fill_color = agg::rgba(f_color.red() / 255.0,
f_color.green() / 255.0,
f_color.blue() / 255.0,
f_color.alpha() / 255.0);
new_attr.fill_flag = true;
}
if (fill_opacity_)
{
new_attr.fill_opacity = *fill_opacity_;
new_attr.fill_flag = true;
}
}
current_group_->elements.emplace_back(new_attr);
}
mutable svg::group* current_group_;
boost::optional<color> const& fill_color_;
boost::optional<double> const& fill_opacity_;
boost::optional<color> const& stroke_color_;
boost::optional<double> const& stroke_width_;
boost::optional<double> const& stroke_opacity_;
};
} // detail
bool push_explicit_style(svg::group const& src,
svg::group& dst,
symbolizer_base const& sym,
feature_impl& feature,
attributes const& vars)
@ -89,60 +182,19 @@ bool push_explicit_style(svg_attribute_type const& src,
auto stroke_color = get_optional<color>(sym, keys::stroke, feature, vars);
auto stroke_width = get_optional<double>(sym, keys::stroke_width, feature, vars);
auto stroke_opacity = get_optional<double>(sym, keys::stroke_opacity, feature, vars);
if (fill_color || fill_opacity || stroke_color || stroke_width || stroke_opacity)
{
bool success = false;
for (unsigned i = 0; i < src.size(); ++i)
{
dst.push_back(src[i]);
mapnik::svg::path_attributes& attr = dst.back();
if (!attr.visibility_flag)
continue;
success = true;
if (!attr.stroke_none)
for (auto const& elem : src.elements)
{
if (stroke_width)
{
attr.stroke_width = *stroke_width;
attr.stroke_flag = true;
}
if (stroke_color)
{
color const& s_color = *stroke_color;
attr.stroke_color = agg::rgba(s_color.red() / 255.0,
s_color.green() / 255.0,
s_color.blue() / 255.0,
s_color.alpha() / 255.0);
attr.stroke_flag = true;
}
if (stroke_opacity)
{
attr.stroke_opacity = *stroke_opacity;
attr.stroke_flag = true;
mapbox::util::apply_visitor
(detail::push_explicit_style
(dst, fill_color, fill_opacity,
stroke_color, stroke_width, stroke_opacity), elem);
}
}
if (!attr.fill_none)
{
if (fill_color)
{
color const& f_color = *fill_color;
attr.fill_color = agg::rgba(f_color.red() / 255.0,
f_color.green() / 255.0,
f_color.blue() / 255.0,
f_color.alpha() / 255.0);
attr.fill_flag = true;
}
if (fill_opacity)
{
attr.fill_opacity = *fill_opacity;
attr.fill_flag = true;
}
}
}
return success;
}
return false;
return true;
}
void setup_transform_scaling(agg::trans_affine& tr,

View file

@ -55,14 +55,14 @@ struct render_marker_symbolizer_visitor
, renderer_context_(renderer_context)
{}
svg_attribute_type const& get_marker_attributes(svg_path_ptr const& stock_marker,
svg_attribute_type& custom_attr) const
svg::group const& get_marker_attributes(svg_path_ptr const& stock_marker,
svg::group& custom_group_attrs) const
{
auto const& stock_attr = stock_marker->attributes();
if (push_explicit_style(stock_attr, custom_attr, sym_, feature_, common_.vars_))
return custom_attr;
auto const& stock_group_attrs = stock_marker->svg_group();
if (push_explicit_style(stock_group_attrs, custom_group_attrs, sym_, feature_, common_.vars_))
return custom_group_attrs;
else
return stock_attr;
return stock_group_attrs;
}
template<typename Marker, typename Dispatch>
@ -130,8 +130,9 @@ struct render_marker_symbolizer_visitor
svg_path_ptr marker_ptr = stock_vector_marker;
bool is_ellipse = false;
svg_attribute_type s_attributes;
auto const& r_attributes = get_marker_attributes(stock_vector_marker, s_attributes);
//svg_attribute_type s_attributes;
svg::group svg_group_attrs;
auto const& svg_group_attrs_updated = get_marker_attributes(stock_vector_marker, svg_group_attrs);
// special case for simple ellipse markers
// to allow for full control over rx/ry dimensions
@ -161,7 +162,7 @@ struct render_marker_symbolizer_visitor
vector_dispatch_type rasterizer_dispatch(marker_ptr,
svg_path,
r_attributes,
svg_group_attrs_updated,
image_tr,
sym_,
*common_.detector_,

View file

@ -47,11 +47,15 @@ void render_pattern<image_rgba8>(marker_svg const& marker,
double opacity,
image_rgba8& image)
{
using pixfmt = agg::pixfmt_rgba32_pre;
using color_type = agg::rgba8;
using order_type = agg::order_rgba;
using blender_type = agg::comp_op_adaptor_rgba_pre<color_type, order_type>; // comp blender
using buf_type = agg::rendering_buffer;
using pixfmt = agg::pixfmt_custom_blend_rgba<blender_type, buf_type>;
using renderer_base = agg::renderer_base<pixfmt>;
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
agg::scanline_u8 sl;
agg::scanline_u8 sl;
mapnik::box2d<double> const& bbox = marker.bounding_box() * tr;
mapnik::coord<double, 2> c = bbox.center();
agg::trans_affine mtx = agg::trans_affine_translation(-c.x, -c.y);
@ -66,9 +70,8 @@ void render_pattern<image_rgba8>(marker_svg const& marker,
svg_path_adapter svg_path(stl_storage);
svg::renderer_agg<svg_path_adapter, svg_attribute_type, renderer_solid, pixfmt> svg_renderer(
svg_path,
marker.get_data()->attributes());
marker.get_data()->svg_group());
rasterizer ras;
svg_renderer.render(ras, sl, renb, mtx, opacity, bbox);
}

View file

@ -48,11 +48,11 @@ struct thunk_markers_renderer_context : markers_renderer_context
virtual void render_marker(svg_path_ptr const& src,
svg_path_adapter& path,
svg_attribute_type const& attrs,
svg::group const& group_attrs,
markers_dispatch_params const& params,
agg::trans_affine const& marker_tr)
{
vector_marker_render_thunk thunk(src, attrs, marker_tr, params.opacity, comp_op_, params.snap_to_pixels);
vector_marker_render_thunk thunk(src, group_attrs, marker_tr, params.opacity, comp_op_, params.snap_to_pixels);
thunks_.emplace_back(std::move(thunk));
}

View file

@ -539,6 +539,7 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
if (parser.css_style_)
process_css(parser, node);
parse_attr(parser, node);
parser.path_.begin_group();
}
break;
case "use"_case:
@ -558,7 +559,9 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
parse_attr(parser, node);
if (parser.path_.display())
{
if (parser.path_.cur_attr().opacity < 1.0) parser.path_.begin_group();
parse_element(parser, node->name(), node);
if (parser.path_.cur_attr().opacity < 1.0) parser.path_.end_group();
}
parser.path_.pop_attr();
}
@ -611,6 +614,7 @@ void end_element(svg_parser& parser, rapidxml::xml_node<char> const* node)
auto name = name_to_int(node->name());
if (!parser.is_defs_ && (name == "g"_case))
{
parser.path_.end_group();
if (node->first_node() != nullptr)
{
parser.path_.pop_attr();
@ -618,6 +622,7 @@ void end_element(svg_parser& parser, rapidxml::xml_node<char> const* node)
}
else if (name == "svg"_case)
{
parser.path_.end_group();
if (node->first_node() != nullptr)
{
parser.path_.pop_attr();
@ -670,6 +675,7 @@ void parse_element(svg_parser& parser, char const* name, rapidxml::xml_node<char
parse_ellipse(parser, node);
break;
case "svg"_case:
parser.path_.begin_group();
parser.path_.push_attr();
parse_dimensions(parser, node);
parse_attr(parser, node);
@ -864,6 +870,7 @@ void parse_attr(svg_parser& parser, char const* name, char const* value)
void parse_attr(svg_parser& parser, rapidxml::xml_node<char> const* node)
{
parser.path_.opacity(1.0); // default path opacity = 1.0
for (rapidxml::xml_attribute<char> const* attr = node->first_attribute(); attr; attr = attr->next_attribute())
{
auto const* name = attr->name();
@ -1544,16 +1551,18 @@ void parse_radial_gradient(svg_parser& parser, rapidxml::xml_node<char> const* n
fx = parse_svg_value(parser, attr->value(), has_percent);
}
else
{
fx = cx;
}
attr = node->first_attribute("fy");
if (attr != nullptr)
{
fy = parse_svg_value(parser, attr->value(), has_percent);
}
else
{
fy = cy;
}
attr = node->first_attribute("r");
if (attr != nullptr)
{

View file

@ -47,7 +47,7 @@ struct test_parser
explicit test_parser(bool strict = false)
: stl_storage(path.source())
, svg_path(stl_storage)
, svg(svg_path, path.attributes())
, svg(svg_path, path.svg_group())
, p(svg, strict)
{}
@ -261,10 +261,11 @@ TEST_CASE("SVG parser")
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
mapnik::svg::svg_path_adapter path(stl_storage);
auto const& attrs = storage->attributes();
auto const& group_attrs = storage->svg_group();
agg::line_cap_e expected_cap(agg::square_cap);
REQUIRE(attrs.size() == 1);
REQUIRE(attrs[0].line_cap == expected_cap);
REQUIRE(group_attrs.elements.size() == 1);
// FIXME
//REQUIRE(attrs[0].line_cap == expected_cap);
double x, y;
unsigned cmd;
@ -427,23 +428,23 @@ TEST_CASE("SVG parser")
REQUIRE(storage);
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
auto const& attrs = storage->attributes();
auto const& group_attrs = storage->svg_group();
agg::line_join_e expected_join(agg::bevel_join);
REQUIRE(attrs.size() == 1);
REQUIRE(attrs[0].line_join == expected_join);
REQUIRE(group_attrs.elements.size() == 1);
// FIXME
//REQUIRE(attrs[0].line_join == expected_join);
}
SECTION("SVG <line>")
{
//
std::string svg_name("./test/data/svg/line.svg");
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(svg_name, false);
REQUIRE(marker);
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(0.3543307086614174,0.3543307086614174,
// 424.8425196850394059,141.3779527559055396));
REQUIRE(bbox == mapnik::box2d<double>(0.3543307086614174,0.3543307086614174,
424.8425196850394059,141.3779527559055396));
auto storage = svg.get_data();
REQUIRE(storage);
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
@ -471,14 +472,13 @@ TEST_CASE("SVG parser")
SECTION("SVG <polyline>")
{
//
std::string svg_name("./test/data/svg/polyline.svg");
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(svg_name, false);
REQUIRE(marker);
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,1199.0,399.0));
REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,1199.0,399.0));
auto storage = svg.get_data();
REQUIRE(storage);
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
@ -510,14 +510,13 @@ TEST_CASE("SVG parser")
SECTION("SVG <polygon>")
{
//
std::string svg_name("./test/data/svg/polygon.svg");
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(svg_name, false);
REQUIRE(marker);
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,1199.0,399.0));
REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,1199.0,399.0));
auto storage = svg.get_data();
REQUIRE(storage);
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
@ -548,14 +547,13 @@ TEST_CASE("SVG parser")
SECTION("SVG <gradient>")
{
//
std::string svg_name("./test/data/svg/gradient.svg");
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(svg_name, false);
REQUIRE(marker);
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,799.0,599.0));
REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,799.0,599.0));
auto storage = svg.get_data();
REQUIRE(storage);
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
@ -651,14 +649,15 @@ TEST_CASE("SVG parser")
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,699.0,199.0));
REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,699.0,199.0));
auto storage = svg.get_data();
REQUIRE(storage);
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
auto const& attrs = storage->attributes();
REQUIRE(attrs.size() == 3);
REQUIRE(attrs[1].fill_gradient == attrs[2].fill_gradient);
auto const& group_attrs = storage->svg_group();
REQUIRE(group_attrs.elements.size() == 3);
// FIXME
//REQUIRE(attrs[1].fill_gradient == attrs[2].fill_gradient);
mapnik::svg::svg_path_adapter path(stl_storage);
double x, y;
@ -694,24 +693,24 @@ TEST_CASE("SVG parser")
SECTION("SVG <gradient> with transformations")
{
//
std::string svg_name("./test/data/svg/gradient-transform.svg");
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(svg_name, false);
REQUIRE(marker);
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,799.0,599.0));
REQUIRE(bbox == mapnik::box2d<double>(1.0,1.0,799.0,599.0));
auto storage = svg.get_data();
REQUIRE(storage);
auto const& attrs = storage->attributes();
REQUIRE(attrs.size() == 3);
REQUIRE(attrs[1].fill_gradient == attrs[2].fill_gradient);
REQUIRE(attrs[1].fill_gradient.get_gradient_type() == mapnik::RADIAL);
auto const& group_attrs = storage->svg_group();
// FIXME
//REQUIRE(attrs.size() == 3);
//REQUIRE(attrs[1].fill_gradient == attrs[2].fill_gradient);
//REQUIRE(attrs[1].fill_gradient.get_gradient_type() == mapnik::RADIAL);
agg::trans_affine transform;
transform *= agg::trans_affine_translation(240, 155);
REQUIRE(attrs[1].fill_gradient.get_transform() == transform);
//REQUIRE(attrs[1].fill_gradient.get_transform() == transform);
}
SECTION("SVG <gradient> with xlink:href")
@ -722,15 +721,16 @@ TEST_CASE("SVG parser")
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(20,20,460,230));
REQUIRE(bbox == mapnik::box2d<double>(20,20,460,230));
auto storage = svg.get_data();
REQUIRE(storage);
auto const& attrs = storage->attributes();
REQUIRE(attrs.size() == 2);
REQUIRE(attrs[0].fill_gradient.get_gradient_type() == mapnik::LINEAR);
REQUIRE(attrs[1].fill_gradient.get_gradient_type() == mapnik::LINEAR);
REQUIRE(attrs[1].fill_gradient.has_stop());
auto const& group_attrs = storage->svg_group();
// FIXME
//REQUIRE(attrs.elements.size() == 2);
//REQUIRE(attrs[0].fill_gradient.get_gradient_type() == mapnik::LINEAR);
//REQUIRE(attrs[1].fill_gradient.get_gradient_type() == mapnik::LINEAR);
//REQUIRE(attrs[1].fill_gradient.has_stop());
}
SECTION("SVG <gradient> with radial percents")
@ -741,21 +741,22 @@ TEST_CASE("SVG parser")
REQUIRE(marker->is<mapnik::marker_svg>());
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
auto bbox = svg.bounding_box();
// REQUIRE(bbox == mapnik::box2d<double>(0,0,200,200));
REQUIRE(bbox == mapnik::box2d<double>(0,0,200,200));
auto storage = svg.get_data();
REQUIRE(storage);
double x1, x2, y1, y2, r;
auto const& attrs = storage->attributes();
REQUIRE(attrs.size() == 1);
REQUIRE(attrs[0].fill_gradient.get_gradient_type() == mapnik::RADIAL);
REQUIRE(attrs[0].fill_gradient.has_stop());
attrs[0].fill_gradient.get_control_points(x1, y1, x2, y2, r);
REQUIRE(x1 == 0);
REQUIRE(y1 == 0.25);
REQUIRE(x2 == 0.10);
REQUIRE(y2 == 0.10);
REQUIRE(r == 0.75);
// FIXME
//auto const& attrs = storage->attributes();
//REQUIRE(attrs.size() == 1);
//REQUIRE(attrs[0].fill_gradient.get_gradient_type() == mapnik::RADIAL);
//REQUIRE(attrs[0].fill_gradient.has_stop());
//attrs[0].fill_gradient.get_control_points(x1, y1, x2, y2, r);
//REQUIRE(x1 == 0);
//REQUIRE(y1 == 0.25);
//REQUIRE(x2 == 0.10);
//REQUIRE(y2 == 0.10);
//REQUIRE(r == 0.75);
}
SECTION("SVG <clipPath>")

View file

@ -38,7 +38,7 @@ void test_path_parser(std::string const& str, Expected const& expected)
mapnik::svg_path_ptr marker_path(std::make_shared<mapnik::svg_storage_type>());
vertex_stl_adapter<svg_path_storage> stl_storage(marker_path->source());
svg_path_adapter svg_path(stl_storage);
svg_converter_type svg(svg_path, marker_path->attributes());
svg_converter_type svg(svg_path, marker_path->svg_group());
CHECK(mapnik::svg::parse_path(str.c_str(), svg));
double x, y;

View file

@ -48,12 +48,18 @@ namespace {
mapnik::image_rgba8 render_svg(std::string const& filename, double scale_factor)
{
using pixfmt = agg::pixfmt_rgba32_pre;
using color_type = agg::rgba8;
using order_type = agg::order_rgba;
using blender_type = agg::comp_op_adaptor_rgba_pre<color_type, order_type>; // comp blender
using buf_type = agg::rendering_buffer;
using pixfmt = agg::pixfmt_custom_blend_rgba<blender_type, buf_type>;
using renderer_base = agg::renderer_base<pixfmt>;
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
agg::rasterizer_scanline_aa<> ras_ptr;
agg::scanline_u8 sl;
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(filename, false);
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
double svg_width, svg_height;
@ -73,8 +79,8 @@ mapnik::image_rgba8 render_svg(std::string const& filename, double scale_factor)
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(svg.get_data()->source());
mapnik::svg::svg_path_adapter svg_path(stl_storage);
mapnik::svg::
renderer_agg<mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, agg::pixfmt_rgba32_pre>
renderer(svg_path, svg.get_data()->attributes());
renderer_agg<mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, pixfmt>
renderer(svg_path, svg.get_data()->svg_group());
double opacity = 1.0;
renderer.render(ras_ptr, sl, renb, mtx, opacity, {0, 0, svg_width, svg_height});
return im;
@ -101,8 +107,8 @@ TEST_CASE("SVG renderer")
double scale_factor = 1.0;
std::string octocat_inline("./test/data/svg/octocat.svg");
std::string octocat_css("./test/data/svg/octocat-css.svg");
auto image1 = render_svg(octocat_inline, 1.0);
auto image2 = render_svg(octocat_css, 1.0);
auto image1 = render_svg(octocat_inline, scale_factor);
auto image2 = render_svg(octocat_css, scale_factor);
REQUIRE(equal(image1, image2));
}
}

View file

@ -64,9 +64,19 @@ struct main_marker_visitor
int operator()(mapnik::marker_svg const& marker) const
{
#if 1
using color_type = agg::rgba8;
using order_type = agg::order_rgba;
using blender_type = agg::comp_op_adaptor_rgba_pre<color_type, order_type>; //comp blender
using buf_type = agg::rendering_buffer;
using pixfmt = agg::pixfmt_custom_blend_rgba<blender_type, buf_type>;
using renderer_base = agg::renderer_base<pixfmt>;
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
#else
using pixfmt = agg::pixfmt_rgba32_pre;
using renderer_base = agg::renderer_base<pixfmt>;
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
#endif
agg::rasterizer_scanline_aa<> ras_ptr;
agg::scanline_u8 sl;
@ -109,9 +119,8 @@ struct main_marker_visitor
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(marker.get_data()->source());
mapnik::svg::svg_path_adapter svg_path(stl_storage);
mapnik::svg::
renderer_agg<mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, agg::pixfmt_rgba32_pre>
svg_renderer_this(svg_path, marker.get_data()->attributes());
mapnik::svg::renderer_agg<mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, pixfmt>
svg_renderer_this(svg_path, marker.get_data()->svg_group());
svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox);