Skip to content

Commit 3cdff9b

Browse files
drottsvgeesus
authored andcommitted
Explanations for use cases, other review comments addressed
1 parent 75f2554 commit 3cdff9b

File tree

1 file changed

+58
-15
lines changed

1 file changed

+58
-15
lines changed

css-conditional-5/font-tech-format-explainer.md

+58-15
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,53 @@
88

99
## Introduction
1010

11-
`font-tech()` and `font-format()` are extensions to the CSS Conditional Syntax
12-
which enable declarative syntax to use a different set of style rules depending
13-
on font format support, as well as programmatic feature detection of
11+
`font-tech()` and `font-format()` are extensions to the `@supports` rule CSS
12+
Conditional Syntax. As such they enable declarative syntax for applying a
13+
different set of style rules depending on font format support. When used through
14+
the `CSS.supports()` method, they also enable programmatic feature detection of
1415
capabilities of the font stack. The latter covers a lack of functionality in web
15-
platform APIs, as most JS APIs and DOM functionality can be easily feature
16+
platform APIs because most JS APIs and DOM functionality can be easily feature
1617
detected, but the abilities of the font stack could not be queried in that way
1718
so far.
1819

1920
The proposed syntax was introduced following discussion in [TAG review
2021
#666](https://github.com/w3ctag/design-reviews/issues/666) on a previous syntax
21-
for the `src:` descriptor, and subsequent [resolutions in the CSS
22-
WG](https://github.com/w3c/csswg-drafts/issues/6520#issuecomment-947810568) to
23-
harmonize functionality between the `src:` descriptor parsing, and CSS
22+
for the `src:` descriptor on `@font-face`, and subsequent [resolutions in the
23+
CSS WG](https://github.com/w3c/csswg-drafts/issues/6520#issuecomment-947810568)
24+
to harmonize functionality between the `src:` descriptor parsing, and CSS
2425
Conditional behavior with respect to font feature detection. This had been a
2526
[request of the
2627
TAG](https://github.com/w3ctag/design-reviews/issues/666#issuecomment-901220221)
27-
review.
28+
review. The syntax between the `src:` line and the `font-*()` conditional
29+
functions differs insofar as in the `src:` descriptor it is clear that the
30+
context is font-related, so the `font-` prefix is dropped, compare `font-tech()`
31+
vs `tech()`, and `font-format()` vs. `format()`. But the single keyword
32+
arguments to these functions are kept in sync between the two specifications.
33+
34+
The intention of such a syntax and feature detection is to be able to determine
35+
whether a UA supports the different technologies that may be required by a
36+
specific font file.
37+
38+
From a mime type and file signature point of view [OpenType font
39+
files](https://docs.microsoft.com/en-us/typography/opentype/spec/otff#table-directory)
40+
all appear the same. However, because the OpenType font file is a container
41+
format, such a font file can make use a number of different font technologies
42+
that have evolved over the years (
43+
[history](https://github.com/w3c/csswg-drafts/blob/main/css-fonts-4/src-explainer.md#history-of-font-technologies).
44+
So the file signature or mime type for font files is not sufficient to identify
45+
whether a UA's font stack would support it. Instead it is necessary to
46+
distinguish what text layout (OpenType, AAT, Graphite) or rasterisation
47+
technologies (TrueType contours, variations, bitmap color font formats, vector
48+
color font formats etc.) are used by the respective font file.
2849

2950
## Use cases
3051

31-
Background: The use cases listed below for are very similar to the `tech()` and
52+
Background: The use cases listed below are very similar to the `tech()` and
3253
`format()` extensions to parsing the `src:` line of the `@font-face`
3354
declaration, [see
3455
here](https://github.com/w3c/csswg-drafts/blob/main/css-fonts-4/src-explainer.md#use-cases). There,
35-
the focus is on resource loading on the `@font-face` level. Here the focus is
36-
more on more general feature detection outside the `src:` line for progressive
56+
in the src: descriptor, the focus is on resource loading on the `@font-face`
57+
level. Here the focus is more on more general feature detection for progressive
3758
enhancement through style rule or programmatic detection of feature support.
3859

3960
1. I want to progressively enhance my site depending on font format capabilities
@@ -65,6 +86,14 @@ Examples:
6586

6687
### Use Case 1 - Progressive Enhancement with color fonts
6788

89+
By default, use a monochromatic icon font for icons. Only when font support for
90+
colored layers—such as in a COLRv0—font is available, upgrade to a COLRv0 font
91+
with multi-colored glyphs.
92+
93+
Without feature detection, sending a COLRv0 font to to a UA with an incompatible
94+
font stack will lead to unexpected and potentially illegible results. Detecting
95+
the feature allows progressive enhancement.
96+
6897
```
6998
.icons {
7099
font-family: monochromatic_icons;
@@ -77,11 +106,25 @@ Examples:
77106
}
78107
```
79108

109+
80110
### Use Case 2 - Programmatic font support detection
81111

82-
```
83-
let vectorColorFontsAvailable = CSS.supports("font-tech(color-COLRv1)") ||
84-
CSS.supports("font-tech(color-COLRv0)") ||
85-
CSS.supports("font-tech(color-SVG)");
112+
If a page wants to dynamically include additional stylesheets or content, it is
113+
desirable to select those based on font technology support to minimize download
114+
size. For example, if vector color font support and palette support is
115+
available, a stylesheet with palette information plus a vector color font may
116+
be loaded. If palette support is missing the stylesheet containing palette
117+
overrides is not needed.
86118

87119
```
120+
if (CSS.supports("font-tech(palettes)") {
121+
// Load palette styleheet here.
122+
if (CSS.supports("font-tech(color-COLRv1)")) {
123+
// Load COLRv1 font here.
124+
} else if (CSS.supports("font-tech(color-COLRv0)) {
125+
// Load COLRv0 font here.
126+
}
127+
} else {
128+
// Don't include palette override stylesheet, load monochromatic font here.
129+
}
130+
```

0 commit comments

Comments
 (0)