Skip to main content

euv_core/font/glyph/
impl.rs

1use super::*;
2
3/// Construction helpers for `GlyphKey`.
4impl GlyphKey {
5    /// Builds a quantized `GlyphKey` from a character, pixel size, and font weight.
6    ///
7    /// # Arguments
8    ///
9    /// - `char` - Character to rasterize.
10    /// - `f32` - Effective physical font size in pixels.
11    /// - `FontWeight` - Font weight determining bold synthesis.
12    ///
13    /// # Returns
14    ///
15    /// - `Self` - Quantized cache key.
16    #[must_use]
17    pub fn from_style(codepoint: char, physical_size: f32, weight: FontWeight) -> Self {
18        let clamped: f32 = physical_size.clamp(6.0, 256.0);
19        let size_tenths: u16 = (clamped * 10.0 + 0.5) as u16;
20        Self::new(codepoint, size_tenths, weight.is_bold())
21    }
22
23    /// Builds a quantized `GlyphKey` capturing size, weight, monospace family, and italic slant from `style`.
24    ///
25    /// # Arguments
26    ///
27    /// - `char` - Character to rasterize.
28    /// - `f32` - Effective physical font size in pixels.
29    /// - `TextStyle` - Active typography style.
30    ///
31    /// # Returns
32    ///
33    /// - `Self` - Quantized cache key distinguishing sans, monospace, bold, and italic faces.
34    #[must_use]
35    pub fn from_text_style(codepoint: char, physical_size: f32, style: TextStyle) -> Self {
36        let clamped: f32 = physical_size.clamp(6.0, 256.0);
37        let size_tenths: u16 = (clamped * 10.0 + 0.5) as u16;
38        Self {
39            codepoint,
40            size_tenths,
41            bold: style.get_weight().is_bold(),
42            monospace: style.get_family() == FontFamily::Monospace,
43            italic: style.get_italic(),
44        }
45    }
46}