I can’t seem to be able to add text to a canvas if the text includes “\n”. I mean, the line breaks do not show/work.
ctxPaint.fillText("s ome \n \\n <br/> thing", x, y);
The above code will draw "s ome \n <br/> thing", on one line.
Is this a limitation of fillText or am I doing it wrong? the “\n”s are there, and aren’t printed, but they don’t work either.
I’m afraid it is a limitation of Canvas’
fillText. There is no multi-line support. Whats worse, there’s no built-in way to measure line height, only width, making doing it yourself even harder!A lot of people have written their own multi-line support, perhaps the most notable project that has is Mozilla Skywriter.
The gist of what you’ll need to do is multiple
fillTextcalls while adding the height of the text to the y value each time. (measuring the width of M is what the skywriter people do to approximate text, I believe.)