commit f0290e617fba4d07670494febc4db4349196e5b5
parent f4ed96250592feb6e435f09305a3f067c6442d61
Author: Jonathan Kew <jkew@mozilla.com>
Date: Wed, 15 Oct 2025 21:11:23 +0000
Bug 1994197 - patch 1 - Use integer nscoord values rather than gfxFloat for gfxFont::Spacing fields. r=layout-reviewers,TYLin
Differential Revision: https://phabricator.services.mozilla.com/D268559
Diffstat:
3 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h
@@ -1652,13 +1652,11 @@ class gfxFont {
* We let layout specify spacing on either side of any
* character. We need to specify both before and after
* spacing so that substring measurement can do the right things.
- * These values are in appunits. They're always an integral number of
- * appunits, but we specify them in floats in case very large spacing
- * values are required.
+ * These values are in appunits.
*/
struct Spacing {
- gfxFloat mBefore;
- gfxFloat mAfter;
+ nscoord mBefore;
+ nscoord mAfter;
};
/**
* Metrics for a particular string
diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp
@@ -3879,8 +3879,8 @@ static gfxFloat ComputeTabWidthAppUnits(const nsIFrame* aFrame) {
RefPtr font = fm->GetThebesFontGroup()->GetFirstValidFont(' ');
auto metrics = font->GetMetrics(vertical ? nsFontMetrics::eVertical
: nsFontMetrics::eHorizontal);
- nscoord spaceWidth = nscoord(
- NS_round(metrics.spaceWidth * cb->PresContext()->AppUnitsPerDevPixel()));
+ nscoord spaceWidth = NSToCoordRound(metrics.spaceWidth *
+ cb->PresContext()->AppUnitsPerDevPixel());
return spaces *
(spaceWidth + styleText->mLetterSpacing.Resolve(fm->EmHeight()) +
styleText->mWordSpacing.Resolve(spaceWidth));
@@ -4091,24 +4091,24 @@ bool nsTextFrame::PropertyProvider::GetSpacingInternal(Range aRange,
// 0 - Gecko legacy model, spacing added to trailing side of letter
// 1 - WebKit/Blink-compatible, spacing added to right-hand side
// 2 - Symmetrical spacing, half added to each side
- gfxFloat before, after;
+ nscoord before, after;
switch (StaticPrefs::layout_css_letter_spacing_model()) {
default: // use Gecko legacy behavior if pref value is unknown
case 0:
- before = 0.0;
+ before = 0;
after = mLetterSpacing;
break;
case 1:
if (mTextRun->IsRightToLeft()) {
before = mLetterSpacing;
- after = 0.0;
+ after = 0;
} else {
- before = 0.0;
+ before = 0;
after = mLetterSpacing;
}
break;
case 2:
- before = mLetterSpacing / 2.0;
+ before = NSToCoordRound(mLetterSpacing * 0.5);
after = mLetterSpacing - before;
break;
}
@@ -4170,12 +4170,12 @@ bool nsTextFrame::PropertyProvider::GetSpacingInternal(Range aRange,
uint32_t runOffsetInSubstring = run.GetSkippedOffset() - aRange.start;
gfxSkipCharsIterator iter = run.GetPos();
for (int32_t i = 0; i < run.GetRunLength(); ++i) {
- if (!atStart && before != 0.0 &&
+ if (!atStart && before != 0 &&
CanAddSpacingBefore(mTextRun, run.GetSkippedOffset() + i,
newlineIsSignificant)) {
aSpacing[runOffsetInSubstring + i].mBefore += before;
}
- if (after != 0.0 &&
+ if (after != 0 &&
CanAddSpacingAfter(mTextRun, run.GetSkippedOffset() + i,
newlineIsSignificant)) {
// End of a cluster, not in a ligature: put letter-spacing after it
diff --git a/layout/generic/nsTextFrame.h b/layout/generic/nsTextFrame.h
@@ -259,10 +259,10 @@ class nsTextFrame : public nsIFrame {
int32_t mLength;
// space for each whitespace char
- const gfxFloat mWordSpacing;
+ const nscoord mWordSpacing;
// space for each letter
- const gfxFloat mLetterSpacing;
+ const nscoord mLetterSpacing;
// If TextAutospace exists, inter-script spacing applies.
Maybe<mozilla::TextAutospace> mTextAutospace;