summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-01-10 14:42:53 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-01-10 15:31:12 -0800
commit542713fefe0b66aa312aff07950772e74b89b0f6 (patch)
tree6f289dfb51e26d16ceeba9e65b2be676590ecfa1
parent76ed5079a547e9f98616a9401c8814d224cec9d8 (diff)
downloadqtlocation-mapboxgl-542713fefe0b66aa312aff07950772e74b89b0f6.tar.gz
[core] Add warning for invalid text-font values
-rw-r--r--src/mbgl/style/parser.cpp6
-rw-r--r--test/fixtures/style_parser/text-font.info.json14
-rw-r--r--test/fixtures/style_parser/text-font.style.json135
3 files changed, 155 insertions, 0 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 52d788b3a1..b177f2159c 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -119,6 +119,9 @@ StyleParseResult Parser::parse(const std::string& json) {
}
}
+ // Call for side effect of logging warnings for invalid values.
+ fontStacks();
+
return nullptr;
}
@@ -286,6 +289,9 @@ std::vector<FontStack> Parser::fontStacks() const {
for (const auto& value : function.possibleOutputs()) {
if (value) {
result.insert(*value);
+ } else {
+ Log::Warning(Event::ParseStyle, "Layer '%s' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression.", layer->getID().c_str());
+ break;
}
}
}
diff --git a/test/fixtures/style_parser/text-font.info.json b/test/fixtures/style_parser/text-font.info.json
new file mode 100644
index 0000000000..0fb9658269
--- /dev/null
+++ b/test/fixtures/style_parser/text-font.info.json
@@ -0,0 +1,14 @@
+{
+ "default": {
+ "log": [
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - get' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - case' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - match' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - at' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - coalesce' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - step' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - let/var' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."],
+ [1, "WARNING", "ParseStyle", "Layer 'invalid expression - identity function' has an invalid value for text-font and will not work offline. Output values must be contained as literals within the expression."]
+ ]
+ }
+}
diff --git a/test/fixtures/style_parser/text-font.style.json b/test/fixtures/style_parser/text-font.style.json
new file mode 100644
index 0000000000..215807ca81
--- /dev/null
+++ b/test/fixtures/style_parser/text-font.style.json
@@ -0,0 +1,135 @@
+{
+ "version": 8,
+ "glyphs": "https://example.com/{fontstack}/{range}",
+ "sources": {
+ "vector": {
+ "type": "vector",
+ "url": "mapbox://mapbox.mapbox-streets-v5"
+ }
+ },
+ "layers": [
+ {
+ "id": "minimum",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["Helvetica"],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "valid expression - case",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["case", ["==", "a", ["string", ["get", "text-font"]]], ["literal", ["Arial"]], ["literal", ["Helvetica"]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "valid expression - match",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["match", ["get", "text-font"], "a", ["literal", ["Arial"]], ["literal", ["Helvetica"]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "valid expression - step",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["array", "string", ["step", ["get", "text-font"], ["literal", ["Arial"]], 0, ["literal", ["Helvetica"]]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - get",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["array", "string", ["get", "text-font"]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - case",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["case", ["==", "a", ["string", ["get", "text-font"]]], ["array", "string", ["get", "text-font-a"]], ["literal", ["Helvetica"]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - match",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["match", ["get", "text-font"], "a", ["array", "string", ["get", "text-font-a"]], ["literal", ["Helvetica"]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - at",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["array", "string", ["at", 0, ["array", ["get", "text-font"]]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - coalesce",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["array", "string", ["coalesce", ["get", "text-font"]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - step",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["step", ["zoom"], ["array", "string", ["get", "text-font-0"]], 0, ["array", "string", ["get", "text-font-1"]]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - let/var",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": ["let", "p", ["array", "string", ["get", "text-font"]], ["var", "p"]],
+ "text-field": "{foo}"
+ }
+ },
+ {
+ "id": "invalid expression - identity function",
+ "type": "symbol",
+ "source": "vector",
+ "source-layer": "layer",
+ "layout": {
+ "text-font": {
+ "type": "identity",
+ "property": "text-font"
+ },
+ "text-field": "{foo}"
+ }
+ }
+ ]
+}