diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-01 16:01:15 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-10 15:40:20 -0800 |
commit | f3d4107d19eef20cc2cf30cd347301128b4f9a86 (patch) | |
tree | dc66d61846b2a7fb036c87f127d1dd18045a9293 /src | |
parent | 7d6c6c00cac53a3864f0dfd399e64fd862d017e1 (diff) | |
download | qtlocation-mapboxgl-f3d4107d19eef20cc2cf30cd347301128b4f9a86.tar.gz |
[core] Add a method for statically evaluating font stacks used by a style
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/style/function.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.hpp | 3 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/mbgl/style/function.hpp b/src/mbgl/style/function.hpp index 4d2e4fcbd7..160f5be390 100644 --- a/src/mbgl/style/function.hpp +++ b/src/mbgl/style/function.hpp @@ -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; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 7d53d603e5..e3470e45d3 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -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 diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 69bd8a3bf9..162a10c87c 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -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&); |