diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-03-11 10:26:19 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-03-13 17:14:53 +0200 |
commit | 8be135231d9efe41a3b12037518d02b36104e8cf (patch) | |
tree | efecd5380232f899aed2cd5824dc16f057f0469a /src/mbgl/style/expression/formatted.cpp | |
parent | 8a51362bccbd6487dd1ed8518443b16ba6114fd8 (diff) | |
download | qtlocation-mapboxgl-8be135231d9efe41a3b12037518d02b36104e8cf.tar.gz |
[core] Add possibility of overriding paint properties inside format expression #14062
* [core] Add format override expression and formatted section to evaluation context
* [core] Add textColor to TaggedString's formatted section
* [core] Add FormatSectionOverrides and introduce overridable properties
* [core] Populate symbol layer paint properties for text sections
* [core] Add benchmark for style that uses text-color override
* [core] Add unit test for FormatOverrideExpression
* [core] Add unit test for FormatSectionOverrides
Diffstat (limited to 'src/mbgl/style/expression/formatted.cpp')
-rw-r--r-- | src/mbgl/style/expression/formatted.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/mbgl/style/expression/formatted.cpp b/src/mbgl/style/expression/formatted.cpp index 8232d0c698..3fa39b2cdc 100644 --- a/src/mbgl/style/expression/formatted.cpp +++ b/src/mbgl/style/expression/formatted.cpp @@ -1,18 +1,15 @@ #include <mbgl/style/expression/formatted.hpp> #include <mbgl/style/conversion_impl.hpp> -#include <mbgl/style/expression/is_constant.hpp> -#include <mbgl/style/expression/is_expression.hpp> -#include <mbgl/style/expression/literal.hpp> -#include <mbgl/style/expression/expression.hpp> -#include <mbgl/style/expression/type.hpp> -#include <mbgl/style/expression/compound_expression.hpp> -#include <mbgl/style/expression/boolean_operator.hpp> +#include <mbgl/style/conversion/constant.hpp> namespace mbgl { namespace style { - namespace expression { +const char* const kFormattedSectionFontScale = "font-scale"; +const char* const kFormattedSectionTextFont = "text-font"; +const char* const kFormattedSectionTextColor = "text-color"; + bool Formatted::operator==(const Formatted& other) const { if (other.sections.size() != sections.size()) { return false; @@ -22,14 +19,14 @@ bool Formatted::operator==(const Formatted& other) const { const auto& otherSection = other.sections.at(i); if (thisSection.text != otherSection.text || thisSection.fontScale != otherSection.fontScale || - thisSection.fontStack != otherSection.fontStack) { + thisSection.fontStack != otherSection.fontStack || + thisSection.textColor != otherSection.textColor) { return false; } } return true; } - - + std::string Formatted::toString() const { std::string result; for (const auto& section : sections) { @@ -37,7 +34,7 @@ std::string Formatted::toString() const { } return result; } - + } // namespace expression namespace conversion { @@ -65,6 +62,7 @@ optional<Formatted> Converter<Formatted>::operator()(const Convertible& value, E optional<double> fontScale; optional<FontStack> textFont; + optional<Color> textColor; if (sectionLength > 1) { Convertible sectionParams = arrayMember(section, 1); if (!isObject(sectionParams)) { @@ -72,12 +70,12 @@ optional<Formatted> Converter<Formatted>::operator()(const Convertible& value, E return nullopt; } - optional<Convertible> fontScaleMember = objectMember(sectionParams, "font-scale"); + optional<Convertible> fontScaleMember = objectMember(sectionParams, kFormattedSectionFontScale); if (fontScaleMember) { fontScale = toDouble(*fontScaleMember); } - optional<Convertible> textFontMember = objectMember(sectionParams, "text-font"); + optional<Convertible> textFontMember = objectMember(sectionParams, kFormattedSectionTextFont); if (textFontMember) { if (isArray(*textFontMember)) { std::vector<std::string> fontsVector; @@ -96,9 +94,17 @@ optional<Formatted> Converter<Formatted>::operator()(const Convertible& value, E return nullopt; } } + + optional<Convertible> textColorMember = objectMember(sectionParams, kFormattedSectionTextColor); + if (textColorMember) { + textColor = convert<Color>(*textColorMember, error); + if (!textColor) { + return nullopt; + } + } } - sections.push_back(FormattedSection(*sectionText, fontScale, textFont)); + sections.push_back(FormattedSection(*sectionText, fontScale, textFont, textColor)); } return Formatted(sections); } else if (optional<std::string> result = toString(value)) { |