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
//! Loading a typeface that arrives at run time.
use Arc;
use ;
/// Decodes a font file and makes its faces available to every shaper in the process, handing back the family name to ask for them by.
///
/// The gap this closes: until now the only way into the font database was [`AppConfig::font_data`](https://docs.rs/telar), which is bytes handed over before the first frame. A face that is downloaded, picked by the user, or shipped in a language pack had nowhere to go — and a caller could not name it in a [`TextStyle`](https://docs.rs/telar) anyway, because the family a file turns out to declare is not something the caller knows.
///
/// So the decoded value *is* the family name:
///
/// ```ignore
/// let faces = AssetLoader::new(transport, Some(cache), Arc::new(FontDecoder));
/// // In a view: the text renders in the platform's font until the face lands, then in the face.
/// match faces.get("Inter").get() {
/// AssetState::Ready(family) => style.with_font_family(family.to_string()),
/// _ => style,
/// }
/// ```
///
/// Loading is additive, like every other way into the database: a shaper already built keeps every face it was built from, so a face arriving late cannot pull one out from under a surface that is drawing.
///
/// A file carrying several faces reports the first family it declares. The rest are loaded and reachable by their own names — this returns one because a caller asking for "the family this file is" wants a name to put in a style, not a set to choose from.
;