Polygon pattern on line geometries for AGG backend
This commit is contained in:
parent
2929c4ae6d
commit
18c1a99604
11 changed files with 378 additions and 153 deletions
156
include/mapnik/agg/render_polygon_pattern.hpp
Normal file
156
include/mapnik/agg/render_polygon_pattern.hpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2017 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_RENDER_POLYGON_PATTERN_HPP
|
||||
#define MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
||||
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <mapnik/vertex_processor.hpp>
|
||||
#include <mapnik/renderer_common/pattern_alignment.hpp>
|
||||
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
|
||||
#include <mapnik/renderer_common/clipping_extent.hpp>
|
||||
#include <mapnik/vertex_converters.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore_agg.hpp>
|
||||
#include "agg_basics.h"
|
||||
#include "agg_rendering_buffer.h"
|
||||
#include "agg_pixfmt_rgba.h"
|
||||
#include "agg_color_rgba.h"
|
||||
#include "agg_rasterizer_scanline_aa.h"
|
||||
#include "agg_scanline_u.h"
|
||||
#include "agg_renderer_scanline.h"
|
||||
#include "agg_span_allocator.h"
|
||||
#include "agg_span_pattern_rgba.h"
|
||||
#include "agg_image_accessors.h"
|
||||
#include "agg_conv_clip_polygon.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
struct agg_pattern_base
|
||||
{
|
||||
image_rgba8 const& pattern_img_;
|
||||
renderer_common const& common_;
|
||||
symbolizer_base const& sym_;
|
||||
mapnik::feature_impl const& feature_;
|
||||
proj_transform const& prj_trans_;
|
||||
|
||||
agg::trans_affine geom_transform() const
|
||||
{
|
||||
agg::trans_affine tr;
|
||||
auto transform = get_optional<transform_type>(sym_, keys::geometry_transform);
|
||||
if (transform)
|
||||
{
|
||||
evaluate_transform(tr, feature_, common_.vars_, *transform, common_.scale_factor_);
|
||||
}
|
||||
return tr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename VertexConverter>
|
||||
struct agg_polygon_pattern : agg_pattern_base
|
||||
{
|
||||
using color_type = agg::rgba8;
|
||||
using order_type = agg::order_rgba;
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<color_type, order_type>;
|
||||
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||
using wrap_x_type = agg::wrap_mode_repeat;
|
||||
using wrap_y_type = agg::wrap_mode_repeat;
|
||||
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre,
|
||||
wrap_x_type,
|
||||
wrap_y_type>;
|
||||
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_type>;
|
||||
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base,
|
||||
agg::span_allocator<agg::rgba8>,
|
||||
span_gen_type>;
|
||||
|
||||
agg_polygon_pattern(image_rgba8 const& pattern_img,
|
||||
renderer_common const& common,
|
||||
symbolizer_base const& sym,
|
||||
mapnik::feature_impl const& feature,
|
||||
proj_transform const& prj_trans)
|
||||
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans},
|
||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
||||
clip_box_(clipping_extent(common)),
|
||||
tr_(geom_transform()),
|
||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
||||
feature, common.vars_, common.scale_factor_)
|
||||
{
|
||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
||||
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
||||
|
||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
||||
converter_.template set<affine_transform_tag>();
|
||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
||||
}
|
||||
|
||||
void render(renderer_base & ren_base, rasterizer & ras)
|
||||
{
|
||||
pattern_alignment_enum alignment = get<pattern_alignment_enum, keys::alignment>(
|
||||
sym_, feature_, common_.vars_);
|
||||
unsigned offset_x=0;
|
||||
unsigned offset_y=0;
|
||||
|
||||
if (alignment == LOCAL_ALIGNMENT)
|
||||
{
|
||||
double x0 = 0;
|
||||
double y0 = 0;
|
||||
using apply_local_alignment = detail::apply_local_alignment;
|
||||
apply_local_alignment apply(common_.t_, prj_trans_, clip_box_, x0, y0);
|
||||
util::apply_visitor(geometry::vertex_processor<apply_local_alignment>(apply), feature_.get_geometry());
|
||||
|
||||
offset_x = unsigned(ren_base.width() - x0);
|
||||
offset_y = unsigned(ren_base.height() - y0);
|
||||
}
|
||||
|
||||
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
|
||||
pattern_img_.width(), pattern_img_.height(),
|
||||
pattern_img_.width() * 4);
|
||||
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
||||
img_source_type img_src(pixf_pattern);
|
||||
span_gen_type sg(img_src, offset_x, offset_y);
|
||||
|
||||
agg::span_allocator<agg::rgba8> sa;
|
||||
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
|
||||
|
||||
using apply_vertex_converter_type = detail::apply_vertex_converter<
|
||||
VertexConverter, rasterizer>;
|
||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||
apply_vertex_converter_type apply(converter_, ras);
|
||||
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||
agg::scanline_u8 sl;
|
||||
agg::render_scanlines(ras, sl, rp);
|
||||
}
|
||||
|
||||
const bool clip_;
|
||||
const box2d<double> clip_box_;
|
||||
const agg::trans_affine tr_;
|
||||
VertexConverter converter_;
|
||||
};
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
|
||||
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
|
@ -25,6 +25,13 @@
|
|||
#define MAPNIK_PATTERN_ALIGNMENT_HPP
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/vertex_adapters.hpp>
|
||||
#include <mapnik/transform_path_adapter.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore_agg.hpp>
|
||||
#include "agg_conv_clip_polygon.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace detail {
|
||||
|
||||
|
|
|
@ -94,7 +94,8 @@ enum class property_types : std::uint8_t
|
|||
target_vertical_alignment,
|
||||
target_upright,
|
||||
target_direction,
|
||||
target_font_feature_settings
|
||||
target_font_feature_settings,
|
||||
target_line_pattern,
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -189,6 +190,7 @@ ENUM_FROM_STRING( text_transform_enum )
|
|||
ENUM_FROM_STRING( text_upright_enum )
|
||||
ENUM_FROM_STRING( direction_enum )
|
||||
ENUM_FROM_STRING( gamma_method_enum )
|
||||
ENUM_FROM_STRING( line_pattern_enum )
|
||||
|
||||
// enum
|
||||
template <typename T, bool is_enum = true>
|
||||
|
|
|
@ -369,6 +369,13 @@ struct symbolizer_default<value_bool, keys::avoid_edges>
|
|||
|
||||
// font-feature-settings
|
||||
|
||||
// line-pattern
|
||||
template <>
|
||||
struct symbolizer_default<line_pattern_enum, keys::line_pattern>
|
||||
{
|
||||
static line_pattern_enum value() { return LINE_PATTERN_WARP; }
|
||||
};
|
||||
|
||||
// extend
|
||||
template <>
|
||||
struct symbolizer_default<value_double, keys::extend>
|
||||
|
|
|
@ -222,6 +222,14 @@ enum gamma_method_enum : std::uint8_t
|
|||
|
||||
DEFINE_ENUM (gamma_method_e, gamma_method_enum );
|
||||
|
||||
enum line_pattern_enum : std::uint8_t
|
||||
{
|
||||
LINE_PATTERN_WARP,
|
||||
LINE_PATTERN_REPEAT,
|
||||
line_pattern_enum_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM (line_pattern_e, line_pattern_enum );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ enum class keys : std::uint8_t
|
|||
avoid_edges,
|
||||
ff_settings,
|
||||
extend,
|
||||
line_pattern,
|
||||
MAX_SYMBOLIZER_KEY
|
||||
};
|
||||
|
||||
|
|
|
@ -27,15 +27,15 @@
|
|||
#include <mapnik/agg_renderer.hpp>
|
||||
#include <mapnik/agg_rasterizer.hpp>
|
||||
#include <mapnik/agg_pattern_source.hpp>
|
||||
#include <mapnik/agg/render_polygon_pattern.hpp>
|
||||
#include <mapnik/marker.hpp>
|
||||
#include <mapnik/marker_cache.hpp>
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <mapnik/vertex_converters.hpp>
|
||||
#include <mapnik/vertex_processor.hpp>
|
||||
#include <mapnik/util/noncopyable.hpp>
|
||||
#include <mapnik/parse_path.hpp>
|
||||
#include <mapnik/renderer_common/clipping_extent.hpp>
|
||||
#include <mapnik/renderer_common/render_pattern.hpp>
|
||||
#include <mapnik/renderer_common/pattern_alignment.hpp>
|
||||
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
|
||||
|
||||
|
||||
|
@ -53,22 +53,139 @@
|
|||
#include "agg_span_allocator.h"
|
||||
#include "agg_span_pattern_rgba.h"
|
||||
#include "agg_renderer_outline_image.h"
|
||||
#include "agg_image_accessors.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename... Converters>
|
||||
using vertex_converter_type = vertex_converter<clip_line_tag,
|
||||
transform_tag,
|
||||
affine_transform_tag,
|
||||
simplify_tag,
|
||||
smooth_tag,
|
||||
offset_transform_tag,
|
||||
Converters...>;
|
||||
|
||||
struct warp_pattern : agg_pattern_base
|
||||
{
|
||||
using vc_type = vertex_converter_type<>;
|
||||
using color_type = agg::rgba8;
|
||||
using order_type = agg::order_rgba;
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<color_type, order_type>;
|
||||
using pattern_filter_type = agg::pattern_filter_bilinear_rgba8;
|
||||
using pattern_type = agg::line_image_pattern<pattern_filter_type>;
|
||||
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_type>;
|
||||
using renderer_type = agg::renderer_outline_image<renderer_base, pattern_type>;
|
||||
using rasterizer_type = agg::rasterizer_outline_aa<renderer_type>;
|
||||
|
||||
warp_pattern(image_rgba8 const& pattern_img,
|
||||
renderer_common const& common,
|
||||
symbolizer_base const& sym,
|
||||
mapnik::feature_impl const& feature,
|
||||
proj_transform const& prj_trans)
|
||||
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans},
|
||||
clip_(get<value_bool, keys::clip>(sym, feature, common.vars_)),
|
||||
offset_(get<value_double, keys::offset>(sym, feature, common.vars_)),
|
||||
clip_box_(clip_box()),
|
||||
tr_(geom_transform()),
|
||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
||||
feature, common.vars_, common.scale_factor_)
|
||||
{
|
||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
||||
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
||||
|
||||
if (std::fabs(offset_) > 0.0) converter_.template set<offset_transform_tag>();
|
||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
||||
converter_.template set<affine_transform_tag>();
|
||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
||||
}
|
||||
|
||||
box2d<double> clip_box() const
|
||||
{
|
||||
box2d<double> clip_box = clipping_extent(common_);
|
||||
if (clip_)
|
||||
{
|
||||
double pad_per_pixel = static_cast<double>(common_.query_extent_.width() / common_.width_);
|
||||
double pixels = std::ceil(std::max(pattern_img_.width() / 2.0 + std::fabs(offset_),
|
||||
(std::fabs(offset_) * offset_converter_default_threshold)));
|
||||
double padding = pad_per_pixel * pixels * common_.scale_factor_;
|
||||
clip_box.pad(padding);
|
||||
}
|
||||
return clip_box;
|
||||
}
|
||||
|
||||
void render(renderer_base & ren_base, rasterizer &)
|
||||
{
|
||||
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||
agg::pattern_filter_bilinear_rgba8 filter;
|
||||
pattern_source source(pattern_img_, opacity);
|
||||
pattern_type pattern (filter, source);
|
||||
renderer_type ren(ren_base, pattern);
|
||||
double half_stroke = std::max(pattern_img_.width() / 2.0, pattern_img_.height() / 2.0);
|
||||
int rast_clip_padding = static_cast<int>(std::round(half_stroke));
|
||||
ren.clip_box(-rast_clip_padding, -rast_clip_padding,
|
||||
common_.width_ + rast_clip_padding,
|
||||
common_.height_ + rast_clip_padding);
|
||||
rasterizer_type ras(ren);
|
||||
|
||||
using apply_vertex_converter_type = detail::apply_vertex_converter<
|
||||
vc_type, rasterizer_type>;
|
||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||
apply_vertex_converter_type apply(converter_, ras);
|
||||
|
||||
util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||
}
|
||||
|
||||
const bool clip_;
|
||||
const double offset_;
|
||||
const box2d<double> clip_box_;
|
||||
const agg::trans_affine tr_;
|
||||
vc_type converter_;
|
||||
};
|
||||
|
||||
using repeat_pattern_base = agg_polygon_pattern<vertex_converter_type<dash_tag,
|
||||
stroke_tag>>;
|
||||
struct repeat_pattern : repeat_pattern_base
|
||||
{
|
||||
using repeat_pattern_base::agg_polygon_pattern;
|
||||
|
||||
void render(renderer_base & ren_base, rasterizer & ras)
|
||||
{
|
||||
if (has_key(sym_, keys::stroke_dasharray))
|
||||
{
|
||||
converter_.set<dash_tag>();
|
||||
}
|
||||
|
||||
if (clip_) converter_.template set<clip_line_tag>();
|
||||
|
||||
value_double offset = get<value_double, keys::offset>(sym_, feature_, common_.vars_);
|
||||
if (std::fabs(offset) > 0.0) converter_.template set<offset_transform_tag>();
|
||||
|
||||
// To allow lines cross themselves.
|
||||
ras.filling_rule(agg::fill_non_zero);
|
||||
|
||||
repeat_pattern_base::render(ren_base, ras);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <typename buffer_type>
|
||||
struct agg_renderer_process_visitor_l
|
||||
{
|
||||
agg_renderer_process_visitor_l(renderer_common & common,
|
||||
agg_renderer_process_visitor_l(renderer_common const& common,
|
||||
buffer_type & current_buffer,
|
||||
std::unique_ptr<rasterizer> const& ras_ptr,
|
||||
rasterizer & ras,
|
||||
line_pattern_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
mapnik::feature_impl const& feature,
|
||||
proj_transform const& prj_trans)
|
||||
: common_(common),
|
||||
current_buffer_(current_buffer),
|
||||
ras_ptr_(ras_ptr),
|
||||
ras_(ras),
|
||||
sym_(sym),
|
||||
feature_(feature),
|
||||
prj_trans_(prj_trans) {}
|
||||
|
@ -82,88 +199,57 @@ struct agg_renderer_process_visitor_l
|
|||
if (image_transform) evaluate_transform(image_tr, feature_, common_.vars_, *image_transform, common_.scale_factor_);
|
||||
mapnik::box2d<double> const& bbox_image = marker.get_data()->bounding_box() * image_tr;
|
||||
image_rgba8 image(bbox_image.width(), bbox_image.height());
|
||||
render_pattern<buffer_type>(*ras_ptr_, marker, image_tr, 1.0, image);
|
||||
render(image, marker.width(), marker.height());
|
||||
render_pattern<buffer_type>(ras_, marker, image_tr, 1.0, image);
|
||||
render_by_pattern_type(image);
|
||||
}
|
||||
|
||||
void operator() (marker_rgba8 const& marker) const
|
||||
{
|
||||
render(marker.get_data(), marker.width(), marker.height());
|
||||
render_by_pattern_type(marker.get_data());
|
||||
}
|
||||
|
||||
private:
|
||||
void render(mapnik::image_rgba8 const& marker, double width, double height) const
|
||||
void render_by_pattern_type(image_rgba8 const& pattern_image) const
|
||||
{
|
||||
using col = agg::rgba8;
|
||||
using order = agg::order_rgba;
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<col, order>;
|
||||
using pattern_filter_type = agg::pattern_filter_bilinear_rgba8;
|
||||
using pattern_type = agg::line_image_pattern<pattern_filter_type>;
|
||||
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_type>;
|
||||
using renderer_type = agg::renderer_outline_image<renderer_base, pattern_type>;
|
||||
using rasterizer_type = agg::rasterizer_outline_aa<renderer_type>;
|
||||
|
||||
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||
value_bool clip = get<value_bool, keys::clip>(sym_, feature_, common_.vars_);
|
||||
value_double offset = get<value_double, keys::offset>(sym_, feature_, common_.vars_);
|
||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
||||
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
||||
line_pattern_enum pattern = get<line_pattern_enum, keys::line_pattern>(sym_, feature_, common_.vars_);
|
||||
switch (pattern)
|
||||
{
|
||||
case LINE_PATTERN_WARP:
|
||||
{
|
||||
warp_pattern pattern(pattern_image, common_, sym_, feature_, prj_trans_);
|
||||
render(pattern);
|
||||
break;
|
||||
}
|
||||
case LINE_PATTERN_REPEAT:
|
||||
{
|
||||
repeat_pattern pattern(pattern_image, common_, sym_, feature_, prj_trans_);
|
||||
render(pattern);
|
||||
break;
|
||||
}
|
||||
case line_pattern_enum_MAX:
|
||||
default:
|
||||
MAPNIK_LOG_ERROR(process_line_pattern_symbolizer) << "Incorrect line-pattern value.";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Pattern>
|
||||
void render(Pattern & pattern) const
|
||||
{
|
||||
agg::rendering_buffer buf(current_buffer_.bytes(), current_buffer_.width(),
|
||||
current_buffer_.height(), current_buffer_.row_size());
|
||||
pixfmt_type pixf(buf);
|
||||
typename Pattern::pixfmt_type pixf(buf);
|
||||
pixf.comp_op(static_cast<agg::comp_op_e>(get<composite_mode_e, keys::comp_op>(sym_, feature_, common_.vars_)));
|
||||
renderer_base ren_base(pixf);
|
||||
agg::pattern_filter_bilinear_rgba8 filter;
|
||||
typename Pattern::renderer_base ren_base(pixf);
|
||||
|
||||
pattern_source source(marker, opacity);
|
||||
pattern_type pattern (filter,source);
|
||||
renderer_type ren(ren_base, pattern);
|
||||
double half_stroke = std::max(width / 2.0, height / 2.0);
|
||||
int rast_clip_padding = static_cast<int>(std::round(half_stroke));
|
||||
ren.clip_box(-rast_clip_padding,-rast_clip_padding,common_.width_+rast_clip_padding,common_.height_+rast_clip_padding);
|
||||
rasterizer_type ras(ren);
|
||||
|
||||
agg::trans_affine tr;
|
||||
auto transform = get_optional<transform_type>(sym_, keys::geometry_transform);
|
||||
if (transform) evaluate_transform(tr, feature_, common_.vars_, *transform, common_.scale_factor_);
|
||||
|
||||
box2d<double> clip_box = clipping_extent(common_);
|
||||
if (clip)
|
||||
{
|
||||
double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
|
||||
double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
|
||||
(std::fabs(offset) * offset_converter_default_threshold)));
|
||||
double padding = pad_per_pixel * pixels * common_.scale_factor_;
|
||||
|
||||
clip_box.pad(padding);
|
||||
}
|
||||
using vertex_converter_type = vertex_converter<clip_line_tag, transform_tag,
|
||||
affine_transform_tag,
|
||||
simplify_tag,smooth_tag,
|
||||
offset_transform_tag>;
|
||||
|
||||
vertex_converter_type converter(clip_box,sym_,common_.t_,prj_trans_,tr,feature_,common_.vars_,common_.scale_factor_);
|
||||
|
||||
if (clip) converter.set<clip_line_tag>();
|
||||
converter.set<transform_tag>(); //always transform
|
||||
if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (std::fabs(offset) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
|
||||
converter.set<affine_transform_tag>(); // optional affine transform
|
||||
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
|
||||
using apply_vertex_converter_type = detail::apply_vertex_converter<vertex_converter_type, rasterizer_type>;
|
||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||
apply_vertex_converter_type apply(converter, ras);
|
||||
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||
if (pattern.clip_) pattern.converter_.template set<clip_line_tag>();
|
||||
pattern.render(ren_base, ras_);
|
||||
}
|
||||
|
||||
renderer_common & common_;
|
||||
renderer_common const& common_;
|
||||
buffer_type & current_buffer_;
|
||||
std::unique_ptr<rasterizer> const& ras_ptr_;
|
||||
rasterizer & ras_;
|
||||
line_pattern_symbolizer const& sym_;
|
||||
mapnik::feature_impl & feature_;
|
||||
mapnik::feature_impl const& feature_;
|
||||
proj_transform const& prj_trans_;
|
||||
};
|
||||
|
||||
|
@ -172,8 +258,6 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
|
|||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans)
|
||||
{
|
||||
|
||||
|
||||
std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_);
|
||||
if (filename.empty()) return;
|
||||
ras_ptr->reset();
|
||||
|
@ -183,10 +267,11 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
|
|||
gamma_method_ = GAMMA_POWER;
|
||||
gamma_ = 1.0;
|
||||
}
|
||||
|
||||
std::shared_ptr<mapnik::marker const> marker = marker_cache::instance().find(filename, true);
|
||||
agg_renderer_process_visitor_l<buffer_type> visitor(common_,
|
||||
buffers_.top().get(),
|
||||
ras_ptr,
|
||||
*ras_ptr,
|
||||
sym,
|
||||
feature,
|
||||
prj_trans);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <mapnik/agg_renderer.hpp>
|
||||
#include <mapnik/agg_helpers.hpp>
|
||||
#include <mapnik/agg_rasterizer.hpp>
|
||||
#include <mapnik/agg/render_polygon_pattern.hpp>
|
||||
#include <mapnik/marker.hpp>
|
||||
#include <mapnik/marker_cache.hpp>
|
||||
#include <mapnik/vertex_converters.hpp>
|
||||
|
@ -35,10 +36,7 @@
|
|||
#include <mapnik/svg/svg_converter.hpp>
|
||||
#include <mapnik/svg/svg_renderer_agg.hpp>
|
||||
#include <mapnik/svg/svg_path_adapter.hpp>
|
||||
#include <mapnik/renderer_common/clipping_extent.hpp>
|
||||
#include <mapnik/renderer_common/render_pattern.hpp>
|
||||
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
|
||||
#include <mapnik/renderer_common/pattern_alignment.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore_agg.hpp>
|
||||
|
@ -111,86 +109,30 @@ private:
|
|||
gamma_ = gamma;
|
||||
}
|
||||
|
||||
value_bool clip = get<value_bool, keys::clip>(sym_, feature_, common_.vars_);
|
||||
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
||||
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
||||
|
||||
box2d<double> clip_box = clipping_extent(common_);
|
||||
|
||||
using col = agg::rgba8;
|
||||
using order = agg::order_rgba;
|
||||
using blender_type = agg::comp_op_adaptor_rgba_pre<col, order>;
|
||||
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||
|
||||
using wrap_x_type = agg::wrap_mode_repeat;
|
||||
using wrap_y_type = agg::wrap_mode_repeat;
|
||||
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre,
|
||||
wrap_x_type,
|
||||
wrap_y_type>;
|
||||
|
||||
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
||||
using ren_base = agg::renderer_base<pixfmt_type>;
|
||||
|
||||
using renderer_type = agg::renderer_scanline_aa_alpha<ren_base,
|
||||
agg::span_allocator<agg::rgba8>,
|
||||
span_gen_type>;
|
||||
|
||||
pixfmt_type pixf(buf);
|
||||
pixf.comp_op(static_cast<agg::comp_op_e>(get<composite_mode_e, keys::comp_op>(sym_, feature_, common_.vars_)));
|
||||
ren_base renb(pixf);
|
||||
|
||||
unsigned w = image.width();
|
||||
unsigned h = image.height();
|
||||
agg::rendering_buffer pattern_rbuf((agg::int8u*)image.bytes(),w,h,w*4);
|
||||
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
||||
img_source_type img_src(pixf_pattern);
|
||||
|
||||
pattern_alignment_enum alignment = get<pattern_alignment_enum, keys::alignment>(sym_, feature_, common_.vars_);
|
||||
unsigned offset_x=0;
|
||||
unsigned offset_y=0;
|
||||
|
||||
if (alignment == LOCAL_ALIGNMENT)
|
||||
{
|
||||
double x0 = 0;
|
||||
double y0 = 0;
|
||||
using apply_local_alignment = detail::apply_local_alignment;
|
||||
apply_local_alignment apply(common_.t_,prj_trans_, clip_box, x0, y0);
|
||||
util::apply_visitor(geometry::vertex_processor<apply_local_alignment>(apply), feature_.get_geometry());
|
||||
|
||||
offset_x = unsigned(current_buffer_.width() - x0);
|
||||
offset_y = unsigned(current_buffer_.height() - y0);
|
||||
}
|
||||
|
||||
span_gen_type sg(img_src, offset_x, offset_y);
|
||||
|
||||
agg::span_allocator<agg::rgba8> sa;
|
||||
renderer_type rp(renb,sa, sg, unsigned(opacity * 255));
|
||||
|
||||
agg::trans_affine tr;
|
||||
auto transform = get_optional<transform_type>(sym_, keys::geometry_transform);
|
||||
if (transform) evaluate_transform(tr, feature_, common_.vars_, *transform, common_.scale_factor_);
|
||||
using vertex_converter_type = vertex_converter<clip_poly_tag,
|
||||
transform_tag,
|
||||
affine_transform_tag,
|
||||
simplify_tag,
|
||||
smooth_tag>;
|
||||
using pattern_type = agg_polygon_pattern<vertex_converter_type>;
|
||||
|
||||
vertex_converter_type converter(clip_box, sym_,common_.t_,prj_trans_,tr,feature_,common_.vars_,common_.scale_factor_);
|
||||
pattern_type pattern(image, common_, sym_, feature_, prj_trans_);
|
||||
|
||||
if (prj_trans_.equal() && clip) converter.set<clip_poly_tag>();
|
||||
converter.set<transform_tag>(); //always transform
|
||||
converter.set<affine_transform_tag>(); // optional affine transform
|
||||
if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
pattern_type::pixfmt_type pixf(buf);
|
||||
pixf.comp_op(static_cast<agg::comp_op_e>(get<composite_mode_e, keys::comp_op>(sym_, feature_, common_.vars_)));
|
||||
pattern_type::renderer_base renb(pixf);
|
||||
|
||||
unsigned w = image.width();
|
||||
unsigned h = image.height();
|
||||
agg::rendering_buffer pattern_rbuf((agg::int8u*)image.bytes(),w,h,w*4);
|
||||
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
||||
pattern_type::img_source_type img_src(pixf_pattern);
|
||||
|
||||
if (prj_trans_.equal() && pattern.clip_) pattern.converter_.set<clip_poly_tag>();
|
||||
|
||||
using apply_vertex_converter_type = detail::apply_vertex_converter<vertex_converter_type, rasterizer>;
|
||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||
apply_vertex_converter_type apply(converter, *ras_ptr_);
|
||||
mapnik::util::apply_visitor(vertex_processor_type(apply),feature_.get_geometry());
|
||||
agg::scanline_u8 sl;
|
||||
ras_ptr_->filling_rule(agg::fill_even_odd);
|
||||
agg::render_scanlines(*ras_ptr_, sl, rp);
|
||||
|
||||
pattern.render(renb, *ras_ptr_);
|
||||
}
|
||||
|
||||
renderer_common & common_;
|
||||
|
@ -220,7 +162,6 @@ void agg_renderer<T0,T1>::process(polygon_pattern_symbolizer const& sym,
|
|||
feature,
|
||||
prj_trans);
|
||||
util::apply_visitor(visitor, *marker);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1174,6 +1174,13 @@ void map_parser::parse_line_pattern_symbolizer(rule & rule, xml_node const & nod
|
|||
set_symbolizer_property<symbolizer_base,double>(sym, keys::opacity, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::offset, node);
|
||||
set_symbolizer_property<symbolizer_base,transform_type>(sym, keys::image_transform, node);
|
||||
set_symbolizer_property<symbolizer_base,value_double>(sym, keys::stroke_miterlimit, node);
|
||||
set_symbolizer_property<symbolizer_base,value_double>(sym, keys::stroke_width, node);
|
||||
set_symbolizer_property<symbolizer_base,line_join_enum>(sym, keys::stroke_linejoin, node);
|
||||
set_symbolizer_property<symbolizer_base,line_cap_enum>(sym, keys::stroke_linecap, node);
|
||||
set_symbolizer_property<symbolizer_base,dash_array>(sym, keys::stroke_dasharray, node);
|
||||
set_symbolizer_property<symbolizer_base,line_pattern_enum>(sym, keys::line_pattern, node);
|
||||
set_symbolizer_property<symbolizer_base,pattern_alignment_enum>(sym, keys::alignment, node);
|
||||
rule.append(std::move(sym));
|
||||
}
|
||||
catch (config_error const& ex)
|
||||
|
|
|
@ -207,4 +207,12 @@ static const char * gamma_method_strings[] = {
|
|||
|
||||
IMPLEMENT_ENUM( gamma_method_e, gamma_method_strings )
|
||||
|
||||
static const char * line_pattern_strings[] = {
|
||||
"warp",
|
||||
"repeat",
|
||||
""
|
||||
};
|
||||
|
||||
IMPLEMENT_ENUM( line_pattern_e, line_pattern_strings )
|
||||
|
||||
} // namespace mapnik
|
||||
|
|
|
@ -159,6 +159,9 @@ static const property_meta_type key_meta[const_max_key] =
|
|||
property_meta_type{ "avoid-edges",nullptr, property_types::target_bool },
|
||||
property_meta_type{ "font-feature-settings", nullptr, property_types::target_font_feature_settings },
|
||||
property_meta_type{ "extend", nullptr, property_types::target_double},
|
||||
property_meta_type{ "line-pattern", [](enumeration_wrapper e)
|
||||
{return enumeration<line_pattern_enum,line_pattern_enum_MAX>(line_pattern_enum(e.value)).as_string();},
|
||||
property_types::target_line_pattern},
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue