Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional lang argument to OffscreenCanvas constructor #10862

Open
schenney-chromium opened this issue Dec 13, 2024 · 9 comments
Open

Add an optional lang argument to OffscreenCanvas constructor #10862

schenney-chromium opened this issue Dec 13, 2024 · 9 comments
Assignees
Labels
i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. topic: canvas

Comments

@schenney-chromium
Copy link
Contributor

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.

@Kaiido
Copy link
Member

Kaiido commented Dec 13, 2024

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.

@xfq xfq added the i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. label Dec 16, 2024
@schenney-chromium
Copy link
Contributor Author

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
Copy link
Member

annevk commented Dec 16, 2024

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.

@schenney-chromium
Copy link
Contributor Author

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

@annevk
Copy link
Member

annevk commented Dec 16, 2024

Sounds good to me!

@annevk
Copy link
Member

annevk commented Dec 16, 2024

cc @whatwg/canvas

@Kaiido
Copy link
Member

Kaiido commented Dec 16, 2024

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.

@schenney-chromium
Copy link
Contributor Author

Draft PR: #10873

@schenney-chromium
Copy link
Contributor Author

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.

@past past removed the agenda+ To be discussed at a triage meeting label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. topic: canvas
Development

No branches or pull requests

5 participants