Skip to content

Interoperable font metrics via explicit font metrics overrides #4792

Closed
@litherum

Description

@litherum

Migrated from #2228 (comment)

In font files, there exist at least three different ascent/descent values:

  • ascender and descender from the hhea table
  • sTypoAscender and sTypoDescender from the OS/2 table
  • usWinAscent and usWinDescent from the OS/2 table
  • maybe others???

Different browsers / OSes use different values. In fact, some even use values that are not present in the font file at all. This leads to content being laid out differently on different browsers / OSes. #2228 is an example of one. There have been others.

There have been efforts to try to introduce "interoperable" metrics into CSS (#3978 is one, #938 is related, there are a few others too), to force browsers to agree on which metrics they use. Many of the existing proposals so far have some downsides:

  • They require browsers to parse font files, rather than relying on special-purpose font parsing libraries (such as CoreText). A tenet of the web platform is that browsers should be able to delegate responsibility to helper libraries.
  • They cause all text to be laid out differently, across every website in the entire web. Such a massive change is too scary from a product development standpoint.
  • Any approach which is opt-in for specific cases causes text metrics to not match throughout the page. This can lead to inconsistent spacing and poor typography / webpage design.

However, interoperable font metrics are desirable for many page authors. Here's a compromise proposal that (I believe) solves all the above problems:

What if we add a new descriptor into @font-face to let the CSS author override the metrics of the font? Something like this:

@font-face {
    font-family: "WebFont";
    src: ...;
    ascent-override: 80%;
    descent-override: 20%;
}

Those percentage values are resolved by multiplying by the font size (em box). Negative values are illegal. The browser doesn't have to parse any font files, all browsers will agree on the resolved value, and all text in all situations drawn with that font will use these values.

There's already precedent for this: the font-feature-values and font-variation-values descriptors in @font-face overrides the defaults present in the font file.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions