clang-format
This commit is contained in:
parent
e790aa6c06
commit
7c24ff09ee
14 changed files with 165 additions and 147 deletions
|
@ -37,7 +37,13 @@ template <typename VertexSource>
|
||||||
struct bounding_box
|
struct bounding_box
|
||||||
{
|
{
|
||||||
bounding_box(VertexSource& vs, double& x1, double& y1, double& x2, double& y2, bool& first)
|
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) {}
|
: vs_(vs)
|
||||||
|
, x1_(x1)
|
||||||
|
, y1_(y1)
|
||||||
|
, x2_(x2)
|
||||||
|
, y2_(y2)
|
||||||
|
, first_(first)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator()(group const& g) const
|
void operator()(group const& g) const
|
||||||
{
|
{
|
||||||
|
@ -67,10 +73,14 @@ struct bounding_box
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (x < x1_) x1_ = x;
|
if (x < x1_)
|
||||||
if (y < y1_) y1_ = y;
|
x1_ = x;
|
||||||
if (x > x2_) x2_ = x;
|
if (y < y1_)
|
||||||
if (y > y2_) y2_ = y;
|
y1_ = y;
|
||||||
|
if (x > x2_)
|
||||||
|
x2_ = x;
|
||||||
|
if (y > y2_)
|
||||||
|
y2_ = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +92,7 @@ struct bounding_box
|
||||||
double& y2_;
|
double& y2_;
|
||||||
bool& first_;
|
bool& first_;
|
||||||
};
|
};
|
||||||
} // detail
|
} // namespace detail
|
||||||
|
|
||||||
template<typename VertexSource>
|
template<typename VertexSource>
|
||||||
void bounding_box(VertexSource& vs, group const& g, double& x1, double& y1, double& x2, double& y2)
|
void bounding_box(VertexSource& vs, group const& g, double& x1, double& y1, double& x2, double& y2)
|
||||||
|
@ -98,7 +108,7 @@ void bounding_box(VertexSource& vs, group const& g, double& x1, double& y1, doub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // svg
|
} // namespace svg
|
||||||
} // mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_SVG_BOUNDING_BOX_HPP
|
#endif // MAPNIK_SVG_BOUNDING_BOX_HPP
|
||||||
|
|
|
@ -58,11 +58,11 @@ class svg_converter : util::noncopyable
|
||||||
public:
|
public:
|
||||||
|
|
||||||
svg_converter(VertexSource& source, group& svg_group)
|
svg_converter(VertexSource& source, group& svg_group)
|
||||||
: source_(source),
|
: source_(source)
|
||||||
svg_group_(svg_group),
|
, svg_group_(svg_group)
|
||||||
attr_stack_(),
|
, attr_stack_()
|
||||||
svg_width_(0.0),
|
, svg_width_(0.0)
|
||||||
svg_height_(0.0)
|
, svg_height_(0.0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void set_opacity(double opacity) { svg_group_.opacity = opacity; }
|
void set_opacity(double opacity) { svg_group_.opacity = opacity; }
|
||||||
|
@ -73,10 +73,7 @@ class svg_converter : util::noncopyable
|
||||||
current_group_ = ¤t_group_->elements.back().get<group>();
|
current_group_ = ¤t_group_->elements.back().get<group>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_group()
|
void end_group() { current_group_ = current_group_->parent; }
|
||||||
{
|
|
||||||
current_group_ = current_group_->parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void begin_path()
|
void begin_path()
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#ifndef MAPNIK_SVG_GROUP_HPP
|
#ifndef MAPNIK_SVG_GROUP_HPP
|
||||||
#define MAPNIK_SVG_GROUP_HPP
|
#define MAPNIK_SVG_GROUP_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <mapnik/svg/svg_path_attributes.hpp>
|
#include <mapnik/svg/svg_path_attributes.hpp>
|
||||||
#include <mapnik/svg/svg_path_adapter.hpp>
|
#include <mapnik/svg/svg_path_adapter.hpp>
|
||||||
#include <mapbox/variant.hpp>
|
#include <mapbox/variant.hpp>
|
||||||
|
@ -43,7 +42,7 @@ struct group
|
||||||
group* parent = nullptr;
|
group* parent = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // svg
|
} // namespace svg
|
||||||
} // mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_SVG_GROUP_HPP
|
#endif // MAPNIK_SVG_GROUP_HPP
|
||||||
|
|
|
@ -154,8 +154,9 @@ class renderer_agg : util::noncopyable
|
||||||
Renderer ren_g(pixf);
|
Renderer ren_g(pixf);
|
||||||
for (auto const& elem : svg_group_.elements)
|
for (auto const& elem : svg_group_.elements)
|
||||||
{
|
{
|
||||||
mapbox::util::apply_visitor(group_renderer<Rasterizer, Scanline, Renderer>
|
mapbox::util::apply_visitor(
|
||||||
(*this, ras, sl, ren_g, mtx, symbol_bbox), elem);
|
group_renderer<Rasterizer, Scanline, Renderer>(*this, ras, sl, ren_g, mtx, symbol_bbox),
|
||||||
|
elem);
|
||||||
}
|
}
|
||||||
ren.blend_from(ren_g.ren(), 0, 0, 0, unsigned(adjusted_opacity * 255));
|
ren.blend_from(ren_g.ren(), 0, 0, 0, unsigned(adjusted_opacity * 255));
|
||||||
}
|
}
|
||||||
|
@ -163,8 +164,9 @@ class renderer_agg : util::noncopyable
|
||||||
{
|
{
|
||||||
for (auto const& elem : svg_group_.elements)
|
for (auto const& elem : svg_group_.elements)
|
||||||
{
|
{
|
||||||
mapbox::util::apply_visitor(group_renderer<Rasterizer, Scanline, Renderer>
|
mapbox::util::apply_visitor(
|
||||||
(*this, ras, sl, ren, mtx, symbol_bbox), elem);
|
group_renderer<Rasterizer, Scanline, Renderer>(*this, ras, sl, ren, mtx, symbol_bbox),
|
||||||
|
elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,15 +175,17 @@ class renderer_agg : util::noncopyable
|
||||||
struct group_renderer
|
struct group_renderer
|
||||||
{
|
{
|
||||||
group_renderer(renderer_agg& renderer,
|
group_renderer(renderer_agg& renderer,
|
||||||
Rasterizer & ras, Scanline& sl, Renderer& ren,
|
Rasterizer& ras,
|
||||||
|
Scanline& sl,
|
||||||
|
Renderer& ren,
|
||||||
agg::trans_affine const& mtx,
|
agg::trans_affine const& mtx,
|
||||||
box2d<double> const& symbol_bbox)
|
box2d<double> const& symbol_bbox)
|
||||||
: renderer_(renderer),
|
: renderer_(renderer)
|
||||||
ras_(ras),
|
, ras_(ras)
|
||||||
sl_(sl),
|
, sl_(sl)
|
||||||
ren_(ren),
|
, ren_(ren)
|
||||||
mtx_(mtx),
|
, mtx_(mtx)
|
||||||
symbol_bbox_(symbol_bbox)
|
, symbol_bbox_(symbol_bbox)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void render_gradient(Rasterizer& ras,
|
void render_gradient(Rasterizer& ras,
|
||||||
|
@ -302,8 +306,7 @@ class renderer_agg : util::noncopyable
|
||||||
Renderer ren(pixf);
|
Renderer ren(pixf);
|
||||||
for (auto const& elem : g.elements)
|
for (auto const& elem : g.elements)
|
||||||
{
|
{
|
||||||
mapbox::util::apply_visitor(
|
mapbox::util::apply_visitor(group_renderer(renderer_, ras_, sl_, ren, mtx_, symbol_bbox_), elem);
|
||||||
group_renderer(renderer_, ras_, sl_, ren, mtx_, symbol_bbox_), elem);
|
|
||||||
}
|
}
|
||||||
ren_.blend_from(ren.ren(), 0, 0, 0, unsigned(opacity * 255));
|
ren_.blend_from(ren.ren(), 0, 0, 0, unsigned(opacity * 255));
|
||||||
}
|
}
|
||||||
|
@ -311,8 +314,7 @@ class renderer_agg : util::noncopyable
|
||||||
{
|
{
|
||||||
for (auto const& elem : g.elements)
|
for (auto const& elem : g.elements)
|
||||||
{
|
{
|
||||||
mapbox::util::apply_visitor(
|
mapbox::util::apply_visitor(group_renderer(renderer_, ras_, sl_, ren_, mtx_, symbol_bbox_), elem);
|
||||||
group_renderer(renderer_, ras_, sl_, ren_, mtx_, symbol_bbox_), elem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,7 +330,8 @@ class renderer_agg : util::noncopyable
|
||||||
curved_trans_contour_type curved_trans_contour(curved_trans);
|
curved_trans_contour_type curved_trans_contour(curved_trans);
|
||||||
curved_trans_contour.auto_detect_orientation(true);
|
curved_trans_contour.auto_detect_orientation(true);
|
||||||
|
|
||||||
if (!attr.visibility_flag) return;
|
if (!attr.visibility_flag)
|
||||||
|
return;
|
||||||
|
|
||||||
transform = attr.transform;
|
transform = attr.transform;
|
||||||
|
|
||||||
|
@ -484,23 +487,24 @@ class renderer_agg : util::noncopyable
|
||||||
struct grid_renderer
|
struct grid_renderer
|
||||||
{
|
{
|
||||||
grid_renderer(renderer_agg& renderer,
|
grid_renderer(renderer_agg& renderer,
|
||||||
Rasterizer& ras, Scanline& sl, Renderer& ren,
|
Rasterizer& ras,
|
||||||
|
Scanline& sl,
|
||||||
|
Renderer& ren,
|
||||||
agg::trans_affine const& mtx,
|
agg::trans_affine const& mtx,
|
||||||
mapnik::value_integer const& feature_id)
|
mapnik::value_integer const& feature_id)
|
||||||
: renderer_(renderer),
|
: renderer_(renderer)
|
||||||
ras_(ras),
|
, ras_(ras)
|
||||||
sl_(sl),
|
, sl_(sl)
|
||||||
ren_(ren),
|
, ren_(ren)
|
||||||
mtx_(mtx),
|
, mtx_(mtx)
|
||||||
feature_id_(feature_id)
|
, feature_id_(feature_id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void operator()(group const& g) const
|
void operator()(group const& g) const
|
||||||
{
|
{
|
||||||
for (auto const& elem : g.elements)
|
for (auto const& elem : g.elements)
|
||||||
{
|
{
|
||||||
mapbox::util::apply_visitor(
|
mapbox::util::apply_visitor(grid_renderer(renderer_, ras_, sl_, ren_, mtx_, feature_id_), elem);
|
||||||
grid_renderer(renderer_, ras_, sl_, ren_, mtx_, feature_id_), elem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void operator()(path_attributes const& attr) const
|
void operator()(path_attributes const& attr) const
|
||||||
|
@ -594,8 +598,9 @@ class renderer_agg : util::noncopyable
|
||||||
{
|
{
|
||||||
for (auto const& elem : svg_group_.elements)
|
for (auto const& elem : svg_group_.elements)
|
||||||
{
|
{
|
||||||
mapbox::util::apply_visitor(grid_renderer<Rasterizer, Scanline, Renderer>
|
mapbox::util::apply_visitor(
|
||||||
(*this, ras, sl, ren, mtx, feature_id), elem);
|
grid_renderer<Rasterizer, Scanline, Renderer>(*this, ras, sl, ren, mtx, feature_id),
|
||||||
|
elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -89,7 +89,8 @@ struct agg_markers_renderer_context : markers_renderer_context
|
||||||
params.snap_to_pixels);
|
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
|
// 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.
|
// render src provided that converts the destination pixel type required.
|
||||||
|
|
|
@ -88,12 +88,12 @@ struct push_explicit_style
|
||||||
boost::optional<color> const& stroke_color,
|
boost::optional<color> const& stroke_color,
|
||||||
boost::optional<double> const& stroke_width,
|
boost::optional<double> const& stroke_width,
|
||||||
boost::optional<double> const& stroke_opacity)
|
boost::optional<double> const& stroke_opacity)
|
||||||
: current_group_(&dst),
|
: current_group_(&dst)
|
||||||
fill_color_(fill_color),
|
, fill_color_(fill_color)
|
||||||
fill_opacity_(fill_opacity),
|
, fill_opacity_(fill_opacity)
|
||||||
stroke_color_(stroke_color),
|
, stroke_color_(stroke_color)
|
||||||
stroke_width_(stroke_width),
|
, stroke_width_(stroke_width)
|
||||||
stroke_opacity_(stroke_opacity)
|
, stroke_opacity_(stroke_opacity)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool operator()(svg::group const& g) const
|
bool operator()(svg::group const& g) const
|
||||||
|
@ -103,13 +103,13 @@ struct push_explicit_style
|
||||||
bool success = false;
|
bool success = false;
|
||||||
for (auto const& elem : g.elements)
|
for (auto const& elem : g.elements)
|
||||||
{
|
{
|
||||||
if (mapbox::util::apply_visitor
|
if (mapbox::util::apply_visitor(push_explicit_style(*current_group_,
|
||||||
(push_explicit_style(*current_group_,
|
|
||||||
fill_color_,
|
fill_color_,
|
||||||
fill_opacity_,
|
fill_opacity_,
|
||||||
stroke_color_,
|
stroke_color_,
|
||||||
stroke_width_,
|
stroke_width_,
|
||||||
stroke_opacity_), elem))
|
stroke_opacity_),
|
||||||
|
elem))
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ struct push_explicit_style
|
||||||
boost::optional<double> const& stroke_opacity_;
|
boost::optional<double> const& stroke_opacity_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // detail
|
} // namespace detail
|
||||||
|
|
||||||
bool push_explicit_style(svg::group const& src,
|
bool push_explicit_style(svg::group const& src,
|
||||||
svg::group& dst,
|
svg::group& dst,
|
||||||
|
@ -194,10 +194,13 @@ bool push_explicit_style(svg::group const& src,
|
||||||
{
|
{
|
||||||
for (auto const& elem : src.elements)
|
for (auto const& elem : src.elements)
|
||||||
{
|
{
|
||||||
if (mapbox::util::apply_visitor
|
if (mapbox::util::apply_visitor(detail::push_explicit_style(dst,
|
||||||
(detail::push_explicit_style
|
fill_color,
|
||||||
(dst, fill_color, fill_opacity,
|
fill_opacity,
|
||||||
stroke_color, stroke_width, stroke_opacity), elem))
|
stroke_color,
|
||||||
|
stroke_width,
|
||||||
|
stroke_opacity),
|
||||||
|
elem))
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,7 @@ struct render_marker_symbolizer_visitor
|
||||||
, renderer_context_(renderer_context)
|
, renderer_context_(renderer_context)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
svg::group const& get_marker_attributes(svg_path_ptr const& stock_marker,
|
svg::group const& get_marker_attributes(svg_path_ptr const& stock_marker, svg::group& custom_group_attrs) const
|
||||||
svg::group& custom_group_attrs) const
|
|
||||||
{
|
{
|
||||||
auto const& stock_group_attrs = stock_marker->svg_group();
|
auto const& stock_group_attrs = stock_marker->svg_group();
|
||||||
if (push_explicit_style(stock_group_attrs, custom_group_attrs, sym_, feature_, common_.vars_))
|
if (push_explicit_style(stock_group_attrs, custom_group_attrs, sym_, feature_, common_.vars_))
|
||||||
|
|
|
@ -548,9 +548,11 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
|
||||||
if (parser.css_style_)
|
if (parser.css_style_)
|
||||||
process_css(parser, node);
|
process_css(parser, node);
|
||||||
parse_attr(parser, node);
|
parse_attr(parser, node);
|
||||||
if (parser.path_.cur_attr().opacity < 1.0) parser.path_.begin_group();
|
if (parser.path_.cur_attr().opacity < 1.0)
|
||||||
|
parser.path_.begin_group();
|
||||||
parse_use(parser, node);
|
parse_use(parser, node);
|
||||||
if (parser.path_.cur_attr().opacity < 1.0) parser.path_.end_group();
|
if (parser.path_.cur_attr().opacity < 1.0)
|
||||||
|
parser.path_.end_group();
|
||||||
parser.path_.pop_attr();
|
parser.path_.pop_attr();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -561,9 +563,11 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
|
||||||
parse_attr(parser, node);
|
parse_attr(parser, node);
|
||||||
if (parser.path_.display())
|
if (parser.path_.display())
|
||||||
{
|
{
|
||||||
if (parser.path_.cur_attr().opacity < 1.0) parser.path_.begin_group();
|
if (parser.path_.cur_attr().opacity < 1.0)
|
||||||
|
parser.path_.begin_group();
|
||||||
parse_element(parser, node->name(), node);
|
parse_element(parser, node->name(), node);
|
||||||
if (parser.path_.cur_attr().opacity < 1.0) parser.path_.end_group();
|
if (parser.path_.cur_attr().opacity < 1.0)
|
||||||
|
parser.path_.end_group();
|
||||||
}
|
}
|
||||||
parser.path_.pop_attr();
|
parser.path_.pop_attr();
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,8 +443,9 @@ TEST_CASE("SVG parser")
|
||||||
REQUIRE(marker->is<mapnik::marker_svg>());
|
REQUIRE(marker->is<mapnik::marker_svg>());
|
||||||
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
|
mapnik::marker_svg const& svg = mapnik::util::get<mapnik::marker_svg>(*marker);
|
||||||
auto bbox = svg.bounding_box();
|
auto bbox = svg.bounding_box();
|
||||||
REQUIRE(bbox == mapnik::box2d<double>(0.3543307086614174,0.3543307086614174,
|
REQUIRE(
|
||||||
424.8425196850394059,141.3779527559055396));
|
bbox ==
|
||||||
|
mapnik::box2d<double>(0.3543307086614174, 0.3543307086614174, 424.8425196850394059, 141.3779527559055396));
|
||||||
auto storage = svg.get_data();
|
auto storage = svg.get_data();
|
||||||
REQUIRE(storage);
|
REQUIRE(storage);
|
||||||
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
|
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(storage->source());
|
||||||
|
|
|
@ -56,7 +56,6 @@ mapnik::image_rgba8 render_svg(std::string const& filename, double scale_factor)
|
||||||
using renderer_base = agg::renderer_base<pixfmt>;
|
using renderer_base = agg::renderer_base<pixfmt>;
|
||||||
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
|
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
|
||||||
|
|
||||||
|
|
||||||
agg::rasterizer_scanline_aa<> ras_ptr;
|
agg::rasterizer_scanline_aa<> ras_ptr;
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
|
|
||||||
|
@ -78,9 +77,9 @@ 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::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::svg_path_adapter svg_path(stl_storage);
|
||||||
mapnik::svg::
|
mapnik::svg::renderer_agg<mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, pixfmt> renderer(
|
||||||
renderer_agg<mapnik::svg_path_adapter, mapnik::svg_attribute_type, renderer_solid, pixfmt>
|
svg_path,
|
||||||
renderer(svg_path, svg.get_data()->svg_group());
|
svg.get_data()->svg_group());
|
||||||
double opacity = 1.0;
|
double opacity = 1.0;
|
||||||
renderer.render(ras_ptr, sl, renb, mtx, opacity, {0, 0, svg_width, svg_height});
|
renderer.render(ras_ptr, sl, renb, mtx, opacity, {0, 0, svg_width, svg_height});
|
||||||
return im;
|
return im;
|
||||||
|
|
|
@ -56,11 +56,11 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
struct main_marker_visitor
|
struct main_marker_visitor
|
||||||
{
|
{
|
||||||
main_marker_visitor(std::string const& svg_name, double scale_factor, double opacity, bool verbose, bool auto_open)
|
main_marker_visitor(std::string const& svg_name, double scale_factor, double opacity, bool verbose, bool auto_open)
|
||||||
: svg_name_(svg_name),
|
: svg_name_(svg_name)
|
||||||
scale_factor_(scale_factor),
|
, scale_factor_(scale_factor)
|
||||||
opacity_(opacity),
|
, opacity_(opacity)
|
||||||
verbose_(verbose),
|
, verbose_(verbose)
|
||||||
auto_open_(auto_open)
|
, auto_open_(auto_open)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int operator()(mapnik::marker_svg const& marker) const
|
int operator()(mapnik::marker_svg const& marker) const
|
||||||
|
|
Loading…
Reference in a new issue