Merge pull request #3980 from mapycz/simple-line-pattern

Polygon pattern on line geometries
This commit is contained in:
Artem Pavlenko 2018-09-18 15:55:16 +01:00 committed by GitHub
commit fcec445a2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 706 additions and 316 deletions

View 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

View file

@ -0,0 +1,174 @@
/*****************************************************************************
*
* 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_CAIRO_RENDER_POLYGON_PATTERN_HPP
#define MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP
#include <mapnik/symbolizer.hpp>
#include <mapnik/vertex_processor.hpp>
#include <mapnik/vertex_converters.hpp>
#include <mapnik/renderer_common/pattern_alignment.hpp>
#include <mapnik/renderer_common/render_pattern.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
#include <mapnik/renderer_common/clipping_extent.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/marker.hpp>
namespace mapnik {
struct cairo_renderer_process_visitor_p
{
cairo_renderer_process_visitor_p(cairo_context & context,
agg::trans_affine & image_tr,
unsigned offset_x,
unsigned offset_y,
float opacity)
: context_(context),
image_tr_(image_tr),
offset_x_(offset_x),
offset_y_(offset_y),
opacity_(opacity) {}
void operator() (marker_null const&) {}
void operator() (marker_svg const& marker)
{
mapnik::rasterizer ras;
mapnik::box2d<double> const& bbox_image = marker.get_data()->bounding_box() * image_tr_;
mapnik::image_rgba8 image(bbox_image.width(), bbox_image.height());
render_pattern<image_rgba8>(ras, marker, image_tr_, 1.0, image);
cairo_pattern pattern(image, opacity_);
pattern.set_extend(CAIRO_EXTEND_REPEAT);
pattern.set_origin(offset_x_, offset_y_);
context_.set_pattern(pattern);
}
void operator() (marker_rgba8 const& marker)
{
cairo_pattern pattern(marker.get_data(), opacity_);
pattern.set_extend(CAIRO_EXTEND_REPEAT);
pattern.set_origin(offset_x_, offset_y_);
context_.set_pattern(pattern);
}
private:
cairo_context & context_;
agg::trans_affine & image_tr_;
unsigned offset_x_;
unsigned offset_y_;
float opacity_;
};
struct cairo_pattern_base
{
mapnik::marker const& marker_;
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 cairo_polygon_pattern : cairo_pattern_base
{
cairo_polygon_pattern(mapnik::marker const& marker,
renderer_common const& common,
symbolizer_base const& sym,
mapnik::feature_impl const& feature,
proj_transform const& prj_trans)
: cairo_pattern_base{marker, 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_);
converter_.template set<affine_transform_tag>();
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
if (smooth > 0.0) converter_.template set<smooth_tag>();
}
void render(cairo_fill_rule_t fill_rule, cairo_context & context)
{
unsigned offset_x=0;
unsigned offset_y=0;
pattern_alignment_enum alignment = get<pattern_alignment_enum, keys::alignment>(sym_, feature_, common_.vars_);
if (alignment == LOCAL_ALIGNMENT)
{
double x0 = 0.0;
double y0 = 0.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 = std::abs(clip_box_.width() - x0);
offset_y = std::abs(clip_box_.height() - y0);
}
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
auto image_transform = get_optional<transform_type>(sym_, keys::image_transform);
if (image_transform)
{
evaluate_transform(image_tr, feature_, common_.vars_, *image_transform, common_.scale_factor_);
}
composite_mode_e comp_op = get<composite_mode_e, keys::comp_op>(sym_, feature_, common_.vars_);
cairo_save_restore guard(context);
context.set_operator(comp_op);
util::apply_visitor(cairo_renderer_process_visitor_p(
context, image_tr, offset_x, offset_y, opacity), marker_);
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, cairo_context>;
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter_, context);
mapnik::util::apply_visitor(vertex_processor_type(apply),feature_.get_geometry());
// fill polygon
context.set_fill_rule(fill_rule);
context.fill();
}
const bool clip_;
const box2d<double> clip_box_;
const agg::trans_affine tr_;
VertexConverter converter_;
};
} // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP

View file

@ -25,6 +25,13 @@
#define MAPNIK_PATTERN_ALIGNMENT_HPP #define MAPNIK_PATTERN_ALIGNMENT_HPP
#include <mapnik/geometry.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 { namespace mapnik { namespace detail {

View file

@ -94,7 +94,8 @@ enum class property_types : std::uint8_t
target_vertical_alignment, target_vertical_alignment,
target_upright, target_upright,
target_direction, target_direction,
target_font_feature_settings target_font_feature_settings,
target_line_pattern,
}; };
template <typename T> template <typename T>
@ -189,6 +190,7 @@ ENUM_FROM_STRING( text_transform_enum )
ENUM_FROM_STRING( text_upright_enum ) ENUM_FROM_STRING( text_upright_enum )
ENUM_FROM_STRING( direction_enum ) ENUM_FROM_STRING( direction_enum )
ENUM_FROM_STRING( gamma_method_enum ) ENUM_FROM_STRING( gamma_method_enum )
ENUM_FROM_STRING( line_pattern_enum )
// enum // enum
template <typename T, bool is_enum = true> template <typename T, bool is_enum = true>

View file

@ -369,6 +369,13 @@ struct symbolizer_default<value_bool, keys::avoid_edges>
// font-feature-settings // 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 // extend
template <> template <>
struct symbolizer_default<value_double, keys::extend> struct symbolizer_default<value_double, keys::extend>

View file

@ -222,6 +222,14 @@ enum gamma_method_enum : std::uint8_t
DEFINE_ENUM (gamma_method_e, gamma_method_enum ); 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 );
} }

View file

@ -93,6 +93,7 @@ enum class keys : std::uint8_t
avoid_edges, avoid_edges,
ff_settings, ff_settings,
extend, extend,
line_pattern,
MAX_SYMBOLIZER_KEY MAX_SYMBOLIZER_KEY
}; };

View file

@ -27,15 +27,15 @@
#include <mapnik/agg_renderer.hpp> #include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_rasterizer.hpp> #include <mapnik/agg_rasterizer.hpp>
#include <mapnik/agg_pattern_source.hpp> #include <mapnik/agg_pattern_source.hpp>
#include <mapnik/agg/render_polygon_pattern.hpp>
#include <mapnik/marker.hpp> #include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp> #include <mapnik/marker_cache.hpp>
#include <mapnik/symbolizer.hpp> #include <mapnik/symbolizer.hpp>
#include <mapnik/vertex_converters.hpp>
#include <mapnik/vertex_processor.hpp> #include <mapnik/vertex_processor.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/parse_path.hpp> #include <mapnik/parse_path.hpp>
#include <mapnik/renderer_common/clipping_extent.hpp> #include <mapnik/renderer_common/clipping_extent.hpp>
#include <mapnik/renderer_common/render_pattern.hpp> #include <mapnik/renderer_common/render_pattern.hpp>
#include <mapnik/renderer_common/pattern_alignment.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp> #include <mapnik/renderer_common/apply_vertex_converter.hpp>
@ -53,22 +53,139 @@
#include "agg_span_allocator.h" #include "agg_span_allocator.h"
#include "agg_span_pattern_rgba.h" #include "agg_span_pattern_rgba.h"
#include "agg_renderer_outline_image.h" #include "agg_renderer_outline_image.h"
#include "agg_image_accessors.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
namespace mapnik { 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> template <typename buffer_type>
struct agg_renderer_process_visitor_l 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, buffer_type & current_buffer,
std::unique_ptr<rasterizer> const& ras_ptr, rasterizer & ras,
line_pattern_symbolizer const& sym, line_pattern_symbolizer const& sym,
mapnik::feature_impl & feature, mapnik::feature_impl const& feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
: common_(common), : common_(common),
current_buffer_(current_buffer), current_buffer_(current_buffer),
ras_ptr_(ras_ptr), ras_(ras),
sym_(sym), sym_(sym),
feature_(feature), feature_(feature),
prj_trans_(prj_trans) {} 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_); 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; mapnik::box2d<double> const& bbox_image = marker.get_data()->bounding_box() * image_tr;
image_rgba8 image(bbox_image.width(), bbox_image.height()); image_rgba8 image(bbox_image.width(), bbox_image.height());
render_pattern<buffer_type>(*ras_ptr_, marker, image_tr, 1.0, image); render_pattern<buffer_type>(ras_, marker, image_tr, 1.0, image);
render(image, marker.width(), marker.height()); render_by_pattern_type(image);
} }
void operator() (marker_rgba8 const& marker) const void operator() (marker_rgba8 const& marker) const
{ {
render(marker.get_data(), marker.width(), marker.height()); render_by_pattern_type(marker.get_data());
} }
private: 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; line_pattern_enum pattern = get<line_pattern_enum, keys::line_pattern>(sym_, feature_, common_.vars_);
using order = agg::order_rgba; switch (pattern)
using blender_type = agg::comp_op_adaptor_rgba_pre<col, order>; {
using pattern_filter_type = agg::pattern_filter_bilinear_rgba8; case LINE_PATTERN_WARP:
using pattern_type = agg::line_image_pattern<pattern_filter_type>; {
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>; warp_pattern pattern(pattern_image, common_, sym_, feature_, prj_trans_);
using renderer_base = agg::renderer_base<pixfmt_type>; render(pattern);
using renderer_type = agg::renderer_outline_image<renderer_base, pattern_type>; break;
using rasterizer_type = agg::rasterizer_outline_aa<renderer_type>; }
case LINE_PATTERN_REPEAT:
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_); {
value_bool clip = get<value_bool, keys::clip>(sym_, feature_, common_.vars_); repeat_pattern pattern(pattern_image, common_, sym_, feature_, prj_trans_);
value_double offset = get<value_double, keys::offset>(sym_, feature_, common_.vars_); render(pattern);
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_); break;
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_); }
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(), agg::rendering_buffer buf(current_buffer_.bytes(), current_buffer_.width(),
current_buffer_.height(), current_buffer_.row_size()); 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_))); 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); typename Pattern::renderer_base ren_base(pixf);
agg::pattern_filter_bilinear_rgba8 filter;
pattern_source source(marker, opacity); if (pattern.clip_) pattern.converter_.template set<clip_line_tag>();
pattern_type pattern (filter,source); pattern.render(ren_base, ras_);
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());
} }
renderer_common & common_; renderer_common const& common_;
buffer_type & current_buffer_; buffer_type & current_buffer_;
std::unique_ptr<rasterizer> const& ras_ptr_; rasterizer & ras_;
line_pattern_symbolizer const& sym_; line_pattern_symbolizer const& sym_;
mapnik::feature_impl & feature_; mapnik::feature_impl const& feature_;
proj_transform const& prj_trans_; proj_transform const& prj_trans_;
}; };
@ -172,8 +258,6 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
mapnik::feature_impl & feature, mapnik::feature_impl & feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
{ {
std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_); std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_);
if (filename.empty()) return; if (filename.empty()) return;
ras_ptr->reset(); ras_ptr->reset();
@ -183,10 +267,11 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
gamma_method_ = GAMMA_POWER; gamma_method_ = GAMMA_POWER;
gamma_ = 1.0; gamma_ = 1.0;
} }
std::shared_ptr<mapnik::marker const> marker = marker_cache::instance().find(filename, true); std::shared_ptr<mapnik::marker const> marker = marker_cache::instance().find(filename, true);
agg_renderer_process_visitor_l<buffer_type> visitor(common_, agg_renderer_process_visitor_l<buffer_type> visitor(common_,
buffers_.top().get(), buffers_.top().get(),
ras_ptr, *ras_ptr,
sym, sym,
feature, feature,
prj_trans); prj_trans);

View file

@ -26,6 +26,7 @@
#include <mapnik/agg_renderer.hpp> #include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp> #include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp> #include <mapnik/agg_rasterizer.hpp>
#include <mapnik/agg/render_polygon_pattern.hpp>
#include <mapnik/marker.hpp> #include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp> #include <mapnik/marker_cache.hpp>
#include <mapnik/vertex_converters.hpp> #include <mapnik/vertex_converters.hpp>
@ -35,10 +36,7 @@
#include <mapnik/svg/svg_converter.hpp> #include <mapnik/svg/svg_converter.hpp>
#include <mapnik/svg/svg_renderer_agg.hpp> #include <mapnik/svg/svg_renderer_agg.hpp>
#include <mapnik/svg/svg_path_adapter.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/render_pattern.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
#include <mapnik/renderer_common/pattern_alignment.hpp>
#pragma GCC diagnostic push #pragma GCC diagnostic push
#include <mapnik/warning_ignore_agg.hpp> #include <mapnik/warning_ignore_agg.hpp>
@ -111,86 +109,30 @@ private:
gamma_ = gamma; 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, using vertex_converter_type = vertex_converter<clip_poly_tag,
transform_tag, transform_tag,
affine_transform_tag, affine_transform_tag,
simplify_tag, simplify_tag,
smooth_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>(); pattern_type::pixfmt_type pixf(buf);
converter.set<transform_tag>(); //always transform pixf.comp_op(static_cast<agg::comp_op_e>(get<composite_mode_e, keys::comp_op>(sym_, feature_, common_.vars_)));
converter.set<affine_transform_tag>(); // optional affine transform pattern_type::renderer_base renb(pixf);
if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter 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); ras_ptr_->filling_rule(agg::fill_even_odd);
agg::render_scanlines(*ras_ptr_, sl, rp);
pattern.render(renb, *ras_ptr_);
} }
renderer_common & common_; renderer_common & common_;
@ -220,7 +162,6 @@ void agg_renderer<T0,T1>::process(polygon_pattern_symbolizer const& sym,
feature, feature,
prj_trans); prj_trans);
util::apply_visitor(visitor, *marker); util::apply_visitor(visitor, *marker);
} }

View file

@ -27,6 +27,7 @@
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
#include <mapnik/proj_transform.hpp> #include <mapnik/proj_transform.hpp>
#include <mapnik/cairo/cairo_renderer.hpp> #include <mapnik/cairo/cairo_renderer.hpp>
#include <mapnik/cairo/render_polygon_pattern.hpp>
#include <mapnik/renderer_common/render_pattern.hpp> #include <mapnik/renderer_common/render_pattern.hpp>
#include <mapnik/vertex_converters.hpp> #include <mapnik/vertex_converters.hpp>
#include <mapnik/vertex_processor.hpp> #include <mapnik/vertex_processor.hpp>
@ -40,11 +41,14 @@
namespace mapnik namespace mapnik
{ {
struct cairo_renderer_process_visitor_l namespace
{ {
cairo_renderer_process_visitor_l(renderer_common const& common,
line_pattern_symbolizer const& sym, struct prepare_pattern_visitor
mapnik::feature_impl & feature, {
prepare_pattern_visitor(renderer_common const& common,
symbolizer_base const& sym,
feature_impl const& feature,
std::size_t & width, std::size_t & width,
std::size_t & height) std::size_t & height)
: common_(common), : common_(common),
@ -81,86 +85,156 @@ struct cairo_renderer_process_visitor_l
private: private:
renderer_common const& common_; renderer_common const& common_;
line_pattern_symbolizer const& sym_; symbolizer_base const& sym_;
mapnik::feature_impl & feature_; feature_impl const& feature_;
std::size_t & width_; std::size_t & width_;
std::size_t & height_; std::size_t & height_;
}; };
template <typename T> template <typename... Converters>
void cairo_renderer<T>::process(line_pattern_symbolizer const& sym, using vertex_converter_type = vertex_converter<clip_line_tag,
mapnik::feature_impl & feature, transform_tag,
proj_transform const& prj_trans) affine_transform_tag,
{ simplify_tag,
std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_); smooth_tag,
composite_mode_e comp_op = get<composite_mode_e, keys::comp_op>(sym, feature, common_.vars_); offset_transform_tag,
value_bool clip = get<value_bool, keys::clip>(sym, feature, common_.vars_); Converters...>;
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_);
if (filename.empty()) struct warp_pattern : cairo_pattern_base
{
using vc_type = vertex_converter_type<>;
warp_pattern(mapnik::marker const& marker,
renderer_common const& common,
symbolizer_base const& sym,
mapnik::feature_impl const& feature,
proj_transform const& prj_trans)
: cairo_pattern_base{marker, 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_(clipping_extent(common)),
tr_(geom_transform()),
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
feature, common.vars_, common.scale_factor_)
{ {
return; 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_);
if (std::fabs(offset) > 0.0) converter_.template set<offset_transform_tag>();
converter_.template set<affine_transform_tag>();
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
if (smooth > 0.0) converter_.template set<smooth_tag>();
if (clip_) converter_.template set<clip_line_tag>();
} }
std::shared_ptr<mapnik::marker const> marker = marker_cache::instance().find(filename, true); box2d<double> clip_box() const
if (marker->is<mapnik::marker_null>()) return;
std::size_t width = marker->width();
std::size_t height = marker->height();
cairo_save_restore guard(context_);
context_.set_operator(comp_op);
// TODO - re-implement at renderer level like polygon_pattern symbolizer
cairo_renderer_process_visitor_l visit(common_,
sym,
feature,
width,
height);
std::shared_ptr<cairo_pattern> pattern = util::apply_visitor(visit, *marker);
context_.set_line_width(height);
pattern->set_extend(CAIRO_EXTEND_REPEAT);
pattern->set_filter(CAIRO_FILTER_BILINEAR);
agg::trans_affine tr;
auto geom_transform = get_optional<transform_type>(sym, keys::geometry_transform);
if (geom_transform) { evaluate_transform(tr, feature, common_.vars_, *geom_transform, common_.scale_factor_); }
box2d<double> clipping_extent = common_.query_extent_;
if (clip)
{ {
double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_); box2d<double> clipping_extent = common_.query_extent_;
double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset), if (clip_)
(std::fabs(offset) * offset_converter_default_threshold))); {
double pad_per_pixel = static_cast<double>(common_.query_extent_.width() / common_.width_);
double pixels = std::ceil(std::max(marker_.width() / 2.0 + std::fabs(offset_),
(std::fabs(offset_) * offset_converter_default_threshold)));
double padding = pad_per_pixel * pixels * common_.scale_factor_; double padding = pad_per_pixel * pixels * common_.scale_factor_;
clipping_extent.pad(padding); clipping_extent.pad(padding);
} }
return clipping_extent;
}
void render(cairo_context & context)
{
std::size_t width = marker_.width();
std::size_t height = marker_.height();
// TODO - re-implement at renderer level like polygon_pattern symbolizer
prepare_pattern_visitor visit(common_, sym_, feature_, width, height);
std::shared_ptr<cairo_pattern> pattern = util::apply_visitor(visit, marker_);
pattern->set_extend(CAIRO_EXTEND_REPEAT);
pattern->set_filter(CAIRO_FILTER_BILINEAR);
composite_mode_e comp_op = get<composite_mode_e, keys::comp_op>(sym_, feature_, common_.vars_);
cairo_save_restore guard(context);
context.set_operator(comp_op);
context.set_line_width(height);
using rasterizer_type = line_pattern_rasterizer<cairo_context>; using rasterizer_type = line_pattern_rasterizer<cairo_context>;
rasterizer_type ras(context_, *pattern, width, height); rasterizer_type ras(context, *pattern, width, height);
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(clipping_extent,sym, common_.t_, prj_trans, tr, feature, common_.vars_, common_.scale_factor_); using apply_vertex_converter_type = detail::apply_vertex_converter<
vc_type, rasterizer_type>;
if (clip) converter.set<clip_line_tag>();
converter.set<transform_tag>(); // always transform
if (std::fabs(offset) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
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
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>; using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter, ras); apply_vertex_converter_type apply(converter_, ras);
mapnik::util::apply_visitor(vertex_processor_type(apply), feature.get_geometry()); mapnik::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 = cairo_polygon_pattern<vertex_converter_type<dash_tag,
stroke_tag>>;
struct repeat_pattern : repeat_pattern_base
{
using repeat_pattern_base::cairo_polygon_pattern;
void render(cairo_context & context)
{
if (has_key(sym_, keys::stroke_dasharray))
{
converter_.template 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>();
repeat_pattern_base::render(CAIRO_FILL_RULE_WINDING, context);
}
};
}
template <typename T>
void cairo_renderer<T>::process(line_pattern_symbolizer const& sym,
feature_impl & feature,
proj_transform const& prj_trans)
{
std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_);
std::shared_ptr<mapnik::marker const> marker = marker_cache::instance().find(filename, true);
if (marker->is<mapnik::marker_null>())
{
return;
}
line_pattern_enum pattern = get<line_pattern_enum, keys::line_pattern>(sym, feature, common_.vars_);
switch (pattern)
{
case LINE_PATTERN_WARP:
{
warp_pattern pattern(*marker, common_, sym, feature, prj_trans);
pattern.render(context_);
break;
}
case LINE_PATTERN_REPEAT:
{
repeat_pattern pattern(*marker, common_, sym, feature, prj_trans);
pattern.render(context_);
break;
}
case line_pattern_enum_MAX:
default:
MAPNIK_LOG_ERROR(process_line_pattern_symbolizer) << "Incorrect line-pattern value.";
}
} }
template void cairo_renderer<cairo_ptr>::process(line_pattern_symbolizer const&, template void cairo_renderer<cairo_ptr>::process(line_pattern_symbolizer const&,

View file

@ -27,123 +27,38 @@
#include <mapnik/proj_transform.hpp> #include <mapnik/proj_transform.hpp>
#include <mapnik/cairo/cairo_renderer.hpp> #include <mapnik/cairo/cairo_renderer.hpp>
#include <mapnik/cairo/cairo_render_vector.hpp> #include <mapnik/cairo/cairo_render_vector.hpp>
#include <mapnik/renderer_common/render_pattern.hpp> #include <mapnik/cairo/render_polygon_pattern.hpp>
#include <mapnik/vertex_converters.hpp> #include <mapnik/vertex_converters.hpp>
#include <mapnik/vertex_processor.hpp> #include <mapnik/vertex_processor.hpp>
#include <mapnik/marker.hpp> #include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp> #include <mapnik/marker_cache.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/renderer_common/clipping_extent.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp> #include <mapnik/renderer_common/apply_vertex_converter.hpp>
#include <mapnik/renderer_common/pattern_alignment.hpp> #include <mapnik/renderer_common/pattern_alignment.hpp>
namespace mapnik namespace mapnik
{ {
struct cairo_renderer_process_visitor_p
{
cairo_renderer_process_visitor_p(cairo_context & context,
agg::trans_affine & image_tr,
unsigned offset_x,
unsigned offset_y,
float opacity)
: context_(context),
image_tr_(image_tr),
offset_x_(offset_x),
offset_y_(offset_y),
opacity_(opacity) {}
void operator() (marker_null const&) {}
void operator() (marker_svg const& marker)
{
mapnik::rasterizer ras;
mapnik::box2d<double> const& bbox_image = marker.get_data()->bounding_box() * image_tr_;
mapnik::image_rgba8 image(bbox_image.width(), bbox_image.height());
render_pattern<image_rgba8>(ras, marker, image_tr_, 1.0, image);
cairo_pattern pattern(image, opacity_);
pattern.set_extend(CAIRO_EXTEND_REPEAT);
pattern.set_origin(offset_x_, offset_y_);
context_.set_pattern(pattern);
}
void operator() (marker_rgba8 const& marker)
{
cairo_pattern pattern(marker.get_data(), opacity_);
pattern.set_extend(CAIRO_EXTEND_REPEAT);
pattern.set_origin(offset_x_, offset_y_);
context_.set_pattern(pattern);
}
private:
cairo_context & context_;
agg::trans_affine & image_tr_;
unsigned offset_x_;
unsigned offset_y_;
float opacity_;
};
template <typename T> template <typename T>
void cairo_renderer<T>::process(polygon_pattern_symbolizer const& sym, void cairo_renderer<T>::process(polygon_pattern_symbolizer const& sym,
mapnik::feature_impl & feature, mapnik::feature_impl & feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
{ {
composite_mode_e comp_op = get<composite_mode_e, keys::comp_op>(sym, feature, common_.vars_);
std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_); std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_);
value_bool clip = get<value_bool, keys::clip>(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_);
value_double opacity = get<value_double, keys::opacity>(sym, feature, common_.vars_);
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
if (image_transform) evaluate_transform(image_tr, feature, common_.vars_, *image_transform, common_.scale_factor_);
cairo_save_restore guard(context_);
context_.set_operator(comp_op);
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(filename,true); std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(filename,true);
if (marker->is<mapnik::marker_null>()) return; if (marker->is<mapnik::marker_null>()) return;
unsigned offset_x=0;
unsigned offset_y=0;
box2d<double> const& clip_box = clipping_extent(common_);
pattern_alignment_enum alignment = get<pattern_alignment_enum, keys::alignment>(sym, feature, common_.vars_);
if (alignment == LOCAL_ALIGNMENT)
{
double x0 = 0.0;
double y0 = 0.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 = std::abs(clip_box.width() - x0);
offset_y = std::abs(clip_box.height() - y0);
}
util::apply_visitor(cairo_renderer_process_visitor_p(context_, image_tr, offset_x, offset_y, opacity), *marker);
agg::trans_affine tr;
auto geom_transform = get_optional<transform_type>(sym, keys::geometry_transform);
if (geom_transform) { evaluate_transform(tr, feature, common_.vars_, *geom_transform, common_.scale_factor_); }
using vertex_converter_type = vertex_converter<clip_poly_tag, using vertex_converter_type = vertex_converter<clip_poly_tag,
transform_tag, transform_tag,
affine_transform_tag, affine_transform_tag,
simplify_tag, simplify_tag,
smooth_tag>; smooth_tag>;
using pattern_type = cairo_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(*marker, 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>();
if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
using apply_vertex_converter_type = detail::apply_vertex_converter<vertex_converter_type, cairo_context>; if (prj_trans.equal() && pattern.clip_) pattern.converter_.set<clip_poly_tag>();
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter, context_); pattern.render(CAIRO_FILL_RULE_EVEN_ODD, context_);
mapnik::util::apply_visitor(vertex_processor_type(apply),feature.get_geometry());
// fill polygon
context_.set_fill_rule(CAIRO_FILL_RULE_EVEN_ODD);
context_.fill();
} }
template void cairo_renderer<cairo_ptr>::process(polygon_pattern_symbolizer const&, template void cairo_renderer<cairo_ptr>::process(polygon_pattern_symbolizer const&,

View file

@ -85,7 +85,9 @@ void grid_renderer<T>::process(line_pattern_symbolizer const& sym,
ras_ptr->reset(); ras_ptr->reset();
std::size_t stroke_width = mark->width(); line_pattern_enum pattern = get<line_pattern_enum, keys::line_pattern>(sym, feature, common_.vars_);
std::size_t stroke_width = (pattern == LINE_PATTERN_WARP) ? mark->width() :
get<value_double, keys::stroke_width>(sym, feature, common_.vars_);
agg::trans_affine tr; agg::trans_affine tr;
auto transform = get_optional<transform_type>(sym, keys::geometry_transform); auto transform = get_optional<transform_type>(sym, keys::geometry_transform);

View file

@ -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::opacity, node);
set_symbolizer_property<symbolizer_base,double>(sym, keys::offset, 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,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)); rule.append(std::move(sym));
} }
catch (config_error const& ex) catch (config_error const& ex)

View file

@ -207,4 +207,12 @@ static const char * gamma_method_strings[] = {
IMPLEMENT_ENUM( gamma_method_e, 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 } // namespace mapnik

View file

@ -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{ "avoid-edges",nullptr, property_types::target_bool },
property_meta_type{ "font-feature-settings", nullptr, property_types::target_font_feature_settings }, 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{ "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},
}; };

@ -1 +1 @@
Subproject commit 263360fae07cceee0fbdb7fa213ae76f3977c567 Subproject commit f527cc7438b64c5b21e8d909547a6708859098c1