summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/layout/symbol_instance.cpp2
-rw-r--r--src/mbgl/layout/symbol_instance.hpp4
-rw-r--r--src/mbgl/layout/symbol_layout.cpp45
-rw-r--r--src/mbgl/layout/symbol_layout.hpp2
-rw-r--r--src/mbgl/style/conversion/constant.cpp18
-rw-r--r--src/mbgl/style/conversion/function.cpp4
-rw-r--r--src/mbgl/style/conversion/property_value.cpp1
-rw-r--r--src/mbgl/style/expression/value.cpp20
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp25
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp4
-rw-r--r--src/mbgl/text/placement.cpp4
-rw-r--r--src/mbgl/text/placement.hpp2
12 files changed, 99 insertions, 32 deletions
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp
index 133cdec698..da26c26b59 100644
--- a/src/mbgl/layout/symbol_instance.cpp
+++ b/src/mbgl/layout/symbol_instance.cpp
@@ -81,7 +81,7 @@ SymbolInstance::SymbolInstance(Anchor& anchor_,
std::u16string key_,
const float overscaling,
const float rotate,
- float radialTextOffset_) :
+ Point<float> radialTextOffset_) :
sharedData(std::move(sharedData_)),
anchor(anchor_),
// 'hasText' depends on finding at least one glyph in the shaping that's also in the GlyphPositionMap
diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp
index 48bb2f0cbc..c0fe5177cf 100644
--- a/src/mbgl/layout/symbol_instance.hpp
+++ b/src/mbgl/layout/symbol_instance.hpp
@@ -59,7 +59,7 @@ public:
std::u16string key,
const float overscaling,
const float rotate,
- float radialTextOffset);
+ Point<float> radialTextOffset);
optional<size_t> getDefaultHorizontalPlacedTextIndex() const;
const GeometryCoordinates& line() const;
@@ -98,7 +98,7 @@ public:
optional<size_t> placedVerticalTextIndex;
optional<size_t> placedIconIndex;
float textBoxScale;
- float radialTextOffset;
+ Point<float> radialTextOffset;
bool singleLine;
uint32_t crossTileID = 0;
};
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index d269ca4144..6548281a06 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -225,26 +225,27 @@ Shaping& shapingForTextJustifyType(ShapedTextOrientations& shapedTextOrientation
} // namespace
// static
-Point<float> SymbolLayout::evaluateRadialOffset(SymbolAnchorType anchor, float radialOffset) {
+Point<float> SymbolLayout::evaluateRadialOffset(SymbolAnchorType anchor, Point<float> radialOffset) {
Point<float> result{};
// solve for r where r^2 + r^2 = radialOffset^2
const float sqrt2 = 1.41421356237f;
- const float hypotenuse = radialOffset / sqrt2;
+ const float hypotenuseX = radialOffset.x / sqrt2;
+ const float hypotenuseY = radialOffset.y / sqrt2;
switch (anchor) {
case SymbolAnchorType::TopRight:
case SymbolAnchorType::TopLeft:
- result.y = hypotenuse - baselineOffset;
+ result.y = hypotenuseY - baselineOffset;
break;
case SymbolAnchorType::BottomRight:
case SymbolAnchorType::BottomLeft:
- result.y = -hypotenuse + baselineOffset;
+ result.y = -hypotenuseY + baselineOffset;
break;
case SymbolAnchorType::Bottom:
- result.y = -radialOffset + baselineOffset;
+ result.y = -radialOffset.y + baselineOffset;
break;
case SymbolAnchorType::Top:
- result.y = radialOffset - baselineOffset;
+ result.y = radialOffset.y - baselineOffset;
break;
default:
break;
@@ -253,17 +254,17 @@ Point<float> SymbolLayout::evaluateRadialOffset(SymbolAnchorType anchor, float r
switch (anchor) {
case SymbolAnchorType::TopRight:
case SymbolAnchorType::BottomRight:
- result.x = -hypotenuse;
+ result.x = -hypotenuseX;
break;
case SymbolAnchorType::TopLeft:
case SymbolAnchorType::BottomLeft:
- result.x = hypotenuse;
+ result.x = hypotenuseX;
break;
case SymbolAnchorType::Left:
- result.x = radialOffset;
+ result.x = radialOffset.x;
break;
case SymbolAnchorType::Right:
- result.x = -radialOffset;
+ result.x = -radialOffset.x;
break;
default:
break;
@@ -272,6 +273,22 @@ Point<float> SymbolLayout::evaluateRadialOffset(SymbolAnchorType anchor, float r
return result;
}
+namespace {
+
+Point<float> handleRadialTextOffset(const std::vector<float>& value) {
+ switch (value.size())
+ {
+ case 0:
+ return { 0.0f, 0.0f };
+ case 1:
+ return { value[0] * util::ONE_EM, value[0] * util::ONE_EM };
+ default:
+ return { value[0] * util::ONE_EM, value[1] * util::ONE_EM };
+ };
+}
+
+} // namespace
+
void SymbolLayout::prepareSymbols(const GlyphMap& glyphMap, const GlyphPositions& glyphPositions,
const ImageMap& imageMap, const ImagePositions& imagePositions) {
const bool isPointPlacement = layout->get<SymbolPlacement>() == SymbolPlacementType::Point;
@@ -306,15 +323,15 @@ void SymbolLayout::prepareSymbols(const GlyphMap& glyphMap, const GlyphPositions
return result;
};
const std::vector<style::TextVariableAnchorType> variableTextAnchor = layout->evaluate<TextVariableAnchor>(zoom, feature);
- const float radialOffset = layout->evaluate<TextRadialOffset>(zoom, feature);
+ const Point<float> radialOffset = handleRadialTextOffset(layout->evaluate<TextRadialOffset>(zoom, feature));
const SymbolAnchorType textAnchor = layout->evaluate<TextAnchor>(zoom, feature);
if (variableTextAnchor.empty()) {
// Layers with variable anchors use the `text-radial-offset` property and the [x, y] offset vector
// is calculated at placement time instead of layout time
- if (radialOffset > 0.0f) {
+ if (radialOffset.x > 0.0f && radialOffset.y > 0.0f) {
// The style spec says don't use `text-offset` and `text-radial-offset` together
// but doesn't actually specify what happens if you use both. We go with the radial offset.
- textOffset = evaluateRadialOffset(textAnchor, radialOffset * util::ONE_EM);
+ textOffset = evaluateRadialOffset(textAnchor, radialOffset);
} else {
textOffset = { layout->evaluate<TextOffset>(zoom, feature)[0] * util::ONE_EM,
layout->evaluate<TextOffset>(zoom, feature)[1] * util::ONE_EM};
@@ -424,7 +441,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex,
const float iconPadding = layout->get<IconPadding>() * tilePixelRatio;
const float textMaxAngle = layout->get<TextMaxAngle>() * util::DEG2RAD;
const float rotation = layout->evaluate<IconRotate>(zoom, feature);
- const float radialTextOffset = layout->evaluate<TextRadialOffset>(zoom, feature) * util::ONE_EM;
+ const Point<float> radialTextOffset = handleRadialTextOffset(layout->evaluate<TextRadialOffset>(zoom, feature));
const SymbolPlacementType textPlacement = layout->get<TextRotationAlignment>() != AlignmentType::Map
? SymbolPlacementType::Point
: layout->get<SymbolPlacement>();
diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp
index 581c3ccb04..82bbc1179b 100644
--- a/src/mbgl/layout/symbol_layout.hpp
+++ b/src/mbgl/layout/symbol_layout.hpp
@@ -45,7 +45,7 @@ public:
const std::string bucketLeaderID;
std::vector<SymbolInstance> symbolInstances;
- static Point<float> evaluateRadialOffset(style::SymbolAnchorType anchor, float radialOffset);
+ static Point<float> evaluateRadialOffset(style::SymbolAnchorType anchor, Point<float> radialOffset);
private:
void addFeature(const size_t,
diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp
index 0fcaab433b..0ed5fad425 100644
--- a/src/mbgl/style/conversion/constant.cpp
+++ b/src/mbgl/style/conversion/constant.cpp
@@ -168,6 +168,24 @@ optional<std::vector<std::string>> Converter<std::vector<std::string>>::operator
return result;
}
+optional<RadialOffsetType> Converter<RadialOffsetType>::operator()(const Convertible& value, Error& error) const {
+ Converter<std::vector<float>> arrayConverter;
+ if (auto val = arrayConverter(value, error)) {
+ RadialOffsetType result = std::move(*val);
+ return result;
+ }
+
+ Converter<float> numberConverter;
+ if (auto val = numberConverter(value, error)) {
+ RadialOffsetType result(2, *val);
+ return result;
+ }
+
+ error.message = "value must be an array of numbers or a number";
+
+ return nullopt;
+}
+
} // namespace conversion
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index 086bc4e277..ade5a5dc5e 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -153,6 +153,10 @@ template optional<PropertyExpression<TranslateAnchorType>>
template optional<PropertyExpression<Formatted>>
convertFunctionToExpression<Formatted>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<RadialOffsetType>>
+ convertFunctionToExpression<RadialOffsetType>(const Convertible&, Error&, bool);
+
+
// Ad-hoc Converters for double and int64_t. We should replace float with double wholesale,
// and promote the int64_t Converter to general use (and it should check that the input is
// an integer).
diff --git a/src/mbgl/style/conversion/property_value.cpp b/src/mbgl/style/conversion/property_value.cpp
index 6e1d747324..91e61ec5cb 100644
--- a/src/mbgl/style/conversion/property_value.cpp
+++ b/src/mbgl/style/conversion/property_value.cpp
@@ -80,6 +80,7 @@ template optional<PropertyValue<TextJustifyType>> Converter<PropertyValue<TextJu
template optional<PropertyValue<TextTransformType>> Converter<PropertyValue<TextTransformType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<TranslateAnchorType>> Converter<PropertyValue<TranslateAnchorType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<mbgl::style::expression::Formatted>> Converter<PropertyValue<mbgl::style::expression::Formatted>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
+template optional<PropertyValue<RadialOffsetType>> Converter<PropertyValue<RadialOffsetType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
} // namespace conversion
} // namespace style
diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp
index 7e11efaa09..6fce98e4d6 100644
--- a/src/mbgl/style/expression/value.cpp
+++ b/src/mbgl/style/expression/value.cpp
@@ -276,6 +276,22 @@ optional<Position> ValueConverter<Position>::fromExpressionValue(const Value& v)
return pos ? optional<Position>(Position(*pos)) : optional<Position>();
}
+Value ValueConverter<RadialOffsetType>::toExpressionValue(const mbgl::style::RadialOffsetType& value) {
+ return ValueConverter<std::vector<float>>::toExpressionValue(value);
+}
+
+optional<RadialOffsetType> ValueConverter<RadialOffsetType>::fromExpressionValue(const Value& v) {
+ if (auto val = ValueConverter<std::vector<float>>::fromExpressionValue(v)) {
+ RadialOffsetType result(std::move(*val));
+ return result;
+ }
+ if (auto val = ValueConverter<float>::fromExpressionValue(v)) {
+ RadialOffsetType result(2, *val);
+ return result;
+ }
+ return nullopt;
+}
+
template <typename T>
Value ValueConverter<T, std::enable_if_t< std::is_enum<T>::value >>::toExpressionValue(const T& value) {
return std::string(Enum<T>::toString(value));
@@ -374,6 +390,10 @@ template struct ValueConverter<HillshadeIlluminationAnchorType>;
template type::Type valueTypeToExpressionType<LightAnchorType>();
template struct ValueConverter<LightAnchorType>;
+template<> type::Type valueTypeToExpressionType<RadialOffsetType>() {
+ return valueTypeToExpressionType<std::vector<float>>();
+}
+
} // namespace expression
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index 6748fbd4aa..c5a32acd12 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -605,15 +605,15 @@ void SymbolLayer::setTextPitchAlignment(const PropertyValue<AlignmentType>& valu
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
-PropertyValue<float> SymbolLayer::getDefaultTextRadialOffset() {
+PropertyValue<RadialOffsetType> SymbolLayer::getDefaultTextRadialOffset() {
return TextRadialOffset::defaultValue();
}
-const PropertyValue<float>& SymbolLayer::getTextRadialOffset() const {
+const PropertyValue<RadialOffsetType>& SymbolLayer::getTextRadialOffset() const {
return impl().layout.get<TextRadialOffset>();
}
-void SymbolLayer::setTextRadialOffset(const PropertyValue<float>& value) {
+void SymbolLayer::setTextRadialOffset(const PropertyValue<RadialOffsetType>& value) {
if (value == getTextRadialOffset())
return;
auto impl_ = mutableImpl();
@@ -1606,7 +1606,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
- if (property == Property::IconRotate || property == Property::IconSize || property == Property::SymbolSortKey || property == Property::TextLetterSpacing || property == Property::TextMaxWidth || property == Property::TextRadialOffset || property == Property::TextRotate || property == Property::TextSize) {
+ if (property == Property::IconRotate || property == Property::IconSize || property == Property::SymbolSortKey || property == Property::TextLetterSpacing || property == Property::TextMaxWidth || property == Property::TextRotate || property == Property::TextSize) {
Error error;
optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
if (!typedValue) {
@@ -1638,11 +1638,6 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
return nullopt;
}
- if (property == Property::TextRadialOffset) {
- setTextRadialOffset(*typedValue);
- return nullopt;
- }
-
if (property == Property::TextRotate) {
setTextRotate(*typedValue);
return nullopt;
@@ -1739,6 +1734,18 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
+ if (property == Property::TextRadialOffset) {
+ Error error;
+ optional<PropertyValue<RadialOffsetType>> typedValue = convert<PropertyValue<RadialOffsetType>>(value, error, true, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setTextRadialOffset(*typedValue);
+ return nullopt;
+
+ }
+
if (property == Property::TextTransform) {
Error error;
optional<PropertyValue<TextTransformType>> typedValue = convert<PropertyValue<TextTransformType>>(value, error, true, false);
diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp
index 0c2bcd2661..4215819abe 100644
--- a/src/mbgl/style/layers/symbol_layer_properties.hpp
+++ b/src/mbgl/style/layers/symbol_layer_properties.hpp
@@ -184,9 +184,9 @@ struct TextPitchAlignment : LayoutProperty<AlignmentType> {
static AlignmentType defaultValue() { return AlignmentType::Auto; }
};
-struct TextRadialOffset : DataDrivenLayoutProperty<float> {
+struct TextRadialOffset : DataDrivenLayoutProperty<RadialOffsetType> {
static constexpr const char *name() { return "text-radial-offset"; }
- static float defaultValue() { return 0; }
+ static RadialOffsetType defaultValue() { return { 0, 0 }; }
};
struct TextRotate : DataDrivenLayoutProperty<float> {
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index f7d13dcb26..c28842069a 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -85,7 +85,7 @@ void Placement::placeLayer(const RenderLayer& layer, const mat4& projMatrix, boo
}
namespace {
-Point<float> calculateVariableLayoutOffset(style::SymbolAnchorType anchor, float width, float height, float radialOffset, float textBoxScale) {
+Point<float> calculateVariableLayoutOffset(style::SymbolAnchorType anchor, float width, float height, Point<float> radialOffset, float textBoxScale) {
AnchorAlignment alignment = AnchorAlignment::getAnchorAlignment(anchor);
float shiftX = -(alignment.horizontalAlign - 0.5f) * width;
float shiftY = -(alignment.verticalAlign - 0.5f) * height;
@@ -410,7 +410,7 @@ void Placement::updateLayerBuckets(const RenderLayer& layer, const TransformStat
}
namespace {
-Point<float> calculateVariableRenderShift(style::SymbolAnchorType anchor, float width, float height, float radialOffset, float textBoxScale, float renderTextSize) {
+Point<float> calculateVariableRenderShift(style::SymbolAnchorType anchor, float width, float height, Point<float> radialOffset, float textBoxScale, float renderTextSize) {
AnchorAlignment alignment = AnchorAlignment::getAnchorAlignment(anchor);
float shiftX = -(alignment.horizontalAlign - 0.5f) * width;
float shiftY = -(alignment.verticalAlign - 0.5f) * height;
diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp
index 2a6a2e1d6e..6a372c1a58 100644
--- a/src/mbgl/text/placement.hpp
+++ b/src/mbgl/text/placement.hpp
@@ -33,7 +33,7 @@ public:
class VariableOffset {
public:
- float radialOffset;
+ Point<float> radialOffset;
float width;
float height;
style::TextVariableAnchorType anchor;