drop karma confix + solve conflicting spirit headers - closes #2323

This commit is contained in:
Dane Springmeyer 2014-07-30 13:06:08 -07:00
parent da457eba81
commit 350c2c29bd
9 changed files with 19 additions and 526 deletions

View file

@ -23,14 +23,6 @@
#ifndef MAPNIK_SVG_GENERATOR_HPP
#define MAPNIK_SVG_GENERATOR_HPP
// FIXME: workaround incompatibility of karma with -DBOOST_SPIRIT_NO_PREDEFINED_TERMINALS=1
/*
boost/spirit/repository/home/karma/directive/confix.hpp:49:23: error: no member named
'confix' in namespace 'boost::spirit::repository'
using repository::confix;
*/
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
// mapnik
#include <mapnik/ctrans.hpp>
#include <mapnik/color.hpp>

View file

@ -37,7 +37,6 @@ namespace mapnik { namespace svg {
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/karma_omit.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/repository/include/karma_confix.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/fusion/include/std_pair.hpp>
@ -103,17 +102,16 @@ struct svg_path_attributes_grammar : karma::grammar<OutputIterator, mapnik::svg:
karma::lit_type lit;
karma::double_type double_;
karma::string_type kstring;
repository::confix_type confix;
svg_path_attributes =
lit("fill=") << confix('"', '"')[kstring]
<< lit(" fill-opacity=") << confix('"', '"')[double_]
<< lit(" stroke=") << confix('"', '"')[kstring]
<< lit(" stroke-opacity=") << confix('"', '"')[double_]
<< lit(" stroke-width=") << confix('"', '"')[double_ << lit("px")]
<< lit(" stroke-linecap=") << confix('"', '"')[kstring]
<< lit(" stroke-linejoin=") << confix('"', '"')[kstring]
<< lit(" stroke-dashoffset=") << confix('"', '"')[double_ << lit("px")];
lit("fill=") << lit('"') << kstring << lit('"')
<< lit(" fill-opacity=\"") << double_ << lit('"')
<< lit(" stroke=") << kstring << lit('"')
<< lit(" stroke-opacity=") << double_ << lit('"')
<< lit(" stroke-width=") << double_ << lit("px") << lit('"')
<< lit(" stroke-linecap=") << kstring << lit('"')
<< lit(" stroke-linejoin=") << kstring << lit('"')
<< lit(" stroke-dashoffset=") << double_ << lit("px") << lit('"');
}
karma::rule<OutputIterator, mapnik::svg::path_output_attributes()> svg_path_attributes;
@ -127,12 +125,9 @@ struct svg_path_dash_array_grammar : karma::grammar<OutputIterator, mapnik::dash
{
karma::double_type double_;
karma::lit_type lit;
repository::confix_type confix;
svg_path_dash_array =
lit("stroke-dasharray=")
<< confix('"', '"')[
-((double_ << lit(',') << double_) % lit(','))];
svg_path_dash_array = lit("stroke-dasharray=") <<
-((double_ << lit(',') << double_) % lit(',')) << lit('"');
}
karma::rule<OutputIterator, mapnik::dash_array()> svg_path_dash_array;
@ -147,14 +142,13 @@ struct svg_rect_attributes_grammar : karma::grammar<OutputIterator, mapnik::svg:
karma::lit_type lit;
karma::int_type int_;
karma::string_type kstring;
repository::confix_type confix;
svg_rect_attributes =
lit("x=") << confix('"', '"')[int_]
<< lit(" y=") << confix('"', '"')[int_]
<< lit(" width=") << confix('"', '"')[int_ << lit("px")]
<< lit(" height=") << confix('"', '"')[int_ << lit("px")]
<< lit(" fill=") << confix('"', '"')[kstring];
lit("x=") << lit('"') << int_ << lit('"')
<< lit(" y=") << int_ << lit('"')
<< lit(" width=") << int_ << lit("px") << lit('"')
<< lit(" height=") << int_ << lit("px") << lit('"')
<< lit(" fill=") << kstring << lit('"');
}
karma::rule<OutputIterator, mapnik::svg::rect_output_attributes()> svg_rect_attributes;
@ -170,13 +164,12 @@ struct svg_root_attributes_grammar : karma::grammar<OutputIterator, mapnik::svg:
karma::int_type int_;
karma::string_type kstring;
karma::double_type double_;
repository::confix_type confix;
svg_root_attributes =
lit("width=") << confix('"', '"')[int_ << lit("px")]
<< lit(" height=") << confix('"', '"')[int_ << lit("px")]
<< " version=" << confix('"', '"')[double_]
<< " xmlns=" << confix('"', '"')[kstring]
lit("width=") << lit('"') << int_ << lit("px") << lit('"')
<< lit(" height=") << int_ << lit("px") << lit('"')
<< " version=" << double_ << lit('"')
<< " xmlns=" << kstring << lit('"')
<< lit(" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"");
}

View file

@ -24,7 +24,6 @@
#define MAPNIK_SVG_RENDERER_HPP
// mapnik
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#include <mapnik/config.hpp>
#include <mapnik/feature_style_processor.hpp>
#include <mapnik/font_engine_freetype.hpp>

