diff options
author | zmiao <zmiao.jamie@gmail.com> | 2019-09-20 11:17:20 +0300 |
---|---|---|
committer | zmiao <miao.zhao@mapbox.com> | 2019-10-06 19:48:08 +0300 |
commit | 54c310f95dec0ed2d972a62a65ef283fce7683a1 (patch) | |
tree | 8afedd4174c5d98b3d11fc2375ceb85ed880eb6c | |
parent | f669a7d26bcd90959204a4d990d52aaccacad917 (diff) | |
download | qtlocation-mapboxgl-54c310f95dec0ed2d972a62a65ef283fce7683a1.tar.gz |
[core] Keep yOffset in case ascender is not available, preventing breaking existed render tests
-rw-r--r-- | src/mbgl/text/shaping.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 81639adefd..d1f70e5173 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -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; @@ -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; @@ -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; |