euv-core 0.48.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
use super::*;

/// Metadata describing the active native or deterministic font rasterization provider.
#[derive(Clone, Debug, Eq, Getter, New, PartialEq)]
pub struct SystemFontInfo {
    /// Active font backend discriminant.
    #[get(type(copy))]
    pub(crate) backend: FontRenderBackend,
    /// Resolved human-readable system font family name.
    pub(crate) family_name: String,
    /// Whether full Unicode / CJK glyph shaping is supported.
    #[get(type(copy))]
    pub(crate) supports_unicode: bool,
    /// Whether smooth subpixel/alpha anti-aliasing is enabled.
    #[get(type(copy))]
    pub(crate) supports_antialiasing: bool,
}

/// Cross-platform native system font provider backed by direct OS font APIs.
#[derive(Clone, Debug, Getter)]
pub struct NativeSystemFont {
    /// Probed system font capability descriptor.
    pub(crate) info: SystemFontInfo,
    /// When `true`, bypasses OS font engines for bit-identical deterministic output.
    #[get(type(copy))]
    pub(crate) deterministic_only: bool,
}

/// Shelf-packed alpha8/RGBA8 glyph texture atlas ready for GPU texture upload.
#[derive(Clone, Debug, Getter, New)]
pub struct PackedGlyphAtlas {
    /// Texture width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Texture height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Packed RGBA8 pixel data (white RGB with glyph alpha coverage).
    pub(crate) pixels: Vec<u8>,
    /// Atlas UV rectangles `(x, y, w, h)` per cached `GlyphKey`.
    pub(crate) regions: HashMap<GlyphKey, (u32, u32, u32, u32)>,
    /// Revision number matching the source `GlyphAtlas`.
    #[get(type(copy))]
    pub(crate) revision: u64,
}

/// Packed placement of one rasterized glyph inside a batched Web strip canvas surface.
#[derive(Clone, Copy, Debug, Default, Eq, Getter, New, PartialEq)]
pub struct GlyphStripPlacement {
    /// Quantized glyph key placed at `(x, y)`.
    #[get(type(copy))]
    pub(crate) key: GlyphKey,
    /// Horizontal pixel offset inside the strip surface.
    #[get(type(copy))]
    pub(crate) x: u32,
    /// Vertical pixel offset inside the strip surface.
    #[get(type(copy))]
    pub(crate) y: u32,
    /// Glyph cell width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Glyph cell height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Horizontal advance in pixels.
    #[get(type(copy))]
    pub(crate) advance: u32,
}

/// Batched strip layout and readback telemetry produced for Web missing-glyph rasterization.
#[derive(Clone, Debug, Default, Eq, Getter, New, PartialEq)]
pub struct WebGlyphStripBatch {
    /// Tight packed strip surface width in pixels.
    #[get(type(copy))]
    pub(crate) strip_width: u32,
    /// Tight packed strip surface height in pixels.
    #[get(type(copy))]
    pub(crate) strip_height: u32,
    /// Per-glyph strip rectangles aligned with the input batch.
    pub(crate) placements: Vec<GlyphStripPlacement>,
    /// Number of `getImageData` readbacks executed (`0` for direct WebGL2/WebGPU canvas upload, `<= 1` for software fallback).
    #[get(type(copy))]
    pub(crate) readbacks_performed: u32,
}

