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"))]
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"))]
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"))]
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"))]
128#[repr(C)]
129#[derive(Clone, Copy)]
130pub(crate) struct CtRect {
131    pub(crate) origin: CtPoint,
132    pub(crate) size: CtSize,
133}
134
135/// Cached Apple CoreText `CTFontRef` handle paired with pre-queried vertical metrics, Clock-LRU bit, and lazy cascaded fallbacks.
136#[cfg(any(target_os = "macos", target_os = "ios"))]
137#[derive(Clone, Copy)]
138pub(crate) struct CoreTextFontCacheEntry {
139    /// Packed `(size_tenths | bold<<16 | monospace<<17 | italic<<18)` style signature (`0` when empty).
140    pub(crate) style_sig: u32,
141    /// Second-chance Clock-LRU reference bit stamped on every cache hit.
142    pub(crate) referenced: bool,
143    /// Retained CoreText `CTFontRef` handle released on eviction or thread exit.
144    pub(crate) font: *mut c_void,
145    /// Pre-queried clamped typographic ascent in points.
146    pub(crate) ascent: f64,
147    /// Pre-queried clamped typographic descent in points.
148    pub(crate) descent: f64,
149    /// Lazily populated cascaded fallback `CTFontRef` slots (e.g. CJK / symbol fonts), null until a glyph misses `font`.
150    pub(crate) fallback_fonts: [*mut c_void; CORETEXT_FALLBACK_SLOTS],
151}
152
153/// Thread-local fixed O(1) Clock-LRU cache of Apple CoreText `CTFontRef` handles, singleton grayscale `CGColorSpaceRef`, and persistent bitmap context.
154#[cfg(any(target_os = "macos", target_os = "ios"))]
155pub(crate) struct CoreTextFontCache {
156    /// Singleton device-gray `CGColorSpaceRef` reused across all glyph rasterizations on this thread.
157    pub(crate) gray_space: *mut c_void,
158    /// Persistent scratch `CGBitmapContextRef` backed by `scratch_buf`, eliminating per-glyph context creation FFI calls.
159    pub(crate) scratch_ctx: *mut c_void,
160    /// Backing alpha8 pixel storage for `scratch_ctx`.
161    pub(crate) scratch_buf: Vec<u8>,
162    /// Current pixel width of `scratch_ctx`.
163    pub(crate) scratch_w: usize,
164    /// Current pixel height of `scratch_ctx`.
165    pub(crate) scratch_h: usize,
166    /// Number of occupied slots in `slots` (`0..=CORETEXT_FONT_CACHE_SLOTS`).
167    pub(crate) count: usize,
168    /// Clock-LRU hand sweeping `slots` for O(1) amortized eviction without `Vec::remove(0)` shifts.
169    pub(crate) clock_hand: usize,
170    /// Open-addressed 64-entry direct index mapping `hash(style_sig) & 63` to slot index (`CORETEXT_INDEX_EMPTY` when vacant).
171    pub(crate) index: [u8; CORETEXT_FONT_INDEX_CAP],
172    /// Fixed stack-inline table of cached base `CTFontRef` handles (`CORETEXT_FONT_CACHE_SLOTS`).
173    pub(crate) slots: [CoreTextFontCacheEntry; CORETEXT_FONT_CACHE_SLOTS],
174}
175
176/// Standard 128-bit Windows COM `GUID` structure for lazy `DWriteCreateFactory` binding.
177#[cfg(target_os = "windows")]
178#[repr(C)]
179#[derive(Clone, Copy)]
180pub(crate) struct WinGuid {
181    pub(crate) data1: u32,
182    pub(crate) data2: u16,
183    pub(crate) data3: u16,
184    pub(crate) data4: [u8; 8],
185}
186
187/// Process-wide lazily loaded Windows DirectWrite (`dwrite.dll`) entry point handle.
188#[cfg(target_os = "windows")]
189#[derive(Clone, Copy)]
190pub(crate) struct DirectWriteLib {
191    /// Resolved `DWriteCreateFactory` function pointer.
192    pub(crate) create_factory: WinDWriteCreateFactoryFn,
193}
194
195/// Cached Windows Win32 `HFONT` handle paired with pre-queried font metrics and Clock-LRU reference bit.
196#[cfg(target_os = "windows")]
197#[derive(Clone, Copy)]
198pub(crate) struct Win32FontCacheEntry {
199    /// Packed `(size_px | bold<<16 | italic<<17 | face_kind<<18)` style signature (`0` when empty).
200    pub(crate) style_sig: u32,
201    /// Second-chance Clock-LRU reference bit stamped on every cache hit.
202    pub(crate) referenced: bool,
203    /// Retained Win32 `HFONT` handle deleted on eviction or thread exit.
204    pub(crate) hfont: *mut c_void,
205    /// Pre-queried clamped typographic ascent in pixels.
206    pub(crate) ascent: i32,
207    /// Pre-queried clamped typographic descent in pixels.
208    pub(crate) descent: i32,
209}
210
211/// Thread-local fixed O(1) Clock-LRU cache of Windows Win32 memory `HDC`, `HFONT` handles, lazy `IDWriteFactory`, and outline scratch storage.
212#[cfg(target_os = "windows")]
213pub(crate) struct Win32FontCache {
214    /// Persistent compatible memory device context reused across glyph misses.
215    pub(crate) hdc: *mut c_void,
216    /// Whether lazy DirectWrite factory initialization has been attempted on first glyph miss.
217    pub(crate) dwrite_attempted: bool,
218    /// Lazily initialized COM `IDWriteFactory` interface pointer released via `IUnknown::Release` on `Drop`.
219    pub(crate) dwrite_factory: *mut c_void,
220    /// Number of occupied slots in `slots` (`0..=WIN32_FONT_CACHE_SLOTS`).
221    pub(crate) count: usize,
222    /// Clock-LRU hand sweeping `slots` for O(1) amortized eviction without `Vec::remove(0)` shifts.
223    pub(crate) clock_hand: usize,
224    /// Open-addressed 64-entry direct index mapping `hash(style_sig) & 63` to slot index (`WIN32_INDEX_EMPTY` when vacant).
225    pub(crate) index: [u8; WIN32_FONT_INDEX_CAP],
226    /// Fixed stack-inline table of cached `HFONT` handles (`WIN32_FONT_CACHE_SLOTS`).
227    pub(crate) slots: [Win32FontCacheEntry; WIN32_FONT_CACHE_SLOTS],
228    /// Reusable `GetGlyphOutlineW` byte scratch buffer eliminating per-glyph allocations.
229    pub(crate) raw_buf: Vec<u8>,
230}
231
232#[cfg(target_os = "windows")]
233#[repr(C)]
234#[derive(Clone, Copy, Default)]
235pub(crate) struct WinFixed {
236    pub(crate) fract: u16,
237    pub(crate) value: i16,
238}
239
240#[cfg(target_os = "windows")]
241#[repr(C)]
242#[derive(Clone, Copy, Default)]
243pub(crate) struct WinMat2 {
244    pub(crate) em11: WinFixed,
245    pub(crate) em12: WinFixed,
246    pub(crate) em21: WinFixed,
247    pub(crate) em22: WinFixed,
248}
249
250#[cfg(target_os = "windows")]
251#[repr(C)]
252#[derive(Clone, Copy, Default)]
253pub(crate) struct WinGlyphMetrics {
254    pub(crate) black_box_x: u32,
255    pub(crate) black_box_y: u32,
256    pub(crate) glyph_origin_x: i32,
257    pub(crate) glyph_origin_y: i32,
258    pub(crate) cell_inc_x: i16,
259    pub(crate) cell_inc_y: i16,
260}
261
262#[cfg(target_os = "windows")]
263#[repr(C)]
264#[derive(Clone, Copy, Default)]
265pub(crate) struct WinTextMetricW {
266    pub(crate) tm_height: i32,
267    pub(crate) tm_ascent: i32,
268    pub(crate) tm_descent: i32,
269    pub(crate) tm_internal_leading: i32,
270    pub(crate) tm_external_leading: i32,
271    pub(crate) tm_ave_char_width: i32,
272    pub(crate) tm_max_char_width: i32,
273    pub(crate) tm_weight: i32,
274    pub(crate) tm_overhang: i32,
275    pub(crate) tm_digitized_aspect_x: i32,
276    pub(crate) tm_digitized_aspect_y: i32,
277    pub(crate) tm_first_char: u16,
278    pub(crate) tm_last_char: u16,
279    pub(crate) tm_default_char: u16,
280    pub(crate) tm_break_char: u16,
281    pub(crate) tm_italic: u8,
282    pub(crate) tm_underlined: u8,
283    pub(crate) tm_struck_out: u8,
284    pub(crate) tm_pitch_and_family: u8,
285    pub(crate) tm_char_set: u8,
286}
287
288#[cfg(any(target_os = "linux", target_os = "android"))]
289#[repr(C)]
290#[derive(Clone, Copy)]
291pub(crate) struct FtBitmap {
292    pub(crate) rows: u32,
293    pub(crate) width: u32,
294    pub(crate) pitch: i32,
295    pub(crate) buffer: *const u8,
296    pub(crate) num_grays: u16,
297    pub(crate) pixel_mode: u8,
298    pub(crate) palette_mode: u8,
299    pub(crate) palette: *mut c_void,
300}
301
302#[cfg(any(target_os = "linux", target_os = "android"))]
303#[repr(C)]
304#[derive(Clone, Copy)]
305pub(crate) struct FtVector {
306    pub(crate) x: isize,
307    pub(crate) y: isize,
308}
309
310#[cfg(any(target_os = "linux", target_os = "android"))]
311#[repr(C)]
312#[derive(Clone, Copy)]
313pub(crate) struct FtGeneric {
314    pub(crate) data: *mut c_void,
315    pub(crate) finalizer: *mut c_void,
316}
317
318#[cfg(any(target_os = "linux", target_os = "android"))]
319#[repr(C)]
320#[derive(Clone, Copy)]
321pub(crate) struct FtBBox {
322    pub(crate) x_min: isize,
323    pub(crate) y_min: isize,
324    pub(crate) x_max: isize,
325    pub(crate) y_max: isize,
326}
327
328#[cfg(any(target_os = "linux", target_os = "android"))]
329#[repr(C)]
330#[derive(Clone, Copy)]
331pub(crate) struct FtGlyphMetrics {
332    pub(crate) width: isize,
333    pub(crate) height: isize,
334    pub(crate) hori_bearing_x: isize,
335    pub(crate) hori_bearing_y: isize,
336    pub(crate) hori_advance: isize,
337    pub(crate) vert_bearing_x: isize,
338    pub(crate) vert_bearing_y: isize,
339    pub(crate) vert_advance: isize,
340}
341
342#[cfg(any(target_os = "linux", target_os = "android"))]
343#[repr(C)]
344#[derive(Clone, Copy)]
345pub(crate) struct FtSizeMetrics {
346    pub(crate) x_ppem: u16,
347    pub(crate) y_ppem: u16,
348    pub(crate) x_scale: isize,
349    pub(crate) y_scale: isize,
350    pub(crate) ascender: isize,
351    pub(crate) descender: isize,
352    pub(crate) height: isize,
353    pub(crate) max_advance: isize,
354}
355
356#[cfg(any(target_os = "linux", target_os = "android"))]
357#[repr(C)]
358#[derive(Clone, Copy)]
359pub(crate) struct FtSizeRec {
360    pub(crate) face: *mut c_void,
361    pub(crate) generic: FtGeneric,
362    pub(crate) metrics: FtSizeMetrics,
363    pub(crate) internal: *mut c_void,
364}
365
366#[cfg(any(target_os = "linux", target_os = "android"))]
367#[repr(C)]
368#[derive(Clone, Copy)]
369pub(crate) struct FtGlyphSlotRec {
370    pub(crate) library: *mut c_void,
371    pub(crate) face: *mut c_void,
372    pub(crate) next: *mut c_void,
373    pub(crate) glyph_index: u32,
374    pub(crate) generic: FtGeneric,
375    pub(crate) metrics: FtGlyphMetrics,
376    pub(crate) linear_hori_advance: isize,
377    pub(crate) linear_vert_advance: isize,
378    pub(crate) advance: FtVector,
379    pub(crate) format: u32,
380    pub(crate) bitmap: FtBitmap,
381    pub(crate) bitmap_left: i32,
382    pub(crate) bitmap_top: i32,
383}
384
385#[cfg(any(target_os = "linux", target_os = "android"))]
386#[repr(C)]
387#[derive(Clone, Copy)]
388pub(crate) struct FtFaceRec {
389    pub(crate) num_faces: isize,
390    pub(crate) face_index: isize,
391    pub(crate) face_flags: isize,
392    pub(crate) style_flags: isize,
393    pub(crate) num_glyphs: isize,
394    pub(crate) family_name: *const c_char,
395    pub(crate) style_name: *const c_char,
396    pub(crate) num_fixed_sizes: i32,
397    pub(crate) available_sizes: *mut c_void,
398    pub(crate) num_charmaps: i32,
399    pub(crate) charmaps: *mut c_void,
400    pub(crate) generic: FtGeneric,
401    pub(crate) bbox: FtBBox,
402    pub(crate) units_per_em: u16,
403    pub(crate) ascender: i16,
404    pub(crate) descender: i16,
405    pub(crate) height: i16,
406    pub(crate) max_advance_width: i16,
407    pub(crate) max_advance_height: i16,
408    pub(crate) underline_position: i16,
409    pub(crate) underline_thickness: i16,
410    pub(crate) glyph: *const FtGlyphSlotRec,
411    pub(crate) size: *const FtSizeRec,
412}
413
414/// Process-wide single persistent `OnceLock` FreeType 2 library symbol table eliminating double-`dlopen`.
415#[cfg(any(target_os = "linux", target_os = "android"))]
416#[derive(Clone, Copy)]
417pub(crate) struct FreeTypeLib {
418    /// Non-zero `dlopen` handle address retained for process lifetime.
419    pub(crate) handle_addr: usize,
420    /// Resolved `FT_Init_FreeType` function pointer.
421    pub(crate) init: FtInitFreeTypeFn,
422    /// Resolved `FT_Done_FreeType` function pointer.
423    pub(crate) done: FtDoneFreeTypeFn,
424    /// Resolved `FT_New_Face` function pointer.
425    pub(crate) new_face: FtNewFaceFn,
426    /// Optional resolved `FT_Done_Face` function pointer for clean face release on `Drop`.
427    pub(crate) done_face: Option<FtDoneFaceFn>,
428    /// Resolved `FT_Set_Pixel_Sizes` function pointer.
429    pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
430    /// Resolved `FT_Get_Char_Index` function pointer.
431    pub(crate) get_char_index: FtGetCharIndexFn,
432    /// Resolved `FT_Load_Glyph` function pointer.
433    pub(crate) load_glyph: FtLoadGlyphFn,
434}
435
436/// Process-wide single persistent Android NDK `libandroid.so` `AFontMatcher` symbol table (API 29+).
437#[cfg(target_os = "android")]
438#[derive(Clone, Copy)]
439pub(crate) struct AndroidFontMatcherLib {
440    /// Non-zero `dlopen` handle address for `libandroid.so`.
441    pub(crate) handle_addr: usize,
442    /// Resolved `AFontMatcher_create` function pointer.
443    pub(crate) create: AFontMatcherCreateFn,
444    /// Resolved `AFontMatcher_destroy` function pointer.
445    pub(crate) destroy: AFontMatcherDestroyFn,
446    /// Resolved `AFontMatcher_setStyle` function pointer.
447    pub(crate) set_style: AFontMatcherSetStyleFn,
448    /// Resolved `AFontMatcher_match` function pointer.
449    pub(crate) match_font: AFontMatcherMatchFn,
450    /// Resolved `AFont_getFontFilePath` function pointer.
451    pub(crate) font_file_path: AFontGetFilePathFn,
452    /// Resolved `AFont_getCollectionIndex` function pointer.
453    pub(crate) collection_index: AFontGetCollectionIndexFn,
454    /// Resolved `AFont_close` function pointer.
455    pub(crate) font_close: AFontCloseFn,
456}
457
458/// Cached Android NDK `AFontMatcher`-resolved FreeType fallback face slot keyed by `(path_hash, collection_index)`.
459#[cfg(target_os = "android")]
460#[derive(Clone, Copy)]
461pub(crate) struct FtAndroidFallbackFace {
462    /// 64-bit FNV-1a hash of the matched font file path (`0` when empty).
463    pub(crate) path_hash: u64,
464    /// TTC collection face index returned by `AFont_getCollectionIndex`.
465    pub(crate) collection_index: u32,
466    /// Second-chance Clock-LRU reference bit.
467    pub(crate) referenced: bool,
468    /// Opened FreeType face and last applied pixel size.
469    pub(crate) slot: FtLazyFace,
470}
471
472/// Lazily loaded FreeType face slot tracking probe state and most recently applied pixel size.
473#[cfg(any(target_os = "linux", target_os = "android"))]
474#[derive(Clone, Copy)]
475pub(crate) struct FtLazyFace {
476    /// Whether candidate font path probing has already been attempted for this slot.
477    pub(crate) probed: bool,
478    /// Opened FreeType face pointer, or null when unprobed or unavailable.
479    pub(crate) face: *mut FtFaceRec,
480    /// Most recently applied pixel size on `face` to skip redundant `FT_Set_Pixel_Sizes` calls.
481    pub(crate) last_size_px: u32,
482}
483
484/// Per-thread FreeType 2 runtime borrowing the persistent `OnceLock` library and lazily opening faces on demand.
485#[cfg(any(target_os = "linux", target_os = "android"))]
486pub(crate) struct FreeTypeRuntime {
487    /// Initialized `FT_Library` handle retained for on-demand `FT_New_Face` calls.
488    pub(crate) library: *mut c_void,
489    /// Resolved `FT_Done_FreeType` function pointer invoked on `Drop`.
490    pub(crate) done: FtDoneFreeTypeFn,
491    /// Resolved `FT_New_Face` function pointer for lazy style and CJK fallback face opening.
492    pub(crate) new_face: FtNewFaceFn,
493    /// Optional resolved `FT_Done_Face` function pointer invoked on eviction and `Drop`.
494    pub(crate) done_face: Option<FtDoneFaceFn>,
495    /// Lazily opened primary regular UI sans face (bound on first glyph miss, never on startup).
496    pub(crate) regular: FtLazyFace,
497    /// Lazily opened bold sans face (opened only on first bold glyph).
498    pub(crate) bold: FtLazyFace,
499    /// Lazily opened monospace face (opened only on first monospace glyph).
500    pub(crate) mono: FtLazyFace,
501    /// Lazily opened bold monospace face (opened only on first bold monospace glyph).
502    pub(crate) mono_bold: FtLazyFace,
503    /// Lazily opened CJK / Unicode fallback face (opened only when primary face misses a codepoint).
504    pub(crate) cjk: FtLazyFace,
505    /// Resolved `FT_Set_Pixel_Sizes` function pointer.
506    pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
507    /// Resolved `FT_Get_Char_Index` function pointer.
508    pub(crate) get_char_index: FtGetCharIndexFn,
509    /// Resolved `FT_Load_Glyph` function pointer.
510    pub(crate) load_glyph: FtLoadGlyphFn,
511    /// Lazily created Android NDK `AFontMatcher` handle (null on API < 29).
512    #[cfg(target_os = "android")]
513    pub(crate) matcher: *mut c_void,
514    /// Bounded Clock-LRU table of Android `AFontMatcher`-resolved fallback FreeType faces.
515    #[cfg(target_os = "android")]
516    pub(crate) android_fallbacks: [FtAndroidFallbackFace; ANDROID_FALLBACK_CACHE_SLOTS],
517    /// Clock eviction cursor for `android_fallbacks`.
518    #[cfg(target_os = "android")]
519    pub(crate) android_fallback_hand: usize,
520}
521
522/// Thread-local reusable offscreen `<canvas>` surfaces and pre-cached CSS font strings for zero-churn Web glyph rasterization.
523#[cfg(target_arch = "wasm32")]
524pub(crate) struct WebFontScratch {
525    /// Persistent CPU-backed (`willReadFrequently: true`) strip `<canvas>` for `<= 1` readback/frame software fallback.
526    pub(crate) readback_canvas: Option<HtmlCanvasElement>,
527    /// Cached 2D context bound to `readback_canvas`.
528    pub(crate) readback_ctx2d: Option<CanvasRenderingContext2d>,
529    /// Current allocated pixel width of `readback_canvas`.
530    pub(crate) readback_width: u32,
531    /// Current allocated pixel height of `readback_canvas`.
532    pub(crate) readback_height: u32,
533    /// Most recently applied packed `style_sig` on `readback_ctx2d` (`u32::MAX` when unset).
534    pub(crate) readback_last_sig: u32,
535    /// Persistent GPU-resident strip `<canvas>` for zero-readback WebGL2 `texSubImage2D` / WebGPU `copyExternalImageToTexture`.
536    pub(crate) gpu_canvas: Option<HtmlCanvasElement>,
537    /// Cached 2D context bound to `gpu_canvas`.
538    pub(crate) gpu_ctx2d: Option<CanvasRenderingContext2d>,
539    /// Current allocated pixel width of `gpu_canvas`.
540    pub(crate) gpu_width: u32,
541    /// Current allocated pixel height of `gpu_canvas`.
542    pub(crate) gpu_height: u32,
543    /// Most recently applied packed `style_sig` on `gpu_ctx2d` (`u32::MAX` when unset).
544    pub(crate) gpu_last_sig: u32,
545    /// Pre-cached CSS `font` strings keyed by `style_sig`, eliminating per-glyph `format!` allocations.
546    pub(crate) css_cache: WebCssFontCache,
547    /// Cumulative `getImageData` readbacks executed on the software fallback path.
548    pub(crate) total_readbacks: u64,
549    /// Cumulative zero-readback GPU strip batches prepared for WebGL2/WebGPU upload.
550    pub(crate) total_gpu_strip_batches: u64,
551}