Skip to content

Commit

Permalink
+ mapnik-serialize-fontset.patch from jonb
Browse files Browse the repository at this point in the history
This adds the fontset support into save_xml
 - Adds fontset_name into the text attributes
 - Adds the fontset definitions
 - glue to read fontsets from map
  • Loading branch information
artemp committed Jan 17, 2009
1 parent cad0a83 commit 387ff21
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
12 changes: 12 additions & 0 deletions include/mapnik/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace mapnik

typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator;
typedef std::map<std::string,feature_type_style>::iterator style_iterator;
typedef std::map<std::string,FontSet>::const_iterator const_fontset_iterator;
typedef std::map<std::string,FontSet>::iterator fontset_iterator;

/*! \brief Default constructor.
*
Expand Down Expand Up @@ -169,6 +171,16 @@ namespace mapnik
*/
FontSet const& find_fontset(std::string const& name) const;

/*! \brief Get all fontsets
* @return Const reference to fontsets
*/
std::map<std::string,FontSet> const& fontsets() const;

/*! \brief Get all fontsets
* @return Non-constant reference to fontsets
*/
std::map<std::string,FontSet> & fontsets();

/*! \brief Get number of all layers.
*/
size_t layerCount() const;
Expand Down
2 changes: 1 addition & 1 deletion src/font_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace mapnik
{
FontSet::FontSet()
: name_("default") {}
: name_("") {}

FontSet::FontSet(std::string const& name)
: name_(name) {}
Expand Down
10 changes: 10 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ namespace mapnik
return default_fontset;
}

std::map<std::string,FontSet> const& Map::fontsets() const
{
return fontsets_;
}

std::map<std::string,FontSet> & Map::fontsets()
{
return fontsets_;
}

boost::optional<feature_type_style const&> Map::find_style(std::string const& name) const
{
std::map<std::string,feature_type_style>::const_iterator itr = styles_.find(name);
Expand Down
36 changes: 35 additions & 1 deletion src/save_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ namespace mapnik
if ( ! face_name.empty() ) {
set_attr( node, "face_name", face_name );
}

const std::string & fontset_name = sym.get_fontset().get_name();
if ( ! fontset_name.empty() ) {
set_attr( node, "fontset_name", fontset_name );
}

set_attr( node, "size", sym.get_text_size() );
set_attr( node, "fill", sym.get_fill() );

Expand Down Expand Up @@ -344,6 +348,27 @@ namespace mapnik

}

void serialize_fontset( ptree & map_node, Map::const_fontset_iterator fontset_it )
{
const FontSet & fontset = fontset_it->second;
const std::string & name = fontset_it->first;

ptree & fontset_node = map_node.push_back(
ptree::value_type("FontSet", ptree()))->second;

set_attr(fontset_node, "name", name);

std::vector<std::string>::const_iterator it = fontset.get_face_names().begin();
std::vector<std::string>::const_iterator end = fontset.get_face_names().end();
for (; it != end; ++it)
{
ptree & font_node = fontset_node.push_back(
ptree::value_type("Font", ptree()))->second;
set_attr(font_node, "face_name", *it);
}

}

void serialize_datasource( ptree & layer_node, datasource_ptr datasource)
{
ptree & datasource_node = layer_node.push_back(
Expand Down Expand Up @@ -434,6 +459,15 @@ namespace mapnik
set_attr( map_node, "bgcolor", * c );
}

{
Map::const_fontset_iterator it = map.fontsets().begin();
Map::const_fontset_iterator end = map.fontsets().end();
for (; it != end; ++it)
{
serialize_fontset( map_node, it);
}
}

Map::const_style_iterator it = map.styles().begin();
Map::const_style_iterator end = map.styles().end();
for (; it != end; ++it)
Expand Down

0 comments on commit 387ff21

Please sign in to comment.