rootvg_text/
lib.rs

1use once_cell::sync::OnceCell;
2use std::sync::RwLock;
3
4pub use glyphon;
5
6pub use glyphon::cosmic_text::Align;
7pub use glyphon::{Attrs, Family, FamilyOwned, Metrics, Shaping, Stretch, Style, Weight, Wrap};
8
9mod buffer;
10mod primitive;
11mod properties;
12
13pub mod pipeline;
14
15pub use buffer::RcTextBuffer;
16pub use primitive::TextPrimitive;
17pub use properties::TextProperties;
18
19/// Returns the global [`FontSystem`].
20pub fn font_system() -> &'static RwLock<FontSystem> {
21    static FONT_SYSTEM: OnceCell<RwLock<FontSystem>> = OnceCell::new();
22
23    FONT_SYSTEM.get_or_init(|| {
24        RwLock::new(FontSystem {
25            raw: glyphon::FontSystem::new(),
26        })
27    })
28}
29
30static WRITE_LOCK_PANIC_MSG: &'static str = "Failed to obtain write lock on font system";
31
32/// A set of system fonts.
33pub struct FontSystem {
34    raw: glyphon::FontSystem,
35}
36
37impl FontSystem {
38    /// Returns the raw [`glyphon::FontSystem`].
39    pub fn raw(&self) -> &glyphon::FontSystem {
40        &self.raw
41    }
42
43    /// Returns the raw [`glyphon::FontSystem`].
44    pub fn raw_mut(&mut self) -> &mut glyphon::FontSystem {
45        &mut self.raw
46    }
47}