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
//! Windows per-codepoint font discovery via font-kit walk.
//!
//! On Linux we get this via fontconfig's `FcFontSort` + `FcCharSet`
//! (a single C call returns sorted candidates). On Windows there's no
//! equivalent in our dep tree — `IDWriteFontFallback::MapCharacters`
//! would be the moral twin but lives in the `windows` / `dwrote` crates,
//! neither of which Debian ships, so we'd violate the workspace's
//! Debian-only constraint.
//!
//! The fallback approach here: ask font-kit for every installed font,
//! then mmap each and probe its CMAP for the codepoint via ttf-parser.
//! Slower per cold lookup than DirectWrite (we touch every font file
//! once until we hit a match), but cached at the font-cache layer so
//! the cost amortizes to zero after the first hit per codepoint per
//! session. doesn't ship Windows discovery yet either, so this
//! still puts us ahead.
//!
//! Future replacement path: when either `windows` or `dwrote` lands in
//! Debian, swap the body of `discover_fallback` for a single
//! `IDWriteFontFallback::MapCharacters` call and delete the walk.
use PathBuf;
use OnceLock;
use Handle;
use SystemSource;
use Mmap;
/// Cached list of every installed font path + collection index.
/// Built once on first miss; subsequent misses iterate in-memory only.
/// `Vec<(PathBuf, u32)>` rather than `Vec<Handle>` so we don't hold
/// onto font-kit's Memory variant (would defeat the lazy mmap).
static SYSTEM_FONTS: = new;
/// Find a font file installed on the system that contains `ch`.
///
/// The signature mirrors `font/linux.rs::discover_fallback` so the
/// cross-platform call site in `FontLibrary::resolve_font_for_char`
/// stays platform-uniform. Style hints are accepted but ignored on
/// this path — picking the right weight/italic among multiple matches
/// would require reading each candidate's `OS/2` table, and the
/// payoff is small for fallback glyphs (CJK, emoji, symbols are
/// usually single-weight families anyway).
/// `true` if the font at `(path, face_index)` declares a glyph for
/// `ch`. mmap + parse + CMAP lookup; fast in practice (< 1 ms per
/// font) because ttf-parser only walks the table directory and the
/// CMAP, not the full font.