typst 0.14.2.2 → 0.15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +0,0 @@
1
- use std::cell::OnceCell;
2
- use std::fs::{self};
3
- use std::path::PathBuf;
4
-
5
- use fontdb::{Database, Source};
6
- use typst::font::{Font, FontBook, FontInfo};
7
-
8
- /// Searches for fonts.
9
- pub struct FontSearcher {
10
- // Metadata about all discovered fonts.
11
- pub book: FontBook,
12
- /// Slots that the fonts are loaded into.
13
- pub fonts: Vec<FontSlot>,
14
- }
15
-
16
- /// Holds details about the location of a font and lazily the font itself.
17
- pub struct FontSlot {
18
- /// The path at which the font can be found on the system.
19
- path: PathBuf,
20
- /// The index of the font in its collection. Zero if the path does not point
21
- /// to a collection.
22
- index: u32,
23
- /// The lazily loaded font.
24
- font: OnceCell<Option<Font>>,
25
- }
26
-
27
- impl FontSlot {
28
- /// Get the font for this slot.
29
- pub fn get(&self) -> Option<Font> {
30
- self.font
31
- .get_or_init(|| {
32
- let data = fs::read(&self.path).ok()?.into();
33
- Font::new(data, self.index)
34
- })
35
- .clone()
36
- }
37
- }
38
-
39
- impl FontSearcher {
40
- /// Create a new, empty system searcher.
41
- pub fn new() -> Self {
42
- Self {
43
- book: FontBook::new(),
44
- fonts: vec![],
45
- }
46
- }
47
-
48
- /// Search everything that is available.
49
- pub fn search(&mut self, font_dirs: &[PathBuf], font_files: &[PathBuf]) {
50
- let mut db = Database::new();
51
-
52
- // Font paths have highest priority.
53
- for path in font_dirs {
54
- db.load_fonts_dir(path);
55
- }
56
-
57
- // System fonts have second priority.
58
- db.load_system_fonts();
59
-
60
- for path in font_files {
61
- let _ret = db.load_font_file(path).ok();
62
- }
63
-
64
- for face in db.faces() {
65
- let path = match &face.source {
66
- Source::File(path) | Source::SharedFile(path, _) => path,
67
- // We never add binary sources to the database, so there
68
- // shouln't be any.
69
- Source::Binary(_) => continue,
70
- };
71
-
72
- let info = db
73
- .with_face_data(face.id, FontInfo::new)
74
- .expect("database must contain this font");
75
-
76
- if let Some(info) = info {
77
- self.book.push(info);
78
- self.fonts.push(FontSlot {
79
- path: path.clone(),
80
- index: face.index,
81
- font: OnceCell::new(),
82
- });
83
- }
84
- }
85
- }
86
- }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file