From 72f1e9a8014690e0d4b96341077cd988f523d51f Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Fri, 6 Sep 2019 12:19:21 +0300 Subject: [core] Swap offset values for vertical POI labels --- src/mbgl/text/quads.cpp | 10 ++++++++-- 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 textOffset, + const std::array 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() == AlignmentType::Map && placement != SymbolPlacementType::Point; SymbolQuads quads; + std::array 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 glyphOffset = alongLine ? Point{ positionedGlyph.x + halfAdvance, positionedGlyph.y } : @@ -95,7 +102,6 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText, Point{ positionedGlyph.x + halfAdvance + textOffset[0], positionedGlyph.y + textOffset[1] }; Point 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; } -- cgit v1.2.1