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

Commit fd2b525

Browse files
committed
[core] Correct x-offset introduced by vertical glyph rotation
Fixes issue#9768. Port of GL JS PR #5100.
1 parent edc8a64 commit fd2b525

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

mapbox-gl-js

Submodule mapbox-gl-js updated 82 files

src/mbgl/text/glyph.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ using GlyphMap = std::map<FontStack, Glyphs>;
5858

5959
class PositionedGlyph {
6060
public:
61-
explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, float angle_)
62-
: glyph(glyph_), x(x_), y(y_), angle(angle_) {}
61+
explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, bool vertical_)
62+
: glyph(glyph_), x(x_), y(y_), vertical(vertical_) {}
6363

6464
GlyphID glyph = 0;
6565
float x = 0;
6666
float y = 0;
67-
float angle = 0;
67+
bool vertical = false;
6868
};
6969

7070
enum class WritingModeType : uint8_t;

src/mbgl/text/quads.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,27 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
133133
const float x2 = x1 + rect.w;
134134
const float y2 = y1 + rect.h;
135135

136-
const Point<float> center{builtInOffset.x - halfAdvance, static_cast<float>(static_cast<float>(glyph.metrics.advance) / 2.0)};
137-
138136
Point<float> tl{x1, y1};
139137
Point<float> tr{x2, y1};
140138
Point<float> bl{x1, y2};
141139
Point<float> br{x2, y2};
142140

143-
if (positionedGlyph.angle != 0) {
144-
tl = util::rotate(tl - center, positionedGlyph.angle) + center;
145-
tr = util::rotate(tr - center, positionedGlyph.angle) + center;
146-
bl = util::rotate(bl - center, positionedGlyph.angle) + center;
147-
br = util::rotate(br - center, positionedGlyph.angle) + center;
141+
if (alongLine && positionedGlyph.vertical) {
142+
// Vertical-supporting glyphs are laid out in 24x24 point boxes (1 square em)
143+
// In horizontal orientation, the y values for glyphs are below the midline
144+
// and we use a "yOffset" of -17 to pull them up to the middle.
145+
// By rotating counter-clockwise around the point at the center of the left
146+
// edge of a 24x24 layout box centered below the midline, we align the center
147+
// of the glyphs with the horizontal midline, so the yOffset is no longer
148+
// necessary, but we also pull the glyph to the left along the x axis
149+
const Point<float> center{-halfAdvance, halfAdvance};
150+
const float verticalRotation = -M_PI_2;
151+
const Point<float> xOffsetCorrection{5, 0};
152+
153+
tl = util::rotate(tl - center, verticalRotation) + center + xOffsetCorrection;
154+
tr = util::rotate(tr - center, verticalRotation) + center + xOffsetCorrection;
155+
bl = util::rotate(bl - center, verticalRotation) + center + xOffsetCorrection;
156+
br = util::rotate(br - center, verticalRotation) + center + xOffsetCorrection;
148157
}
149158

150159
if (textRotate) {

src/mbgl/text/shaping.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ void shapeLines(Shaping& shaping,
237237
const Glyph& glyph = **it->second;
238238

239239
if (writingMode == WritingModeType::Horizontal || !util::i18n::hasUprightVerticalOrientation(chr)) {
240-
shaping.positionedGlyphs.emplace_back(chr, x, y, 0);
240+
shaping.positionedGlyphs.emplace_back(chr, x, y, false);
241241
x += glyph.metrics.advance + spacing;
242242
} else {
243-
shaping.positionedGlyphs.emplace_back(chr, x, 0, -M_PI_2);
243+
shaping.positionedGlyphs.emplace_back(chr, x, 0, true);
244244
x += verticalHeight + spacing;
245245
}
246246
}

test/text/quads.test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST(getIconQuads, style) {
5050
shapedText.bottom = 30.0f;
5151
shapedText.left = -60.0f;
5252
shapedText.right = 20.0f;
53-
shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f, 0));
53+
shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f, false));
5454

5555
// none
5656
{

0 commit comments

Comments
 (0)