@@ -9292,14 +9292,21 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
92929292 finalSize.ISize (wm) =
92939293 NSToCoordCeilClamped (std::max(gfxFloat(0.0 ), textMetrics.mAdvanceWidth));
92949294
9295+ nscoord fontBaseline;
9296+ // Note(dshin): Baseline should tecnhically be halfway through the em box for
9297+ // a central baseline. It is simply half of the text run block size so that it
9298+ // can be easily calculated in `GetNaturalBaselineBOffset`.
92959299 if (transformedCharsFit == 0 && !usedHyphenation) {
92969300 aMetrics.SetBlockStartAscent (0 );
92979301 finalSize.BSize (wm) = 0 ;
9302+ fontBaseline = 0 ;
92989303 } else if (boundingBoxType != gfxFont::LOOSE_INK_EXTENTS) {
9304+ fontBaseline = NSToCoordCeil(textMetrics.mAscent );
9305+ const auto size = fontBaseline + NSToCoordCeil(textMetrics.mDescent );
92999306 // Use actual text metrics for floating first letter frame.
9300- aMetrics.SetBlockStartAscent (NSToCoordCeil(textMetrics. mAscent ));
9301- finalSize. BSize (wm) =
9302- aMetrics. BlockStartAscent () + NSToCoordCeil(textMetrics. mDescent ) ;
9307+ aMetrics.SetBlockStartAscent (wm. IsAlphabeticalBaseline () ? fontBaseline
9308+ : size / 2 );
9309+ finalSize. BSize (wm) = size ;
93039310 } else {
93049311 // Otherwise, ascent should contain the overline drawable area.
93059312 // And also descent should contain the underline drawable area.
@@ -9309,16 +9316,18 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
93099316 wm.IsLineInverted () ? fm->MaxDescent () : fm->MaxAscent ();
93109317 nscoord fontDescent =
93119318 wm.IsLineInverted () ? fm->MaxAscent () : fm->MaxDescent ();
9312- aMetrics. SetBlockStartAscent (
9313- std::max (NSToCoordCeil(textMetrics. mAscent ), fontAscent));
9314- nscoord descent =
9319+ fontBaseline = std::max (NSToCoordCeil(textMetrics. mAscent ), fontAscent);
9320+ const auto size =
9321+ fontBaseline +
93159322 std::max (NSToCoordCeil(textMetrics.mDescent ), fontDescent);
9316- finalSize.BSize (wm) = aMetrics.BlockStartAscent () + descent;
9323+ aMetrics.SetBlockStartAscent (wm.IsAlphabeticalBaseline () ? fontBaseline
9324+ : size / 2 );
9325+ finalSize.BSize (wm) = size;
93179326 }
93189327 if (Style ()->IsTextCombined ()) {
93199328 nsFontMetrics* fm = provider.GetFontMetrics ();
9320- gfxFloat width = finalSize.ISize (wm);
9321- gfxFloat em = fm->EmHeight ();
9329+ nscoord width = finalSize.ISize (wm);
9330+ nscoord em = fm->EmHeight ();
93229331 // Compress the characters in horizontal axis if necessary.
93239332 if (width <= em) {
93249333 RemoveProperty (TextCombineScaleFactorProperty ());
@@ -9328,8 +9337,9 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
93289337 }
93299338 // Make the characters be in an 1em square.
93309339 if (finalSize.BSize (wm) != em) {
9331- aMetrics.SetBlockStartAscent (aMetrics.BlockStartAscent () +
9332- (em - finalSize.BSize (wm)) / 2 );
9340+ fontBaseline =
9341+ aMetrics.BlockStartAscent () + (em - finalSize.BSize (wm)) / 2 ;
9342+ aMetrics.SetBlockStartAscent (fontBaseline);
93339343 finalSize.BSize (wm) = em;
93349344 }
93359345 }
@@ -9343,7 +9353,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
93439353 0,
93449354 "Negative descent???");
93459355
9346- mAscent = aMetrics. BlockStartAscent () ;
9356+ mAscent = fontBaseline ;
93479357
93489358 // Handle text that runs outside its normal bounds.
93499359 nsRect boundingBox = RoundOut (textMetrics.mBoundingBox );
@@ -10021,6 +10031,10 @@ Maybe<nscoord> nsTextFrame::GetNaturalBaselineBOffset(
1002110031 }
1002210032
1002310033 if (!aWM.IsOrthogonalTo (GetWritingMode ())) {
10034+ if (aWM.IsCentralBaseline ()) {
10035+ return Some (GetLogicalUsedBorderAndPadding (aWM).BStart (aWM) +
10036+ ContentSize (aWM).BSize (aWM) / 2 );
10037+ }
1002410038 return Some (mAscent );
1002510039 }
1002610040
0 commit comments