From 1cdd0bda498a5bcd44ea0b5a32977b3a591d5d8f Mon Sep 17 00:00:00 2001 From: zmiao Date: Fri, 20 Sep 2019 11:17:20 +0300 Subject: [PATCH] [core] Keep yOffset in case ascender is not available, preventing breaking existed render tests --- src/mbgl/text/shaping.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 81639adefd4..d1f70e51735 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;