From ea5911192aa59087f635be659882a368fc6a2d8c Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Mon, 8 Jan 2024 11:59:45 -0800 Subject: [PATCH] Remove empty closed paths As discussed in the github issue, https://github.com/whatwg/html/issues/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. In this cl, it verifies if each closed path is empty, then it removes the empty closed subpaths from path. As the subpaths are removed, the corresponding line caps are skipped. Bug: 644067 Change-Id: I14c5c4819a31eb9249d01574ff1b5c60826c3b9e --- ...h.stroke.prune.closePath.arc-expected.html | 25 +++ .../2d.path.stroke.prune.closePath.arc.html | 35 ++++ ....prune.closePath.bezierCurve-expected.html | 25 +++ ...th.stroke.prune.closePath.bezierCurve.html | 35 ++++ ....stroke.prune.closePath.line-expected.html | 25 +++ .../2d.path.stroke.prune.closePath.line.html | 35 ++++ ...une.closePath.quadraticCurve-expected.html | 25 +++ ...stroke.prune.closePath.quadraticCurve.html | 35 ++++ ...h.stroke.prune.closePath.arc-expected.html | 25 +++ .../2d.path.stroke.prune.closePath.arc.html | 38 +++++ .../2d.path.stroke.prune.closePath.arc.w.html | 52 ++++++ ....prune.closePath.bezierCurve-expected.html | 25 +++ ...th.stroke.prune.closePath.bezierCurve.html | 38 +++++ ....stroke.prune.closePath.bezierCurve.w.html | 52 ++++++ ....stroke.prune.closePath.line-expected.html | 25 +++ .../2d.path.stroke.prune.closePath.line.html | 38 +++++ ...2d.path.stroke.prune.closePath.line.w.html | 52 ++++++ ...une.closePath.quadraticCurve-expected.html | 25 +++ ...stroke.prune.closePath.quadraticCurve.html | 38 +++++ ...roke.prune.closePath.quadraticCurve.w.html | 52 ++++++ html/canvas/tools/yaml-new/path-objects.yaml | 151 ++++++++++++++++++ 21 files changed, 851 insertions(+) create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc-expected.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line-expected.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html create mode 100644 html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc-expected.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.w.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.w.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line-expected.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.w.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html create mode 100644 html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.w.html diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc-expected.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc-expected.html new file mode 100644 index 00000000000000..a78a280014edd4 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.arc +

2d.path.stroke.prune.closePath.arc

+

Test if zero-lengthed closePath before and after arc are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc.html new file mode 100644 index 00000000000000..71876a029c7783 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.arc.html @@ -0,0 +1,35 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.arc +

2d.path.stroke.prune.closePath.arc

+

Test if zero-lengthed closePath before and after arc are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html new file mode 100644 index 00000000000000..4b867f821fa70f --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.bezierCurve +

2d.path.stroke.prune.closePath.bezierCurve

+

Test if zero-lengthed closePath before and after bezier curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html new file mode 100644 index 00000000000000..e75aeb9529f053 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html @@ -0,0 +1,35 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.bezierCurve +

2d.path.stroke.prune.closePath.bezierCurve

+

Test if zero-lengthed closePath before and after bezier curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line-expected.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line-expected.html new file mode 100644 index 00000000000000..87a99c79380036 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.line +

2d.path.stroke.prune.closePath.line

+

Test if zero-lengthed closePath before and after line are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line.html new file mode 100644 index 00000000000000..5237c7ad199c53 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.line.html @@ -0,0 +1,35 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.line +

2d.path.stroke.prune.closePath.line

+

Test if zero-lengthed closePath before and after line are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html new file mode 100644 index 00000000000000..03635b01483857 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve +

2d.path.stroke.prune.closePath.quadraticCurve

+

Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html new file mode 100644 index 00000000000000..cd786944c50876 --- /dev/null +++ b/html/canvas/element/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html @@ -0,0 +1,35 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve +

2d.path.stroke.prune.closePath.quadraticCurve

+

Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc-expected.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc-expected.html new file mode 100644 index 00000000000000..a78a280014edd4 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.arc +

2d.path.stroke.prune.closePath.arc

+

Test if zero-lengthed closePath before and after arc are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.html new file mode 100644 index 00000000000000..f0e5ce2919c953 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.html @@ -0,0 +1,38 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.arc +

2d.path.stroke.prune.closePath.arc

