Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] don't force downloading of Open Sans fonts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kkaefer committed Jan 26, 2018
1 parent c148a7a commit dcb7705
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mbgl/style/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/style_parser/font_stacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"source": "source",
"source-layer": "source-layer",
"layout": {
"text-field": "a",
"text-font": ["a"]
}
}, {
Expand All @@ -20,6 +21,7 @@
"source": "source",
"source-layer": "source-layer",
"layout": {
"text-field": "a",
"text-font": {
"stops": [[0, ["a", "b"]]]
}
Expand All @@ -30,6 +32,7 @@
"source": "source",
"source-layer": "source-layer",
"layout": {
"text-field": "a",
"text-font": {
"stops": [[0, ["a", "b"]], [1, ["a", "b", "c"]]]
}
Expand Down
21 changes: 21 additions & 0 deletions test/style/style_parser.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"({
Expand All @@ -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"]]]
}
}]
Expand All @@ -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"]]]
}
}]
Expand All @@ -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"]]]]
}
}]
Expand All @@ -170,6 +190,7 @@ TEST(StyleParser, FontStacksGetExpression) {
"type": "symbol",
"source": "vector",
"layout": {
"text-field": "a",
"text-font": ["array", "string", ["get", "text-font"]]
}
}]
Expand Down

0 comments on commit dcb7705

Please sign in to comment.