Bug 1371196 - Round font-weight when interpolating, don't floor; r?hiro
The spec says,
font weight: interpolated via discrete steps (multiples of 100). The
interpolation happens in real number space and is converted to an integer by
rounding to the nearest multiple of 100, with values halfway between
multiples of 100 rounded towards positive infinity.[1]
However, our implementation pre-dates this spec text (
bug 528234 landed Nov 2009
whereas the spec was updated in Mar 2012[2]).
This patch rounds the result by simply adding 50 to the result before we floor
it (which is good enough in this case because we don't need to worry about
negative values).
It also slightly simplifies the logic by re-using Clamp from MathAlgorithms.h.
[1] https://drafts.csswg.org/css-transitions/#animtype-font-weight
[2] https://github.com/w3c/csswg-drafts/commit/00c62861095c9c3b911f3af0747790440a8e6467
MozReview-Commit-ID: BjCg7MG70hW
--- a/dom/smil/test/db_smilCSSFromTo.js
+++ b/dom/smil/test/db_smilCSSFromTo.js
@@ -326,17 +326,17 @@ var gFromToBundles = [
new AnimTestcaseFromTo("small-caps", "normal"),
]),
new TestcaseBundle(gPropList.font_weight, [
new AnimTestcaseFromTo("100", "900", { midComp: "500" }),
new AnimTestcaseFromTo("700", "100", { midComp: "400" }),
new AnimTestcaseFromTo("inherit", "200",
{ fromComp: "400", midComp: "300" }),
new AnimTestcaseFromTo("normal", "bold",
- { fromComp: "400", midComp: "500", toComp: "700" }),
+ { fromComp: "400", midComp: "600", toComp: "700" }),
new AnimTestcaseFromTo("lighter", "bolder", {},
"need support for animating between " +
"relative 'font-weight' values"),
]),
// NOTE: Mozilla doesn't currently support "glyph-orientation-horizontal" or
// "glyph-orientation-vertical", but I'm testing them here in case we ever
// add support for them, because they're explicitly not animatable in the SVG
// spec.
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -2920,22 +2920,20 @@ StyleAnimationValue::AddWeighted(nsCSSPr
return true;
}
case eUnit_Integer: {
// https://drafts.csswg.org/css-transitions/#animtype-integer
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;
- } else if (result > 900) {
- result = 900;
- }
+ // https://drafts.csswg.org/css-transitions/#animtype-font-weight
+ result += 50;
result -= result % 100;
+ result = Clamp(result, 100, 900);
} else {
result = RestrictValue(aProperty, result);
}
aResultValue.SetIntValue(result, eUnit_Integer);
return true;
}
case eUnit_Coord: {
aResultValue.SetCoordValue(RestrictValue(aProperty, NSToCoordRound(