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

Clamp argument to SVGGeometryElement.getPointAtLength to [0, length]

Per:

  https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength

Bug: 847198
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I9067ce9f196453bd54560d5119ebc38d35c8ac86
Reviewed-on: https://chromium-review.googlesource.com/1075332Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#562422}
parent 5474d2f4
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:html="http://www.w3.org/1999/xhtml">
<title>SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length]</title>
<metadata>
<html:link rel="help" href="https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength"/>
<html:meta name="assert" content="SVGGeometryElement.prototype.getPointAtLength clamps its argument."/>
</metadata>
<g stroke="blue">
<line id="line" x1="50" y1="60" x2="100" y2="60"/>
<path id="path" d="M40,70L110,70"/>
</g>
<html:script src="/resources/testharness.js"/>
<html:script src="/resources/testharnessreport.js"/>
<script><![CDATA[
test(function() {
let line = document.getElementById('line');
let point = line.getPointAtLength(-10);
assert_equals(point.x, 50, 'starting x');
assert_equals(point.y, 60, 'starting y');
}, document.title+', less than zero (SVGLineElement).');
test(function() {
let path = document.getElementById('path');
let point = path.getPointAtLength(-10);
assert_equals(point.x, 40, 'starting x');
assert_equals(point.y, 70, 'starting y');
}, document.title+', less than zero (SVGPathElement).');
test(function() {
let line = document.getElementById('line');
assert_less_than(line.getTotalLength(), 80);
let point = line.getPointAtLength(80);
assert_equals(point.x, 100, 'ending x');
assert_equals(point.y, 60, 'ending y');
}, document.title+', greater than \'length\' (SVGLineElement).');
test(function() {
let path = document.getElementById('path');
assert_less_than(path.getTotalLength(), 80);
let point = path.getPointAtLength(80);
assert_equals(point.x, 110, 'ending x');
assert_equals(point.y, 70, 'ending y');
}, document.title+', greater than \'length\' (SVGPathElement).');
]]></script>
</svg>
......@@ -141,8 +141,17 @@ SVGPointTearOff* SVGGeometryElement::getPointAtLength(float length) {
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
FloatPoint point;
if (GetLayoutObject())
point = AsPath().PointAtLength(length);
if (GetLayoutObject()) {
const Path& path = AsPath();
if (length < 0) {
length = 0;
} else {
float computed_length = path.length();
if (length > computed_length)
length = computed_length;
}
point = path.PointAtLength(length);
}
return SVGPointTearOff::CreateDetached(point);
}
......
......@@ -70,7 +70,15 @@ float SVGPathElement::getTotalLength() {
SVGPointTearOff* SVGPathElement::getPointAtLength(float length) {
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
FloatPoint point = SVGPathQuery(PathByteStream()).GetPointAtLength(length);
SVGPathQuery path_query(PathByteStream());
if (length < 0) {
length = 0;
} else {
float computed_length = path_query.GetTotalLength();
if (length > computed_length)
length = computed_length;
}
FloatPoint point = path_query.GetPointAtLength(length);
return SVGPointTearOff::CreateDetached(point);
}
......
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