Issue #2751 - Use rounded interpolation value when interpolating the Integer type and Font stretch type, per spec.

Resolves #2751
This commit is contained in:
Moonchild 2025-06-13 11:40:49 +02:00 committed by roytam1
commit 321b75a391
2 changed files with 12 additions and 9 deletions

View file

@ -2675,8 +2675,10 @@ StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty,
switch (aProperty) {
case eCSSProperty_font_stretch: {
// Animate just like eUnit_Integer.
int32_t result = floor(aCoeff1 * double(aValue1.GetIntValue()) +
aCoeff2 * double(aValue2.GetIntValue()));
// https://drafts.csswg.org/css-fonts-3/#font-stretch-animation
double interpolatedValue = aCoeff1 * double(aValue1.GetIntValue()) +
aCoeff2 * double(aValue2.GetIntValue());
int32_t result = floor(interpolatedValue + 0.5); // Fast round.
if (result < NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED) {
result = NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED;
} else if (result > NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED) {
@ -2708,10 +2710,11 @@ StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty,
return true;
}
case eUnit_Integer: {
// http://dev.w3.org/csswg/css3-transitions/#animation-of-property-types-
// says we should use floor
int32_t result = floor(aCoeff1 * double(aValue1.GetIntValue()) +
aCoeff2 * double(aValue2.GetIntValue()));
// https://drafts.csswg.org/css-transitions/#animtype-integer
// Spec says animation of properties should use rounding.
double interpolatedValue = aCoeff1 * double(aValue1.GetIntValue()) +
aCoeff2 * double(aValue2.GetIntValue());
int32_t result = floor(interpolatedValue + 0.5);
if (aProperty == eCSSProperty_font_weight) {
if (result < 100) {
result = 100;