@@ -326,8 +326,7 @@ void shapeLines(Shaping& shaping,
326326 const GlyphMap& glyphMap,
327327 bool allowVerticalPlacement) {
328328 float x = 0 ;
329- float y = Shaping::yOffset;
330-
329+ float y = 0 ;
331330 float maxLineLength = 0 ;
332331
333332
@@ -359,21 +358,25 @@ void shapeLines(Shaping& shaping,
359358 if (it == glyphs->second .end () || !it->second ) {
360359 continue ;
361360 }
362-
363- // We don't know the baseline, but since we're laying out
364- // at 24 points, we can calculate how much it will move when
365- // we scale up or down.
366- const double baselineOffset = (lineMaxScale - section.scale ) * util::ONE_EM ;
367-
361+
368362 const Glyph& glyph = **it->second ;
369363
364+ // Each glyph's baseline is starting from its acsender, which is the vertical distance
365+ // from the horizontal baseline to the highest ‘character’ coordinate in a font face.
366+ // Since we're laying out at 24 points, we need also calculate how much it will move
367+ // when we scale up or down.
368+ const double baselineOffset = -glyph.metrics .ascender * section.scale +
369+ (lineMaxScale - section.scale ) * util::ONE_EM ;
370+
370371 if (writingMode == WritingModeType::Horizontal ||
371372 // Don't verticalize glyphs that have no upright orientation if vertical placement is disabled.
372373 (!allowVerticalPlacement && !util::i18n::hasUprightVerticalOrientation (codePoint)) ||
373374 // If vertical placement is ebabled, don't verticalize glyphs that
374375 // are from complex text layout script, or whitespaces.
375376 (allowVerticalPlacement && (util::i18n::isWhitespace (codePoint) || util::i18n::isCharInComplexShapingScript (codePoint)))) {
376- shaping.positionedGlyphs .emplace_back (codePoint, x, y + baselineOffset, false , section.fontStackHash , section.scale , sectionIndex);
377+ shaping.positionedGlyphs .emplace_back (codePoint, x, y + baselineOffset, false ,
378+ section.fontStackHash , section.scale ,
379+ sectionIndex);
377380 x += glyph.metrics .advance * section.scale + spacing;
378381 } else {
379382 shaping.positionedGlyphs .emplace_back (codePoint, x, y + baselineOffset, true , section.fontStackHash , section.scale , sectionIndex);
@@ -399,7 +402,6 @@ void shapeLines(Shaping& shaping,
399402 align (shaping, justify, anchorAlign.horizontalAlign , anchorAlign.verticalAlign , maxLineLength,
400403 lineHeight, lines.size ());
401404 const float height = y - Shaping::yOffset;
402-
403405 // Calculate the bounding box
404406 shaping.top += -anchorAlign.verticalAlign * height;
405407 shaping.bottom = shaping.top + height;
0 commit comments