summaryrefslogtreecommitdiff
path: root/src/mbgl/style/expression/formatted.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/expression/formatted.cpp')
-rw-r--r--src/mbgl/style/expression/formatted.cpp36
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)) {