Skip to content

Commit

Permalink
Skip line caps for closed paths
Browse files Browse the repository at this point in the history
As discussed in the github issue,
whatwg/html#1079, it's generally agreed to
skip drawing line caps for closed paths. This is a follow up cl of:
https://chromium-review.googlesource.com/c/chromium/src/+/4864061
It fixes the extra line caps issue for closed path with other paths.

Bug: 644067

Change-Id: I14c5c4819a31eb9249d01574ff1b5c60826c3b9e
  • Loading branch information
Yi Xu authored and chromium-wpt-export-bot committed Jan 8, 2024
1 parent 32017da commit c6abdb1
Show file tree
Hide file tree
Showing 21 changed files with 851 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.path.stroke.prune.closePath.arc</title>
<h1>2d.path.stroke.prune.closePath.arc</h1>
<p class="desc">Test if zero-lengthed closePath before and after arc are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(75, 20, 0, Math.PI);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.path.stroke.prune.closePath.arc-expected.html">
<title>Canvas test: 2d.path.stroke.prune.closePath.arc</title>
<h1>2d.path.stroke.prune.closePath.arc</h1>
<p class="desc">Test if zero-lengthed closePath before and after arc are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(50, 25);
ctx.lineTo(50, 25);
ctx.closePath();

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(75, 20, 0, Math.PI);
ctx.closePath();

ctx.moveTo(50, 50);
ctx.lineTo(50, 50);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.path.stroke.prune.closePath.bezierCurve</title>
<h1>2d.path.stroke.prune.closePath.bezierCurve</h1>
<p class="desc">Test if zero-lengthed closePath before and after bezier curve are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.moveTo(10, 10);
ctx.bezierCurveTo(10, 30, 40, 50, 100, 50);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.path.stroke.prune.closePath.bezierCurve-expected.html">
<title>Canvas test: 2d.path.stroke.prune.closePath.bezierCurve</title>
<h1>2d.path.stroke.prune.closePath.bezierCurve</h1>
<p class="desc">Test if zero-lengthed closePath before and after bezier curve are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(50, 25);
ctx.lineTo(50, 25);
ctx.closePath();

ctx.moveTo(10, 10);
ctx.bezierCurveTo(10, 30, 40, 50, 100, 50);
ctx.closePath();

ctx.moveTo(20, 50);
ctx.lineTo(20, 50);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.path.stroke.prune.closePath.line</title>
<h1>2d.path.stroke.prune.closePath.line</h1>
<p class="desc">Test if zero-lengthed closePath before and after line are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.moveTo(10, 10);
ctx.lineTo(40, 40);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.path.stroke.prune.closePath.line-expected.html">
<title>Canvas test: 2d.path.stroke.prune.closePath.line</title>
<h1>2d.path.stroke.prune.closePath.line</h1>
<p class="desc">Test if zero-lengthed closePath before and after line are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(50, 25);
ctx.lineTo(50, 25);
ctx.closePath();

ctx.moveTo(10, 10);
ctx.lineTo(40, 40);
ctx.closePath();

ctx.moveTo(50, 50);
ctx.lineTo(50, 50);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve</title>
<h1>2d.path.stroke.prune.closePath.quadraticCurve</h1>
<p class="desc">Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(80, 10, 100, 50);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.path.stroke.prune.closePath.quadraticCurve-expected.html">
<title>Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve</title>
<h1>2d.path.stroke.prune.closePath.quadraticCurve</h1>
<p class="desc">Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(50, 25);
ctx.lineTo(50, 25);
ctx.closePath();

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(80, 10, 100, 50);
ctx.closePath();

ctx.moveTo(50, 50);
ctx.lineTo(50, 50);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.path.stroke.prune.closePath.arc</title>
<h1>2d.path.stroke.prune.closePath.arc</h1>
<p class="desc">Test if zero-lengthed closePath before and after arc are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(75, 20, 0, Math.PI);
ctx.closePath();
ctx.stroke();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<link rel="match" href="2d.path.stroke.prune.closePath.arc-expected.html">
<title>Canvas test: 2d.path.stroke.prune.closePath.arc</title>
<h1>2d.path.stroke.prune.closePath.arc</h1>
<p class="desc">Test if zero-lengthed closePath before and after arc are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = new OffscreenCanvas(100, 50);
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(50, 25);
ctx.lineTo(50, 25);
ctx.closePath();

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(75, 20, 0, Math.PI);
ctx.closePath();

ctx.moveTo(50, 50);
ctx.lineTo(50, 50);
ctx.closePath();
ctx.stroke();

const outputCanvas = document.getElementById("canvas");
outputCanvas.getContext('2d').drawImage(canvas, 0, 0);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<html class="reftest-wait">
<link rel="match" href="2d.path.stroke.prune.closePath.arc-expected.html">
<title>Canvas test: 2d.path.stroke.prune.closePath.arc</title>
<h1>2d.path.stroke.prune.closePath.arc</h1>
<p class="desc">Test if zero-lengthed closePath before and after arc are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script id='myWorker' type='text/worker'>
self.onmessage = function(e) {
const canvas = new OffscreenCanvas(100, 50);
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(50, 25);
ctx.lineTo(50, 25);
ctx.closePath();

ctx.moveTo(10, 10);
ctx.quadraticCurveTo(75, 20, 0, Math.PI);
ctx.closePath();

ctx.moveTo(50, 50);
ctx.lineTo(50, 50);
ctx.closePath();
ctx.stroke();

const bitmap = canvas.transferToImageBitmap();
self.postMessage(bitmap, bitmap);
};
</script>
<script>
const blob = new Blob([document.getElementById('myWorker').textContent]);
const worker = new Worker(URL.createObjectURL(blob));
worker.addEventListener('message', msg => {
const outputCtx = document.getElementById("canvas").getContext('2d');
outputCtx.drawImage(msg.data, 0, 0);
document.documentElement.classList.remove("reftest-wait");
});
worker.postMessage(null);
</script>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.path.stroke.prune.closePath.bezierCurve</title>
<h1>2d.path.stroke.prune.closePath.bezierCurve</h1>
<p class="desc">Test if zero-lengthed closePath before and after bezier curve are ignored corrected.</p>
<canvas id="canvas" width="100" height="50">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);

ctx.strokeStyle = '#f00';
ctx.lineWidth = 10;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

ctx.moveTo(10, 10);
ctx.bezierCurveTo(10, 30, 40, 50, 100, 50);
ctx.closePath();
ctx.stroke();
</script>
Loading

0 comments on commit c6abdb1

Please sign in to comment.