diff --git a/include/mapnik/svg_renderer.hpp b/include/mapnik/svg_renderer.hpp index 851e44151..70ce4db1a 100644 --- a/include/mapnik/svg_renderer.hpp +++ b/include/mapnik/svg_renderer.hpp @@ -94,13 +94,19 @@ namespace mapnik return output_stream_; } - // constant variable that stores the xml declaration. + // XML declaration. static const std::string XML_DECLARATION; - // constant variable that stores the dtd urls. + // DTD urls. 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: T& output_stream_; + const int width_; + const int height_; }; } diff --git a/src/svg/svg_renderer.cpp b/src/svg/svg_renderer.cpp index 8798acc30..cf2077527 100644 --- a/src/svg/svg_renderer.cpp +++ b/src/svg/svg_renderer.cpp @@ -32,9 +32,11 @@ // boost.spirit #include -#include +#include namespace karma = boost::spirit::karma; +namespace repository = boost::spirit::repository; +namespace ascii = karma::ascii; namespace mapnik { @@ -48,10 +50,21 @@ namespace mapnik template const std::string svg_renderer::SVG_DTD = ""; + /* + * I'm not sure if these values should be stored or directly put inside + * a generator expression. + */ + template + const double svg_renderer::SVG_VERSION = 1.1; + template + const std::string svg_renderer::SVG_NAMESPACE_URL = "http://www.w3.org/2000/svg"; + template svg_renderer::svg_renderer(Map const& m, T & output_stream) : feature_style_processor(m), - output_stream_(output_stream) + output_stream_(output_stream), + width_(m.width()), + height_(m.height()) { // nothing yet. } @@ -59,8 +72,6 @@ namespace mapnik template svg_renderer::~svg_renderer() {} - // only empty methods for now. - template void svg_renderer::start_map_processing(Map const& map) { @@ -68,17 +79,44 @@ namespace mapnik std::clog << "start map processing" << std::endl; #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("")[string], + SVG_NAMESPACE_URL); } template void svg_renderer::end_map_processing(Map const& map) { - // nothing yet. - #ifdef MAPNIK_DEBUG std::clog << "end map processing" << std::endl; #endif + + // generate SVG root element closing tag. } template diff --git a/tests/cpp_tests/svg_renderer_tests/combined_test.cpp b/tests/cpp_tests/svg_renderer_tests/combined_test.cpp new file mode 100644 index 000000000..d4c10fc3e --- /dev/null +++ b/tests/cpp_tests/svg_renderer_tests/combined_test.cpp @@ -0,0 +1,48 @@ +#define BOOST_TEST_MODULE combined_tests + +// boost.test +#include + +// mapnik +#include +#include + +// std +#include +#include + +/** + * 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 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" + + ""; + + std::string actual_output = renderer.get_output_stream().str(); + BOOST_CHECK_EQUAL(actual_output, expected_output); +} +