diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 49744a53e..cbddbd74e 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -655,6 +655,7 @@ __all__ = [ 'Feature', 'Featureset', 'FontEngine', + 'FontSet', 'Geometry2d', 'GlyphSymbolizer', 'Image', diff --git a/bindings/python/mapnik_map.cpp b/bindings/python/mapnik_map.cpp index 86a16d568..a947eeef8 100644 --- a/bindings/python/mapnik_map.cpp +++ b/bindings/python/mapnik_map.cpp @@ -122,7 +122,8 @@ std::vector const& (Map::*layers_const)() const = &Map::layers; mapnik::parameters& (Map::*attr_nonconst)() = &Map::get_extra_attributes; mapnik::parameters& (Map::*params_nonconst)() = &Map::get_extra_parameters; -mapnik::feature_type_style find_style (mapnik::Map const& m, std::string const& name) + +mapnik::feature_type_style find_style(mapnik::Map const& m, std::string const& name) { boost::optional style = m.find_style(name); if (!style) @@ -133,6 +134,17 @@ mapnik::feature_type_style find_style (mapnik::Map const& m, std::string const& return *style; } +mapnik::font_set find_fontset(mapnik::Map const& m, std::string const& name) +{ + boost::optional fontset = m.find_fontset(name); + if (!fontset) + { + PyErr_SetString(PyExc_KeyError, "Invalid font_set name"); + boost::python::throw_error_already_set(); + } + return *fontset; +} + bool has_metawriter(mapnik::Map const& m) { if (m.metawriters().size() >=1) @@ -239,6 +251,11 @@ void export_map() "False # you can only append styles with unique names\n" ) + .def("append_fontset",&Map::insert_fontset, + (arg("fontset")), + "Add a FontSet to the map." + ) + .def("buffered_envelope", &Map::get_buffered_extent, "Get the Box2d() of the Map given\n" @@ -271,9 +288,14 @@ void export_map() "...'maxy', 'minx', 'miny', 'width'\n" ) + .def("find_fontset",find_fontset, + (arg("name")), + "Find a fontset by name." + ) + .def("find_style", find_style, - (arg("style_name")), + (arg("name")), "Query the Map for a style by name and return\n" "a style object if found or raise KeyError\n" "style if not found.\n" diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 768bb6686..52b846a8d 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -47,6 +47,7 @@ void export_style(); void export_stroke(); void export_feature(); void export_featureset(); +void export_fontset(); void export_datasource(); void export_datasource_cache(); void export_symbolizer(); @@ -397,6 +398,7 @@ BOOST_PYTHON_MODULE(_mapnik) export_geometry(); export_feature(); export_featureset(); + export_fontset(); export_datasource(); export_parameters(); export_color(); diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index bbc5d9432..3e24b540b 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -218,7 +218,7 @@ public: * @param name The name of the fontset. * @return The fontset if found. If not found return the default map fontset. */ - font_set const& find_fontset(std::string const& name) const; + boost::optional find_fontset(std::string const& name) const; /*! \brief Get all fontsets * @return Const reference to fontsets diff --git a/src/map.cpp b/src/map.cpp index 4b7af5513..e421998b8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -204,14 +204,14 @@ bool Map::insert_fontset(std::string const& name, font_set const& fontset) { return fontsets_.insert(make_pair(name, fontset)).second; } - -font_set const& Map::find_fontset(std::string const& name) const + +boost::optional Map::find_fontset(std::string const& name) const { std::map::const_iterator itr = fontsets_.find(name); - if (itr!=fontsets_.end()) - return itr->second; - static font_set default_fontset; - return default_fontset; + if (itr != fontsets_.end()) + return boost::optional(itr->second); + else + return boost::optional() ; } std::map const& Map::fontsets() const