2011-02-28 14:17:46 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
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
|
|
|
* Copyright (C) 2013 Artem Pavlenko
|
2011-02-28 14:17:46 +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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-02-17 20:53:00 +01:00
|
|
|
// mapnik
|
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/text/text_properties.hpp>
|
|
|
|
#include <mapnik/text/layout.hpp>
|
2013-01-04 05:00:23 +01:00
|
|
|
#include <mapnik/debug.hpp>
|
|
|
|
#include <mapnik/feature.hpp>
|
2012-01-22 02:56:28 +01:00
|
|
|
#include <mapnik/ptree_helpers.hpp>
|
2012-02-17 20:53:00 +01:00
|
|
|
#include <mapnik/expression_string.hpp>
|
2013-11-08 05:09:22 +01:00
|
|
|
#include <mapnik/text/formatting/text.hpp>
|
2012-03-11 23:24:28 +01:00
|
|
|
#include <mapnik/xml_node.hpp>
|
2012-03-08 18:51:23 +01:00
|
|
|
#include <mapnik/config_error.hpp>
|
2013-11-28 07:50:15 +01:00
|
|
|
#include <mapnik/symbolizer.hpp>
|
2011-02-28 14:17:46 +01:00
|
|
|
|
2012-03-10 01:20:50 +01:00
|
|
|
// boost
|
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
|
|
|
|
2013-01-04 03:06:07 +01:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
2012-03-10 01:20:50 +01:00
|
|
|
|
2012-02-17 20:53:00 +01:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2012-01-22 02:56:28 +01:00
|
|
|
using boost::optional;
|
|
|
|
|
2013-11-28 07:50:15 +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
|
|
|
static const char * label_placement_strings[] = {
|
|
|
|
"point",
|
|
|
|
"line",
|
|
|
|
"vertex",
|
|
|
|
"interior",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
IMPLEMENT_ENUM(label_placement_e, label_placement_strings)
|
|
|
|
|
|
|
|
static const char * vertical_alignment_strings[] = {
|
|
|
|
"top",
|
|
|
|
"middle",
|
|
|
|
"bottom",
|
|
|
|
"auto",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
IMPLEMENT_ENUM(vertical_alignment_e, vertical_alignment_strings)
|
|
|
|
|
|
|
|
static const char * horizontal_alignment_strings[] = {
|
|
|
|
"left",
|
|
|
|
"middle",
|
|
|
|
"right",
|
|
|
|
"auto",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
IMPLEMENT_ENUM(horizontal_alignment_e, horizontal_alignment_strings)
|
|
|
|
|
|
|
|
static const char * justify_alignment_strings[] = {
|
|
|
|
"left",
|
|
|
|
"center", // not 'middle' in order to match CSS
|
|
|
|
"right",
|
|
|
|
"auto",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
IMPLEMENT_ENUM(justify_alignment_e, justify_alignment_strings)
|
|
|
|
|
|
|
|
static const char * text_transform_strings[] = {
|
|
|
|
"none",
|
|
|
|
"uppercase",
|
|
|
|
"lowercase",
|
|
|
|
"capitalize",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
IMPLEMENT_ENUM(text_transform_e, text_transform_strings)
|
|
|
|
|
|
|
|
|
|
|
|
static const char * text_upright_strings[] = {
|
|
|
|
"auto",
|
|
|
|
"left",
|
|
|
|
"right",
|
|
|
|
"left_only",
|
|
|
|
"right_only",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
IMPLEMENT_ENUM(text_upright_e, text_upright_strings)
|
|
|
|
|
2013-11-28 07:50:15 +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
|
|
|
|
2012-01-22 02:56:28 +01:00
|
|
|
text_symbolizer_properties::text_symbolizer_properties() :
|
|
|
|
label_placement(POINT_PLACEMENT),
|
2013-10-24 08:48:24 +02:00
|
|
|
label_spacing(0.0),
|
|
|
|
label_position_tolerance(0.0),
|
2012-01-22 02:56:28 +01:00
|
|
|
avoid_edges(false),
|
|
|
|
minimum_distance(0.0),
|
|
|
|
minimum_padding(0.0),
|
2012-03-05 22:48:35 +01:00
|
|
|
minimum_path_length(0.0),
|
2012-01-22 02:56:28 +01:00
|
|
|
max_char_angle_delta(22.5 * M_PI/180.0),
|
|
|
|
force_odd_labels(false),
|
|
|
|
allow_overlap(false),
|
2012-06-25 16:00:53 +02:00
|
|
|
largest_bbox_only(true),
|
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
|
|
|
upright(UPRIGHT_AUTO),
|
2014-01-30 12:01:57 +01:00
|
|
|
layout_defaults(std::make_shared<text_layout_properties>()),
|
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
|
|
|
format(std::make_shared<char_properties>()),
|
2012-01-31 16:24:58 +01:00
|
|
|
tree_()
|
2012-01-22 02:56:28 +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
|
|
|
void text_symbolizer_properties::process(text_layout &output, feature_impl const& feature) const
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
|
|
|
output.clear();
|
|
|
|
if (tree_) {
|
2012-02-16 00:17:22 +01:00
|
|
|
tree_->apply(format, feature, output);
|
2012-01-31 16:24:58 +01:00
|
|
|
} else {
|
2012-04-10 00:51:04 +02:00
|
|
|
MAPNIK_LOG_WARN(text_properties) << "text_symbolizer_properties can't produce text: No formatting tree!";
|
2012-01-31 16:24:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-12 22:48:44 +01:00
|
|
|
void text_symbolizer_properties::set_format_tree(formatting::node_ptr tree)
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
|
|
|
tree_ = tree;
|
|
|
|
}
|
|
|
|
|
2012-02-12 22:48:44 +01:00
|
|
|
formatting::node_ptr text_symbolizer_properties::format_tree() const
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
|
|
|
return tree_;
|
|
|
|
}
|
|
|
|
|
2013-12-20 00:11:35 +01:00
|
|
|
void text_symbolizer_properties::placement_properties_from_xml(xml_node const &sym)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<label_placement_e> placement_ = sym.get_opt_attr<label_placement_e>("placement");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (placement_) label_placement = *placement_;
|
2013-10-24 08:48:24 +02:00
|
|
|
optional<double> label_position_tolerance_ = sym.get_opt_attr<double>("label-position-tolerance");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (label_position_tolerance_) label_position_tolerance = *label_position_tolerance_;
|
2012-09-05 02:15:58 +02:00
|
|
|
optional<double> spacing_ = sym.get_opt_attr<double>("spacing");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (spacing_) label_spacing = *spacing_;
|
2012-08-21 23:50:24 +02:00
|
|
|
else {
|
|
|
|
// https://github.com/mapnik/mapnik/issues/1427
|
2012-09-05 02:15:58 +02:00
|
|
|
spacing_ = sym.get_opt_attr<double>("label-spacing");
|
2012-08-21 23:50:24 +02:00
|
|
|
if (spacing_) label_spacing = *spacing_;
|
|
|
|
}
|
2012-09-05 02:15:58 +02:00
|
|
|
optional<double> minimum_distance_ = sym.get_opt_attr<double>("minimum-distance");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (minimum_distance_) minimum_distance = *minimum_distance_;
|
2012-09-05 02:15:58 +02:00
|
|
|
optional<double> min_padding_ = sym.get_opt_attr<double>("minimum-padding");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (min_padding_) minimum_padding = *min_padding_;
|
2012-09-05 02:15:58 +02:00
|
|
|
optional<double> min_path_length_ = sym.get_opt_attr<double>("minimum-path-length");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (min_path_length_) minimum_path_length = *min_path_length_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<boolean> avoid_edges_ = sym.get_opt_attr<boolean>("avoid-edges");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (avoid_edges_) avoid_edges = *avoid_edges_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<boolean> allow_overlap_ = sym.get_opt_attr<boolean>("allow-overlap");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (allow_overlap_) allow_overlap = *allow_overlap_;
|
2012-06-25 16:00:53 +02:00
|
|
|
optional<boolean> largest_bbox_only_ = sym.get_opt_attr<boolean>("largest-bbox-only");
|
|
|
|
if (largest_bbox_only_) largest_bbox_only = *largest_bbox_only_;
|
2013-12-20 00:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer_properties::from_xml(xml_node const &sym, fontset_map const & fontsets)
|
|
|
|
{
|
|
|
|
placement_properties_from_xml(sym);
|
|
|
|
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<double> max_char_angle_delta_ = sym.get_opt_attr<double>("max-char-angle-delta");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (max_char_angle_delta_) max_char_angle_delta=(*max_char_angle_delta_)*(M_PI/180);
|
2014-01-30 12:01:57 +01:00
|
|
|
optional<text_upright_e> upright_ = sym.get_opt_attr<text_upright_e>("upright");
|
|
|
|
if (upright_) upright = *upright_;
|
|
|
|
|
|
|
|
layout_defaults->from_xml(sym);
|
2012-01-31 16:24:58 +01:00
|
|
|
|
2012-07-04 20:59:36 +02:00
|
|
|
optional<expression_ptr> name_ = sym.get_opt_attr<expression_ptr>("name");
|
2012-04-08 02:20:56 +02:00
|
|
|
if (name_)
|
|
|
|
{
|
2012-04-10 00:51:04 +02:00
|
|
|
MAPNIK_LOG_WARN(text_placements) << "Using 'name' in TextSymbolizer/ShieldSymbolizer is deprecated!";
|
|
|
|
|
2012-07-04 20:59:36 +02:00
|
|
|
set_old_style_expression(*name_);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2012-01-31 16:24:58 +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
|
|
|
format->from_xml(sym, fontsets);
|
2012-02-12 22:48:44 +01:00
|
|
|
formatting::node_ptr n(formatting::node::from_xml(sym));
|
2012-01-31 16:24:58 +01:00
|
|
|
if (n) set_format_tree(n);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
|
2012-03-05 20:31:58 +01:00
|
|
|
void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node,
|
|
|
|
bool explicit_defaults,
|
|
|
|
text_symbolizer_properties const& dfl) const
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
|
|
|
if (label_placement != dfl.label_placement || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "placement", label_placement);
|
|
|
|
}
|
|
|
|
if (label_position_tolerance != dfl.label_position_tolerance || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "label-position-tolerance", label_position_tolerance);
|
|
|
|
}
|
|
|
|
if (label_spacing != dfl.label_spacing || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "spacing", label_spacing);
|
|
|
|
}
|
|
|
|
if (minimum_distance != dfl.minimum_distance || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "minimum-distance", minimum_distance);
|
|
|
|
}
|
|
|
|
if (minimum_padding != dfl.minimum_padding || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "minimum-padding", minimum_padding);
|
|
|
|
}
|
|
|
|
if (minimum_path_length != dfl.minimum_path_length || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "minimum-path-length", minimum_path_length);
|
|
|
|
}
|
|
|
|
if (avoid_edges != dfl.avoid_edges || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "avoid-edges", avoid_edges);
|
|
|
|
}
|
2014-01-30 12:01:57 +01:00
|
|
|
if (allow_overlap != dfl.allow_overlap || explicit_defaults)
|
2012-06-25 16:00:53 +02:00
|
|
|
{
|
2014-01-30 12:01:57 +01:00
|
|
|
set_attr(node, "allow-overlap", allow_overlap);
|
|
|
|
}
|
|
|
|
if (largest_bbox_only != dfl.largest_bbox_only || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "largest-bbox-only", largest_bbox_only);
|
2012-06-25 16:00:53 +02:00
|
|
|
}
|
2012-01-22 02:56:28 +01:00
|
|
|
if (max_char_angle_delta != dfl.max_char_angle_delta || explicit_defaults)
|
|
|
|
{
|
2014-02-11 04:37:40 +01:00
|
|
|
set_attr(node, "max-char-angle-delta", max_char_angle_delta/(M_PI/180));
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-01-30 12:01:57 +01:00
|
|
|
if (upright != dfl.upright || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "upright", upright);
|
|
|
|
}
|
|
|
|
|
|
|
|
layout_defaults->to_xml(node, explicit_defaults, *(dfl.layout_defaults));
|
|
|
|
format->to_xml(node, explicit_defaults, *(dfl.format));
|
|
|
|
if (tree_) tree_->to_xml(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void text_symbolizer_properties::add_expressions(expression_set &output) const
|
|
|
|
{
|
|
|
|
if (layout_defaults) layout_defaults->add_expressions(output);
|
|
|
|
if (tree_) tree_->add_expressions(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer_properties::set_old_style_expression(expression_ptr expr)
|
|
|
|
{
|
|
|
|
tree_ = std::make_shared<formatting::text_node>(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
text_layout_properties::text_layout_properties() :
|
|
|
|
orientation(),
|
|
|
|
displacement(0.0,0.0),
|
|
|
|
halign(H_AUTO),
|
|
|
|
jalign(J_AUTO),
|
|
|
|
valign(V_AUTO),
|
|
|
|
text_ratio(0.0),
|
|
|
|
wrap_width(0.0),
|
|
|
|
wrap_before(false),
|
|
|
|
rotate_displacement(false)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_layout_properties::from_xml(xml_node const &sym)
|
|
|
|
{
|
|
|
|
optional<double> dx = sym.get_opt_attr<double>("dx");
|
|
|
|
if (dx) displacement.x = *dx;
|
|
|
|
optional<double> dy = sym.get_opt_attr<double>("dy");
|
|
|
|
if (dy) displacement.y = *dy;
|
|
|
|
optional<vertical_alignment_e> valign_ = sym.get_opt_attr<vertical_alignment_e>("vertical-alignment");
|
|
|
|
if (valign_) valign = *valign_;
|
|
|
|
optional<horizontal_alignment_e> halign_ = sym.get_opt_attr<horizontal_alignment_e>("horizontal-alignment");
|
|
|
|
if (halign_) halign = *halign_;
|
|
|
|
optional<justify_alignment_e> jalign_ = sym.get_opt_attr<justify_alignment_e>("justify-alignment");
|
|
|
|
if (jalign_) jalign = *jalign_;
|
|
|
|
optional<double> text_ratio_ = sym.get_opt_attr<double>("text-ratio");
|
|
|
|
if (text_ratio_) text_ratio = *text_ratio_;
|
|
|
|
optional<double> wrap_width_ = sym.get_opt_attr<double>("wrap-width");
|
|
|
|
if (wrap_width_) wrap_width = *wrap_width_;
|
|
|
|
optional<boolean> wrap_before_ = sym.get_opt_attr<boolean>("wrap-before");
|
|
|
|
if (wrap_before_) wrap_before = *wrap_before_;
|
|
|
|
optional<boolean> rotate_displacement_ = sym.get_opt_attr<boolean>("rotate-displacement");
|
|
|
|
if (rotate_displacement_) rotate_displacement = *rotate_displacement_;
|
|
|
|
optional<expression_ptr> orientation_ = sym.get_opt_attr<expression_ptr>("orientation");
|
|
|
|
if (orientation_) orientation = *orientation_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_layout_properties::to_xml(boost::property_tree::ptree &node,
|
|
|
|
bool explicit_defaults,
|
|
|
|
text_layout_properties const& dfl) const
|
|
|
|
{
|
|
|
|
if (displacement.x != dfl.displacement.x || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "dx", displacement.x);
|
|
|
|
}
|
|
|
|
if (displacement.y != dfl.displacement.y || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "dy", displacement.y);
|
|
|
|
}
|
|
|
|
if (valign != dfl.valign || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "vertical-alignment", valign);
|
|
|
|
}
|
2012-01-22 02:56:28 +01:00
|
|
|
if (halign != dfl.halign || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "horizontal-alignment", halign);
|
|
|
|
}
|
|
|
|
if (jalign != dfl.jalign || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "justify-alignment", jalign);
|
|
|
|
}
|
2014-01-30 12:01:57 +01:00
|
|
|
if (text_ratio != dfl.text_ratio || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-01-30 12:01:57 +01:00
|
|
|
set_attr(node, "text-ratio", text_ratio);
|
|
|
|
}
|
|
|
|
if (wrap_width != dfl.wrap_width || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "wrap-width", wrap_width);
|
|
|
|
}
|
|
|
|
if (wrap_before != dfl.wrap_before || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "wrap-before", wrap_before);
|
2012-01-22 02:56:28 +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
|
|
|
if (rotate_displacement != dfl.rotate_displacement || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "rotate-displacement", rotate_displacement);
|
|
|
|
}
|
2014-01-30 12:01:57 +01:00
|
|
|
if (orientation)
|
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-01-30 12:01:57 +01:00
|
|
|
std::string const& orientationstr = to_expression_string(*orientation);
|
|
|
|
if (!dfl.orientation || orientationstr != to_expression_string(*(dfl.orientation)) || explicit_defaults) {
|
|
|
|
set_attr(node, "orientation", orientationstr);
|
|
|
|
}
|
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
|
|
|
}
|
2012-01-31 16:24:58 +01:00
|
|
|
}
|
|
|
|
|
2014-01-30 12:01:57 +01:00
|
|
|
void text_layout_properties::add_expressions(expression_set &output) const
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
2012-02-05 03:11:00 +01:00
|
|
|
output.insert(orientation);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char_properties::char_properties() :
|
2012-03-05 22:48:35 +01:00
|
|
|
face_name(),
|
|
|
|
fontset(),
|
2012-01-22 02:56:28 +01:00
|
|
|
text_size(10.0),
|
|
|
|
character_spacing(0),
|
|
|
|
line_spacing(0),
|
|
|
|
text_opacity(1.0),
|
|
|
|
wrap_char(' '),
|
|
|
|
text_transform(NONE),
|
|
|
|
fill(color(0,0,0)),
|
|
|
|
halo_fill(color(255,255,255)),
|
|
|
|
halo_radius(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-07 02:23:16 +01:00
|
|
|
void char_properties::from_xml(xml_node const& sym, fontset_map const& fontsets)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-09-05 02:15:58 +02:00
|
|
|
optional<double> text_size_ = sym.get_opt_attr<double>("size");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (text_size_) text_size = *text_size_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<double> character_spacing_ = sym.get_opt_attr<double>("character-spacing");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (character_spacing_) character_spacing = *character_spacing_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<color> fill_ = sym.get_opt_attr<color>("fill");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (fill_) fill = *fill_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<color> halo_fill_ = sym.get_opt_attr<color>("halo-fill");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (halo_fill_) halo_fill = *halo_fill_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<double> halo_radius_ = sym.get_opt_attr<double>("halo-radius");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (halo_radius_) halo_radius = *halo_radius_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<text_transform_e> tconvert_ = sym.get_opt_attr<text_transform_e>("text-transform");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (tconvert_) text_transform = *tconvert_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<double> line_spacing_ = sym.get_opt_attr<double>("line-spacing");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (line_spacing_) line_spacing = *line_spacing_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<double> opacity_ = sym.get_opt_attr<double>("opacity");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (opacity_) text_opacity = *opacity_;
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<std::string> wrap_char_ = sym.get_opt_attr<std::string>("wrap-character");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (wrap_char_ && (*wrap_char_).size() > 0) wrap_char = ((*wrap_char_)[0]);
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<std::string> face_name_ = sym.get_opt_attr<std::string>("face-name");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (face_name_)
|
|
|
|
{
|
|
|
|
face_name = *face_name_;
|
|
|
|
}
|
2012-03-07 02:23:16 +01:00
|
|
|
optional<std::string> fontset_name_ = sym.get_opt_attr<std::string>("fontset-name");
|
2012-01-22 02:56:28 +01:00
|
|
|
if (fontset_name_) {
|
|
|
|
std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name_);
|
|
|
|
if (itr != fontsets.end())
|
|
|
|
{
|
|
|
|
fontset = itr->second;
|
2012-03-05 20:31:58 +01:00
|
|
|
}
|
|
|
|
else
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-03-12 01:09:26 +01:00
|
|
|
throw config_error("Unable to find any fontset named '" + *fontset_name_ + "'", sym);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-14 23:17:45 +02:00
|
|
|
if (!face_name.empty() && fontset)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-03-12 01:09:26 +01:00
|
|
|
throw config_error("Can't have both face-name and fontset-name", sym);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2012-09-14 23:17:45 +02:00
|
|
|
if (face_name.empty() && !fontset)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-03-12 01:09:26 +01:00
|
|
|
throw config_error("Must have face-name or fontset-name", sym);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void char_properties::to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const &dfl) const
|
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
if (fontset)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
set_attr(node, "fontset-name", fontset->get_name());
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (face_name != dfl.face_name || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "face-name", face_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text_size != dfl.text_size || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "size", text_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fill != dfl.fill || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "fill", fill);
|
|
|
|
}
|
|
|
|
if (halo_radius != dfl.halo_radius || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "halo-radius", halo_radius);
|
|
|
|
}
|
|
|
|
if (halo_fill != dfl.halo_fill || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "halo-fill", halo_fill);
|
|
|
|
}
|
|
|
|
if (wrap_char != dfl.wrap_char || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "wrap-character", std::string(1, wrap_char));
|
|
|
|
}
|
|
|
|
if (text_transform != dfl.text_transform || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "text-transform", text_transform);
|
|
|
|
}
|
|
|
|
if (line_spacing != dfl.line_spacing || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "line-spacing", line_spacing);
|
|
|
|
}
|
|
|
|
if (character_spacing != dfl.character_spacing || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "character-spacing", character_spacing);
|
|
|
|
}
|
|
|
|
// for shield_symbolizer this is later overridden
|
|
|
|
if (text_opacity != dfl.text_opacity || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "opacity", text_opacity);
|
|
|
|
}
|
|
|
|
}
|
2011-02-28 14:17:46 +01:00
|
|
|
|
2012-02-17 20:53:00 +01:00
|
|
|
} //ns mapnik
|