@@ -9292,14 +9292,21 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
9292
9292
finalSize.ISize(wm) =
9293
9293
NSToCoordCeilClamped(std::max(gfxFloat(0.0), textMetrics.mAdvanceWidth));
9294
9294
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`.
9295
9299
if (transformedCharsFit == 0 && !usedHyphenation) {
9296
9300
aMetrics.SetBlockStartAscent(0);
9297
9301
finalSize.BSize(wm) = 0;
9302
+ fontBaseline = 0;
9298
9303
} else if (boundingBoxType != gfxFont::LOOSE_INK_EXTENTS) {
9304
+ fontBaseline = NSToCoordCeil(textMetrics.mAscent);
9305
+ const auto size = fontBaseline + NSToCoordCeil(textMetrics.mDescent);
9299
9306
// 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 ;
9303
9310
} else {
9304
9311
// Otherwise, ascent should contain the overline drawable area.
9305
9312
// And also descent should contain the underline drawable area.
@@ -9309,16 +9316,18 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
9309
9316
wm.IsLineInverted() ? fm->MaxDescent() : fm->MaxAscent();
9310
9317
nscoord fontDescent =
9311
9318
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 +
9315
9322
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;
9317
9326
}
9318
9327
if (Style()->IsTextCombined()) {
9319
9328
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();
9322
9331
// Compress the characters in horizontal axis if necessary.
9323
9332
if (width <= em) {
9324
9333
RemoveProperty(TextCombineScaleFactorProperty());
@@ -9328,8 +9337,9 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
9328
9337
}
9329
9338
// Make the characters be in an 1em square.
9330
9339
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);
9333
9343
finalSize.BSize(wm) = em;
9334
9344
}
9335
9345
}
@@ -9343,7 +9353,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
9343
9353
0,
9344
9354
"Negative descent???");
9345
9355
9346
- mAscent = aMetrics.BlockStartAscent() ;
9356
+ mAscent = fontBaseline ;
9347
9357
9348
9358
// Handle text that runs outside its normal bounds.
9349
9359
nsRect boundingBox = RoundOut(textMetrics.mBoundingBox);
@@ -10021,6 +10031,10 @@ Maybe<nscoord> nsTextFrame::GetNaturalBaselineBOffset(
10021
10031
}
10022
10032
10023
10033
if (!aWM.IsOrthogonalTo(GetWritingMode())) {
10034
+ if (aWM.IsCentralBaseline()) {
10035
+ return Some(GetLogicalUsedBorderAndPadding(aWM).BStart(aWM) +
10036
+ ContentSize(aWM).BSize(aWM) / 2);
10037
+ }
10024
10038
return Some(mAscent);
10025
10039
}
10026
10040
0 commit comments