mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-04 07:40:42 +00:00
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] 00c6286109
MozReview-Commit-ID: BjCg7MG70hW
--HG--
extra : rebase_source : 879ea18d7d1a49ff425d6e467081983a130a65e3
This commit is contained in:
parent
e25479050a
commit
f7f386ac4e
@ -331,7 +331,7 @@ var gFromToBundles = [
|
||||
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"),
|
||||
|
@ -2925,12 +2925,10 @@ StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty,
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user