zng_view_api/
font.rs

1//! Font types.
2
3use serde::{Deserialize, Serialize};
4use zng_unit::Px;
5
6use crate::{config::FontAntiAliasing, declare_id};
7
8declare_id! {
9    /// Font resource in a renderer cache.
10    ///
11    /// The View Process defines the ID.
12    pub struct FontFaceId(_);
13
14    /// Sized font in a renderer.
15    ///
16    /// The View Process defines the ID.
17    pub struct FontId(_);
18}
19
20/// Extra font options.
21#[derive(Default, Debug, PartialEq, Clone, Deserialize, Serialize)]
22#[non_exhaustive]
23pub struct FontOptions {
24    /// Font render mode.
25    ///
26    /// Default value must be already resolved here, it falls back to Subpixel.
27    pub aa: FontAntiAliasing,
28
29    /// If synthetic bold is enabled.
30    pub synthetic_bold: bool,
31    /// If synthetic skew is enabled.
32    pub synthetic_oblique: bool,
33}
34impl FontOptions {
35    /// New font options.
36    pub fn new(aa: FontAntiAliasing, synthetic_bold: bool, synthetic_oblique: bool) -> Self {
37        Self {
38            aa,
39            synthetic_bold,
40            synthetic_oblique,
41        }
42    }
43}
44
45/// Extra font options send with text glyphs.
46pub type GlyphOptions = FontOptions;
47
48/// Font feature name, `*b"hlig"` for example.
49pub type FontVariationName = [u8; 4];
50
51/// Glyph index with position.
52#[repr(C)]
53#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
54#[non_exhaustive]
55pub struct GlyphInstance {
56    /// Glyph id.
57    pub index: GlyphIndex,
58    /// Glyph position.
59    pub point: euclid::Point2D<f32, Px>,
60}
61impl GlyphInstance {
62    /// New glyph.
63    pub fn new(index: GlyphIndex, point: euclid::Point2D<f32, Px>) -> Self {
64        Self { index, point }
65    }
66}
67
68/// Glyph index in a font.
69pub type GlyphIndex = u32;