cranpose_render_wgpu/text_system.rs
1use cranpose_render_common::text_fonts::TextFonts;
2
3/// The fonts a [`WgpuRenderer`](crate::WgpuRenderer) hands the app its text
4/// lays out and draws with.
5#[derive(Clone)]
6pub struct WgpuTextSystem {
7 fonts: TextFonts,
8}
9
10impl WgpuTextSystem {
11 /// Parses `fonts`, font file bytes ordered by priority with the first highest, into a text
12 /// system. Files that do not parse are skipped. When none parses, the text system holds the
13 /// embedded default font if the build has it, and no font otherwise.
14 pub fn from_fonts(fonts: &[&'static [u8]]) -> Self {
15 Self::from_text_fonts(TextFonts::from_fonts_or_default(fonts))
16 }
17
18 /// Adopt fonts an app already built, the path app-supplied families
19 /// take, where faces were parsed once at startup rather than from
20 /// static byte slices here.
21 pub fn from_text_fonts(fonts: TextFonts) -> Self {
22 Self { fonts }
23 }
24
25 pub(crate) fn fonts(&self) -> &TextFonts {
26 &self.fonts
27 }
28}