Implement the letterSpacing and wordSpacing attributes for Canvas2D text
Categories
(Core :: Graphics: Canvas2D, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox115 | --- | fixed |
People
(Reporter: jfkthame, Assigned: jfkthame)
References
(Blocks 2 open bugs)
Details
Attachments
(3 files)
Comment 1•2 years ago
|
||
Triage - since this is marked as a defect it needs severity, the letterSpacing and wordSpacing attributes sound like details that can significantly affect layout of text in a canvas, so I am marking this S3.
Updated•2 years ago
|
Comment 2•2 years ago
|
||
:jfkthame, are there any plans to implement these two properties ?
Assignee | ||
Comment 3•2 years ago
|
||
I'm hoping to get to them in the fairly near future (sorry, nothing more specific than that).
Updated•1 year ago
|
Assignee | ||
Comment 4•1 year ago
|
||
:emilio, the initial patch here doesn't work for OffscreenCanvas because it can't parse the values without the style context (to resolve font-relative lengths) -- can you look into what it'd take to handle that? Do we have existing ways to do it? Thanks!
Assignee | ||
Comment 5•1 year ago
|
||
Currently, this works only for the <canvas> element, not for OffscreenCanvas,
because CanvasRenderingContext2D::ResolveStyleForProperty needs the presShell
and canvas element to resolve CSS lengths (which may use font-relative units).
Updated•1 year ago
|
Assignee | ||
Comment 6•1 year ago
|
||
Depends on D177019
Comment 7•1 year ago
|
||
So there's no reasonable reference value for all these units like vh/vw. This is basically https://github.com/whatwg/html/issues/7847, right?
The discussion there leaned into only allowing non-relative lengths / percentages, right? In fact you're already disallowing word-spacing percentages. If so, and given these are relatively simple properties, I think we could add a simple API that worked on canvas for absolute lengths.
Comment 8•1 year ago
|
||
This should allow making these work on canvas.
Assignee | ||
Comment 9•1 year ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #7)
So there's no reasonable reference value for all these units like vh/vw. This is basically https://github.com/whatwg/html/issues/7847, right?
Right, I don't think there's any sensible way to use things like vh
/vw
, but it would be nice to have font-relative units like em
, ex
, ch
, etc., resolved against the canvas font
attribute, and there seem to be existing tests that expect at least em
to work. For letter- and word-spacing, em
is probably the most useful unit for authors, though I could imagine ch
also being popular.
In fact you're already disallowing word-spacing percentages.
Yeah - the HTML spec explicitly says that
The wordSpacing setter steps are:
- Let parsed be the result of parsing the given value as a CSS <length>.
...
so only <length> is allowed, not <percentage>.
Comment 10•1 year ago
|
||
(In reply to Jonathan Kew [:jfkthame] from comment #9)
(In reply to Emilio Cobos Álvarez (:emilio) from comment #7)
So there's no reasonable reference value for all these units like vh/vw. This is basically https://github.com/whatwg/html/issues/7847, right?
Right, I don't think there's any sensible way to use things like
vh
/vw
, but it would be nice to have font-relative units likeem
,ex
,ch
, etc.,
Shouldn't be hard to extend the resolve_pixel_value
shenanigans to resolve against a font, perhaps... Might need some rejiggering of the relative fonts to take a font struct or so, but should be doable...
In fact you're already disallowing word-spacing percentages.
Yeah - the HTML spec explicitly says that
The wordSpacing setter steps are:
- Let parsed be the result of parsing the given value as a CSS <length>.
Does that mean that normal
is not expected to work either per spec? Are there tests for that?
Comment 11•1 year ago
|
||
Updated•1 year ago
|
Comment 12•1 year ago
|
||
bugherder |
Updated•1 year ago
|
Comment 13•1 year ago
|
||
Assignee | ||
Updated•1 year ago
|
Comment 15•1 year ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/158519168b2c
https://hg.mozilla.org/mozilla-central/rev/c94a256988d7
Description
•