Skip to content

[css-fonts] Proposal to expose font metrics #4780

@chriskirknielsen

Description

@chriskirknielsen

Introduction

It would be useful to expose metrics from the font that is being used by the browser.

These values would be normalised across all fonts, and not defined as an additional metadata in font files. This would insure backward compatibility with all fonts.

Use cases

Syntax

I'd like to propose a syntax similar to custom properties or environment variables that would be familiar to most authors:

font(--x-height)
font(--ascender)
font(--descender)
font(--cap-height)
/* etc. */

The double hyphen syntax could be a quoted value instead, such as font("x-height"), but maybe that should be kept for custom ident in font files.

Questions

These metrics are available with tools like Font Inspector, but are they passed along to the browser when it loads in the font? If not, I realise this proposal would not be feasible.

Limitations

I can imagine that the rise of variable fonts also means a single font can have multiple x-heights based on the different parameters, and I am not sure if this should be handled by browsers or authors.

One argument for it to be handled by browsers is that authors cannot predict a font that failed to load (unless using something like Font Face Observer to apply styles conditionally…).

Thanks for your time reading this. Please let me know if this has already been discussed, or if there is any interest in this.

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