+

Test if zero-lengthed closePath before and after arc are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.w.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.w.html new file mode 100644 index 00000000000000..86f13ec6b357ea --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.arc.w.html @@ -0,0 +1,52 @@ + + + + +Canvas test: 2d.path.stroke.prune.closePath.arc +

2d.path.stroke.prune.closePath.arc

+

Test if zero-lengthed closePath before and after arc are ignored corrected.

+ +

FAIL (fallback content)

+
+ + + diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html new file mode 100644 index 00000000000000..4b867f821fa70f --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.bezierCurve +

2d.path.stroke.prune.closePath.bezierCurve

+

Test if zero-lengthed closePath before and after bezier curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html new file mode 100644 index 00000000000000..1a42127db18887 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.html @@ -0,0 +1,38 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.bezierCurve +

2d.path.stroke.prune.closePath.bezierCurve

+

Test if zero-lengthed closePath before and after bezier curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.w.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.w.html new file mode 100644 index 00000000000000..8cf6726a92e8f5 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.bezierCurve.w.html @@ -0,0 +1,52 @@ + + + + +Canvas test: 2d.path.stroke.prune.closePath.bezierCurve +

2d.path.stroke.prune.closePath.bezierCurve

+

Test if zero-lengthed closePath before and after bezier curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ + + diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line-expected.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line-expected.html new file mode 100644 index 00000000000000..87a99c79380036 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.line +

2d.path.stroke.prune.closePath.line

+

Test if zero-lengthed closePath before and after line are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.html new file mode 100644 index 00000000000000..b5a998072768bc --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.html @@ -0,0 +1,38 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.line +

2d.path.stroke.prune.closePath.line

+

Test if zero-lengthed closePath before and after line are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.w.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.w.html new file mode 100644 index 00000000000000..94f8f5041f1bdc --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.line.w.html @@ -0,0 +1,52 @@ + + + + +Canvas test: 2d.path.stroke.prune.closePath.line +

2d.path.stroke.prune.closePath.line

+

Test if zero-lengthed closePath before and after line are ignored corrected.

+ +

FAIL (fallback content)

+
+ + + diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html new file mode 100644 index 00000000000000..03635b01483857 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve-expected.html @@ -0,0 +1,25 @@ + + +Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve +

2d.path.stroke.prune.closePath.quadraticCurve

+

Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html new file mode 100644 index 00000000000000..344bcbc7596240 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.html @@ -0,0 +1,38 @@ + + + +Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve +

2d.path.stroke.prune.closePath.quadraticCurve

+

Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ diff --git a/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.w.html b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.w.html new file mode 100644 index 00000000000000..417691c4703354 --- /dev/null +++ b/html/canvas/offscreen/path-objects/2d.path.stroke.prune.closePath.quadraticCurve.w.html @@ -0,0 +1,52 @@ + + + + +Canvas test: 2d.path.stroke.prune.closePath.quadraticCurve +

2d.path.stroke.prune.closePath.quadraticCurve

+

Test if zero-lengthed closePath before and after quadratic curve are ignored corrected.

+ +

FAIL (fallback content)

+
+ + + diff --git a/html/canvas/tools/yaml-new/path-objects.yaml b/html/canvas/tools/yaml-new/path-objects.yaml index 673c9085744279..3691915067e0a2 100644 --- a/html/canvas/tools/yaml-new/path-objects.yaml +++ b/html/canvas/tools/yaml-new/path-objects.yaml @@ -2879,6 +2879,157 @@ @assert pixel 50,25 == 0,255,0,255; expected: green +- name: 2d.path.stroke.prune.closePath.line + desc: Test if zero-lengthed closePath before and after line are ignored corrected. + code: | + 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(); + reference: | + 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(); + +- name: 2d.path.stroke.prune.closePath.bezierCurve + desc: Test if zero-lengthed closePath before and after bezier curve are ignored corrected. + code: | + 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(); + reference: | + 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(); + +- name: 2d.path.stroke.prune.closePath.quadraticCurve + desc: Test if zero-lengthed closePath before and after quadratic curve are ignored corrected. + code: | + 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(); + reference: | + 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(); + +- name: 2d.path.stroke.prune.closePath.arc + desc: Test if zero-lengthed closePath before and after arc are ignored corrected. + code: | + 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(); + reference: | + 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(); - name: 2d.path.transformation.basic code: |