mapnik/src/formatting/text.cpp

95 lines
2.6 KiB
C++
Raw Normal View History

2012-02-17 15:50:24 +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
*
*****************************************************************************/
// mapnik
#include <mapnik/formatting/text.hpp>
#include <mapnik/expression_string.hpp>
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/processed_text.hpp>
2012-03-11 23:24:28 +01:00
#include <mapnik/xml_node.hpp>
#include <mapnik/value_types.hpp>
2012-02-17 15:50:24 +01:00
// boost
#include <boost/property_tree/ptree.hpp>
2013-01-10 01:45:37 +01:00
#include <boost/make_shared.hpp>
2012-02-17 15:50:24 +01:00
namespace mapnik
{
namespace formatting
{
2013-01-10 01:45:37 +01:00
using boost::property_tree::ptree;
2012-02-17 15:50:24 +01:00
void text_node::to_xml(ptree &xml) const
{
ptree &new_node = xml.push_back(ptree::value_type(
"<xmltext>", ptree()))->second;
new_node.put_value(to_expression_string(*text_));
}
node_ptr text_node::from_xml(xml_node const& xml)
2012-02-17 15:50:24 +01:00
{
return boost::make_shared<text_node>(xml.get_value<expression_ptr>());
2012-02-17 15:50:24 +01:00
}
2013-01-04 08:54:04 +01:00
void text_node::apply(char_properties const& p, feature_impl const& feature, processed_text &output) const
2012-02-17 15:50:24 +01:00
{
mapnik::value_unicode_string text_str = boost::apply_visitor(evaluate<feature_impl,value_type>(feature), *text_).to_unicode();
2012-02-17 15:50:24 +01:00
if (p.text_transform == UPPERCASE)
{
text_str = text_str.toUpper();
}
else if (p.text_transform == LOWERCASE)
{
text_str = text_str.toLower();
}
else if (p.text_transform == CAPITALIZE)
{
text_str = text_str.toTitle(NULL);
}
if (text_str.length() > 0) {
output.push_back(p, text_str);
}
}
void text_node::add_expressions(expression_set &output) const
{
if (text_) output.insert(text_);
}
void text_node::set_text(expression_ptr text)
{
text_ = text;
}
expression_ptr text_node::get_text() const
{
return text_;
}
} //ns formatting
} //ns mapnik