From 387ff213ef4472d292feb935462514783efdcf55 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Sat, 17 Jan 2009 20:18:41 +0000 Subject: [PATCH] + mapnik-serialize-fontset.patch from jonb 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 --- include/mapnik/map.hpp | 12 ++++++++++++ src/font_set.cpp | 2 +- src/map.cpp | 10 ++++++++++ src/save_map.cpp | 36 +++++++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index eed579595..355226f1b 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -76,6 +76,8 @@ namespace mapnik typedef std::map::const_iterator const_style_iterator; typedef std::map::iterator style_iterator; + typedef std::map::const_iterator const_fontset_iterator; + typedef std::map::iterator fontset_iterator; /*! \brief Default constructor. * @@ -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 const& fontsets() const; + + /*! \brief Get all fontsets + * @return Non-constant reference to fontsets + */ + std::map & fontsets(); + /*! \brief Get number of all layers. */ size_t layerCount() const; diff --git a/src/font_set.cpp b/src/font_set.cpp index 4a3efff99..3a145111e 100644 --- a/src/font_set.cpp +++ b/src/font_set.cpp @@ -31,7 +31,7 @@ namespace mapnik { FontSet::FontSet() - : name_("default") {} + : name_("") {} FontSet::FontSet(std::string const& name) : name_(name) {} diff --git a/src/map.cpp b/src/map.cpp index 2f1502a13..9034990d5 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -125,6 +125,16 @@ namespace mapnik return default_fontset; } + std::map const& Map::fontsets() const + { + return fontsets_; + } + + std::map & Map::fontsets() + { + return fontsets_; + } + boost::optional Map::find_style(std::string const& name) const { std::map::const_iterator itr = styles_.find(name); diff --git a/src/save_map.cpp b/src/save_map.cpp index ded012825..4ad651431 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -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() ); @@ -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::const_iterator it = fontset.get_face_names().begin(); + std::vector::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( @@ -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)