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

Commit

Permalink
[core] Keep yOffset in case ascender is not available, preventing bre…
Browse files Browse the repository at this point in the history
…aking existed render tests
  • Loading branch information
zmiao committed Sep 20, 2019
1 parent c14f327 commit 21e65d7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/mbgl/text/shaping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ void shapeLines(Shaping& shaping,
float y = 0;
float maxLineLength = 0;


const float justify = textJustify == style::TextJustifyType::Right ? 1 :
textJustify == style::TextJustifyType::Left ? 0 :
0.5;
Expand Down Expand Up @@ -365,15 +364,17 @@ void shapeLines(Shaping& shaping,
// from the horizontal baseline to the highest ‘character’ coordinate in a font face.
// Since we're laying out at 24 points, we need also calculate how much it will move
// when we scale up or down.
const double baselineOffset =
-glyph.metrics.ascender * section.scale + (lineMaxScale - section.scale) * util::ONE_EM;
const bool hasBaseline = glyph.metrics.ascender != 0 && glyph.metrics.descender != 0;
const double baselineOffset = (hasBaseline ? (-glyph.metrics.ascender * section.scale) : shaping.yOffset) +
(lineMaxScale - section.scale) * util::ONE_EM;

if (writingMode == WritingModeType::Horizontal ||
// Don't verticalize glyphs that have no upright orientation if vertical placement is disabled.
(!allowVerticalPlacement && !util::i18n::hasUprightVerticalOrientation(codePoint)) ||
// If vertical placement is ebabled, don't verticalize glyphs that
// are from complex text layout script, or whitespaces.
(allowVerticalPlacement && (util::i18n::isWhitespace(codePoint) || util::i18n::isCharInComplexShapingScript(codePoint)))) {
(allowVerticalPlacement &&
(util::i18n::isWhitespace(codePoint) || util::i18n::isCharInComplexShapingScript(codePoint)))) {
shaping.positionedGlyphs.emplace_back(
codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale, sectionIndex);
x += glyph.metrics.advance * section.scale + spacing;
Expand All @@ -400,7 +401,7 @@ void shapeLines(Shaping& shaping,

align(shaping, justify, anchorAlign.horizontalAlign, anchorAlign.verticalAlign, maxLineLength,
lineHeight, lines.size());
const float height = y - Shaping::yOffset;
const float height = y;
// Calculate the bounding box
shaping.top += -anchorAlign.verticalAlign * height;
shaping.bottom = shaping.top + height;
Expand Down

0 comments on commit 21e65d7

Please sign in to comment.