Re: [csswg-drafts] [css-inline] text-layout: glyph-bounding-box (#2228)

I finally got around to doing some proper testing. Here's what I believe is the algorithm for extracting ascent, descent and line-gap from OpenType fonts across several browsers:

```java
int ems = post.ems; // 1000, 2048 etc
boolean usetypo = (os2.fsSelector & 128) != 0; // USE_TYPO_METRICS
int ascent; // distance from text-top to baseline; positive
int descent; // distance from text-bottom to baseline; negative
int linegap; // add to ascent and -descent to get default line-height

if (safari_on_mac || chrome_on_mac) {
    ascent = hhea.ascent;
    descent = hhea.descent;
    linegap = hhea.linegap;
} else if (firefox_on_mac || chrome_on_linux) {
    ascent = usetypo ? os2.sTypoAscender : hhea.ascent;
    descent = usetypo ? os2.sTypoDescender: hhea.descent;
    linegap = usetypo ? os2.sTypoLineGap : hhea.linegap;
} else if (firefox_on_linux) {
    ascent = usetypo ? os2.sTypoAscender : hhea.ascent;
    descent = usetypo ? os2.sTypoDescender: hhea.descent;
    linegap = os2.sTypoLineGap;
} else if (chrome_on_windows || firefox_on_windows) {
    ascent = usetypo ? os2.sTypoAscender : os2.usWinAscent;
    descent = usetypo ? os2.sTypoAscender : -os2.usWinDescent;
    linegap = usetypo ? os2.sTypoLineGap : hhea.linegap;
}
if (firefox) {
    if (linegap == 0 && ascent - descent <= ems) {
        linegap = ems * 1.15 - ascent + descent; // line-height always 1.15em
    } else if (ascent - descent < ems) {
        linegap += ems - ascent + descent;
    }
}
```
I'd hoped to show exhaustive working in one place, but the testing got a bit out of hand and there are just too many combinations! Plus some of this I'd already established so didn't need to retest. I didn't test anything really weird (e.g. -ve ascents) and I haven't fully confirmed the firefox "fix up the line-gap" algorithm is the same on all platforms. so there's probably more to this, but I think it's pretty close.

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

Received on Wednesday, 20 May 2020 18:49:14 UTC