Skip to content

Commit

Permalink
Bug 1950455 [wpt PR 50942] - Implement ctx.strokeTextCluster(), a=tes…
Browse files Browse the repository at this point in the history
…tonly

Automatic update from web-platform-tests
Implement ctx.strokeTextCluster()

This CL creates a new method for CanvasRenderingContext2d that strokes
a TextCluster object. Its fill counterpart, ctx.fillTextCluster(), was
merged in https://crrev.com/c/5854270.

This new method came to be from the discussion around the spec for the
TextMetrics additions: whatwg/html#11000

The existing tests for fillTextCluster() were renamed to include the
method name in the title, since before only "rendering" was mentioned.
The new tests are explicitly named using strokeTextCluster().

A line that was duplicated on the tests for fillTextCluster() was also
removed.

Bug: 341213359
Change-Id: Icd792b56e48f3ea5091e958671c19fcefe67fdec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6282180
Commit-Queue: Andres Ricardo Perez <[email protected]>
Reviewed-by: Fernando Serboncini <[email protected]>
Reviewed-by: Stephen Chenney <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1425171}

--

wpt-commits: e515834325719ce9e2a15e2d41bfce49f020db7a
wpt-pr: 50942
  • Loading branch information
AndresRPerez12 authored and moz-wptsync-bot committed Feb 28, 2025
1 parent b622c5d commit 2064df7
Show file tree
Hide file tree
Showing 53 changed files with 2,660 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-align.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-align.tentative</h1>
<title>Canvas test: 2d.text.measure.fillTextCluster-align.tentative</title>
<h1>2d.text.measure.fillTextCluster-align.tentative</h1>
<p class="desc">Test that fillTextCluster() correctly positions the text, taking into account the textAlign from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<link rel="match" href="2d.text.measure.text-clusters-rendering-align.tentative-expected.html">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-align.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-align.tentative</h1>
<link rel="match" href="2d.text.measure.fillTextCluster-align.tentative-expected.html">
<title>Canvas test: 2d.text.measure.fillTextCluster-align.tentative</title>
<h1>2d.text.measure.fillTextCluster-align.tentative</h1>
<p class="desc">Test that fillTextCluster() correctly positions the text, taking into account the textAlign from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-baseline.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-baseline.tentative</h1>
<title>Canvas test: 2d.text.measure.fillTextCluster-baseline.tentative</title>
<h1>2d.text.measure.fillTextCluster-baseline.tentative</h1>
<p class="desc">Test that fillTextCluster() correctly positions the text, taking into account the textBaseline from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<link rel="match" href="2d.text.measure.text-clusters-rendering-baseline.tentative-expected.html">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-baseline.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-baseline.tentative</h1>
<link rel="match" href="2d.text.measure.fillTextCluster-baseline.tentative-expected.html">
<title>Canvas test: 2d.text.measure.fillTextCluster-baseline.tentative</title>
<h1>2d.text.measure.fillTextCluster-baseline.tentative</h1>
<p class="desc">Test that fillTextCluster() correctly positions the text, taking into account the textBaseline from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-drawing-styles-change.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-drawing-styles-change.tentative</h1>
<title>Canvas test: 2d.text.measure.fillTextCluster-drawing-styles-change.tentative</title>
<h1>2d.text.measure.fillTextCluster-drawing-styles-change.tentative</h1>
<p class="desc">Test that fillTextCluster() renders using the drawing styles as they were when `ctx.measureText()` was called, regardless of any changes in the context since.</p>

<div class="grid-container" style="--grid-width: 2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<link rel="match" href="2d.text.measure.text-clusters-rendering-drawing-styles-change.tentative-expected.html">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-drawing-styles-change.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-drawing-styles-change.tentative</h1>
<link rel="match" href="2d.text.measure.fillTextCluster-drawing-styles-change.tentative-expected.html">
<title>Canvas test: 2d.text.measure.fillTextCluster-drawing-styles-change.tentative</title>
<h1>2d.text.measure.fillTextCluster-drawing-styles-change.tentative</h1>
<p class="desc">Test that fillTextCluster() renders using the drawing styles as they were when `ctx.measureText()` was called, regardless of any changes in the context since.</p>

