tinymist_world/font/
partial_book.rs

1use core::fmt;
2
3use typst::text::{FontFlags, FontInfo, FontVariant};
4
5use crate::font::FontSlot;
6
7#[derive(Clone, Debug, Hash, PartialEq, Eq)]
8pub struct FontInfoKey {
9    pub family: String,
10    pub variant: FontVariant,
11    pub flags: FontFlags,
12}
13
14impl From<&FontInfo> for FontInfoKey {
15    fn from(info: &FontInfo) -> Self {
16        Self {
17            family: info.family.clone(),
18            variant: info.variant,
19            flags: info.flags,
20        }
21    }
22}
23
24#[derive(Debug, Default)]
25pub struct PartialFontBook {
26    pub revision: usize,
27    pub partial_hit: bool,
28    pub changes: Vec<(Option<usize>, FontInfo, FontSlot)>,
29}
30
31impl PartialFontBook {
32    pub fn push(&mut self, change: (Option<usize>, FontInfo, FontSlot)) {
33        self.partial_hit = true;
34        self.changes.push(change);
35    }
36}
37
38impl fmt::Display for PartialFontBook {
39    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40        for (idx, info, slot) in &self.changes {
41            writeln!(
42                f,
43                "{:?}: {} -> {:?}\n",
44                idx,
45                info.family,
46                slot.get_uninitialized()
47            )?;
48        }
49
50        Ok(())
51    }
52}