2012-02-17 20:53:00 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-02-28 01:39:34 +01:00
|
|
|
|
2012-03-07 02:23:16 +01:00
|
|
|
//mapnik
|
2013-11-08 05:09:22 +01:00
|
|
|
#include <mapnik/text/placements/list.hpp>
|
2012-03-11 23:24:28 +01:00
|
|
|
#include <mapnik/xml_node.hpp>
|
2014-07-10 13:45:51 +02:00
|
|
|
#include <mapnik/make_unique.hpp>
|
2012-03-07 02:23:16 +01:00
|
|
|
//boost
|
2013-01-04 03:06:07 +01:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
2012-02-28 01:39:34 +01:00
|
|
|
|
2012-02-17 20:53:00 +01:00
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
|
|
|
|
bool text_placement_info_list::next()
|
|
|
|
{
|
2014-07-16 17:34:42 +02:00
|
|
|
if (state == 0)
|
|
|
|
{
|
2012-02-17 20:53:00 +01:00
|
|
|
properties = parent_->defaults;
|
2014-07-16 17:34:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (state >= parent_->list_.size() + 1) return false;
|
2012-02-17 20:53:00 +01:00
|
|
|
properties = parent_->list_[state-1];
|
2014-07-17 17:33:41 +02:00
|
|
|
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
2014-07-16 17:34:42 +02:00
|
|
|
{
|
|
|
|
return pixel_position(dx,dy);
|
|
|
|
};
|
2012-02-17 20:53:00 +01:00
|
|
|
}
|
2014-07-16 15:24:00 +02:00
|
|
|
++state;
|
2012-02-17 20:53:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_symbolizer_properties & text_placements_list::add()
|
|
|
|
{
|
|
|
|
if (list_.size()) {
|
2014-07-16 15:24:00 +02:00
|
|
|
text_symbolizer_properties & last = list_.back();
|
2012-02-17 20:53:00 +01:00
|
|
|
list_.push_back(last); //Preinitialize with old values
|
|
|
|
} else {
|
|
|
|
list_.push_back(defaults);
|
|
|
|
}
|
|
|
|
return list_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
text_symbolizer_properties & text_placements_list::get(unsigned i)
|
|
|
|
{
|
|
|
|
return list_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-04 16:38:40 +01:00
|
|
|
text_placement_info_ptr text_placements_list::get_placement_info(double scale_factor) const
|
2012-02-17 20:53:00 +01:00
|
|
|
{
|
2014-07-09 12:31:03 +02:00
|
|
|
return std::make_unique<text_placement_info_list>(this, scale_factor);
|
2012-02-17 20:53:00 +01:00
|
|
|
}
|
|
|
|
|
2014-07-09 12:31:03 +02:00
|
|
|
text_placements_list::text_placements_list()
|
2014-07-16 15:24:00 +02:00
|
|
|
: text_placements(),
|
|
|
|
list_(0) {}
|
2012-02-17 20:53:00 +01:00
|
|
|
|
2014-07-15 12:15:26 +02:00
|
|
|
void text_placements_list::add_expressions(expression_set & output) const
|
2012-02-17 20:53:00 +01:00
|
|
|
{
|
|
|
|
defaults.add_expressions(output);
|
2014-07-16 17:34:42 +02:00
|
|
|
for (auto & prop : list_)
|
2012-02-17 20:53:00 +01:00
|
|
|
{
|
2014-07-16 17:34:42 +02:00
|
|
|
prop.add_expressions(output);
|
2012-02-17 20:53:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned text_placements_list::size() const
|
|
|
|
{
|
|
|
|
return list_.size();
|
|
|
|
}
|
|
|
|
|
2014-07-15 12:15:26 +02:00
|
|
|
text_placements_ptr text_placements_list::from_xml(xml_node const& xml, fontset_map const & fontsets)
|
2012-02-18 00:39:14 +01:00
|
|
|
{
|
|
|
|
using boost::property_tree::ptree;
|
2014-07-16 17:34:42 +02:00
|
|
|
auto list = std::make_shared<text_placements_list>();
|
|
|
|
|
2012-02-18 00:39:14 +01:00
|
|
|
list->defaults.from_xml(xml, fontsets);
|
2014-07-16 17:34:42 +02:00
|
|
|
for (auto const& node : xml)
|
2012-02-28 01:39:34 +01:00
|
|
|
{
|
2014-07-16 17:34:42 +02:00
|
|
|
if (node.is_text() || !node.is("Placement")) continue;
|
2014-07-16 15:24:00 +02:00
|
|
|
text_symbolizer_properties & p = list->add();
|
2014-07-16 17:34:42 +02:00
|
|
|
p.format = std::make_shared<char_properties>(*(p.format)); //Make a deep copy <-- FIXME
|
|
|
|
|
2014-07-09 12:31:03 +02:00
|
|
|
//p.layout_defaults = std::make_shared<text_layout_properties>(*(p.layout_defaults));
|
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
|
|
|
//TODO: This needs a real copy constructor for text_symbolizer_properties
|
2014-07-16 17:34:42 +02:00
|
|
|
p.from_xml(node, fontsets);
|
|
|
|
|
|
|
|
//TODO: if (strict_ &&
|
2012-02-18 00:39:14 +01:00
|
|
|
// !p.format.fontset.size())
|
|
|
|
// ensure_font_face(p.format.face_name);
|
|
|
|
}
|
2014-07-16 17:34:42 +02:00
|
|
|
return list;
|
2012-02-18 00:39:14 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 20:53:00 +01:00
|
|
|
} //ns mapnik
|