Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/element/text/fillText-bidi-rtl.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Canvas Test: fillText reorders bidirectional text in a right-to-left paragraph</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm">
<link rel="match" href="reference/fillText-bidi-rtl-ref.html">
<meta name="assert" content="Latin text and numbers inside Hebrew text keep their left-to-right order while the paragraph runs right-to-left.">
<style>
canvas {
margin: 10px;
}
</style>
<canvas id="canvas" width="400" height="120"></canvas>
<script>
const context = canvas.getContext("2d");
context.font = "20px sans-serif";
context.direction = "rtl";
context.textAlign = "left";
// Latin run after a Hebrew run.
context.fillText("אבג abc", 10, 40);
// Number between two Hebrew runs.
context.fillText("אבג 123 דהו", 10, 90);
</script>