From eba506c96f8fe9abe96db35818c60fe8b66ef547 Mon Sep 17 00:00:00 2001 From: Stephen Chenney Date: Tue, 17 Dec 2024 22:00:53 -0500 Subject: [PATCH 1/6] Add the lang IDL attribute to CanvasTextDrawingStyles Also clean up what "inherit" means for direction. --- source | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/source b/source index 0553c000382..e03fac401e7 100644 --- a/source +++ b/source @@ -65271,6 +65271,7 @@ interface mixin CanvasPathDrawingStyles { interface mixin CanvasTextDrawingStyles { // text + attribute DOMString lang; // (default: "inherit") attribute DOMString font; // (default 10px sans-serif) attribute CanvasTextAlign textAlign; // (default: "start") attribute CanvasTextBaseline textBaseline; // (default: "alphabetic") @@ -65735,6 +65736,7 @@ context.fillRect(100,0,50,50); // only this square remains data-x="dom-context-2d-shadowOffsetX">shadowOffsetX, shadowOffsetY, shadowBlur, lang, font, textAlign, textBaseline,
Text styles
+
context.lang [ = value ]
+
styles.lang [ = value ]
+
+

Returns the current language setting.

+ +

Can be set, to change the language used when resolving fonts. The syntax and valid values + are the same as those for the lang element attribute. Values + that are not valid are ignored.

+ +

The default is the lang of the canvas element + or the unknown language when there is no canvas element.

+
+
context.font [ = value ]
styles.font [ = value ]
@@ -66407,15 +66422,56 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]); Notice that the font is only loaded inside the worker, and not in the document context.

+

The choice of fonts and glyphs within a font may vary according to the lang + IDL attribute. On setting, lang must be + a valid BCP 47 language tag or the string "inherit". + To determine the used value + for lang, use the following steps:

+ +
    +
  1. If object's lang value is + "inherit", then

    +
      +
    1. If object's font style source object is a canvas + element, then return the element's lang atribute + value.

    2. + +
    3. +

      Otherwise, object's font style source object is an + OffscreenCanvas object:

      + +
        +
      1. Let global be object's relevant global + object.

      2. + +
      3. If global is a Window object, then return the + lang attribute from global's + associated Document.

      4. + +
      5. Otherwise, return a user-agent-defined default lang.

      6. +
      +
    4. +
    +
  2. Otherwise, the used value is the lang + value.

  3. +
+ +

The lang IDL attribute, on getting, must return + the current value.

+

The font IDL attribute, on setting, must be parsed as a CSS <'font'> value (but without supporting property-independent style sheet syntax like 'inherit'), and the resulting font - must be assigned to the context, with the 'line-height' component forced to 'normal', - with the 'font-size' component converted to CSS pixels, - and with system fonts being computed to explicit values. If the new value is syntactically - incorrect (including using property-independent style sheet syntax like 'inherit' or 'initial'), - then it must be ignored, without assigning a new font value. CSS

+ must be assigned to the context, with the primary language set to the used-value for lang, with the 'line-height' + component forced to 'normal', with the 'font-size' component converted to CSS pixels, and with system fonts being computed to explicit values. If the + new value is syntactically incorrect (including using property-independent style sheet syntax + like 'inherit' or 'initial'), then it must be ignored, without assigning a new font value. + CSS

Font family names must be interpreted in the context of the font style source object when the font is to be used; any fonts embedded using

inherit -

Default to the directionality of the canvas element or Document - as appropriate.

+

Use the following process to determine which direction to treat input to the text preparation algorithm

+ +
    +
  1. If object's font style source object is a canvas + element:

    + +
      +
    1. If dir attribute of the element is + auto then use the element's computed value of + 'direction' as the direction.

    2. + +
    3. Otherwise, use the value of the dir attribute of the element + as the direction.

    4. +
    + +
  2. +

    Otherwise, object's font style source object is an + OffscreenCanvas object:

    + +
      +
    1. Let global be object's relevant global + object.

    2. + +
    3. If global is a Window object:

      +
        +
      1. Let Document be the global's + associated Document.

      2. + +
      3. If the value of the dir attribute from + Document is auto then use the + Document's computed value of 'direction' + as the direction.

      4. + +
      5. Otherwise, use the value of the dir attribute from + Document as the direction.

      6. +
      +
    4. + +
    5. Otherwise, treat input to the text preparation algorithm as left-to-right text.

    6. +
    +
  3. +
+