/// Bounded pre-cached CSS `font` string table eliminating per-glyph `format!` allocations on Web.
#[derive(Clone, Debug, Default, Getter)]
pub struct WebCssFontCache {
    /// Cached `(style_sig, css_font_decl)` entries bounded by `WEB_FONT_CSS_CACHE_MAX`.
    #[get(skip)]
    pub(crate) entries: Vec<(u32, String)>,
    /// Clock eviction cursor cycling through `entries` once full.
    #[get(skip)]
    pub(crate) evict_cursor: usize,
    /// Cumulative CSS cache hits served without formatting.
    #[get(type(copy))]
    pub(crate) hits: u64,
    /// Cumulative CSS cache misses requiring string construction.
    #[get(type(copy))]
    pub(crate) misses: u64,
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct CtRange {
    pub(crate) location: isize,
    pub(crate) length: isize,
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct CtPoint {
    pub(crate) x: f64,
    pub(crate) y: f64,
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct CtSize {
    pub(crate) width: f64,
    pub(crate) height: f64,
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct CtRect {
    pub(crate) origin: CtPoint,
    pub(crate) size: CtSize,
}

/// Cached Apple CoreText `CTFontRef` handle paired with pre-queried vertical metrics, Clock-LRU bit, and lazy cascaded fallbacks.
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[derive(Clone, Copy)]
pub(crate) struct CoreTextFontCacheEntry {
    /// Packed `(size_tenths | bold<<16 | monospace<<17 | italic<<18)` style signature (`0` when empty).
    pub(crate) style_sig: u32,
    /// Second-chance Clock-LRU reference bit stamped on every cache hit.
    pub(crate) referenced: bool,
    /// Retained CoreText `CTFontRef` handle released on eviction or thread exit.
    pub(crate) font: *mut c_void,
    /// Pre-queried clamped typographic ascent in points.
    pub(crate) ascent: f64,
    /// Pre-queried clamped typographic descent in points.
    pub(crate) descent: f64,
    /// Lazily populated cascaded fallback `CTFontRef` slots (e.g. CJK / symbol fonts), null until a glyph misses `font`.
    pub(crate) fallback_fonts: [*mut c_void; CORETEXT_FALLBACK_SLOTS],
}

/// Thread-local fixed O(1) Clock-LRU cache of Apple CoreText `CTFontRef` handles, singleton grayscale `CGColorSpaceRef`, and persistent bitmap context.
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) struct CoreTextFontCache {
    /// Singleton device-gray `CGColorSpaceRef` reused across all glyph rasterizations on this thread.
    pub(crate) gray_space: *mut c_void,
    /// Persistent scratch `CGBitmapContextRef` backed by `scratch_buf`, eliminating per-glyph context creation FFI calls.
    pub(crate) scratch_ctx: *mut c_void,
    /// Backing alpha8 pixel storage for `scratch_ctx`.
    pub(crate) scratch_buf: Vec<u8>,
    /// Current pixel width of `scratch_ctx`.
    pub(crate) scratch_w: usize,
    /// Current pixel height of `scratch_ctx`.
    pub(crate) scratch_h: usize,
    /// Number of occupied slots in `slots` (`0..=CORETEXT_FONT_CACHE_SLOTS`).
    pub(crate) count: usize,
    /// Clock-LRU hand sweeping `slots` for O(1) amortized eviction without `Vec::remove(0)` shifts.
    pub(crate) clock_hand: usize,
    /// Open-addressed 64-entry direct index mapping `hash(style_sig) & 63` to slot index (`CORETEXT_INDEX_EMPTY` when vacant).
    pub(crate) index: [u8; CORETEXT_FONT_INDEX_CAP],
    /// Fixed stack-inline table of cached base `CTFontRef` handles (`CORETEXT_FONT_CACHE_SLOTS`).
    pub(crate) slots: [CoreTextFontCacheEntry; CORETEXT_FONT_CACHE_SLOTS],
}

/// Standard 128-bit Windows COM `GUID` structure for lazy `DWriteCreateFactory` binding.
#[cfg(target_os = "windows")]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct WinGuid {
    pub(crate) data1: u32,
    pub(crate) data2: u16,
    pub(crate) data3: u16,
    pub(crate) data4: [u8; 8],
}

/// Process-wide lazily loaded Windows DirectWrite (`dwrite.dll`) entry point handle.
#[cfg(target_os = "windows")]
#[derive(Clone, Copy)]
pub(crate) struct DirectWriteLib {
    /// Resolved `DWriteCreateFactory` function pointer.
    pub(crate) create_factory: WinDWriteCreateFactoryFn,
}

/// Cached Windows Win32 `HFONT` handle paired with pre-queried font metrics and Clock-LRU reference bit.
#[cfg(target_os = "windows")]
#[derive(Clone, Copy)]
pub(crate) struct Win32FontCacheEntry {
    /// Packed `(size_px | bold<<16 | italic<<17 | face_kind<<18)` style signature (`0` when empty).
    pub(crate) style_sig: u32,
    /// Second-chance Clock-LRU reference bit stamped on every cache hit.
    pub(crate) referenced: bool,
    /// Retained Win32 `HFONT` handle deleted on eviction or thread exit.
    pub(crate) hfont: *mut c_void,
    /// Pre-queried clamped typographic ascent in pixels.
    pub(crate) ascent: i32,
    /// Pre-queried clamped typographic descent in pixels.
    pub(crate) descent: i32,
}

/// Thread-local fixed O(1) Clock-LRU cache of Windows Win32 memory `HDC`, `HFONT` handles, lazy `IDWriteFactory`, and outline scratch storage.
#[cfg(target_os = "windows")]
pub(crate) struct Win32FontCache {
    /// Persistent compatible memory device context reused across glyph misses.
    pub(crate) hdc: *mut c_void,
    /// Whether lazy DirectWrite factory initialization has been attempted on first glyph miss.
    pub(crate) dwrite_attempted: bool,
    /// Lazily initialized COM `IDWriteFactory` interface pointer released via `IUnknown::Release` on `Drop`.
    pub(crate) dwrite_factory: *mut c_void,
    /// Number of occupied slots in `slots` (`0..=WIN32_FONT_CACHE_SLOTS`).
    pub(crate) count: usize,
    /// Clock-LRU hand sweeping `slots` for O(1) amortized eviction without `Vec::remove(0)` shifts.
    pub(crate) clock_hand: usize,
    /// Open-addressed 64-entry direct index mapping `hash(style_sig) & 63` to slot index (`WIN32_INDEX_EMPTY` when vacant).
    pub(crate) index: [u8; WIN32_FONT_INDEX_CAP],
    /// Fixed stack-inline table of cached `HFONT` handles (`WIN32_FONT_CACHE_SLOTS`).
    pub(crate) slots: [Win32FontCacheEntry; WIN32_FONT_CACHE_SLOTS],
    /// Reusable `GetGlyphOutlineW` byte scratch buffer eliminating per-glyph allocations.
    pub(crate) raw_buf: Vec<u8>,
}

#[cfg(target_os = "windows")]
#[repr(C)]
#[derive(Clone, Copy, Default)]
pub(crate) struct WinFixed {
    pub(crate) fract: u16,
    pub(crate) value: i16,
}

#[cfg(target_os = "windows")]
#[repr(C)]
#[derive(Clone, Copy, Default)]
pub(crate) struct WinMat2 {
    pub(crate) em11: WinFixed,
    pub(crate) em12: WinFixed,
    pub(crate) em21: WinFixed,
    pub(crate) em22: WinFixed,
}

#[cfg(target_os = "windows")]
#[repr(C)]
#[derive(Clone, Copy, Default)]
pub(crate) struct WinGlyphMetrics {
    pub(crate) black_box_x: u32,
    pub(crate) black_box_y: u32,
    pub(crate) glyph_origin_x: i32,
    pub(crate) glyph_origin_y: i32,
    pub(crate) cell_inc_x: i16,
    pub(crate) cell_inc_y: i16,
}

#[cfg(target_os = "windows")]
#[repr(C)]
#[derive(Clone, Copy, Default)]
pub(crate) struct WinTextMetricW {
    pub(crate) tm_height: i32,
    pub(crate) tm_ascent: i32,
    pub(crate) tm_descent: i32,
    pub(crate) tm_internal_leading: i32,
    pub(crate) tm_external_leading: i32,
    pub(crate) tm_ave_char_width: i32,
    pub(crate) tm_max_char_width: i32,
    pub(crate) tm_weight: i32,
    pub(crate) tm_overhang: i32,
    pub(crate) tm_digitized_aspect_x: i32,
    pub(crate) tm_digitized_aspect_y: i32,
    pub(crate) tm_first_char: u16,
    pub(crate) tm_last_char: u16,
    pub(crate) tm_default_char: u16,
    pub(crate) tm_break_char: u16,
    pub(crate) tm_italic: u8,
    pub(crate) tm_underlined: u8,
    pub(crate) tm_struck_out: u8,
    pub(crate) tm_pitch_and_family: u8,
    pub(crate) tm_char_set: u8,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtBitmap {
    pub(crate) rows: u32,
    pub(crate) width: u32,
    pub(crate) pitch: i32,
    pub(crate) buffer: *const u8,
    pub(crate) num_grays: u16,
    pub(crate) pixel_mode: u8,
    pub(crate) palette_mode: u8,
    pub(crate) palette: *mut c_void,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtVector {
    pub(crate) x: isize,
    pub(crate) y: isize,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtGeneric {
    pub(crate) data: *mut c_void,
    pub(crate) finalizer: *mut c_void,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtBBox {
    pub(crate) x_min: isize,
    pub(crate) y_min: isize,
    pub(crate) x_max: isize,
    pub(crate) y_max: isize,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtGlyphMetrics {
    pub(crate) width: isize,
    pub(crate) height: isize,
    pub(crate) hori_bearing_x: isize,
    pub(crate) hori_bearing_y: isize,
    pub(crate) hori_advance: isize,
    pub(crate) vert_bearing_x: isize,
    pub(crate) vert_bearing_y: isize,
    pub(crate) vert_advance: isize,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtSizeMetrics {
    pub(crate) x_ppem: u16,
    pub(crate) y_ppem: u16,
    pub(crate) x_scale: isize,
    pub(crate) y_scale: isize,
    pub(crate) ascender: isize,
    pub(crate) descender: isize,
    pub(crate) height: isize,
    pub(crate) max_advance: isize,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtSizeRec {
    pub(crate) face: *mut c_void,
    pub(crate) generic: FtGeneric,
    pub(crate) metrics: FtSizeMetrics,
    pub(crate) internal: *mut c_void,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtGlyphSlotRec {
    pub(crate) library: *mut c_void,
    pub(crate) face: *mut c_void,
    pub(crate) next: *mut c_void,
    pub(crate) glyph_index: u32,
    pub(crate) generic: FtGeneric,
    pub(crate) metrics: FtGlyphMetrics,
    pub(crate) linear_hori_advance: isize,
    pub(crate) linear_vert_advance: isize,
    pub(crate) advance: FtVector,
    pub(crate) format: u32,
    pub(crate) bitmap: FtBitmap,
    pub(crate) bitmap_left: i32,
    pub(crate) bitmap_top: i32,
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[repr(C)]
#[derive(Clone, Copy)]
pub(crate) struct FtFaceRec {
    pub(crate) num_faces: isize,
    pub(crate) face_index: isize,
    pub(crate) face_flags: isize,
    pub(crate) style_flags: isize,
    pub(crate) num_glyphs: isize,
    pub(crate) family_name: *const c_char,
    pub(crate) style_name: *const c_char,
    pub(crate) num_fixed_sizes: i32,
    pub(crate) available_sizes: *mut c_void,
    pub(crate) num_charmaps: i32,
    pub(crate) charmaps: *mut c_void,
    pub(crate) generic: FtGeneric,
    pub(crate) bbox: FtBBox,
    pub(crate) units_per_em: u16,
    pub(crate) ascender: i16,
    pub(crate) descender: i16,
    pub(crate) height: i16,
    pub(crate) max_advance_width: i16,
    pub(crate) max_advance_height: i16,
    pub(crate) underline_position: i16,
    pub(crate) underline_thickness: i16,
    pub(crate) glyph: *const FtGlyphSlotRec,
    pub(crate) size: *const FtSizeRec,
}

/// Process-wide single persistent `OnceLock` FreeType 2 library symbol table eliminating double-`dlopen`.
#[cfg(any(target_os = "linux", target_os = "android"))]
#[derive(Clone, Copy)]
pub(crate) struct FreeTypeLib {
    /// Non-zero `dlopen` handle address retained for process lifetime.
    pub(crate) handle_addr: usize,
    /// Resolved `FT_Init_FreeType` function pointer.
    pub(crate) init: FtInitFreeTypeFn,
    /// Resolved `FT_Done_FreeType` function pointer.
    pub(crate) done: FtDoneFreeTypeFn,
    /// Resolved `FT_New_Face` function pointer.
    pub(crate) new_face: FtNewFaceFn,
    /// Optional resolved `FT_Done_Face` function pointer for clean face release on `Drop`.
    pub(crate) done_face: Option<FtDoneFaceFn>,
    /// Resolved `FT_Set_Pixel_Sizes` function pointer.
    pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
    /// Resolved `FT_Get_Char_Index` function pointer.
    pub(crate) get_char_index: FtGetCharIndexFn,
    /// Resolved `FT_Load_Glyph` function pointer.
    pub(crate) load_glyph: FtLoadGlyphFn,
}

/// Process-wide single persistent Android NDK `libandroid.so` `AFontMatcher` symbol table (API 29+).
#[cfg(target_os = "android")]
#[derive(Clone, Copy)]
pub(crate) struct AndroidFontMatcherLib {
    /// Non-zero `dlopen` handle address for `libandroid.so`.
    pub(crate) handle_addr: usize,
    /// Resolved `AFontMatcher_create` function pointer.
    pub(crate) create: AFontMatcherCreateFn,
    /// Resolved `AFontMatcher_destroy` function pointer.
    pub(crate) destroy: AFontMatcherDestroyFn,
    /// Resolved `AFontMatcher_setStyle` function pointer.
    pub(crate) set_style: AFontMatcherSetStyleFn,
    /// Resolved `AFontMatcher_match` function pointer.
    pub(crate) match_font: AFontMatcherMatchFn,
    /// Resolved `AFont_getFontFilePath` function pointer.
    pub(crate) font_file_path: AFontGetFilePathFn,
    /// Resolved `AFont_getCollectionIndex` function pointer.
    pub(crate) collection_index: AFontGetCollectionIndexFn,
    /// Resolved `AFont_close` function pointer.
    pub(crate) font_close: AFontCloseFn,
}

/// Cached Android NDK `AFontMatcher`-resolved FreeType fallback face slot keyed by `(path_hash, collection_index)`.
#[cfg(target_os = "android")]
#[derive(Clone, Copy)]
pub(crate) struct FtAndroidFallbackFace {
    /// 64-bit FNV-1a hash of the matched font file path (`0` when empty).
    pub(crate) path_hash: u64,
    /// TTC collection face index returned by `AFont_getCollectionIndex`.
    pub(crate) collection_index: u32,
    /// Second-chance Clock-LRU reference bit.
    pub(crate) referenced: bool,
    /// Opened FreeType face and last applied pixel size.
    pub(crate) slot: FtLazyFace,
}

/// Lazily loaded FreeType face slot tracking probe state and most recently applied pixel size.
#[cfg(any(target_os = "linux", target_os = "android"))]
#[derive(Clone, Copy)]
pub(crate) struct FtLazyFace {
    /// Whether candidate font path probing has already been attempted for this slot.
    pub(crate) probed: bool,
    /// Opened FreeType face pointer, or null when unprobed or unavailable.
    pub(crate) face: *mut FtFaceRec,
    /// Most recently applied pixel size on `face` to skip redundant `FT_Set_Pixel_Sizes` calls.
    pub(crate) last_size_px: u32,
}

/// Per-thread FreeType 2 runtime borrowing the persistent `OnceLock` library and lazily opening faces on demand.
#[cfg(any(target_os = "linux", target_os = "android"))]
pub(crate) struct FreeTypeRuntime {
    /// Initialized `FT_Library` handle retained for on-demand `FT_New_Face` calls.
    pub(crate) library: *mut c_void,
    /// Resolved `FT_Done_FreeType` function pointer invoked on `Drop`.
    pub(crate) done: FtDoneFreeTypeFn,
    /// Resolved `FT_New_Face` function pointer for lazy style and CJK fallback face opening.
    pub(crate) new_face: FtNewFaceFn,
    /// Optional resolved `FT_Done_Face` function pointer invoked on eviction and `Drop`.
    pub(crate) done_face: Option<FtDoneFaceFn>,
    /// Lazily opened primary regular UI sans face (bound on first glyph miss, never on startup).
    pub(crate) regular: FtLazyFace,
    /// Lazily opened bold sans face (opened only on first bold glyph).
    pub(crate) bold: FtLazyFace,
    /// Lazily opened monospace face (opened only on first monospace glyph).
    pub(crate) mono: FtLazyFace,
    /// Lazily opened bold monospace face (opened only on first bold monospace glyph).
    pub(crate) mono_bold: FtLazyFace,
    /// Lazily opened CJK / Unicode fallback face (opened only when primary face misses a codepoint).
    pub(crate) cjk: FtLazyFace,
    /// Resolved `FT_Set_Pixel_Sizes` function pointer.
    pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
    /// Resolved `FT_Get_Char_Index` function pointer.
    pub(crate) get_char_index: FtGetCharIndexFn,
    /// Resolved `FT_Load_Glyph` function pointer.
    pub(crate) load_glyph: FtLoadGlyphFn,
    /// Lazily created Android NDK `AFontMatcher` handle (null on API < 29).
    #[cfg(target_os = "android")]
    pub(crate) matcher: *mut c_void,
    /// Bounded Clock-LRU table of Android `AFontMatcher`-resolved fallback FreeType faces.
    #[cfg(target_os = "android")]
    pub(crate) android_fallbacks: [FtAndroidFallbackFace; ANDROID_FALLBACK_CACHE_SLOTS],
    /// Clock eviction cursor for `android_fallbacks`.
    #[cfg(target_os = "android")]
    pub(crate) android_fallback_hand: usize,
}

/// Thread-local reusable offscreen `<canvas>` surfaces and pre-cached CSS font strings for zero-churn Web glyph rasterization.
#[cfg(target_arch = "wasm32")]
pub(crate) struct WebFontScratch {
    /// Persistent CPU-backed (`willReadFrequently: true`) strip `<canvas>` for `<= 1` readback/frame software fallback.
    pub(crate) readback_canvas: Option<HtmlCanvasElement>,
    /// Cached 2D context bound to `readback_canvas`.
    pub(crate) readback_ctx2d: Option<CanvasRenderingContext2d>,
    /// Current allocated pixel width of `readback_canvas`.
    pub(crate) readback_width: u32,
    /// Current allocated pixel height of `readback_canvas`.
    pub(crate) readback_height: u32,
    /// Most recently applied packed `style_sig` on `readback_ctx2d` (`u32::MAX` when unset).
    pub(crate) readback_last_sig: u32,
    /// Persistent GPU-resident strip `<canvas>` for zero-readback WebGL2 `texSubImage2D` / WebGPU `copyExternalImageToTexture`.
    pub(crate) gpu_canvas: Option<HtmlCanvasElement>,
    /// Cached 2D context bound to `gpu_canvas`.
    pub(crate) gpu_ctx2d: Option<CanvasRenderingContext2d>,
    /// Current allocated pixel width of `gpu_canvas`.
    pub(crate) gpu_width: u32,
    /// Current allocated pixel height of `gpu_canvas`.
    pub(crate) gpu_height: u32,
    /// Most recently applied packed `style_sig` on `gpu_ctx2d` (`u32::MAX` when unset).
    pub(crate) gpu_last_sig: u32,
    /// Pre-cached CSS `font` strings keyed by `style_sig`, eliminating per-glyph `format!` allocations.
    pub(crate) css_cache: WebCssFontCache,
    /// Cumulative `getImageData` readbacks executed on the software fallback path.
    pub(crate) total_readbacks: u64,
    /// Cumulative zero-readback GPU strip batches prepared for WebGL2/WebGPU upload.
    pub(crate) total_gpu_strip_batches: u64,
}