Skip to content

Commit

Permalink
Skip line caps for closed ellipse 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. Add test cases for full
ellipse path.

Bug: 644067

Change-Id: I3fde274f4b15a96d4ecaa593b0317c585eeb4a25
  • Loading branch information
Yi Xu authored and chromium-wpt-export-bot committed Oct 6, 2023
1 parent 0a366a4 commit 111153a
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
38 changes: 38 additions & 0 deletions html/canvas/element/path-objects/2d.path.stroke.prune.ellipse.html
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. -->
<title>Canvas test: 2d.path.stroke.prune.ellipse</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<h1>2d.path.stroke.prune.ellipse</h1>
<p class="desc">Zero-length full ellipse are removed before stroking with miters</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<p class="output expectedtext">Expected output:<p><img src="/images/green-100x50.png" class="output expected" id="expected" alt="">
<ul id="d"></ul>
<script>
var t = async_test("Zero-length full ellipse are removed before stroking with miters");
_addTest(function(canvas, ctx) {

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

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

ctx.beginPath();
ctx.ellipse(25, 25, 0, 0, 0, 0, 2 * Math.PI);
ctx.stroke();

_assertPixel(canvas, 50,25, 0,255,0,255);

});
</script>

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>OffscreenCanvas test: 2d.path.stroke.prune.ellipse</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>

<h1>2d.path.stroke.prune.ellipse</h1>
<p class="desc">Zero-length full ellipse are removed before stroking with miters</p>


<script>
var t = async_test("Zero-length full ellipse are removed before stroking with miters");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var canvas = new OffscreenCanvas(100, 50);
var ctx = canvas.getContext('2d');

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

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

ctx.beginPath();
ctx.ellipse(25, 25, 0, 0, 0, 0, 2 * Math.PI);
ctx.stroke();

_assertPixel(canvas, 50,25, 0,255,0,255);
t.done();

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
// OffscreenCanvas test in a worker:2d.path.stroke.prune.ellipse
// Description:Zero-length full ellipse are removed before stroking with miters
// Note:

importScripts("/resources/testharness.js");
importScripts("/html/canvas/resources/canvas-tests.js");

var t = async_test("Zero-length full ellipse are removed before stroking with miters");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {

var canvas = new OffscreenCanvas(100, 50);
var ctx = canvas.getContext('2d');

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

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

ctx.beginPath();
ctx.ellipse(25, 25, 0, 0, 0, 0, 2 * Math.PI);
ctx.stroke();

_assertPixel(canvas, 50,25, 0,255,0,255);
t.done();
});
done();
17 changes: 17 additions & 0 deletions html/canvas/tools/yaml-new/path-objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,23 @@
@assert pixel 50,25 == 0,255,0,255;
expected: green

- name: 2d.path.stroke.prune.ellipse
desc: Zero-length full ellipse are removed before stroking with miters
code: |
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.strokeStyle = '#f00';
ctx.lineWidth = 100;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.beginPath();
ctx.ellipse(25, 25, 0, 0, 0, 0, 2 * Math.PI);
ctx.stroke();
@assert pixel 50,25 == 0,255,0,255;
expected: green

- name: 2d.path.transformation.basic
code: |
Expand Down

0 comments on commit 111153a

Please sign in to comment.