Re: [csswg-drafts] [css-fonts-5] advance-override details (#5983)

I'm [prototyping](https://chromium-review.googlesource.com/c/chromium/src/+/2747538) @fantasai's [proposal](https://github.com/w3c/csswg-drafts/issues/5983#issuecomment-790241213), which is very implementable. And I found one detail that I'd like to discuss regarding whether we break grapheme clusters.

Consider Bengali text `আগুনের শিখা নিভে গিয়েছিল` with `advance-override: 200%`. A strict implementation of the proposal gives the following, where many grapheme clusters (syllables) are broken:

![7C45F5DE-C4ED-4EDB-8CC6-24AFA7FF1973_4_5005_c](https://user-images.githubusercontent.com/19384155/111215978-0c6aa580-8591-11eb-8b9f-45095dd9418f.jpeg)

This is because a grapheme cluster (e.g., `নে`) may be composed of multiple glyphs, each of which has a positive advance. When we add extra spacing to both sides of the glyphs, they got separated.

(Btw the situation seems common in many Indic and related scripts)

---

One thing I like about the proposal is that, it affects the text width (and hence CLS) in a very predictable way: **the result text width is scaled by exactly the given percentage**. So I'd like to do some small tweaks to make the text layout look better, while preserving this property. The result on the previous Bengali text looks like:

![C9C2981F-EACD-42FF-BDF2-2A2F1693E2CE_4_5005_c](https://user-images.githubusercontent.com/19384155/111216209-5d7a9980-8591-11eb-80ff-28a1b771ff5d.jpeg)

(Note that the total text width is exactly the same as before)

The tweak is basically adjusting the total advance of each *grapheme cluster* as a whole, instead of glyphs:
1. For each grapheme cluster, let `advance` be the total advance of its glyphs
2. An extra spacing of `advance * (advance_override - 1) / 2` is applied before the first glyph and after the last glyph of the grapheme cluster, respectively

Similar as before, the adjustment is unconditionally applied to each grapheme cluster after shaping.

This also handles simpler cases like diacritics well, since diacritic glyphs have zero advance:

<img width="483" alt="Screen Shot 2021-03-15 at 2 31 07 PM" src="https://user-images.githubusercontent.com/19384155/111224036-2a3d0800-859b-11eb-99fe-5f43469c497a.png">

Unfortunately, cursive joining of e.g. Arabic may still be broken because each letter is a single grapheme cluster (at least when using Noto Naskh Arabic). This seems unfixable, because after shaping, there's no way to know whether adding spacing between two grapheme clusters breaks cursive joining or not. The situation is the same as when applying `letter-spacing` to Arabic.

<img width="435" alt="Screen Shot 2021-03-15 at 2 32 32 PM" src="https://user-images.githubusercontent.com/19384155/111224185-4e004e00-859b-11eb-9bd4-58817046c012.png">


-- 
GitHub Notification of comment by xiaochengh
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5983#issuecomment-799770586 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 15 March 2021 21:39:38 UTC