Skip to content

[css-fonts-5] Add font-size descriptor to @font-face which allows ranges (for optical sizing) #806

Closed
@robmck-ms

Description

@robmck-ms

The current draft of the Fonts module defines the font-optical-sizing property, which will automatically chooses a variable font instance along the optical size axis for the given text span/block. I propose that this be extended to support automatic optical style switching for static font families as well.

Option 1:
Add a font-size-range property to @font-face rules. This property defines the size range for which this @font-face rule is applicable.

@font-face {
	src: url(http://example.com/fonts/chepman-text.ttf);
	font-family: Chepman;
	opticalfont-size-range: 0pt-18pt;
}
@font-face {
	src: url(http://example.com/fonts/chepman-heading.ttf);
	font-family: Chepman;
	opticalfont-size-range: 18pt-36pt;
}

article {
	font-family: Chepman;
	font-size: 12pt;
}
article h1 {
	font-family: Chepman;
	font-size: 20pt;
}

Option 2:
The above handles web fonts but not locally installed fonts. For local fonts, we can take advantage of the STAT table introduced in the OpenType 1.8 spec. In static fonts, the STAT table provides the same sort of information that an @font-face rule does for web fonts (except src, which is already known). One of the parameters in the STAT table defines a size range for which the given font is applicable (provides the functional equivalent to font-size-range, above).

So, one could simply have the following in CSS:

article {
	font-family: Chepman;
	font-size: 12pt;
}
article h1 {
	font-family: Chepman;
	font-size: 20pt;
}

Browsers that want to support this would have to extend their font selection algorithm to also include PreferredFamilyName (NameID 16 from the name table) as the value for PreferredFamilyName will be exactly the same for all fonts in the font family.

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