Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/offscreen/text/2d.text.measure.text-clusters-rendering-options.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>OffscreenCanvas test: 2d.text.measure.text-clusters-rendering-options.tentative</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<h1>2d.text.measure.text-clusters-rendering-options.tentative</h1>
<p class="desc">Test that fillTextCluster() correctly applies the options passed as a dictionary.</p>
<script>
promise_test(async t => {
var canvas = new OffscreenCanvas(100, 300);
var ctx = canvas.getContext('2d');
var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')");
f.load();
document.fonts.add(f);
await document.fonts.ready;
ctx.font = '50px CanvasTest';
ctx.textAlign = 'left';
ctx.textBaseline = 'top';
const text = 'E';
const tm = ctx.measureText(text);
const cluster = tm.getTextClusters()[0];
// Background color.
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#0f0';
// Override the align and baseline of the cluster.
ctx.fillTextCluster(cluster, 50, 50, {align: 'right', baseline: 'bottom'});
_assertPixelApprox(canvas, 5,5, 0,255,0,255, 2);
_assertPixelApprox(canvas, 45,5, 0,255,0,255, 2);
_assertPixelApprox(canvas, 5,45, 0,255,0,255, 2);
_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.
ctx.fillTextCluster(cluster, 0, 100, {x: 10, y: 10});
_assertPixelApprox(canvas, 15,115, 0,255,0,255, 2);
_assertPixelApprox(canvas, 55,115, 0,255,0,255, 2);
_assertPixelApprox(canvas, 15,155, 0,255,0,255, 2);
_assertPixelApprox(canvas, 55,155, 0,255,0,255, 2);
_assertPixelApprox(canvas, 65,115, 255,0,0,255, 2);
_assertPixelApprox(canvas, 15,165, 255,0,0,255, 2);
_assertPixelApprox(canvas, 65,165, 255,0,0,255, 2);
// Override the align, baseline, x, and y values of the cluster.
ctx.fillTextCluster(cluster, 50, 250,
{align: 'right', baseline: 'bottom', x: 10, y: 10});
_assertPixelApprox(canvas, 15,215, 0,255,0,255, 2);
_assertPixelApprox(canvas, 55,215, 0,255,0,255, 2);
_assertPixelApprox(canvas, 15,255, 0,255,0,255, 2);
_assertPixelApprox(canvas, 55,255, 0,255,0,255, 2);
_assertPixelApprox(canvas, 65,215, 255,0,0,255, 2);
_assertPixelApprox(canvas, 15,265, 255,0,0,255, 2);
_assertPixelApprox(canvas, 65,265, 255,0,0,255, 2);
}, "Test that fillTextCluster() correctly applies the options passed as a dictionary.");
</script>