diff options
Diffstat (limited to 'src/mbgl/style')
-rw-r--r-- | src/mbgl/style/function.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/property_parsing.cpp | 49 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/style/types.cpp | 16 |
7 files changed, 57 insertions, 33 deletions
diff --git a/src/mbgl/style/function.cpp b/src/mbgl/style/function.cpp index 55643ed43f..bc3e6074fb 100644 --- a/src/mbgl/style/function.cpp +++ b/src/mbgl/style/function.cpp @@ -14,9 +14,10 @@ template <> inline bool defaultStopsValue() { return true; } template <> inline float defaultStopsValue() { return 1.0f; } template <> inline Color defaultStopsValue() { return {{ 0, 0, 0, 1 }}; } template <> inline std::vector<float> defaultStopsValue() { return {{ 1, 0 }}; } +template <> inline std::vector<std::string> defaultStopsValue() { return {{}}; } template <> inline std::array<float, 2> defaultStopsValue() { return {{ 0, 0 }}; } -template <> inline std:: string defaultStopsValue() { return {}; } +template <> inline std::string defaultStopsValue() { return {}; } template <> inline TranslateAnchorType defaultStopsValue() { return {}; }; template <> inline RotateAnchorType defaultStopsValue() { return {}; }; template <> inline LineCapType defaultStopsValue() { return {}; }; @@ -79,6 +80,7 @@ template class Function<bool>; template class Function<float>; template class Function<Color>; template class Function<std::vector<float>>; +template class Function<std::vector<std::string>>; template class Function<std::array<float, 2>>; template class Function<std::string>; diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 879f61411a..6f052222e4 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -32,28 +32,6 @@ optional<float> parseProperty(const char* name, const JSValue& value) { template <> optional<std::string> parseProperty(const char* name, const JSValue& value) { - if (std::string { "text-font" } == name) { - if (!value.IsArray()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name); - return {}; - } - - std::string result = ""; - for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSValue& stop = value[i]; - if (stop.IsString()) { - result += stop.GetString(); - if (i < value.Size()-1) { - result += ","; - } - } else { - Log::Warning(Event::ParseStyle, "text-font members must be strings"); - return {}; - } - } - return result; - } - if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -209,6 +187,29 @@ optional<std::vector<float>> parseProperty(const char* name, const JSValue& valu } template <> +optional<std::vector<std::string>> parseProperty(const char* name, const JSValue& value) { + if (!value.IsArray()) { + Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name); + return {}; + } + + std::vector<std::string> result; + + for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { + const JSValue& part = value[i]; + + if (!part.IsString()) { + Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name); + return {}; + } + + result.push_back({ part.GetString(), part.GetStringLength() }); + } + + return result; +} + +template <> optional<PropertyTransition> parseProperty(const char *, const JSValue& value) { PropertyTransition transition; if (value.IsObject()) { @@ -362,6 +363,10 @@ template<> optional<Function<Color>> parseProperty(const char* name, const JSVal return parseFunction<Color>(name, value); } +template<> optional<Function<std::vector<std::string>>> parseProperty(const char* name, const JSValue& value) { + return parseFunction<std::vector<std::string>>(name, value); +} + template <typename T> optional<Function<Faded<T>>> parseFadedFunction(const JSValue& value) { if (!value.HasMember("stops")) { diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index a480ef8d97..338f6113b0 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -330,16 +330,16 @@ void Style::setObserver(Observer* observer_) { observer = observer_; } -void Style::onGlyphsLoaded(const std::string& fontStack, const GlyphRange& glyphRange) { +void Style::onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) { shouldReparsePartialTiles = true; observer->onGlyphsLoaded(fontStack, glyphRange); observer->onResourceLoaded(); } -void Style::onGlyphsError(const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { +void Style::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { lastError = error; Log::Error(Event::Style, "Failed to load glyph range %d-%d for font stack %s: %s", - glyphRange.first, glyphRange.second, fontStack.c_str(), util::toString(error).c_str()); + glyphRange.first, glyphRange.second, fontStackToString(fontStack).c_str(), util::toString(error).c_str()); observer->onGlyphsError(fontStack, glyphRange, error); observer->onResourceError(error); } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index b3c06d8214..790518d08e 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -128,8 +128,8 @@ private: std::vector<std::unique_ptr<StyleLayer>>::const_iterator findLayer(const std::string& layerID) const; // GlyphStore::Observer implementation. - void onGlyphsLoaded(const std::string& fontStack, const GlyphRange&) override; - void onGlyphsError(const std::string& fontStack, const GlyphRange&, std::exception_ptr) override; + void onGlyphsLoaded(const FontStack&, const GlyphRange&) override; + void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override; // SpriteStore::Observer implementation. void onSpriteLoaded() override; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index e312dee3b3..ff0a3b13af 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -492,12 +492,12 @@ 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; +std::vector<FontStack> StyleParser::fontStacks() const { + std::set<FontStack> result; for (const auto& layer : layers) { if (layer->is<SymbolLayer>()) { - LayoutProperty<std::string> property = layer->as<SymbolLayer>()->layout.textFont; + LayoutProperty<FontStack> property = layer->as<SymbolLayer>()->layout.textFont; if (property.parsedValue) { for (const auto& stop : property.parsedValue->getStops()) { result.insert(stop.second); @@ -508,7 +508,7 @@ std::vector<std::string> StyleParser::fontStacks() const { } } - return std::vector<std::string>(result.begin(), result.end()); + return std::vector<FontStack>(result.begin(), result.end()); } } // namespace mbgl diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 280cda530b..4cc4e2f2cb 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -1,6 +1,7 @@ #ifndef MBGL_STYLE_STYLE_PARSER #define MBGL_STYLE_STYLE_PARSER +#include <mbgl/style/types.hpp> #include <mbgl/style/style_layer.hpp> #include <mbgl/source/source.hpp> #include <mbgl/util/rapidjson.hpp> @@ -29,7 +30,7 @@ public: std::vector<std::unique_ptr<StyleLayer>> layers; // Statically evaluate layer properties to determine what font stacks are used. - std::vector<std::string> fontStacks() const; + std::vector<FontStack> fontStacks() const; static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize); static std::unique_ptr<SourceInfo> parseTileJSON(const JSValue&); diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp new file mode 100644 index 0000000000..27574afa93 --- /dev/null +++ b/src/mbgl/style/types.cpp @@ -0,0 +1,16 @@ +#include <mbgl/style/types.hpp> + +#include <boost/functional/hash.hpp> +#include <boost/algorithm/string/join.hpp> + +namespace mbgl { + +std::string fontStackToString(const FontStack& fontStack) { + return boost::algorithm::join(fontStack, ","); +} + +std::size_t FontStackHash::operator()(const FontStack& fontStack) const { + return boost::hash_range(fontStack.begin(), fontStack.end()); +} + +} // namespace mbgl |