View file

@ -1,167 +0,0 @@
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#define BOOST_TEST_MODULE background_color_test
/*
* This test module contains several generators for
* the implementation of a background color in SVG
* using a rectangle.
*/
// boost.test
#include <boost/test/included/unit_test.hpp>
// boost.spirit
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/repository/include/karma_confix.hpp>
// boost
#include <boost/fusion/tuple.hpp>
// stl
#include <string>
#include <sstream>
namespace karma = boost::spirit::karma;
namespace repository = boost::spirit::repository;
namespace fusion = boost::fusion;
using namespace karma;
struct F
{
F() :
x(0),
y(0),
width(100),
height(100),
bgcolor("#ffffff"),
expected_output("<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" style=\"fill: #ffffff\"/>") {}
~F() {}
const int x;
const int y;
const int width;
const int height;
const std::string bgcolor;
const std::string expected_output;
std::ostringstream actual_output;
};
/*
* This test case uses one compound generator to generate the SVG element.
*
* It makes only one call to the format function and uses an ostringstream
* as its output destination.
*
* The attribute values are provided as arguments to the format function.
* The disadvantage of this is that the number of arguments is limited
* by the preprocessor constant SPIRIT_ARGUMENTS_LIMIT, whose default
* value is 10. The advantage is that they can be of any type (as long
* as they are compatible with the corresponding generator type).
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
{
actual_output
<< format(
"<rect x=\"" << int_ << "\" "
<< "y=\"" << int_ << "\" "
<< "width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" "
<< "style=\"fill: " << string << "\""
<< "/>",
x, y, width, "px", height, "px", bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
* This test case uses confix to wrap each xml attribute's value
* inside double quotes.
*
* Notice that the generators' attribute list contains also tuples.
* Tuples are needed to specify each confix's attributes that contain
* more than one generator, like confix()[int_ << string] (this
* generator needs a tuple: tuple<int, string>).
*
* The difference between this generator and the one in test case
* 'bgcolor_stream_test_case' is the use of less << operators and
* a more clean handling of double quotes.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
{
using repository::confix;
using fusion::tuple;
actual_output
<< format(
"<rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]
<< "/>",
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
* This test case generates the angle brackets of the svg/xml tag
* using confix. notice that a confix generator can be part of another
* confix generator's expression.
*
* Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each
* generator is meant to have a list of attributes if it has more than one.
*
* If the generator is nested inside another generator, the former's attribute
* list will be another list (a tuple, for example) inside the latter's.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F)
{
using repository::confix;
using fusion::tuple;
actual_output
<< format(
confix('<', "/>")[
"rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
* This test case uses an iterator to receive the generated
* output. The iterator comes from the std::ostringstream that's
* been used in the previous test cases, so the output is
* actually generated into the stream.
*
* Using iterators instead of streams has the advantage that
* more advanced concepts are implemented in karma for them,
* like rules and grammars.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_iterator_test_case, F)
{
using repository::confix;
using fusion::tuple;
std::ostream_iterator<char> actual_output_iterator(actual_output);
generate(
actual_output_iterator,
confix("<", "/>")[
"rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}

View file

@ -1,57 +0,0 @@
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#define BOOST_TEST_MODULE combined_tests
// boost.test
#include <boost/test/included/unit_test.hpp>
// mapnik
#include <mapnik/map.hpp>
#include <mapnik/svg/output/svg_renderer.hpp>
#include <mapnik/color_factory.hpp>
// std
#include <string>
#include <sstream>
#include <iterator>
/**
* 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;
using svg_ren = svg_renderer<std::ostream_iterator<char> >;
Map map(800, 600);
map.set_background(parse_color("white"));
std::ostringstream output_stream;
std::ostream_iterator<char> output_stream_iterator(output_stream);
svg_ren renderer(map, output_stream_iterator);
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
+ "\">"
+"\n"
+"<rect x=\"0\" y=\"0\" width=\"800px\" height=\"600px\" style=\"fill: #ffffff\"/>"
+"\n"
+"</svg>";
std::string actual_output = output_stream.str();
BOOST_CHECK_EQUAL(actual_output, expected_output);
*/
}

View file

@ -1,37 +0,0 @@
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#define BOOST_TEST_MODULE compile_test
// boost.test
#include <boost/test/included/unit_test.hpp>
// mapnik
#include <mapnik/map.hpp>
#include <mapnik/svg/output/svg_renderer.hpp>
// std
#include <sstream>
#include <iterator>
/**
* This test is meant to see if the empty
* implementation of SVG renderer compiles
* and runs when using the inherited methods.
*/
BOOST_AUTO_TEST_CASE(compile_test_case)
{
using namespace mapnik;
Map map(800, 600);
try
{
std::ostringstream output_stream;
std::ostream_iterator<char> output_stream_iterator(output_stream);
svg_renderer<std::ostream_iterator<char> > renderer(map, output_stream_iterator);
renderer.apply();
}
catch(...)
{
BOOST_FAIL("Empty implementation throws exception.");
}
}

