diff --git a/include/mapnik/renderer_common/pattern_alignment.hpp b/include/mapnik/renderer_common/pattern_alignment.hpp new file mode 100644 index 000000000..aabac52e8 --- /dev/null +++ b/include/mapnik/renderer_common/pattern_alignment.hpp @@ -0,0 +1,68 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 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_PATTERN_ALIGNMENT_HPP +#define MAPNIK_PATTERN_ALIGNMENT_HPP + +#include + +namespace mapnik { namespace detail { + +struct apply_local_alignment +{ + apply_local_alignment(view_transform const& t, + proj_transform const& prj_trans, + box2d const& clip_box, + double & x, double & y) + : t_(t), + prj_trans_(prj_trans), + clip_box_(clip_box), + x_(x), + y_(y) {} + + void operator() (new_geometry::polygon_vertex_adapter & va) + { + using clipped_geometry_type = agg::conv_clip_polygon; + using path_type = transform_path_adapter; + clipped_geometry_type clipped(va); + clipped.clip_box(clip_box_.minx(),clip_box_.miny(),clip_box_.maxx(),clip_box_.maxy()); + path_type path(t_, clipped, prj_trans_); + path.vertex(&x_,&y_); + } + + template + void operator() (Adapter & va) + { + // no-op + } + + view_transform const& t_; + proj_transform const& prj_trans_; + box2d const& clip_box_; + double & x_; + double & y_; +}; + +}} + +#endif // MAPNIK_PATTERN_ALIGNMENT_HPP diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index 0f5949bb1..89707d541 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -38,6 +38,7 @@ #include #include #include +#include // agg #include "agg_basics.h" #include "agg_rendering_buffer.h" @@ -85,8 +86,8 @@ struct agg_renderer_process_visitor_p mapnik::image_rgba8 image(bbox_image.width(), bbox_image.height()); render_pattern(*ras_ptr_, marker, image_tr, 1.0, image); - using clipped_geometry_type = agg::conv_clip_polygon; - using path_type = transform_path_adapter; + //using clipped_geometry_type = agg::conv_clip_polygon; + //using path_type = transform_path_adapter; agg::rendering_buffer buf(current_buffer_->getBytes(), current_buffer_->width(), current_buffer_->height(), current_buffer_->getRowSize()); @@ -143,16 +144,9 @@ struct agg_renderer_process_visitor_p { double x0 = 0; double y0 = 0; -#if 0 // FIXME - if (feature_.num_geometries() > 0) - { - vertex_adapter va(feature_.get_geometry(0)); - clipped_geometry_type clipped(va); - clipped.clip_box(clip_box.minx(),clip_box.miny(),clip_box.maxx(),clip_box.maxy()); - path_type path(common_.t_,clipped,prj_trans_); - path.vertex(&x0,&y0); - } -#endif + using apply_local_alignment = detail::apply_local_alignment; + apply_local_alignment apply(common_.t_,prj_trans_, clip_box, x0, y0); + util::apply_visitor(new_geometry::vertex_processor(apply), feature_.get_geometry()); offset_x = unsigned(current_buffer_->width() - x0); offset_y = unsigned(current_buffer_->height() - y0); } @@ -252,16 +246,10 @@ struct agg_renderer_process_visitor_p { double x0 = 0; double y0 = 0; -#if 0 // FIXME - if (feature_.num_geometries() > 0) - { - vertex_adapter va(feature_.get_geometry(0)); - clipped_geometry_type clipped(va); - clipped.clip_box(clip_box.minx(),clip_box.miny(),clip_box.maxx(),clip_box.maxy()); - path_type path(common_.t_,clipped,prj_trans_); - path.vertex(&x0,&y0); - } -#endif + using apply_local_alignment = detail::apply_local_alignment; + apply_local_alignment apply(common_.t_,prj_trans_, clip_box, x0, y0); + util::apply_visitor(new_geometry::vertex_processor(apply), feature_.get_geometry()); + offset_x = unsigned(current_buffer_->width() - x0); offset_y = unsigned(current_buffer_->height() - y0); } diff --git a/src/cairo/process_polygon_pattern_symbolizer.cpp b/src/cairo/process_polygon_pattern_symbolizer.cpp index 25eb3ea48..7dbba48b4 100644 --- a/src/cairo/process_polygon_pattern_symbolizer.cpp +++ b/src/cairo/process_polygon_pattern_symbolizer.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace mapnik { @@ -111,22 +112,11 @@ void cairo_renderer::process(polygon_pattern_symbolizer const& sym, { double x0 = 0.0; double y0 = 0.0; -// FIXME -#if 0 - if (feature.num_geometries() > 0) - { - using clipped_geometry_type = agg::conv_clip_polygon; - using path_type = transform_path_adapter; - vertex_adapter va(feature.get_geometry(0)); - clipped_geometry_type clipped(va); - clipped.clip_box(clip_box.minx(), clip_box.miny(), - clip_box.maxx(), clip_box.maxy()); - path_type path(common_.t_, clipped, prj_trans); - path.vertex(&x0, &y0); - } + using apply_local_alignment = detail::apply_local_alignment; + apply_local_alignment apply(common_.t_, prj_trans, clip_box, x0, y0); + util::apply_visitor(new_geometry::vertex_processor(apply), feature.get_geometry()); offset_x = std::abs(clip_box.width() - x0); offset_y = std::abs(clip_box.height() - y0); -#endif } util::apply_visitor(cairo_renderer_process_visitor_p(context_, image_tr, offset_x, offset_y, opacity), marker);