From 209af16763a251f1fcd2e995600ad908df6604d3 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 15 Dec 2015 15:16:18 +0000 Subject: [PATCH] rename SVG2 back to CSS as it's a better fit --- ...mmar_def.hpp => css_color_grammar_def.hpp} | 16 ++++---- src/color_factory.cpp | 4 +- test/unit/color/css_color.cpp | 38 ++++--------------- 3 files changed, 18 insertions(+), 40 deletions(-) rename include/mapnik/{svg2_color_grammar_def.hpp => css_color_grammar_def.hpp} (97%) diff --git a/include/mapnik/svg2_color_grammar_def.hpp b/include/mapnik/css_color_grammar_def.hpp similarity index 97% rename from include/mapnik/svg2_color_grammar_def.hpp rename to include/mapnik/css_color_grammar_def.hpp index a866cd1a8..216a97909 100644 --- a/include/mapnik/svg2_color_grammar_def.hpp +++ b/include/mapnik/css_color_grammar_def.hpp @@ -22,8 +22,8 @@ // http://www.w3.org/TR/SVG2/color.html -#ifndef MAPNIK_SVG2_COLOR_GRAMMAR_DEF_HPP -#define MAPNIK_SVG2_COLOR_GRAMMAR_DEF_HPP +#ifndef MAPNIK_CSS_COLOR_GRAMMAR_DEF_HPP +#define MAPNIK_CSS_COLOR_GRAMMAR_DEF_HPP #include #include @@ -48,7 +48,7 @@ namespace mapnik { namespace x3 = boost::spirit::x3; -namespace svg2_color_grammar { +namespace css_color_grammar { using x3::lit; using x3::uint_parser; @@ -220,7 +220,7 @@ x3::uint_parser hex2; x3::uint_parser hex1; x3::uint_parser dec3; -x3::rule const svg2_color("svg2_color"); +x3::rule const css_color("css_color"); x3::rule const hex2_color("hex2_color"); x3::rule const hex1_color("hex1_color"); x3::rule const rgb_color("rgb_color"); @@ -383,7 +383,7 @@ auto const hsla_values = x3::rule {} = hsl_values[hsl_to_rgba]; auto const hsla_color = x3::rule {} = hsla_values[hsl_to_rgba]; -auto const svg2_color_def = +auto const css_color_def = no_case[named_colors] | hex2_color @@ -406,7 +406,7 @@ auto const svg2_color_def = #pragma GCC diagnostic push #include BOOST_SPIRIT_DEFINE( - svg2_color, + css_color, hex2_color, hex1_color, rgb_color, @@ -416,9 +416,9 @@ BOOST_SPIRIT_DEFINE( ); #pragma GCC diagnostic pop -auto const expression = svg2_color; +auto const expression = css_color; }} -#endif //MAPNIK_SVG2_COLOR_GRAMMAR_DEF_HPP +#endif //MAPNIK_CSS_COLOR_GRAMMAR_DEF_HPP diff --git a/src/color_factory.cpp b/src/color_factory.cpp index a16ebed42..ae24facfd 100644 --- a/src/color_factory.cpp +++ b/src/color_factory.cpp @@ -24,13 +24,13 @@ #include #include #include -#include +#include namespace mapnik { color parse_color(std::string const& str) { // TODO - early return for @color? - auto const& grammar = mapnik::svg2_color_grammar::expression; + auto const& grammar = mapnik::css_color_grammar::expression; color c; std::string::const_iterator first = str.begin(); std::string::const_iterator last = str.end(); diff --git a/test/unit/color/css_color.cpp b/test/unit/color/css_color.cpp index 839104d4d..958f5e2f6 100644 --- a/test/unit/color/css_color.cpp +++ b/test/unit/color/css_color.cpp @@ -2,46 +2,24 @@ #include #include -#include +#include -TEST_CASE("SVG2 color") { +TEST_CASE("CSS color") { SECTION("conversions") { - using namespace mapnik::svg2_color_grammar; + using namespace mapnik::css_color_grammar; CHECK( percent_converter::call(1.0) == 3 ); CHECK( percent_converter::call(60.0) == 153 ); // should not overflow on invalid input - CHECK( mapnik::svg2_color_grammar::percent_converter::call(100000.0) == 255 ); - CHECK( mapnik::svg2_color_grammar::percent_converter::call(-100000.0) == 0 ); - -#if 0 - CHECK( opacity(0.5) == 128 ); - CHECK( opacity(1.0) == 255 ); - // should not overflow on invalid input - CHECK( opacity(60.0) == 255 ); - CHECK( opacity(100000.0) == 255 ); - CHECK( opacity(-100000.0) == 0 ); - mapnik::hsl_conv_impl conv3; - mapnik::color c; - conv3(c, 1.0, 1.0, 1.0); - CHECK( c.alpha() == 255 ); - CHECK( c.red() == 3 ); - CHECK( c.green() == 3 ); - CHECK( c.blue() == 3 ); - // invalid - conv3(c, -1, -1, -1); - CHECK( c.alpha() == 255 ); // should not be touched by hsl converter - CHECK( c.red() == 0 ); - CHECK( c.green() == 0 ); - CHECK( c.blue() == 0 ); -#endif + CHECK( percent_converter::call(100000.0) == 255 ); + CHECK( percent_converter::call(-100000.0) == 0 ); } - SECTION("SVG2 colors") + SECTION("CSS colors") { - auto const& color_grammar = mapnik::svg2_color_grammar::expression; + auto const& color_grammar = mapnik::css_color_grammar::expression; boost::spirit::x3::ascii::space_type space; { // rgb @@ -103,7 +81,7 @@ TEST_CASE("SVG2 color") { CHECK( c.green() == 64 ); CHECK( c.blue() == 191 ); } - // hslaza + // hsla { std::string s("hsla(240,50%,50%,0.5)"); mapnik::color c;