/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2014 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 * *****************************************************************************/ #if defined(HAVE_CAIRO) // mapnik #include #include #include #include #include #include #include #include #include namespace mapnik { template void cairo_renderer::process(line_pattern_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { using conv_types = boost::mpl::vector; std::string filename = get(sym, keys::file, feature, common_.vars_); composite_mode_e comp_op = get(sym, keys::comp_op, feature, common_.vars_, src_over); bool clip = get(sym, keys::clip, feature, common_.vars_, false); double offset = get(sym, keys::offset, feature, common_.vars_, 0.0); double simplify_tolerance = get(sym, keys::simplify_tolerance, feature, common_.vars_, 0.0); double smooth = get(sym, keys::smooth, feature, common_.vars_, 0.0); boost::optional marker; if ( !filename.empty() ) { marker = marker_cache::instance().find(filename, true); } if (!marker || !(*marker)) return; unsigned width = (*marker)->width(); unsigned height = (*marker)->height(); cairo_save_restore guard(context_); context_.set_operator(comp_op); std::shared_ptr pattern; image_ptr image = nullptr; // TODO - re-implement at renderer level like polygon_pattern symbolizer double opacity = get(sym, keys::opacity, feature, common_.vars_,1.0); if ((*marker)->is_bitmap()) { pattern = std::make_unique(**((*marker)->get_bitmap_data()), opacity); context_.set_line_width(height); } else { mapnik::rasterizer ras; agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_); auto image_transform = get_optional(sym, keys::image_transform); if (image_transform) evaluate_transform(image_tr, feature, common_.vars_, *image_transform); image = render_pattern(ras, **marker, image_tr, 1.0); pattern = std::make_unique(*image, opacity); width = image->width(); height = image->height(); 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(sym, keys::geometry_transform); if (geom_transform) { evaluate_transform(tr, feature, common_.vars_, *geom_transform, common_.scale_factor_); } box2d clipping_extent = common_.query_extent_; if (clip) { double padding = (double)(common_.query_extent_.width()/common_.width_); double half_stroke = width/2.0; if (half_stroke > 1) padding *= half_stroke; if (std::fabs(offset) > 0) padding *= std::fabs(offset) * 1.2; padding *= common_.scale_factor_; clipping_extent.pad(padding); } using rasterizer_type = line_pattern_rasterizer; rasterizer_type ras(context_, *pattern, width, height); vertex_converter, rasterizer_type, line_pattern_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> converter(clipping_extent, ras, sym, common_.t_, prj_trans, tr, feature, common_.vars_, common_.scale_factor_); if (clip) converter.set(); // optional clip (default: true) converter.set(); // always transform if (std::fabs(offset) > 0.0) converter.set(); // parallel offset converter.set(); // optional affine transform if (simplify_tolerance > 0.0) converter.set(); // optional simplify converter if (smooth > 0.0) converter.set(); // optional smooth converter for (auto & geom : feature.paths()) { if (geom.size() > 1) { converter.apply(geom); } } } template void cairo_renderer::process(line_pattern_symbolizer const&, mapnik::feature_impl &, proj_transform const&); } #endif // HAVE_CAIRO