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