Skip to content

[css-fonts] Improve implementation guidance for font-kerning #7958

Open

Description

@jfkthame

The CSS Fonts spec says that when kerning is enabled (i.e. with font-kerning: normal, or with the initial auto value "at the discretion of the user agent"), the OpenType 'kern' (horizontal) or 'vkrn' (vertical) feature should be applied.

In https://bugzilla.mozilla.org/show_bug.cgi?id=1797431, the reporter points out that the OpenType feature registry says that

If 'kern' is activated, 'palt' must also be activated if it exists.

Similarly, 'vpal' is supposed to be applied along with 'vkrn'.

Current browser engines appear to have overlooked this, and by default apply 'kern' but not 'palt' in the reporter's testcase.

I'd suggest it would be helpful to mention these associated features in the CSS Fonts description of how kerning is implemented when using OpenType fonts.

Activity

  1. jfkthame commented on Oct 27, 2022

    @jfkthame
    ContributorAuthor

    In addition, the reporter in https://bugzilla.mozilla.org/show_bug.cgi?id=1797431 points out that for CJK text, kerning should not be used by default. The testcase at https://tama-san.com/otf_test/ indicates that current browsers (I tried Firefox, Safari and Chrome) all apply kerning by default (i.e. when font-kerning: auto is in effect) to the CJK characters, which is not desired.

    The spec currently leaves the behavior of auto to "the discretion of the user agent". We should note that while the UA may use its "discretion" for content such as Latin (e.g. to optimize performance, as implied by the comments in the spec), for CJK scripts, kerning SHOULD NOT (or MUST NOT?) be applied automatically, but only when explicitly requested by font-kerning: normal.

  2. added
    i18n-trackerGroup bringing to attention of Internationalization, or tracked by i18n but not needing response.
    on Oct 27, 2022
  3. r12a commented on Oct 28, 2022

    @r12a
    Contributor

    Apologies for asking some basic questions. The spec says

    'normal' Specifies that kerning is applied

    So for CJK, does normal mean 'not-normal'? Or does it mean that kerning applies only if the font supports it?

    Is it possible for the browser to kern CJK fonts when no such information is included in the font?

    (Is there a general case here where we need to be more careful about script-specific assumptions before using values like 'normal'?)

  4. jfkthame commented on Oct 28, 2022

    @jfkthame
    ContributorAuthor

    Apologies for asking some basic questions. The spec says

    'normal' Specifies that kerning is applied

    So for CJK, does normal mean 'not-normal'?

    You could say that, yes. (But remember that the initial value of font-kerning is not normal but auto, which gives the browser scope to "do the right thing" automatically as a default.)

    Or does it mean that kerning applies only if the font supports it?

    Well, that's always part of the picture -- yes, a feature like kerning depends on font support. If the font doesn't define any kerning, then the font-kerning property will have no effect.

    Is it possible for the browser to kern CJK fonts when no such information is included in the font?

    In theory (for any font, not just CJK), but I'm not aware of any browser engine that does so. (I believe some desktop publishing software such as InDesign may do things like that.)

    (Is there a general case here where we need to be more careful about script-specific assumptions before using values like 'normal'?)

    Maybe. Though I tend to think of things like font-kerning as being quite script-agnostic. The value normal doesn't directly mean "do what is normal (for any given script or context)", but rather "use what the font designer specified". (Perhaps it should've been named always instead? But then, it wouldn't really mean "always", it'd mean "always, if the font provides it".)

  5. faceless2 commented on Oct 28, 2022

    @faceless2

    Based on the bug report and the "default" output (the first line of text) shown in there after your patch, am I correct that the intention for font-kerning:auto will be:

    • kerning is not applied between two glyphs that are in a CJK script
    • kerning is applied between two glyphs that are latin, regardless of language
    • I'm unclear what happens with neutrals, eg ティ(0)ティ(0)WA - it to me that it shouldn't be applied between the kana but should apply elsewhere? Including between ")" and "テ" for example?
  6. jfkthame commented on Oct 28, 2022

    @jfkthame
    ContributorAuthor

    My mental model is that text is segmented into script runs, with "neutrals" adopting the script of their context. (Some hand-waving about behavior of neutrals at boundaries....) At the point where the font shaping engine performs kerning of a given piece of text, some decision must have been made regarding script, because it is an input to the shaping process. Then it's as simple as letting the font-kerning:auto value behave according to the resolved script of the text run being shaped.

    So in your example, I'd expect the parentheses to be considered part of the Japanese text run, where no kerning is to be applied.

  7. kojiishi commented on Nov 2, 2022

    @kojiishi
    Contributor

    This was once discussed in JLTF, and IIUC we consider this part of the OpenType spec is controversial, may have a negative impact for CJK. I think what we should do is to file an issue to OpenType.

    /cc @kidayasuo @r12a How about discussing this in JLTF again?

  8. kojiishi commented on Nov 17, 2022

    @kojiishi
    Contributor

    I noticed #6723 is about the same topic? I'm sending both to JLTF soon.

  9. ln-north commented on Nov 28, 2022

    @ln-north

    I'm a reporter on Bugzilla#1797431. Thank you for your cooperation.

    I noticed #6723 is about the same topic?

    Seems like it. This isssue seems a bit more specific.

    I'm sending both to JLTF soon.

    If possible, I would like to know a way to catch up on what you discuss (or outline) at JLTF and what you report to Opentype.

  10. kojiishi commented on Nov 28, 2022

    @kojiishi
    Contributor

    If possible, I would like to know a way to catch up on what you discuss (or outline) at JLTF and what you report to Opentype.

    I'll get back to here with the results. This seems complicated.

    • Some font vendors want to apply kern only to glyphs that are not CJK, and glyphs that are CJK but are not fullwidth, even if font-kerning: normal.
    • Some other font vendors want to apply kern to all glyphs.

    Both sides are already shipping fonts based on their assumptions.

  11. ln-north commented on Nov 29, 2022

    @ln-north

    I am a font engineer in font vendor. So I understand the difficulty in changing font files that have already been released.

    It certainly seems to me that we need Opentype's cooperation on the issues you present.
    (For example, meta information such as glyph groups could be added)
    We understand that there is a need to cooperate with the CSS WG and JLTF as well in providing CSS users means to already released fonts, and in using the information on Opentype that has been formulated.

    One of the issues seems to be the ability to specify glyph groups to which the Opentype Feature is applied. If so, I think it would be acceptable to follow the current Opentype behavior as the default behavior.

    I look forward to the results of the discussion in the JLTF.

  12. r12a commented on Nov 29, 2022

    @r12a
    Contributor

    kerning is not applied between two glyphs that are in a CJK script

    It seems to me from reading the above that some font designers do apply kerning to their CJK fonts, and presumably there should be a way for the content author to enable that as a default if the font kerns by default. So turning off any kerning for CJK characters seems a bit draconian. As for where to apply kerning and where not, doesn't that fall out of which font is being used for a range of characters, rather than which characters are being used? If so, perhaps normal (and/or auto?) should perhaps simply apply what the font designer intended. Doesn't that circumvent the issues surrounding when to apply kerning and when not? (Of course, one may want the ability to also turn on non-default kerning, if it's available (although perhaps a new value is needed for font-kerning to do that?), or to turn off kerning, but those seem like straightforward choices.)

    Sorry if i'm barking up the wrong tree.

  13. MurakamiShinyu commented on Feb 4, 2023

    @MurakamiShinyu

    Instead of the 'not-normal' normal, or always, the new keyword all is proposed:

    In this proposal, font-kerning: normal means "kern non-CJK only" and font-kerning: all means "apply palt/vpal and kern everything".

    Perhaps "kern non-CJK only" should be modified for proportional-only CJK fonts.

    Let's continue the discussion in #6723.

  14. ln-north commented on Feb 7, 2023

    @ln-north

    This proposal satisfies all my requirements.
    I will continue to watch that discussion.
    Thank you for your contribution, @MurakamiShinyu.

  15. moved this to Tuesday Internationalization session topics in CSSWG agenda TPAC 2026on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    css-fonts-4Current Worki18n-trackerGroup bringing to attention of Internationalization, or tracked by i18n but not needing response.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions