canvas-formatted-text
canvas-formatted-text copied to clipboard
Suggestion: Ship polyfill that can already be used
As far as I understand the following thing would be very tricky to implement with the existing canvas API:
- have a very long text that one wants to render at a fixed with 300px
- if doing so in plain HTML, the browser automatically break the lines based on font information & CSS
- now wanting to render the paragraph identical in canvas without manually specifying the line breaks would be pretty much impossible with existing APIs
All it currently exposes if one was to parse the original paragraph is all the boundingClientRects for each line, but there is not way of telling which character / word belong to which line.
The proposed API would pretty much solve the problem, yet will probably take quite a long time before it's adopted by all major browsers.
Perhaps if possible, one could already ship a polyfill for the library that would allow to use its functionality before shipped natively in browsers, especially with the focus on that line breaking behaves identicaly to how the browser determines it.