2012-02-18 14:03:21 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2014-11-20 15:25:50 +01:00
|
|
|
* Copyright (C) 2014 Artem Pavlenko
|
2012-02-18 14:03:21 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
// mapnik
|
2013-11-08 05:09:22 +01:00
|
|
|
#include <mapnik/text/symbolizer_helpers.hpp>
|
2012-02-12 03:55:13 +01:00
|
|
|
#include <mapnik/label_collision_detector.hpp>
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
2014-07-28 13:10:34 +02:00
|
|
|
#include <mapnik/text/text_layout.hpp>
|
2014-09-30 21:50:08 +02:00
|
|
|
#include <mapnik/feature.hpp>
|
|
|
|
#include <mapnik/marker.hpp>
|
|
|
|
#include <mapnik/marker_cache.hpp>
|
2015-03-24 13:32:05 +01:00
|
|
|
#include <mapnik/geometry.hpp>
|
2015-03-06 12:17:02 +01:00
|
|
|
#include <mapnik/geometry_type.hpp>
|
|
|
|
#include <mapnik/geometry_centroid.hpp>
|
2015-03-18 16:17:37 +01:00
|
|
|
#include <mapnik/vertex_processor.hpp>
|
2012-08-22 22:27:44 +02:00
|
|
|
#include <mapnik/geom_util.hpp>
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
#include <mapnik/parse_path.hpp>
|
|
|
|
#include <mapnik/debug.hpp>
|
2013-11-28 07:50:15 +01:00
|
|
|
#include <mapnik/symbolizer.hpp>
|
|
|
|
#include <mapnik/value_types.hpp>
|
2014-08-06 14:10:24 +02:00
|
|
|
#include <mapnik/text/placement_finder_impl.hpp>
|
2013-11-28 07:50:15 +01:00
|
|
|
#include <mapnik/text/placements/base.hpp>
|
|
|
|
#include <mapnik/text/placements/dummy.hpp>
|
|
|
|
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
//agg
|
2012-03-07 13:48:51 +01:00
|
|
|
#include "agg_conv_clip_polyline.h"
|
2012-01-29 04:49:02 +01:00
|
|
|
|
2015-03-18 16:17:37 +01:00
|
|
|
namespace mapnik { namespace detail {
|
|
|
|
|
|
|
|
template <typename Points>
|
|
|
|
struct apply_vertex_placement
|
|
|
|
{
|
|
|
|
apply_vertex_placement(Points & points, view_transform const& tr, proj_transform const& prj_trans)
|
|
|
|
: points_(points),
|
|
|
|
tr_(tr),
|
|
|
|
prj_trans_(prj_trans) {}
|
|
|
|
|
|
|
|
template <typename Adapter>
|
|
|
|
void operator() (Adapter const& va) const
|
|
|
|
{
|
|
|
|
double label_x, label_y, z = 0;
|
|
|
|
va.rewind(0);
|
2015-05-28 17:06:56 +02:00
|
|
|
for (unsigned cmd; (cmd = va.vertex(&label_x, &label_y)) != SEG_END; )
|
2015-03-18 16:17:37 +01:00
|
|
|
{
|
|
|
|
if (cmd != SEG_CLOSE)
|
|
|
|
{
|
|
|
|
prj_trans_.backward(label_x, label_y, z);
|
|
|
|
tr_.forward(&label_x, &label_y);
|
|
|
|
points_.emplace_back(label_x, label_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Points & points_;
|
|
|
|
view_transform const& tr_;
|
|
|
|
proj_transform const& prj_trans_;
|
|
|
|
};
|
|
|
|
|
2015-03-25 12:55:37 +01:00
|
|
|
template <typename T>
|
|
|
|
struct split_multi_geometries
|
|
|
|
{
|
|
|
|
using container_type = T;
|
2015-03-25 14:20:47 +01:00
|
|
|
split_multi_geometries(container_type & cont, view_transform const& t,
|
|
|
|
proj_transform const& prj_trans, double minimum_path_length)
|
|
|
|
: cont_(cont),
|
|
|
|
t_(t),
|
|
|
|
prj_trans_(prj_trans),
|
|
|
|
minimum_path_length_(minimum_path_length) {}
|
2015-03-25 12:55:37 +01:00
|
|
|
|
|
|
|
void operator() (geometry::geometry_empty const&) const {}
|
2015-04-09 22:22:51 +02:00
|
|
|
void operator() (geometry::multi_point<double> const& multi_pt) const
|
2015-03-25 12:55:37 +01:00
|
|
|
{
|
|
|
|
for ( auto const& pt : multi_pt )
|
|
|
|
{
|
2015-06-02 15:25:57 +02:00
|
|
|
cont_.push_back(base_symbolizer_helper::geometry_cref(std::cref(pt)));
|
2015-03-25 12:55:37 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 22:22:51 +02:00
|
|
|
void operator() (geometry::multi_line_string<double> const& multi_line) const
|
2015-03-25 12:55:37 +01:00
|
|
|
{
|
|
|
|
for ( auto const& line : multi_line )
|
|
|
|
{
|
2015-06-02 15:25:57 +02:00
|
|
|
cont_.push_back(base_symbolizer_helper::geometry_cref(std::cref(line)));
|
2015-03-25 12:55:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:22:51 +02:00
|
|
|
void operator() (geometry::polygon<double> const& poly) const
|
2015-03-25 14:20:47 +01:00
|
|
|
{
|
|
|
|
if (minimum_path_length_ > 0)
|
|
|
|
{
|
|
|
|
box2d<double> bbox = t_.forward(geometry::envelope(poly), prj_trans_);
|
|
|
|
if (bbox.width() >= minimum_path_length_)
|
|
|
|
{
|
2015-06-02 15:25:57 +02:00
|
|
|
cont_.push_back(base_symbolizer_helper::geometry_cref(std::cref(poly)));
|
2015-03-25 14:20:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-02 15:25:57 +02:00
|
|
|
cont_.push_back(base_symbolizer_helper::geometry_cref(std::cref(poly)));
|
2015-03-25 14:20:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:22:51 +02:00
|
|
|
void operator() (geometry::multi_polygon<double> const& multi_poly) const
|
2015-03-25 12:55:37 +01:00
|
|
|
{
|
|
|
|
for ( auto const& poly : multi_poly )
|
|
|
|
{
|
2015-03-25 14:20:47 +01:00
|
|
|
(*this)(poly);
|
2015-03-25 12:55:37 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-25 14:20:47 +01:00
|
|
|
|
2015-04-09 22:22:51 +02:00
|
|
|
void operator() (geometry::geometry_collection<double> const& collection) const
|
2015-03-25 12:55:37 +01:00
|
|
|
{
|
|
|
|
for ( auto const& geom : collection)
|
|
|
|
{
|
2015-03-25 14:20:47 +01:00
|
|
|
util::apply_visitor(*this, geom);
|
2015-03-25 12:55:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Geometry>
|
|
|
|
void operator() (Geometry const& geom) const
|
|
|
|
{
|
2015-06-02 15:25:57 +02:00
|
|
|
cont_.push_back(base_symbolizer_helper::geometry_cref(std::cref(geom)));
|
2015-03-25 12:55:37 +01:00
|
|
|
}
|
2015-03-25 14:20:47 +01:00
|
|
|
|
2015-03-25 12:55:37 +01:00
|
|
|
container_type & cont_;
|
2015-03-25 14:20:47 +01:00
|
|
|
view_transform const& t_;
|
|
|
|
proj_transform const& prj_trans_;
|
|
|
|
double minimum_path_length_;
|
2015-03-25 12:55:37 +01:00
|
|
|
};
|
|
|
|
|
2015-03-18 16:17:37 +01:00
|
|
|
} // ns detail
|
2012-01-29 04:49:02 +01:00
|
|
|
|
2014-01-09 14:42:32 +01:00
|
|
|
base_symbolizer_helper::base_symbolizer_helper(
|
2014-05-11 22:08:24 +02:00
|
|
|
symbolizer_base const& sym,
|
|
|
|
feature_impl const& feature,
|
|
|
|
attributes const& vars,
|
|
|
|
proj_transform const& prj_trans,
|
2014-01-09 14:42:32 +01:00
|
|
|
unsigned width, unsigned height, double scale_factor,
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform const& t,
|
2014-05-11 22:08:24 +02:00
|
|
|
box2d<double> const& query_extent)
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
: sym_(sym),
|
|
|
|
feature_(feature),
|
2014-05-11 22:08:24 +02:00
|
|
|
vars_(vars),
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
prj_trans_(prj_trans),
|
|
|
|
t_(t),
|
|
|
|
dims_(0, 0, width, height),
|
|
|
|
query_extent_(query_extent),
|
2014-01-09 14:42:32 +01:00
|
|
|
scale_factor_(scale_factor),
|
2014-12-20 04:05:54 +01:00
|
|
|
info_ptr_(mapnik::get<text_placements_ptr>(sym_, keys::text_placements_)->get_placement_info(scale_factor,feature_,vars_)),
|
2014-10-13 01:07:26 +02:00
|
|
|
text_props_(evaluate_text_properties(info_ptr_->properties,feature_,vars_))
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
initialize_geometries();
|
2014-07-15 17:31:43 +02:00
|
|
|
if (!geometries_to_process_.size()) return; // FIXME - bad practise
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
initialize_points();
|
2012-01-29 04:49:02 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 12:52:43 +01:00
|
|
|
struct largest_bbox_first
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
bool operator() (geometry::geometry<double> const* g0, geometry::geometry<double> const* g1) const
|
2012-01-31 12:52:43 +01:00
|
|
|
{
|
2015-03-24 14:21:28 +01:00
|
|
|
box2d<double> b0 = geometry::envelope(*g0);
|
|
|
|
box2d<double> b1 = geometry::envelope(*g1);
|
2015-03-06 12:17:02 +01:00
|
|
|
return b0.width() * b0.height() > b1.width() * b1.height();
|
2012-01-31 12:52:43 +01:00
|
|
|
}
|
2015-03-25 12:55:37 +01:00
|
|
|
bool operator() (base_symbolizer_helper::geometry_cref const& g0,
|
|
|
|
base_symbolizer_helper::geometry_cref const& g1) const
|
|
|
|
{
|
|
|
|
box2d<double> b0 = geometry::envelope(g0);
|
|
|
|
box2d<double> b1 = geometry::envelope(g1);
|
|
|
|
return b0.width() * b0.height() > b1.width() * b1.height();
|
|
|
|
}
|
2012-01-31 12:52:43 +01:00
|
|
|
};
|
2012-01-29 04:49:02 +01:00
|
|
|
|
2014-10-10 08:00:39 +02:00
|
|
|
void base_symbolizer_helper::initialize_geometries() const
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
2014-10-10 13:38:06 +02:00
|
|
|
bool largest_box_only = text_props_->largest_bbox_only;
|
|
|
|
double minimum_path_length = text_props_->minimum_path_length;
|
2015-03-25 14:20:47 +01:00
|
|
|
util::apply_visitor(detail::split_multi_geometries<geometry_container_type>
|
|
|
|
(geometries_to_process_, t_, prj_trans_, minimum_path_length ), feature_.get_geometry());
|
2015-03-16 08:32:25 +01:00
|
|
|
// FIXME: return early if geometries_to_process_.empty() ?
|
2012-01-31 12:52:43 +01:00
|
|
|
if (largest_box_only)
|
|
|
|
{
|
|
|
|
geometries_to_process_.sort(largest_bbox_first());
|
|
|
|
geo_itr_ = geometries_to_process_.begin();
|
2015-03-25 12:55:37 +01:00
|
|
|
geometries_to_process_.erase(++geo_itr_, geometries_to_process_.end());
|
2012-01-31 12:52:43 +01:00
|
|
|
}
|
2012-01-29 04:49:02 +01:00
|
|
|
geo_itr_ = geometries_to_process_.begin();
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:00:39 +02:00
|
|
|
void base_symbolizer_helper::initialize_points() const
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
2014-10-10 13:38:06 +02:00
|
|
|
label_placement_enum how_placed = text_props_->label_placement;
|
2012-03-06 03:00:45 +01:00
|
|
|
if (how_placed == LINE_PLACEMENT)
|
|
|
|
{
|
2012-01-29 04:49:02 +01:00
|
|
|
point_placement_ = false;
|
|
|
|
return;
|
2012-03-06 03:00:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-29 04:49:02 +01:00
|
|
|
point_placement_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double label_x=0.0;
|
|
|
|
double label_y=0.0;
|
|
|
|
double z=0.0;
|
|
|
|
|
2015-03-25 12:55:37 +01:00
|
|
|
for (auto const& geom : geometries_to_process_)
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
|
|
|
if (how_placed == VERTEX_PLACEMENT)
|
|
|
|
{
|
2015-03-18 16:17:37 +01:00
|
|
|
using apply_vertex_placement = detail::apply_vertex_placement<std::list<pixel_position> >;
|
|
|
|
apply_vertex_placement apply(points_, t_, prj_trans_);
|
2015-03-24 14:21:28 +01:00
|
|
|
util::apply_visitor(geometry::vertex_processor<apply_vertex_placement>(apply), geom);
|
2012-03-06 03:00:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-21 21:51:39 +02:00
|
|
|
// https://github.com/mapnik/mapnik/issues/1423
|
|
|
|
bool success = false;
|
|
|
|
// https://github.com/mapnik/mapnik/issues/1350
|
2015-03-24 14:21:28 +01:00
|
|
|
auto type = geometry::geometry_type(geom);
|
2015-03-18 16:17:37 +01:00
|
|
|
|
2015-03-16 08:32:25 +01:00
|
|
|
// FIXME: how to handle MultiLineString?
|
2015-03-24 14:21:28 +01:00
|
|
|
if (type == geometry::geometry_types::LineString)
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
auto const& line = mapnik::util::get<geometry::line_string<double> >(geom);
|
|
|
|
geometry::line_string_vertex_adapter<double> va(line);
|
2015-02-06 16:45:51 +01:00
|
|
|
success = label::middle_point(va, label_x,label_y);
|
2012-07-31 03:29:26 +02:00
|
|
|
}
|
|
|
|
else if (how_placed == POINT_PLACEMENT)
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry::point<double> pt;
|
2015-03-24 14:21:28 +01:00
|
|
|
geometry::centroid(geom, pt);
|
2015-03-18 16:17:37 +01:00
|
|
|
label_x = pt.x;
|
|
|
|
label_y = pt.y;
|
2015-03-06 12:17:02 +01:00
|
|
|
success = true;
|
2012-03-06 03:00:45 +01:00
|
|
|
}
|
2015-03-25 14:20:47 +01:00
|
|
|
else if (how_placed == INTERIOR_PLACEMENT) // polygon
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
2015-03-25 14:20:47 +01:00
|
|
|
if (type == geometry::geometry_types::Polygon)
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
auto const& poly = mapnik::util::get<geometry::polygon<double> >(geom);
|
|
|
|
geometry::polygon_vertex_adapter<double> va(poly);
|
2015-03-25 14:20:47 +01:00
|
|
|
success = label::interior_position(va, label_x, label_y);
|
|
|
|
}
|
2012-03-06 03:00:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-10 00:51:04 +02:00
|
|
|
MAPNIK_LOG_ERROR(symbolizer_helpers) << "ERROR: Unknown placement type in initialize_points()";
|
2012-01-29 04:49:02 +01:00
|
|
|
}
|
2012-08-21 21:51:39 +02:00
|
|
|
if (success)
|
|
|
|
{
|
2015-03-18 16:17:37 +01:00
|
|
|
prj_trans_.backward(label_x, label_y, z);
|
|
|
|
t_.forward(&label_x, &label_y);
|
|
|
|
points_.emplace_back(label_x, label_y);
|
2012-08-21 21:51:39 +02:00
|
|
|
}
|
2012-01-29 04:49:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
point_itr_ = points_.begin();
|
|
|
|
}
|
|
|
|
|
2014-01-09 14:42:32 +01:00
|
|
|
template <typename FaceManagerT, typename DetectorT>
|
|
|
|
text_symbolizer_helper::text_symbolizer_helper(
|
2014-05-11 22:08:24 +02:00
|
|
|
text_symbolizer const& sym,
|
|
|
|
feature_impl const& feature,
|
|
|
|
attributes const& vars,
|
|
|
|
proj_transform const& prj_trans,
|
2014-01-09 14:42:32 +01:00
|
|
|
unsigned width, unsigned height, double scale_factor,
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform const& t, FaceManagerT & font_manager,
|
2014-08-06 15:54:38 +02:00
|
|
|
DetectorT &detector, box2d<double> const& query_extent,
|
|
|
|
agg::trans_affine const& affine_trans)
|
2014-05-11 22:08:24 +02:00
|
|
|
: base_symbolizer_helper(sym, feature, vars, prj_trans, width, height, scale_factor, t, query_extent),
|
2014-10-13 01:07:26 +02:00
|
|
|
finder_(feature, vars, detector, dims_, *info_ptr_, font_manager, scale_factor),
|
2014-08-06 14:10:24 +02:00
|
|
|
adapter_(finder_,false),
|
2015-04-28 14:18:33 +02:00
|
|
|
converter_(query_extent_, sym_, t, prj_trans, affine_trans, feature, vars, scale_factor)
|
2014-01-09 14:42:32 +01:00
|
|
|
{
|
2014-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
// setup vertex converter
|
2014-10-17 21:45:15 +02:00
|
|
|
value_bool clip = mapnik::get<value_bool, keys::clip>(sym_, feature_, vars_);
|
|
|
|
value_double simplify_tolerance = mapnik::get<value_double, keys::simplify_tolerance>(sym_, feature_, vars_);
|
|
|
|
value_double smooth = mapnik::get<value_double, keys::smooth>(sym_, feature_, vars_);
|
2014-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
if (clip) converter_.template set<clip_line_tag>(); //optional clip (default: true)
|
|
|
|
converter_.template set<transform_tag>(); //always transform
|
|
|
|
converter_.template set<affine_transform_tag>();
|
|
|
|
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>(); // optional simplify converter
|
|
|
|
if (smooth > 0.0) converter_.template set<smooth_tag>(); // optional smooth converter
|
|
|
|
|
2014-01-09 14:42:32 +01:00
|
|
|
if (geometries_to_process_.size()) finder_.next_position();
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:00:39 +02:00
|
|
|
placements_list const& text_symbolizer_helper::get() const
|
2014-01-09 14:42:32 +01:00
|
|
|
{
|
|
|
|
if (point_placement_)
|
|
|
|
{
|
|
|
|
while (next_point_placement());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-09 20:40:30 +02:00
|
|
|
while (next_line_placement());
|
2014-01-09 14:42:32 +01:00
|
|
|
}
|
|
|
|
return finder_.placements();
|
|
|
|
}
|
|
|
|
|
2015-04-29 17:50:40 +02:00
|
|
|
class apply_line_placement_visitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
apply_line_placement_visitor(vertex_converter_type & converter,
|
|
|
|
placement_finder_adapter<placement_finder> const & adapter)
|
|
|
|
: converter_(converter), adapter_(adapter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(geometry::line_string<double> const & geo) const
|
|
|
|
{
|
|
|
|
geometry::line_string_vertex_adapter<double> va(geo);
|
|
|
|
converter_.apply(va, adapter_);
|
|
|
|
return adapter_.status();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(geometry::polygon<double> const & geo) const
|
|
|
|
{
|
|
|
|
geometry::polygon_vertex_adapter<double> va(geo);
|
|
|
|
converter_.apply(va, adapter_);
|
|
|
|
return adapter_.status();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator()(T const & geo) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vertex_converter_type & converter_;
|
|
|
|
placement_finder_adapter<placement_finder> const & adapter_;
|
|
|
|
};
|
|
|
|
|
2014-10-10 08:00:39 +02:00
|
|
|
bool text_symbolizer_helper::next_line_placement() const
|
2014-01-09 14:42:32 +01:00
|
|
|
{
|
|
|
|
while (!geometries_to_process_.empty())
|
|
|
|
{
|
|
|
|
if (geo_itr_ == geometries_to_process_.end())
|
|
|
|
{
|
|
|
|
//Just processed the last geometry. Try next placement.
|
|
|
|
if (!finder_.next_position()) return false; //No more placements
|
|
|
|
//Start again from begin of list
|
|
|
|
geo_itr_ = geometries_to_process_.begin();
|
|
|
|
continue; //Reexecute size check
|
|
|
|
}
|
2015-03-06 12:17:02 +01:00
|
|
|
|
2015-04-29 17:50:40 +02:00
|
|
|
if (mapnik::util::apply_visitor(apply_line_placement_visitor(converter_, adapter_), *geo_itr_))
|
2014-01-09 14:42:32 +01:00
|
|
|
{
|
2015-04-29 17:50:40 +02:00
|
|
|
//Found a placement
|
|
|
|
geo_itr_ = geometries_to_process_.erase(geo_itr_);
|
|
|
|
return true;
|
2014-01-09 14:42:32 +01:00
|
|
|
}
|
2015-04-29 10:58:19 +02:00
|
|
|
|
|
|
|
// No placement for this geometry. Keep it in geometries_to_process_ for next try.
|
|
|
|
++geo_itr_;
|
2014-01-09 14:42:32 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-10 08:00:39 +02:00
|
|
|
bool text_symbolizer_helper::next_point_placement() const
|
2014-01-09 14:42:32 +01:00
|
|
|
{
|
|
|
|
while (!points_.empty())
|
|
|
|
{
|
|
|
|
if (point_itr_ == points_.end())
|
|
|
|
{
|
|
|
|
//Just processed the last point. Try next placement.
|
|
|
|
if (!finder_.next_position()) return false; //No more placements
|
|
|
|
//Start again from begin of list
|
|
|
|
point_itr_ = points_.begin();
|
|
|
|
continue; //Reexecute size check
|
|
|
|
}
|
|
|
|
if (finder_.find_point_placement(*point_itr_))
|
|
|
|
{
|
|
|
|
//Found a placement
|
|
|
|
point_itr_ = points_.erase(point_itr_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//No placement for this point. Keep it in points_ for next try.
|
|
|
|
point_itr_++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-29 04:49:02 +01:00
|
|
|
template <typename FaceManagerT, typename DetectorT>
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
text_symbolizer_helper::text_symbolizer_helper(
|
2014-05-11 22:08:24 +02:00
|
|
|
shield_symbolizer const& sym,
|
|
|
|
feature_impl const& feature,
|
|
|
|
attributes const& vars,
|
|
|
|
proj_transform const& prj_trans,
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
unsigned width, unsigned height, double scale_factor,
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform const& t, FaceManagerT & font_manager,
|
2014-08-06 15:54:38 +02:00
|
|
|
DetectorT & detector, box2d<double> const& query_extent, agg::trans_affine const& affine_trans)
|
2014-05-11 22:08:24 +02:00
|
|
|
: base_symbolizer_helper(sym, feature, vars, prj_trans, width, height, scale_factor, t, query_extent),
|
2014-10-13 01:07:26 +02:00
|
|
|
finder_(feature, vars, detector, dims_, *info_ptr_, font_manager, scale_factor),
|
2014-08-06 14:10:24 +02:00
|
|
|
adapter_(finder_,true),
|
2015-04-28 14:18:33 +02:00
|
|
|
converter_(query_extent_, sym_, t, prj_trans, affine_trans, feature, vars, scale_factor)
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
2014-08-06 15:54:38 +02:00
|
|
|
// setup vertex converter
|
2014-10-17 21:45:15 +02:00
|
|
|
value_bool clip = mapnik::get<value_bool, keys::clip>(sym_, feature_, vars_);
|
|
|
|
value_double simplify_tolerance = mapnik::get<value_double, keys::simplify_tolerance>(sym_, feature_, vars_);
|
|
|
|
value_double smooth = mapnik::get<value_double, keys::smooth>(sym_, feature_, vars_);
|
2014-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
if (clip) converter_.template set<clip_line_tag>(); //optional clip (default: true)
|
|
|
|
converter_.template set<transform_tag>(); //always transform
|
|
|
|
converter_.template set<affine_transform_tag>();
|
|
|
|
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>(); // optional simplify converter
|
|
|
|
if (smooth > 0.0) converter_.template set<smooth_tag>(); // optional smooth converter
|
2014-01-09 14:42:32 +01:00
|
|
|
if (geometries_to_process_.size())
|
|
|
|
{
|
|
|
|
init_marker();
|
|
|
|
finder_.next_position();
|
|
|
|
}
|
2012-01-29 04:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 08:00:39 +02:00
|
|
|
void text_symbolizer_helper::init_marker() const
|
2012-01-29 04:49:02 +01:00
|
|
|
{
|
2014-10-17 21:45:15 +02:00
|
|
|
std::string filename = mapnik::get<std::string,keys::file>(sym_, feature_, vars_);
|
2014-05-11 22:08:24 +02:00
|
|
|
if (filename.empty()) return;
|
2015-05-04 21:11:41 +02:00
|
|
|
std::shared_ptr<mapnik::marker const> marker = marker_cache::instance().find(filename, true);
|
|
|
|
if (marker->is<marker_null>()) return;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
agg::trans_affine trans;
|
2013-11-28 07:50:15 +01:00
|
|
|
auto image_transform = get_optional<transform_type>(sym_, keys::image_transform);
|
2014-05-11 22:08:24 +02:00
|
|
|
if (image_transform) evaluate_transform(trans, feature_, vars_, *image_transform);
|
2015-05-04 21:11:41 +02:00
|
|
|
double width = marker->width();
|
|
|
|
double height = marker->height();
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
double px0 = - 0.5 * width;
|
|
|
|
double py0 = - 0.5 * height;
|
|
|
|
double px1 = 0.5 * width;
|
|
|
|
double py1 = 0.5 * height;
|
2012-01-29 04:49:02 +01:00
|
|
|
double px2 = px1;
|
|
|
|
double py2 = py0;
|
|
|
|
double px3 = px0;
|
|
|
|
double py3 = py1;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
trans.transform(&px0, &py0);
|
|
|
|
trans.transform(&px1, &py1);
|
|
|
|
trans.transform(&px2, &py2);
|
|
|
|
trans.transform(&px3, &py3);
|
|
|
|
box2d<double> bbox(px0, py0, px1, py1);
|
|
|
|
bbox.expand_to_include(px2, py2);
|
|
|
|
bbox.expand_to_include(px3, py3);
|
2014-10-17 21:45:15 +02:00
|
|
|
value_bool unlock_image = mapnik::get<value_bool, keys::unlock_image>(sym_, feature_, vars_);
|
|
|
|
value_double shield_dx = mapnik::get<value_double, keys::shield_dx>(sym_, feature_, vars_);
|
|
|
|
value_double shield_dy = mapnik::get<value_double, keys::shield_dy>(sym_, feature_, vars_);
|
2013-11-28 07:50:15 +01:00
|
|
|
pixel_position marker_displacement;
|
|
|
|
marker_displacement.set(shield_dx,shield_dy);
|
2015-02-19 05:58:33 +01:00
|
|
|
finder_.set_marker(std::make_shared<marker_info>(marker, trans), bbox, unlock_image, marker_displacement);
|
2012-01-29 04:49:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-09 14:42:32 +01:00
|
|
|
|
2014-05-11 22:08:24 +02:00
|
|
|
template text_symbolizer_helper::text_symbolizer_helper(
|
|
|
|
text_symbolizer const& sym,
|
|
|
|
feature_impl const& feature,
|
|
|
|
attributes const& vars,
|
|
|
|
proj_transform const& prj_trans,
|
2013-11-28 07:50:15 +01:00
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
|
|
|
double scale_factor,
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform const& t,
|
2014-10-02 03:54:11 +02:00
|
|
|
face_manager_freetype & font_manager,
|
2013-11-28 07:50:15 +01:00
|
|
|
label_collision_detector4 &detector,
|
2014-08-06 15:54:38 +02:00
|
|
|
box2d<double> const& query_extent,
|
|
|
|
agg::trans_affine const&);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
2014-05-11 22:08:24 +02:00
|
|
|
template text_symbolizer_helper::text_symbolizer_helper(
|
|
|
|
shield_symbolizer const& sym,
|
|
|
|
feature_impl const& feature,
|
|
|
|
attributes const& vars,
|
|
|
|
proj_transform const& prj_trans,
|
2013-11-28 07:50:15 +01:00
|
|
|
unsigned width,
|
|
|
|
unsigned height,
|
|
|
|
double scale_factor,
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform const& t,
|
2014-10-02 03:54:11 +02:00
|
|
|
face_manager_freetype & font_manager,
|
2013-11-28 07:50:15 +01:00
|
|
|
label_collision_detector4 &detector,
|
2014-08-06 15:54:38 +02:00
|
|
|
box2d<double> const& query_extent,
|
|
|
|
agg::trans_affine const&);
|
2012-01-29 04:49:02 +01:00
|
|
|
} //namespace
|