From 93ab8b46900aa6b398d2592be960f1a21fcc68b1 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 12 Apr 2024 14:19:26 +0100 Subject: [PATCH 1/3] Fix compiler warning - `definition of implicit copy constructor for 'enumeration' is deprecated because it has a user-provided copy assignment operator [-Wdeprecated-copy-with-user-provided-copy] void operator=(const enumeration& other) { value_ = other.value_; }` --- include/mapnik/enumeration.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/mapnik/enumeration.hpp b/include/mapnik/enumeration.hpp index c9453a673..d5b08736e 100644 --- a/include/mapnik/enumeration.hpp +++ b/include/mapnik/enumeration.hpp @@ -149,9 +149,7 @@ struct MAPNIK_DECL enumeration { using native_type = ENUM; constexpr operator ENUM() const { return value_; } - // constexpr bool operator==(const enumeration_new& rhs) { return value_ == rhs.value_; } void operator=(ENUM v) { value_ = v; } - void operator=(const enumeration& other) { value_ = other.value_; } enumeration() : value_() From 5ac45af78e708ffa7332d475f07f09764fcb2eb0 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 15 Apr 2024 14:09:04 +0100 Subject: [PATCH 2/3] Allow percentage values with a fractional component (implements https://github.com/mapnik/mapnik/issues/4437) (https://www.w3.org/TR/css-color-4/#funcdef-rgba) --- .../mapnik/css/css_color_grammar_x3_def.hpp | 24 +++++----- test/unit/color/css_color.cpp | 45 +++++++++++++++++-- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/include/mapnik/css/css_color_grammar_x3_def.hpp b/include/mapnik/css/css_color_grammar_x3_def.hpp index eec9abae3..c52d20c59 100644 --- a/include/mapnik/css/css_color_grammar_x3_def.hpp +++ b/include/mapnik/css/css_color_grammar_x3_def.hpp @@ -352,9 +352,9 @@ auto const rgb_color_def = lit("rgb") >> 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('%') + >> lit('(') >> double_[percent_red] >> lit('%') + >> lit(',') >> double_[percent_green] >> lit('%') + >> lit(',') >> double_[percent_blue] >> lit('%') >> attr(255) >> lit(')'); auto const rgba_color_def = lit("rgba") @@ -364,24 +364,24 @@ auto const rgba_color_def = lit("rgba") >> 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('%') + >> lit('(') >> double_[percent_red] >> lit('%') + >> lit(',') >> double_[percent_green] >> lit('%') + >> lit(',') >> double_[percent_blue] >> lit('%') >> lit(',') >> double_[opacity] >> lit(')'); -auto const hsl_values = x3::rule> {} = +auto const hsl_values = x3::rule> {} = lit("hsl") >> lit('(') >> dec3 - >> lit(',') >> dec3 >> lit('%') - >> lit(',') >> dec3 >> lit('%') + >> lit(',') >> double_ >> lit('%') + >> lit(',') >> double_ >> lit('%') >> attr(1.0) >> lit(')') ; -auto const hsla_values = x3::rule> {} = +auto const hsla_values = x3::rule> {} = lit("hsla") >> lit('(') >> dec3 - >> lit(',') >> dec3 >> lit('%') - >> lit(',') >> dec3 >> lit('%') + >> lit(',') >> double_ >> lit('%') + >> lit(',') >> double_ >> lit('%') >> lit(',') >> double_ >> lit(')') ; diff --git a/test/unit/color/css_color.cpp b/test/unit/color/css_color.cpp index c1c21b4d0..e065bdab0 100644 --- a/test/unit/color/css_color.cpp +++ b/test/unit/color/css_color.cpp @@ -14,6 +14,9 @@ TEST_CASE("CSS color") using namespace mapnik::css_color_grammar; CHECK(percent_converter::call(1.0) == 3); CHECK(percent_converter::call(60.0) == 153); + CHECK(percent_converter::call(10) == 26); + CHECK(percent_converter::call(35) == 89); + CHECK(percent_converter::call(35.4999) == 91); // should not overflow on invalid input CHECK(percent_converter::call(100000.0) == 255); CHECK(percent_converter::call(-100000.0) == 0); @@ -35,13 +38,20 @@ TEST_CASE("CSS color") } { // rgb (percent) - std::string s("rgb(50%,0%,100%)"); + std::string s1("rgb(50%,0%,100%)"); mapnik::color c; - CHECK(boost::spirit::x3::phrase_parse(s.cbegin(), s.cend(), color_grammar, space, c)); + CHECK(boost::spirit::x3::phrase_parse(s1.cbegin(), s1.cend(), color_grammar, space, c)); CHECK(c.alpha() == 0xff); CHECK(c.red() == 0x80); CHECK(c.green() == 0x00); CHECK(c.blue() == 0xff); + // rgb (fractional percent) + std::string s2("rgb(50.5%,0.5%,99.5%)"); // #8101fe + CHECK(boost::spirit::x3::phrase_parse(s2.cbegin(), s2.cend(), color_grammar, space, c)); + CHECK(c.alpha() == 0xff); + CHECK(c.red() == 0x81); + CHECK(c.green() == 0x01); + CHECK(c.blue() == 0xfe); } { // rgba @@ -55,13 +65,20 @@ TEST_CASE("CSS color") } { // rgba (percent) - std::string s("rgba(50%,0%,100%,0.5)"); + std::string s1("rgba(50%,0%,100%,0.5)"); mapnik::color c; - CHECK(boost::spirit::x3::phrase_parse(s.cbegin(), s.cend(), color_grammar, space, c)); + CHECK(boost::spirit::x3::phrase_parse(s1.cbegin(), s1.cend(), color_grammar, space, c)); CHECK(c.alpha() == 0x80); CHECK(c.red() == 0x80); CHECK(c.green() == 0x00); CHECK(c.blue() == 0xff); + // rgba (fractional percent) + std::string s2("rgb(50.5%,0.5%,99.5%)"); //#8101fe80 + CHECK(boost::spirit::x3::phrase_parse(s2.cbegin(), s2.cend(), color_grammar, space, c)); + CHECK(c.alpha() == 0x80); + CHECK(c.red() == 0x81); + CHECK(c.green() == 0x01); + CHECK(c.blue() == 0xfe); } { // named colours @@ -83,6 +100,16 @@ TEST_CASE("CSS color") CHECK(c.green() == 64); CHECK(c.blue() == 191); } + // hsl (fractional percent) + { + std::string s("hsl(240,50.5%,49.5%)"); //Color(R=62,G=62,B=190,A=255) + mapnik::color c; + CHECK(boost::spirit::x3::phrase_parse(s.cbegin(), s.cend(), color_grammar, space, c)); + CHECK(c.alpha() == 255); + CHECK(c.red() == 62); + CHECK(c.green() == 62); + CHECK(c.blue() == 190); + } // hsl (hue range 0..360) { std::string s1("hsl(0, 100%, 50%)"); @@ -116,6 +143,16 @@ TEST_CASE("CSS color") CHECK(c.green() == 64); CHECK(c.blue() == 191); } + // hsla (fractional percent) + { + std::string s("hsl(240,50.5%,49.5%,0.5)"); //Color(R=62,G=62,B=190,A=128) + mapnik::color c; + CHECK(boost::spirit::x3::phrase_parse(s.cbegin(), s.cend(), color_grammar, space, c)); + CHECK(c.alpha() == 128); + CHECK(c.red() == 62); + CHECK(c.green() == 62); + CHECK(c.blue() == 190); + } // hsla (hue range 0..360) { std::string s1("hsla(0, 100%, 50%, 1)"); From 7afaa7e6cc154cd001350bfbf9111dfb9d7cc9e5 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 15 Apr 2024 14:13:14 +0100 Subject: [PATCH 3/3] clang-format --- test/unit/color/css_color.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/color/css_color.cpp b/test/unit/color/css_color.cpp index e065bdab0..c10a09672 100644 --- a/test/unit/color/css_color.cpp +++ b/test/unit/color/css_color.cpp @@ -102,7 +102,7 @@ TEST_CASE("CSS color") } // hsl (fractional percent) { - std::string s("hsl(240,50.5%,49.5%)"); //Color(R=62,G=62,B=190,A=255) + std::string s("hsl(240,50.5%,49.5%)"); // Color(R=62,G=62,B=190,A=255) mapnik::color c; CHECK(boost::spirit::x3::phrase_parse(s.cbegin(), s.cend(), color_grammar, space, c)); CHECK(c.alpha() == 255); @@ -145,7 +145,7 @@ TEST_CASE("CSS color") } // hsla (fractional percent) { - std::string s("hsl(240,50.5%,49.5%,0.5)"); //Color(R=62,G=62,B=190,A=128) + std::string s("hsl(240,50.5%,49.5%,0.5)"); // Color(R=62,G=62,B=190,A=128) mapnik::color c; CHECK(boost::spirit::x3::phrase_parse(s.cbegin(), s.cend(), color_grammar, space, c)); CHECK(c.alpha() == 128);