Added generation of SVG root element with width and height attributes. Also added test for testing the output generated by svg_renderer (combined_test.cpp).
This commit is contained in:
parent
1b535430cb
commit
bb44d76ee1
3 changed files with 101 additions and 9 deletions
|
@ -94,13 +94,19 @@ namespace mapnik
|
||||||
return output_stream_;
|
return output_stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// constant variable that stores the xml declaration.
|
// XML declaration.
|
||||||
static const std::string XML_DECLARATION;
|
static const std::string XML_DECLARATION;
|
||||||
// constant variable that stores the dtd urls.
|
// DTD urls.
|
||||||
static const std::string SVG_DTD;
|
static const std::string SVG_DTD;
|
||||||
|
// SVG version to which the generated document will be compliant.
|
||||||
|
static const double SVG_VERSION;
|
||||||
|
// SVG XML namespace url.
|
||||||
|
static const std::string SVG_NAMESPACE_URL;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T& output_stream_;
|
T& output_stream_;
|
||||||
|
const int width_;
|
||||||
|
const int height_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,11 @@
|
||||||
|
|
||||||
// boost.spirit
|
// boost.spirit
|
||||||
#include <boost/spirit/include/karma.hpp>
|
#include <boost/spirit/include/karma.hpp>
|
||||||
#include <boost/spirit/include/karma_string.hpp>
|
#include <boost/spirit/repository/include/karma_confix.hpp>
|
||||||
|
|
||||||
namespace karma = boost::spirit::karma;
|
namespace karma = boost::spirit::karma;
|
||||||
|
namespace repository = boost::spirit::repository;
|
||||||
|
namespace ascii = karma::ascii;
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
|
@ -48,10 +50,21 @@ namespace mapnik
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const std::string svg_renderer<T>::SVG_DTD = "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">";
|
const std::string svg_renderer<T>::SVG_DTD = "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* I'm not sure if these values should be stored or directly put inside
|
||||||
|
* a generator expression.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
const double svg_renderer<T>::SVG_VERSION = 1.1;
|
||||||
|
template <typename T>
|
||||||
|
const std::string svg_renderer<T>::SVG_NAMESPACE_URL = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
svg_renderer<T>::svg_renderer(Map const& m, T & output_stream) :
|
svg_renderer<T>::svg_renderer(Map const& m, T & output_stream) :
|
||||||
feature_style_processor<svg_renderer>(m),
|
feature_style_processor<svg_renderer>(m),
|
||||||
output_stream_(output_stream)
|
output_stream_(output_stream),
|
||||||
|
width_(m.width()),
|
||||||
|
height_(m.height())
|
||||||
{
|
{
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
@ -59,8 +72,6 @@ namespace mapnik
|
||||||
template <typename T>
|
template <typename T>
|
||||||
svg_renderer<T>::~svg_renderer() {}
|
svg_renderer<T>::~svg_renderer() {}
|
||||||
|
|
||||||
// only empty methods for now.
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void svg_renderer<T>::start_map_processing(Map const& map)
|
void svg_renderer<T>::start_map_processing(Map const& map)
|
||||||
{
|
{
|
||||||
|
@ -68,17 +79,44 @@ namespace mapnik
|
||||||
std::clog << "start map processing" << std::endl;
|
std::clog << "start map processing" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
output_stream_ << karma::format(karma::lit(XML_DECLARATION) << karma::eol << karma::lit(SVG_DTD), "");
|
using repository::confix;
|
||||||
|
using karma::format;
|
||||||
|
using karma::lit;
|
||||||
|
using karma::eol;
|
||||||
|
using karma::int_;
|
||||||
|
using karma::double_;
|
||||||
|
using ascii::string;
|
||||||
|
using ascii::space;
|
||||||
|
|
||||||
|
// should I move these lines to the constructor?
|
||||||
|
|
||||||
|
// generate XML header.
|
||||||
|
output_stream_ << format(lit(XML_DECLARATION) << eol << lit(SVG_DTD) << eol);
|
||||||
|
|
||||||
|
// generate SVG root element opening tag.
|
||||||
|
output_stream_
|
||||||
|
<< format(
|
||||||
|
confix("<svg width=\"", "\"")[int_ << string],
|
||||||
|
width_, "px")
|
||||||
|
<< format(
|
||||||
|
confix(" height=\"", "\"")[int_ << string],
|
||||||
|
height_, "px")
|
||||||
|
<< format(
|
||||||
|
confix(" version=\"", "\"")[double_],
|
||||||
|
SVG_VERSION)
|
||||||
|
<< format(
|
||||||
|
confix(" xmlns=\"", "\">")[string],
|
||||||
|
SVG_NAMESPACE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void svg_renderer<T>::end_map_processing(Map const& map)
|
void svg_renderer<T>::end_map_processing(Map const& map)
|
||||||
{
|
{
|
||||||
// nothing yet.
|
|
||||||
|
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
std::clog << "end map processing" << std::endl;
|
std::clog << "end map processing" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// generate SVG root element closing tag.
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
48
tests/cpp_tests/svg_renderer_tests/combined_test.cpp
Normal file
48
tests/cpp_tests/svg_renderer_tests/combined_test.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#define BOOST_TEST_MODULE combined_tests
|
||||||
|
|
||||||
|
// boost.test
|
||||||
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
|
||||||
|
// mapnik
|
||||||
|
#include <mapnik/map.hpp>
|
||||||
|
#include <mapnik/svg_renderer.hpp>
|
||||||
|
|
||||||
|
// std
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test case tests all the generators inside svg_renderer,
|
||||||
|
* verifying the correctness of the whole SVG document.
|
||||||
|
*
|
||||||
|
* The test sets the svg_renderer object with a simple Map that
|
||||||
|
* has only its dimensions specified and calls the apply()
|
||||||
|
* method to produce the output.
|
||||||
|
*
|
||||||
|
* The output stream is a stringstream (the output is generated
|
||||||
|
* into a stringstream).
|
||||||
|
*/
|
||||||
|
BOOST_AUTO_TEST_CASE(combined_test_case)
|
||||||
|
{
|
||||||
|
using namespace mapnik;
|
||||||
|
typedef svg_renderer<std::stringstream> svg_ren;
|
||||||
|
|
||||||
|
Map map(800, 600);
|
||||||
|
|
||||||
|
std::stringstream output_stream;
|
||||||
|
svg_ren renderer(map, output_stream);
|
||||||
|
renderer.apply();
|
||||||
|
|
||||||
|
std::string expected_output =
|
||||||
|
svg_ren::XML_DECLARATION
|
||||||
|
+ "\n"
|
||||||
|
+ svg_ren::SVG_DTD
|
||||||
|
+ "\n"
|
||||||
|
+ "<svg width=\"800px\" height=\"600px\" version=\"1.1\" xmlns=\""
|
||||||
|
+ svg_ren::SVG_NAMESPACE_URL
|
||||||
|
+ "\">";
|
||||||
|
|
||||||
|
std::string actual_output = renderer.get_output_stream().str();
|
||||||
|
BOOST_CHECK_EQUAL(actual_output, expected_output);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue