[core] Add a method for statically evaluating font stacks used by a style
This commit is contained in:
@@ -27,6 +27,9 @@ public:
|
||||
|
||||
T evaluate(const StyleCalculationParameters&) const;
|
||||
|
||||
float getBase() const { return base; }
|
||||
const std::vector<std::pair<float, T>>& getStops() const { return stops; }
|
||||
|
||||
private:
|
||||
float base = 1;
|
||||
std::vector<std::pair<float, T>> stops;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -484,4 +485,23 @@ void StyleParser::parseVisibility(StyleLayer& layer, const JSValue& value) {
|
||||
layer.visibility = VisibilityTypeClass({ value["visibility"].GetString(), value["visibility"].GetStringLength() });
|
||||
}
|
||||
|
||||
std::vector<std::string> StyleParser::fontStacks() const {
|
||||
std::set<std::string> result;
|
||||
|
||||
for (const auto& layer : layers) {
|
||||
if (layer->is<SymbolLayer>()) {
|
||||
LayoutProperty<std::string> property = layer->as<SymbolLayer>()->layout.text.font;
|
||||
if (property.parsedValue) {
|
||||
for (const auto& stop : property.parsedValue->getStops()) {
|
||||
result.insert(stop.second);
|
||||
}
|
||||
} else {
|
||||
result.insert(property.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::vector<std::string>(result.begin(), result.end());
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -28,6 +28,9 @@ public:
|
||||
std::vector<std::unique_ptr<Source>> sources;
|
||||
std::vector<std::unique_ptr<StyleLayer>> layers;
|
||||
|
||||
// Statically evaluate layer properties to determine what font stacks are used.
|
||||
std::vector<std::string> fontStacks() const;
|
||||
|
||||
static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType);
|
||||
static std::unique_ptr<SourceInfo> parseTileJSON(const JSValue&);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user