From 075d458403ba2c7367f06e5fc66c2a00c788634a Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Fri, 14 Jun 2019 13:55:51 +0300 Subject: [core] Add style bindings for "text-writing-mode" layout property --- include/mbgl/style/layers/symbol_layer.hpp | 4 +++ include/mbgl/style/types.hpp | 5 ++++ src/mbgl/style/conversion/constant.cpp | 1 + src/mbgl/style/conversion/function.cpp | 2 ++ src/mbgl/style/conversion/property_value.cpp | 1 + src/mbgl/style/expression/value.cpp | 3 +++ src/mbgl/style/layers/symbol_layer.cpp | 32 ++++++++++++++++++++++- src/mbgl/style/layers/symbol_layer_properties.hpp | 8 +++++- src/mbgl/style/types.cpp | 5 ++++ 9 files changed, 59 insertions(+), 2 deletions(-) diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 2493df6046..853c0b282e 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -186,6 +186,10 @@ public: const PropertyValue>& getTextVariableAnchor() const; void setTextVariableAnchor(const PropertyValue>&); + static PropertyValue> getDefaultTextWritingMode(); + const PropertyValue>& getTextWritingMode() const; + void setTextWritingMode(const PropertyValue>&); + // Paint properties static PropertyValue getDefaultIconColor(); diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 13a2e50f01..5d88dafb33 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -115,6 +115,11 @@ enum class IconTextFitType : uint8_t { Height }; +enum class TextWritingModeType : uint8_t { + Horizontal, + Vertical +}; + enum class LightAnchorType: bool { Map, Viewport diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp index 0fcaab433b..ffdb17858d 100644 --- a/src/mbgl/style/conversion/constant.cpp +++ b/src/mbgl/style/conversion/constant.cpp @@ -86,6 +86,7 @@ template optional Converter::operator()(co template optional Converter::operator()(const Convertible&, Error&) const; template optional Converter::operator()(const Convertible&, Error&) const; template optional> Converter>::operator()(const Convertible&, Error&) const; +template optional> Converter>::operator()(const Convertible&, Error&) const; optional Converter::operator()(const Convertible& value, Error& error) const { optional string = toString(value); diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 086bc4e277..646c1983a2 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -152,6 +152,8 @@ template optional> template optional> convertFunctionToExpression(const Convertible&, Error&, bool); +template optional>> + convertFunctionToExpression>(const Convertible&, Error&, bool); // Ad-hoc Converters for double and int64_t. We should replace float with double wholesale, // and promote the int64_t Converter to general use (and it should check that the input is diff --git a/src/mbgl/style/conversion/property_value.cpp b/src/mbgl/style/conversion/property_value.cpp index 6e1d747324..5c2f720a60 100644 --- a/src/mbgl/style/conversion/property_value.cpp +++ b/src/mbgl/style/conversion/property_value.cpp @@ -80,6 +80,7 @@ template optional> Converter> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; } // namespace conversion } // namespace style diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp index 7e11efaa09..6d18f1b9bd 100644 --- a/src/mbgl/style/expression/value.cpp +++ b/src/mbgl/style/expression/value.cpp @@ -374,6 +374,9 @@ template struct ValueConverter; template type::Type valueTypeToExpressionType(); template struct ValueConverter; +template type::Type valueTypeToExpressionType>(); +template struct ValueConverter>; + } // namespace expression } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 6748fbd4aa..4b335ead3c 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -701,6 +701,22 @@ void SymbolLayer::setTextVariableAnchor(const PropertyValueonLayerChanged(*this); } +PropertyValue> SymbolLayer::getDefaultTextWritingMode() { + return TextWritingMode::defaultValue(); +} + +const PropertyValue>& SymbolLayer::getTextWritingMode() const { + return impl().layout.get(); +} + +void SymbolLayer::setTextWritingMode(const PropertyValue>& value) { + if (value == getTextWritingMode()) + return; + auto impl_ = mutableImpl(); + impl_->layout.get() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} // Paint properties @@ -1387,6 +1403,7 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co TextSize, TextTransform, TextVariableAnchor, + TextWritingMode, }; MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ { "icon-allow-overlap", static_cast(Property::IconAllowOverlap) }, @@ -1428,7 +1445,8 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co { "text-rotation-alignment", static_cast(Property::TextRotationAlignment) }, { "text-size", static_cast(Property::TextSize) }, { "text-transform", static_cast(Property::TextTransform) }, - { "text-variable-anchor", static_cast(Property::TextVariableAnchor) } + { "text-variable-anchor", static_cast(Property::TextVariableAnchor) }, + { "text-writing-mode", static_cast(Property::TextWritingMode) } }); const auto it = properties.find(name.c_str()); @@ -1763,6 +1781,18 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co } + if (property == Property::TextWritingMode) { + Error error; + optional>> typedValue = convert>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setTextWritingMode(*typedValue); + return nullopt; + + } + return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 0c2bcd2661..59d65b3c86 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -214,6 +214,11 @@ struct TextVariableAnchor : LayoutProperty> static std::vector defaultValue() { return { }; } }; +struct TextWritingMode : LayoutProperty> { + static constexpr const char *name() { return "text-writing-mode"; } + static std::vector defaultValue() { return { }; } +}; + struct IconColor : DataDrivenPaintProperty { static Color defaultValue() { return Color::black(); } }; @@ -313,7 +318,8 @@ class SymbolLayoutProperties : public Properties< TextRotationAlignment, TextSize, TextTransform, - TextVariableAnchor + TextVariableAnchor, + TextWritingMode > {}; class SymbolPaintProperties : public Properties< diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp index f388a9385f..c4a7b76b66 100644 --- a/src/mbgl/style/types.cpp +++ b/src/mbgl/style/types.cpp @@ -96,6 +96,11 @@ MBGL_DEFINE_ENUM(TextTransformType, { { TextTransformType::Lowercase, "lowercase" }, }); +MBGL_DEFINE_ENUM(TextWritingModeType, { + { TextWritingModeType::Horizontal, "horizontal" }, + { TextWritingModeType::Vertical, "vertical" } +}); + MBGL_DEFINE_ENUM(AlignmentType, { { AlignmentType::Map, "map" }, { AlignmentType::Viewport, "viewport" }, -- cgit v1.2.1