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

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

Open
jfkthame opened this issue Oct 26, 2022 · 13 comments
Open

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

jfkthame opened this issue Oct 26, 2022 · 13 comments
Labels
css-fonts-4 Current Work i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response.

Comments

@jfkthame
Copy link
Contributor

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.

@jfkthame
Copy link
Contributor Author

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.

@svgeesus svgeesus added css-fonts-4 Current Work i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. labels Oct 27, 2022
@r12a
Copy link
Contributor

r12a commented Oct 28, 2022

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'?)

@jfkthame
Copy link
Contributor Author

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".)

@faceless2
Copy link

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?

@jfkthame
Copy link
Contributor Author

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.

@kojiishi
Copy link
Contributor

kojiishi commented Nov 2, 2022

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?

@kojiishi
Copy link
Contributor

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

@ln-north
Copy link

ln-north commented Nov 28, 2022

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.

@kojiishi
Copy link
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.

@ln-north
Copy link

ln-north commented Nov 29, 2022

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.

@r12a
Copy link
Contributor

r12a commented Nov 29, 2022

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.

@MurakamiShinyu
Copy link
Collaborator

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.

@ln-north
Copy link

ln-north commented Feb 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-fonts-4 Current Work i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response.
Projects
None yet
Development

No branches or pull requests

7 participants