diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-09-06 12:19:21 +0300 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-09-06 12:45:25 +0300 |
commit | 72f1e9a8014690e0d4b96341077cd988f523d51f (patch) | |
tree | 2c32493ca09aea02e16a297970cdc765654847d4 | |
parent | f53143f1a1018050a2104f9afd929c963951527d (diff) | |
download | qtlocation-mapboxgl-upstream/alexshalamov_vertical_label_offset.tar.gz |
[core] Swap offset values for vertical POI labelsupstream/alexshalamov_vertical_label_offset
-rw-r--r-- | src/mbgl/text/quads.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/text/shaping.cpp | 12 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 281c5d99de..91b4d723a3 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -58,7 +58,7 @@ SymbolQuad getIconQuad(const PositionedIcon& shapedIcon, } SymbolQuads getGlyphQuads(const Shaping& shapedText, - const std::array<float, 2> textOffset, + const std::array<float, 2> textOffset_, const SymbolLayoutProperties::Evaluated& layout, const style::SymbolPlacementType placement, const GlyphPositions& positions, @@ -67,6 +67,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText, const bool alongLine = layout.get<TextRotationAlignment>() == AlignmentType::Map && placement != SymbolPlacementType::Point; SymbolQuads quads; + std::array<float, 2> textOffset = textOffset_; for (const PositionedGlyph &positionedGlyph: shapedText.positionedGlyphs) { auto fontPositions = positions.find(positionedGlyph.font); @@ -85,6 +86,12 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText, const float rectBuffer = 3.0f + glyphPadding; const float halfAdvance = glyph.metrics.advance * positionedGlyph.scale / 2.0; + const bool rotateVerticalGlyph = (alongLine || allowVerticalPlacement) && positionedGlyph.vertical; + + // Swap offsets for vertical POI labels + if (rotateVerticalGlyph) { + textOffset = {{textOffset_[1], -textOffset_[0]}}; + } const Point<float> glyphOffset = alongLine ? Point<float>{ positionedGlyph.x + halfAdvance, positionedGlyph.y } : @@ -95,7 +102,6 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText, Point<float>{ positionedGlyph.x + halfAdvance + textOffset[0], positionedGlyph.y + textOffset[1] }; Point<float> verticalizedLabelOffset = { 0.0f, 0.0f }; - const bool rotateVerticalGlyph = (alongLine || allowVerticalPlacement) && positionedGlyph.vertical; if (rotateVerticalGlyph) { // Vertical POI labels, that are rotated 90deg CW and whose glyphs must preserve upright orientation // need to be rotated 90deg CCW. After quad is rotated, it is translated to the original built-in offset. diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index d6d9a3d34e..a454fc6506 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -432,10 +432,18 @@ const Shaping getShaping(const TaggedString& formattedString, reorderedLines.emplace_back(line, formattedString.getSections()); } } - Shaping shaping(translate[0], translate[1], writingMode, reorderedLines.size()); + + Shaping shaping; + // Swap text-offset for vertical POI labels. + if (allowVerticalPlacement && writingMode == WritingModeType::Vertical) { + shaping = Shaping(translate[1], -translate[0], writingMode, reorderedLines.size()); + } else { + shaping = Shaping(translate[0], translate[1], writingMode, reorderedLines.size()); + } + shapeLines(shaping, reorderedLines, spacing, lineHeight, textAnchor, textJustify, writingMode, glyphs, allowVerticalPlacement); - + return shaping; } |