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

[core] don't force downloading of Open Sans fonts #11057

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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