From 71af6a8fe3fb16404c8896622b00056fdd7c0e94 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 4 Mar 2016 15:53:15 +0100 Subject: [PATCH] css_color_grammar + image_filters_grammar - move phoenix into ctors --- include/mapnik/css_color_grammar.hpp | 58 +------------------ include/mapnik/css_color_grammar_impl.hpp | 57 +++++++++++++++++- include/mapnik/image_filter_grammar.hpp | 2 - include/mapnik/image_filter_grammar_impl.hpp | 3 + include/mapnik/svg/svg_path_grammar_impl.hpp | 2 + .../mapnik/svg/svg_points_grammar_impl.hpp | 3 +- .../mapnik/svg/svg_transform_grammar_impl.hpp | 2 + 7 files changed, 67 insertions(+), 60 deletions(-) diff --git a/include/mapnik/css_color_grammar.hpp b/include/mapnik/css_color_grammar.hpp index 9dff6a2a0..8fbdeaa6f 100644 --- a/include/mapnik/css_color_grammar.hpp +++ b/include/mapnik/css_color_grammar.hpp @@ -32,7 +32,6 @@ #pragma GCC diagnostic push #include #include -#include #pragma GCC diagnostic pop // stl @@ -43,65 +42,15 @@ namespace mapnik namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; -namespace phoenix = boost::phoenix; using ascii_space_type = boost::spirit::ascii::space_type; -struct percent_conv_impl -{ - using result_type = unsigned; - unsigned operator() (double val) const - { - return safe_cast(std::lround((255.0 * val)/100.0)); - } -}; - -struct alpha_conv_impl -{ - using result_type = unsigned; - unsigned operator() (double val) const - { - return safe_cast(std::lround((255.0 * val))); - } -}; - -struct hsl_conv_impl -{ - using result_type = void; - template - void operator() (T0 & c, T1 h, T2 s, T3 l) const - { - double m1,m2; - // normalize values - h /= 360.0; - s /= 100.0; - l /= 100.0; - - if (l <= 0.5) - { - m2 = l * (s + 1.0); - } - else - { - m2 = l + s - l*s; - } - m1 = l * 2 - m2; - - double r = hue_to_rgb(m1, m2, h + 1.0/3.0); - double g = hue_to_rgb(m1, m2, h); - double b = hue_to_rgb(m1, m2, h - 1.0/3.0); - - c.set_red(safe_cast(std::lround(255.0 * r))); - c.set_green(safe_cast(std::lround(255.0 * g))); - c.set_blue(safe_cast(std::lround(255.0 * b))); - } -}; - - template struct css_color_grammar : qi::grammar { + // ctor css_color_grammar(); + // rules qi::uint_parser< unsigned, 16, 2, 2 > hex2 ; qi::uint_parser< unsigned, 16, 1, 1 > hex1 ; qi::uint_parser< unsigned, 10, 1, 3 > dec3 ; @@ -111,9 +60,6 @@ struct css_color_grammar : qi::grammar qi::rule hex_color; qi::rule hex_color_small; qi::rule css_color; - phoenix::function percent_converter; - phoenix::function alpha_converter; - phoenix::function hsl_converter; }; } diff --git a/include/mapnik/css_color_grammar_impl.hpp b/include/mapnik/css_color_grammar_impl.hpp index 9a227f033..22fa74472 100644 --- a/include/mapnik/css_color_grammar_impl.hpp +++ b/include/mapnik/css_color_grammar_impl.hpp @@ -43,6 +43,57 @@ BOOST_FUSION_ADAPT_ADT( namespace mapnik { +namespace phoenix = boost::phoenix; + +struct percent_conv_impl +{ + using result_type = unsigned; + unsigned operator() (double val) const + { + return safe_cast(std::lround((255.0 * val)/100.0)); + } +}; + +struct alpha_conv_impl +{ + using result_type = unsigned; + unsigned operator() (double val) const + { + return safe_cast(std::lround((255.0 * val))); + } +}; + +struct hsl_conv_impl +{ + using result_type = void; + template + void operator() (T0 & c, T1 h, T2 s, T3 l) const + { + double m1,m2; + // normalize values + h /= 360.0; + s /= 100.0; + l /= 100.0; + + if (l <= 0.5) + { + m2 = l * (s + 1.0); + } + else + { + m2 = l + s - l*s; + } + m1 = l * 2 - m2; + + double r = hue_to_rgb(m1, m2, h + 1.0/3.0); + double g = hue_to_rgb(m1, m2, h); + double b = hue_to_rgb(m1, m2, h - 1.0/3.0); + + c.set_red(safe_cast(std::lround(255.0 * r))); + c.set_green(safe_cast(std::lround(255.0 * g))); + c.set_blue(safe_cast(std::lround(255.0 * b))); + } +}; struct named_colors : qi::symbols { @@ -215,8 +266,12 @@ css_color_grammar::css_color_grammar() qi::lexeme_type lexeme; ascii::no_case_type no_case; using phoenix::at_c; - + // symbols named_colors named; + // functions + phoenix::function percent_converter; + phoenix::function alpha_converter; + phoenix::function hsl_converter; css_color %= rgba_color | rgba_percent_color diff --git a/include/mapnik/image_filter_grammar.hpp b/include/mapnik/image_filter_grammar.hpp index 5eb82dfaa..ca96116eb 100644 --- a/include/mapnik/image_filter_grammar.hpp +++ b/include/mapnik/image_filter_grammar.hpp @@ -74,11 +74,9 @@ struct image_filter_grammar : css_color_grammar css_color_; qi::rule color_stop_; qi::rule color_stop_offset; - phoenix::function percent_offset; private: alternative_type & add(std::string const& symbol); - static constexpr unsigned max_alternatives = 16; unsigned num_alternatives = 0; alternative_type alternative_storage[max_alternatives]; diff --git a/include/mapnik/image_filter_grammar_impl.hpp b/include/mapnik/image_filter_grammar_impl.hpp index 98de7119f..bf1770083 100644 --- a/include/mapnik/image_filter_grammar_impl.hpp +++ b/include/mapnik/image_filter_grammar_impl.hpp @@ -64,6 +64,9 @@ image_filter_grammar::image_filter_grammar() using phoenix::push_back; using phoenix::construct; + // functions + phoenix::function percent_offset; + start = -(filter % *lit(',')) ; diff --git a/include/mapnik/svg/svg_path_grammar_impl.hpp b/include/mapnik/svg/svg_path_grammar_impl.hpp index 2946005ff..5d5fd1a7a 100644 --- a/include/mapnik/svg/svg_path_grammar_impl.hpp +++ b/include/mapnik/svg/svg_path_grammar_impl.hpp @@ -20,6 +20,8 @@ * *****************************************************************************/ +// NOTE: This is an implementation header file and is only meant to be included +// from implementation files. It therefore doesn't have an include guard. // mapnik #include diff --git a/include/mapnik/svg/svg_points_grammar_impl.hpp b/include/mapnik/svg/svg_points_grammar_impl.hpp index 4431909fa..5d56f7e25 100644 --- a/include/mapnik/svg/svg_points_grammar_impl.hpp +++ b/include/mapnik/svg/svg_points_grammar_impl.hpp @@ -20,7 +20,8 @@ * *****************************************************************************/ - +// NOTE: This is an implementation header file and is only meant to be included +// from implementation files. It therefore doesn't have an include guard. // mapnik #include #include diff --git a/include/mapnik/svg/svg_transform_grammar_impl.hpp b/include/mapnik/svg/svg_transform_grammar_impl.hpp index 464e0a556..f0bd54260 100644 --- a/include/mapnik/svg/svg_transform_grammar_impl.hpp +++ b/include/mapnik/svg/svg_transform_grammar_impl.hpp @@ -20,6 +20,8 @@ * *****************************************************************************/ +// NOTE: This is an implementation header file and is only meant to be included +// from implementation files. It therefore doesn't have an include guard. // mapnik #include // agg