euv_core/font/system/impl.rs
1use super::*;
2
3/// Default `NativeSystemFont` uses deterministic cross-platform rasterization.
4impl Default for NativeSystemFont {
5 /// Creates a deterministic `NativeSystemFont`.
6 ///
7 /// # Returns
8 ///
9 /// - `Self` - Deterministic font provider.
10 fn default() -> Self {
11 Self::deterministic()
12 }
13}
14
15/// Construction and mode helpers for `NativeSystemFont`.
16impl NativeSystemFont {
17 /// Creates a `NativeSystemFont` probing the active operating system's native font engine.
18 ///
19 /// # Returns
20 ///
21 /// - `Self` - Native OS font provider with automatic deterministic fallback.
22 #[must_use]
23 pub fn system() -> Self {
24 Self {
25 info: probe_system_font(),
26 deterministic_only: false,
27 }
28 }
29
30 /// Creates a deterministic cross-platform font provider guaranteeing identical pixels on every OS.
31 ///
32 /// # Returns
33 ///
34 /// - `Self` - Deterministic bitmap/stroke font provider.
35 #[must_use]
36 pub fn deterministic() -> Self {
37 Self {
38 info: SystemFontInfo::new(
39 FontRenderBackend::DeterministicBitmap,
40 FONT_FAMILY_DETERMINISTIC.to_string(),
41 true,
42 false,
43 ),
44 deterministic_only: true,
45 }
46 }
47}
48
49/// `SystemFontProvider` implementation delegating to OS native APIs with deterministic fallback.
50impl SystemFontProvider for NativeSystemFont {
51 /// Returns the active `SystemFontInfo`.
52 ///
53 /// # Arguments
54 ///
55 /// - `&Self` - Font provider reference.
56 ///
57 /// # Returns
58 ///
59 /// - `SystemFontInfo` - Provider capability descriptor.
60 fn font_info(&self) -> SystemFontInfo {
61 self.get_info().clone()
62 }
63
64 /// Rasterizes `key` via the native OS font engine, falling back to deterministic rasterization.
65 ///
66 /// # Arguments
67 ///
68 /// - `&Self` - Font provider reference.
69 /// - `GlyphKey` - Quantized glyph descriptor.
70 ///
71 /// # Returns
72 ///
73 /// - `Option<RasterizedGlyph>` - Rasterized alpha8 coverage bitmap.
74 fn rasterize(&self, key: GlyphKey) -> Option<RasterizedGlyph> {
75 if !self.get_deterministic_only()
76 && let Some(native_glyph) = rasterize_native_glyph(key)
77 {
78 return Some(native_glyph);
79 }
80 Some(rasterize_glyph(key))
81 }
82}