reflexo_typst2vec/
ir.rs

1use std::sync::Arc;
2
3use reflexo::hash::{item_hash128, Fingerprint};
4pub use reflexo::vector::ir::*;
5use ttf_parser::GlyphId;
6use typst::text::Font;
7
8/// A glyph item.
9#[derive(Debug, Clone, Hash, PartialEq, Eq)]
10pub enum GlyphItem {
11    /// A missing glyph.
12    None,
13
14    /// Raw glyph representation.
15    /// The raw glyphs is generated in lowering stage.
16    Raw(Font, GlyphId),
17
18    /// Glyphs in SVG or Bitmap format.
19    Image(Arc<ImageGlyphItem>),
20
21    /// Glyphs in path instructions, known as the "d" attribute of a
22    /// `<path/>` element.
23    Outline(Arc<OutlineGlyphItem>),
24}
25
26impl From<FlatGlyphItem> for GlyphItem {
27    fn from(item: FlatGlyphItem) -> Self {
28        match item {
29            FlatGlyphItem::Image(item) => GlyphItem::Image(item),
30            FlatGlyphItem::Outline(item) => GlyphItem::Outline(item),
31            FlatGlyphItem::None => GlyphItem::None,
32        }
33    }
34}
35
36impl GlyphItem {
37    #[comemo::memoize]
38    pub fn get_fingerprint(&self) -> Fingerprint {
39        Fingerprint::from_u128(item_hash128(self))
40    }
41}