The fontKerning attribute's allowed keywords @@ -146511,6 +146608,7 @@ INSERT INTERFACES HERE Ştefan Vargyas, Stefan Weiss, Steffen Meschkat, + Stephen Chenney, Stephen Ma, Stephen Stewart, Stephen White, From 488b95b63d487a309a726ff6f55c40efa296a4bf Mon Sep 17 00:00:00 2001 From: Stephen Chenney Date: Tue, 17 Dec 2024 22:12:45 -0500 Subject: [PATCH 2/6] Fix Developer info --- source | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source b/source index 37bf63603fe..d03ada738ef 100644 --- a/source +++ b/source @@ -66240,11 +66240,12 @@ transform. ack Shaun Morris. -->

Returns the current language setting.

Can be set, to change the language used when resolving fonts. The syntax and valid values - are the same as those for the lang element attribute. Values - that are not valid are ignored.

+ are the same as those for the lang element attribute, or the + value "inherit".

-

The default is the lang of the canvas element - or the unknown language when there is no canvas element.

+

The default is "inherit", which uses the lang of the + canvas element, or the Document associated with a Worker when there is no + canvas element, or a user-agent default language when neither source exists.

context.font [ = value ]
From 1b5a1df95a0e30abe6d50cddefa5c9935e5121ca Mon Sep 17 00:00:00 2001 From: Stephen Chenney Date: Tue, 21 Jan 2025 22:20:25 -0500 Subject: [PATCH 3/6] Post review revisions --- source | 127 +++++++++++++++++++++++++++------------------------------ 1 file changed, 59 insertions(+), 68 deletions(-) diff --git a/source b/source index 14cc24498f9..3f28bc62cd6 100644 --- a/source +++ b/source @@ -66525,11 +66525,10 @@ transform. ack Shaun Morris. -->

Can be set, to change the language used when resolving fonts. The syntax and valid values are the same as those for the lang element attribute, or the - value "inherit".

+ value "inherit" which is described + below.

-

The default is "inherit", which uses the lang of the - canvas element, or the Document associated with a Worker when there is no - canvas element, or a user-agent default language when neither source exists.

+

The default is "inherit".

context.font [ = value ]
@@ -66538,7 +66537,7 @@ transform. ack Shaun Morris. -->

Returns the current font settings.

Can be set, to change the font. The syntax is the same as for the CSS 'font' - property; values that cannot be parsed as CSS font values are ignored.

+ property; values that cannot be parsed as CSS font values are ignored. The default is "10px sans-serif".

Relative keywords and lengths are computed relative to the font of the canvas element.

@@ -66714,35 +66713,52 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]);
attribute for="CanvasTextDrawingStyles">lang IDL attribute. On setting, lang must be a valid BCP 47 language tag or the string "inherit". - To determine the used value - for lang, use the following steps:

+ To determine the language for the font from + the lang IDL attribute, use the following steps:

  1. If object's lang value is "inherit", then

    1. If object's font style source object is a canvas - element, then return the element's lang atribute - value.

    2. + element, then set the language for the + font to the element's language. The language for the font must be updated when the + rendering context is created and each time the + lang attribute is + set to "inherit" (not on all changes to the element's language).

      + +
    3. Otherwise, if object's font style source object is an + OffscreenCanvas object created via transferControlToOffscreen, + then set the language for the font to + the source canvas element's language. The source + canvas's language should be snapshot at the time of transfer and the value used + whenever the lang value is "inherit".

    4. Otherwise, object's font style source object is an OffscreenCanvas object:

      -
      1. Let global be object's relevant global object.

      2. -
      3. If global is a Window object, then return the - lang attribute from global's - associated Document.

      4. - -
      5. Otherwise, return a user-agent-defined default lang.

      6. +
      7. If global is a Window object, then set the language for the font to the + language from global's + associated Document. + The associated Document's + language should be snapshot when the OffscreenCanvas is + created and the value used whenever the lang + value is "inherit".

      8. + +
      9. Otherwise, the language for the + font is explicitly unknown.

    -
  2. Otherwise, the used value is the lang - value.

  3. +
  4. Otherwise, the language for the font is the lang value.

The lang IDL attribute, on getting, must return @@ -66752,9 +66768,8 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]); data-x="dom-context-2d-font">font IDL attribute, on setting, must be parsed as a CSS <'font'> value (but without supporting property-independent style sheet syntax like 'inherit'), and the resulting font - must be assigned to the context, with the primary language set to the used-value for lang, with the 'line-height' + must be assigned to the context, with the language + for the font as determined above, with the 'line-height' component forced to 'normal', with the 'font-size' component converted to CSS pixels, and with system fonts being computed to explicit values. If the new value is syntactically incorrect (including using property-independent style sheet syntax @@ -66957,53 +66972,50 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]);

