whatwg/html

Add an optional lang argument to OffscreenCanvas constructor

Opened this issue · 9 comments

What is the issue with the HTML Standard?

The <canvas> DOM element, like all DOM elements, accepts a lang attribute that is used to define location specific treatment for font selection (when fonts have locale specific glyphs). Browsers respect this attribute. However, when an OffscreenCanvas is created in JS, there is no way to set locale information, possibly resulting in a state where an offscreen canvas produces rendered results that differ from the canvas in which it's output is used.

I propose adding an optional string lang parameter to the OffscreenCanvas constructor, and spec text indicating how offscreen canvases created from canvas elements should inherit the lang.

Both Chrome and Firefox on linux always use the system language settings for offscreen canvas, even when transferred from a canvas element, as far as I can tell.

Why not follow the same setup as for direction here? Would other context types also need this?

Also it'd probably be great if all such inherited properties could be specced clearly.

Why not follow the same setup as for direction here? Would other context types also need this?

Also it'd probably be great if all such inherited properties could be specced clearly.

Are you saying that instead of using an HTML attribute on the element, use an IDL attribute on CanvasTextDrawingStyles?

I'd be fine with that but it would need some statement of how the "lang" attribute on <canvas> does not apply, or is used as the initial value for the CanvasTextDrawingStyles. Regardless we would need some sensible initial value for a lang IDL attribute.

The spec text you linked to also seems to imply that the workers lang should come from the Document. I was not seeing that behavior though I'm not entirely confident I was testing correctly.

annevk commented

I suspect we want a nullable string attribute. When it's null it defers to the language of the canvas element. Otherwise it's the given value. And if there is no canvas element it acts as if it's the unknown language.

We should probably also tidy up the language for direction as it makes no sense that it talks about Document there or implies it would work for workers. In that case it also needs to default.

Shall I take a stab at my first significant PR and plan to discuss at this week's WHATNOT meeting?

annevk commented

Sounds good to me!

annevk commented

cc @whatwg/canvas

Kaiido commented

Are you saying that instead of using an HTML attribute on the element

I'm saying that if it only concerns the 2d context it shouldn't be an option on the OffscreenCanvas constructor but a 2d context attribute instead.
Note that direction does default to "inherit" which does use the canvas element's value if any.

The spec text you linked to also seems to imply that the workers lang should come from the Document

I don't see no mention of the lang attribute in the current texts. But note that the direction is actually computed in the text preparation steps, you'd probably want to take inspiration from that.
Ps: and for an OffscreenCanvas in a Worker, inherit would return "ltr", from the last branch of the algo.

WHATNOT meeting issues:

  • Snapshotting of values when context is transferred to worker.
  • Snapshotting of values when TextMetrics is created.
  • Does a change in the lang attribute require font reload?

Basically, figure out all the dynamic situations.