Skip to main content

euv_core/font/system/
struct.rs

1use super::*;
2
3/// Metadata describing the active native or deterministic font rasterization provider.
4#[derive(Clone, Debug, Eq, Getter, New, PartialEq)]
5pub struct SystemFontInfo {
6    /// Active font backend discriminant.
7    #[get(type(copy))]
8    pub(crate) backend: FontRenderBackend,
9    /// Resolved human-readable system font family name.
10    pub(crate) family_name: String,
11    /// Whether full Unicode / CJK glyph shaping is supported.
12    #[get(type(copy))]
13    pub(crate) supports_unicode: bool,
14    /// Whether smooth subpixel/alpha anti-aliasing is enabled.
15    #[get(type(copy))]
16    pub(crate) supports_antialiasing: bool,
17}
18
19/// Cross-platform native system font provider backed by direct OS font APIs.
20#[derive(Clone, Debug, Getter)]
21pub struct NativeSystemFont {
22    /// Probed system font capability descriptor.
23    pub(crate) info: SystemFontInfo,
24    /// When `true`, bypasses OS font engines for bit-identical deterministic output.
25    #[get(type(copy))]
26    pub(crate) deterministic_only: bool,
27}
28
29/// Shelf-packed alpha8/RGBA8 glyph texture atlas ready for GPU texture upload.
30#[derive(Clone, Debug, Getter, New)]
31pub struct PackedGlyphAtlas {
32    /// Texture width in pixels.
33    #[get(type(copy))]
34    pub(crate) width: u32,
35    /// Texture height in pixels.
36    #[get(type(copy))]
37    pub(crate) height: u32,
38    /// Packed RGBA8 pixel data (white RGB with glyph alpha coverage).
39    pub(crate) pixels: Vec<u8>,
40    /// Atlas UV rectangles `(x, y, w, h)` per cached `GlyphKey`.
41    pub(crate) regions: HashMap<GlyphKey, (u32, u32, u32, u32)>,
42    /// Revision number matching the source `GlyphAtlas`.
43    #[get(type(copy))]
44    pub(crate) revision: u64,
45}
46
47/// Packed placement of one rasterized glyph inside a batched Web strip canvas surface.
48#[derive(Clone, Copy, Debug, Default, Eq, Getter, New, PartialEq)]
49pub struct GlyphStripPlacement {
50    /// Quantized glyph key placed at `(x, y)`.
51    #[get(type(copy))]
52    pub(crate) key: GlyphKey,
53    /// Horizontal pixel offset inside the strip surface.
54    #[get(type(copy))]
55    pub(crate) x: u32,
56    /// Vertical pixel offset inside the strip surface.
57    #[get(type(copy))]
58    pub(crate) y: u32,
59    /// Glyph cell width in pixels.
60    #[get(type(copy))]
61    pub(crate) width: u32,
62    /// Glyph cell height in pixels.
63    #[get(type(copy))]
64    pub(crate) height: u32,
65    /// Horizontal advance in pixels.
66    #[get(type(copy))]
67    pub(crate) advance: u32,
68}
69
70/// Batched strip layout and readback telemetry produced for Web missing-glyph rasterization.
71#[derive(Clone, Debug, Default, Eq, Getter, New, PartialEq)]
72pub struct WebGlyphStripBatch {
73    /// Tight packed strip surface width in pixels.
74    #[get(type(copy))]
75    pub(crate) strip_width: u32,
76    /// Tight packed strip surface height in pixels.
77    #[get(type(copy))]
78    pub(crate) strip_height: u32,
79    /// Per-glyph strip rectangles aligned with the input batch.
80    pub(crate) placements: Vec<GlyphStripPlacement>,
81    /// Number of `getImageData` readbacks executed (`0` for direct WebGL2/WebGPU canvas upload, `<= 1` for software fallback).
82    #[get(type(copy))]
83    pub(crate) readbacks_performed: u32,
84}
85
86/// Bounded pre-cached CSS `font` string table eliminating per-glyph `format!` allocations on Web.
87#[derive(Clone, Debug, Default, Getter)]
88pub struct WebCssFontCache {
89    /// Cached `(style_sig, css_font_decl)` entries bounded by `WEB_FONT_CSS_CACHE_MAX`.
90    #[get(skip)]
91    pub(crate) entries: Vec<(u32, String)>,
92    /// Clock eviction cursor cycling through `entries` once full.
93    #[get(skip)]
94    pub(crate) evict_cursor: usize,
95    /// Cumulative CSS cache hits served without formatting.
96    #[get(type(copy))]
97    pub(crate) hits: u64,
98    /// Cumulative CSS cache misses requiring string construction.
99    #[get(type(copy))]
100    pub(crate) misses: u64,
101}
102
103#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
104#[repr(C)]
105#[derive(Clone, Copy)]
106pub(crate) struct CtRange {
107    pub(crate) location: isize,
108    pub(crate) length: isize,
109}
110
111#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
112#[repr(C)]
113#[derive(Clone, Copy)]
114pub(crate) struct CtPoint {
115    pub(crate) x: f64,
116    pub(crate) y: f64,
117}
118
119#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
120#[repr(C)]
121#[derive(Clone, Copy)]
122pub(crate) struct CtSize {
123    pub(crate) width: f64,
124    pub(crate) height: f64,
125}
126
127#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
128#[repr(C)]
129#[derive(Clone, Copy)]
130pub(crate) struct CtRect {
131    pub(crate) origin: CtPoint,
132    pub(crate) size: CtSize,
133}
134
135#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
136#[repr(C)]
137#[derive(Clone, Copy)]
138pub(crate) struct CtAffineTransform {
139    pub(crate) a: f64,
140    pub(crate) b: f64,
141    pub(crate) c: f64,
142    pub(crate) d: f64,
143    pub(crate) tx: f64,
144    pub(crate) ty: f64,
145}
146
147/// Cached Apple CoreText `CTFontRef` handle paired with pre-queried vertical metrics, Clock-LRU bit, and lazy cascaded fallbacks.
148#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
149#[derive(Clone, Copy)]
150pub(crate) struct CoreTextFontCacheEntry {
151    /// Packed `(size_tenths | bold<<16 | monospace<<17 | italic<<18)` style signature (`0` when empty).
152    pub(crate) style_sig: u32,
153    /// Second-chance Clock-LRU reference bit stamped on every cache hit.
154    pub(crate) referenced: bool,
155    /// Retained CoreText `CTFontRef` handle released on eviction or thread exit.
156    pub(crate) font: *mut c_void,
157    /// Pre-queried clamped typographic ascent in points.
158    pub(crate) ascent: f64,
159    /// Pre-queried clamped typographic descent in points.
160    pub(crate) descent: f64,
161    /// Lazily populated cascaded fallback `CTFontRef` slots (e.g. CJK / symbol fonts), null until a glyph misses `font`.
162    pub(crate) fallback_fonts: [*mut c_void; CORETEXT_FALLBACK_SLOTS],
163}
164
165/// Thread-local fixed O(1) Clock-LRU cache of Apple CoreText `CTFontRef` handles, singleton grayscale `CGColorSpaceRef`, and persistent bitmap context.
166#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
167pub(crate) struct CoreTextFontCache {
168    /// Singleton device-gray `CGColorSpaceRef` reused across all glyph rasterizations on this thread.
169    pub(crate) gray_space: *mut c_void,
170    /// Persistent scratch `CGBitmapContextRef` backed by `scratch_buf`, eliminating per-glyph context creation FFI calls.
171    pub(crate) scratch_ctx: *mut c_void,
172    /// Backing alpha8 pixel storage for `scratch_ctx`.
173    pub(crate) scratch_buf: Vec<u8>,
174    /// Current pixel width of `scratch_ctx`.
175    pub(crate) scratch_w: usize,
176    /// Current pixel height of `scratch_ctx`.
177    pub(crate) scratch_h: usize,
178    /// Number of occupied slots in `slots` (`0..=CORETEXT_FONT_CACHE_SLOTS`).
179    pub(crate) count: usize,
180    /// Clock-LRU hand sweeping `slots` for O(1) amortized eviction without `Vec::remove(0)` shifts.
181    pub(crate) clock_hand: usize,
182    /// Open-addressed 64-entry direct index mapping `hash(style_sig) & 63` to slot index (`CORETEXT_INDEX_EMPTY` when vacant).
183    pub(crate) index: [u8; CORETEXT_FONT_INDEX_CAP],
184    /// Fixed stack-inline table of cached base `CTFontRef` handles (`CORETEXT_FONT_CACHE_SLOTS`).
185    pub(crate) slots: [CoreTextFontCacheEntry; CORETEXT_FONT_CACHE_SLOTS],
186}
187
188/// Standard 128-bit Windows COM `GUID` structure for lazy `DWriteCreateFactory` binding.
189#[cfg(target_os = "windows")]
190#[repr(C)]
191#[derive(Clone, Copy)]
192pub(crate) struct WinGuid {
193    pub(crate) data1: u32,
194    pub(crate) data2: u16,
195    pub(crate) data3: u16,
196    pub(crate) data4: [u8; 8],
197}
198
199/// Process-wide lazily loaded Windows DirectWrite (`dwrite.dll`) entry point handle.
200#[cfg(target_os = "windows")]
201#[derive(Clone, Copy)]
202pub(crate) struct DirectWriteLib {
203    /// Resolved `DWriteCreateFactory` function pointer.
204    pub(crate) create_factory: WinDWriteCreateFactoryFn,
205}
206
207/// Cached Windows Win32 `HFONT` handle paired with pre-queried font metrics and Clock-LRU reference bit.
208#[cfg(target_os = "windows")]
209#[derive(Clone, Copy)]
210pub(crate) struct Win32FontCacheEntry {
211    /// Packed `(size_px | bold<<16 | italic<<17 | face_kind<<18)` style signature (`0` when empty).
212    pub(crate) style_sig: u32,
213    /// Second-chance Clock-LRU reference bit stamped on every cache hit.
214    pub(crate) referenced: bool,
215    /// Retained Win32 `HFONT` handle deleted on eviction or thread exit.
216    pub(crate) hfont: *mut c_void,
217    /// Pre-queried clamped typographic ascent in pixels.
218    pub(crate) ascent: i32,
219    /// Pre-queried clamped typographic descent in pixels.
220    pub(crate) descent: i32,
221}
222
223/// Thread-local fixed O(1) Clock-LRU cache of Windows Win32 memory `HDC`, `HFONT` handles, lazy `IDWriteFactory`, and outline scratch storage.
224#[cfg(target_os = "windows")]
225pub(crate) struct Win32FontCache {
226    /// Persistent compatible memory device context reused across glyph misses.
227    pub(crate) hdc: *mut c_void,
228    /// Whether lazy DirectWrite factory initialization has been attempted on first glyph miss.
229    pub(crate) dwrite_attempted: bool,
230    /// Lazily initialized COM `IDWriteFactory` interface pointer released via `IUnknown::Release` on `Drop`.
231    pub(crate) dwrite_factory: *mut c_void,
232    /// Number of occupied slots in `slots` (`0..=WIN32_FONT_CACHE_SLOTS`).
233    pub(crate) count: usize,
234    /// Clock-LRU hand sweeping `slots` for O(1) amortized eviction without `Vec::remove(0)` shifts.
235    pub(crate) clock_hand: usize,
236    /// Open-addressed 64-entry direct index mapping `hash(style_sig) & 63` to slot index (`WIN32_INDEX_EMPTY` when vacant).
237    pub(crate) index: [u8; WIN32_FONT_INDEX_CAP],
238    /// Fixed stack-inline table of cached `HFONT` handles (`WIN32_FONT_CACHE_SLOTS`).
239    pub(crate) slots: [Win32FontCacheEntry; WIN32_FONT_CACHE_SLOTS],
240    /// Reusable `GetGlyphOutlineW` byte scratch buffer eliminating per-glyph allocations.
241    pub(crate) raw_buf: Vec<u8>,
242}
243
244#[cfg(target_os = "windows")]
245#[repr(C)]
246#[derive(Clone, Copy, Default)]
247pub(crate) struct WinFixed {
248    pub(crate) fract: u16,
249    pub(crate) value: i16,
250}
251
252#[cfg(target_os = "windows")]
253#[repr(C)]
254#[derive(Clone, Copy, Default)]
255pub(crate) struct WinMat2 {
256    pub(crate) em11: WinFixed,
257    pub(crate) em12: WinFixed,
258    pub(crate) em21: WinFixed,
259    pub(crate) em22: WinFixed,
260}
261
262#[cfg(target_os = "windows")]
263#[repr(C)]
264#[derive(Clone, Copy, Default)]
265pub(crate) struct WinGlyphMetrics {
266    pub(crate) black_box_x: u32,
267    pub(crate) black_box_y: u32,
268    pub(crate) glyph_origin_x: i32,
269    pub(crate) glyph_origin_y: i32,
270    pub(crate) cell_inc_x: i16,
271    pub(crate) cell_inc_y: i16,
272}
273
274#[cfg(target_os = "windows")]
275#[repr(C)]
276#[derive(Clone, Copy, Default)]
277pub(crate) struct WinTextMetricW {
278    pub(crate) tm_height: i32,
279    pub(crate) tm_ascent: i32,
280    pub(crate) tm_descent: i32,
281    pub(crate) tm_internal_leading: i32,
282    pub(crate) tm_external_leading: i32,
283    pub(crate) tm_ave_char_width: i32,
284    pub(crate) tm_max_char_width: i32,
285    pub(crate) tm_weight: i32,
286    pub(crate) tm_overhang: i32,
287    pub(crate) tm_digitized_aspect_x: i32,
288    pub(crate) tm_digitized_aspect_y: i32,
289    pub(crate) tm_first_char: u16,
290    pub(crate) tm_last_char: u16,
291    pub(crate) tm_default_char: u16,
292    pub(crate) tm_break_char: u16,
293    pub(crate) tm_italic: u8,
294    pub(crate) tm_underlined: u8,
295    pub(crate) tm_struck_out: u8,
296    pub(crate) tm_pitch_and_family: u8,
297    pub(crate) tm_char_set: u8,
298}
299
300#[cfg(any(target_os = "linux", target_os = "android"))]
301#[repr(C)]
302#[derive(Clone, Copy)]
303pub(crate) struct FtBitmap {
304    pub(crate) rows: u32,
305    pub(crate) width: u32,
306    pub(crate) pitch: i32,
307    pub(crate) buffer: *const u8,
308    pub(crate) num_grays: u16,
309    pub(crate) pixel_mode: u8,
310    pub(crate) palette_mode: u8,
311    pub(crate) palette: *mut c_void,
312}
313
314#[cfg(any(target_os = "linux", target_os = "android"))]
315#[repr(C)]
316#[derive(Clone, Copy)]
317pub(crate) struct FtVector {
318    pub(crate) x: isize,
319    pub(crate) y: isize,
320}
321
322#[cfg(any(target_os = "linux", target_os = "android"))]
323#[repr(C)]
324#[derive(Clone, Copy)]
325pub(crate) struct FtGeneric {
326    pub(crate) data: *mut c_void,
327    pub(crate) finalizer: *mut c_void,
328}
329
330#[cfg(any(target_os = "linux", target_os = "android"))]
331#[repr(C)]
332#[derive(Clone, Copy)]
333pub(crate) struct FtBBox {
334    pub(crate) x_min: isize,
335    pub(crate) y_min: isize,
336    pub(crate) x_max: isize,
337    pub(crate) y_max: isize,
338}
339
340#[cfg(any(target_os = "linux", target_os = "android"))]
341#[repr(C)]
342#[derive(Clone, Copy)]
343pub(crate) struct FtGlyphMetrics {
344    pub(crate) width: isize,
345    pub(crate) height: isize,
346    pub(crate) hori_bearing_x: isize,
347    pub(crate) hori_bearing_y: isize,
348    pub(crate) hori_advance: isize,
349    pub(crate) vert_bearing_x: isize,
350    pub(crate) vert_bearing_y: isize,
351    pub(crate) vert_advance: isize,
352}
353
354#[cfg(any(target_os = "linux", target_os = "android"))]
355#[repr(C)]
356#[derive(Clone, Copy)]
357pub(crate) struct FtSizeMetrics {
358    pub(crate) x_ppem: u16,
359    pub(crate) y_ppem: u16,
360    pub(crate) x_scale: isize,
361    pub(crate) y_scale: isize,
362    pub(crate) ascender: isize,
363    pub(crate) descender: isize,
364    pub(crate) height: isize,
365    pub(crate) max_advance: isize,
366}
367
368#[cfg(any(target_os = "linux", target_os = "android"))]
369#[repr(C)]
370#[derive(Clone, Copy)]
371pub(crate) struct FtSizeRec {
372    pub(crate) face: *mut c_void,
373    pub(crate) generic: FtGeneric,
374    pub(crate) metrics: FtSizeMetrics,
375    pub(crate) internal: *mut c_void,
376}
377
378#[cfg(any(target_os = "linux", target_os = "android"))]
379#[repr(C)]
380#[derive(Clone, Copy)]
381pub(crate) struct FtGlyphSlotRec {
382    pub(crate) library: *mut c_void,
383    pub(crate) face: *mut c_void,
384    pub(crate) next: *mut c_void,
385    pub(crate) glyph_index: u32,
386    pub(crate) generic: FtGeneric,
387    pub(crate) metrics: FtGlyphMetrics,
388    pub(crate) linear_hori_advance: isize,
389    pub(crate) linear_vert_advance: isize,
390    pub(crate) advance: FtVector,
391    pub(crate) format: u32,
392    pub(crate) bitmap: FtBitmap,
393    pub(crate) bitmap_left: i32,
394    pub(crate) bitmap_top: i32,
395}
396
397#[cfg(any(target_os = "linux", target_os = "android"))]
398#[repr(C)]
399#[derive(Clone, Copy)]
400pub(crate) struct FtFaceRec {
401    pub(crate) num_faces: isize,
402    pub(crate) face_index: isize,
403    pub(crate) face_flags: isize,
404    pub(crate) style_flags: isize,
405    pub(crate) num_glyphs: isize,
406    pub(crate) family_name: *const c_char,
407    pub(crate) style_name: *const c_char,
408    pub(crate) num_fixed_sizes: i32,
409    pub(crate) available_sizes: *mut c_void,
410    pub(crate) num_charmaps: i32,
411    pub(crate) charmaps: *mut c_void,
412    pub(crate) generic: FtGeneric,
413    pub(crate) bbox: FtBBox,
414    pub(crate) units_per_em: u16,
415    pub(crate) ascender: i16,
416    pub(crate) descender: i16,
417    pub(crate) height: i16,
418    pub(crate) max_advance_width: i16,
419    pub(crate) max_advance_height: i16,
420    pub(crate) underline_position: i16,
421    pub(crate) underline_thickness: i16,
422    pub(crate) glyph: *const FtGlyphSlotRec,
423    pub(crate) size: *const FtSizeRec,
424}
425
426/// Process-wide single persistent `OnceLock` FreeType 2 library symbol table eliminating double-`dlopen`.
427#[cfg(any(target_os = "linux", target_os = "android"))]
428#[derive(Clone, Copy)]
429pub(crate) struct FreeTypeLib {
430    /// Non-zero `dlopen` handle address retained for process lifetime.
431    pub(crate) handle_addr: usize,
432    /// Resolved `FT_Init_FreeType` function pointer.
433    pub(crate) init: FtInitFreeTypeFn,
434    /// Resolved `FT_Done_FreeType` function pointer.
435    pub(crate) done: FtDoneFreeTypeFn,
436    /// Resolved `FT_New_Face` function pointer.
437    pub(crate) new_face: FtNewFaceFn,
438    /// Optional resolved `FT_Done_Face` function pointer for clean face release on `Drop`.
439    pub(crate) done_face: Option<FtDoneFaceFn>,
440    /// Resolved `FT_Set_Pixel_Sizes` function pointer.
441    pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
442    /// Optional resolved `FT_Set_Char_Size` function pointer for exact sub-pixel fractional font sizing.
443    pub(crate) set_char_size: Option<FtSetCharSizeFn>,
444    /// Resolved `FT_Get_Char_Index` function pointer.
445    pub(crate) get_char_index: FtGetCharIndexFn,
446    /// Resolved `FT_Load_Glyph` function pointer.
447    pub(crate) load_glyph: FtLoadGlyphFn,
448}
449
450/// Process-wide single persistent Android NDK `libandroid.so` `AFontMatcher` symbol table (API 29+).
451#[cfg(target_os = "android")]
452#[derive(Clone, Copy)]
453pub(crate) struct AndroidFontMatcherLib {
454    /// Non-zero `dlopen` handle address for `libandroid.so`.
455    pub(crate) handle_addr: usize,
456    /// Resolved `AFontMatcher_create` function pointer.
457    pub(crate) create: AFontMatcherCreateFn,
458    /// Resolved `AFontMatcher_destroy` function pointer.
459    pub(crate) destroy: AFontMatcherDestroyFn,
460    /// Resolved `AFontMatcher_setStyle` function pointer.
461    pub(crate) set_style: AFontMatcherSetStyleFn,
462    /// Resolved `AFontMatcher_match` function pointer.
463    pub(crate) match_font: AFontMatcherMatchFn,
464    /// Resolved `AFont_getFontFilePath` function pointer.
465    pub(crate) font_file_path: AFontGetFilePathFn,
466    /// Resolved `AFont_getCollectionIndex` function pointer.
467    pub(crate) collection_index: AFontGetCollectionIndexFn,
468    /// Resolved `AFont_close` function pointer.
469    pub(crate) font_close: AFontCloseFn,
470}
471
472/// Cached Android NDK `AFontMatcher`-resolved FreeType fallback face slot keyed by `(path_hash, collection_index)`.
473#[cfg(target_os = "android")]
474#[derive(Clone, Copy)]
475pub(crate) struct FtAndroidFallbackFace {
476    /// 64-bit FNV-1a hash of the matched font file path (`0` when empty).
477    pub(crate) path_hash: u64,
478    /// TTC collection face index returned by `AFont_getCollectionIndex`.
479    pub(crate) collection_index: u32,
480    /// Second-chance Clock-LRU reference bit.
481    pub(crate) referenced: bool,
482    /// Opened FreeType face and last applied pixel size.
483    pub(crate) slot: FtLazyFace,
484}
485
486/// Lazily loaded FreeType face slot tracking probe state and most recently applied pixel size.
487#[cfg(any(target_os = "linux", target_os = "android"))]
488#[derive(Clone, Copy)]
489pub(crate) struct FtLazyFace {
490    /// Whether candidate font path probing has already been attempted for this slot.
491    pub(crate) probed: bool,
492    /// Opened FreeType face pointer, or null when unprobed or unavailable.
493    pub(crate) face: *mut FtFaceRec,
494    /// Most recently applied quantized pixel size in tenths (`px * 10`) on `face` to skip redundant FreeType size updates.
495    pub(crate) last_size_tenths: u32,
496}
497
498/// Per-thread FreeType 2 runtime borrowing the persistent `OnceLock` library and lazily opening faces on demand.
499#[cfg(any(target_os = "linux", target_os = "android"))]
500pub(crate) struct FreeTypeRuntime {
501    /// Initialized `FT_Library` handle retained for on-demand `FT_New_Face` calls.
502    pub(crate) library: *mut c_void,
503    /// Resolved `FT_Done_FreeType` function pointer invoked on `Drop`.
504    pub(crate) done: FtDoneFreeTypeFn,
505    /// Resolved `FT_New_Face` function pointer for lazy style and CJK fallback face opening.
506    pub(crate) new_face: FtNewFaceFn,
507    /// Optional resolved `FT_Done_Face` function pointer invoked on eviction and `Drop`.
508    pub(crate) done_face: Option<FtDoneFaceFn>,
509    /// Lazily opened primary regular UI sans face (bound on first glyph miss, never on startup).
510    pub(crate) regular: FtLazyFace,
511    /// Lazily opened bold sans face (opened only on first bold glyph).
512    pub(crate) bold: FtLazyFace,
513    /// Lazily opened monospace face (opened only on first monospace glyph).
514    pub(crate) mono: FtLazyFace,
515    /// Lazily opened bold monospace face (opened only on first bold monospace glyph).
516    pub(crate) mono_bold: FtLazyFace,
517    /// Lazily opened CJK / Unicode fallback face (opened only when primary face misses a codepoint).
518    pub(crate) cjk: FtLazyFace,
519    /// Resolved `FT_Set_Pixel_Sizes` function pointer.
520    pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
521    /// Optional resolved `FT_Set_Char_Size` function pointer for exact sub-pixel fractional font sizing.
522    pub(crate) set_char_size: Option<FtSetCharSizeFn>,
523    /// Resolved `FT_Get_Char_Index` function pointer.
524    pub(crate) get_char_index: FtGetCharIndexFn,
525    /// Resolved `FT_Load_Glyph` function pointer.
526    pub(crate) load_glyph: FtLoadGlyphFn,
527    /// Lazily created Android NDK `AFontMatcher` handle (null on API < 29).
528    #[cfg(target_os = "android")]
529    pub(crate) matcher: *mut c_void,
530    /// Bounded Clock-LRU table of Android `AFontMatcher`-resolved fallback FreeType faces.
531    #[cfg(target_os = "android")]
532    pub(crate) android_fallbacks: [FtAndroidFallbackFace; ANDROID_FALLBACK_CACHE_SLOTS],
533    /// Clock eviction cursor for `android_fallbacks`.
534    #[cfg(target_os = "android")]
535    pub(crate) android_fallback_hand: usize,
536}
537
538/// Thread-local reusable offscreen `<canvas>` surfaces and pre-cached CSS font strings for zero-churn Web glyph rasterization.
539#[cfg(target_arch = "wasm32")]
540pub(crate) struct WebFontScratch {
541    /// Persistent CPU-backed (`willReadFrequently: true`) strip `<canvas>` for `<= 1` readback/frame software fallback.
542    pub(crate) readback_canvas: Option<HtmlCanvasElement>,
543    /// Cached 2D context bound to `readback_canvas`.
544    pub(crate) readback_ctx2d: Option<CanvasRenderingContext2d>,
545    /// Current allocated pixel width of `readback_canvas`.
546    pub(crate) readback_width: u32,
547    /// Current allocated pixel height of `readback_canvas`.
548    pub(crate) readback_height: u32,
549    /// Most recently applied packed `style_sig` on `readback_ctx2d` (`u32::MAX` when unset).
550    pub(crate) readback_last_sig: u32,
551    /// Persistent GPU-resident strip `<canvas>` for zero-readback WebGL2 `texSubImage2D` / WebGPU `copyExternalImageToTexture`.
552    pub(crate) gpu_canvas: Option<HtmlCanvasElement>,
553    /// Cached 2D context bound to `gpu_canvas`.
554    pub(crate) gpu_ctx2d: Option<CanvasRenderingContext2d>,
555    /// Current allocated pixel width of `gpu_canvas`.
556    pub(crate) gpu_width: u32,
557    /// Current allocated pixel height of `gpu_canvas`.
558    pub(crate) gpu_height: u32,
559    /// Most recently applied packed `style_sig` on `gpu_ctx2d` (`u32::MAX` when unset).
560    pub(crate) gpu_last_sig: u32,
561    /// Pre-cached CSS `font` strings keyed by `style_sig`, eliminating per-glyph `format!` allocations.
562    pub(crate) css_cache: WebCssFontCache,
563    /// Cumulative `getImageData` readbacks executed on the software fallback path.
564    pub(crate) total_readbacks: u64,
565    /// Cumulative zero-readback GPU strip batches prepared for WebGL2/WebGPU upload.
566    pub(crate) total_gpu_strip_batches: u64,
567}