Merge branch 'master' into python-textplacement
This commit is contained in:
commit
03e9cac7f6
8 changed files with 86 additions and 140 deletions
|
@ -140,7 +140,6 @@ private:
|
|||
|
||||
class format_node: public node {
|
||||
public:
|
||||
format_node();
|
||||
void to_xml(boost::property_tree::ptree &xml) const;
|
||||
static node_ptr from_xml(boost::property_tree::ptree const& xml);
|
||||
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
|
||||
|
@ -148,29 +147,19 @@ public:
|
|||
void set_child(node_ptr child);
|
||||
node_ptr get_child() const;
|
||||
|
||||
void set_face_name(boost::optional<std::string> face_name);
|
||||
void set_text_size(boost::optional<unsigned> text_size);
|
||||
void set_character_spacing(boost::optional<unsigned> character_spacing);
|
||||
void set_line_spacing(boost::optional<unsigned> line_spacing);
|
||||
void set_text_opacity(boost::optional<double> opacity);
|
||||
void set_wrap_before(boost::optional<bool> wrap_before);
|
||||
void set_wrap_char(boost::optional<unsigned> wrap_char);
|
||||
void set_text_transform(boost::optional<text_transform_e> text_trans);
|
||||
void set_fill(boost::optional<color> fill);
|
||||
void set_halo_fill(boost::optional<color> halo_fill);
|
||||
void set_halo_radius(boost::optional<double> radius);
|
||||
boost::optional<std::string> face_name;
|
||||
boost::optional<unsigned> text_size;
|
||||
boost::optional<unsigned> character_spacing;
|
||||
boost::optional<unsigned> line_spacing;
|
||||
boost::optional<double> text_opacity;
|
||||
boost::optional<bool> wrap_before;
|
||||
boost::optional<unsigned> wrap_char;
|
||||
boost::optional<text_transform_e> text_transform;
|
||||
boost::optional<color> fill;
|
||||
boost::optional<color> halo_fill;
|
||||
boost::optional<double> halo_radius;
|
||||
|
||||
private:
|
||||
boost::optional<std::string> face_name_;
|
||||
boost::optional<unsigned> text_size_;
|
||||
boost::optional<unsigned> character_spacing_;
|
||||
boost::optional<unsigned> line_spacing_;
|
||||
boost::optional<double> text_opacity_;
|
||||
boost::optional<bool> wrap_before_;
|
||||
boost::optional<unsigned> wrap_char_;
|
||||
boost::optional<text_transform_e> text_transform_;
|
||||
boost::optional<color> fill_;
|
||||
boost::optional<color> halo_fill_;
|
||||
boost::optional<double> halo_radius_;
|
||||
node_ptr child_;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,13 +27,32 @@
|
|||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <boost/ptr_container/ptr_vector.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
namespace wkt {
|
||||
template <typename Iterator> struct wkt_collection_grammar;
|
||||
}
|
||||
|
||||
MAPNIK_DECL bool from_wkt(std::string const& wkt, boost::ptr_vector<geometry_type> & paths);
|
||||
|
||||
#if BOOST_VERSION >= 104700
|
||||
|
||||
class wkt_parser
|
||||
{
|
||||
typedef std::string::const_iterator iterator_type;
|
||||
public:
|
||||
wkt_parser();
|
||||
bool parse(std::string const& wkt, boost::ptr_vector<geometry_type> & paths);
|
||||
private:
|
||||
boost::scoped_ptr<mapnik::wkt::wkt_collection_grammar<iterator_type> > grammar_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ void agg_renderer<T>::process(building_symbolizer const& sym,
|
|||
proj_transform const& prj_trans)
|
||||
{
|
||||
typedef coord_transform2<CoordTransform,geometry_type> path_type;
|
||||
typedef coord_transform3<CoordTransform,geometry_type> path_type_roof;
|
||||
typedef agg::renderer_base<agg::pixfmt_rgba32_plain> ren_base;
|
||||
typedef agg::renderer_scanline_aa_solid<ren_base> renderer;
|
||||
|
||||
|
|
|
@ -745,7 +745,6 @@ void cairo_renderer_base::start_map_processing(Map const& map)
|
|||
proj_transform const& prj_trans)
|
||||
{
|
||||
typedef coord_transform2<CoordTransform,geometry_type> path_type;
|
||||
typedef coord_transform3<CoordTransform,geometry_type> path_type_roof;
|
||||
|
||||
cairo_context context(context_);
|
||||
|
||||
|
|
|
@ -587,7 +587,7 @@ featureset_ptr Map::query_point(unsigned index, double x, double y) const
|
|||
catch (...)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "exception caught in \"query_map_point\"\n";
|
||||
std::clog << "exception caught in \"query_point\"\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,28 +198,20 @@ expression_ptr text_node::get_text() const
|
|||
|
||||
/************************************************************/
|
||||
|
||||
format_node::format_node():
|
||||
node(),
|
||||
fill_(),
|
||||
child_()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void format_node::to_xml(ptree &xml) const
|
||||
{
|
||||
ptree &new_node = xml.push_back(ptree::value_type("Format", ptree()))->second;
|
||||
if (face_name_) set_attr(new_node, "face-name", *face_name_);
|
||||
if (text_size_) set_attr(new_node, "size", *text_size_);
|
||||
if (character_spacing_) set_attr(new_node, "character-spacing", *character_spacing_);
|
||||
if (line_spacing_) set_attr(new_node, "line-spacing", *line_spacing_);
|
||||
if (text_opacity_) set_attr(new_node, "opacity", *text_opacity_);
|
||||
if (wrap_before_) set_attr(new_node, "wrap-before", *wrap_before_);
|
||||
if (wrap_char_) set_attr(new_node, "wrap-character", *wrap_char_);
|
||||
if (text_transform_) set_attr(new_node, "text-transform", *text_transform_);
|
||||
if (fill_) set_attr(new_node, "fill", *fill_);
|
||||
if (halo_fill_) set_attr(new_node, "halo-fill", *halo_fill_);
|
||||
if (halo_radius_) set_attr(new_node, "halo-radius", *halo_radius_);
|
||||
if (face_name) set_attr(new_node, "face-name", *face_name);
|
||||
if (text_size) set_attr(new_node, "size", *text_size);
|
||||
if (character_spacing) set_attr(new_node, "character-spacing", *character_spacing);
|
||||
if (line_spacing) set_attr(new_node, "line-spacing", *line_spacing);
|
||||
if (text_opacity) set_attr(new_node, "opacity", *text_opacity);
|
||||
if (wrap_before) set_attr(new_node, "wrap-before", *wrap_before);
|
||||
if (wrap_char) set_attr(new_node, "wrap-character", *wrap_char);
|
||||
if (text_transform) set_attr(new_node, "text-transform", *text_transform);
|
||||
if (fill) set_attr(new_node, "fill", *fill);
|
||||
if (halo_fill) set_attr(new_node, "halo-fill", *halo_fill);
|
||||
if (halo_radius) set_attr(new_node, "halo-radius", *halo_radius);
|
||||
if (child_) child_->to_xml(new_node);
|
||||
}
|
||||
|
||||
|
@ -232,21 +224,19 @@ node_ptr format_node::from_xml(ptree const& xml)
|
|||
node_ptr child = node::from_xml(xml);
|
||||
n->set_child(child);
|
||||
|
||||
n->set_face_name(get_opt_attr<std::string>(xml, "face-name"));
|
||||
n->face_name = get_opt_attr<std::string>(xml, "face-name");
|
||||
/*TODO: Fontset is problematic. We don't have the fontsets pointer here... */
|
||||
n->set_text_size(get_opt_attr<unsigned>(xml, "size"));
|
||||
n->set_character_spacing(get_opt_attr<unsigned>(xml, "character-spacing"));
|
||||
n->set_line_spacing(get_opt_attr<unsigned>(xml, "line-spacing"));
|
||||
n->set_text_opacity(get_opt_attr<double>(xml, "opactity"));
|
||||
n->text_size = get_opt_attr<unsigned>(xml, "size");
|
||||
n->character_spacing = get_opt_attr<unsigned>(xml, "character-spacing");
|
||||
n->line_spacing = get_opt_attr<unsigned>(xml, "line-spacing");
|
||||
n->text_opacity = get_opt_attr<double>(xml, "opactity");
|
||||
boost::optional<boolean> wrap = get_opt_attr<boolean>(xml, "wrap-before");
|
||||
boost::optional<bool> wrap_before;
|
||||
if (wrap) wrap_before = *wrap;
|
||||
n->set_wrap_before(wrap_before);
|
||||
n->set_wrap_char(get_opt_attr<unsigned>(xml, "wrap-character"));
|
||||
n->set_text_transform(get_opt_attr<text_transform_e>(xml, "text-transform"));
|
||||
n->set_fill(get_opt_attr<color>(xml, "fill"));
|
||||
n->set_halo_fill(get_opt_attr<color>(xml, "halo-fill"));
|
||||
n->set_halo_radius(get_opt_attr<double>(xml, "halo-radius"));
|
||||
if (wrap) n->wrap_before = *wrap;
|
||||
n->wrap_char = get_opt_attr<unsigned>(xml, "wrap-character");
|
||||
n->text_transform = get_opt_attr<text_transform_e>(xml, "text-transform");
|
||||
n->fill = get_opt_attr<color>(xml, "fill");
|
||||
n->halo_fill = get_opt_attr<color>(xml, "halo-fill");
|
||||
n->halo_radius = get_opt_attr<double>(xml, "halo-radius");
|
||||
return np;
|
||||
}
|
||||
|
||||
|
@ -254,17 +244,17 @@ node_ptr format_node::from_xml(ptree const& xml)
|
|||
void format_node::apply(char_properties const& p, const Feature &feature, processed_text &output) const
|
||||
{
|
||||
char_properties new_properties = p;
|
||||
if (face_name_) new_properties.face_name = *face_name_;
|
||||
if (text_size_) new_properties.text_size = *text_size_;
|
||||
if (character_spacing_) new_properties.character_spacing = *character_spacing_;
|
||||
if (line_spacing_) new_properties.line_spacing = *line_spacing_;
|
||||
if (text_opacity_) new_properties.text_opacity = *text_opacity_;
|
||||
if (wrap_before_) new_properties.wrap_before = *wrap_before_;
|
||||
if (wrap_char_) new_properties.wrap_char = *wrap_char_;
|
||||
if (text_transform_) new_properties.text_transform = *text_transform_;
|
||||
if (fill_) new_properties.fill = *fill_;
|
||||
if (halo_fill_) new_properties.halo_fill = *halo_fill_;
|
||||
if (halo_radius_) new_properties.halo_radius = *halo_radius_;
|
||||
if (face_name) new_properties.face_name = *face_name;
|
||||
if (text_size) new_properties.text_size = *text_size;
|
||||
if (character_spacing) new_properties.character_spacing = *character_spacing;
|
||||
if (line_spacing) new_properties.line_spacing = *line_spacing;
|
||||
if (text_opacity) new_properties.text_opacity = *text_opacity;
|
||||
if (wrap_before) new_properties.wrap_before = *wrap_before;
|
||||
if (wrap_char) new_properties.wrap_char = *wrap_char;
|
||||
if (text_transform) new_properties.text_transform = *text_transform;
|
||||
if (fill) new_properties.fill = *fill;
|
||||
if (halo_fill) new_properties.halo_fill = *halo_fill;
|
||||
if (halo_radius) new_properties.halo_radius = *halo_radius;
|
||||
|
||||
if (child_) {
|
||||
child_->apply(new_properties, feature, output);
|
||||
|
@ -287,61 +277,6 @@ node_ptr format_node::get_child() const
|
|||
return child_;
|
||||
}
|
||||
|
||||
|
||||
void format_node::set_face_name(optional<std::string> face_name)
|
||||
{
|
||||
face_name_ = face_name;
|
||||
}
|
||||
|
||||
void format_node::set_text_size(optional<unsigned> text_size)
|
||||
{
|
||||
text_size_ = text_size;
|
||||
}
|
||||
|
||||
void format_node::set_character_spacing(optional<unsigned> character_spacing)
|
||||
{
|
||||
character_spacing_ = character_spacing;
|
||||
}
|
||||
|
||||
void format_node::set_line_spacing(optional<unsigned> line_spacing)
|
||||
{
|
||||
line_spacing_ = line_spacing;
|
||||
}
|
||||
|
||||
void format_node::set_text_opacity(optional<double> text_opacity)
|
||||
{
|
||||
text_opacity_ = text_opacity;
|
||||
}
|
||||
|
||||
void format_node::set_wrap_before(optional<bool> wrap_before)
|
||||
{
|
||||
wrap_before_ = wrap_before;
|
||||
}
|
||||
|
||||
void format_node::set_wrap_char(optional<unsigned> wrap_char)
|
||||
{
|
||||
wrap_char_ = wrap_char;
|
||||
}
|
||||
|
||||
void format_node::set_text_transform(optional<text_transform_e> text_transform)
|
||||
{
|
||||
text_transform_ = text_transform;
|
||||
}
|
||||
|
||||
void format_node::set_fill(optional<color> c)
|
||||
{
|
||||
fill_ = c;
|
||||
}
|
||||
|
||||
void format_node::set_halo_fill(optional<color> c)
|
||||
{
|
||||
halo_fill_ = c;
|
||||
}
|
||||
|
||||
void format_node::set_halo_radius(optional<double> radius)
|
||||
{
|
||||
halo_radius_ = radius;
|
||||
}
|
||||
} //namespace formating
|
||||
|
||||
/************************************************************/
|
||||
|
|
|
@ -34,15 +34,25 @@
|
|||
namespace mapnik
|
||||
{
|
||||
|
||||
#if BOOST_VERSION >= 104700
|
||||
wkt_parser::wkt_parser()
|
||||
: grammar_(new mapnik::wkt::wkt_collection_grammar<iterator_type>)
|
||||
{}
|
||||
|
||||
bool wkt_parser::parse(std::string const& wkt, boost::ptr_vector<geometry_type> & paths)
|
||||
{
|
||||
using namespace boost::spirit;
|
||||
iterator_type first = wkt.begin();
|
||||
iterator_type last = wkt.end();
|
||||
return qi::phrase_parse(first, last, *grammar_, ascii::space, paths);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool from_wkt(std::string const& wkt, boost::ptr_vector<geometry_type> & paths)
|
||||
{
|
||||
#if BOOST_VERSION >= 104700
|
||||
using namespace boost::spirit;
|
||||
typedef std::string::const_iterator iterator_type;
|
||||
iterator_type first = wkt.begin();
|
||||
iterator_type last = wkt.end();
|
||||
mapnik::wkt::wkt_collection_grammar<iterator_type> grammar;
|
||||
return qi::phrase_parse(first, last, grammar, ascii::space, paths);
|
||||
wkt_parser parser;
|
||||
return parser.parse(wkt,paths);
|
||||
#else
|
||||
// TODO - remove this after mapnik 2.0.0 release
|
||||
std::ostringstream s;
|
||||
|
|
|
@ -8,23 +8,18 @@ import os, mapnik
|
|||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson
|
||||
import simplejson as json
|
||||
|
||||
grid_correct = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
|
||||
|
||||
grid_correct_new = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$ %% ", " $$$ %%% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
|
||||
def resolve(grid,x,y):
|
||||
def resolve(grid,row,col):
|
||||
""" Resolve the attributes for a given pixel in a grid.
|
||||
|
||||
js version:
|
||||
https://github.com/mapbox/mbtiles-spec/blob/master/1.1/utfgrid.md
|
||||
spec:
|
||||
https://github.com/mapbox/wax/blob/master/control/lib/gridutil.js
|
||||
|
||||
"""
|
||||
utf_val = grid['grid'][x][y]
|
||||
row = grid['grid'][row]
|
||||
utf_val = row[col]
|
||||
#http://docs.python.org/library/functions.html#ord
|
||||
codepoint = ord(utf_val)
|
||||
if (codepoint >= 93):
|
||||
|
|
Loading…
Reference in a new issue