Treat input to the text preparation algorithm as right-to-left text.

- -
inherit -

Use the following process to determine which direction to treat input to the text preparation algorithm

+

Use the following process to determine the value for the + inherited direction referred to in the text preparation algorithm

  1. If object's font style source object is a canvas element:

      -
    1. If dir attribute of the element is - auto then use the element's computed value of - 'direction' as the direction.

    2. +
    3. If the element has a computed value for + 'direction' use that as the inherited direction.

    4. -
    5. Otherwise, use the value of the dir attribute of the element - as the direction.

    6. +
    7. Otherwise, use the directionality + of the element as the inherited direction.

  2. Otherwise, object's font style source object is an - OffscreenCanvas object:

    + OffscreenCanvas object, set the + inherited direction when + the OffscreenCanvas is created and use the same value through the + life of the OffscreenCanvas:

      -
    1. Let global be object's relevant global - object.

    2. +
    3. If the OffscreenCanvas was created via transferControlToOffscreen, + then set the inherited direction + to that of source canvas element's as described in the case above.

    4. -
    5. If global is a Window object:

      +
    6. Otherwise, if global is a Window object:

      1. Let Document be the global's associated Document.

      2. -
      3. If the value of the dir attribute from - Document is auto then use the - Document's computed value of 'direction' - as the direction.

      4. - -
      5. Otherwise, use the value of the dir attribute from - Document as the direction.

      6. +
      7. Use the directionality of the + Document as the inherited direction.

    7. -
    8. Otherwise, treat input to the text preparation algorithm as left-to-right text.

    9. +
    10. Otherwise, set the inherited direction to + "ltr".

