From 13fe7b45490fa7f9056340e5257b18125c738605 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 28 Sep 2023 14:04:30 +0200 Subject: [PATCH] Add `FontBook::from_infos` --- crates/typst/src/font/book.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/typst/src/font/book.rs b/crates/typst/src/font/book.rs index b758e585a..38b9b4217 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) -> Self { + /// Create a font book from a collection of font infos. + pub fn from_infos(infos: impl IntoIterator) -> 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) -> 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();