2012-01-30 02:32:25 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2012-02-07 23:40:02 +00:00
|
|
|
* Copyright (C) 2012 Artem Pavlenko, Jean-Francois Doyon
|
2012-01-30 02:32:25 +00: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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2013-10-23 22:42:01 +00:00
|
|
|
|
2014-08-12 12:40:45 +00:00
|
|
|
#include <mapnik/config.hpp>
|
2014-08-12 17:44:11 +00:00
|
|
|
|
2014-08-12 16:43:04 +00:00
|
|
|
#include "boost_std_shared_shim.hpp"
|
|
|
|
|
2012-01-30 02:32:25 +00:00
|
|
|
#include <boost/python.hpp>
|
2012-02-11 10:21:33 +00:00
|
|
|
#include <boost/python/stl_iterator.hpp>
|
2012-12-16 20:50:36 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2012-01-30 02:32:25 +00:00
|
|
|
|
2013-11-08 04:09:22 +00:00
|
|
|
#include <mapnik/text/text_properties.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 08:06:32 +00:00
|
|
|
#include <mapnik/text/placements/simple.hpp>
|
|
|
|
#include <mapnik/text/placements/list.hpp>
|
2013-11-08 04:09:22 +00:00
|
|
|
#include <mapnik/text/formatting/text.hpp>
|
|
|
|
#include <mapnik/text/formatting/list.hpp>
|
|
|
|
#include <mapnik/text/formatting/format.hpp>
|
2014-01-30 11:33:29 +00:00
|
|
|
#include <mapnik/text/formatting/layout.hpp>
|
2014-07-28 11:10:34 +00:00
|
|
|
#include <mapnik/text/text_layout.hpp>
|
2013-11-28 06:50:15 +00:00
|
|
|
#include <mapnik/symbolizer.hpp>
|
2012-02-12 03:06:34 +00:00
|
|
|
|
|
|
|
#include "mapnik_enumeration.hpp"
|
2012-02-07 23:40:02 +00:00
|
|
|
#include "mapnik_threads.hpp"
|
2012-01-30 02:32:25 +00:00
|
|
|
|
|
|
|
using namespace mapnik;
|
2012-02-05 14:11:08 +00:00
|
|
|
|
|
|
|
/* Notes:
|
2012-03-13 14:59:22 +00:00
|
|
|
Overriding functions in inherited classes:
|
|
|
|
boost.python documentation doesn't really tell you how to do it.
|
|
|
|
But this helps:
|
|
|
|
http://www.gamedev.net/topic/446225-inheritance-in-boostpython/
|
2012-02-05 14:11:08 +00:00
|
|
|
|
2012-03-13 14:59:22 +00:00
|
|
|
register_ptr_to_python is required for wrapped classes, but not for unwrapped.
|
2012-02-05 14:11:08 +00:00
|
|
|
|
2012-03-13 14:59:22 +00:00
|
|
|
Functions don't have to be members of the class, but can also be
|
|
|
|
normal functions taking a ref to the class as first parameter.
|
2012-02-05 14:11:08 +00:00
|
|
|
*/
|
2012-01-30 02:32:25 +00:00
|
|
|
|
|
|
|
namespace {
|
2013-11-05 23:11:23 +00:00
|
|
|
|
2012-01-30 02:32:25 +00:00
|
|
|
using namespace boost::python;
|
|
|
|
|
2013-11-05 23:11:23 +00:00
|
|
|
// This class works around a feature in boost python.
|
|
|
|
// See http://osdir.com/ml/python.c++/2003-11/msg00158.html
|
|
|
|
|
|
|
|
template <typename T,
|
|
|
|
typename X1 = boost::python::detail::not_specified,
|
|
|
|
typename X2 = boost::python::detail::not_specified,
|
|
|
|
typename X3 = boost::python::detail::not_specified>
|
|
|
|
class class_with_converter : public boost::python::class_<T, X1, X2, X3>
|
|
|
|
{
|
|
|
|
public:
|
2014-07-07 17:23:15 +00:00
|
|
|
using self = class_with_converter<T,X1,X2,X3>;
|
2013-11-05 23:11:23 +00:00
|
|
|
// Construct with the class name, with or without docstring, and default __init__() function
|
|
|
|
class_with_converter(char const* name, char const* doc = 0) : boost::python::class_<T, X1, X2, X3>(name, doc) { }
|
|
|
|
|
|
|
|
// Construct with class name, no docstring, and an uncallable __init__ function
|
|
|
|
class_with_converter(char const* name, boost::python::no_init_t y) : boost::python::class_<T, X1, X2, X3>(name, y) { }
|
|
|
|
|
|
|
|
// Construct with class name, docstring, and an uncallable __init__ function
|
|
|
|
class_with_converter(char const* name, char const* doc, boost::python::no_init_t y) : boost::python::class_<T, X1, X2, X3>(name, doc, y) { }
|
|
|
|
|
|
|
|
// Construct with class name and init<> function
|
|
|
|
template <class DerivedT> class_with_converter(char const* name, boost::python::init_base<DerivedT> const& i)
|
|
|
|
: boost::python::class_<T, X1, X2, X3>(name, i) { }
|
|
|
|
|
|
|
|
// Construct with class name, docstring and init<> function
|
|
|
|
template <class DerivedT>
|
|
|
|
inline class_with_converter(char const* name, char const* doc, boost::python::init_base<DerivedT> const& i)
|
|
|
|
: boost::python::class_<T, X1, X2, X3>(name, doc, i) { }
|
|
|
|
|
|
|
|
template <class D>
|
|
|
|
self& def_readwrite_convert(char const* name, D const& d, char const* /*doc*/=0)
|
|
|
|
{
|
|
|
|
this->add_property(name,
|
|
|
|
boost::python::make_getter(d, boost::python::return_value_policy<boost::python::return_by_value>()),
|
|
|
|
boost::python::make_setter(d, boost::python::default_call_policies()));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-30 11:01:57 +00:00
|
|
|
boost::python::tuple get_displacement(text_layout_properties const& t)
|
2012-01-30 02:32:25 +00:00
|
|
|
{
|
2014-07-15 09:15:56 +00:00
|
|
|
return boost::python::make_tuple(0.0,0.0);// FIXME t.displacement.x, t.displacement.y);
|
2012-01-30 02:32:25 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 11:01:57 +00:00
|
|
|
void set_displacement(text_layout_properties &t, boost::python::tuple arg)
|
2012-01-30 02:32:25 +00:00
|
|
|
{
|
2012-01-31 20:46:36 +00:00
|
|
|
if (len(arg) != 2)
|
|
|
|
{
|
|
|
|
PyErr_SetObject(PyExc_ValueError,
|
|
|
|
("expected 2-item tuple in call to set_displacement; got %s"
|
|
|
|
% arg).ptr()
|
|
|
|
);
|
|
|
|
throw_error_already_set();
|
|
|
|
}
|
2012-02-02 01:30:26 +00:00
|
|
|
|
2014-07-29 16:39:07 +00:00
|
|
|
//double x = extract<double>(arg[0]);
|
|
|
|
//double y = extract<double>(arg[1]);
|
2014-07-15 09:15:56 +00:00
|
|
|
//t.displacement.set(x, y); FIXME
|
2012-01-30 02:32:25 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
/*
|
|
|
|
struct NodeWrap
|
|
|
|
: formatting::node, wrapper<formatting::node>
|
2012-02-03 01:01:01 +00:00
|
|
|
{
|
2014-07-15 10:15:26 +00:00
|
|
|
NodeWrap()
|
|
|
|
: formatting::node(), wrapper<formatting::node>() {}
|
2012-02-03 23:19:20 +00:00
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-03 01:01:01 +00:00
|
|
|
{
|
2012-02-08 23:22:12 +00:00
|
|
|
python_block_auto_unblock b;
|
2014-05-11 20:08:24 +00:00
|
|
|
this->get_override("apply")(ptr(&p), ptr(&feature), ptr(&vars), ptr(&output));
|
2012-02-03 01:01:01 +00:00
|
|
|
}
|
2012-02-05 03:09:09 +00:00
|
|
|
|
|
|
|
virtual void add_expressions(expression_set &output) const
|
|
|
|
{
|
|
|
|
override o = this->get_override("add_expressions");
|
|
|
|
if (o)
|
|
|
|
{
|
2012-02-08 23:22:12 +00:00
|
|
|
python_block_auto_unblock b;
|
2012-02-05 03:09:09 +00:00
|
|
|
o(ptr(&output));
|
|
|
|
} else
|
|
|
|
{
|
2012-02-12 22:00:38 +00:00
|
|
|
formatting::node::add_expressions(output);
|
2012-02-05 03:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_add_expressions(expression_set &output) const
|
|
|
|
{
|
2012-02-12 22:00:38 +00:00
|
|
|
formatting::node::add_expressions(output);
|
2012-02-05 03:09:09 +00:00
|
|
|
}
|
2012-02-03 01:01:01 +00:00
|
|
|
};
|
2014-07-15 10:15:26 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
struct TextNodeWrap
|
|
|
|
: formatting::text_node, wrapper<formatting::text_node>
|
2012-02-03 23:19:20 +00:00
|
|
|
{
|
2014-07-15 10:15:26 +00:00
|
|
|
TextNodeWrap(expression_ptr expr)
|
|
|
|
: formatting::text_node(expr), wrapper<formatting::text_node>() {}
|
2012-02-12 00:49:54 +00:00
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
TextNodeWrap(std::string expr_text)
|
|
|
|
: formatting::text_node(expr_text), wrapper<formatting::text_node>() {}
|
2012-02-03 23:19:20 +00:00
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-03 23:19:20 +00:00
|
|
|
{
|
2012-02-07 23:40:02 +00:00
|
|
|
if(override o = this->get_override("apply"))
|
2012-02-03 23:19:20 +00:00
|
|
|
{
|
2012-02-08 23:22:12 +00:00
|
|
|
python_block_auto_unblock b;
|
2014-05-11 20:08:24 +00:00
|
|
|
o(ptr(&p), ptr(&feature), ptr(&vars), ptr(&output));
|
2012-02-03 23:19:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::text_node::apply(p, feature, vars, output);
|
2012-02-03 23:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void default_apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-03 23:19:20 +00:00
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::text_node::apply(p, feature, vars, output);
|
2012-02-03 23:19:20 +00:00
|
|
|
}
|
2012-02-06 00:10:09 +00:00
|
|
|
};
|
2014-07-15 10:15:26 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
struct FormatNodeWrap
|
|
|
|
: formatting::format_node, wrapper<formatting::format_node>
|
2012-02-06 00:10:09 +00:00
|
|
|
{
|
2014-07-28 16:22:32 +00:00
|
|
|
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-06 00:10:09 +00:00
|
|
|
{
|
2012-02-07 23:40:02 +00:00
|
|
|
if(override o = this->get_override("apply"))
|
2012-02-06 00:10:09 +00:00
|
|
|
{
|
2012-02-08 23:22:12 +00:00
|
|
|
python_block_auto_unblock b;
|
2014-05-11 20:08:24 +00:00
|
|
|
o(ptr(&p), ptr(&feature), ptr(&vars), ptr(&output));
|
2012-02-06 00:10:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::format_node::apply(p, feature, vars ,output);
|
2012-02-06 00:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-03 23:19:20 +00:00
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void default_apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-06 00:10:09 +00:00
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::format_node::apply(p, feature, vars, output);
|
2012-02-06 00:10:09 +00:00
|
|
|
}
|
2012-02-03 23:19:20 +00:00
|
|
|
};
|
|
|
|
|
2012-02-19 01:03:25 +00:00
|
|
|
struct ExprFormatWrap: formatting::expression_format, wrapper<formatting::expression_format>
|
|
|
|
{
|
2014-07-28 16:22:32 +00:00
|
|
|
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-19 01:03:25 +00:00
|
|
|
{
|
|
|
|
if(override o = this->get_override("apply"))
|
|
|
|
{
|
|
|
|
python_block_auto_unblock b;
|
2014-05-11 20:08:24 +00:00
|
|
|
o(ptr(&p), ptr(&feature), ptr(&vars), ptr(&output));
|
2012-02-19 01:03:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::expression_format::apply(p, feature, vars, output);
|
2012-02-19 01:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void default_apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-19 01:03:25 +00:00
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::expression_format::apply(p, feature, vars, output);
|
2012-02-19 01:03:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-30 11:33:29 +00:00
|
|
|
struct LayoutNodeWrap: formatting::layout_node, wrapper<formatting::layout_node>
|
|
|
|
{
|
2014-07-28 16:22:32 +00:00
|
|
|
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2014-01-30 11:33:29 +00:00
|
|
|
{
|
|
|
|
if(override o = this->get_override("apply"))
|
|
|
|
{
|
|
|
|
python_block_auto_unblock b;
|
2014-05-11 20:08:24 +00:00
|
|
|
o(ptr(&p), ptr(&feature), ptr(&vars), ptr(&output));
|
2014-01-30 11:33:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::layout_node::apply(p, feature, vars, output);
|
2014-01-30 11:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void default_apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2014-01-30 11:33:29 +00:00
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::layout_node::apply(p, feature, vars, output);
|
2014-01-30 11:33:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-12 22:00:38 +00:00
|
|
|
struct ListNodeWrap: formatting::list_node, wrapper<formatting::list_node>
|
2012-02-11 10:21:33 +00:00
|
|
|
{
|
|
|
|
//Default constructor
|
2012-02-12 22:00:38 +00:00
|
|
|
ListNodeWrap() : formatting::list_node(), wrapper<formatting::list_node>()
|
2012-02-11 10:21:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//Special constructor: Takes a python sequence as its argument
|
2012-02-12 22:00:38 +00:00
|
|
|
ListNodeWrap(object l) : formatting::list_node(), wrapper<formatting::list_node>()
|
2012-02-11 10:21:33 +00:00
|
|
|
{
|
2012-02-12 22:00:38 +00:00
|
|
|
stl_input_iterator<formatting::node_ptr> begin(l), end;
|
2013-07-30 19:14:47 +00:00
|
|
|
while (begin != end)
|
|
|
|
{
|
|
|
|
children_.push_back(*begin);
|
|
|
|
++begin;
|
|
|
|
}
|
2012-02-11 10:21:33 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
// TODO: Add constructor taking variable number of arguments.
|
|
|
|
http://wiki.python.org/moin/boost.python/HowTo#A.22Raw.22_function
|
2012-02-11 10:21:33 +00:00
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-11 10:21:33 +00:00
|
|
|
{
|
|
|
|
if(override o = this->get_override("apply"))
|
|
|
|
{
|
|
|
|
python_block_auto_unblock b;
|
2014-05-11 20:08:24 +00:00
|
|
|
o(ptr(&p), ptr(&feature), ptr(&vars), ptr(&output));
|
2012-02-11 10:21:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::list_node::apply(p, feature, vars, output);
|
2012-02-11 10:21:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void default_apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const
|
2012-02-11 10:21:33 +00:00
|
|
|
{
|
2014-05-11 20:08:24 +00:00
|
|
|
formatting::list_node::apply(p, feature, vars, output);
|
2012-02-11 10:21:33 +00:00
|
|
|
}
|
2012-02-19 01:03:25 +00:00
|
|
|
|
|
|
|
inline void IndexError(){
|
|
|
|
PyErr_SetString(PyExc_IndexError, "Index out of range");
|
|
|
|
throw_error_already_set();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned get_length()
|
|
|
|
{
|
|
|
|
return children_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
formatting::node_ptr get_item(int i)
|
|
|
|
{
|
2012-06-26 18:23:26 +00:00
|
|
|
if (i < 0) i+= children_.size();
|
|
|
|
if (i < static_cast<int>(children_.size())) return children_[i];
|
2012-02-19 01:03:25 +00:00
|
|
|
IndexError();
|
|
|
|
return formatting::node_ptr(); //Avoid compiler warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_item(int i, formatting::node_ptr ptr)
|
|
|
|
{
|
2012-06-26 18:23:26 +00:00
|
|
|
if (i < 0) i+= children_.size();
|
|
|
|
if (i < static_cast<int>(children_.size())) children_[i] = ptr;
|
2012-02-19 01:03:25 +00:00
|
|
|
IndexError();
|
|
|
|
}
|
|
|
|
|
|
|
|
void append(formatting::node_ptr ptr)
|
|
|
|
{
|
|
|
|
children_.push_back(ptr);
|
|
|
|
}
|
2012-02-11 10:21:33 +00:00
|
|
|
};
|
2014-07-15 10:15:26 +00:00
|
|
|
*/
|
2012-02-11 10:21:33 +00:00
|
|
|
|
2012-02-03 12:54:49 +00:00
|
|
|
struct TextPlacementsWrap: text_placements, wrapper<text_placements>
|
|
|
|
{
|
2012-03-04 15:38:40 +00:00
|
|
|
text_placement_info_ptr get_placement_info(double scale_factor_) const
|
2012-02-03 12:54:49 +00:00
|
|
|
{
|
2012-02-08 23:22:12 +00:00
|
|
|
python_block_auto_unblock b;
|
2014-07-09 10:31:03 +00:00
|
|
|
//return this->get_override("get_placement_info")();
|
|
|
|
return text_placement_info_ptr();
|
2012-02-03 12:54:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextPlacementInfoWrap: text_placement_info, wrapper<text_placement_info>
|
|
|
|
{
|
|
|
|
TextPlacementInfoWrap(text_placements const* parent,
|
2012-03-13 14:59:22 +00:00
|
|
|
double scale_factor_)
|
2012-03-04 15:38:40 +00:00
|
|
|
: text_placement_info(parent, scale_factor_)
|
2012-02-03 12:54:49 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool next()
|
|
|
|
{
|
2012-02-08 23:22:12 +00:00
|
|
|
python_block_auto_unblock b;
|
|
|
|
return this->get_override("next")();
|
2012-02-03 12:54:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-05 03:09:09 +00:00
|
|
|
void insert_expression(expression_set *set, expression_ptr p)
|
|
|
|
{
|
|
|
|
set->insert(p);
|
|
|
|
}
|
|
|
|
|
2013-11-28 06:50:15 +00:00
|
|
|
/*
|
2014-07-28 16:22:32 +00:00
|
|
|
evaluated_format_properties_ptr get_format(text_symbolizer const& sym)
|
2012-02-05 23:33:47 +00:00
|
|
|
{
|
2012-02-15 23:27:03 +00:00
|
|
|
return sym.get_placement_options()->defaults.format;
|
2012-02-05 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 16:22:32 +00:00
|
|
|
void set_format(text_symbolizer const& sym, evaluated_format_properties_ptr format)
|
2012-02-05 23:33:47 +00:00
|
|
|
{
|
2012-02-15 23:27:03 +00:00
|
|
|
sym.get_placement_options()->defaults.format = format;
|
2012-02-05 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
text_symbolizer_properties & get_properties(text_symbolizer const& sym)
|
|
|
|
{
|
2012-02-15 23:27:03 +00:00
|
|
|
return sym.get_placement_options()->defaults;
|
2012-02-05 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 23:27:03 +00:00
|
|
|
void set_properties(text_symbolizer const& sym, text_symbolizer_properties & defaults)
|
2012-02-05 23:33:47 +00:00
|
|
|
{
|
2012-02-15 23:27:03 +00:00
|
|
|
sym.get_placement_options()->defaults = defaults;
|
2012-02-05 23:33:47 +00:00
|
|
|
}
|
2013-11-28 06:50:15 +00:00
|
|
|
*/
|
2012-01-30 02:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void export_text_placement()
|
|
|
|
{
|
|
|
|
using namespace boost::python;
|
|
|
|
|
|
|
|
enumeration_<label_placement_e>("label_placement")
|
|
|
|
.value("LINE_PLACEMENT",LINE_PLACEMENT)
|
|
|
|
.value("POINT_PLACEMENT",POINT_PLACEMENT)
|
|
|
|
.value("VERTEX_PLACEMENT",VERTEX_PLACEMENT)
|
|
|
|
.value("INTERIOR_PLACEMENT",INTERIOR_PLACEMENT)
|
|
|
|
;
|
|
|
|
enumeration_<vertical_alignment_e>("vertical_alignment")
|
|
|
|
.value("TOP",V_TOP)
|
|
|
|
.value("MIDDLE",V_MIDDLE)
|
|
|
|
.value("BOTTOM",V_BOTTOM)
|
|
|
|
.value("AUTO",V_AUTO)
|
|
|
|
;
|
|
|
|
|
|
|
|
enumeration_<horizontal_alignment_e>("horizontal_alignment")
|
|
|
|
.value("LEFT",H_LEFT)
|
|
|
|
.value("MIDDLE",H_MIDDLE)
|
|
|
|
.value("RIGHT",H_RIGHT)
|
|
|
|
.value("AUTO",H_AUTO)
|
|
|
|
;
|
|
|
|
|
|
|
|
enumeration_<justify_alignment_e>("justify_alignment")
|
|
|
|
.value("LEFT",J_LEFT)
|
|
|
|
.value("MIDDLE",J_MIDDLE)
|
|
|
|
.value("RIGHT",J_RIGHT)
|
2012-03-19 16:12:53 +00:00
|
|
|
.value("AUTO", J_AUTO)
|
2012-01-30 02:32:25 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
enumeration_<text_transform_e>("text_transform")
|
|
|
|
.value("NONE",NONE)
|
|
|
|
.value("UPPERCASE",UPPERCASE)
|
|
|
|
.value("LOWERCASE",LOWERCASE)
|
|
|
|
.value("CAPITALIZE",CAPITALIZE)
|
|
|
|
;
|
|
|
|
|
2013-03-09 04:32:39 +00:00
|
|
|
enumeration_<halo_rasterizer_e>("halo_rasterizer")
|
|
|
|
.value("FULL",HALO_RASTERIZER_FULL)
|
|
|
|
.value("FAST",HALO_RASTERIZER_FAST)
|
|
|
|
;
|
|
|
|
|
2012-02-05 22:42:44 +00:00
|
|
|
class_<text_symbolizer>("TextSymbolizer",
|
2012-03-13 14:59:22 +00:00
|
|
|
init<>())
|
2012-02-05 22:42:44 +00:00
|
|
|
;
|
|
|
|
|
2012-01-30 02:32:25 +00:00
|
|
|
|
2012-02-21 08:52:14 +00:00
|
|
|
class_with_converter<text_symbolizer_properties>
|
2012-03-13 14:59:22 +00:00
|
|
|
("TextSymbolizerProperties")
|
2012-02-21 08:52:14 +00:00
|
|
|
.def_readwrite_convert("label_placement", &text_symbolizer_properties::label_placement)
|
2014-01-30 11:01:57 +00:00
|
|
|
.def_readwrite_convert("upright", &text_symbolizer_properties::upright)
|
2012-02-02 01:30:26 +00:00
|
|
|
.def_readwrite("label_spacing", &text_symbolizer_properties::label_spacing)
|
|
|
|
.def_readwrite("label_position_tolerance", &text_symbolizer_properties::label_position_tolerance)
|
|
|
|
.def_readwrite("avoid_edges", &text_symbolizer_properties::avoid_edges)
|
2014-09-10 11:45:41 +00:00
|
|
|
.def_readwrite("margin", &text_symbolizer_properties::margin)
|
2014-08-03 20:10:21 +00:00
|
|
|
.def_readwrite("repeat_distance", &text_symbolizer_properties::repeat_distance)
|
2014-08-20 23:43:36 +00:00
|
|
|
.def_readwrite("minimum_distance", &text_symbolizer_properties::minimum_distance)
|
2012-02-02 01:30:26 +00:00
|
|
|
.def_readwrite("minimum_padding", &text_symbolizer_properties::minimum_padding)
|
|
|
|
.def_readwrite("minimum_path_length", &text_symbolizer_properties::minimum_path_length)
|
|
|
|
.def_readwrite("maximum_angle_char_delta", &text_symbolizer_properties::max_char_angle_delta)
|
|
|
|
.def_readwrite("allow_overlap", &text_symbolizer_properties::allow_overlap)
|
2012-06-25 14:09:40 +00:00
|
|
|
.def_readwrite("largest_bbox_only", &text_symbolizer_properties::largest_bbox_only)
|
2014-01-30 11:01:57 +00:00
|
|
|
.def_readwrite("layout_defaults", &text_symbolizer_properties::layout_defaults)
|
2014-07-23 15:19:14 +00:00
|
|
|
//.def_readwrite("format", &text_symbolizer_properties::format)
|
2012-02-03 01:01:01 +00:00
|
|
|
.add_property ("format_tree",
|
|
|
|
&text_symbolizer_properties::format_tree,
|
|
|
|
&text_symbolizer_properties::set_format_tree);
|
2012-03-13 14:59:22 +00:00
|
|
|
/* from_xml, to_xml operate on mapnik's internal XML tree and don't make sense in python.
|
|
|
|
add_expressions isn't useful in python either. The result is only needed by
|
|
|
|
attribute_collector (which isn't exposed in python) and
|
|
|
|
it just calls add_expressions of the associated formatting tree.
|
|
|
|
set_old_style expression is just a compatibility wrapper and doesn't need to be exposed in python. */
|
|
|
|
;
|
2012-02-03 12:54:49 +00:00
|
|
|
|
2014-01-30 11:01:57 +00:00
|
|
|
class_with_converter<text_layout_properties>
|
|
|
|
("TextLayoutProperties")
|
|
|
|
.def_readwrite_convert("horizontal_alignment", &text_layout_properties::halign)
|
|
|
|
.def_readwrite_convert("justify_alignment", &text_layout_properties::jalign)
|
|
|
|
.def_readwrite_convert("vertical_alignment", &text_layout_properties::valign)
|
|
|
|
.def_readwrite("text_ratio", &text_layout_properties::text_ratio)
|
|
|
|
.def_readwrite("wrap_width", &text_layout_properties::wrap_width)
|
|
|
|
.def_readwrite("wrap_before", &text_layout_properties::wrap_before)
|
|
|
|
.def_readwrite("orientation", &text_layout_properties::orientation)
|
|
|
|
.def_readwrite("rotate_displacement", &text_layout_properties::rotate_displacement)
|
|
|
|
.add_property("displacement", &get_displacement, &set_displacement);
|
2014-07-28 16:22:32 +00:00
|
|
|
/*
|
|
|
|
class_with_converter<detail::evaluated_format_properties>
|
2012-03-13 14:59:22 +00:00
|
|
|
("CharProperties")
|
2014-07-28 16:22:32 +00:00
|
|
|
.def_readwrite_convert("text_transform", &detail::evaluated_format_properties::text_transform)
|
|
|
|
.def_readwrite_convert("fontset", &detail::evaluated_format_properties::fontset)
|
|
|
|
.def(init<detail::evaluated_format_properties const&>()) //Copy constructor
|
|
|
|
.def_readwrite("face_name", &detail::evaluated_format_properties::face_name)
|
|
|
|
.def_readwrite("text_size", &detail::evaluated_format_properties::text_size)
|
|
|
|
.def_readwrite("character_spacing", &detail::evaluated_format_properties::character_spacing)
|
|
|
|
.def_readwrite("line_spacing", &detail::evaluated_format_properties::line_spacing)
|
|
|
|
.def_readwrite("text_opacity", &detail::evaluated_format_properties::text_opacity)
|
|
|
|
.def_readwrite("fill", &detail::evaluated_format_properties::fill)
|
|
|
|
.def_readwrite("halo_fill", &detail::evaluated_format_properties::halo_fill)
|
|
|
|
.def_readwrite("halo_radius", &evaluated_format_properties::halo_radius)
|
|
|
|
//from_xml, to_xml operate on mapnik's internal XML tree and don't make sense in python.
|
2012-02-03 12:54:49 +00:00
|
|
|
;
|
2014-07-28 16:22:32 +00:00
|
|
|
*/
|
2012-02-03 23:19:20 +00:00
|
|
|
class_<TextPlacementsWrap,
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<TextPlacementsWrap>,
|
2012-03-13 14:59:22 +00:00
|
|
|
boost::noncopyable>
|
|
|
|
("TextPlacements")
|
2012-02-15 23:27:03 +00:00
|
|
|
.def_readwrite("defaults", &text_placements::defaults)
|
2014-07-09 10:31:03 +00:00
|
|
|
//.def("get_placement_info", pure_virtual(&text_placements::get_placement_info))
|
2012-02-05 14:45:30 +00:00
|
|
|
/* TODO: add_expressions() */
|
2012-02-03 12:54:49 +00:00
|
|
|
;
|
2013-09-20 13:00:11 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<text_placements> >();
|
2012-02-03 12:54:49 +00:00
|
|
|
|
2012-02-03 23:19:20 +00:00
|
|
|
class_<TextPlacementInfoWrap,
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<TextPlacementInfoWrap>,
|
2012-03-13 14:59:22 +00:00
|
|
|
boost::noncopyable>
|
|
|
|
("TextPlacementInfo",
|
|
|
|
init<text_placements const*, double>())
|
2012-02-03 12:54:49 +00:00
|
|
|
.def("next", pure_virtual(&text_placement_info::next))
|
|
|
|
.def_readwrite("properties", &text_placement_info::properties)
|
|
|
|
.def_readwrite("scale_factor", &text_placement_info::scale_factor)
|
2012-02-02 01:30:26 +00:00
|
|
|
;
|
2013-09-20 13:00:11 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<text_placement_info> >();
|
2012-02-03 01:01:01 +00:00
|
|
|
|
2012-02-05 14:45:30 +00:00
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
class_<expression_set,std::shared_ptr<expression_set>,
|
|
|
|
boost::noncopyable>("ExpressionSet")
|
2012-02-05 14:45:30 +00:00
|
|
|
.def("insert", &insert_expression);
|
2012-03-13 14:59:22 +00:00
|
|
|
;
|
2012-02-05 03:09:09 +00:00
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
/*
|
|
|
|
class_<formatting::node,std::shared_ptr<formatting::node>,
|
|
|
|
boost::noncopyable>("FormattingNode")
|
2012-02-12 22:00:38 +00:00
|
|
|
.def("apply", pure_virtual(&formatting::node::apply))
|
2014-07-15 10:15:26 +00:00
|
|
|
.def("add_expressions", pure_virtual(&formatting::node::add_expressions))
|
|
|
|
.def("to_xml", pure_virtual(&formatting::node::to_xml))
|
2012-02-03 01:01:01 +00:00
|
|
|
;
|
2012-02-03 23:19:20 +00:00
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<formatting::node> >();
|
2012-02-05 14:45:30 +00:00
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
class_<formatting::text_node,
|
|
|
|
std::shared_ptr<formatting::text_node>,
|
|
|
|
bases<formatting::node>,boost::noncopyable>("FormattingText", init<expression_ptr>())
|
2012-02-12 00:49:54 +00:00
|
|
|
.def(init<std::string>())
|
2014-07-15 10:15:26 +00:00
|
|
|
.def("apply", &formatting::text_node::apply)//, &TextNodeWrap::default_apply)
|
|
|
|
.add_property("text",&formatting::text_node::get_text, &formatting::text_node::set_text)
|
2012-02-03 23:19:20 +00:00
|
|
|
;
|
|
|
|
|
2014-07-15 10:15:26 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<formatting::text_node> >();
|
2012-02-06 00:10:09 +00:00
|
|
|
|
2012-02-21 08:52:14 +00:00
|
|
|
class_with_converter<FormatNodeWrap,
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<FormatNodeWrap>,
|
2012-03-13 14:59:22 +00:00
|
|
|
bases<formatting::node>,
|
|
|
|
boost::noncopyable>
|
|
|
|
("FormattingFormat")
|
2012-02-21 08:52:14 +00:00
|
|
|
.def_readwrite_convert("text_size", &formatting::format_node::text_size)
|
|
|
|
.def_readwrite_convert("face_name", &formatting::format_node::face_name)
|
|
|
|
.def_readwrite_convert("character_spacing", &formatting::format_node::character_spacing)
|
|
|
|
.def_readwrite_convert("line_spacing", &formatting::format_node::line_spacing)
|
|
|
|
.def_readwrite_convert("text_opacity", &formatting::format_node::text_opacity)
|
|
|
|
.def_readwrite_convert("text_transform", &formatting::format_node::text_transform)
|
|
|
|
.def_readwrite_convert("fill", &formatting::format_node::fill)
|
|
|
|
.def_readwrite_convert("halo_fill", &formatting::format_node::halo_fill)
|
|
|
|
.def_readwrite_convert("halo_radius", &formatting::format_node::halo_radius)
|
2012-02-12 22:00:38 +00:00
|
|
|
.def("apply", &formatting::format_node::apply, &FormatNodeWrap::default_apply)
|
2012-02-06 00:10:09 +00:00
|
|
|
.add_property("child",
|
2012-02-12 22:00:38 +00:00
|
|
|
&formatting::format_node::get_child,
|
|
|
|
&formatting::format_node::set_child)
|
2012-02-06 00:10:09 +00:00
|
|
|
;
|
2013-09-20 13:00:11 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<formatting::format_node> >();
|
2012-02-11 10:21:33 +00:00
|
|
|
|
|
|
|
class_<ListNodeWrap,
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<ListNodeWrap>,
|
2012-03-13 14:59:22 +00:00
|
|
|
bases<formatting::node>,
|
|
|
|
boost::noncopyable>
|
|
|
|
("FormattingList", init<>())
|
2012-02-11 10:21:33 +00:00
|
|
|
.def(init<list>())
|
2012-02-12 22:00:38 +00:00
|
|
|
.def("append", &formatting::list_node::push_back)
|
|
|
|
.def("apply", &formatting::list_node::apply, &ListNodeWrap::default_apply)
|
2012-02-19 01:03:25 +00:00
|
|
|
.def("__len__", &ListNodeWrap::get_length)
|
|
|
|
.def("__getitem__", &ListNodeWrap::get_item)
|
|
|
|
.def("__setitem__", &ListNodeWrap::set_item)
|
|
|
|
.def("append", &ListNodeWrap::append)
|
2012-03-13 14:59:22 +00:00
|
|
|
;
|
2012-02-11 10:21:33 +00:00
|
|
|
|
2013-09-20 13:00:11 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<formatting::list_node> >();
|
2012-02-19 01:03:25 +00:00
|
|
|
|
|
|
|
class_<ExprFormatWrap,
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<ExprFormatWrap>,
|
2012-03-13 14:59:22 +00:00
|
|
|
bases<formatting::node>,
|
|
|
|
boost::noncopyable>
|
|
|
|
("FormattingExpressionFormat")
|
2012-02-19 01:03:25 +00:00
|
|
|
.def_readwrite("text_size", &formatting::expression_format::text_size)
|
|
|
|
.def_readwrite("face_name", &formatting::expression_format::face_name)
|
|
|
|
.def_readwrite("character_spacing", &formatting::expression_format::character_spacing)
|
|
|
|
.def_readwrite("line_spacing", &formatting::expression_format::line_spacing)
|
|
|
|
.def_readwrite("text_opacity", &formatting::expression_format::text_opacity)
|
|
|
|
.def_readwrite("fill", &formatting::expression_format::fill)
|
|
|
|
.def_readwrite("halo_fill", &formatting::expression_format::halo_fill)
|
|
|
|
.def_readwrite("halo_radius", &formatting::expression_format::halo_radius)
|
|
|
|
.def("apply", &formatting::expression_format::apply, &ExprFormatWrap::default_apply)
|
|
|
|
.add_property("child",
|
|
|
|
&formatting::expression_format::get_child,
|
|
|
|
&formatting::expression_format::set_child)
|
|
|
|
;
|
2013-09-20 13:00:11 +00:00
|
|
|
register_ptr_to_python<std::shared_ptr<formatting::expression_format> >();
|
2014-07-15 10:15:26 +00:00
|
|
|
*/
|
2012-02-19 01:03:25 +00:00
|
|
|
//TODO: registry
|
2012-01-30 02:32:25 +00:00
|
|
|
}
|