summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/layer_impl.cpp2
-rw-r--r--src/mbgl/style/layer_impl.hpp4
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.cpp27
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.hpp1
-rw-r--r--src/mbgl/style/parser.cpp5
-rw-r--r--src/mbgl/style/parser.hpp2
-rw-r--r--src/mbgl/util/font_stack.cpp30
7 files changed, 38 insertions, 33 deletions
diff --git a/src/mbgl/style/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp
index a9a3941f3e..c6a248de90 100644
--- a/src/mbgl/style/layer_impl.cpp
+++ b/src/mbgl/style/layer_impl.cpp
@@ -9,5 +9,7 @@ Layer::Impl::Impl(LayerType type_, std::string layerID, std::string sourceID)
source(std::move(sourceID)) {
}
+void Layer::Impl::populateFontStack(std::set<FontStack>&) const {}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp
index 014fb60348..948bbab619 100644
--- a/src/mbgl/style/layer_impl.hpp
+++ b/src/mbgl/style/layer_impl.hpp
@@ -41,8 +41,12 @@ public:
// Utility function for automatic layer grouping.
virtual void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const = 0;
+ // Returns pointer to the statically allocated layer type info structure.
virtual const LayerTypeInfo* getTypeInfo() const noexcept = 0;
+ // Populates the given \a fontStack with fonts being used by the layer.
+ virtual void populateFontStack(std::set<FontStack>& fontStack) const;
+
// Note: LayerType is deprecated, do not use it.
const LayerType type;
std::string id;
diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp
index 753b2fa184..e177391686 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.cpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.cpp
@@ -1,5 +1,7 @@
#include <mbgl/style/layers/symbol_layer_impl.hpp>
+#include <mbgl/util/logging.hpp>
+
namespace mbgl {
namespace style {
@@ -12,5 +14,30 @@ bool SymbolLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const {
paint.hasDataDrivenPropertyDifference(impl.paint);
}
+void SymbolLayer::Impl::populateFontStack(std::set<FontStack>& fontStack) const {
+ if (layout.get<TextField>().isUndefined()) {
+ return;
+ }
+
+ layout.get<TextFont>().match(
+ [&] (Undefined) {
+ fontStack.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
+ },
+ [&] (const FontStack& constant) {
+ fontStack.insert(constant);
+ },
+ [&] (const auto& function) {
+ for (const auto& value : function.possibleOutputs()) {
+ if (value) {
+ fontStack.insert(*value);
+ } else {
+ Log::Warning(Event::ParseStyle, "Layer '%s' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression.", id.c_str());
+ break;
+ }
+ }
+ }
+ );
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp
index 21e47ad89a..01ff9772b8 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.hpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.hpp
@@ -14,6 +14,7 @@ public:
bool hasLayoutDifference(const Layer::Impl&) const override;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
const LayerTypeInfo* getTypeInfo() const noexcept final;
+ void populateFontStack(std::set<FontStack>& fontStack) const final;
SymbolLayoutProperties::Unevaluated layout;
SymbolPaintProperties::Transitionable paint;
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 77cf23bad0..ae298bd915 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -267,14 +267,13 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
}
}
-std::vector<FontStack> Parser::fontStacks() const {
+std::set<FontStack> Parser::fontStacks() const {
std::vector<Immutable<Layer::Impl>> impls;
impls.reserve(layers.size());
for (const auto& layer : layers) {
impls.emplace_back(layer->baseImpl);
}
- std::set<FontStack> result = mbgl::fontStacks(impls);
- return std::vector<FontStack>(result.begin(), result.end());
+ return mbgl::fontStacks(impls);
}
} // namespace style
diff --git a/src/mbgl/style/parser.hpp b/src/mbgl/style/parser.hpp
index ec7be038fb..f992519083 100644
--- a/src/mbgl/style/parser.hpp
+++ b/src/mbgl/style/parser.hpp
@@ -43,7 +43,7 @@ public:
double pitch = 0;
// Statically evaluate layer properties to determine what font stacks are used.
- std::vector<FontStack> fontStacks() const;
+ std::set<FontStack> fontStacks() const;
private:
void parseTransition(const JSValue&);
diff --git a/src/mbgl/util/font_stack.cpp b/src/mbgl/util/font_stack.cpp
index 4093a21793..362fdf1845 100644
--- a/src/mbgl/util/font_stack.cpp
+++ b/src/mbgl/util/font_stack.cpp
@@ -1,5 +1,4 @@
#include <mbgl/util/font_stack.hpp>
-#include <mbgl/util/logging.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/util/hash.hpp>
@@ -23,35 +22,8 @@ FontStackHash FontStackHasher::operator()(const FontStack& fontStack) const {
std::set<FontStack> fontStacks(const std::vector<Immutable<style::Layer::Impl>>& layers) {
std::set<FontStack> result;
-
for (const auto& layer : layers) {
- if (layer->type != LayerType::Symbol) {
- continue;
- }
-
- const SymbolLayer::Impl& impl = dynamic_cast<const SymbolLayer::Impl&>(*layer);
- if (impl.layout.get<TextField>().isUndefined()) {
- continue;
- }
-
- impl.layout.get<TextFont>().match(
- [&] (Undefined) {
- result.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
- },
- [&] (const FontStack& constant) {
- result.insert(constant);
- },
- [&] (const auto& function) {
- 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 render text. Output values must be contained as literals within the expression.", impl.id.c_str());
- break;
- }
- }
- }
- );
+ layer->populateFontStack(result);
}
return result;