Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/offscreen/text/2d.text.shape.fillGlyphRun-direction-change.tentative.w.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">
<html class="reftest-wait">
<link rel="match" href="2d.text.shape.fillGlyphRun-direction-change.tentative-expected.html">
<script src="/common/reftest-wait.js"></script>
<title>Canvas test: 2d.text.shape.fillGlyphRun-direction-change.tentative</title>
<h1>2d.text.shape.fillGlyphRun-direction-change.tentative</h1>
<p class="desc">Test that fillGlyphRun() and fillGlyphRuns() render with the direction used when the text was shaped, even if the direction set on the context has changed since.</p>
<canvas id="canvas" width="500" height="200">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script id='myWorker' type='text/worker'>
self.onmessage = function(e) {
try {
const canvas = new OffscreenCanvas(500, 200);
const ctx = canvas.getContext('2d');
ctx.font = '30px serif';
ctx.textAlign = 'left';
ctx.direction = 'rtl';
// Brackets next to the paragraph edges take the paragraph direction, and
// are mirrored in RTL.
const texts = ['ab (', 'א (b)', 'Test ☺️ א World'];
const shaped = texts.map((text) => ctx.shapeText(text));
ctx.direction = 'ltr';
for (let i = 0; i < shaped.length; ++i) {
const y = 40 + i * 60;
for (const cluster of shaped[i].glyphClusters()) {
ctx.fillGlyphRun(cluster, 10, y);
}
ctx.fillGlyphRuns(shaped[i].glyphRuns(), 260, y);
}
const bitmap = canvas.transferToImageBitmap();
self.postMessage({ type: 'bitmap', bitmap }, [bitmap]);
} catch (error) {
self.postMessage({ type: 'error', message: error });
}
};
</script>
<script>
const blob = new Blob([document.getElementById('myWorker').textContent]);
const worker = new Worker(URL.createObjectURL(blob));
worker.onerror = failOnError;
worker.onmessage = reftestStep(msg => {
if (msg.data.type === 'error') {
failOnError(msg.data.message);
return;
}
const outputCtx = document.getElementById("canvas").getContext('2d');
outputCtx.drawImage(msg.data.bitmap, 0, 0);
takeScreenshot();
});
worker.postMessage(null);
</script>
</html>