summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mbgl/style/style_parser.cpp36
-rw-r--r--test/fixtures/resources/style.json4
-rw-r--r--test/fixtures/style_parser/function-string-bool-enum.style.json2
3 files changed, 24 insertions, 18 deletions
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index fb834c02bf..933587862e 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -473,24 +473,30 @@ StyleParser::Status StyleParser::parseOptionalProperty(const char *property_name
}
}
-std::string normalizeFontStack(const std::string &name) {
- namespace algo = boost::algorithm;
- std::vector<std::string> parts;
- algo::split(parts, name, algo::is_any_of(","), algo::token_compress_on);
- std::for_each(parts.begin(), parts.end(), [](std::string& str) { algo::trim(str); });
- return algo::join(parts, ", ");
-}
-
template<> StyleParser::Result<std::string> StyleParser::parseProperty(JSVal value, const char *property_name) {
- if (!value.IsString()) {
+ if (std::string { "text-font" } == property_name) {
+ if (!value.IsArray()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", property_name);
+ return Result<std::string> { StyleParserFailure, std::string() };
+ } else {
+ std::string result = "";
+ for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
+ JSVal stop = value[i];
+ if (stop.IsString()) {
+ result += stop.GetString();
+ if (i < value.Size()-1) {
+ result += ",";
+ }
+ } else {
+ Log::Warning(Event::ParseStyle, "text-font members must be strings");
+ return Result<std::string> { StyleParserFailure, {} };
+ }
+ }
+ return Result<std::string> { StyleParserSuccess, result };
+ }
+ } else if (!value.IsString()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
return Result<std::string> { StyleParserFailure, std::string() };
- }
-
- if (std::string { "text-font" } == property_name) {
- return Result<std::string> {
- StyleParserSuccess, normalizeFontStack({ value.GetString(), value.GetStringLength() })
- };
} else {
return Result<std::string> { StyleParserSuccess, { value.GetString(), value.GetStringLength() } };
}
diff --git a/test/fixtures/resources/style.json b/test/fixtures/resources/style.json
index 6ac8f48566..fc5f9c973b 100644
--- a/test/fixtures/resources/style.json
+++ b/test/fixtures/resources/style.json
@@ -20,7 +20,7 @@
"source": "vectorsource",
"source-layer": "road_label",
"layout": {
- "text-font": "Open Sans Regular, Arial Unicode MS Regular",
+ "text-font": ["Open Sans Regular", "Arial Unicode MS Regular"],
"text-field": "{name_en}"
}
}, {
@@ -29,7 +29,7 @@
"source": "vectorsource",
"source-layer": "poi_label",
"layout": {
- "text-font": "Open Sans Regular, Arial Unicode MS Regular",
+ "text-font": ["Open Sans Regular", "Arial Unicode MS Regular"],
"icon-image": "{maki}_icon"
}
}]
diff --git a/test/fixtures/style_parser/function-string-bool-enum.style.json b/test/fixtures/style_parser/function-string-bool-enum.style.json
index 76fb9be9f4..0447990911 100644
--- a/test/fixtures/style_parser/function-string-bool-enum.style.json
+++ b/test/fixtures/style_parser/function-string-bool-enum.style.json
@@ -31,7 +31,7 @@
"source-layer": "waterway",
"layout": {
"text-font": {
- "stops": [[0, "Open Sans Regular"]]
+ "stops": [[0, ["Open Sans Regular"]]]
},
"text-keep-upright": {
"stops": [[0, false], [10, true]]