Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Enable variable label placement for allowed text overlap #15354

Merged
merged 4 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started.

## master
- Enable variable label placement when `text-allow-overlap` property is set to true [#15354](https://github.com/mapbox/mapbox-gl-native/pull/15354).
- Introduce `text-writing-mode` layout property for symbol layer [#14932](https://github.com/mapbox/mapbox-gl-native/pull/14932). The `text-writing-mode` layout property allows control over symbol's preferred writing mode. The new property value is an array, whose values are enumeration values from a ( `horizontal` | `vertical` ) set.

### Features
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT

### Styles and rendering

* Enable variable label placement when `text-allow-overlap` property is set to true. ([#15354](https://github.com/mapbox/mapbox-gl-native/pull/15354))
* Introduce `text-writing-mode` layout property for symbol layer ([#14932](https://github.com/mapbox/mapbox-gl-native/pull/14932)). The `text-writing-mode` layout property allows control over symbol's preferred writing mode. The new property value is an array, whose values are enumeration values from a ( `horizontal` | `vertical` ) set.

## 5.3.0
Expand Down
26 changes: 14 additions & 12 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ void Placement::placeBucket(
const float height = textBox.y2 - textBox.y1;
const float textBoxScale = symbolInstance.textBoxScale;
std::pair<bool, bool> placedFeature = {false, false};
for (auto anchor : variableTextAnchors) {
const size_t anchorsSize = variableTextAnchors.size();
const size_t placementAttempts = textAllowOverlap ? anchorsSize * 2 : anchorsSize;
for (size_t i = 0u; i < placementAttempts; ++i) {
auto anchor = variableTextAnchors[i % anchorsSize];
const bool allowOverlap = (i >= anchorsSize);
Point<float> shift = calculateVariableLayoutOffset(anchor, width, height, symbolInstance.radialTextOffset, textBoxScale);
if (rotateWithMap) {
float angle = pitchWithMap ? state.getBearing() : -state.getBearing();
Expand All @@ -285,7 +289,7 @@ void Placement::placeBucket(
placedFeature = collisionIndex.placeFeature(collisionFeature, shift,
posMatrix, mat4(), pixelRatio,
placedSymbol, scale, fontSize,
layout.get<style::TextAllowOverlap>(),
allowOverlap,
pitchWithMap,
params.showCollisionBoxes, avoidEdges, collisionGroup.second, textBoxes);
if (placedFeature.first) {
Expand Down Expand Up @@ -584,15 +588,13 @@ bool Placement::updateBucketDynamicVertices(SymbolBucket& bucket, const Transfor
if (pitchWithMap) {
shiftedAnchor = project(Point<float>(tileAnchor.x + shift.x, tileAnchor.y + shift.y),
labelPlaneMatrix).first;
} else if (rotateWithMap) {
auto rotated = util::rotate(shift, -state.getPitch());
shiftedAnchor = Point<float>(projectedAnchor.first.x + rotated.x,
projectedAnchor.first.y + rotated.y);
} else {
if (rotateWithMap) {
auto rotated = util::rotate(shift, -state.getPitch());
shiftedAnchor = Point<float>(projectedAnchor.first.x + rotated.x,
projectedAnchor.first.y + rotated.y);
} else {
shiftedAnchor = Point<float>(projectedAnchor.first.x + shift.x,
projectedAnchor.first.y + shift.y);
}
shiftedAnchor = Point<float>(projectedAnchor.first.x + shift.x,
projectedAnchor.first.y + shift.y);
}

for (std::size_t i = 0; i < symbol.glyphOffsets.size(); ++i) {
Expand Down Expand Up @@ -806,7 +808,7 @@ const style::TextJustifyType justifyTypes[] = {style::TextJustifyType::Right, st

} // namespace

void Placement::markUsedJustification(SymbolBucket& bucket, style::TextVariableAnchorType placedAnchor, SymbolInstance& symbolInstance, style::TextWritingModeType orientation) {
void Placement::markUsedJustification(SymbolBucket& bucket, style::TextVariableAnchorType placedAnchor, const SymbolInstance& symbolInstance, style::TextWritingModeType orientation) {
style::TextJustifyType anchorJustify = getAnchorJustification(placedAnchor);
assert(anchorJustify != style::TextJustifyType::Auto);
const optional<size_t>& autoIndex = justificationToIndex(anchorJustify, symbolInstance, orientation);
Expand All @@ -826,7 +828,7 @@ void Placement::markUsedJustification(SymbolBucket& bucket, style::TextVariableA
}
}

void Placement::markUsedOrientation(SymbolBucket& bucket, style::TextWritingModeType orientation, SymbolInstance& symbolInstance) {
void Placement::markUsedOrientation(SymbolBucket& bucket, style::TextWritingModeType orientation, const SymbolInstance& symbolInstance) {
auto horizontal = orientation == style::TextWritingModeType::Horizontal ?
optional<style::TextWritingModeType>(orientation) : nullopt;
auto vertical = orientation == style::TextWritingModeType::Vertical ?
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/text/placement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class Placement {
// Returns `true` if bucket vertices were updated; returns `false` otherwise.
bool updateBucketDynamicVertices(SymbolBucket&, const TransformState&, const RenderTile& tile) const;
void updateBucketOpacities(SymbolBucket&, const TransformState&, std::set<uint32_t>&);
void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, SymbolInstance&, style::TextWritingModeType orientation);
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, SymbolInstance&);
void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, const SymbolInstance&, style::TextWritingModeType orientation);
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&);

CollisionIndex collisionIndex;

Expand Down