@@ -67131,32 +67143,11 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]); data-x="dom-context-2d-direction-rtl">rtl"
Let direction be 'rtl'.
- - -
If the target object's font style source object is an - element
- -
Let direction be the directionality of the target object's font style source object.
- -
If the target object's font style source object is a - Document with a non-null document element
- -
Let direction be the directionality of the target - object's font style source object's document element.
- -
Otherwise
- -
Let direction be 'ltr'.
+ data-x="dom-context-2d-direction-inherit">inherit" +
Let direction be the target's inherited direction.
From 152e3a449b7142cf745e503c892bcfc12ac45d89 Mon Sep 17 00:00:00 2001 From: Stephen Chenney Date: Wed, 22 Jan 2025 20:18:49 -0500 Subject: [PATCH 4/6] Clean up offscreen snapshot behavior --- source | 118 +++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 66 deletions(-) diff --git a/source b/source index 3f28bc62cd6..078aed3e121 100644 --- a/source +++ b/source @@ -65339,6 +65339,14 @@ callback BlobCallback = undefined (Blob? blob);
  • Set this canvas element's context mode to placeholder.

  • +
  • Set the inherited language of + offscreenCanvas to the language of this + canvas element.

  • + +
  • Set the inherited direction of + offscreenCanvas to the directionality of this + canvas element.

  • +
  • Return offscreenCanvas.

  • @@ -66722,41 +66730,12 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]);
    1. If object's font style source object is a canvas element, then set the language for the - font to the element's language. The language for the font must be updated when the - rendering context is created and each time the - lang attribute is - set to "inherit" (not on all changes to the element's language).

    2. - -
    3. Otherwise, if object's font style source object is an - OffscreenCanvas object created via transferControlToOffscreen, - then set the language for the font to - the source canvas element's language. The source - canvas's language should be snapshot at the time of transfer and the value used - whenever the lang value is "inherit".

    4. + font to the element's language.

      -
    5. -

      Otherwise, object's font style source object is an - OffscreenCanvas object:

      -
        -
      1. Let global be object's relevant global - object.

      2. - -
      3. If global is a Window object, then set the language for the font to the - language from global's - associated Document. - The associated Document's - language should be snapshot when the OffscreenCanvas is - created and the value used whenever the lang - value is "inherit".

      4. - -
      5. Otherwise, the language for the - font is explicitly unknown.

      6. -
      -
    6. +
    7. Otherwise, object's font style source object is an + OffscreenCanvas object/ Set the + language for the font to the OffscreenCanvas's internal + inherited language.

  • Otherwise, the language for the font is the lang value.

  • @@ -66980,7 +66959,6 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]);
    1. If object's font style source object is a canvas element:

      -
      1. If the element has a computed value for 'direction' use that as the inherited direction.

      2. @@ -66989,35 +66967,12 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]); of the element as the inherited direction.

      -
    2. -

      Otherwise, object's font style source object is an - OffscreenCanvas object, set the - inherited direction when - the OffscreenCanvas is created and use the same value through the - life of the OffscreenCanvas:

      - -
        -
      1. If the OffscreenCanvas was created via transferControlToOffscreen, - then set the inherited direction - to that of source canvas element's as described in the case above.

      2. - -
      3. Otherwise, if global is a Window object:

        -
          -
        1. Let Document be the global's - associated Document.

        2. - -
        3. Use the directionality of the - Document as the inherited direction.

        4. -
        -
      4. - -
      5. Otherwise, set the inherited direction to - "ltr".

      6. -
      -
    3. +
    4. Otherwise, object's font style source object is an + OffscreenCanvas object. Set the inherited direction to the + OffscreenCanvas's internal inherited + direction.

    @@ -71357,6 +71312,11 @@ interface OffscreenCanvas : EventTarget { data-x="dom-OffscreenCanvas-height">height attributes of the OffscreenCanvas object. Initially, all the bitmap's pixels are transparent black.

    +

    An OffscreenCanvas object has an internal inherited language and inherited direction set when + the OffscreenCanvas is created.

    +

    An OffscreenCanvas object can have a rendering context bound to it. Initially, it does not have a bound rendering context. To keep track of whether it has a rendering context or not, and what kind of rendering context it is, an OffscreenCanvas object also @@ -71377,9 +71337,35 @@ interface OffscreenCanvas : EventTarget { array of transparent black pixels of the dimensions specified by width and height; and its width and height attributes initialized to width and - height respectively.

    + height respectively. The inherited + language and inherited direction + internal values must be set as follows:

    -
    +
      +
    1. Let global be the OffscreenCanvas's relevant global + object.

    2. +
    3. If global is a Window object:

      +
        +
      1. Let Document be the global's + associated Document.

      2. + +
      3. Set the inherited language + to the Document's language.

      4. + +
      5. Set the inherited direction + to the Document's directionality.

      6. +
      +
    4. +
    5. Otherwise:

      +
        +
      1. Set the inherited language + to explicitly unknown.

      2. + +
      3. Set the inherited direction + to "ltr".

      4. +
      +
    6. +

    OffscreenCanvas objects are transferable. Their transfer steps, given value and From 60a59711005d2ba6888ef91bb545a7af7d4076c0 Mon Sep 17 00:00:00 2001 From: Stephen Chenney Date: Wed, 22 Jan 2025 20:55:27 -0500 Subject: [PATCH 5/6] Fix the setter/getter for lang. --- source | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/source b/source index 078aed3e121..444a147871e 100644 --- a/source +++ b/source @@ -66717,31 +66717,39 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]); Notice that the font is only loaded inside the worker, and not in the document context.

    -

    The choice of fonts and glyphs within a font may vary according to the lang - IDL attribute. On setting, lang must be - a valid BCP 47 language tag or the string "inherit". - To determine the language for the font from - the lang IDL attribute, use the following steps:

    +

    Objects that implement the CanvasTextDrawingStyles interface have a lang attribute + that controls localization of the font. The lang IDL + attribute, on getting, must return the current value. The lang setter steps are:

      -
    1. If object's lang value is - "inherit", then

      -
        -
      1. If object's font style source object is a canvas - element, then set the language for the - font to the element's language.

      2. - -
      3. Otherwise, object's font style source object is an - OffscreenCanvas object/ Set the - language for the font to the OffscreenCanvas's internal - inherited language.

      4. -
      -
    2. Otherwise, the language for the font is the lang value.

    3. +
    4. Change the current value to the new value.

    5. +
    6. Set the language for the font using the + following steps:

      +
        +
      1. If the value is "inherit", then

        +
          +
        1. If object's font style source object is a canvas + element, then set the language for the + font to the element's language.

        2. + +
        3. Otherwise, object's font style source object is an + OffscreenCanvas object/ Set the + language for the font to the OffscreenCanvas's internal + inherited language.

        4. +
        +
      2. +
      3. Otherwise, the language for the font + is the value.

      4. +
      +
    -

    The lang IDL attribute, on getting, must return - the current value.

    +

    When the object implementing the CanvasTextDrawingStyles interface is created, + the lang attribute must initially have the value + "inherit" and the + language for the font must be set as above.

    The font IDL attribute, on setting, must be Date: Thu, 23 Jan 2025 17:46:19 -0500 Subject: [PATCH 6/6] Next round of edits. --- source | 85 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/source b/source index 444a147871e..44958edf80c 100644 --- a/source +++ b/source @@ -65332,20 +65332,20 @@ callback BlobCallback = undefined (Blob? blob); and height content attributes of this canvas element.

    -
  • Set the placeholder canvas - element of offscreenCanvas to a weak reference to this canvas - element.

  • +
  • Set the offscreenCanvas's placeholder canvas element of + offscreenCanvas to a weak reference to this canvas element.

  • Set this canvas element's context mode to placeholder.

  • -
  • Set the inherited language of - offscreenCanvas to the language of this - canvas element.

  • +
  • Set the offscreenCanvas's inherited language to the language of this canvas element.

  • -
  • Set the inherited direction of - offscreenCanvas to the directionality of this - canvas element.

  • +
  • Set the offscreenCanvas's inherited direction to the directionality of this canvas element.

  • Return offscreenCanvas.

  • @@ -66545,7 +66545,8 @@ transform. ack Shaun Morris. -->

    Returns the current font settings.

    Can be set, to change the font. The syntax is the same as for the CSS 'font' - property; values that cannot be parsed as CSS font values are ignored. The default is "10px sans-serif".

    + property; values that cannot be parsed as CSS font values are ignored. The default is "10px + sans-serif".

    Relative keywords and lengths are computed relative to the font of the canvas element.

    @@ -66719,49 +66720,51 @@ worker.postMessage(offscreenCanvas, [offscreenCanvas]);

    Objects that implement the CanvasTextDrawingStyles interface have a lang attribute - that controls localization of the font. The lang IDL - attribute, on getting, must return the current value. The lang setter steps are:

    + that controls localization of the font. It is used to set the internal font language used when setting the + font attribute.

    + +

    The lang getter steps are to return the current + value.

    + +

    The lang setter steps are:

    1. Change the current value to the new value.

    2. -
    3. Set the language for the font using the - following steps:

      +
    4. If the value is "inherit", then

        -
      1. If the value is "inherit", then

        -
          -
        1. If object's font style source object is a canvas - element, then set the language for the - font to the element's language.

        2. - -
        3. Otherwise, object's font style source object is an - OffscreenCanvas object/ Set the - language for the font to the OffscreenCanvas's internal - inherited language.

        4. -
        -
      2. -
      3. Otherwise, the language for the font - is the value.

      4. +
      5. If object's font style source object is a canvas + element, then set the font + language to the element's language.

      6. + +
      7. Otherwise, object's font style source object is an + OffscreenCanvas object. Set the + font language to the OffscreenCanvas's internal + inherited language.

    5. +
    6. Otherwise, the font + language is the value.

    When the object implementing the CanvasTextDrawingStyles interface is created, the lang attribute must initially have the value "inherit" and the - language for the font must be set as above.

    + font language must be set as + above.

    The font IDL attribute, on setting, must be parsed as a CSS <'font'> value (but without supporting property-independent style sheet syntax like 'inherit'), and the resulting font - must be assigned to the context, with the language - for the font as determined above, with the 'line-height' - component forced to 'normal', with the 'font-size' component converted to CSS pixels, and with system fonts being computed to explicit values. If the - new value is syntactically incorrect (including using property-independent style sheet syntax - like 'inherit' or 'initial'), then it must be ignored, without assigning a new font value. - CSS

    + must be assigned to the context, with the font language as determined above, + with the 'line-height' component forced to 'normal', with the + 'font-size' component converted to CSS pixels, and with + system fonts being computed to explicit values. If the new value is syntactically incorrect + (including using property-independent style sheet syntax like 'inherit' or 'initial'), then it + must be ignored, without assigning a new font value.CSS

    Font family names must be interpreted in the context of the font style source object when the font is to be used; any fonts embedded using OffscreenCanvas : EventTarget {

  • Let Document be the global's associated Document.

  • -
  • Set the inherited language - to the Document's language.

  • +
  • Set the OffscreenCanvas's inherited language to the + Document's language.

  • -
  • Set the inherited direction +

  • Set the OffscreenCanvas's inherited direction to the Document's directionality.