<div class="grid-container" style="--grid-width: 2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-font-change.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-font-change.tentative</h1>
<title>Canvas test: 2d.text.measure.fillTextCluster-font-change.tentative</title>
<h1>2d.text.measure.fillTextCluster-font-change.tentative</h1>
<p class="desc">Test that fillTextCluster() renders in the font used originally when the text was measured, even if the font set on the context has changed since.</p>
<canvas id="canvas" width="500" height="200">
<p class="fallback">FAIL (fallback content)</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="match" href="2d.text.measure.text-clusters-rendering-font-change.tentative-expected.html">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-font-change.tentative</title>
<h1>2d.text.measure.text-clusters-rendering-font-change.tentative</h1>
<link rel="match" href="2d.text.measure.fillTextCluster-font-change.tentative-expected.html">
<title>Canvas test: 2d.text.measure.fillTextCluster-font-change.tentative</title>
<h1>2d.text.measure.fillTextCluster-font-change.tentative</h1>
<p class="desc">Test that fillTextCluster() renders in the font used originally when the text was measured, even if the font set on the context has changed since.</p>
<canvas id="canvas" width="500" height="200">
<p class="fallback">FAIL (fallback content)</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.text.measure.text-clusters-rendering-options.tentative</title>
<title>Canvas test: 2d.text.measure.fillTextCluster-options.tentative</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
Expand All @@ -14,7 +14,7 @@
</style>
<body class="show_output">

<h1>2d.text.measure.text-clusters-rendering-options.tentative</h1>
<h1>2d.text.measure.fillTextCluster-options.tentative</h1>
<p class="desc">Test that fillTextCluster() correctly applies the options passed as a dictionary.</p>


Expand Down Expand Up @@ -52,7 +52,6 @@ <h1>2d.text.measure.text-clusters-rendering-options.tentative</h1>
_assertPixelApprox(canvas, 45,45, 0,255,0,255, 2);
_assertPixelApprox(canvas, 55,5, 255,0,0,255, 2);
_assertPixelApprox(canvas, 5,55, 255,0,0,255, 2);
_assertPixelApprox(canvas, 5,55, 255,0,0,255, 2);
_assertPixelApprox(canvas, 55,55, 255,0,0,255, 2);

// Override the x and y values of the cluster.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.text.measure.text-clusters-range.tentative</title>
<title>Canvas test: 2d.text.measure.fillTextCluster-range.tentative</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
Expand All @@ -14,7 +14,7 @@
</style>
<body class="show_output">

<h1>2d.text.measure.text-clusters-range.tentative</h1>
<h1>2d.text.measure.fillTextCluster-range.tentative</h1>
<p class="desc">Test that getTextClusters() and fillTextCluster() correctly render different ranges of the input text.</p>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<title>Canvas test: 2d.text.measure.strokeTextCluster-align.tentative</title>
<h1>2d.text.measure.strokeTextCluster-align.tentative</h1>
<p class="desc">Test that strokeTextCluster() correctly positions the text, taking into account the textAlign from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 3">
<span>
<div>ctx_align_left</div>
<canvas class="grid-cell-content" id="canvas0" width="250" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas0");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = canvas.width / 2;
const y = canvas.height / 2;

ctx.textAlign = 'left';

// Rendering all clusters with the same (x, y) parameters must be
// equivalent to a strokeText() call at (x, y).
ctx.strokeText(text, x, y);
</script>
</span>

<span>
<div>ctx_align_center</div>
<canvas class="grid-cell-content" id="canvas1" width="250" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas1");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = canvas.width / 2;
const y = canvas.height / 2;

ctx.textAlign = 'center';

// Rendering all clusters with the same (x, y) parameters must be
// equivalent to a strokeText() call at (x, y).
ctx.strokeText(text, x, y);
</script>
</span>

<span>
<div>ctx_align_right</div>
<canvas class="grid-cell-content" id="canvas2" width="250" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas2");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = canvas.width / 2;
const y = canvas.height / 2;

