diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-09-28 14:04:30 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-09-28 14:04:30 +0200 |
| commit | 13fe7b45490fa7f9056340e5257b18125c738605 (patch) | |
| tree | 3b256d3eb4f8fc7a0ec81955dbf3a7e31858df1c | |
| parent | e84cd13ce7c83e876c1fb55e4d452fc83767050d (diff) | |
Add `FontBook::from_infos`
| -rw-r--r-- | crates/typst/src/font/book.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/typst/src/font/book.rs b/crates/typst/src/font/book.rs index b758e585..38b9b421 100644 --- a/crates/typst/src/font/book.rs +++ b/crates/typst/src/font/book.rs @@ -22,15 +22,20 @@ impl FontBook { Self { families: BTreeMap::new(), infos: vec![] } } - /// Create a font book for a collection of fonts. - pub fn from_fonts<'a>(fonts: impl IntoIterator<Item = &'a Font>) -> Self { + /// Create a font book from a collection of font infos. + pub fn from_infos(infos: impl IntoIterator<Item = FontInfo>) -> Self { let mut book = Self::new(); - for font in fonts { - book.push(font.info().clone()); + for info in infos { + book.push(info); } book } + /// Create a font book for a collection of fonts. + pub fn from_fonts<'a>(fonts: impl IntoIterator<Item = &'a Font>) -> Self { + Self::from_infos(fonts.into_iter().map(|font| font.info().clone())) + } + /// Insert metadata into the font book. pub fn push(&mut self, info: FontInfo) { let index = self.infos.len(); |
