summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-01-25 15:24:29 -0800
committerKonstantin Käfer <mail@kkaefer.com>2018-01-26 14:36:51 -0800
commitce429dcc1fce2a827e5c9462e3226c3bb04c6a39 (patch)
tree5eed851bef213b319289f70c3361826075570b02
parent306898d77bae63220b3a69191aaadef6da7e2fc5 (diff)
downloadqtlocation-mapboxgl-ce429dcc1fce2a827e5c9462e3226c3bb04c6a39.tar.gz
[core] don't force downloading of Open Sans fonts
When a SymbolLayer doesn't have a text-font defined, we automatically add Open Sans/Arial Unicode MS. However, when the SymbolLayer is only used for rendering icons, it doesn't have text-field defined either. In those cases, we still force downloading Open Sans/Arial Unicode MS during offline pack creation. If the user doesn't use this font, this change should save ~15MB and a few seconds in download time.
-rw-r--r--src/mbgl/style/parser.cpp2
-rw-r--r--test/fixtures/style_parser/font_stacks.json3
-rw-r--r--test/style/style_parser.test.cpp21
3 files changed, 25 insertions, 1 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index b177f2159c..8d14d7972c 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -277,7 +277,7 @@ std::vector<FontStack> Parser::fontStacks() const {
std::set<FontStack> result;
for (const auto& layer : layers) {
- if (layer->is<SymbolLayer>()) {
+ if (layer->is<SymbolLayer>() && !layer->as<SymbolLayer>()->getTextField().isUndefined()) {
layer->as<SymbolLayer>()->getTextFont().match(
[&] (Undefined) {
result.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
diff --git a/test/fixtures/style_parser/font_stacks.json b/test/fixtures/style_parser/font_stacks.json
index 07fe223d46..0ff3e936a8 100644
--- a/test/fixtures/style_parser/font_stacks.json
+++ b/test/fixtures/style_parser/font_stacks.json
@@ -12,6 +12,7 @@
"source": "source",
"source-layer": "source-layer",
"layout": {
+ "text-field": "a",
"text-font": ["a"]
}
}, {
@@ -20,6 +21,7 @@
"source": "source",
"source-layer": "source-layer",
"layout": {
+ "text-field": "a",
"text-font": {
"stops": [[0, ["a", "b"]]]
}
@@ -30,6 +32,7 @@
"source": "source",
"source-layer": "source-layer",
"layout": {
+ "text-field": "a",
"text-font": {
"stops": [[0, ["a", "b"]], [1, ["a", "b", "c"]]]
}
diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp
index 7f7c06f4c5..43b982c3b9 100644
--- a/test/style/style_parser.test.cpp
+++ b/test/style/style_parser.test.cpp
@@ -103,6 +103,23 @@ TEST(StyleParser, FontStacks) {
ASSERT_EQ(FontStack({"a", "b", "c"}), result[2]);
}
+TEST(StyleParser, FontStacksNoTextField) {
+ style::Parser parser;
+ parser.parse(R"({
+ "version": 8,
+ "layers": [{
+ "id": "symbol",
+ "type": "symbol",
+ "source": "vector",
+ "layout": {
+ "text-font": ["a"]
+ }
+ }]
+ })");
+ auto result = parser.fontStacks();
+ ASSERT_EQ(0u, result.size());
+}
+
TEST(StyleParser, FontStacksCaseExpression) {
style::Parser parser;
parser.parse(R"({
@@ -112,6 +129,7 @@ TEST(StyleParser, FontStacksCaseExpression) {
"type": "symbol",
"source": "vector",
"layout": {
+ "text-field": "a",
"text-font": ["case", ["==", "a", ["string", ["get", "text-font"]]], ["literal", ["Arial"]], ["literal", ["Helvetica"]]]
}
}]
@@ -131,6 +149,7 @@ TEST(StyleParser, FontStacksMatchExpression) {
"type": "symbol",
"source": "vector",
"layout": {
+ "text-field": "a",
"text-font": ["match", ["get", "text-font"], "a", ["literal", ["Arial"]], ["literal", ["Helvetica"]]]
}
}]
@@ -150,6 +169,7 @@ TEST(StyleParser, FontStacksStepExpression) {
"type": "symbol",
"source": "vector",
"layout": {
+ "text-field": "a",
"text-font": ["array", "string", ["step", ["get", "text-font"], ["literal", ["Arial"]], 0, ["literal", ["Helvetica"]]]]
}
}]
@@ -170,6 +190,7 @@ TEST(StyleParser, FontStacksGetExpression) {
"type": "symbol",
"source": "vector",
"layout": {
+ "text-field": "a",
"text-font": ["array", "string", ["get", "text-font"]]
}
}]