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/element/text/2d.text.shape.glyph-clusters-position.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>Canvas test: 2d.text.shape.glyph-clusters-position.tentative</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">
<style>
@font-face {
font-family: CanvasTest;
src: url("/fonts/CanvasTest.ttf");
}
</style>
<body class="show_output">
<h1>2d.text.shape.glyph-clusters-position.tentative</h1>
<p class="desc">Test that ShapedText::glyphClusters() and ShapedText::glyphRuns() return GlyphRun objects positioned according to the context textAlign and textBaseline at shapeText() time, and expose per-run TextMetrics.</p>
<span style="font-family: CanvasTest; position: absolute; visibility: hidden">A</span>
<p class="output">Actual output:</p>
<canvas id="c" class="output" width="500" height="500"><p class="fallback">FAIL (fallback content)</p></canvas>
<ul id="d"></ul>
<script>
promise_test(async t => {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
await document.fonts.ready;
ctx.font = '40px CanvasTest';
const text = 'E';
ctx.textBaseline = 'top';
ctx.textAlign = 'left';
let st = ctx.shapeText(text);
_assertSame(Math.abs(st.glyphClusters()[0].x), 0, "Math.abs(st.glyphClusters()[\""+(0)+"\"].x)", "0");
_assertSame(Math.abs(st.glyphClusters()[0].y), 0, "Math.abs(st.glyphClusters()[\""+(0)+"\"].y)", "0");
_assertSame(st.glyphClusters()[0].width, 40, "st.glyphClusters()[\""+(0)+"\"].width", "40");
_assertSame(st.glyphClusters()[0].textMetrics().width, 40, "st.glyphClusters()[\""+(0)+"\"].textMetrics().width", "40");
_assertSame(st.glyphRuns().length, 1, "st.glyphRuns().length", "1");
_assertSame(Math.abs(st.glyphRuns()[0].x), 0, "Math.abs(st.glyphRuns()[\""+(0)+"\"].x)", "0");
_assertSame(st.glyphRuns()[0].width, 40, "st.glyphRuns()[\""+(0)+"\"].width", "40");
ctx.textAlign = 'center';
st = ctx.shapeText(text);
_assertSame(st.glyphClusters()[0].x, -20, "st.glyphClusters()[\""+(0)+"\"].x", "-20");
_assertSame(st.glyphRuns()[0].x, -20, "st.glyphRuns()[\""+(0)+"\"].x", "-20");
ctx.textAlign = 'right';
st = ctx.shapeText(text);
_assertSame(st.glyphClusters()[0].x, -40, "st.glyphClusters()[\""+(0)+"\"].x", "-40");
_assertSame(st.glyphRuns()[0].x, -40, "st.glyphRuns()[\""+(0)+"\"].x", "-40");
}, "Test that ShapedText::glyphClusters() and ShapedText::glyphRuns() return GlyphRun objects positioned according to the context textAlign and textBaseline at shapeText() time, and expose per-run TextMetrics.");
</script>