Commit 00c4d7d6 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

[PE] Fix edge-cases in SVGGeometryElement::PathLengthScaleFactor

Update the computation of the scale factor to match what the spec [1]
has to say about a value of zero: i.e yield (near) infinity rather than
zero. Also update the case where the computed path length is zero.

[1] https://svgwg.org/svg2-draft/paths.html#PathLengthAttribute

Bug: 803127
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I6816b6bdd47cbaee90e8ad22e16d1dcf44498c7d
Reviewed-on: https://chromium-review.googlesource.com/893184Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#533003}
parent 871421fc
......@@ -142,15 +142,25 @@ float SVGGeometryElement::PathLengthScaleFactor() const {
if (!pathLength()->IsSpecified())
return 1;
float author_path_length = pathLength()->CurrentValue()->Value();
// https://svgwg.org/svg2-draft/paths.html#PathLengthAttribute
// "A negative value is an error"
if (author_path_length < 0)
return 1;
if (!author_path_length)
return 0;
DCHECK(GetLayoutObject());
// If the computed path length is zero, then the scale factor will
// always be zero except if the author path length is also zero - in
// which case performing the division would yield a NaN. Avoid the
// division in this case and always return zero.
float computed_path_length = ComputePathLength();
if (!computed_path_length)
return 1;
return computed_path_length / author_path_length;
return 0;
// "A value of zero is valid and must be treated as a scaling factor
// of infinity. A value of zero scaled infinitely must remain zero,
// while any value greater than zero must become +Infinity."
// However, since 0 * Infinity is not zero (but rather NaN) per
// IEEE, we need to make sure to clamp the result below - avoiding
// the actual Infinity (and using max()) instead.
return clampTo<float>(computed_path_length / author_path_length);
}
LayoutObject* SVGGeometryElement::CreateLayoutObject(const ComputedStyle&) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment