[core] Add style bindings for "text-writing-mode" layout property

This commit is contained in:
Alexander Shalamov
2019-06-14 13:55:51 +03:00
parent fc94852b28
commit 075d458403
9 changed files with 59 additions and 2 deletions

View File

@@ -186,6 +186,10 @@ public:
const PropertyValue<std::vector<TextVariableAnchorType>>& getTextVariableAnchor() const;
void setTextVariableAnchor(const PropertyValue<std::vector<TextVariableAnchorType>>&);
static PropertyValue<std::vector<TextWritingModeType>> getDefaultTextWritingMode();
const PropertyValue<std::vector<TextWritingModeType>>& getTextWritingMode() const;
void setTextWritingMode(const PropertyValue<std::vector<TextWritingModeType>>&);
// Paint properties
static PropertyValue<Color> getDefaultIconColor();

View File

@@ -115,6 +115,11 @@ enum class IconTextFitType : uint8_t {
Height
};
enum class TextWritingModeType : uint8_t {
Horizontal,
Vertical
};
enum class LightAnchorType: bool {
Map,
Viewport

View File

@@ -86,6 +86,7 @@ template optional<TextTransformType> Converter<TextTransformType>::operator()(co
template optional<TranslateAnchorType> Converter<TranslateAnchorType>::operator()(const Convertible&, Error&) const;
template optional<VisibilityType> Converter<VisibilityType>::operator()(const Convertible&, Error&) const;
template optional<std::vector<TextVariableAnchorType>> Converter<std::vector<TextVariableAnchorType>>::operator()(const Convertible&, Error&) const;
template optional<std::vector<TextWritingModeType>> Converter<std::vector<TextWritingModeType>>::operator()(const Convertible&, Error&) const;
optional<Color> Converter<Color>::operator()(const Convertible& value, Error& error) const {
optional<std::string> string = toString(value);

View File

@@ -152,6 +152,8 @@ template optional<PropertyExpression<TranslateAnchorType>>
template optional<PropertyExpression<Formatted>>
convertFunctionToExpression<Formatted>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::vector<TextWritingModeType>>>
convertFunctionToExpression<std::vector<TextWritingModeType>>(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

View File

@@ -80,6 +80,7 @@ template optional<PropertyValue<TextJustifyType>> Converter<PropertyValue<TextJu
template optional<PropertyValue<TextTransformType>> Converter<PropertyValue<TextTransformType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<TranslateAnchorType>> Converter<PropertyValue<TranslateAnchorType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<mbgl::style::expression::Formatted>> Converter<PropertyValue<mbgl::style::expression::Formatted>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<std::vector<TextWritingModeType>>> Converter<PropertyValue<std::vector<TextWritingModeType>>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
} // namespace conversion
} // namespace style

View File

@@ -374,6 +374,9 @@ template struct ValueConverter<HillshadeIlluminationAnchorType>;
template type::Type valueTypeToExpressionType<LightAnchorType>();
template struct ValueConverter<LightAnchorType>;
template type::Type valueTypeToExpressionType<std::vector<TextWritingModeType>>();
template struct ValueConverter<std::vector<TextWritingModeType>>;
} // namespace expression
} // namespace style
} // namespace mbgl

View File

@@ -701,6 +701,22 @@ void SymbolLayer::setTextVariableAnchor(const PropertyValue<std::vector<TextVari
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
PropertyValue<std::vector<TextWritingModeType>> SymbolLayer::getDefaultTextWritingMode() {
return TextWritingMode::defaultValue();
}
const PropertyValue<std::vector<TextWritingModeType>>& SymbolLayer::getTextWritingMode() const {
return impl().layout.get<TextWritingMode>();
}
void SymbolLayer::setTextWritingMode(const PropertyValue<std::vector<TextWritingModeType>>& value) {
if (value == getTextWritingMode())
return;
auto impl_ = mutableImpl();
impl_->layout.get<TextWritingMode>() = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Paint properties
@@ -1387,6 +1403,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
TextSize,
TextTransform,
TextVariableAnchor,
TextWritingMode,
};
MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({
{ "icon-allow-overlap", static_cast<uint8_t>(Property::IconAllowOverlap) },
@@ -1428,7 +1445,8 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
{ "text-rotation-alignment", static_cast<uint8_t>(Property::TextRotationAlignment) },
{ "text-size", static_cast<uint8_t>(Property::TextSize) },
{ "text-transform", static_cast<uint8_t>(Property::TextTransform) },
{ "text-variable-anchor", static_cast<uint8_t>(Property::TextVariableAnchor) }
{ "text-variable-anchor", static_cast<uint8_t>(Property::TextVariableAnchor) },
{ "text-writing-mode", static_cast<uint8_t>(Property::TextWritingMode) }
});
const auto it = properties.find(name.c_str());
@@ -1763,6 +1781,18 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
if (property == Property::TextWritingMode) {
Error error;
optional<PropertyValue<std::vector<TextWritingModeType>>> typedValue = convert<PropertyValue<std::vector<TextWritingModeType>>>(value, error, false, false);
if (!typedValue) {
return error;
}
setTextWritingMode(*typedValue);
return nullopt;
}
return Error { "layer doesn't support this property" };
}

View File

@@ -214,6 +214,11 @@ struct TextVariableAnchor : LayoutProperty<std::vector<TextVariableAnchorType>>
static std::vector<TextVariableAnchorType> defaultValue() { return { }; }
};
struct TextWritingMode : LayoutProperty<std::vector<TextWritingModeType>> {
static constexpr const char *name() { return "text-writing-mode"; }
static std::vector<TextWritingModeType> defaultValue() { return { }; }
};
struct IconColor : DataDrivenPaintProperty<Color, attributes::fill_color, uniforms::fill_color> {
static Color defaultValue() { return Color::black(); }
};
@@ -313,7 +318,8 @@ class SymbolLayoutProperties : public Properties<
TextRotationAlignment,
TextSize,
TextTransform,
TextVariableAnchor
TextVariableAnchor,
TextWritingMode
> {};
class SymbolPaintProperties : public Properties<

View File

@@ -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" },