forked from WICG/local-font-access
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.bs
446 lines (323 loc) · 18.6 KB
/
index.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<pre class=metadata>
Title: Font Enumeration API
Shortname: FontEnum
Abstract: This specification documents web browser support for allowing users to grant web sites access to the full set of available system fonts for enumeration and use.
Status: DREAM
Editor: Emil A. Eklund, Google Inc. https://google.com, [email protected]
Editor: Alex Russell, Google Inc. https://google.com, [email protected]
Editor: Joshua Bell, Google Inc. https://google.com, [email protected]
Assume Explicit For: yes
Markup Shorthands: markdown yes, css yes
Complain About: accidental-2119 yes, missing-example-ids yes
Favicon: logo-font-enumeration.png
</pre>
<!--
Repository: inexorabletash/font-enumeration
Level: 1
Group: wicg
ED: https://wicg.github.io/font-enumeration
Test Suite: https://github.com/web-platform-tests/wpt/tree/master/font-enumeration
-->
<pre class=anchors>
spec: webidl; urlPrefix: https://heycam.github.io/webidl/
type: dfn
text: asynchronous iterator initialization steps; url: #TBD
text: get the next iteration result; url: #TBD
spec: css-font-loading-3; urlPrefix: https://drafts.csswg.org/css-font-loading
type: dfn
text: CSS-connected; url: #css-connected
</pre>
<style>
/* Default ED/WD stylesheets set "both"; not needed for logo floated right */
div.head h1 { clear: left; }
dl.domintro dt {
font-family: Menlo, Consolas, "DejaVu Sans Mono", Monaco, monospace;
padding-top: 0.5em;
padding-bottom: 1em;
}
dl.domintro dt a {
color: inherit; border-bottom-style: none;
}
dl.domintro dt code {
font-size: inherit;
}
</style>
<img src="logo-font-enumeration.svg" alt="logo"
style="height: 100px; width: 100px; position: absolute; right: 20px; top: 30px;">
<!-- ============================================================ -->
# Introduction # {#introduction}
<!-- ============================================================ -->
This specification describes a font enumeration API for web browsers which may, optionally, allow users to grant access to the full set of available system fonts.
Web developers historically lack anything more than heuristic information about which local fonts are available for use in styling page content. Web developers often include complex lists of `font-family` values in their CSS to control font fallback in a heuristic way. Generating good fallbacks is such a complex task for designers that tools have been built to help "eyeball" likely-available local matches.
Font enumeration helps by enabling:
* Logging of likely-available fonts to improve server-side font rule generation.
* Scripts to generate style rules based on "similar" local fonts, perhaps saving a download.
* Improving styling options for user-generated content, allowing the generation of style rules via more expressive font selection menus.
<!-- ============================================================ -->
# Goals # {#goals}
<!-- ============================================================ -->
The API should:
* Provide efficient enumeration of all local fonts without blocking the main thread
* Be available from Workers
* Allow multiple levels of privacy preservation; e.g., full access for "trusted" sites and degraded access for untrusted scenarios
* Reflect local font access state in the Permissions API
* Restrict access to local font data to Secure Contexts
* Provide unique identification of families and instances (variants like "bold" and "italic"), including PostScript names
* Provide easy identification of variable and colour (COLR, CBDT, sbix) fonts
* Re-use Web Font types and interfaces to the greatest extent possible
<!--
The ability to uniquely identify a specific font in the case of conflicting names (e.g., Web Font aliases vs. local PostScript font names)
-->
<!-- ============================================================ -->
# Examples # {#examples}
<!-- ============================================================ -->
*This section is non-normative.*
<!-- ============================================================ -->
## Enumerating local fonts ## {#example-enumerate-local-fonts}
<!-- ============================================================ -->
The API allows script to enumerate local fonts, including properties about each font.
<aside class=example id=example-async-query>
The following code queries the available local fonts, and logs details about each to the console.
```js
// Asynchronous Query and Iteration
(async () => { // Async block
// May prompt the user:
const status = await navigator.permissions.request({ name: "local-fonts" });
if (status.state != "granted")
throw new Error("Cannot enumerate local fonts");
// This sketch returns individual FontFace instances rather than families:
// In the future, query() could take filters e.g. family name, and/or options
// e.g. locale.
const fontsIterator = navigator.fonts.query();
for await (let face of fontsIterator) {
const metadata = await face.getMetadata();
console.log(f.family); // The given "family" name
// NEW metadata:
console.log(m.instanceName);
console.log(m.postScriptName);
console.log(m.fullName);
console.log(m.isVariable);// TODO: boolean enough?
console.log(m.isColor); // TODO: boolean enough?
// ...
}
})();
```
</aside>
<!-- ============================================================ -->
## Styling with local fonts ## {#example-style-with-local-fonts}
<!-- ============================================================ -->
Advanced creative tools may wish to use CSS to style text using all available local fonts. In this case, getting access to the local font name allows the user to select from a richer set of choices:
<aside class=example id=example-query-build-ui>
The following code populates a drop-down selection form element with the available local fonts, and could be used as part of the user interface for an editing application.
```js
const fontSelect = document.createElement("select");
fontSelect.onchange = e => {
console.log("selected:", fontSelect.value);
// Use the selected font to style something here.
};
document.body.appendChild(fontSelect);
(async () => { // Async block
// May prompt the user:
const status = await navigator.permissions.request({ name: "local-fonts" });
if (status.state != "granted")
throw new Error("Cannot continue to style with local fonts");
// TODO(slightlyoff): is this expressive enough?
for await (const face of navigator.fonts.query() {
await metadata = face.getMetadata();
console.log(f.family);
console.log(metadata.instanceName);
console.log(metadata.postScriptName);
const option = document.createElement("option");
option.text = f.family;
option.value = f.family;
option.setAttribute("postScriptName", f.postScriptName);
fontSelect.append(option);
}
})();
```
</aside>
<!-- ============================================================ -->
# Concepts # {#concepts}
<!-- ============================================================ -->
Issue: Define any new concepts beyond just the API
<!-- ============================================================ -->
# Local font access permission # {#permission}
<!-- ============================================================ -->
Enumeration of local fonts requires a permission to be granted.
The <dfn for=PermissionName enum-value>"`local-fonts`"</dfn> [=/powerful feature=]’s permission-related flags, algorithms, and types are defaulted.
<aside class=example id=example-request-permission>
Permission to enumerate local fonts can be requested using the `navigator.permissions` API:
```js
const status = await navigator.permissions.request({ name: "local-fonts" });
if (status.state === "granted")
console.log("permission was granted 👍");
else
console.log("permission was denied 👎")
```
</aside>
<!-- ============================================================ -->
# API # {#api}
<!-- ============================================================ -->
<!-- ============================================================ -->
## Font manager ## {#font-manager-api}
<!-- ============================================================ -->
<dl class="domintro note">
: for await (const |fontFace| of navigator . fonts . {{FontManager/query()}} { ... }
:: Asynchronously iterate over the available fonts. Each time through the loop, |fontFace| will be a new {{FontFace}} object.
</dl>
<xmp class=idl>
[SecureContext]
interface mixin NavigatorFonts {
[SameObject] readonly attribute FontManager fonts;
};
Navigator includes NavigatorFonts;
WorkerNavigator includes NavigatorFonts;
</xmp>
<div class=algorithm>
Each [=/environment settings object=] has an associated {{FontManager}} object.
The <dfn attribute for=NavigatorFonts>fonts</dfn> attribute's getter must return **this**'s [=/relevant settings object=]'s {{FontManager}} object.
</div>
<xmp class=idl>
[SecureContext,
Exposed=(Window,Worker)]
interface FontManager {
FontFaceIterator query();
};
</xmp>
<div class=algorithm>
The <dfn method for=FontManager>query()</dfn> method, when invoked, must run these steps:
1. Let |promise| be a new promise.
1. If **this**’s [=relevant settings object=]'s [=origin=] is an [=opaque origin=], then reject |promise| with a {{TypeError}}.
1. Otherwise, run these steps [=in parallel=]:
1. Let |permission| be the result of [=requesting permission to use=] {{PermissionName/"local-fonts"}}.
1. If |permission| is not {{PermissionState/"granted"}}, then reject |promise| with a "{{NotAllowedError}}" {{DOMException}}, and abort these steps.
1. Resolve |promise| with a newly created {{FontFaceIterator}}.
1. Return |promise|.
</div>
<xmp class=idl>
[SecureContext,
Exposed=(Window,Worker)]
interface FontFaceIterator {
/*async*/ iterable<FontFace>;
};
</xmp>
All {{FontFaceIterator}} objects contain an internal <dfn attribute for=FontFaceIterator>\[[FontList]]</dfn> slot.
<div class=algorithm>
The [=asynchronous iterator initialization steps=] for {{FontFaceIterator}} are as follows:
1. Set **this**'s {{FontFaceIterator/[[FontList]]}} to a new empty [=/queue=].
1. For each local font |font| on the system, run these steps:
1. Let |font face| be a new {{FontFace}} describing |font|. The |font face| is not [=CSS-connected=].
1. Set |font face|'s {{FontFace/[[FontStatusPromise]]}} slot to a new fulfilled promise.
1. Set |font face|'s {{FontFace/[[Urls]]}} slot to null.
1. Set |font face|'s {{FontFace/[[Data]]}} slot to null.
Issue: Modify the definition of {{FontFace}} to allow {{FontFace/[[Urls]]}} and {{FontFace/[[Data]]}} to both be null.
Issue: Are there further details about the {{FontFace}} objects we need to specify here?
1. [=queue/Enqueue=] |font face| to **this**'s {{FontFaceIterator/[[FontList]]}}.
</div>
Note: User agents are expected to actually populate the iterator's queue asynchronously and possibly lazily, although this is not observable.
<div class=algorithm>
To [=get the next iteration result=] for {{FontFaceIterator}}, run the following steps:
1. Let |promise| be a new promise.
1. If **this**'s {{FontFaceIterator/[[FontList]]}} is [=queue/empty=], then:
1. Resolve |promise| with undefined.
1. Otherwise:
1. Let |font face| be the result of [=queue/dequeuing=] from **this**'s {{FontFaceIterator/[[FontList]]}}.
1. Resolve |promise| with |font face|.
1. Return |promise|.
</div>
<!-- ============================================================ -->
## {{FontFace}} additions ## {#fontface-additions}
<!-- ============================================================ -->
<dl class="domintro note">
: await |metadata| = |fontFace| . {{FontFace/getMetadata()}}
:: Request additional metadata about a {{FontFace}}. The returned object |metadata| contains properties describing |fontFace| in more detail.
This method is only usable for local fonts, and will throw an exception if called for a web font.
</dl>
<xmp class=idl>
[Exposed=(Window,Worker)]
partial interface FontFace {
[SecureContext] Promise<FontFaceMetadata> getMetadata();
};
</xmp>
<div class=algorithm>
The <dfn method for=FontFace>getMetadata()</dfn> method, when invoked, must run these steps:
1. Let |promise| be a new promise.
1. If either of **this**'s {{FontFace/[[Urls]]}} or {{FontFace/[[Data]]}} slots are not null, then reject |promise| with a {{TypeError}}.
1. Otherwise, run these steps [=in parallel=]:
1. Let |permission| be the result of [=requesting permission to use=] {{PermissionName/"local-fonts"}}.
1. If |permission| is not {{PermissionState/"granted"}}, then reject |promise| with a "{{NotAllowedError}}" {{DOMException}}, and abort these steps.
1. Let |metadata| be a newly created {{FontFaceMetadata}} populated with more details about **this**'s font.
1. Resolve |promise| with |metadata|.
1. Return |promise|.
</div>
<xmp class=idl>
dictionary FontFaceMetadata {
USVString instanceName;
USVString postScriptName;
USVString fullName;
boolean isVariable;
boolean isColor;
};
</xmp>
A {{FontFaceMetadata}} provides details about a font face. The descriptions below assume the font is an OpenType [[!OPENTYPE]] font.
The {{FontFaceMetadata/instanceName}} member corresponds to name ID 2 in the font's `name` table (the font subfamily name.) Example: `"Bold"`.
The {{FontFaceMetadata/postScriptName}} member corresponds to name ID 6 in the font's `name` table (the PostScript name.) Example: `"Arial-Bold"`.
The {{FontFaceMetadata/fullName}} member corresponds to name ID 4 in the font's `name` table (the full font name.) Example: `"Arial Bold"`.
<aside class=issue>
Verify source for all of the above. See [Microsoft Typography](https://docs.microsoft.com/en-us/typography/opentype/spec/name)
* Encoding - assume everything has been successfully transcoded to UTF-16 (USVStrings) ?
* Localization - we will provide "en-us"-equivalent labels here - define that behavior.
</aside>
Issue: Include `name` ID 3 (Unique identifier) as well?
The {{FontFaceMetadata/isVariable}} member is true if the font incorporates multiple faces; the presence of a `fvar` table indicates support.
The {{FontFaceMetadata/isColor}} member is true if the font contains multi-colored glyphs; the presence of a `COLR` table indicates support.
Issue: Should user agents that support `SBIX`, `CBDT`, `SVG` etc also set this flag?
<!-- ============================================================ -->
# Internationalization considerations # {#i18n}
<!-- ============================================================ -->
Issue: Document internationalization consideration, e.g. string localization
<!-- ============================================================ -->
## Font Names ## {#i18n-names}
<!-- ============================================================ -->
The `name` table in OpenType [[!OPENTYPE]] fonts allows names (family, subfamily, etc) to have multilingual strings, using either platform-specific numeric language identifiers or language-tag strings conforming to [[BCP47]]. For example, a font could have family name strings defined for both "en" and "zh-Hant-HK".
The {{FontFaceMetadata}} properties {{FontFaceMetadata/instanceName}}, {{FontFaceMetadata/postScriptName}}, and {{FontFaceMetadata/fullName}} are provided by this API simply as strings, using the "en" locale. This matches the behavior of the {{FontFace}} {{FontFace/family}} property.
Web applications that need to provide names in other language can request and parse the `name` table directly using the [Font Table Access API](https://inexorabletash.github.io/font-table-access).
Issue: Should we define an option to the {{FontManager/query()}} method to specify the desired language for strings (e.g. `{lang: 'zh'}`), falling back to "en" if not present?
<!-- ============================================================ -->
# Accessibility considerations # {#a11y}
<!-- ============================================================ -->
There are no known accessibility impacts of this feature.
<!-- ============================================================ -->
# Security considerations # {#security}
<!-- ============================================================ -->
There are no known security impacts of this feature.
<!-- ============================================================ -->
# Privacy considerations # {#privacy}
<!-- ============================================================ -->
<!-- ============================================================ -->
## Fingerprinting ## {#privacy-fingerprinting}
<!-- ============================================================ -->
The font list includes:
* Fonts included in the operating system distribution.
* Fonts installed by particular applications installed on the system, for example office suites.
* Fonts directly installed by the system administrator and/or end user.
This provides several "bits of entropy" to distinguish users.
User agents could mitigate this in certain cases (e.g. when the permission is denied, or in Private Browsing / "incognito" mode) by providing an enumeration of a fixed set of fonts provided with the user agent.
<!-- ============================================================ -->
## Identification ## {#privacy-identification}
<!-- ============================================================ -->
Users from a particular organization could have specific fonts installed. Employees of "Example Co." could all have an "Example Corporate Typeface" installed by their system administrator, which would allow distinguishing users of a site as employees.
There are services which create fonts based on handwriting samples. If these fonts are given names including personally identifiable information (e.g. "Alice's Handwriting Font"), then personally identifiable information would be made available. This may not be apparent to users if the information is included as properties within the font, not just the font name.
<!-- ============================================================ -->
# Acknowledgements # {#acknowledgements}
<!-- ============================================================ -->
We'd like to acknowledge the contributions of:
* Daniel Nishi, Owen Campbell-Moore, and Mike Tsao who helped pioneer the previous local font access proposal.
* Evan Wallace, Biru, Leah Cassidy, Katie Gregorio, Morgan Kennedy, and Noah Levin of Figma who have patiently enumerated the needs of their ambitious web product.
* Tab Atkins, Jr. and the CSS Working Group who have provided usable base-classes which only need slight extension to enable these cases.
Special thanks (again!) to Tab Atkins, Jr. for creating and maintaining [Bikeshed](https://github.com/tabatkins/bikeshed), the specification authoring tool used to create this document.
And thanks to
Chase Phillips,
Dominik Röttsches, and
Igor Kopylov
for suggestions, reviews, and other feedback.