Closed Bug 1778909 Opened 2 years ago Closed 1 year ago

Implement the letterSpacing and wordSpacing attributes for Canvas2D text

Categories

(Core :: Graphics: Canvas2D, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
115 Branch
Tracking Status
firefox115 --- fixed

People

(Reporter: jfkthame, Assigned: jfkthame)

References

(Blocks 2 open bugs)

Details

Attachments

(3 files)

No description provided.

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.

Severity: -- → S3

:jfkthame, are there any plans to implement these two properties ?

Flags: needinfo?(jfkthame)

I'm hoping to get to them in the fairly near future (sorry, nothing more specific than that).

Flags: needinfo?(jfkthame)
Type: defect → enhancement

: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!

Flags: needinfo?(emilio)

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).

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED

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.

Flags: needinfo?(emilio)

(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:

  1. Let parsed be the result of parsing the given value as a CSS <length>.
    ...

so only <length> is allowed, not <percentage>.

(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 like em, 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:

  1. 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?

Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b3fb213b502f Add an API to parse an absolute length without any other context. r=jfkthame
Attachment #9331345 - Attachment description: Bug 1778909 - Update metadata for canvas letterSpacing/wordSpacing tests that now pass; add a small epsilon to some tests to allow for floating-point inaccuracies. r=#layout-reviewers → Bug 1778909 - Update tests and metadata for canvas letterSpacing/wordSpacing attributes. r=#layout-reviewers
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/158519168b2c Implement letterSpacing and wordSpacing attributes for Canvas2D text. r=saschanaz,emilio https://hg.mozilla.org/integration/autoland/rev/c94a256988d7 Update tests and metadata for canvas letterSpacing/wordSpacing attributes. r=boris
Keywords: leave-open
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/39991 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 115 Branch
Blocks: 1832955
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: