tinymist_world/font/
cache.rs1use serde::{Deserialize, Serialize};
2use sha2::{Digest, Sha256};
3use typst::text::FontInfo;
4
5#[derive(Serialize, Deserialize)]
6#[serde(tag = "t", content = "v")]
7pub enum CacheCondition {
8 Sha256(String),
9}
10
11#[derive(Serialize, Deserialize)]
12pub struct FontInfoCache {
13 pub info: Vec<FontInfo>,
14 pub conditions: Vec<CacheCondition>,
15}
16
17impl FontInfoCache {
18 pub fn from_data(buffer: &[u8]) -> Self {
19 let hash = hex::encode(Sha256::digest(buffer));
20
21 FontInfoCache {
22 info: FontInfo::iter(buffer).collect(),
23 conditions: vec![CacheCondition::Sha256(hash)],
24 }
25 }
26}