[core] Enable property functions for text-{field,transform} (#7944)

This commit is contained in:
Anand Thakker
2017-02-17 16:16:25 -05:00
committed by John Firebaugh
parent d4c569a018
commit 062b18374d
23 changed files with 474 additions and 175 deletions

View File

@@ -72,8 +72,14 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
layout.get<IconSize>() = leader.layout.evaluate<IconSize>(PropertyEvaluationParameters(zoom + 1));
layout.get<TextSize>() = leader.layout.evaluate<TextSize>(PropertyEvaluationParameters(zoom + 1));
const bool hasTextField = layout.get<TextField>().match(
[&] (const std::string& s) { return !s.empty(); },
[&] (const auto&) { return true; }
);
const bool hasText = !layout.get<TextFont>().empty() && hasTextField;
const bool hasText = !layout.get<TextField>().empty() && !layout.get<TextFont>().empty();
const bool hasIcon = !layout.get<IconImage>().empty();
if (!hasText && !hasIcon) {
@@ -110,13 +116,18 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
return util::toString(value->get<double>());
return "null";
};
if (hasText) {
std::string u8string = util::replaceTokens(layout.get<TextField>(), getValue);
std::string u8string = layout.evaluate<TextField>(zoom, *feature);
if (layout.get<TextField>().isConstant()) {
u8string = util::replaceTokens(u8string, getValue);
}
auto textTransform = layout.evaluate<TextTransform>(zoom, *feature);
if (layout.get<TextTransform>() == TextTransformType::Uppercase) {
if (textTransform == TextTransformType::Uppercase) {
u8string = platform::uppercase(u8string);
} else if (layout.get<TextTransform>() == TextTransformType::Lowercase) {
} else if (textTransform == TextTransformType::Lowercase) {
u8string = platform::lowercase(u8string);
}
@@ -154,7 +165,12 @@ bool SymbolLayout::hasSymbolInstances() const {
}
bool SymbolLayout::canPrepare(GlyphAtlas& glyphAtlas) {
if (!layout.get<TextField>().empty() && !layout.get<TextFont>().empty() && !glyphAtlas.hasGlyphRanges(layout.get<TextFont>(), ranges)) {
const bool hasTextField = layout.get<TextField>().match(
[&] (const std::string& s) { return !s.empty(); },
[&] (const auto&) { return true; }
);
if (hasTextField && !layout.get<TextFont>().empty() && !glyphAtlas.hasGlyphRanges(layout.get<TextFont>(), ranges)) {
return false;
}

View File

@@ -1,4 +1,5 @@
#include <mbgl/style/function/categorical_stops.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/color.hpp>
#include <array>
@@ -30,6 +31,8 @@ optional<T> CategoricalStops<T>::evaluate(const Value& value) const {
template class CategoricalStops<float>;
template class CategoricalStops<Color>;
template class CategoricalStops<std::array<float, 2>>;
template class CategoricalStops<std::string>;
template class CategoricalStops<TextTransformType>;
} // namespace style
} // namespace mbgl

View File

@@ -1,4 +1,6 @@
#include <mbgl/style/function/identity_stops.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/color.hpp>
#include <array>
@@ -11,6 +13,15 @@ optional<float> IdentityStops<float>::evaluate(const Value& value) const {
return numericValue<float>(value);
}
template <>
optional<std::string> IdentityStops<std::string>::evaluate(const Value& value) const {
if (!value.is<std::string>()) {
return {};
}
return value.get<std::string>();
}
template <>
optional<Color> IdentityStops<Color>::evaluate(const Value& value) const {
if (!value.is<std::string>()) {
@@ -20,6 +31,15 @@ optional<Color> IdentityStops<Color>::evaluate(const Value& value) const {
return Color::parse(value.get<std::string>());
}
template <>
optional<TextTransformType> IdentityStops<TextTransformType>::evaluate(const Value& value) const {
if (!value.is<std::string>()) {
return {};
}
return Enum<TextTransformType>::toEnum(value.get<std::string>());
}
template <>
optional<std::array<float, 2>> IdentityStops<std::array<float, 2>>::evaluate(const Value& value) const {
if (!value.is<std::vector<Value>>()) {

View File

@@ -301,15 +301,15 @@ void SymbolLayer::setTextRotationAlignment(PropertyValue<AlignmentType> value) {
impl->layout.unevaluated.get<TextRotationAlignment>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotation-alignment");
}
PropertyValue<std::string> SymbolLayer::getDefaultTextField() {
DataDrivenPropertyValue<std::string> SymbolLayer::getDefaultTextField() {
return TextField::defaultValue();
}
PropertyValue<std::string> SymbolLayer::getTextField() const {
DataDrivenPropertyValue<std::string> SymbolLayer::getTextField() const {
return impl->layout.unevaluated.get<TextField>();
}
void SymbolLayer::setTextField(PropertyValue<std::string> value) {
void SymbolLayer::setTextField(DataDrivenPropertyValue<std::string> value) {
if (value == getTextField())
return;
impl->layout.unevaluated.get<TextField>() = value;
@@ -469,15 +469,15 @@ void SymbolLayer::setTextKeepUpright(PropertyValue<bool> value) {
impl->layout.unevaluated.get<TextKeepUpright>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "text-keep-upright");
}
PropertyValue<TextTransformType> SymbolLayer::getDefaultTextTransform() {
DataDrivenPropertyValue<TextTransformType> SymbolLayer::getDefaultTextTransform() {
return TextTransform::defaultValue();
}
PropertyValue<TextTransformType> SymbolLayer::getTextTransform() const {
DataDrivenPropertyValue<TextTransformType> SymbolLayer::getTextTransform() const {
return impl->layout.unevaluated.get<TextTransform>();
}
void SymbolLayer::setTextTransform(PropertyValue<TextTransformType> value) {
void SymbolLayer::setTextTransform(DataDrivenPropertyValue<TextTransformType> value) {
if (value == getTextTransform())
return;
impl->layout.unevaluated.get<TextTransform>() = value;

View File

@@ -95,7 +95,7 @@ struct TextRotationAlignment : LayoutProperty<AlignmentType> {
static AlignmentType defaultValue() { return AlignmentType::Auto; }
};
struct TextField : LayoutProperty<std::string> {
struct TextField : DataDrivenLayoutProperty<std::string> {
static constexpr const char * key = "text-field";
static std::string defaultValue() { return ""; }
};
@@ -155,7 +155,7 @@ struct TextKeepUpright : LayoutProperty<bool> {
static bool defaultValue() { return true; }
};
struct TextTransform : LayoutProperty<TextTransformType> {
struct TextTransform : DataDrivenLayoutProperty<TextTransformType> {
static constexpr const char * key = "text-transform";
static TextTransformType defaultValue() { return TextTransformType::None; }
};