w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.46k stars 657 forks source link

[css-fonts-4] font-kerning:normal and CJK fonts with kerning pairs for fullwidth not well defined #6723

Open macnmm opened 2 years ago

macnmm commented 2 years ago

Normal kerning for CJK fonts that support the ‘kern’ feature should only apply the feature on proportional glyphs. By default this means excluding the fullwidth CJK glyphs and only kerning the proportional Latin glyphs. If kerning the CJK fullwidth glyphs you must also apply ‘palt’ (‘vpal’ in vertical) or the kerning amounts will be incorrect. This kerning should be optional and not the default.

xfq commented 2 years ago

Spec URL: https://drafts.csswg.org/css-fonts-4/#font-kerning-prop

svgeesus commented 2 years ago

Regarding optionality and the default: CSS Fonts 4 does not specify that kerning is on by default. The initial value is 'auto':

auto Specifies that kerning is applied at the discretion of the user agent When set to auto, user agents can determine whether to apply kerning or not based on a number of factors: text size, script, or other factors that influence text processing speed.

However it does claim that:

When rendering with OpenType fonts, the [OPENTYPE] specification suggests that kerning be enabled by default.

I don't find that suggestion in the definition of the kern table or the GPOS table and find the opposite in the OpenType overview:

Many features expose optional capabilities that authors and typographers may choose to use at their discretion; for example, small cap forms, or kerning.

So I wonder where that claim came from and whether we should remove it.

Regarding the specifics of kerning and CJK, I wonder if we can expand the mention of "script" quoted above to give the specific details that fixed-width glyphs should not be kerned. I don't find the 'palt' or 'vpal' tables in the OpenType specification, nor in the TrueType specification. Where are they defined?

svgeesus commented 2 years ago

Oh I see they are OpenType features, not tables: 'palt' and 'vpal'

macnmm commented 2 years ago

Agree that 'auto' is currently confusing and those UAs that apply the 'kern' feature when kerning is 'auto' will run into the CJK issue above.

frivoal commented 1 year ago

These messages (in Japanese) are relevant to this discussion:

fantasai commented 1 year ago

Discussing with @MurakamiShinyu, we outlined 5 possible things that an author might want to do:

  1. no kerning
  2. kern non-CJK† only
  3. apply palt/vpal and kern everything
  4. apply palt/vpal and kern non-CJK
  5. apply palt/vpal and kern nothing

Of these 5, the first 3 seem to be clearly needed; the last two, we're not sure. Either way, the spec should clarify that kerning CJK requires applying palt/vpal as well.

A question raised was whether palt/vpal should be applied via font-variant-east-asian where we already have the somewhat-related proportional-width keyword. But font-variant is fundamentally about alternate glyphs whereas palt/vpal is about spacing, so font-kerning is probably a better place to control it.

Possible syntax for these options:

  1. font-kerning: none
  2. font-kerning: normal
  3. font-kerning: all (new keyword)
  4. Unclear if we need this (not easy to work around if needed)
  5. Unclear if we need this (can use font-feature-settings if needed‡)

It might be useful to hear from @macnmm and others if options 4 or 5 are needed.

† The appropriate division here is probably East Asian Wide vs others. ‡ The naive way to do this would be font-kerning: none; font-feature-settings: "palt", but this doesn't handle writing modes correctly, so the correct way to do it would be font-kerning: all; font-feature-settings: "kern" off, "vkrn" off.

macnmm commented 1 year ago

I don't think option 4 is common. Option 5 is common only because most CJK fonts lack kerning pairs so palt/vpal is their only option for proportional layout and they may have documents that do not set kerning on or have it set to 0. However, option 5 would also turn off kerning for non-CJK, so perhaps it is not common because of that.

MurakamiShinyu commented 1 year ago

I tweeted about extending the font-kerning property values for CJK proportional spacing and kerning,

and got many supportive reactions for the new value all (= 3. apply palt/vpal and kern everything).

Options 4 and 5 do not appear to be needed. I got a reply about it:

For "loose kerning" purpose, it will be better to use letter-spacing together with font-kerning: all, e.g.:

.loose-kerning {
  font-kerning: all; /* 'palt' on, 'kern' on */
  letter-spacing: 0.05em;
}
kojiishi commented 1 year ago

How about sending this issue to OpenType, so that they can improve the definition?

Given existing fonts are incompatible today, they can improve the definition so that future fonts being more compatible. They could also define features that can make both types of fonts happy, and CSS can define a property to control the features.

With the current shaping engine APIs, it's not easy for browsers to apply features only if glyphs are fullwidth. Resolving this issue by the cooperation with OpenType and shaping engines can also ensure browsers match the native applications.

/cc @litherum @jfkthame

macnmm commented 1 year ago

How about sending this issue to OpenType, so that they can improve the definition?

Given existing fonts are incompatible today, they can improve the definition so that future fonts being more compatible. They could also define features that can make both types of fonts happy, and CSS can define a property to control the features.

With the current shaping engine APIs, it's not easy for browsers to apply features only if glyphs are fullwidth. Resolving this issue by the cooperation with OpenType and shaping engines can also ensure browsers match the native applications.

/cc @litherum @jfkthame

I am not aware of font incompatibilities -- when the font has 'kern' values set on fullwidth glyphs, they must necessarily start from the 'palt' widths, otherwise they would have too many pairs and not achieve proportional typography, which is the point of kerning.

As far as when to apply proportional features, this is kind of the legacy of CJK fonts mixing proportional Latin with monospaced CJK in one font by default, but offering non-default widths and kerning as an option. Not sure a new OTF feature would solve this differently...

MurakamiShinyu commented 1 year ago

@kojiishi:

With the current shaping engine APIs, it's not easy for browsers to apply features only if glyphs are fullwidth.

Does this mean that it is difficult to not apply 'kern' only if glyphs are fullwidth?

In @fantasai's suggestion, “2. kern non-CJK† only” does not require checking if glyphs are really fullwidth, because “† The appropriate division here is probably East Asian Wide vs others.”

This better default font-kerning behavior “kern non-CJK only” is already implemented in Firefox (effective when font-kerning: auto. Their font-kerning: normal corresponds to font-kerning: all in the new proposal here).

I think this default “kern non-CJK only” is very nice for most CJK fonts. However, this may be not good for some not very common CJK fonts which have proportional CJK glyphs by default (not by 'palt') and have kerning feature. I am not aware of such Japanese fonts, but it would be possible. (MS PGothic and MS PMincho are well known examples of Japanese proportional fonts, but they have no kerning feature.)

On Korean font kerning, Requirements for Hangul Text Layout and Typography - §2.4 Kerning for Hangul Fonts is very interesting.

AG Ahnsangsoo 2012 is a proportional Hangul font family with kerning feature.

Kerning should be enabled for CJK text by default for such fonts. So I think the normal font-kerning behavior should be corrected to:

Is this difficult to implement?

kojiishi commented 1 year ago

There is a long Japanese thread at public-i18n-japanese, still without consensus.

I replied to @MurakamiShinyu's questions above in the Japanese thread.

macnmm commented 1 year ago

I wrote up an issue to make a tiny edit to the OTF docs for 'kern' and 'palt' so we will see what the response is.