rename SVG2 back to CSS as it's a better fit

This commit is contained in:
artemp 2015-12-15 15:16:18 +00:00
parent 6e5a67c1fb
commit 209af16763
3 changed files with 18 additions and 40 deletions

View file

@ -22,8 +22,8 @@
// http://www.w3.org/TR/SVG2/color.html // http://www.w3.org/TR/SVG2/color.html
#ifndef MAPNIK_SVG2_COLOR_GRAMMAR_DEF_HPP #ifndef MAPNIK_CSS_COLOR_GRAMMAR_DEF_HPP
#define MAPNIK_SVG2_COLOR_GRAMMAR_DEF_HPP #define MAPNIK_CSS_COLOR_GRAMMAR_DEF_HPP
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/util/hsl.hpp> #include <mapnik/util/hsl.hpp>
@ -48,7 +48,7 @@ namespace mapnik {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace svg2_color_grammar { namespace css_color_grammar {
using x3::lit; using x3::lit;
using x3::uint_parser; using x3::uint_parser;
@ -220,7 +220,7 @@ x3::uint_parser<std::uint8_t, 16, 2, 2> hex2;
x3::uint_parser<std::uint8_t, 16, 1, 1> hex1; x3::uint_parser<std::uint8_t, 16, 1, 1> hex1;
x3::uint_parser<std::uint8_t, 10, 1, 3> dec3; x3::uint_parser<std::uint8_t, 10, 1, 3> dec3;
x3::rule<class svg2_color, color> const svg2_color("svg2_color"); x3::rule<class css_color, color> const css_color("css_color");
x3::rule<class hex2_color, color> const hex2_color("hex2_color"); x3::rule<class hex2_color, color> const hex2_color("hex2_color");
x3::rule<class hex1_color, color> const hex1_color("hex1_color"); x3::rule<class hex1_color, color> const hex1_color("hex1_color");
x3::rule<class rgb_color, color> const rgb_color("rgb_color"); x3::rule<class rgb_color, color> const rgb_color("rgb_color");
@ -383,7 +383,7 @@ auto const hsla_values = x3::rule<class hsla_values, std::tuple<std::uint8_t,std
auto const hsl_color = x3::rule<class hsl_color, color> {} = hsl_values[hsl_to_rgba]; auto const hsl_color = x3::rule<class hsl_color, color> {} = hsl_values[hsl_to_rgba];
auto const hsla_color = x3::rule<class hsla_color, color> {} = hsla_values[hsl_to_rgba]; auto const hsla_color = x3::rule<class hsla_color, color> {} = hsla_values[hsl_to_rgba];
auto const svg2_color_def = auto const css_color_def =
no_case[named_colors] no_case[named_colors]
| |
hex2_color hex2_color
@ -406,7 +406,7 @@ auto const svg2_color_def =
#pragma GCC diagnostic push #pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
BOOST_SPIRIT_DEFINE( BOOST_SPIRIT_DEFINE(
svg2_color, css_color,
hex2_color, hex2_color,
hex1_color, hex1_color,
rgb_color, rgb_color,
@ -416,9 +416,9 @@ BOOST_SPIRIT_DEFINE(
); );
#pragma GCC diagnostic pop #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

View file

@ -24,13 +24,13 @@
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/color_factory.hpp> #include <mapnik/color_factory.hpp>
#include <mapnik/config_error.hpp> #include <mapnik/config_error.hpp>
#include <mapnik/svg2_color_grammar_def.hpp> #include <mapnik/css_color_grammar_def.hpp>
namespace mapnik { namespace mapnik {
color parse_color(std::string const& str) color parse_color(std::string const& str)
{ {
// TODO - early return for @color? // TODO - early return for @color?
auto const& grammar = mapnik::svg2_color_grammar::expression; auto const& grammar = mapnik::css_color_grammar::expression;
color c; color c;
std::string::const_iterator first = str.begin(); std::string::const_iterator first = str.begin();
std::string::const_iterator last = str.end(); std::string::const_iterator last = str.end();

View file

@ -2,46 +2,24 @@
#include <mapnik/safe_cast.hpp> #include <mapnik/safe_cast.hpp>
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/svg2_color_grammar_def.hpp> #include <mapnik/css_color_grammar_def.hpp>
TEST_CASE("SVG2 color") { TEST_CASE("CSS color") {
SECTION("conversions") 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(1.0) == 3 );
CHECK( percent_converter::call(60.0) == 153 ); CHECK( percent_converter::call(60.0) == 153 );
// should not overflow on invalid input // should not overflow on invalid input
CHECK( mapnik::svg2_color_grammar::percent_converter::call(100000.0) == 255 ); CHECK( percent_converter::call(100000.0) == 255 );
CHECK( mapnik::svg2_color_grammar::percent_converter::call(-100000.0) == 0 ); CHECK( 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
} }
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; boost::spirit::x3::ascii::space_type space;
{ {
// rgb // rgb
@ -103,7 +81,7 @@ TEST_CASE("SVG2 color") {
CHECK( c.green() == 64 ); CHECK( c.green() == 64 );
CHECK( c.blue() == 191 ); CHECK( c.blue() == 191 );
} }
// hslaza // hsla
{ {
std::string s("hsla(240,50%,50%,0.5)"); std::string s("hsla(240,50%,50%,0.5)");
mapnik::color c; mapnik::color c;