Skip to content

Commit 886a1e3

Browse files
schenney-chromiummoz-wptsync-bot
authored andcommitted
Bug 1949801 [wpt PR 50870] - Implement the Canvas TextStyles lang attribute, a=testonly
Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870
1 parent cf74dec commit 886a1e3

30 files changed

+788
-2
lines changed

testing/web-platform/tests/html/canvas/element/manual/filters/tentative/canvas-filter-object-turbulence.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<head>
2-
<link rel="match" href="canvas-filter-object-turbulence-expected.html">
2+
<link rel="match" href="canvas-filter-object-blur-expected.html">
33
</head>
44
<body>
55
</body>

testing/web-platform/tests/html/canvas/element/manual/text/canvas.2d.direction.inherit.dynamic.canvas.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html dir="ltr">
33
<meta charset="utf-8">
44
<head>
5-
<title>HTML5 Canvas Test: The direction attribute dynamiclaly updates</title>
5+
<title>HTML5 Canvas Test: The direction attribute dynamically updates</title>
66
<link rel="match" href="canvas.2d.direction.dynamic-ref.html"/>
77
<link rel="author" href="mailto:[email protected]"/>
88
<link rel="help"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype HTML>
2+
<meta charset="utf-8">
3+
<title>HTML5 Canvas Test Reference: The lang attribute.</title>
4+
<link rel="author" href="mailto:[email protected]"/>
5+
<script>
6+
function generateReference() {
7+
var canvas = document.getElementById('canvas1');
8+
var ctx = canvas.getContext('2d');
9+
10+
// The default for lang is inherit, so no need to set any text styles.
11+
ctx.font = '25px serif';
12+
ctx.fillText('今骨直', 5, 50);
13+
}
14+
</script>
15+
<body onload="generateReference()">
16+
<canvas lang="zh-CN" id="canvas1" width="300" height="150">
17+
Browser does not support HTML5 Canvas.
18+
</canvas>
19+
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!doctype HTML>
2+
<meta charset="utf-8">
3+
<title>HTML5 Canvas Test Reference: The lang attribute.</title>
4+
<link rel="author" href="mailto:[email protected]"/>
5+
<style>
6+
#canvas1 {
7+
position: absolute;
8+
left: 0px;
9+
top: 0px;
10+
}
11+
#canvas2 {
12+
position: absolute;
13+
left: 0px;
14+
top: 50px;
15+
}
16+
#canvas3 {
17+
position: absolute;
18+
left: 0px;
19+
top: 100px;
20+
}
21+
#canvas4 {
22+
position: absolute;
23+
left: 0px;
24+
top: 150px;
25+
}
26+
</style>
27+
<script>
28+
function generateReference() {
29+
var canvas1 = document.getElementById('canvas1');
30+
var ctx1 = canvas1.getContext('2d');
31+
ctx1.font = '25px serif';
32+
ctx1.fillText('今骨直', 60, 30);
33+
34+
var canvas2 = document.getElementById('canvas2');
35+
var ctx2 = canvas2.getContext('2d');
36+
ctx2.font = '25px serif';
37+
ctx2.fillText('今骨直', 60, 30);
38+
39+
var canvas3 = document.getElementById('canvas3');
40+
var ctx3 = canvas3.getContext('2d');
41+
ctx3.font = '25px serif';
42+
ctx3.fillText('今骨直', 60, 30);
43+
44+
var canvas4 = document.getElementById('canvas4');
45+
var ctx4 = canvas4.getContext('2d');
46+
ctx4.font = '25px serif';
47+
ctx4.fillText('今骨直', 60, 30);
48+
}
49+
</script>
50+
<body onload="generateReference()">
51+
<canvas id="canvas1" lang="ja" width="300" height="50">
52+
Browser does not support HTML5 Canvas.
53+
</canvas>
54+
<canvas id="canvas2" lang="zh-CN" width="300" height="50">
55+
Browser does not support HTML5 Canvas.
56+
</canvas>
57+
<canvas id="canvas3" lang="ja" width="300" height="50">
58+
Browser does not support HTML5 Canvas.
59+
</canvas>
60+
<canvas id="canvas4" lang="zh-CN" width="300" height="50">
61+
Browser does not support HTML5 Canvas.
62+
</canvas>
63+
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype HTML>
2+
<meta charset="utf-8">
3+
<title>HTML5 Canvas Test: The lang attribute dynamically updates</title>
4+
<link rel="match" href="canvas.2d.lang.dynamic-ref.html"/>
5+
<link rel="author" href="mailto:[email protected]"/>
6+
<link rel="help"
7+
href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
8+
<meta name="assert" content="Verify that a text lang change is applied."/>
9+
<style>
10+
canvas {
11+
position: absolute;
12+
left: 0px;
13+
top: 0px;
14+
}
15+
</style>
16+
<script type="text/javascript">
17+
function runTest() {
18+
var canvas = document.getElementById('canvas1');
19+
var ctx = canvas.getContext('2d');
20+
21+
ctx.font = '25px serif';
22+
ctx.fillText('今骨直', 60, 30);
23+
24+
canvas.setAttribute('lang', 'zh-CN');
25+
ctx.fillText('今骨直', 60, 80);
26+
27+
ctx.lang = 'ja';
28+
ctx.fillText('今骨直', 60, 130);
29+
30+
ctx.lang = 'inherit';
31+
ctx.fillText('今骨直', 60, 180);
32+
}
33+
</script>
34+
<body onload="runTest()">
35+
<canvas lang="ja" id="canvas1" width="300" height="200">
36+
Browser does not support HTML5 Canvas.
37+
</canvas>
38+
</body>
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype HTML>
2+
<meta charset="utf-8">
3+
<title>HTML5 Canvas Test Reference: The lang attribute.</title>
4+
<link rel="author" href="mailto:[email protected]"/>
5+
<script>
6+
function generateReference() {
7+
var canvas = document.getElementById('canvas1');
8+
var ctx = canvas.getContext('2d');
9+
10+
// The default for lang is inherit, so no need to set any text styles.
11+
ctx.font = '25px serif';
12+
ctx.fillText('今骨直', 5, 50);
13+
}
14+
</script>
15+
<body onload="generateReference()">
16+
<canvas id="canvas1" width="300" height="150">
17+
Browser does not support HTML5 Canvas.
18+
</canvas>
19+
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype HTML>
2+
<html lang="zh-CN">
3+
<meta charset="utf-8">
4+
<title>HTML5 Canvas Test: The empty string lang attribute uses the unknown language</title>
5+
<link rel="match" href="canvas.2d.lang.empty-ref.html" />
6+
<link rel="author" href="mailto:[email protected]"/>
7+
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
8+
<meta name="assert" content="When the lang attribute is the empty string, use the unknown language." />
9+
<script type="text/javascript">
10+
function runTest() {
11+
var canvas = document.getElementById('canvas1');
12+
var ctx = canvas.getContext('2d');
13+
14+
ctx.font = '25px serif';
15+
ctx.lang = '';
16+
ctx.fillText('今骨直', 5, 50);
17+
}
18+
</script>
19+
<body onload="runTest()">
20+
<canvas lang="zh-CN" id="canvas1" width="300" height="150">
21+
Browser does not support HTML5 Canvas.
22+
</canvas>
23+
</body>
24+
</html>
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype HTML>
2+
<html lang="en-US">
3+
<meta charset="utf-8">
4+
<title>HTML5 Canvas Test: The lang attribute inherits from the canvas rather than the document</title>
5+
<link rel="match" href="canvas.2d.lang-ref.html" />
6+
<link rel="author" href="mailto:[email protected]"/>
7+
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
8+
<meta name="assert" content="When the canvas element has a lang attribute, override the document." />
9+
<script type="text/javascript">
10+
function runTest() {
11+
var canvas = document.getElementById('canvas1');
12+
var ctx = canvas.getContext('2d');
13+
14+
ctx.font = '25px serif';
15+
ctx.fillText('今骨直', 5, 50);
16+
}
17+
</script>
18+
<body onload="runTest()">
19+
<canvas lang="zh-CN" id="canvas1" width="300" height="150">
20+
Browser does not support HTML5 Canvas.
21+
</canvas>
22+
</body>
23+
</html>
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!doctype HTML>
2+
<html lang="en-US">
3+
<meta charset="utf-8">
4+
<title>HTML5 Canvas Test: The lang attribute inherits from a disconnected canvas element</title>
5+
<link rel="match" href="canvas.2d.lang-ref.html"/>
6+
<link rel="author" href="mailto:[email protected]"/>
7+
<link rel="help"
8+
href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
9+
<meta name="assert" content="Verify that a disconnected canvas uses the canvas lang."/>
10+
<style>
11+
canvas {
12+
position: absolute;
13+
top: 8px;
14+
left: 8px;
15+
}
16+
</style>
17+
<body>
18+
<script type="text/javascript">
19+
var canvas = document.createElement('canvas');
20+
canvas.setAttribute('lang', 'zh-CN');
21+
canvas.setAttribute('width', '300');
22+
canvas.setAttribute('height', '150');
23+
var ctx = canvas.getContext('2d');
24+
25+
// The default for direction is inherit
26+
ctx.font = '25px serif';
27+
ctx.fillText('今骨直', 5, 50);
28+
29+
document.body.appendChild(canvas);
30+
</script>
31+
</body>
32+
</html>
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype HTML>
2+
<html lang="zh-CN">
3+
<meta charset="utf-8">
4+
<title>HTML5 Canvas Test: The lang attribute inherits the document lang when disconnected</title>
5+
<link rel="match" href="canvas.2d.lang-ref.html"/>
6+
<link rel="author" href="mailto:[email protected]"/>
7+
<link rel="help"
8+
href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
9+
<meta name="assert" content="Verify that a disconnected canvas with no lang attribnute uses the document lang."/>
10+
<style>
11+
canvas {
12+
position: absolute;
13+
top: 8px;
14+
left: 8px;
15+
}
16+
</style>
17+
<body>
18+
<script type="text/javascript">
19+
var canvas = document.createElement('canvas');
20+
canvas.setAttribute('width', '300');
21+
canvas.setAttribute('height', '150');
22+
var ctx = canvas.getContext('2d');
23+
24+
// The default for direction is inherit
25+
ctx.font = '25px serif';
26+
ctx.fillText('今骨直', 5, 50);
27+
28+
document.body.appendChild(canvas);
29+
</script>
30+
</body>
31+
</html>
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype HTML>
2+
<html lang="zh-CN">
3+
<meta charset="utf-8">
4+
<title>HTML5 Canvas Test: The lang attribute inherits from the document when no lang on the canvas</title>
5+
<link rel="match" href="canvas.2d.lang-ref.html" />
6+
<link rel="author" href="mailto:[email protected]"/>
7+
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
8+
<meta name="assert" content="When the canvas element has no lang attribute, inherit it from the document." />
9+
<script type="text/javascript">
10+
function runTest() {
11+
var canvas = document.getElementById('canvas1');
12+
var ctx = canvas.getContext('2d');
13+
14+
// The default for lang is inherit, so no need to set any text styles.
15+
ctx.font = '25px serif';
16+
ctx.fillText('今骨直', 5, 50);
17+
}
18+
</script>
19+
<body onload="runTest()">
20+
<canvas id="canvas1" width="300" height="150">
21+
Browser does not support HTML5 Canvas.
22+
</canvas>
23+
</body>
24+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype HTML>
2+
<html lang="en-US">
3+
<meta charset="utf-8">
4+
<title>HTML5 Canvas Test: The lang attribute is respected.</title>
5+
<link rel="match" href="canvas.2d.lang-ref.html" />
6+
<link rel="author" href="mailto:[email protected]"/>
7+
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#text-styles"/>
8+
<meta name="assert" content="When the canvas context has a lang attribute, override the document." />
9+
<script type="text/javascript">
10+
function runTest() {
11+
var canvas = document.getElementById('canvas1');
12+
var ctx = canvas.getContext('2d');
13+
14+
ctx.font = '25px serif';
15+
ctx.lang = 'zh-CN';
16+
ctx.fillText('今骨直', 5, 50);
17+
}
18+
</script>
19+
<body onload="runTest()">
20+
<canvas id="canvas1" width="300" height="150">
21+
Browser does not support HTML5 Canvas.
22+
</canvas>
23+
</body>
24+
</html>
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.text.lang.default.tentative</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.text.lang.default.tentative</h1>
12+
<p class="desc"></p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("");
21+
_addTest(function(canvas, ctx) {
22+
23+
_assertSame(ctx.lang, 'inherit', "ctx.lang", "'inherit'");
24+
25+
});
26+
</script>
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.text.lang.valid.tentative</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.text.lang.valid.tentative</h1>
12+
<p class="desc"></p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("");
21+
_addTest(function(canvas, ctx) {
22+
23+
ctx.lang = '';
24+
_assertSame(ctx.lang, '', "ctx.lang", "''");
25+
26+
ctx.lang = 'inherit';
27+
_assertSame(ctx.lang, 'inherit', "ctx.lang", "'inherit'");
28+
29+
ctx.lang = 'en-US';
30+
_assertSame(ctx.lang, 'en-US', "ctx.lang", "'en-US'");
31+
32+
ctx.lang = 'not-a-real-lang';
33+
_assertSame(ctx.lang, 'not-a-real-lang', "ctx.lang", "'not-a-real-lang'");
34+
35+
});
36+
</script>
37+

0 commit comments

Comments
 (0)