-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 a lang
IDL Attribute to CanvasTextDrawingStyles, and clarify "direction" on same
#10873
Conversation
Also clean up what "inherit" means for direction.
@AndresRPerez12, @annevk, @fserb, @Kaiido Note that currently Chromium does not resolve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this!
I personally think it's great this hidden inheritance is finally made explicit, and having a way to set it on the context directly is a big plus.
Thanks for the very quick first round of review. I'll make the changes and update the PR. |
I plan to get this updated in the coming week. One issue is a lack of testing coverage for offscreen canvas objects transferred from HTML canvas, needed to the the "inherit" attribute value. I filed web-platform-tests/wpt#49987 to get that added to wpt, and I think I'll try to do the work for it. |
I've finally updated the PR. Please take another look. The WHATNOT meeting 2 weeks from now is my target to discuss this, and hopefully approve the algorithms, if not the exact language. |
The whole snapshot thing seems super complex and probably surprising for web-authors. Given that Note: The current default behavior doesn't seem interoperable, where Chrome actually uses the updated |
I agree it's somewhat confusing, but every time I tried to come up with something more intuitive I failed. In particular, for things that affect the font, Chromium currently re-resolves the font each time one of those things changes. Hence Chrome is currently updating for the lang value (though I would have to look at how invalidation works in that case in the current code). Codifying that is hard because there's no definitive time when the font gets resolved. Maybe "changes in the inherited lang must be applied before the font is next used to render text or metrics" which is essentially the direction behavior.
There is no easy way for authors to get the "computed value" for the language of an element. That's Issue #7039 that Anne linked to. In practice , WebKit and Chromium both have the CSS Removing And then if you allow a special initial value, then how do you reset to that initial value? Drop
I just changed Chrome to use inherit-at-creation for |
New version up. Thanks, as always, for the reviews. |
Next round of edits are done. This process will help me a lot when doing my next PR. |
source
Outdated
<li><p>Change the current value to the new value.</p></li> | ||
<li><p>If the value is "<code data-x="dom-context-2d-direction-inherit">inherit</code>", then</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably perform the same checks as in https://whatpr.org/html/10873/dom.html#the-lang-and-xml:lang-attributes so that it's limited to BCP 47 allowed values and the special inherit value (, and maybe ""
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it says it must be valid, but then it says:
If the resulting value is not a recognized language tag, then it must be treated as an unknown language having the given language tag, distinct from all other languages. For the purposes of round-tripping or communicating with other services that expect language tags, user agents should pass unknown language tags through unmodified, and tagged as being BCP 47 language tags, so that subsequent services do not interpret the data as another type of language description. [[BCP47]](https://whatpr.org/html/10873/references.html#refsBCP47)
So maybe say it must be valid but the UA must still pass invalid values through unmodified?
It starts to look a lot better to me (modulo the internal value used by the getter and setter, I guess). I still think that
I'm not sure how relevant it is for the canvas context |
Looking good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks folks. Next version on the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found the final newline to add. Nice work!
One thing I'd like to understand a bit better before merging this is the test situation as currently OP links to too many tests for this change. What tests are specifically covering what is being defined here? (Links to PRs written for this change are fine as well.)
</li> | ||
</ol> | ||
</li> | ||
<li><p>If <var>language</var> is the empty string, then set <var>language</var> to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline before this list item.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Regarding tests ...
For direction
and lang
values, in wpt/html/canvas/element/text and wpt/html/canvas/offscreen/text
- 2d.text.direction.default.tentative.html
- 2d.text.direction.invalid.html
- 2d.text.direction.valid.tentative.html
- 2d.text.lang.default.tentative.html
For the behavior of direction
in DOM canvas, in wpt/html/canvas/element/manual/text:
- canvas.2d.direction.inherit.canvas.html
- canvas.2d.direction.inherit.disconnected.canvas.html
- canvas.2d.direction.inherit.document.html
- canvas.2d.direction.inherit.dynamic.canvas.html
- canvas.2d.direction.inherit.style.html
For the behavior of lang
in DOM canvas, in wpt/html/canvas/element/manual/text:
- canvas.2d.lang.dynamic.html
- canvas.2d.lang.empty.canvas.tentative.html
- canvas.2d.lang.inherit.canvas.tentative.html
- canvas.2d.lang.inherit.disconnected.canvas.tentative.html
- canvas.2d.lang.inherit.document.disconnected.canvas.tentative.html
- canvas.2d.lang.inherit.document.tentative.html
- canvas.2d.lang.tentative.html
For the behavior of direction
in offscreen canvas and workers, in wpt/html/canvas/offscreen/manual/text:
- canvas.2d.offscreen.direction.html
- canvas.2d.offscreen.transferred.direction.inherit.document.html
- canvas.2d.offscreen.transferred.direction.inherit.html
- canvas.2d.offscreen.worker.direction.html
- canvas.2d.offscreen.worker.direction.inherit.html
For the behavior of lang
in offscreen canvas and workers, in wpt/html/canvas/offscreen/manual/text:
- canvas.2d.offscreen.lang.inherit.tentative.html
- canvas.2d.offscreen.lang.tentative.html
- canvas.2d.offscreen.transferred.lang.inherit.document.tentative.html
- canvas.2d.offscreen.transferred.lang.inherit.tentative.html
- canvas.2d.offscreen.transferred.lang.tentative.html
- canvas.2d.offscreen.worker.lang.inherit.tentative.html
- canvas.2d.offscreen.worker.lang.tentative.html
Note I'll remove the "tentative" once this PR lands. There may also be an issue on Mac with the fonts used for distinguishing languages, which I'll also be addressing in a follow up CL.
And I'll be doing the MDN work in the next week or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Normally there's a WPT PR up to rename tentative tests. (The HTML standard PR template also asks for this.)
For MDN all that's required is that you file an issue which you did.
Thanks for all your patience. I've listed all the tests in the comment above. Does the "Merging is Blocked" "This branch must not contain merge commits." something that's going to cause problems? |
@schenney-chromium thanks! "Merging is Blocked" does not appear for me so I think that's fine. Two more things:
|
Locally on Firefox the tests don't pass, so I need to look at what's going on on WPT. For Safari the tests may be passing due to font choices, such that the references don't work as expected. I'll modify the tests to address that particular issue. I'll remove the tentative too. The ordering of actions was not clear to me. Sorry I didn't understand the pre-requisites for testing before landing. I'll try to get the tests updated today. |
Well that's not quite the order either. A PR should be up that the editor then merges (and can review) together with the specification PR. It's probably okay to do it like this though. |
Ahh, now I understand the testing thing. The issue with the Safari and Firefox passing the WPT appears to be due to different default language choices compared to Chrome and Edge. That is, they use "zh-CN" by default, not "ja". Given the tests all assume "ja" is default and test setting the lang to "zh-CN" the browsers pass by default. The fix is to render two languages in each test or maybe use languages that no browser is likely to consider default. |
Yeah, or duplicate the tests so you have cover both zh-CN and ja. |
…ribute, a=testonly Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870
…estonly Automatic update from web-platform-tests Cleanup Canvas text direction tests Fix various style issues. And add tests for default, valid and invalid values. The tests for valid and default values fail because we never report `inherit`, but report the computed value instead. A spec issue was filed for the round-tripping of `direction` and it was resolved to return "inherit" rather than the computed value. See whatwg/html#10884 and the spec PR at whatwg/html#10873. The code will not be changed to pass these tests until the results of UseCounters have been reviewed to identify how often this change might affect sites. A search of HTTP Archive did not find failure cases, mostly because Firefox already returns "inherit" so sites check for that. Change-Id: I39645acd997786c22d4983f84a9d17c7b976797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6277644 Reviewed-by: Andres Ricardo Perez <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1425228} -- wpt-commits: e0a8cfa0bbb879d889e2ddf8b2b4161feb6a2204 wpt-pr: 50969
…ribute, a=testonly Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870
…estonly Automatic update from web-platform-tests Cleanup Canvas text direction tests Fix various style issues. And add tests for default, valid and invalid values. The tests for valid and default values fail because we never report `inherit`, but report the computed value instead. A spec issue was filed for the round-tripping of `direction` and it was resolved to return "inherit" rather than the computed value. See whatwg/html#10884 and the spec PR at whatwg/html#10873. The code will not be changed to pass these tests until the results of UseCounters have been reviewed to identify how often this change might affect sites. A search of HTTP Archive did not find failure cases, mostly because Firefox already returns "inherit" so sites check for that. Change-Id: I39645acd997786c22d4983f84a9d17c7b976797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6277644 Reviewed-by: Andres Ricardo Perez <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1425228} -- wpt-commits: e0a8cfa0bbb879d889e2ddf8b2b4161feb6a2204 wpt-pr: 50969
…ribute, a=testonly Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <jpgravelchromium.org> Commit-Queue: Stephen Chenney <schenneychromium.org> Cr-Commit-Position: refs/heads/main{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870 UltraBlame original commit: 5e5efe6c3eeefb3e6842b11ecf09c86ed8b0e921
…estonly Automatic update from web-platform-tests Cleanup Canvas text direction tests Fix various style issues. And add tests for default, valid and invalid values. The tests for valid and default values fail because we never report `inherit`, but report the computed value instead. A spec issue was filed for the round-tripping of `direction` and it was resolved to return "inherit" rather than the computed value. See whatwg/html#10884 and the spec PR at whatwg/html#10873. The code will not be changed to pass these tests until the results of UseCounters have been reviewed to identify how often this change might affect sites. A search of HTTP Archive did not find failure cases, mostly because Firefox already returns "inherit" so sites check for that. Change-Id: I39645acd997786c22d4983f84a9d17c7b976797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6277644 Reviewed-by: Andres Ricardo Perez <andresrperezchromium.org> Commit-Queue: Stephen Chenney <schenneychromium.org> Cr-Commit-Position: refs/heads/main{#1425228} -- wpt-commits: e0a8cfa0bbb879d889e2ddf8b2b4161feb6a2204 wpt-pr: 50969 UltraBlame original commit: 95c6e5bb08ff14626bab0ee8d8ffb3bdc502947f
…ribute, a=testonly Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <jpgravelchromium.org> Commit-Queue: Stephen Chenney <schenneychromium.org> Cr-Commit-Position: refs/heads/main{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870 UltraBlame original commit: 5e5efe6c3eeefb3e6842b11ecf09c86ed8b0e921
…estonly Automatic update from web-platform-tests Cleanup Canvas text direction tests Fix various style issues. And add tests for default, valid and invalid values. The tests for valid and default values fail because we never report `inherit`, but report the computed value instead. A spec issue was filed for the round-tripping of `direction` and it was resolved to return "inherit" rather than the computed value. See whatwg/html#10884 and the spec PR at whatwg/html#10873. The code will not be changed to pass these tests until the results of UseCounters have been reviewed to identify how often this change might affect sites. A search of HTTP Archive did not find failure cases, mostly because Firefox already returns "inherit" so sites check for that. Change-Id: I39645acd997786c22d4983f84a9d17c7b976797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6277644 Reviewed-by: Andres Ricardo Perez <andresrperezchromium.org> Commit-Queue: Stephen Chenney <schenneychromium.org> Cr-Commit-Position: refs/heads/main{#1425228} -- wpt-commits: e0a8cfa0bbb879d889e2ddf8b2b4161feb6a2204 wpt-pr: 50969 UltraBlame original commit: 95c6e5bb08ff14626bab0ee8d8ffb3bdc502947f
…ribute, a=testonly Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <jpgravelchromium.org> Commit-Queue: Stephen Chenney <schenneychromium.org> Cr-Commit-Position: refs/heads/main{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870 UltraBlame original commit: 5e5efe6c3eeefb3e6842b11ecf09c86ed8b0e921
…estonly Automatic update from web-platform-tests Cleanup Canvas text direction tests Fix various style issues. And add tests for default, valid and invalid values. The tests for valid and default values fail because we never report `inherit`, but report the computed value instead. A spec issue was filed for the round-tripping of `direction` and it was resolved to return "inherit" rather than the computed value. See whatwg/html#10884 and the spec PR at whatwg/html#10873. The code will not be changed to pass these tests until the results of UseCounters have been reviewed to identify how often this change might affect sites. A search of HTTP Archive did not find failure cases, mostly because Firefox already returns "inherit" so sites check for that. Change-Id: I39645acd997786c22d4983f84a9d17c7b976797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6277644 Reviewed-by: Andres Ricardo Perez <andresrperezchromium.org> Commit-Queue: Stephen Chenney <schenneychromium.org> Cr-Commit-Position: refs/heads/main{#1425228} -- wpt-commits: e0a8cfa0bbb879d889e2ddf8b2b4161feb6a2204 wpt-pr: 50969 UltraBlame original commit: 95c6e5bb08ff14626bab0ee8d8ffb3bdc502947f
Remove the tentative naming for whatwg/html#10873. And make all the tests verify two languages, because browsers differ in which language they consider the default.
Thanks @schenney-chromium! |
…ribute, a=testonly Automatic update from web-platform-tests Implement the Canvas TextStyles lang attribute The HTML canvas textStyle "lang" attribute provides control over the locale when using text features in a canvas. The default is "inherit" that takes the language from the host document element. Other strings are used directly as a locale. Spec PR: whatwg/html#10873 Bug: 385006131 Change-Id: I624c1ddc8bf550d17307affc8aa6a97544cf0c53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150170 Reviewed-by: Jean-Philippe Gravel <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1423150} -- wpt-commits: 5b42b1c845eef3989b4390a0c943099210ee2aad wpt-pr: 50870
…estonly Automatic update from web-platform-tests Cleanup Canvas text direction tests Fix various style issues. And add tests for default, valid and invalid values. The tests for valid and default values fail because we never report `inherit`, but report the computed value instead. A spec issue was filed for the round-tripping of `direction` and it was resolved to return "inherit" rather than the computed value. See whatwg/html#10884 and the spec PR at whatwg/html#10873. The code will not be changed to pass these tests until the results of UseCounters have been reviewed to identify how often this change might affect sites. A search of HTTP Archive did not find failure cases, mostly because Firefox already returns "inherit" so sites check for that. Change-Id: I39645acd997786c22d4983f84a9d17c7b976797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6277644 Reviewed-by: Andres Ricardo Perez <[email protected]> Commit-Queue: Stephen Chenney <[email protected]> Cr-Commit-Position: refs/heads/main@{#1425228} -- wpt-commits: e0a8cfa0bbb879d889e2ddf8b2b4161feb6a2204 wpt-pr: 50969
Automatic update from web-platform-tests Update canvas language tests Remove the tentative naming for whatwg/html#10873. And make all the tests verify two languages, because browsers differ in which language they consider the default. -- wpt-commits: 20365259dffd3f467b695c4ed0d03006fe50ce23 wpt-pr: 51041
Automatic update from web-platform-tests Update canvas language tests Remove the tentative naming for whatwg/html#10873. And make all the tests verify two languages, because browsers differ in which language they consider the default. -- wpt-commits: 20365259dffd3f467b695c4ed0d03006fe50ce23 wpt-pr: 51041
There is no way to localize the fonts used in HTML Canvas text rendering and metrics when using an
OffscreenCanvas
, and there is no information in the spec about how to determine the primary language even for regular 2D canvas (though implementations seem to agree to use the canvas element'slang
attribute and use the default locale from the HTTP header for Offscreen). This proposal adds alang
IDL attribute toCanvasTextDrawingStyles
, which is mixed into bothCanvasRenderingContext2D
andOffscreenCanvasRenderingContext2D
.The changes in this PR define how the language for font resolution should be chosen for canvas contexts and applies the same treatment to the
inherit
value for thedirection
IDL attribute which is currently not well defined.See the discussion in issue #10862.
At least two implementers are interested (and none opposed):
Tests are written and can be reviewed and commented upon at:
https://wpt.fyi/results/html/canvas/element/manual/text?label=master&label=experimental
https://wpt.fyi/results/html/canvas/offscreen/manual/text?label=master&label=experimental
https://wpt.fyi/results/html/canvas/element/text?label=master&label=experimental
https://wpt.fyi/results/html/canvas/offscreen/text?label=master&label=experimental
Implementation bugs are filed:
Corresponding HTML AAM & ARIA in HTML issues & PRs: Not relevant
MDN issue
The top of this comment includes a clear commit message to use.
/acknowledgements.html ( diff )
/canvas.html ( diff )
/dom.html ( diff )
/infrastructure.html ( diff )