python: reflect fontsets to enable fuller test of map.deepcopy - closes #348

This commit is contained in:
Dane Springmeyer 2011-12-20 12:34:27 -08:00
parent dd8581bf5a
commit bbeeaada4d
5 changed files with 34 additions and 9 deletions

View file

@ -655,6 +655,7 @@ __all__ = [
'Feature',
'Featureset',
'FontEngine',
'FontSet',
'Geometry2d',
'GlyphSymbolizer',
'Image',

View file

@ -122,6 +122,7 @@ std::vector<layer> 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)
{
boost::optional<mapnik::feature_type_style const&> style = m.find_style(name);
@ -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<mapnik::font_set const&> 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"

View file

@ -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();

View file

@ -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<font_set const&> find_fontset(std::string const& name) const;
/*! \brief Get all fontsets
* @return Const reference to fontsets

View file

@ -205,13 +205,13 @@ 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<font_set const&> Map::find_fontset(std::string const& name) const
{
std::map<std::string,font_set>::const_iterator itr = fontsets_.find(name);
if (itr != fontsets_.end())
return itr->second;
static font_set default_fontset;
return default_fontset;
return boost::optional<font_set const&>(itr->second);
else
return boost::optional<font_set const&>() ;
}
std::map<std::string,font_set> const& Map::fontsets() const