NEW169922
fillText ignores canvas RTL unless canvas is member of the DOM
https://bugs.webkit.org/show_bug.cgi?id=169922
Summary fillText ignores canvas RTL unless canvas is member of the DOM
Richard Davey
Reported 2017-03-21 14:04:57 PDT
Demo: http://codepen.io/photonstorm/pen/peLyyX?editors=1010 Issue: The canvas fillText function ignores the canvas dir and canvas.style.direction properties unless the canvas itself has been added to the DOM. For example this works fine: ``` var str1 = "این یک آزمایش است."; var canvas = document.createElement('canvas'); canvas.dir = 'rtl'; document.body.appendChild(canvas); var ctx = canvas.getContext('2d'); ctx.font = '48px serif'; ctx.fillStyle = '#ff00ff'; ctx.fillText(str1, 500, 100); ``` The Arabic text will respect the canvas dir attribute and render correctly. However if you do not add the canvas to the document body, it will ignore the dir property entirely, making this fail: ``` // However if the canvas is NOT added to the document.body then it's clear that // fillText ignores the RTL setting entirely, as seen below: var canvas3 = document.createElement('canvas'); var ctx3 = canvas3.getContext('2d'); // Both of the following are ignored, because the canvas isn't in the DOM canvas3.dir = 'rtl'; canvas3.style.direction = 'rtl'; canvas3.width = 600; canvas3.height = 600; ctx3.font = '48px serif'; ctx3.fillStyle = '#00ff00'; ctx3.textAlign = 'end'; ctx3.fillText(str1, 500, 300); ctx.drawImage(canvas3, 0, 0); ``` You can see all of this, plus more examples here: http://codepen.io/photonstorm/pen/peLyyX?editors=1010 I don't know if this behaviour matches the spec or not as I couldn't find anything specific to this issue in it, but it doesn't really make sense (on a logical level, maybe on a technical one it does).
Attachments
test case (1.33 KB, text/html)
2017-03-27 18:05 PDT, Said Abou-Hallawa
no flags
test case (1.33 KB, text/html)
2017-03-27 18:09 PDT, Said Abou-Hallawa
no flags
Radar WebKit Bug Importer
Comment 1 2017-03-24 18:58:33 PDT
Said Abou-Hallawa
Comment 2 2017-03-27 18:05:25 PDT
Created attachment 305532 [details] test case
Said Abou-Hallawa
Comment 3 2017-03-27 18:09:46 PDT
Created attachment 305534 [details] test case
Matan Rosenberg
Comment 4 2018-02-05 05:27:48 PST
Hey. Just wondering that is the status of this issue - is it going to be fixed sometime soon? Thanks!
Ahmad Saleem
Comment 5 2023-09-19 17:45:08 PDT
I am still able to reproduce this bug using attached test case in Safari Technology Preview 178. Second and Third line has incorrect . and ( compared to Chrome Canary 119 and Firefox Nightly 119, which match each other.
Anne van Kesteren
Comment 6 2024-09-04 00:57:28 PDT
Per the specification it should honer context.direction first canvas.dir second but never canvas.style.direction. (There's also a problem with the specification where it assumes canvas.dir works for OffscreenCanvas, but it can't.)
Note You need to log in before you can comment on or make changes to this bug.