ctx.textAlign = 'right';

// Rendering all clusters with the same (x, y) parameters must be
// equivalent to a strokeText() call at (x, y).
ctx.strokeText(text, x, y);
</script>
</span>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<link rel="match" href="2d.text.measure.strokeTextCluster-align.tentative-expected.html">
<title>Canvas test: 2d.text.measure.strokeTextCluster-align.tentative</title>
<h1>2d.text.measure.strokeTextCluster-align.tentative</h1>
<p class="desc">Test that strokeTextCluster() correctly positions the text, taking into account the textAlign from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 3">
<span>
<div>ctx_align_left</div>
<canvas class="grid-cell-content" id="canvas0" width="250" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas0");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = canvas.width / 2;
const y = canvas.height / 2;

ctx.textAlign = 'left';
let tm = ctx.measureText(text);
const clusters = tm.getTextClusters();

// Rendering all clusters with the same (x, y) parameters must be
// equivalent to a strokeText() call at (x, y).
for (const cluster of clusters) {
ctx.strokeTextCluster(cluster, x, y);
}
</script>
</span>

<span>
<div>ctx_align_center</div>
<canvas class="grid-cell-content" id="canvas1" width="250" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas1");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = canvas.width / 2;
const y = canvas.height / 2;

ctx.textAlign = 'center';
let tm = ctx.measureText(text);
const clusters = tm.getTextClusters();

// Rendering all clusters with the same (x, y) parameters must be
// equivalent to a strokeText() call at (x, y).
for (const cluster of clusters) {
ctx.strokeTextCluster(cluster, x, y);
}
</script>
</span>

<span>
<div>ctx_align_right</div>
<canvas class="grid-cell-content" id="canvas2" width="250" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas2");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = canvas.width / 2;
const y = canvas.height / 2;

ctx.textAlign = 'right';
let tm = ctx.measureText(text);
const clusters = tm.getTextClusters();

// Rendering all clusters with the same (x, y) parameters must be
// equivalent to a strokeText() call at (x, y).
for (const cluster of clusters) {
ctx.strokeTextCluster(cluster, x, y);
}
</script>
</span>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<link rel="stylesheet" href="/html/canvas/resources/canvas-grid-reftest.css">
<title>Canvas test: 2d.text.measure.strokeTextCluster-baseline.tentative</title>
<h1>2d.text.measure.strokeTextCluster-baseline.tentative</h1>
<p class="desc">Test that strokeTextCluster() correctly positions the text, taking into account the textBaseline from the context at the time the text was measured.</p>

<div class="grid-container" style="--grid-width: 4">
<span>
<div>ctx_baseline_top</div>
<canvas class="grid-cell-content" id="canvas0" width="180" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas0");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = 20;
const y = canvas.height / 2;

ctx.textBaseline = 'top';
ctx.strokeText(text, x, y);
</script>
</span>

<span>
<div>ctx_baseline_middle</div>
<canvas class="grid-cell-content" id="canvas1" width="180" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas1");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = 20;
const y = canvas.height / 2;

ctx.textBaseline = 'middle';
ctx.strokeText(text, x, y);
</script>
</span>

<span>
<div>ctx_baseline_bottom</div>
<canvas class="grid-cell-content" id="canvas2" width="180" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas2");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = 20;
const y = canvas.height / 2;

ctx.textBaseline = 'bottom';
ctx.strokeText(text, x, y);
</script>
</span>

<span>
<div>ctx_baseline_alphabetic</div>
<canvas class="grid-cell-content" id="canvas3" width="180" height="43">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script type="module">
const canvas = document.getElementById("canvas3");
const ctx = canvas.getContext('2d');

ctx.font = '20px serif';
const text = 'Test ☺️ א';
const x = 20;
const y = canvas.height / 2;

ctx.textBaseline = 'alphabetic';
ctx.strokeText(text, x, y);
</script>
</span>

</div>
Loading

0 comments on commit 2064df7

Please sign in to comment.