Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for text-variable-anchor-offset property #2921

Merged
merged 48 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
75362aa
add variableAnchorOffsetCollection data type for text-variable-anchor…
Aug 23, 2024
b1557f4
Merge branch 'main' into text-variable-anchor-offset
Aug 23, 2024
06619f3
revert change in placement
Aug 23, 2024
7096c76
use text-variable-anchor-offset in placement
Sep 6, 2024
f7fe15a
fix failed render test
Sep 11, 2024
7688166
change map to vector
Sep 19, 2024
ae701a2
add test case
Sep 19, 2024
ccc68bd
build pass on Android
Sep 23, 2024
38732fe
WIP: coersion when using data binding
random3940 Sep 25, 2024
ebf2f58
WIP: NSExpressions
random3940 Sep 26, 2024
108002b
update code to pass render test
Sep 27, 2024
1dd1ec3
WIP: More NSExpressions
random3940 Sep 27, 2024
f6334d1
update expected images
Sep 29, 2024
f48fc21
WIP
random3940 Sep 29, 2024
2282396
fix unit build and update expected images
Sep 30, 2024
4c4a61e
Minor clean-up
random3940 Oct 1, 2024
2464724
Fix node.js build
random3940 Oct 3, 2024
3156ef5
Streamline VariableAnchorOffsetCollection API
random3940 Oct 3, 2024
ea9c411
Merge branch 'main' of https://github.com/wangyingfang/maplibre-nativ…
Oct 9, 2024
d23b90d
update cache style db
Oct 9, 2024
7f19db2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
e9e8ac4
Merge branch 'main' of https://github.com/wangyingfang/maplibre-nativ…
Oct 9, 2024
c61ea7b
fix comments
Oct 10, 2024
1f8350c
Merge branch 'text-variable-anchor-offset' of https://github.com/wang…
Oct 10, 2024
a58bf3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
768bc29
update mjs
Oct 11, 2024
28e8795
add jni for text-variable-anchor-offset on Anroid
Oct 12, 2024
58417d9
update size in metric
Oct 12, 2024
4b43f8e
add more metrics
Oct 12, 2024
518d98f
fix clang format
Oct 14, 2024
8d83c75
resolve comments
Oct 15, 2024
6438b59
revert bad changes
Oct 15, 2024
c031166
Merge pull request #2 from wangyingfang/text-variable-anchor-offset-w…
wangyingfang Oct 15, 2024
e09c64d
Merge branch 'maplibre:main' into text-variable-anchor-offset
wangyingfang Oct 15, 2024
ead66a8
resolve comments
Oct 16, 2024
aded18d
Merge branch 'main' into text-variable-anchor-offset
wangyingfang Oct 16, 2024
7b269ed
fix build error
Oct 16, 2024
7b265f9
add more unit tests
Oct 18, 2024
d40ff29
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2024
723ece0
Merge branch 'main' into text-variable-anchor-offset
louwers Oct 18, 2024
5a35f80
fix comments and fix build error
Oct 21, 2024
bb5afe3
Merge branch 'main' into text-variable-anchor-offset
wangyingfang Oct 22, 2024
7d46f8f
fix comments
Oct 24, 2024
9389638
update unit test
Oct 24, 2024
5f9a162
Merge branch 'main' into text-variable-anchor-offset
wangyingfang Oct 24, 2024
85bc5a4
Merge branch 'text-variable-anchor-offset' of https://github.com/wang…
Oct 24, 2024
dab4f05
Merge branch 'main' into text-variable-anchor-offset
louwers Oct 26, 2024
fbfc988
Merge branch 'main' into text-variable-anchor-offset
wangyingfang Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ list(APPEND INCLUDE_FILES
${PROJECT_SOURCE_DIR}/include/mbgl/style/transition_options.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/types.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/undefined.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/variable_anchor_offset_collection.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/text/glyph.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/text/glyph_range.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/tile/tile_id.hpp
Expand Down Expand Up @@ -864,6 +865,7 @@ list(APPEND SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/style/style_impl.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/style_impl.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/types.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/variable_anchor_offset_collection.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_layer.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_layer_render_parameters.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/layermanager/custom_layer_factory.cpp
Expand Down
2 changes: 2 additions & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ MLN_CORE_SOURCE = [
"src/mbgl/style/style_impl.cpp",
"src/mbgl/style/style_impl.hpp",
"src/mbgl/style/types.cpp",
"src/mbgl/style/variable_anchor_offset_collection.cpp",
"src/mbgl/text/bidi.hpp",
"src/mbgl/text/check_max_angle.cpp",
"src/mbgl/text/check_max_angle.hpp",
Expand Down Expand Up @@ -802,6 +803,7 @@ MLN_CORE_HEADERS = [
"include/mbgl/style/transition_options.hpp",
"include/mbgl/style/types.hpp",
"include/mbgl/style/undefined.hpp",
"include/mbgl/style/variable_anchor_offset_collection.hpp",
"include/mbgl/text/glyph.hpp",
"include/mbgl/text/glyph_range.hpp",
"include/mbgl/tile/tile_id.hpp",
Expand Down
6 changes: 6 additions & 0 deletions include/mbgl/style/conversion/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/style/conversion.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/variable_anchor_offset_collection.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/padding.hpp>
Expand Down Expand Up @@ -50,6 +51,11 @@ struct Converter<Padding> {
std::optional<Padding> operator()(const Convertible& value, Error& error) const;
};

template <>
struct Converter<VariableAnchorOffsetCollection> {
std::optional<VariableAnchorOffsetCollection> operator()(const Convertible& value, Error& error) const;
};

template <size_t N>
struct Converter<std::array<float, N>> {
std::optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const;
Expand Down
10 changes: 10 additions & 0 deletions include/mbgl/style/conversion_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ struct ValueFactory<Padding> {
static Value make(const Padding& padding) { return padding.serialize(); }
};

template <>
struct ValueFactory<VariableAnchorOffsetCollection> {
static Value make(const VariableAnchorOffsetCollection& variableAnchorOffset) {
return variableAnchorOffset.serialize();
}
};

template <typename T>
struct ValueFactory<T, typename std::enable_if_t<(!std::is_enum_v<T> && !is_linear_container<T>::value)>> {
static Value make(const T& arg) { return {arg}; }
Expand Down Expand Up @@ -370,6 +377,9 @@ StyleProperty makeStyleProperty(const PropertyValue<T>& value) {
[](const Undefined&) -> StyleProperty { return {}; },
[](const Color& c) -> StyleProperty { return {makeValue(c), StyleProperty::Kind::Expression}; },
[](const Padding& p) -> StyleProperty { return {makeValue(p), StyleProperty::Kind::Expression}; },
[](const VariableAnchorOffsetCollection& v) -> StyleProperty {
return {makeValue(v), StyleProperty::Kind::Expression};
},
[](const PropertyExpression<T>& fn) -> StyleProperty {
return {fn.getExpression().serialize(), StyleProperty::Kind::Expression};
},
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/style/expression/dsl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ std::unique_ptr<Expression> boolean(std::unique_ptr<Expression>, std::unique_ptr

std::unique_ptr<Expression> toColor(std::unique_ptr<Expression>, std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> toPadding(std::unique_ptr<Expression> value, std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> toVariableAnchorOffset(std::unique_ptr<Expression>,
std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> toString(std::unique_ptr<Expression>, std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> toFormatted(std::unique_ptr<Expression>, std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> toImage(std::unique_ptr<Expression>, std::unique_ptr<Expression> def = nullptr);
Expand Down
8 changes: 8 additions & 0 deletions include/mbgl/style/expression/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ struct PaddingType {
bool operator==(const PaddingType&) const { return true; }
};

struct VariableAnchorOffsetCollectionType {
constexpr VariableAnchorOffsetCollectionType() = default;
std::string getName() const { return "variableAnchorOffsetCollection"; }
bool operator==(const VariableAnchorOffsetCollectionType&) const { return true; }
};

struct ObjectType {
constexpr ObjectType() = default;
std::string getName() const { return "object"; }
Expand Down Expand Up @@ -92,6 +98,7 @@ constexpr StringType String;
constexpr BooleanType Boolean;
constexpr ColorType Color;
constexpr PaddingType Padding;
constexpr VariableAnchorOffsetCollectionType VariableAnchorOffsetCollection;
constexpr ValueType Value;
constexpr ObjectType Object;
constexpr CollatorType Collator;
Expand All @@ -107,6 +114,7 @@ using Type = variant<NullType,
StringType,
ColorType,
PaddingType,
VariableAnchorOffsetCollectionType,
ObjectType,
ValueType,
mapbox::util::recursive_wrapper<Array>,
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/style/expression/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <mbgl/style/position.hpp>
#include <mbgl/style/rotation.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/variable_anchor_offset_collection.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/feature.hpp>
Expand All @@ -28,6 +29,7 @@ using ValueBase = variant<NullValue,
double,
std::string,
Color,
VariableAnchorOffsetCollection,
Collator,
Formatted,
Image,
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/layers/layer.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<% } -%>
<% if (type === 'symbol') { -%>
#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/style/variable_anchor_offset_collection.hpp>
<% } -%>
#include <mbgl/util/color.hpp>

Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/style/layers/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/style/variable_anchor_offset_collection.hpp>
#include <mbgl/util/color.hpp>

#include <vector>
Expand Down Expand Up @@ -184,6 +185,10 @@ class SymbolLayer final : public Layer {
const PropertyValue<std::vector<TextVariableAnchorType>>& getTextVariableAnchor() const;
void setTextVariableAnchor(const PropertyValue<std::vector<TextVariableAnchorType>>&);

static PropertyValue<VariableAnchorOffsetCollection> getDefaultTextVariableAnchorOffset();
const PropertyValue<VariableAnchorOffsetCollection>& getTextVariableAnchorOffset() const;
void setTextVariableAnchorOffset(const PropertyValue<VariableAnchorOffsetCollection>&);

static PropertyValue<std::vector<TextWritingModeType>> getDefaultTextWritingMode();
const PropertyValue<std::vector<TextWritingModeType>>& getTextWritingMode() const;
void setTextWritingMode(const PropertyValue<std::vector<TextWritingModeType>>&);
Expand Down
61 changes: 61 additions & 0 deletions include/mbgl/style/variable_anchor_offset_collection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <mbgl/style/types.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/geometry.hpp>

#include <array>
#include <string>
#include <vector>

namespace mbgl {

struct AnchorOffsetPair {
style::SymbolAnchorType anchorType;
std::array<float, 2> offset;

AnchorOffsetPair(style::SymbolAnchorType anchorType_, std::array<float, 2> offset_)
: anchorType(anchorType_),
offset(offset_) {}

bool operator==(const AnchorOffsetPair& other) const = default;
};

class VariableAnchorOffsetCollection {
private:
using CollectionType = std::vector<AnchorOffsetPair>;
CollectionType anchorOffsets;

public:
VariableAnchorOffsetCollection() = default;

VariableAnchorOffsetCollection(const VariableAnchorOffsetCollection& other) = default;

VariableAnchorOffsetCollection(VariableAnchorOffsetCollection&& other) noexcept = default;

VariableAnchorOffsetCollection(std::vector<AnchorOffsetPair>&& values) { anchorOffsets = std::move(values); }

std::array<float, 2> getOffsetByAnchor(const style::SymbolAnchorType& anchorType) const;

std::string toString() const;

mbgl::Value serialize() const;

bool empty() const { return anchorOffsets.size() == 0; }

CollectionType::size_type size() const { return anchorOffsets.size(); }

CollectionType::const_iterator begin() const { return anchorOffsets.begin(); }

CollectionType::const_iterator end() const { return anchorOffsets.end(); }

const AnchorOffsetPair& operator[](size_t index) const { return anchorOffsets[index]; }

VariableAnchorOffsetCollection& operator=(const VariableAnchorOffsetCollection& other) = default;

VariableAnchorOffsetCollection& operator=(VariableAnchorOffsetCollection&& other) noexcept = default;

bool operator==(const VariableAnchorOffsetCollection& other) const = default;
};

} // namespace mbgl
34 changes: 34 additions & 0 deletions include/mbgl/util/interpolate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/position.hpp>
#include <mbgl/style/rotation.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/variable_anchor_offset_collection.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/string.hpp>

#include <array>
#include <vector>
Expand Down Expand Up @@ -143,6 +147,36 @@ struct Interpolator<Padding> {
}
};

template <>
struct Interpolator<VariableAnchorOffsetCollection> {
public:
VariableAnchorOffsetCollection operator()(const VariableAnchorOffsetCollection& a,
const VariableAnchorOffsetCollection& b,
const float t) const {
if (a.size() != b.size()) {
throw std::runtime_error("Cannot interpolate values of different length. from: " + a.toString() +
", to: " + b.toString());
}
std::vector<AnchorOffsetPair> offsetMap;
offsetMap.reserve(a.size());
for (size_t index = 0; index < a.size(); index++) {
const auto& aPair = a[index];
const auto& bPair = b[index];
if (aPair.anchorType != bPair.anchorType) {
throw std::runtime_error(
"Cannot interpolate values containing mismatched anchors. index: " + util::toString(index) +
"from: " + Enum<style::SymbolAnchorType>::toString(aPair.anchorType) +
", to: " + Enum<style::SymbolAnchorType>::toString(bPair.anchorType));
}
auto offset = std::array<float, 2>{interpolate(aPair.offset[0], bPair.offset[0], t),
interpolate(aPair.offset[1], bPair.offset[1], t)};
offsetMap.emplace_back(aPair.anchorType, offset);
wangyingfang marked this conversation as resolved.
Show resolved Hide resolved
}

return VariableAnchorOffsetCollection(std::move(offsetMap));
}
};

template <>
struct Interpolator<style::Rotation> {
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
7,
1778473
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
8,
13,
37,
1,
[
90448,
90448
],
[
100366,
100366
],
[
1337984,
1337984
]
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
4,
686859
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
1,
5,
9,
1,
[
52212,
52212
],
[
5494,
5494
],
[
73024,
73024
]
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": [
[
"probeNetwork - default - end",
7,
1778473
],
[
"probeNetwork - default - start",
0,
0
]
],
"gfx": [
[
"probeGFX - default - end",
4,
13,
21,
1,
[
143312,
143312
],
[
97654,
97654
],
[
1301824,
1301824
]
]
]
}
Loading
Loading