From ffb6db7b4d0920d57a01d1dfa6a8ac5288dd0eab Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 4 May 2021 15:07:32 +0100 Subject: [PATCH] CSS color: relax grammar to allow floating point percentages and mixed case e.g 'rGB' names --- .../mapnik/css/css_color_grammar_x3_def.hpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/include/mapnik/css/css_color_grammar_x3_def.hpp b/include/mapnik/css/css_color_grammar_x3_def.hpp index e42c02470..998219b19 100644 --- a/include/mapnik/css/css_color_grammar_x3_def.hpp +++ b/include/mapnik/css/css_color_grammar_x3_def.hpp @@ -52,6 +52,7 @@ namespace x3 = boost::spirit::x3; namespace css_color_grammar { using x3::lit; +using x3::float_; using x3::uint_parser; using x3::hex; using x3::symbols; @@ -223,6 +224,7 @@ x3::uint_parser hex2; x3::uint_parser hex1; x3::uint_parser dec3; + // rules x3::rule const hex2_color("hex2_color"); x3::rule const hex1_color("hex1_color"); @@ -367,32 +369,32 @@ auto const hex1_color_def = no_skip[lit('#') >> hex1[hex1_blue] >> (hex1[hex1_opacity] | attr(15)[hex1_opacity])]; -auto const rgb_color_def = lit("rgb") +auto const rgb_color_def = no_case["rgb"] >> lit('(') >> dec3[dec_red] >> lit(',') >> dec3[dec_green] >> lit(',') >> dec3[dec_blue] >> attr(255) >> lit(')'); -auto const rgb_color_percent_def = lit("rgb") - >> lit('(') >> dec3[percent_red] >> lit('%') - >> lit(',') >> dec3[percent_green] >> lit('%') - >> lit(',') >> dec3[percent_blue] >> lit('%') +auto const rgb_color_percent_def = no_case["rgb"] + >> lit('(') >> float_[percent_red] >> lit('%') + >> lit(',') >> float_[percent_green] >> lit('%') + >> lit(',') >> float_[percent_blue] >> lit('%') >> attr(255) >> lit(')'); -auto const rgba_color_def = lit("rgba") +auto const rgba_color_def = no_case["rgba"] >> lit('(') >> dec3[dec_red] >> lit(',') >> dec3[dec_green] >> lit(',') >> dec3[dec_blue] >> lit(',') >> double_[opacity] >> lit(')'); -auto const rgba_color_percent_def = lit("rgba") - >> lit('(') >> dec3[percent_red] >> lit('%') - >> lit(',') >> dec3[percent_green] >> lit('%') - >> lit(',') >> dec3[percent_blue] >> lit('%') +auto const rgba_color_percent_def = no_case["rgba"] + >> lit('(') >> float_[percent_red] >> lit('%') + >> lit(',') >> float_[percent_green] >> lit('%') + >> lit(',') >> float_[percent_blue] >> lit('%') >> lit(',') >> double_[opacity] >> lit(')'); auto const hsl_values = x3::rule> {} = - lit("hsl") + no_case["hsl"] >> lit('(') >> dec3 >> lit(',') >> dec3 >> lit('%') >> lit(',') >> dec3 >> lit('%') @@ -400,7 +402,7 @@ auto const hsl_values = x3::rule> {} = - lit("hsla") + no_case["hsla"] >> lit('(') >> dec3 >> lit(',') >> dec3 >> lit('%') >> lit(',') >> dec3 >> lit('%')