Skip to main content

rustex_lib/engine/
fonts.rs

1use tex_engine::engine::filesystem::FileSystem;
2use tex_engine::engine::fontsystem::{Font, FontSystem as FontSystemT};
3use tex_engine::engine::{EngineAux, EngineTypes};
4use tex_engine::tex::numerics::Dim32;
5use tex_engine::tex::tokens::control_sequences::InternedCSName;
6
7pub(crate) type FontStore = tex_glyphs::encodings::FontInfoStore<String, fn(&str) -> String>;
8
9fn get(s: &str) -> String {
10    match tex_engine::engine::filesystem::kpathsea::KPATHSEA.which(s) {
11        Some(p) => p.display().to_string(),
12        None => s.to_string(),
13    }
14}
15#[derive(Clone, Debug)]
16pub struct Fontsystem {
17    fs: tex_engine::engine::fontsystem::TfmFontSystem<i32, Dim32, InternedCSName<u8>>,
18    pub glyphmaps: FontStore,
19}
20impl FontSystemT for Fontsystem {
21    type Char = u8;
22    type Int = i32;
23    type Font = tex_engine::engine::fontsystem::TfmFont<i32, Dim32, InternedCSName<u8>>;
24    type Dim = Dim32;
25    type CS = InternedCSName<u8>;
26    fn new<ET: EngineTypes<Char = Self::Char, CSName = Self::CS>>(aux: &mut EngineAux<ET>) -> Self {
27        Fontsystem {
28            fs: tex_engine::engine::fontsystem::TfmFontSystem::new(aux),
29            glyphmaps: FontStore::new(get),
30        }
31    }
32
33    fn new_font<S: AsRef<str>, F: FileSystem>(
34        &mut self,
35        path: S,
36        macroname: <Self::Font as Font>::CS,
37        fs: &mut F,
38    ) -> Self::Font {
39        self.fs.new_font(path, macroname, fs)
40    }
41
42    fn null(&self) -> Self::Font {
43        self.fs.null()
44    }
45}