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

Commit

Permalink
[core] fix text-offset bug
Browse files Browse the repository at this point in the history
fixes #3469
kelvinabrokwa authored and ansis committed Jan 8, 2016
1 parent c8a39e1 commit 52844d4
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
],
"devDependencies": {
"aws-sdk": "^2.2.21",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#c2044f24883579041c3a076ecc654bb8eb49a681",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#4cee4c1369d013d59fe8b453ae3305f9eb057edf",
"node-gyp": "^3.2.1",
"request": "^2.67.0",
"tape": "^4.2.2"
16 changes: 8 additions & 8 deletions src/mbgl/text/font_stack.cpp
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ const Shaping FontStack::getShaping(const std::u32string &string, const float ma
// the y offset *should* be part of the font metadata
const int32_t yOffset = -17;

float x = ::round(translate.x * 24); // one em
const float y = ::round(translate.y * 24) + yOffset; // one em
float x = 0;
const float y = yOffset;

// Loop through all characters of this label and shape.
for (uint32_t chr : string) {
@@ -42,16 +42,16 @@ const Shaping FontStack::getShaping(const std::u32string &string, const float ma
if (shaping.positionedGlyphs.empty())
return shaping;

lineWrap(shaping, lineHeight, maxWidth, horizontalAlign, verticalAlign, justify);
lineWrap(shaping, lineHeight, maxWidth, horizontalAlign, verticalAlign, justify, translate);

return shaping;
}

void align(Shaping &shaping, const float justify, const float horizontalAlign,
const float verticalAlign, const uint32_t maxLineLength, const float lineHeight,
const uint32_t line) {
const float shiftX = (justify - horizontalAlign) * maxLineLength;
const float shiftY = (-verticalAlign * (line + 1) + 0.5) * lineHeight;
const uint32_t line, const vec2<float> &translate) {
const float shiftX = (justify - horizontalAlign) * maxLineLength + ::round(translate.x * 24/* one em */);
const float shiftY = (-verticalAlign * (line + 1) + 0.5) * lineHeight + ::round(translate.y * 24/* one em */);

for (auto& glyph : shaping.positionedGlyphs) {
glyph.x += shiftX;
@@ -75,7 +75,7 @@ void justifyLine(std::vector<PositionedGlyph> &positionedGlyphs, const std::map<

void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float maxWidth,
const float horizontalAlign, const float verticalAlign,
const float justify) const {
const float justify, const vec2<float> &translate) const {
uint32_t lastSafeBreak = 0;

uint32_t lengthBeforeCurrentLine = 0;
@@ -146,7 +146,7 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m
const uint32_t height = (line + 1) * lineHeight;

justifyLine(positionedGlyphs, metrics, lineStartIndex, uint32_t(positionedGlyphs.size()) - 1, justify);
align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, line);
align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, line, translate);

// Calculate the bounding box
shaping.top += -verticalAlign * height;
2 changes: 1 addition & 1 deletion src/mbgl/text/font_stack.hpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ class FontStack {
float horizontalAlign, float verticalAlign, float justify,
float spacing, const vec2<float> &translate) const;
void lineWrap(Shaping &shaping, float lineHeight, float maxWidth, float horizontalAlign,
float verticalAlign, float justify) const;
float verticalAlign, float justify, const vec2<float> &translate) const;

private:
std::map<uint32_t, std::string> bitmaps;

0 comments on commit 52844d4

Please sign in to comment.