[core] Add possibility of overriding paint properties inside format expression #14062
* [core] Add format override expression and formatted section to evaluation context * [core] Add textColor to TaggedString's formatted section * [core] Add FormatSectionOverrides and introduce overridable properties * [core] Populate symbol layer paint properties for text sections * [core] Add benchmark for style that uses text-color override * [core] Add unit test for FormatOverrideExpression * [core] Add unit test for FormatSectionOverrides
This commit is contained in:
@@ -51,6 +51,18 @@ static void API_renderStill_reuse_map(::benchmark::State& state) {
|
||||
}
|
||||
}
|
||||
|
||||
static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state) {
|
||||
RenderBenchmark bench;
|
||||
HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.fileSource, bench.threadPool };
|
||||
Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1,
|
||||
bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) };
|
||||
prepare(map, util::read_file("benchmark/fixtures/api/style_formatted_labels.json"));
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
frontend.render(map);
|
||||
}
|
||||
}
|
||||
|
||||
static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
|
||||
RenderBenchmark bench;
|
||||
HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.fileSource, bench.threadPool };
|
||||
@@ -78,5 +90,6 @@ static void API_renderStill_recreate_map(::benchmark::State& state) {
|
||||
}
|
||||
|
||||
BENCHMARK(API_renderStill_reuse_map);
|
||||
BENCHMARK(API_renderStill_reuse_map_formatted_labels);
|
||||
BENCHMARK(API_renderStill_reuse_map_switch_styles);
|
||||
BENCHMARK(API_renderStill_recreate_map);
|
||||
|
||||
3993
benchmark/fixtures/api/style_formatted_labels.json
Normal file
3993
benchmark/fixtures/api/style_formatted_labels.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@ static void Parse_Filter(benchmark::State& state) {
|
||||
static void Parse_EvaluateFilter(benchmark::State& state) {
|
||||
const style::Filter filter = parse(R"FILTER(["==", "foo", "bar"])FILTER");
|
||||
const StubGeometryTileFeature feature = { {}, FeatureType::Unknown , {}, {{ "foo", std::string("bar") }} };
|
||||
const style::expression::EvaluationContext context = { &feature };
|
||||
const style::expression::EvaluationContext context(&feature);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
filter(context);
|
||||
|
||||
@@ -25,18 +25,26 @@ public:
|
||||
|
||||
class EvaluationContext {
|
||||
public:
|
||||
EvaluationContext(float zoom_) : zoom(zoom_), feature(nullptr) {}
|
||||
EvaluationContext(GeometryTileFeature const * feature_) : zoom(optional<float>()), feature(feature_) {}
|
||||
EvaluationContext() = default;
|
||||
explicit EvaluationContext(float zoom_) : zoom(zoom_) {}
|
||||
explicit EvaluationContext(GeometryTileFeature const * feature_) : feature(feature_) {}
|
||||
EvaluationContext(float zoom_, GeometryTileFeature const * feature_) :
|
||||
zoom(zoom_), feature(feature_)
|
||||
{}
|
||||
EvaluationContext(optional<float> zoom_, GeometryTileFeature const * feature_, optional<double> colorRampParameter_) :
|
||||
zoom(std::move(zoom_)), feature(feature_), colorRampParameter(std::move(colorRampParameter_))
|
||||
{}
|
||||
|
||||
|
||||
EvaluationContext& withFormattedSection(const Value* formattedSection_) noexcept {
|
||||
formattedSection = formattedSection_;
|
||||
return *this;
|
||||
};
|
||||
|
||||
optional<float> zoom;
|
||||
GeometryTileFeature const * feature;
|
||||
GeometryTileFeature const * feature = nullptr;
|
||||
optional<double> colorRampParameter;
|
||||
// Contains formatted section object, std::unordered_map<std::string, Value>.
|
||||
const Value* formattedSection = nullptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -134,6 +142,7 @@ enum class Kind : int32_t {
|
||||
All,
|
||||
Comparison,
|
||||
FormatExpression,
|
||||
FormatSectionOverride
|
||||
};
|
||||
|
||||
class Expression {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
#include <mbgl/style/expression/parsing_context.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -14,16 +10,18 @@ namespace expression {
|
||||
struct FormatExpressionSection {
|
||||
FormatExpressionSection(std::unique_ptr<Expression> text_,
|
||||
optional<std::unique_ptr<Expression>> fontScale_,
|
||||
optional<std::unique_ptr<Expression>> textFont_);
|
||||
optional<std::unique_ptr<Expression>> textFont_,
|
||||
optional<std::unique_ptr<Expression>> textColor_);
|
||||
|
||||
std::shared_ptr<Expression> text;
|
||||
optional<std::shared_ptr<Expression>> fontScale;
|
||||
optional<std::shared_ptr<Expression>> textFont;
|
||||
optional<std::shared_ptr<Expression>> textColor;
|
||||
};
|
||||
|
||||
class FormatExpression : public Expression {
|
||||
class FormatExpression final : public Expression {
|
||||
public:
|
||||
FormatExpression(std::vector<FormatExpressionSection> sections);
|
||||
explicit FormatExpression(std::vector<FormatExpressionSection> sections);
|
||||
|
||||
EvaluationResult evaluate(const EvaluationContext&) const override;
|
||||
static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&);
|
||||
@@ -38,13 +36,12 @@ public:
|
||||
return { nullopt };
|
||||
}
|
||||
|
||||
const std::vector<FormatExpressionSection>& getSections() const { return sections; }
|
||||
|
||||
mbgl::Value serialize() const override;
|
||||
std::string getOperator() const override { return "format"; }
|
||||
private:
|
||||
std::vector<FormatExpressionSection> sections;
|
||||
std::unique_ptr<Expression> text;
|
||||
optional<std::unique_ptr<Expression>> fontScale;
|
||||
optional<std::unique_ptr<Expression>> textFont;
|
||||
};
|
||||
|
||||
} // namespace expression
|
||||
|
||||
82
include/mbgl/style/expression/format_section_override.hpp
Normal file
82
include/mbgl/style/expression/format_section_override.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/renderer/possibly_evaluated_property_value.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace expression {
|
||||
|
||||
template<class T>
|
||||
class FormatSectionOverride final : public Expression {
|
||||
public:
|
||||
FormatSectionOverride(const type::Type& type_,
|
||||
PossiblyEvaluatedPropertyValue<T> defaultValue_,
|
||||
std::string propertyName_) :
|
||||
Expression(Kind::FormatSectionOverride, type_),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
propertyName(std::move(propertyName_))
|
||||
{}
|
||||
|
||||
EvaluationResult evaluate(const EvaluationContext& context) const final {
|
||||
using Object = std::unordered_map<std::string, expression::Value>;
|
||||
if (context.formattedSection &&
|
||||
context.formattedSection->is<Object>()) {
|
||||
const auto& section = context.formattedSection->get<Object>();
|
||||
if (section.find(propertyName) != section.end()) {
|
||||
return section.at(propertyName);
|
||||
}
|
||||
}
|
||||
return defaultValue.evaluate(*context.feature, *context.zoom, T());
|
||||
}
|
||||
|
||||
void eachChild(const std::function<void(const Expression&)>& fn) const final {
|
||||
defaultValue.match([&fn] (const style::PropertyExpression<T>& e) { fn(e.getExpression()); },
|
||||
[] (const T&) {});
|
||||
}
|
||||
|
||||
bool operator==(const Expression& e) const final {
|
||||
if (e.getKind() == Kind::FormatSectionOverride) {
|
||||
const auto* other = static_cast<const FormatSectionOverride*>(&e);
|
||||
|
||||
if (getType() != other->getType() || propertyName != other->propertyName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that default values or property expressions are equal.
|
||||
return defaultValue.match(
|
||||
[other] (const style::PropertyExpression<T>& thisExpr) {
|
||||
return other->defaultValue.match([&thisExpr] (const style::PropertyExpression<T>& otherExpr) {
|
||||
return thisExpr == otherExpr;
|
||||
},
|
||||
[] (const T&) {
|
||||
return false;
|
||||
});
|
||||
},
|
||||
[other] (const T& thisValue) {
|
||||
return other->defaultValue.match([&thisValue] (const T& otherValue) {
|
||||
return thisValue == otherValue;
|
||||
},
|
||||
[] (const style::PropertyExpression<T>&) {
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<optional<Value>> possibleOutputs() const final {
|
||||
return {nullopt};
|
||||
}
|
||||
|
||||
std::string getOperator() const final { return "format-section-override"; }
|
||||
|
||||
private:
|
||||
PossiblyEvaluatedPropertyValue<T> defaultValue;
|
||||
std::string propertyName;
|
||||
};
|
||||
|
||||
} // namespace expression
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/util/color.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -12,15 +12,25 @@ namespace mbgl {
|
||||
namespace style {
|
||||
namespace expression {
|
||||
|
||||
extern const char* const kFormattedSectionFontScale;
|
||||
extern const char* const kFormattedSectionTextFont;
|
||||
extern const char* const kFormattedSectionTextColor;
|
||||
|
||||
struct FormattedSection {
|
||||
FormattedSection(std::string text_, optional<double> fontScale_, optional<FontStack> fontStack_)
|
||||
FormattedSection(std::string text_,
|
||||
optional<double> fontScale_,
|
||||
optional<FontStack> fontStack_,
|
||||
optional<Color> textColor_)
|
||||
: text(std::move(text_))
|
||||
, fontScale(std::move(fontScale_))
|
||||
, fontStack(std::move(fontStack_))
|
||||
, textColor(std::move(textColor_))
|
||||
{}
|
||||
|
||||
std::string text;
|
||||
optional<double> fontScale;
|
||||
optional<FontStack> fontStack;
|
||||
optional<Color> textColor;
|
||||
};
|
||||
|
||||
class Formatted {
|
||||
@@ -28,7 +38,7 @@ public:
|
||||
Formatted() = default;
|
||||
|
||||
Formatted(const char* plainU8String) {
|
||||
sections.emplace_back(std::string(plainU8String), nullopt, nullopt);
|
||||
sections.emplace_back(std::string(plainU8String), nullopt, nullopt, nullopt);
|
||||
}
|
||||
|
||||
Formatted(std::vector<FormattedSection> sections_)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/value.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/expression/interpolate.hpp>
|
||||
#include <mbgl/style/expression/step.hpp>
|
||||
@@ -11,106 +10,68 @@
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
class PropertyExpressionBase {
|
||||
public:
|
||||
explicit PropertyExpressionBase(std::unique_ptr<expression::Expression>);
|
||||
|
||||
bool isZoomConstant() const noexcept;
|
||||
bool isFeatureConstant() const noexcept;
|
||||
bool canEvaluateWith(const expression::EvaluationContext&) const noexcept;
|
||||
float interpolationFactor(const Range<float>&, const float) const noexcept;
|
||||
Range<float> getCoveringStops(const float, const float) const noexcept;
|
||||
const expression::Expression& getExpression() const noexcept;
|
||||
|
||||
bool useIntegerZoom = false;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<const expression::Expression> expression;
|
||||
variant<std::nullptr_t, const expression::Interpolate*, const expression::Step*> zoomCurve;
|
||||
bool isZoomConstant_;
|
||||
bool isFeatureConstant_;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class PropertyExpression {
|
||||
class PropertyExpression final : public PropertyExpressionBase {
|
||||
public:
|
||||
// Second parameter to be used only for conversions from legacy functions.
|
||||
PropertyExpression(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {})
|
||||
: expression(std::move(expression_)),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get())) {
|
||||
PropertyExpression(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = nullopt)
|
||||
: PropertyExpressionBase(std::move(expression_)),
|
||||
defaultValue(std::move(defaultValue_)) {
|
||||
}
|
||||
|
||||
bool isZoomConstant() const { return expression::isZoomConstant(*expression); }
|
||||
bool isFeatureConstant() const { return expression::isFeatureConstant(*expression); }
|
||||
T evaluate(const expression::EvaluationContext& context, T finalDefaultValue = T()) const {
|
||||
assert(canEvaluateWith(context));
|
||||
const expression::EvaluationResult result = expression->evaluate(context);
|
||||
if (result) {
|
||||
const optional<T> typed = expression::fromExpressionValue<T>(*result);
|
||||
return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue;
|
||||
}
|
||||
return defaultValue ? *defaultValue : finalDefaultValue;
|
||||
}
|
||||
|
||||
T evaluate(float zoom) const {
|
||||
assert(!expression::isZoomConstant(*expression));
|
||||
assert(expression::isFeatureConstant(*expression));
|
||||
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(zoom, nullptr));
|
||||
if (result) {
|
||||
const optional<T> typed = expression::fromExpressionValue<T>(*result);
|
||||
return typed ? *typed : defaultValue ? *defaultValue : T();
|
||||
}
|
||||
return defaultValue ? *defaultValue : T();
|
||||
return evaluate(expression::EvaluationContext(zoom));
|
||||
}
|
||||
|
||||
template <class Feature>
|
||||
T evaluate(const Feature& feature, T finalDefaultValue) const {
|
||||
assert(expression::isZoomConstant(*expression));
|
||||
assert(!expression::isFeatureConstant(*expression));
|
||||
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature));
|
||||
if (result) {
|
||||
const optional<T> typed = expression::fromExpressionValue<T>(*result);
|
||||
return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue;
|
||||
}
|
||||
return defaultValue ? *defaultValue : finalDefaultValue;
|
||||
T evaluate(const GeometryTileFeature& feature, T finalDefaultValue) const {
|
||||
return evaluate(expression::EvaluationContext(&feature), finalDefaultValue);
|
||||
}
|
||||
|
||||
template <class Feature>
|
||||
T evaluate(float zoom, const Feature& feature, T finalDefaultValue) const {
|
||||
assert(!expression::isFeatureConstant(*expression));
|
||||
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext({zoom}, &feature));
|
||||
if (result) {
|
||||
const optional<T> typed = expression::fromExpressionValue<T>(*result);
|
||||
return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue;
|
||||
}
|
||||
return defaultValue ? *defaultValue : finalDefaultValue;
|
||||
}
|
||||
|
||||
float interpolationFactor(const Range<float>& inputLevels, const float inputValue) const {
|
||||
return zoomCurve.match(
|
||||
[](std::nullptr_t) {
|
||||
assert(false);
|
||||
return 0.0f;
|
||||
},
|
||||
[&](const expression::Interpolate* z) {
|
||||
return z->interpolationFactor(Range<double> { inputLevels.min, inputLevels.max }, inputValue);
|
||||
},
|
||||
[&](const expression::Step*) {
|
||||
return 0.0f;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Range<float> getCoveringStops(const float lower, const float upper) const {
|
||||
return zoomCurve.match(
|
||||
[](std::nullptr_t) {
|
||||
assert(false);
|
||||
return Range<float>(0.0f, 0.0f);
|
||||
},
|
||||
[&](auto z) {
|
||||
return z->getCoveringStops(lower, upper);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Return the range obtained by evaluating the function at each of the zoom levels in zoomRange
|
||||
template <class Feature>
|
||||
Range<T> evaluate(const Range<float>& zoomRange, const Feature& feature, T finalDefaultValue) {
|
||||
return Range<T> {
|
||||
evaluate(zoomRange.min, feature, finalDefaultValue),
|
||||
evaluate(zoomRange.max, feature, finalDefaultValue)
|
||||
};
|
||||
T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const {
|
||||
return evaluate(expression::EvaluationContext(zoom, &feature), finalDefaultValue);
|
||||
}
|
||||
|
||||
std::vector<optional<T>> possibleOutputs() const {
|
||||
return expression::fromExpressionValues<T>(expression->possibleOutputs());
|
||||
}
|
||||
|
||||
const expression::Expression& getExpression() const { return *expression; }
|
||||
|
||||
bool useIntegerZoom = false;
|
||||
|
||||
friend bool operator==(const PropertyExpression& lhs,
|
||||
const PropertyExpression& rhs) {
|
||||
return *lhs.expression == *rhs.expression;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<const expression::Expression> expression;
|
||||
optional<T> defaultValue;
|
||||
variant<std::nullptr_t, const expression::Interpolate*, const expression::Step*> zoomCurve;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -19,6 +19,29 @@ global.isLightProperty = function (property) {
|
||||
return property['light-property'] === true;
|
||||
};
|
||||
|
||||
global.isOverridable = function (property) {
|
||||
return ['text-color'].includes(property.name);
|
||||
};
|
||||
|
||||
global.expressionType = function (property) {
|
||||
switch (property.type) {
|
||||
case 'boolean':
|
||||
return 'BooleanType';
|
||||
case 'number':
|
||||
case 'enum':
|
||||
return 'NumberType';
|
||||
case 'string':
|
||||
return 'StringType';
|
||||
case 'color':
|
||||
return `ColorType`;
|
||||
case 'formatted':
|
||||
return `FormattedType`;
|
||||
case 'array':
|
||||
return `Array<${expressionType({type: property.value})}>`;
|
||||
default: throw new Error(`unknown type for ${property.name}`)
|
||||
}
|
||||
};
|
||||
|
||||
global.evaluatedType = function (property) {
|
||||
if (/-translate-anchor$/.test(property.name)) {
|
||||
return 'TranslateAnchorType';
|
||||
@@ -93,6 +116,8 @@ global.layoutPropertyType = function (property) {
|
||||
global.paintPropertyType = function (property, type) {
|
||||
switch (property['property-type']) {
|
||||
case 'data-driven':
|
||||
if (isOverridable(property))
|
||||
return `DataDrivenPaintProperty<${evaluatedType(property)}, ${attributeUniformType(property, type)}, true>`;
|
||||
return `DataDrivenPaintProperty<${evaluatedType(property)}, ${attributeUniformType(property, type)}>`;
|
||||
case 'cross-faded-data-driven':
|
||||
return `CrossFadedDataDrivenPaintProperty<${evaluatedType(property)}, ${attributeUniformType(property, type)}>`;
|
||||
|
||||
@@ -225,6 +225,7 @@
|
||||
"src/mbgl/style/light.cpp",
|
||||
"src/mbgl/style/light_impl.cpp",
|
||||
"src/mbgl/style/parser.cpp",
|
||||
"src/mbgl/style/property_expression.cpp",
|
||||
"src/mbgl/style/source.cpp",
|
||||
"src/mbgl/style/source_impl.cpp",
|
||||
"src/mbgl/style/sources/custom_geometry_source.cpp",
|
||||
@@ -390,6 +391,7 @@
|
||||
"mbgl/style/expression/expression.hpp": "include/mbgl/style/expression/expression.hpp",
|
||||
"mbgl/style/expression/find_zoom_curve.hpp": "include/mbgl/style/expression/find_zoom_curve.hpp",
|
||||
"mbgl/style/expression/format_expression.hpp": "include/mbgl/style/expression/format_expression.hpp",
|
||||
"mbgl/style/expression/format_section_override.hpp": "include/mbgl/style/expression/format_section_override.hpp",
|
||||
"mbgl/style/expression/formatted.hpp": "include/mbgl/style/expression/formatted.hpp",
|
||||
"mbgl/style/expression/get_covering_stops.hpp": "include/mbgl/style/expression/get_covering_stops.hpp",
|
||||
"mbgl/style/expression/interpolate.hpp": "include/mbgl/style/expression/interpolate.hpp",
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
#include <mbgl/layout/layout.hpp>
|
||||
#include <mbgl/layout/symbol_layout.hpp>
|
||||
#include <mbgl/layout/merge_lines.hpp>
|
||||
#include <mbgl/layout/clip_lines.hpp>
|
||||
#include <mbgl/renderer/buckets/symbol_bucket.hpp>
|
||||
#include <mbgl/renderer/bucket_parameters.hpp>
|
||||
#include <mbgl/renderer/layers/render_symbol_layer.hpp>
|
||||
#include <mbgl/renderer/image_atlas.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
#include <mbgl/text/get_anchors.hpp>
|
||||
#include <mbgl/text/shaping.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/utf.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/i18n.hpp>
|
||||
#include <mbgl/math/clamp.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
#include <mbgl/math/log2.hpp>
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
|
||||
#include <mapbox/polylabel.hpp>
|
||||
@@ -31,11 +22,27 @@ using namespace style;
|
||||
template <class Property>
|
||||
static bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) {
|
||||
return layout.get<Property>().match(
|
||||
[&] (const typename Property::Type& t) { return !t.empty(); },
|
||||
[&] (const auto&) { return true; }
|
||||
[] (const typename Property::Type& t) { return !t.empty(); },
|
||||
[] (const auto&) { return true; }
|
||||
);
|
||||
}
|
||||
|
||||
namespace {
|
||||
expression::Value sectionOptionsToValue(const SectionOptions& options) {
|
||||
std::unordered_map<std::string, expression::Value> result;
|
||||
// TODO: Data driven properties that can be overridden on per section basis.
|
||||
// TextOpacity
|
||||
// TextHaloColor
|
||||
// TextHaloWidth
|
||||
// TextHaloBlur
|
||||
if (options.textColor) {
|
||||
result.emplace(expression::kFormattedSectionTextColor, *options.textColor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
std::unique_ptr<GeometryTileLayer> sourceLayer_,
|
||||
@@ -108,7 +115,6 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
auto formatted = layout.evaluate<TextField>(zoom, ft);
|
||||
auto textTransform = layout.evaluate<TextTransform>(zoom, ft);
|
||||
FontStack baseFontStack = layout.evaluate<TextFont>(zoom, ft);
|
||||
FontStackHash baseFontStackHash = FontStackHasher()(baseFontStack);
|
||||
|
||||
ft.formattedText = TaggedString();
|
||||
for (std::size_t j = 0; j < formatted.sections.size(); j++) {
|
||||
@@ -122,8 +128,8 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
|
||||
ft.formattedText->addSection(applyArabicShaping(util::convertUTF8ToUTF16(u8string)),
|
||||
section.fontScale ? *section.fontScale : 1.0,
|
||||
section.fontStack ? FontStackHasher()(*section.fontStack) : baseFontStackHash);
|
||||
|
||||
section.fontStack ? *section.fontStack : baseFontStack,
|
||||
section.textColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -273,6 +279,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex,
|
||||
: layout.get<SymbolPlacement>();
|
||||
|
||||
const float textRepeatDistance = symbolSpacing / 2;
|
||||
const auto evaluatedLayoutProperties = layout.evaluate(zoom, feature);
|
||||
IndexedSubfeature indexedFeature(feature.index, sourceLayer->getName(), bucketLeaderID, symbolInstances.size());
|
||||
|
||||
auto addSymbolInstance = [&] (const GeometryCoordinates& line, Anchor& anchor) {
|
||||
@@ -285,7 +292,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex,
|
||||
// (1) render symbols that overlap into this tile
|
||||
// (2) approximate collision detection effects from neighboring symbols
|
||||
symbolInstances.emplace_back(anchor, line, shapedTextOrientations, shapedIcon,
|
||||
layout.evaluate(zoom, feature), layoutTextSize,
|
||||
evaluatedLayoutProperties, layoutTextSize,
|
||||
textBoxScale, textPadding, textPlacement, textOffset,
|
||||
iconBoxScale, iconPadding, iconOffset,
|
||||
glyphPositions, indexedFeature, layoutFeatureIndex, feature.index,
|
||||
@@ -418,43 +425,14 @@ void SymbolLayout::createBucket(const ImagePositions&, std::unique_ptr<FeatureIn
|
||||
|
||||
// Insert final placement into collision tree and add glyphs/icons to buffers
|
||||
|
||||
if (hasText) {
|
||||
const Range<float> sizeData = bucket->textSizeBinder->getVertexSizeData(feature);
|
||||
bucket->text.placedSymbols.emplace_back(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max,
|
||||
symbolInstance.textOffset, symbolInstance.writingModes, symbolInstance.line, CalculateTileDistances(symbolInstance.line, symbolInstance.anchor));
|
||||
symbolInstance.placedTextIndex = bucket->text.placedSymbols.size() - 1;
|
||||
PlacedSymbol& horizontalSymbol = bucket->text.placedSymbols.back();
|
||||
|
||||
bool firstHorizontal = true;
|
||||
for (const auto& symbol : symbolInstance.horizontalGlyphQuads) {
|
||||
size_t index = addSymbol(
|
||||
bucket->text, sizeData, symbol,
|
||||
symbolInstance.anchor, horizontalSymbol);
|
||||
if (firstHorizontal) {
|
||||
horizontalSymbol.vertexStartIndex = index;
|
||||
firstHorizontal = false;
|
||||
}
|
||||
}
|
||||
if (hasText && feature.formattedText) {
|
||||
std::size_t index = addSymbolGlyphQuads(*bucket, symbolInstance, feature, symbolInstance.writingModes, symbolInstance.placedTextIndex, symbolInstance.horizontalGlyphQuads);
|
||||
|
||||
if (symbolInstance.writingModes & WritingModeType::Vertical) {
|
||||
bucket->text.placedSymbols.emplace_back(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max,
|
||||
symbolInstance.textOffset, WritingModeType::Vertical, symbolInstance.line, CalculateTileDistances(symbolInstance.line, symbolInstance.anchor));
|
||||
symbolInstance.placedVerticalTextIndex = bucket->text.placedSymbols.size() - 1;
|
||||
|
||||
PlacedSymbol& verticalSymbol = bucket->text.placedSymbols.back();
|
||||
bool firstVertical = true;
|
||||
|
||||
for (const auto& symbol : symbolInstance.verticalGlyphQuads) {
|
||||
size_t index = addSymbol(
|
||||
bucket->text, sizeData, symbol,
|
||||
symbolInstance.anchor, verticalSymbol);
|
||||
|
||||
if (firstVertical) {
|
||||
verticalSymbol.vertexStartIndex = index;
|
||||
firstVertical = false;
|
||||
}
|
||||
}
|
||||
index = addSymbolGlyphQuads(*bucket, symbolInstance, feature, WritingModeType::Vertical, symbolInstance.placedVerticalTextIndex, symbolInstance.verticalGlyphQuads, index);
|
||||
}
|
||||
|
||||
updatePaintPropertiesForSection(*bucket, feature, index);
|
||||
}
|
||||
|
||||
if (hasIcon) {
|
||||
@@ -466,12 +444,11 @@ void SymbolLayout::createBucket(const ImagePositions&, std::unique_ptr<FeatureIn
|
||||
PlacedSymbol& iconSymbol = bucket->icon.placedSymbols.back();
|
||||
iconSymbol.vertexStartIndex = addSymbol(bucket->icon, sizeData, *symbolInstance.iconQuad,
|
||||
symbolInstance.anchor, iconSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& pair : bucket->paintProperties) {
|
||||
pair.second.iconBinders.populateVertexVectors(feature, bucket->icon.vertices.elements(), {}, {});
|
||||
pair.second.textBinders.populateVertexVectors(feature, bucket->text.vertices.elements(), {}, {});
|
||||
for (auto& pair : bucket->paintProperties) {
|
||||
pair.second.iconBinders.populateVertexVectors(feature, bucket->icon.vertices.elements(), {}, {});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,12 +466,53 @@ void SymbolLayout::createBucket(const ImagePositions&, std::unique_ptr<FeatureIn
|
||||
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
size_t SymbolLayout::addSymbol(Buffer& buffer,
|
||||
const Range<float> sizeData,
|
||||
const SymbolQuad& symbol,
|
||||
const Anchor& labelAnchor,
|
||||
PlacedSymbol& placedSymbol) {
|
||||
void SymbolLayout::updatePaintPropertiesForSection(SymbolBucket& bucket,
|
||||
const SymbolFeature& feature,
|
||||
std::size_t sectionIndex) {
|
||||
const auto& formattedSection = sectionOptionsToValue((*feature.formattedText).sectionAt(sectionIndex));
|
||||
for (auto& pair : bucket.paintProperties) {
|
||||
pair.second.textBinders.populateVertexVectors(feature, bucket.text.vertices.elements(), {}, {}, formattedSection);
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t SymbolLayout::addSymbolGlyphQuads(SymbolBucket& bucket,
|
||||
SymbolInstance& symbolInstance,
|
||||
const SymbolFeature& feature,
|
||||
WritingModeType writingMode,
|
||||
optional<size_t>& placedIndex,
|
||||
const SymbolQuads& glyphQuads,
|
||||
optional<std::size_t> lastAddedSection) {
|
||||
const Range<float> sizeData = bucket.textSizeBinder->getVertexSizeData(feature);
|
||||
const bool hasFormatSectionOverrides = bucket.hasFormatSectionOverrides();
|
||||
|
||||
bucket.text.placedSymbols.emplace_back(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max,
|
||||
symbolInstance.textOffset, writingMode, symbolInstance.line, CalculateTileDistances(symbolInstance.line, symbolInstance.anchor));
|
||||
placedIndex = bucket.text.placedSymbols.size() - 1;
|
||||
PlacedSymbol& placedSymbol = bucket.text.placedSymbols.back();
|
||||
|
||||
bool firstSymbol = true;
|
||||
for (const auto& symbolQuad : glyphQuads) {
|
||||
if (hasFormatSectionOverrides) {
|
||||
if (lastAddedSection && *lastAddedSection != symbolQuad.sectionIndex) {
|
||||
updatePaintPropertiesForSection(bucket, feature, *lastAddedSection);
|
||||
}
|
||||
lastAddedSection = symbolQuad.sectionIndex;
|
||||
}
|
||||
size_t index = addSymbol(bucket.text, sizeData, symbolQuad, symbolInstance.anchor, placedSymbol);
|
||||
if (firstSymbol) {
|
||||
placedSymbol.vertexStartIndex = index;
|
||||
firstSymbol = false;
|
||||
}
|
||||
}
|
||||
|
||||
return lastAddedSection ? *lastAddedSection : 0u;
|
||||
}
|
||||
|
||||
size_t SymbolLayout::addSymbol(SymbolBucket::Buffer& buffer,
|
||||
const Range<float> sizeData,
|
||||
const SymbolQuad& symbol,
|
||||
const Anchor& labelAnchor,
|
||||
PlacedSymbol& placedSymbol) {
|
||||
constexpr const uint16_t vertexLength = 4;
|
||||
|
||||
const auto &tl = symbol.tl;
|
||||
|
||||
@@ -6,18 +6,15 @@
|
||||
#include <mbgl/layout/symbol_feature.hpp>
|
||||
#include <mbgl/layout/symbol_instance.hpp>
|
||||
#include <mbgl/text/bidi.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
#include <mbgl/programs/symbol_program.hpp>
|
||||
#include <mbgl/renderer/buckets/symbol_bucket.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class BucketParameters;
|
||||
class SymbolBucket;
|
||||
class Anchor;
|
||||
class RenderLayer;
|
||||
class PlacedSymbol;
|
||||
@@ -26,7 +23,7 @@ namespace style {
|
||||
class Filter;
|
||||
} // namespace style
|
||||
|
||||
class SymbolLayout : public Layout {
|
||||
class SymbolLayout final : public Layout {
|
||||
public:
|
||||
SymbolLayout(const BucketParameters&,
|
||||
const std::vector<const RenderLayer*>&,
|
||||
@@ -62,12 +59,25 @@ private:
|
||||
void addToDebugBuffers(SymbolBucket&);
|
||||
|
||||
// Adds placed items to the buffer.
|
||||
template <typename Buffer>
|
||||
size_t addSymbol(Buffer&,
|
||||
const Range<float> sizeData,
|
||||
const SymbolQuad&,
|
||||
const Anchor& labelAnchor,
|
||||
PlacedSymbol& placedSymbol);
|
||||
size_t addSymbol(SymbolBucket::Buffer&,
|
||||
const Range<float> sizeData,
|
||||
const SymbolQuad&,
|
||||
const Anchor& labelAnchor,
|
||||
PlacedSymbol& placedSymbol);
|
||||
|
||||
// Adds symbol quads to bucket and returns formatted section index of last
|
||||
// added quad.
|
||||
std::size_t addSymbolGlyphQuads(SymbolBucket&,
|
||||
SymbolInstance&,
|
||||
const SymbolFeature&,
|
||||
WritingModeType,
|
||||
optional<size_t>& placedIndex,
|
||||
const SymbolQuads&,
|
||||
optional<std::size_t> lastAddedSection = nullopt);
|
||||
|
||||
void updatePaintPropertiesForSection(SymbolBucket&,
|
||||
const SymbolFeature&,
|
||||
std::size_t sectionIndex);
|
||||
|
||||
// Stores the layer so that we can hold on to GeometryTileFeature instances in SymbolFeature,
|
||||
// which may reference data from this object.
|
||||
|
||||
@@ -28,13 +28,17 @@ SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layo
|
||||
iconSizeBinder(SymbolSizeBinder::create(zoom, iconSize, IconSize::defaultValue())) {
|
||||
|
||||
for (const auto& pair : paintProperties_) {
|
||||
auto layerPaintProperties = pair.second;
|
||||
if (hasFormatSectionOverrides()) {
|
||||
setPaintPropertyOverrides(layerPaintProperties);
|
||||
}
|
||||
paintProperties.emplace(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(pair.first),
|
||||
std::forward_as_tuple(PaintProperties {
|
||||
pair.second,
|
||||
{ RenderSymbolLayer::iconPaintProperties(pair.second), zoom },
|
||||
{ RenderSymbolLayer::textPaintProperties(pair.second), zoom }
|
||||
layerPaintProperties,
|
||||
{ RenderSymbolLayer::iconPaintProperties(layerPaintProperties), zoom },
|
||||
{ RenderSymbolLayer::textPaintProperties(layerPaintProperties), zoom }
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -226,4 +230,23 @@ void SymbolBucket::sortFeatures(const float angle) {
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolBucket::updatePaintProperties(const std::string& layerID,
|
||||
style::SymbolPaintProperties::PossiblyEvaluated updated) {
|
||||
if (hasFormatSectionOverrides()) {
|
||||
SymbolLayerPaintPropertyOverrides::updateOverrides(paintProperties.at(layerID).evaluated, updated);
|
||||
}
|
||||
paintProperties.at(layerID).evaluated = updated;
|
||||
}
|
||||
|
||||
void SymbolBucket::setPaintPropertyOverrides(style::SymbolPaintProperties::PossiblyEvaluated& paint) {
|
||||
SymbolLayerPaintPropertyOverrides::setOverrides(layout, paint);
|
||||
}
|
||||
|
||||
bool SymbolBucket::hasFormatSectionOverrides() {
|
||||
if (!hasFormatSectionOverrides_) {
|
||||
hasFormatSectionOverrides_= SymbolLayerPaintPropertyOverrides::hasOverrides(layout.get<TextField>());
|
||||
}
|
||||
return *hasFormatSectionOverrides_;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -58,6 +58,10 @@ public:
|
||||
bool hasIconData() const;
|
||||
bool hasCollisionBoxData() const;
|
||||
bool hasCollisionCircleData() const;
|
||||
bool hasFormatSectionOverrides();
|
||||
void updatePaintProperties(const std::string& layerID,
|
||||
style::SymbolPaintProperties::PossiblyEvaluated);
|
||||
void setPaintPropertyOverrides(style::SymbolPaintProperties::PossiblyEvaluated&);
|
||||
|
||||
void updateOpacity();
|
||||
void sortFeatures(const float angle);
|
||||
@@ -87,7 +91,7 @@ public:
|
||||
|
||||
std::unique_ptr<SymbolSizeBinder> textSizeBinder;
|
||||
|
||||
struct TextBuffer {
|
||||
struct Buffer {
|
||||
gfx::VertexVector<SymbolLayoutVertex> vertices;
|
||||
gfx::VertexVector<gfx::Vertex<SymbolDynamicLayoutAttributes>> dynamicVertices;
|
||||
gfx::VertexVector<gfx::Vertex<SymbolOpacityAttributes>> opacityVertices;
|
||||
@@ -103,19 +107,8 @@ public:
|
||||
|
||||
std::unique_ptr<SymbolSizeBinder> iconSizeBinder;
|
||||
|
||||
struct IconBuffer {
|
||||
gfx::VertexVector<SymbolLayoutVertex> vertices;
|
||||
gfx::VertexVector<gfx::Vertex<SymbolDynamicLayoutAttributes>> dynamicVertices;
|
||||
gfx::VertexVector<gfx::Vertex<SymbolOpacityAttributes>> opacityVertices;
|
||||
gfx::IndexVector<gfx::Triangles> triangles;
|
||||
SegmentVector<SymbolIconAttributes> segments;
|
||||
std::vector<PlacedSymbol> placedSymbols;
|
||||
struct IconBuffer : public Buffer {
|
||||
PremultipliedImage atlasImage;
|
||||
|
||||
optional<gfx::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
|
||||
optional<gfx::VertexBuffer<gfx::Vertex<SymbolDynamicLayoutAttributes>>> dynamicVertexBuffer;
|
||||
optional<gfx::VertexBuffer<gfx::Vertex<SymbolOpacityAttributes>>> opacityVertexBuffer;
|
||||
optional<gfx::IndexBuffer> indexBuffer;
|
||||
} icon;
|
||||
|
||||
struct CollisionBuffer {
|
||||
@@ -139,6 +132,7 @@ public:
|
||||
|
||||
uint32_t bucketInstanceId = 0;
|
||||
bool justReloaded = false;
|
||||
optional<bool> hasFormatSectionOverrides_;
|
||||
|
||||
std::shared_ptr<std::vector<size_t>> featureSortOrder;
|
||||
};
|
||||
|
||||
@@ -411,7 +411,7 @@ void RenderSymbolLayer::sortRenderTiles(const TransformState& state) {
|
||||
|
||||
void RenderSymbolLayer::updateBucketPaintProperties(Bucket* bucket) const {
|
||||
assert(bucket->supportsLayer(*baseImpl));
|
||||
static_cast<SymbolBucket*>(bucket)->paintProperties.at(getID()).evaluated = evaluated;
|
||||
static_cast<SymbolBucket*>(bucket)->updatePaintProperties(getID(), evaluated);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -95,7 +95,10 @@ public:
|
||||
|
||||
virtual ~PaintPropertyBinder() = default;
|
||||
|
||||
virtual void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, const ImagePositions&, const optional<PatternDependency>&) = 0;
|
||||
virtual void populateVertexVector(const GeometryTileFeature& feature,
|
||||
std::size_t length, const ImagePositions&,
|
||||
const optional<PatternDependency>&,
|
||||
const style::expression::Value&) = 0;
|
||||
virtual void upload(gfx::Context& context) = 0;
|
||||
virtual void setPatternParameters(const optional<ImagePosition>&, const optional<ImagePosition>&, CrossfadeParameters&) = 0;
|
||||
virtual std::tuple<ExpandToType<As, optional<gl::AttributeBinding>>...> attributeBinding(const PossiblyEvaluatedType& currentValue) const = 0;
|
||||
@@ -114,7 +117,7 @@ public:
|
||||
: constant(std::move(constant_)) {
|
||||
}
|
||||
|
||||
void populateVertexVector(const GeometryTileFeature&, std::size_t, const ImagePositions&, const optional<PatternDependency>&) override {}
|
||||
void populateVertexVector(const GeometryTileFeature&, std::size_t, const ImagePositions&, const optional<PatternDependency>&, const style::expression::Value&) override {}
|
||||
void upload(gfx::Context&) override {}
|
||||
void setPatternParameters(const optional<ImagePosition>&, const optional<ImagePosition>&, CrossfadeParameters&) override {};
|
||||
|
||||
@@ -135,13 +138,13 @@ private:
|
||||
};
|
||||
|
||||
template <class T, class... As>
|
||||
class ConstantCrossFadedPaintPropertyBinder : public PaintPropertyBinder<T, std::array<uint16_t, 4>,PossiblyEvaluatedPropertyValue<Faded<T>>, As...> {
|
||||
class ConstantCrossFadedPaintPropertyBinder final : public PaintPropertyBinder<T, std::array<uint16_t, 4>,PossiblyEvaluatedPropertyValue<Faded<T>>, As...> {
|
||||
public:
|
||||
ConstantCrossFadedPaintPropertyBinder(Faded<T> constant_)
|
||||
: constant(std::move(constant_)), constantPatternPositions({}) {
|
||||
}
|
||||
|
||||
void populateVertexVector(const GeometryTileFeature&, std::size_t, const ImagePositions&, const optional<PatternDependency>&) override {}
|
||||
void populateVertexVector(const GeometryTileFeature&, std::size_t, const ImagePositions&, const optional<PatternDependency>&, const style::expression::Value&) override {}
|
||||
void upload(gfx::Context&) override {}
|
||||
|
||||
void setPatternParameters(const optional<ImagePosition>& posA, const optional<ImagePosition>& posB, CrossfadeParameters&) override {
|
||||
@@ -171,7 +174,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T, class A>
|
||||
class SourceFunctionPaintPropertyBinder : public PaintPropertyBinder<T, T, PossiblyEvaluatedPropertyValue<T>, A> {
|
||||
class SourceFunctionPaintPropertyBinder final : public PaintPropertyBinder<T, T, PossiblyEvaluatedPropertyValue<T>, A> {
|
||||
public:
|
||||
using BaseAttributeType = A;
|
||||
using BaseVertex = gfx::Vertex<BaseAttributeType>;
|
||||
@@ -183,8 +186,9 @@ public:
|
||||
defaultValue(std::move(defaultValue_)) {
|
||||
}
|
||||
void setPatternParameters(const optional<ImagePosition>&, const optional<ImagePosition>&, CrossfadeParameters&) override {};
|
||||
void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, const ImagePositions&, const optional<PatternDependency>&) override {
|
||||
auto evaluated = expression.evaluate(feature, defaultValue);
|
||||
void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, const ImagePositions&, const optional<PatternDependency>&, const style::expression::Value& formattedSection) override {
|
||||
using style::expression::EvaluationContext;
|
||||
auto evaluated = expression.evaluate(EvaluationContext(&feature).withFormattedSection(&formattedSection), defaultValue);
|
||||
this->statistics.add(evaluated);
|
||||
auto value = attributeValue(evaluated);
|
||||
for (std::size_t i = vertexVector.elements(); i < length; ++i) {
|
||||
@@ -227,7 +231,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T, class A>
|
||||
class CompositeFunctionPaintPropertyBinder : public PaintPropertyBinder<T, T, PossiblyEvaluatedPropertyValue<T>, A> {
|
||||
class CompositeFunctionPaintPropertyBinder final : public PaintPropertyBinder<T, T, PossiblyEvaluatedPropertyValue<T>, A> {
|
||||
public:
|
||||
|
||||
using AttributeType = ZoomInterpolatedAttributeType<A>;
|
||||
@@ -240,8 +244,12 @@ public:
|
||||
zoomRange({zoom, zoom + 1}) {
|
||||
}
|
||||
void setPatternParameters(const optional<ImagePosition>&, const optional<ImagePosition>&, CrossfadeParameters&) override {};
|
||||
void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, const ImagePositions&, const optional<PatternDependency>&) override {
|
||||
Range<T> range = expression.evaluate(zoomRange, feature, defaultValue);
|
||||
void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, const ImagePositions&, const optional<PatternDependency>&, const style::expression::Value& formattedSection) override {
|
||||
using style::expression::EvaluationContext;
|
||||
Range<T> range = {
|
||||
expression.evaluate(EvaluationContext(zoomRange.min, &feature).withFormattedSection(&formattedSection), defaultValue),
|
||||
expression.evaluate(EvaluationContext(zoomRange.max, &feature).withFormattedSection(&formattedSection), defaultValue),
|
||||
};
|
||||
this->statistics.add(range.min);
|
||||
this->statistics.add(range.max);
|
||||
AttributeValue value = zoomInterpolatedAttributeValue(
|
||||
@@ -292,7 +300,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T, class A1, class A2>
|
||||
class CompositeCrossFadedPaintPropertyBinder : public PaintPropertyBinder<T, std::array<uint16_t, 4>, PossiblyEvaluatedPropertyValue<Faded<T>>, A1, A2> {
|
||||
class CompositeCrossFadedPaintPropertyBinder final : public PaintPropertyBinder<T, std::array<uint16_t, 4>, PossiblyEvaluatedPropertyValue<Faded<T>>, A1, A2> {
|
||||
public:
|
||||
using AttributeType = ZoomInterpolatedAttributeType<A1>;
|
||||
using AttributeType2 = ZoomInterpolatedAttributeType<A2>;
|
||||
@@ -313,7 +321,7 @@ public:
|
||||
crossfade = crossfade_;
|
||||
};
|
||||
|
||||
void populateVertexVector(const GeometryTileFeature&, std::size_t length, const ImagePositions& patternPositions, const optional<PatternDependency>& patternDependencies) override {
|
||||
void populateVertexVector(const GeometryTileFeature&, std::size_t length, const ImagePositions& patternPositions, const optional<PatternDependency>& patternDependencies, const style::expression::Value&) override {
|
||||
|
||||
if (patternDependencies->mid.empty()) {
|
||||
// Unlike other propperties with expressions that evaluate to null, the default value for `*-pattern` properties is an empty
|
||||
@@ -474,9 +482,9 @@ public:
|
||||
PaintPropertyBinders(PaintPropertyBinders&&) = default;
|
||||
PaintPropertyBinders(const PaintPropertyBinders&) = delete;
|
||||
|
||||
void populateVertexVectors(const GeometryTileFeature& feature, std::size_t length, const ImagePositions& patternPositions, const optional<PatternDependency>& patternDependencies) {
|
||||
void populateVertexVectors(const GeometryTileFeature& feature, std::size_t length, const ImagePositions& patternPositions, const optional<PatternDependency>& patternDependencies, const style::expression::Value& formattedSection = {}) {
|
||||
util::ignore({
|
||||
(binders.template get<Ps>()->populateVertexVector(feature, length, patternPositions, patternDependencies), 0)...
|
||||
(binders.template get<Ps>()->populateVertexVector(feature, length, patternPositions, patternDependencies, formattedSection), 0)...
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ bool hasTokens(const std::string& source) {
|
||||
std::unique_ptr<Expression> convertTokenStringToFormatExpression(const std::string& source) {
|
||||
auto textExpression = convertTokenStringToExpression(source);
|
||||
std::vector<FormatExpressionSection> sections;
|
||||
sections.emplace_back(std::move(textExpression), nullopt, nullopt);
|
||||
sections.emplace_back(std::move(textExpression), nullopt, nullopt, nullopt);
|
||||
return std::make_unique<FormatExpression>(sections);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,13 +189,13 @@ std::unique_ptr<Expression> concat(std::vector<std::unique_ptr<Expression>> inpu
|
||||
std::unique_ptr<Expression> format(const char* value) {
|
||||
return std::make_unique<Literal>(Formatted(value));
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Expression> format(std::unique_ptr<Expression> input) {
|
||||
std::vector<FormatExpressionSection> sections;
|
||||
sections.emplace_back(std::move(input), nullopt, nullopt);
|
||||
sections.emplace_back(std::move(input), nullopt, nullopt, nullopt);
|
||||
return std::make_unique<FormatExpression>(sections);
|
||||
}
|
||||
|
||||
|
||||
} // namespace dsl
|
||||
} // namespace expression
|
||||
} // namespace style
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
#include <mbgl/style/expression/format_expression.hpp>
|
||||
#include <mbgl/style/expression/literal.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -10,15 +8,21 @@ namespace expression {
|
||||
|
||||
FormatExpressionSection::FormatExpressionSection(std::unique_ptr<Expression> text_,
|
||||
optional<std::unique_ptr<Expression>> fontScale_,
|
||||
optional<std::unique_ptr<Expression>> textFont_)
|
||||
optional<std::unique_ptr<Expression>> textFont_,
|
||||
optional<std::unique_ptr<Expression>> textColor_)
|
||||
: text(std::move(text_))
|
||||
{
|
||||
if (fontScale_) {
|
||||
fontScale = std::shared_ptr<Expression>(std::move(*fontScale_));
|
||||
}
|
||||
|
||||
if (textFont_) {
|
||||
textFont = std::shared_ptr<Expression>(std::move(*textFont_));
|
||||
}
|
||||
|
||||
if (textColor_) {
|
||||
textColor = std::shared_ptr<Expression>(std::move(*textColor_));
|
||||
}
|
||||
}
|
||||
|
||||
FormatExpression::FormatExpression(std::vector<FormatExpressionSection> sections_)
|
||||
@@ -53,7 +57,7 @@ ParseResult FormatExpression::parse(const Convertible& value, ParsingContext& ct
|
||||
return ParseResult();
|
||||
}
|
||||
|
||||
const optional<Convertible> fontScaleOption = objectMember(options, "font-scale");
|
||||
const optional<Convertible> fontScaleOption = objectMember(options, kFormattedSectionFontScale);
|
||||
ParseResult fontScale;
|
||||
if (fontScaleOption) {
|
||||
fontScale = ctx.parse(*fontScaleOption, 1, {type::Number});
|
||||
@@ -62,7 +66,7 @@ ParseResult FormatExpression::parse(const Convertible& value, ParsingContext& ct
|
||||
}
|
||||
}
|
||||
|
||||
const optional<Convertible> textFontOption = objectMember(options, "text-font");
|
||||
const optional<Convertible> textFontOption = objectMember(options, kFormattedSectionTextFont);
|
||||
ParseResult textFont;
|
||||
if (textFontOption) {
|
||||
textFont = ctx.parse(*textFontOption, 1, {type::Array(type::String)});
|
||||
@@ -70,7 +74,20 @@ ParseResult FormatExpression::parse(const Convertible& value, ParsingContext& ct
|
||||
return ParseResult();
|
||||
}
|
||||
}
|
||||
sections.emplace_back(std::move(*text), std::move(fontScale), std::move(textFont));
|
||||
|
||||
const optional<Convertible> textColorOption = objectMember(options, kFormattedSectionTextColor);
|
||||
ParseResult textColor;
|
||||
if (textColorOption) {
|
||||
textColor = ctx.parse(*textColorOption, 1, {type::Color});
|
||||
if (!textColor) {
|
||||
return ParseResult();
|
||||
}
|
||||
}
|
||||
|
||||
sections.emplace_back(std::move(*text),
|
||||
std::move(fontScale),
|
||||
std::move(textFont),
|
||||
std::move(textColor));
|
||||
}
|
||||
|
||||
return ParseResult(std::make_unique<FormatExpression>(std::move(sections)));
|
||||
@@ -85,6 +102,9 @@ void FormatExpression::eachChild(const std::function<void(const Expression&)>& f
|
||||
if (section.textFont) {
|
||||
fn(**section.textFont);
|
||||
}
|
||||
if (section.textColor) {
|
||||
fn(**section.textColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +128,10 @@ bool FormatExpression::operator==(const Expression& e) const {
|
||||
(!lhsSection.textFont && rhsSection.textFont)) {
|
||||
return false;
|
||||
}
|
||||
if ((lhsSection.textColor && (!rhsSection.textColor || **lhsSection.textColor != **rhsSection.textColor)) ||
|
||||
(!lhsSection.textColor && rhsSection.textColor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -115,15 +139,18 @@ bool FormatExpression::operator==(const Expression& e) const {
|
||||
}
|
||||
|
||||
mbgl::Value FormatExpression::serialize() const {
|
||||
std::vector<mbgl::Value> serialized{{ std::string("format") }};
|
||||
std::vector<mbgl::Value> serialized{{ getOperator() }};
|
||||
for (const auto& section : sections) {
|
||||
serialized.push_back(section.text->serialize());
|
||||
std::unordered_map<std::string, mbgl::Value> options;
|
||||
if (section.fontScale) {
|
||||
options.emplace("font-scale", (*section.fontScale)->serialize());
|
||||
options.emplace(kFormattedSectionFontScale, (*section.fontScale)->serialize());
|
||||
}
|
||||
if (section.textFont) {
|
||||
options.emplace("text-font", (*section.textFont)->serialize());
|
||||
options.emplace(kFormattedSectionTextFont, (*section.textFont)->serialize());
|
||||
}
|
||||
if (section.textColor) {
|
||||
options.emplace(kFormattedSectionTextColor, (*section.textColor)->serialize());
|
||||
}
|
||||
serialized.push_back(options);
|
||||
}
|
||||
@@ -164,7 +191,20 @@ EvaluationResult FormatExpression::evaluate(const EvaluationContext& params) con
|
||||
}
|
||||
evaluatedTextFont = *textFontValue;
|
||||
}
|
||||
evaluatedSections.emplace_back(*evaluatedText, evaluatedFontScale, evaluatedTextFont);
|
||||
|
||||
optional<Color> evaluatedTextColor;
|
||||
if (section.textColor) {
|
||||
auto textColorResult = (*section.textColor)->evaluate(params);
|
||||
if (!textColorResult) {
|
||||
return textColorResult.error();
|
||||
}
|
||||
|
||||
evaluatedTextColor = fromExpressionValue<Color>(*textColorResult);
|
||||
if (!evaluatedTextColor) {
|
||||
return EvaluationError { "Format text-color option must evaluate to Color" };
|
||||
}
|
||||
}
|
||||
evaluatedSections.emplace_back(*evaluatedText, evaluatedFontScale, evaluatedTextFont, evaluatedTextColor);
|
||||
}
|
||||
return Formatted(evaluatedSections);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/expression/is_expression.hpp>
|
||||
#include <mbgl/style/expression/literal.hpp>
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/type.hpp>
|
||||
#include <mbgl/style/expression/compound_expression.hpp>
|
||||
#include <mbgl/style/expression/boolean_operator.hpp>
|
||||
#include <mbgl/style/conversion/constant.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
namespace expression {
|
||||
|
||||
const char* const kFormattedSectionFontScale = "font-scale";
|
||||
const char* const kFormattedSectionTextFont = "text-font";
|
||||
const char* const kFormattedSectionTextColor = "text-color";
|
||||
|
||||
bool Formatted::operator==(const Formatted& other) const {
|
||||
if (other.sections.size() != sections.size()) {
|
||||
return false;
|
||||
@@ -22,14 +19,14 @@ bool Formatted::operator==(const Formatted& other) const {
|
||||
const auto& otherSection = other.sections.at(i);
|
||||
if (thisSection.text != otherSection.text ||
|
||||
thisSection.fontScale != otherSection.fontScale ||
|
||||
thisSection.fontStack != otherSection.fontStack) {
|
||||
thisSection.fontStack != otherSection.fontStack ||
|
||||
thisSection.textColor != otherSection.textColor) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Formatted::toString() const {
|
||||
std::string result;
|
||||
for (const auto& section : sections) {
|
||||
@@ -37,7 +34,7 @@ std::string Formatted::toString() const {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} // namespace expression
|
||||
|
||||
namespace conversion {
|
||||
@@ -65,6 +62,7 @@ optional<Formatted> Converter<Formatted>::operator()(const Convertible& value, E
|
||||
|
||||
optional<double> fontScale;
|
||||
optional<FontStack> textFont;
|
||||
optional<Color> textColor;
|
||||
if (sectionLength > 1) {
|
||||
Convertible sectionParams = arrayMember(section, 1);
|
||||
if (!isObject(sectionParams)) {
|
||||
@@ -72,12 +70,12 @@ optional<Formatted> Converter<Formatted>::operator()(const Convertible& value, E
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
optional<Convertible> fontScaleMember = objectMember(sectionParams, "font-scale");
|
||||
optional<Convertible> fontScaleMember = objectMember(sectionParams, kFormattedSectionFontScale);
|
||||
if (fontScaleMember) {
|
||||
fontScale = toDouble(*fontScaleMember);
|
||||
}
|
||||
|
||||
optional<Convertible> textFontMember = objectMember(sectionParams, "text-font");
|
||||
optional<Convertible> textFontMember = objectMember(sectionParams, kFormattedSectionTextFont);
|
||||
if (textFontMember) {
|
||||
if (isArray(*textFontMember)) {
|
||||
std::vector<std::string> fontsVector;
|
||||
@@ -96,9 +94,17 @@ optional<Formatted> Converter<Formatted>::operator()(const Convertible& value, E
|
||||
return nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
optional<Convertible> textColorMember = objectMember(sectionParams, kFormattedSectionTextColor);
|
||||
if (textColorMember) {
|
||||
textColor = convert<Color>(*textColorMember, error);
|
||||
if (!textColor) {
|
||||
return nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sections.push_back(FormattedSection(*sectionText, fontScale, textFont));
|
||||
sections.push_back(FormattedSection(*sectionText, fontScale, textFont, textColor));
|
||||
}
|
||||
return Formatted(sections);
|
||||
} else if (optional<std::string> result = toString(value)) {
|
||||
|
||||
@@ -17,18 +17,22 @@ bool isFeatureConstant(const Expression& expression) {
|
||||
return false;
|
||||
} else if (name == "has" && parameterCount && *parameterCount == 1) {
|
||||
return false;
|
||||
} else if (0 == name.rfind(filter, 0)) {
|
||||
// Legacy filters begin with "filter-" and are never constant.
|
||||
return false;
|
||||
} else if (
|
||||
name == "properties" ||
|
||||
name == "geometry-type" ||
|
||||
name == "id"
|
||||
) {
|
||||
return false;
|
||||
} else if (0u == name.rfind(filter, 0u)) {
|
||||
// Legacy filters begin with "filter-" and are never constant.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (expression.getKind() == Kind::FormatSectionOverride) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expression.getKind() == Kind::CollatorExpression) {
|
||||
// Although the results of a Collator expression with fixed arguments
|
||||
// generally shouldn't change between executions, we can't serialize them
|
||||
|
||||
@@ -31,6 +31,11 @@ struct <%- camelize(property.name) %> : ColorRampProperty {
|
||||
<% } else { -%>
|
||||
struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %> {
|
||||
static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
|
||||
<% if (isOverridable(property)) { -%>
|
||||
static constexpr const char *name() { return "<%- property.name %>"; }
|
||||
static constexpr auto expressionType() { return expression::type::<%- expressionType(property) %>{}; };
|
||||
template<typename T> static bool hasOverride(const T& t) { return !!t.<%- camelizeWithLeadingLowercase(property.name) %>; };
|
||||
<% } -%>
|
||||
};
|
||||
<% } -%>
|
||||
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
bool SymbolLayer::Impl::hasFormatSectionOverrides() const {
|
||||
if (!hasFormatSectionOverrides_) {
|
||||
hasFormatSectionOverrides_ = SymbolLayerPaintPropertyOverrides::hasOverrides(layout.get<TextField>());
|
||||
}
|
||||
return *hasFormatSectionOverrides_;
|
||||
}
|
||||
|
||||
bool SymbolLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const {
|
||||
assert(other.getTypeInfo() == getTypeInfo());
|
||||
const auto& impl = static_cast<const style::SymbolLayer::Impl&>(other);
|
||||
return filter != impl.filter ||
|
||||
visibility != impl.visibility ||
|
||||
layout != impl.layout ||
|
||||
paint.hasDataDrivenPropertyDifference(impl.paint);
|
||||
paint.hasDataDrivenPropertyDifference(impl.paint) ||
|
||||
(hasFormatSectionOverrides() && SymbolLayerPaintPropertyOverrides::hasPaintPropertyDifference(paint, impl.paint));
|
||||
}
|
||||
|
||||
void SymbolLayer::Impl::populateFontStack(std::set<FontStack>& fontStack) const {
|
||||
@@ -20,10 +27,10 @@ void SymbolLayer::Impl::populateFontStack(std::set<FontStack>& fontStack) const
|
||||
}
|
||||
|
||||
layout.get<TextFont>().match(
|
||||
[&] (Undefined) {
|
||||
[&fontStack] (Undefined) {
|
||||
fontStack.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
|
||||
},
|
||||
[&] (const FontStack& constant) {
|
||||
[&fontStack] (const FontStack& constant) {
|
||||
fontStack.insert(constant);
|
||||
},
|
||||
[&] (const auto& function) {
|
||||
|
||||
@@ -3,10 +3,104 @@
|
||||
#include <mbgl/style/layer_impl.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_properties.hpp>
|
||||
#include <mbgl/style/expression/format_expression.hpp>
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
#include <mbgl/style/expression/format_section_override.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
template<typename PaintProperty>
|
||||
struct FormatSectionOverrides;
|
||||
|
||||
template<typename... PaintProperty>
|
||||
struct FormatSectionOverrides<TypeList<PaintProperty...>> {
|
||||
template<typename Property, typename T, typename U>
|
||||
static void setOverride(const T& overrides, U& overridable) {
|
||||
if (hasOverride<Property>(overrides.template get<TextField>())) {
|
||||
auto override =
|
||||
std::make_unique<expression::FormatSectionOverride<typename Property::Type>>(Property::expressionType(),
|
||||
std::move(overridable.template get<Property>()),
|
||||
Property::name());
|
||||
PropertyExpression<typename Property::Type> expr(std::move(override));
|
||||
overridable.template get<Property>() = PossiblyEvaluatedPropertyValue<typename Property::Type>(std::move(expr));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
static void setOverrides(const T& overrides, U& overridable) {
|
||||
util::ignore({(setOverride<PaintProperty>(overrides, overridable), 0)...});
|
||||
}
|
||||
|
||||
template<typename Property, typename T, typename U>
|
||||
static void updateOverride(T& evaluated, U& updated) {
|
||||
auto property = evaluated.template get<Property>();
|
||||
if (!property.isConstant()) {
|
||||
const bool hasFormatSectionOverride = property.match(
|
||||
[] (const style::PropertyExpression<typename Property::Type>& e) {
|
||||
return e.getExpression().getKind() == expression::Kind::FormatSectionOverride;
|
||||
},
|
||||
[] (const auto&) {
|
||||
return false;
|
||||
});
|
||||
if (hasFormatSectionOverride) {
|
||||
updated.template get<Property>() = std::move(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
static void updateOverrides(T& evaluated, U& updated) {
|
||||
util::ignore({(updateOverride<PaintProperty>(evaluated, updated), 0)...});
|
||||
}
|
||||
|
||||
template<typename Property, typename FormattedProperty>
|
||||
static bool hasOverride(const FormattedProperty& formatted) {
|
||||
return formatted.match(
|
||||
[] (const TextField::Type& t) {
|
||||
for (const auto& section : t.sections) {
|
||||
if (Property::hasOverride(section)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[] (const PropertyExpression<TextField::Type>& t) {
|
||||
if (t.getExpression().getKind() == expression::Kind::FormatExpression) {
|
||||
const auto* e = static_cast<const expression::FormatExpression*>(&t.getExpression());
|
||||
for (const auto& section : e->getSections()) {
|
||||
if (Property::hasOverride(section)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[] (const auto&) {
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
template <typename FormattedProperty>
|
||||
static bool hasOverrides(const FormattedProperty& formatted) {
|
||||
bool result = false;
|
||||
util::ignore({ (result |= hasOverride<PaintProperty>(formatted))... });
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename PaintProperties>
|
||||
static bool hasPaintPropertyDifference(const PaintProperties& lhs, const PaintProperties& rhs) {
|
||||
bool result = false;
|
||||
util::ignore({ (result |= lhs.template get<PaintProperty>().value.isConstant() &&
|
||||
rhs.template get<PaintProperty>().value.isConstant() &&
|
||||
(lhs.template get<PaintProperty>().value.asConstant() != rhs.template get<PaintProperty>().value.asConstant()))... });
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
using SymbolLayerPaintPropertyOverrides = FormatSectionOverrides<SymbolPaintProperties::OverridableProperties>;
|
||||
|
||||
class SymbolLayer::Impl : public Layer::Impl {
|
||||
public:
|
||||
using Layer::Impl::Impl;
|
||||
@@ -19,6 +113,10 @@ public:
|
||||
SymbolPaintProperties::Transitionable paint;
|
||||
|
||||
DECLARE_LAYER_TYPE_INFO;
|
||||
|
||||
private:
|
||||
bool hasFormatSectionOverrides() const;
|
||||
mutable optional<bool> hasFormatSectionOverrides_;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -229,8 +229,11 @@ struct TextOpacity : DataDrivenPaintProperty<float, attributes::a_opacity, unifo
|
||||
static float defaultValue() { return 1; }
|
||||
};
|
||||
|
||||
struct TextColor : DataDrivenPaintProperty<Color, attributes::a_fill_color, uniforms::u_fill_color> {
|
||||
struct TextColor : DataDrivenPaintProperty<Color, attributes::a_fill_color, uniforms::u_fill_color, true> {
|
||||
static Color defaultValue() { return Color::black(); }
|
||||
static constexpr const char *name() { return "text-color"; }
|
||||
static constexpr auto expressionType() { return expression::type::ColorType{}; };
|
||||
template<typename T> static bool hasOverride(const T& t) { return !!t.textColor; };
|
||||
};
|
||||
|
||||
struct TextHaloColor : DataDrivenPaintProperty<Color, attributes::a_halo_color, uniforms::u_halo_color> {
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
using PossiblyEvaluatedType = T;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = false;
|
||||
static constexpr bool IsOverridable = false;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@@ -27,6 +28,7 @@ public:
|
||||
using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<T>;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = true;
|
||||
static constexpr bool IsOverridable = false;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
using PossiblyEvaluatedType = T;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = false;
|
||||
static constexpr bool IsOverridable = false;
|
||||
};
|
||||
|
||||
struct LightAnchor : LightProperty<LightAnchorType> {
|
||||
|
||||
@@ -21,9 +21,10 @@ public:
|
||||
using PossiblyEvaluatedType = T;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = false;
|
||||
static constexpr bool IsOverridable = false;
|
||||
};
|
||||
|
||||
template <class T, class A, class U>
|
||||
template <class T, class A, class U, bool isOverridable = false>
|
||||
class DataDrivenPaintProperty {
|
||||
public:
|
||||
using TransitionableType = Transitionable<PropertyValue<T>>;
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<T>;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = true;
|
||||
static constexpr bool IsOverridable = isOverridable;
|
||||
|
||||
using Attribute = A;
|
||||
using AttributeList = TypeList<A>;
|
||||
@@ -48,6 +50,7 @@ public:
|
||||
using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<Faded<T>>;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = true;
|
||||
static constexpr bool IsOverridable = false;
|
||||
|
||||
using Attribute = A1;
|
||||
using AttributeList = TypeList<A1, A2>;
|
||||
@@ -64,6 +67,7 @@ public:
|
||||
using PossiblyEvaluatedType = Faded<T>;
|
||||
using Type = T;
|
||||
static constexpr bool IsDataDriven = false;
|
||||
static constexpr bool IsOverridable = false;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -84,6 +88,7 @@ public:
|
||||
using PossiblyEvaluatedType = Color;
|
||||
using Type = Color;
|
||||
static constexpr bool IsDataDriven = false;
|
||||
static constexpr bool IsOverridable = false;
|
||||
|
||||
static Color defaultValue() { return {}; }
|
||||
};
|
||||
|
||||
@@ -99,6 +99,9 @@ public:
|
||||
template <class P>
|
||||
struct IsDataDriven : std::integral_constant<bool, P::IsDataDriven> {};
|
||||
|
||||
template <class P>
|
||||
struct IsOverridable : std::integral_constant<bool, P::IsOverridable> {};
|
||||
|
||||
template <class... Ps>
|
||||
class Properties {
|
||||
public:
|
||||
@@ -122,6 +125,7 @@ public:
|
||||
using EvaluatedTypes = TypeList<typename Ps::Type...>;
|
||||
|
||||
using DataDrivenProperties = FilteredTypeList<PropertyTypes, IsDataDriven>;
|
||||
using OverridableProperties = FilteredTypeList<PropertyTypes, IsOverridable>;
|
||||
|
||||
template <class TypeList>
|
||||
using Tuple = IndexedTuple<PropertyTypes, TypeList>;
|
||||
|
||||
68
src/mbgl/style/property_expression.cpp
Normal file
68
src/mbgl/style/property_expression.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <mbgl/style/property_expression.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
PropertyExpressionBase::PropertyExpressionBase(std::unique_ptr<expression::Expression> expression_)
|
||||
: expression(std::move(expression_)),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get())) {
|
||||
isZoomConstant_ = expression::isZoomConstant(*expression);
|
||||
isFeatureConstant_ = expression::isFeatureConstant(*expression);
|
||||
}
|
||||
|
||||
bool PropertyExpressionBase::isZoomConstant() const noexcept {
|
||||
return isZoomConstant_;
|
||||
}
|
||||
|
||||
bool PropertyExpressionBase::isFeatureConstant() const noexcept {
|
||||
return isFeatureConstant_;
|
||||
}
|
||||
|
||||
bool PropertyExpressionBase::canEvaluateWith(const expression::EvaluationContext& context) const noexcept {
|
||||
if (context.zoom) {
|
||||
if (context.feature != nullptr) {
|
||||
return !isFeatureConstant();
|
||||
}
|
||||
return !isZoomConstant() && isFeatureConstant();
|
||||
}
|
||||
|
||||
if (context.feature != nullptr) {
|
||||
return isZoomConstant() && !isFeatureConstant();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float PropertyExpressionBase::interpolationFactor(const Range<float>& inputLevels, const float inputValue) const noexcept {
|
||||
return zoomCurve.match(
|
||||
[](std::nullptr_t) {
|
||||
assert(false);
|
||||
return 0.0f;
|
||||
},
|
||||
[&](const expression::Interpolate* z) {
|
||||
return z->interpolationFactor(Range<double> { inputLevels.min, inputLevels.max }, inputValue);
|
||||
},
|
||||
[](const expression::Step*) {
|
||||
return 0.0f;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Range<float> PropertyExpressionBase::getCoveringStops(const float lower, const float upper) const noexcept {
|
||||
return zoomCurve.match(
|
||||
[](std::nullptr_t) {
|
||||
assert(false);
|
||||
return Range<float>(0.0f, 0.0f);
|
||||
},
|
||||
[&](auto z) {
|
||||
return z->getCoveringStops(lower, upper);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const expression::Expression& PropertyExpressionBase::getExpression() const noexcept {
|
||||
return *expression;
|
||||
}
|
||||
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
@@ -19,7 +19,7 @@ namespace mbgl {
|
||||
|
||||
using GlyphID = char16_t;
|
||||
using GlyphIDs = std::set<GlyphID>;
|
||||
|
||||
|
||||
// Note: this only works for the BMP
|
||||
GlyphRange getGlyphRange(GlyphID glyph);
|
||||
|
||||
@@ -59,8 +59,8 @@ using GlyphMap = std::map<FontStackHash, Glyphs>;
|
||||
|
||||
class PositionedGlyph {
|
||||
public:
|
||||
explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, bool vertical_, FontStackHash font_, float scale_)
|
||||
: glyph(glyph_), x(x_), y(y_), vertical(vertical_), font(font_), scale(scale_)
|
||||
explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, bool vertical_, FontStackHash font_, float scale_, std::size_t sectionIndex_ = 0)
|
||||
: glyph(glyph_), x(x_), y(y_), vertical(vertical_), font(font_), scale(scale_), sectionIndex(sectionIndex_)
|
||||
{}
|
||||
|
||||
GlyphID glyph = 0;
|
||||
@@ -70,6 +70,8 @@ public:
|
||||
|
||||
FontStackHash font = 0;
|
||||
float scale = 0.0;
|
||||
// Maps positioned glyph to TaggedString section
|
||||
std::size_t sectionIndex;
|
||||
};
|
||||
|
||||
enum class WritingModeType : uint8_t;
|
||||
|
||||
@@ -172,7 +172,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
|
||||
br = util::matrixMultiply(matrix, br);
|
||||
}
|
||||
|
||||
quads.emplace_back(tl, tr, bl, br, rect, shapedText.writingMode, glyphOffset);
|
||||
quads.emplace_back(tl, tr, bl, br, rect, shapedText.writingMode, glyphOffset, positionedGlyph.sectionIndex);
|
||||
}
|
||||
|
||||
return quads;
|
||||
|
||||
@@ -20,14 +20,16 @@ public:
|
||||
Point<float> br_,
|
||||
Rect<uint16_t> tex_,
|
||||
WritingModeType writingMode_,
|
||||
Point<float> glyphOffset_)
|
||||
Point<float> glyphOffset_,
|
||||
size_t sectionIndex_ = 0)
|
||||
: tl(std::move(tl_)),
|
||||
tr(std::move(tr_)),
|
||||
bl(std::move(bl_)),
|
||||
br(std::move(br_)),
|
||||
tex(std::move(tex_)),
|
||||
writingMode(writingMode_),
|
||||
glyphOffset(glyphOffset_) {}
|
||||
glyphOffset(glyphOffset_),
|
||||
sectionIndex(sectionIndex_){}
|
||||
|
||||
Point<float> tl;
|
||||
Point<float> tr;
|
||||
@@ -36,6 +38,7 @@ public:
|
||||
Rect<uint16_t> tex;
|
||||
WritingModeType writingMode;
|
||||
Point<float> glyphOffset;
|
||||
size_t sectionIndex;
|
||||
};
|
||||
|
||||
using SymbolQuads = std::vector<SymbolQuad>;
|
||||
|
||||
@@ -299,7 +299,8 @@ void shapeLines(Shaping& shaping,
|
||||
|
||||
std::size_t lineStartIndex = shaping.positionedGlyphs.size();
|
||||
for (std::size_t i = 0; i < line.length(); i++) {
|
||||
const SectionOptions& section = line.getSection(i);
|
||||
const std::size_t sectionIndex = line.getSectionIndex(i);
|
||||
const SectionOptions& section = line.sectionAt(sectionIndex);
|
||||
char16_t codePoint = line.getCharCodeAt(i);
|
||||
auto glyphs = glyphMap.find(section.fontStackHash);
|
||||
if (glyphs == glyphMap.end()) {
|
||||
@@ -318,10 +319,10 @@ void shapeLines(Shaping& shaping,
|
||||
const Glyph& glyph = **it->second;
|
||||
|
||||
if (writingMode == WritingModeType::Horizontal || !util::i18n::hasUprightVerticalOrientation(codePoint)) {
|
||||
shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale);
|
||||
shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale, sectionIndex);
|
||||
x += glyph.metrics.advance * section.scale + spacing;
|
||||
} else {
|
||||
shaping.positionedGlyphs.emplace_back(codePoint, x, baselineOffset, true, section.fontStackHash, section.scale);
|
||||
shaping.positionedGlyphs.emplace_back(codePoint, x, baselineOffset, true, section.fontStackHash, section.scale, sectionIndex);
|
||||
x += verticalHeight * section.scale + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <mbgl/text/tagged_string.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
#include <mbgl/util/i18n.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStackHash fontStack) {
|
||||
void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStack fontStack, optional<Color> textColor) {
|
||||
styledText.first += sectionText;
|
||||
sections.emplace_back(scale, fontStack);
|
||||
sections.emplace_back(scale, fontStack, std::move(textColor));
|
||||
styledText.second.resize(styledText.first.size(), sections.size() - 1);
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ void TaggedString::trim() {
|
||||
double TaggedString::getMaxScale() const {
|
||||
double maxScale = 0.0;
|
||||
for (std::size_t i = 0; i < styledText.first.length(); i++) {
|
||||
maxScale = std::max(maxScale, getSection(i).scale);
|
||||
maxScale = util::max(maxScale, getSection(i).scale);
|
||||
}
|
||||
return maxScale;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/text/bidi.hpp>
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
struct SectionOptions {
|
||||
SectionOptions(double scale_, FontStackHash fontStackHash_)
|
||||
: scale(scale_), fontStackHash(fontStackHash_)
|
||||
SectionOptions(double scale_, FontStack fontStack_, optional<Color> textColor_ = nullopt)
|
||||
: scale(scale_),
|
||||
fontStackHash(FontStackHasher()(fontStack_)),
|
||||
fontStack(std::move(fontStack_)),
|
||||
textColor(std::move(textColor_))
|
||||
{}
|
||||
|
||||
double scale;
|
||||
FontStackHash fontStackHash;
|
||||
FontStack fontStack;
|
||||
optional<Color> textColor;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -71,7 +77,11 @@ struct TaggedString {
|
||||
return styledText;
|
||||
}
|
||||
|
||||
void addSection(const std::u16string& text, double scale, FontStackHash fontStack);
|
||||
void addSection(const std::u16string& text,
|
||||
double scale,
|
||||
FontStack fontStack,
|
||||
optional<Color> textColor_ = nullopt);
|
||||
|
||||
const SectionOptions& sectionAt(std::size_t index) const {
|
||||
return sections.at(index);
|
||||
}
|
||||
@@ -88,7 +98,7 @@ struct TaggedString {
|
||||
void trim();
|
||||
|
||||
void verticalizePunctuation();
|
||||
|
||||
|
||||
private:
|
||||
StyledText styledText;
|
||||
std::vector<SectionOptions> sections;
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
#include <mbgl/renderer/property_evaluator.hpp>
|
||||
#include <mbgl/renderer/property_evaluation_parameters.hpp>
|
||||
#include <mbgl/style/expression/dsl.hpp>
|
||||
#include <mbgl/style/expression/format_section_override.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
using namespace mbgl::style::expression;
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
|
||||
using namespace std::string_literals;
|
||||
@@ -24,10 +26,23 @@ static StubGeometryTileFeature oneString {
|
||||
PropertyMap {{ "property", "1"s }}
|
||||
};
|
||||
|
||||
static StubGeometryTileFeature oneColor {
|
||||
PropertyMap {{ "color", "red"s }}
|
||||
};
|
||||
|
||||
float evaluate(PropertyValue<float> value, float zoom) {
|
||||
return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto createOverride(expression::type::Type exprType,
|
||||
PossiblyEvaluatedPropertyValue<T> propValue,
|
||||
std::string propName) {
|
||||
return std::make_unique<FormatSectionOverride<T>>(std::move(exprType),
|
||||
std::move(propValue),
|
||||
std::move(propName));
|
||||
}
|
||||
|
||||
TEST(PropertyExpression, Constant) {
|
||||
EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0));
|
||||
EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 0));
|
||||
@@ -121,3 +136,38 @@ TEST(PropertyExpression, Issue8460) {
|
||||
EXPECT_NEAR(600.0f, fn2.evaluate(18.0f, oneInteger, -1.0f), 0.00);
|
||||
EXPECT_NEAR(600.0f, fn2.evaluate(19.0f, oneInteger, -1.0f), 0.00);
|
||||
}
|
||||
|
||||
TEST(PropertyExpression, FormatSectionOverride) {
|
||||
using Value = expression::Value;
|
||||
Value formattedSection =
|
||||
std::unordered_map<std::string, Value>{ {"text-color", Value{Color::blue()}} };
|
||||
auto ctx = expression::EvaluationContext(&oneDouble).withFormattedSection(&formattedSection);
|
||||
PossiblyEvaluatedPropertyValue<Color> constantValueRed(Color::red());
|
||||
PossiblyEvaluatedPropertyValue<Color> constantValueGreen(Color::green());
|
||||
PossiblyEvaluatedPropertyValue<Color> ddsValueRed(toColor(string(get("color"))));
|
||||
|
||||
// Evaluation test
|
||||
{
|
||||
auto override1 = createOverride(expression::type::Color, constantValueGreen, "text-color");
|
||||
PropertyExpression<Color> propExpr(std::move(override1));
|
||||
EXPECT_EQ(Color::green(), propExpr.evaluate(15.0f, oneDouble, Color()));
|
||||
EXPECT_EQ(Color::green(), propExpr.evaluate(oneDouble, Color()));
|
||||
EXPECT_EQ(Color::blue(), propExpr.evaluate(ctx));
|
||||
|
||||
auto override2 = createOverride(expression::type::Color, ddsValueRed, "text-color");
|
||||
PropertyExpression<Color> propExprDDS(std::move(override2));
|
||||
EXPECT_EQ(Color::red(), propExprDDS.evaluate(oneColor, Color()));
|
||||
EXPECT_EQ(Color::blue(), propExprDDS.evaluate(ctx));
|
||||
}
|
||||
|
||||
// Equality test
|
||||
{
|
||||
auto override1 = createOverride(expression::type::Color, constantValueRed, "text-color");
|
||||
auto override2 = createOverride(expression::type::Color, constantValueGreen, "text-color");
|
||||
auto override3 = createOverride(expression::type::Color, constantValueGreen, "text-halo-color");
|
||||
auto override4 = createOverride(expression::type::Color, ddsValueRed, "text-color");
|
||||
EXPECT_TRUE(*override1 != *override2);
|
||||
EXPECT_TRUE(*override2 != *override3);
|
||||
EXPECT_TRUE(*override1 != *override4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/test/stub_layer_observer.hpp>
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
#include <mbgl/style/expression/dsl.hpp>
|
||||
#include <mbgl/style/expression/format_expression.hpp>
|
||||
#include <mbgl/style/style_impl.hpp>
|
||||
#include <mbgl/style/layers/background_layer.hpp>
|
||||
#include <mbgl/style/layers/background_layer_impl.hpp>
|
||||
@@ -16,6 +15,9 @@
|
||||
#include <mbgl/style/layers/raster_layer_impl.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/test/stub_layer_observer.hpp>
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
#include <mbgl/util/color.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/default_thread_pool.hpp>
|
||||
@@ -25,6 +27,9 @@
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
using namespace expression;
|
||||
using namespace expression::dsl;
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -50,6 +55,10 @@ const auto saturation = 1.0f;
|
||||
const auto contrast = 1.0f;
|
||||
const auto duration = 1.0f;
|
||||
|
||||
class MockLayoutProperties : public Properties<TextField> {};
|
||||
class MockPaintProperties : public Properties<TextColor> {};
|
||||
using MockOverrides = FormatSectionOverrides<MockPaintProperties::OverridableProperties>;
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(Layer, BackgroundProperties) {
|
||||
@@ -291,3 +300,75 @@ TEST(Layer, DuplicateLayer) {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
template<template<typename> class PropertyValueType, typename LayoutType>
|
||||
void testHasOverrides(LayoutType& layout) {
|
||||
// Undefined
|
||||
layout.template get<TextField>() = PropertyValueType<Formatted>();
|
||||
EXPECT_FALSE(MockOverrides::hasOverrides(layout.template get<TextField>()));
|
||||
|
||||
// Constant, no overrides.
|
||||
layout.template get<TextField>() = PropertyValueType<Formatted>(Formatted(""));
|
||||
EXPECT_FALSE(MockOverrides::hasOverrides(layout.template get<TextField>()));
|
||||
|
||||
// Constant, overridden text-color.
|
||||
auto formatted = Formatted("");
|
||||
formatted.sections.emplace_back("section text"s, nullopt, nullopt, Color::green());
|
||||
layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(formatted));
|
||||
EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get<TextField>()));
|
||||
|
||||
// Expression, no overrides.
|
||||
auto formatExpr = std::make_unique<FormatExpression>(std::vector<FormatExpressionSection>{});
|
||||
PropertyExpression<Formatted> propExpr(std::move(formatExpr));
|
||||
layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(propExpr));
|
||||
EXPECT_FALSE(MockOverrides::hasOverrides(layout.template get<TextField>()));
|
||||
|
||||
// Expression, overridden text-color.
|
||||
FormatExpressionSection section(literal(""), nullopt, nullopt, toColor(literal("red")));
|
||||
auto formatExprOverride = std::make_unique<FormatExpression>(std::vector<FormatExpressionSection>{section});
|
||||
PropertyExpression<Formatted> propExprOverride(std::move(formatExprOverride));
|
||||
layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(propExprOverride));
|
||||
EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get<TextField>()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(Layer, SymbolLayerOverrides) {
|
||||
|
||||
// Unevaluated / transitionable.
|
||||
{
|
||||
MockLayoutProperties::Unevaluated layout;
|
||||
testHasOverrides<PropertyValue>(layout);
|
||||
|
||||
MockPaintProperties::Transitionable current;
|
||||
MockPaintProperties::Transitionable updated;
|
||||
current.get<TextColor>() = Transitionable<PropertyValue<Color>>{{Color::green()}, {}};
|
||||
updated.get<TextColor>() = Transitionable<PropertyValue<Color>>{{Color::green()}, {}};
|
||||
EXPECT_FALSE(MockOverrides::hasPaintPropertyDifference(current, updated));
|
||||
|
||||
current.get<TextColor>() = Transitionable<PropertyValue<Color>>{{Color::red()}, {}};
|
||||
EXPECT_TRUE(MockOverrides::hasPaintPropertyDifference(current, updated));
|
||||
}
|
||||
|
||||
// Possibly evaluated.
|
||||
{
|
||||
MockLayoutProperties::PossiblyEvaluated layout;
|
||||
MockPaintProperties::PossiblyEvaluated paint;
|
||||
testHasOverrides<PossiblyEvaluatedPropertyValue>(layout);
|
||||
|
||||
// Constant, overridden text-color.
|
||||
auto formatted = Formatted("");
|
||||
formatted.sections.emplace_back("section text"s, nullopt, nullopt, Color::green());
|
||||
layout.get<TextField>() = PossiblyEvaluatedPropertyValue<Formatted>(std::move(formatted));
|
||||
paint.get<TextColor>() = PossiblyEvaluatedPropertyValue<Color>{Color::red()};
|
||||
EXPECT_TRUE(paint.get<TextColor>().isConstant());
|
||||
MockOverrides::setOverrides(layout, paint);
|
||||
EXPECT_FALSE(paint.get<TextColor>().isConstant());
|
||||
|
||||
MockPaintProperties::PossiblyEvaluated updated;
|
||||
updated.get<TextColor>() = PossiblyEvaluatedPropertyValue<Color>{Color::red()};
|
||||
MockOverrides::updateOverrides(paint, updated);
|
||||
EXPECT_FALSE(updated.get<TextColor>().isConstant());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,22 +6,22 @@
|
||||
using namespace mbgl;
|
||||
|
||||
TEST(TaggedString, Trim) {
|
||||
TaggedString basic(u" \t\ntrim that and not this \n\t", SectionOptions(1.0f, 0));
|
||||
TaggedString basic(u" \t\ntrim that and not this \n\t", SectionOptions(1.0f, {}));
|
||||
basic.trim();
|
||||
EXPECT_EQ(basic.rawText(), u"trim that and not this");
|
||||
|
||||
TaggedString twoSections;
|
||||
twoSections.addSection(u" \t\ntrim that", 1.5f, 1);
|
||||
twoSections.addSection(u" and not this \n\t", 0.5f, 2);
|
||||
twoSections.addSection(u" \t\ntrim that", 1.5f, {});
|
||||
twoSections.addSection(u" and not this \n\t", 0.5f, {});
|
||||
|
||||
twoSections.trim();
|
||||
EXPECT_EQ(twoSections.rawText(), u"trim that and not this");
|
||||
|
||||
TaggedString empty(u"\n\t\v \r \t\n", SectionOptions(1.0f, 0));
|
||||
TaggedString empty(u"\n\t\v \r \t\n", SectionOptions(1.0f, {}));
|
||||
empty.trim();
|
||||
EXPECT_EQ(empty.rawText(), u"");
|
||||
|
||||
TaggedString noTrim(u"no trim!", SectionOptions(1.0f, 0));
|
||||
TaggedString noTrim(u"no trim!", SectionOptions(1.0f, {}));
|
||||
noTrim.trim();
|
||||
EXPECT_EQ(noTrim.rawText(), u"no trim!");
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
SymbolFeature(std::make_unique<StubGeometryTileFeature>(std::move(id_), type_, std::move(geometry_), std::move(properties_)))
|
||||
{
|
||||
if (text_) {
|
||||
formattedText = TaggedString(*text_, SectionOptions(1.0, 0));
|
||||
formattedText = TaggedString(*text_, SectionOptions(1.0, {}));
|
||||
}
|
||||
icon = std::move(icon_);
|
||||
index = index_;
|
||||
|
||||
Reference in New Issue
Block a user