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 0f0e04e6dc
commit d7c720f0af
5 changed files with 34 additions and 9 deletions

View file

@ -655,6 +655,7 @@ __all__ = [
'Feature', 'Feature',
'Featureset', 'Featureset',
'FontEngine', 'FontEngine',
'FontSet',
'Geometry2d', 'Geometry2d',
'GlyphSymbolizer', 'GlyphSymbolizer',
'Image', '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::*attr_nonconst)() = &Map::get_extra_attributes;
mapnik::parameters& (Map::*params_nonconst)() = &Map::get_extra_parameters; 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<mapnik::feature_type_style const&> style = m.find_style(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; 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) bool has_metawriter(mapnik::Map const& m)
{ {
if (m.metawriters().size() >=1) if (m.metawriters().size() >=1)
@ -239,6 +251,11 @@ void export_map()
"False # you can only append styles with unique names\n" "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", .def("buffered_envelope",
&Map::get_buffered_extent, &Map::get_buffered_extent,
"Get the Box2d() of the Map given\n" "Get the Box2d() of the Map given\n"
@ -271,9 +288,14 @@ void export_map()
"...'maxy', 'minx', 'miny', 'width'\n" "...'maxy', 'minx', 'miny', 'width'\n"
) )
.def("find_fontset",find_fontset,
(arg("name")),
"Find a fontset by name."
)
.def("find_style", .def("find_style",
find_style, find_style,
(arg("style_name")), (arg("name")),
"Query the Map for a style by name and return\n" "Query the Map for a style by name and return\n"
"a style object if found or raise KeyError\n" "a style object if found or raise KeyError\n"
"style if not found.\n" "style if not found.\n"

View file

@ -47,6 +47,7 @@ void export_style();
void export_stroke(); void export_stroke();
void export_feature(); void export_feature();
void export_featureset(); void export_featureset();
void export_fontset();
void export_datasource(); void export_datasource();
void export_datasource_cache(); void export_datasource_cache();
void export_symbolizer(); void export_symbolizer();
@ -397,6 +398,7 @@ BOOST_PYTHON_MODULE(_mapnik)
export_geometry(); export_geometry();
export_feature(); export_feature();
export_featureset(); export_featureset();
export_fontset();
export_datasource(); export_datasource();
export_parameters(); export_parameters();
export_color(); export_color();

View file

@ -218,7 +218,7 @@ public:
* @param name The name of the fontset. * @param name The name of the fontset.
* @return The fontset if found. If not found return the default map 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 /*! \brief Get all fontsets
* @return Const reference to 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; 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); std::map<std::string,font_set>::const_iterator itr = fontsets_.find(name);
if (itr != fontsets_.end()) if (itr != fontsets_.end())
return itr->second; return boost::optional<font_set const&>(itr->second);
static font_set default_fontset; else
return default_fontset; return boost::optional<font_set const&>() ;
} }
std::map<std::string,font_set> const& Map::fontsets() const std::map<std::string,font_set> const& Map::fontsets() const