View file

@ -1,70 +0,0 @@
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#define BOOST_TEST_MODULE file_output_test
/*
* This test module contains test cases that
* verify the correct generation of SVG output
* using file streams as destinations.
*/
// boost.test
#include <boost/test/included/unit_test.hpp>
// boost.filesystem
#include <boost/filesystem.hpp>
// mapnik
#include <mapnik/map.hpp>
#include <mapnik/svg/output/svg_renderer.hpp>
#include <mapnik/color_factory.hpp>
// stl
#include <fstream>
#include <iterator>
namespace fs = boost::filesystem;
/*
* This test case tests the generation of an SVG document
* using a file stream. It uses svg_renderer parameterized
* with an std::ofstream as a target for output.
*
* It's important to notice that svg_renderer doesn't create
* or close the file stream, but leaves that task to the client.
*
* The test fails if the file can't be created and succeeds
* otherwise.
*
* Note: the file is created in the directory in which the
* test is run.
*/
BOOST_AUTO_TEST_CASE(file_output_test_case)
{
using namespace mapnik;
using svg_ren = svg_renderer<std::ostream_iterator<char> >;
Map map(800, 600);
map.set_background(parse_color("blue"));
std::string output_filename = "file_output_test_case.svg";
std::ofstream output_stream(output_filename.c_str());
if(output_stream)
{
std::ostream_iterator<char> output_stream_iterator(output_stream);
svg_ren renderer(map, output_stream_iterator);
renderer.apply();
output_stream.close();
fs::path output_filename_path =
fs::system_complete(fs::path(".")) / fs::path(output_filename);
BOOST_CHECK_MESSAGE(fs::exists(output_filename_path), "File '"+output_filename_path.string()+"' was created.");
}
else
{
BOOST_FAIL("Could not create create/open file '"+output_filename+"'.");
}
}

View file

@ -1,4 +1,3 @@
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#define BOOST_TEST_MODULE path_element_tests
// boost

View file

@ -1,159 +0,0 @@
#undef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
#define BOOST_TEST_MODULE root_element_test
/*
* This test module contains several generators for
* the SVG root element.
*/
// boost.test
#include <boost/test/included/unit_test.hpp>
// boost.spirit
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/repository/include/karma_confix.hpp>
// boost
#include <boost/fusion/tuple.hpp>
// stl
#include <string>
#include <sstream>
namespace karma = boost::spirit::karma;
namespace repository = boost::spirit::repository;
namespace fusion = boost::fusion;
using namespace karma;
struct F
{
F() :
width(100),
height(100),
version(1.1),
xmlns("http://www.w3.org/2000/svg"),
expected_output("<svg width=\"100px\" height=\"100px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">") {}
~F() {}
const int width;
const int height;
const float version;
const std::string xmlns;
const std::string expected_output;
std::ostringstream actual_output;
};
/*
* This test case uses one compound generator to generate the SVG element.
*
* It makes only one call to the format function and uses an ostringstream
* as its output destination.
*
* The attribute values are provided as arguments to the format function.
* The disadvantage of this is that the number of arguments is limited
* by the preprocessor constant SPIRIT_ARGUMENTS_LIMIT, whose default
* value is 10. The advantage is that they can be of any type (as long
* as they are compatible with the corresponding generator type).
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
{
actual_output
<< format(
"<svg width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" "
<< "version=\"" << float_ << "\" "
<< "xmlns=\"" << string << "\""
<< ">",
width, "px", height, "px", version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
* This test case uses confix to wrap each xml attribute's value
* inside double quotes.
*
* Notice that the generators' attribute list contains also tuples.
* Tuples are needed to specify each confix's attributes that contain
* more than one generator, like confix()[int_ << string] (this
* generator needs a tuple: tuple<int, string>).
*
* The difference between this generator and the one in test case
* 'bgcolor_stream_test_case' is the use of less << operators and
* a more clean handling of double quotes.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
{
using repository::confix;
using fusion::tuple;
actual_output
<< format(
"<svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]
<< ">",
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
* This test case generates the angle brackets of the svg/xml tag
* using confix. notice that a confix generator can be part of another
* confix generator's expression.
*
* Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each
* generator is meant to have a list of attributes if it has more than one.
*
* If the generator is nested inside another generator, the former's attribute
* list will be another list (a tuple, for example) inside the latter's.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F)
{
using repository::confix;
using fusion::tuple;
actual_output
<< format(
confix('<', ">")[
"svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]],
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
* This test case uses an iterator to receive the generated
* output. The iterator comes from the std::ostringstream that's
* been used in the previous test cases, so the output is
* actually generated into the stream.
*
* Using iterators instead of streams has the advantage that
* more advanced concepts are implemented in karma for them,
* like rules and grammars.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_iterator_test_case, F)
{
using repository::confix;
using fusion::tuple;
std::ostream_iterator<char> actual_output_iterator(actual_output);
generate(
actual_output_iterator,
confix("<", ">")[
"svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]],
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}