summaryrefslogtreecommitdiff
path: root/src/mbgl/text/quads.cpp
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-08-14 15:33:19 -0700
committerChris Loer <chris.loer@mapbox.com>2017-08-18 10:53:26 -0700
commitfd2b525c4d196520abaf9f347d3a73c37b47bd61 (patch)
tree289765c0508c5e64a7f9fd8afbf1e691fbb0e363 /src/mbgl/text/quads.cpp
parentedc8a6492eec6d2f7237cd8a64f3c30817506132 (diff)
downloadqtlocation-mapboxgl-fd2b525c4d196520abaf9f347d3a73c37b47bd61.tar.gz
[core] Correct x-offset introduced by vertical glyph rotation
Fixes issue#9768. Port of GL JS PR #5100.
Diffstat (limited to 'src/mbgl/text/quads.cpp')
-rw-r--r--src/mbgl/text/quads.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp
index 7908ea4abc..0014ae8d01 100644
--- a/src/mbgl/text/quads.cpp
+++ b/src/mbgl/text/quads.cpp
@@ -133,18 +133,27 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
const float x2 = x1 + rect.w;
const float y2 = y1 + rect.h;
- const Point<float> center{builtInOffset.x - halfAdvance, static_cast<float>(static_cast<float>(glyph.metrics.advance) / 2.0)};
-
Point<float> tl{x1, y1};
Point<float> tr{x2, y1};
Point<float> bl{x1, y2};
Point<float> br{x2, y2};
- if (positionedGlyph.angle != 0) {
- tl = util::rotate(tl - center, positionedGlyph.angle) + center;
- tr = util::rotate(tr - center, positionedGlyph.angle) + center;
- bl = util::rotate(bl - center, positionedGlyph.angle) + center;
- br = util::rotate(br - center, positionedGlyph.angle) + center;
+ if (alongLine && positionedGlyph.vertical) {
+ // Vertical-supporting glyphs are laid out in 24x24 point boxes (1 square em)
+ // In horizontal orientation, the y values for glyphs are below the midline
+ // and we use a "yOffset" of -17 to pull them up to the middle.
+ // By rotating counter-clockwise around the point at the center of the left
+ // edge of a 24x24 layout box centered below the midline, we align the center
+ // of the glyphs with the horizontal midline, so the yOffset is no longer
+ // necessary, but we also pull the glyph to the left along the x axis
+ const Point<float> center{-halfAdvance, halfAdvance};
+ const float verticalRotation = -M_PI_2;
+ const Point<float> xOffsetCorrection{5, 0};
+
+ tl = util::rotate(tl - center, verticalRotation) + center + xOffsetCorrection;
+ tr = util::rotate(tr - center, verticalRotation) + center + xOffsetCorrection;
+ bl = util::rotate(bl - center, verticalRotation) + center + xOffsetCorrection;
+ br = util::rotate(br - center, verticalRotation) + center + xOffsetCorrection;
}
if (textRotate) {