1use super::*;
2
3#[derive(Clone, Debug, Eq, Getter, New, PartialEq)]
5pub struct SystemFontInfo {
6 #[get(type(copy))]
8 pub(crate) backend: FontRenderBackend,
9 pub(crate) family_name: String,
11 #[get(type(copy))]
13 pub(crate) supports_unicode: bool,
14 #[get(type(copy))]
16 pub(crate) supports_antialiasing: bool,
17}
18
19#[derive(Clone, Debug, Getter)]
21pub struct NativeSystemFont {
22 pub(crate) info: SystemFontInfo,
24 #[get(type(copy))]
26 pub(crate) deterministic_only: bool,
27}
28
29#[derive(Clone, Debug, Getter, New)]
31pub struct PackedGlyphAtlas {
32 #[get(type(copy))]
34 pub(crate) width: u32,
35 #[get(type(copy))]
37 pub(crate) height: u32,
38 pub(crate) pixels: Vec<u8>,
40 pub(crate) regions: HashMap<GlyphKey, (u32, u32, u32, u32)>,
42 #[get(type(copy))]
44 pub(crate) revision: u64,
45}
46
47#[derive(Clone, Copy, Debug, Default, Eq, Getter, New, PartialEq)]
49pub struct GlyphStripPlacement {
50 #[get(type(copy))]
52 pub(crate) key: GlyphKey,
53 #[get(type(copy))]
55 pub(crate) x: u32,
56 #[get(type(copy))]
58 pub(crate) y: u32,
59 #[get(type(copy))]
61 pub(crate) width: u32,
62 #[get(type(copy))]
64 pub(crate) height: u32,
65 #[get(type(copy))]
67 pub(crate) advance: u32,
68}
69
70#[derive(Clone, Debug, Default, Eq, Getter, New, PartialEq)]
72pub struct WebGlyphStripBatch {
73 #[get(type(copy))]
75 pub(crate) strip_width: u32,
76 #[get(type(copy))]
78 pub(crate) strip_height: u32,
79 pub(crate) placements: Vec<GlyphStripPlacement>,
81 #[get(type(copy))]
83 pub(crate) readbacks_performed: u32,
84}
85
86#[derive(Clone, Debug, Default, Getter)]
88pub struct WebCssFontCache {
89 #[get(skip)]
91 pub(crate) entries: Vec<(u32, String)>,
92 #[get(skip)]
94 pub(crate) evict_cursor: usize,
95 #[get(type(copy))]
97 pub(crate) hits: u64,
98 #[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#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
149#[derive(Clone, Copy)]
150pub(crate) struct CoreTextFontCacheEntry {
151 pub(crate) style_sig: u32,
153 pub(crate) referenced: bool,
155 pub(crate) font: *mut c_void,
157 pub(crate) ascent: f64,
159 pub(crate) descent: f64,
161 pub(crate) fallback_fonts: [*mut c_void; CORETEXT_FALLBACK_SLOTS],
163}
164
165#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
167pub(crate) struct CoreTextFontCache {
168 pub(crate) gray_space: *mut c_void,
170 pub(crate) scratch_ctx: *mut c_void,
172 pub(crate) scratch_buf: Vec<u8>,
174 pub(crate) scratch_w: usize,
176 pub(crate) scratch_h: usize,
178 pub(crate) count: usize,
180 pub(crate) clock_hand: usize,
182 pub(crate) index: [u8; CORETEXT_FONT_INDEX_CAP],
184 pub(crate) slots: [CoreTextFontCacheEntry; CORETEXT_FONT_CACHE_SLOTS],
186}
187
188#[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#[cfg(target_os = "windows")]
201#[derive(Clone, Copy)]
202pub(crate) struct DirectWriteLib {
203 pub(crate) create_factory: WinDWriteCreateFactoryFn,
205}
206
207#[cfg(target_os = "windows")]
209#[derive(Clone, Copy)]
210pub(crate) struct Win32FontCacheEntry {
211 pub(crate) style_sig: u32,
213 pub(crate) referenced: bool,
215 pub(crate) hfont: *mut c_void,
217 pub(crate) ascent: i32,
219 pub(crate) descent: i32,
221}
222
223#[cfg(target_os = "windows")]
225pub(crate) struct Win32FontCache {
226 pub(crate) hdc: *mut c_void,
228 pub(crate) dwrite_attempted: bool,
230 pub(crate) dwrite_factory: *mut c_void,
232 pub(crate) count: usize,
234 pub(crate) clock_hand: usize,
236 pub(crate) index: [u8; WIN32_FONT_INDEX_CAP],
238 pub(crate) slots: [Win32FontCacheEntry; WIN32_FONT_CACHE_SLOTS],
240 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#[cfg(any(target_os = "linux", target_os = "android"))]
428#[derive(Clone, Copy)]
429pub(crate) struct FreeTypeLib {
430 pub(crate) handle_addr: usize,
432 pub(crate) init: FtInitFreeTypeFn,
434 pub(crate) done: FtDoneFreeTypeFn,
436 pub(crate) new_face: FtNewFaceFn,
438 pub(crate) done_face: Option<FtDoneFaceFn>,
440 pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
442 pub(crate) set_char_size: Option<FtSetCharSizeFn>,
444 pub(crate) get_char_index: FtGetCharIndexFn,
446 pub(crate) load_glyph: FtLoadGlyphFn,
448}
449
450#[cfg(target_os = "android")]
452#[derive(Clone, Copy)]
453pub(crate) struct AndroidFontMatcherLib {
454 pub(crate) handle_addr: usize,
456 pub(crate) create: AFontMatcherCreateFn,
458 pub(crate) destroy: AFontMatcherDestroyFn,
460 pub(crate) set_style: AFontMatcherSetStyleFn,
462 pub(crate) match_font: AFontMatcherMatchFn,
464 pub(crate) font_file_path: AFontGetFilePathFn,
466 pub(crate) collection_index: AFontGetCollectionIndexFn,
468 pub(crate) font_close: AFontCloseFn,
470}
471
472#[cfg(target_os = "android")]
474#[derive(Clone, Copy)]
475pub(crate) struct FtAndroidFallbackFace {
476 pub(crate) path_hash: u64,
478 pub(crate) collection_index: u32,
480 pub(crate) referenced: bool,
482 pub(crate) slot: FtLazyFace,
484}
485
486#[cfg(any(target_os = "linux", target_os = "android"))]
488#[derive(Clone, Copy)]
489pub(crate) struct FtLazyFace {
490 pub(crate) probed: bool,
492 pub(crate) face: *mut FtFaceRec,
494 pub(crate) last_size_tenths: u32,
496}
497
498#[cfg(any(target_os = "linux", target_os = "android"))]
500pub(crate) struct FreeTypeRuntime {
501 pub(crate) library: *mut c_void,
503 pub(crate) done: FtDoneFreeTypeFn,
505 pub(crate) new_face: FtNewFaceFn,
507 pub(crate) done_face: Option<FtDoneFaceFn>,
509 pub(crate) regular: FtLazyFace,
511 pub(crate) bold: FtLazyFace,
513 pub(crate) mono: FtLazyFace,
515 pub(crate) mono_bold: FtLazyFace,
517 pub(crate) cjk: FtLazyFace,
519 pub(crate) set_pixel_sizes: FtSetPixelSizesFn,
521 pub(crate) set_char_size: Option<FtSetCharSizeFn>,
523 pub(crate) get_char_index: FtGetCharIndexFn,
525 pub(crate) load_glyph: FtLoadGlyphFn,
527 #[cfg(target_os = "android")]
529 pub(crate) matcher: *mut c_void,
530 #[cfg(target_os = "android")]
532 pub(crate) android_fallbacks: [FtAndroidFallbackFace; ANDROID_FALLBACK_CACHE_SLOTS],
533 #[cfg(target_os = "android")]
535 pub(crate) android_fallback_hand: usize,
536}
537
538#[cfg(target_arch = "wasm32")]
540pub(crate) struct WebFontScratch {
541 pub(crate) readback_canvas: Option<HtmlCanvasElement>,
543 pub(crate) readback_ctx2d: Option<CanvasRenderingContext2d>,
545 pub(crate) readback_width: u32,
547 pub(crate) readback_height: u32,
549 pub(crate) readback_last_sig: u32,
551 pub(crate) gpu_canvas: Option<HtmlCanvasElement>,
553 pub(crate) gpu_ctx2d: Option<CanvasRenderingContext2d>,
555 pub(crate) gpu_width: u32,
557 pub(crate) gpu_height: u32,
559 pub(crate) gpu_last_sig: u32,
561 pub(crate) css_cache: WebCssFontCache,
563 pub(crate) total_readbacks: u64,
565 pub(crate) total_gpu_strip_batches: u64,
567}