summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-11-06 17:23:23 -0800
committerChris Loer <chris.loer@gmail.com>2017-11-06 17:24:01 -0800
commit3675cf3c78d58268e92bafb1348a31422c4836bd (patch)
tree5be965d8ca4299d735eb4b78042897bb744fd325
parentc02ec9f06c984dd9d35d305a493136c0abc3e2ad (diff)
downloadqtlocation-mapboxgl-upstream/start-collision-query-tests.tar.gz
Port fix of gl-js issue #5546 (correct vertical orientation for single-glyph labels)upstream/start-collision-query-tests
-rw-r--r--src/mbgl/layout/symbol_projection.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/mbgl/layout/symbol_projection.cpp b/src/mbgl/layout/symbol_projection.cpp
index d99b7e7620..fa88ffdf22 100644
--- a/src/mbgl/layout/symbol_projection.cpp
+++ b/src/mbgl/layout/symbol_projection.cpp
@@ -252,6 +252,28 @@ namespace mbgl {
return std::make_pair(*firstPlacedGlyph, *lastPlacedGlyph);
}
+
+ optional<PlacementResult> requiresOrientationChange(const WritingModeType writingModes, const Point<float>& firstPoint, const Point<float>& lastPoint, const float aspectRatio) {
+ if (writingModes == (WritingModeType::Horizontal | WritingModeType::Vertical)) {
+ // On top of choosing whether to flip, choose whether to render this version of the glyphs or the alternate
+ // vertical glyphs. We can't just filter out vertical glyphs in the horizontal range because the horizontal
+ // and vertical versions can have slightly different projections which could lead to angles where both or
+ // neither showed.
+ auto rise = std::abs(lastPoint.y - firstPoint.y);
+ auto run = std::abs(lastPoint.x - firstPoint.x) * aspectRatio;
+ if (rise > run) {
+ return PlacementResult::UseVertical;
+ }
+ }
+
+ if ((writingModes == WritingModeType::Vertical) ?
+ (firstPoint.y < lastPoint.y) :
+ (firstPoint.x > lastPoint.x)) {
+ // Includes "horizontalOnly" case for labels without vertical glyphs
+ return PlacementResult::NeedsFlipping;
+ }
+ return {};
+ }
PlacementResult placeGlyphsAlongLine(const PlacedSymbol& symbol,
const float fontSize,
@@ -280,25 +302,10 @@ namespace mbgl {
const Point<float> lastPoint = project(firstAndLastGlyph->second.point, glCoordMatrix).first;
if (keepUpright && !flip) {
- if (symbol.writingModes == (WritingModeType::Horizontal | WritingModeType::Vertical)) {
- // On top of choosing whether to flip, choose whether to render this version of the glyphs or the alternate
- // vertical glyphs. We can't just filter out vertical glyphs in the horizontal range because the horizontal
- // and vertical versions can have slightly different projections which could lead to angles where both or
- // neither showed.
- auto rise = std::abs(lastPoint.y - firstPoint.y);
- auto run = std::abs(lastPoint.x - firstPoint.x) * aspectRatio;
- if (rise > run) {
- return PlacementResult::UseVertical;
- }
- }
-
- if ((symbol.writingModes == WritingModeType::Vertical) ?
- (firstPoint.y < lastPoint.y) :
- (firstPoint.x > lastPoint.x)) {
- // Includes "horizontalOnly" case for labels without vertical glyphs
- return PlacementResult::NeedsFlipping;
+ auto orientationChange = requiresOrientationChange(symbol.writingModes, firstPoint, lastPoint, aspectRatio);
+ if (orientationChange) {
+ return *orientationChange;
}
-
}
placedGlyphs.push_back(firstAndLastGlyph->first);
@@ -323,8 +330,9 @@ namespace mbgl {
projectedVertex.first :
projectTruncatedLineSegment(symbol.anchorPoint,tileSegmentEnd, a, 1, posMatrix);
- if (symbol.writingModes == WritingModeType::Vertical ? b.y > a.y : b.x < a.x) {
- return PlacementResult::NeedsFlipping;
+ auto orientationChange = requiresOrientationChange(symbol.writingModes, a, b, aspectRatio);
+ if (orientationChange) {
+ return *orientationChange;
}
}
assert(symbol.glyphOffsets.size() == 1); // We are relying on SymbolInstance.hasText filtering out symbols without any glyphs at all