mirror of
https://github.com/typst/typst
synced 2025-05-17 10:35:28 +08:00
Add FontBook::from_infos
This commit is contained in:
parent
e84cd13ce7
commit
13fe7b4549
@ -22,15 +22,20 @@ impl FontBook {
|
|||||||
Self { families: BTreeMap::new(), infos: vec![] }
|
Self { families: BTreeMap::new(), infos: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a font book for a collection of fonts.
|
/// Create a font book from a collection of font infos.
|
||||||
pub fn from_fonts<'a>(fonts: impl IntoIterator<Item = &'a Font>) -> Self {
|
pub fn from_infos(infos: impl IntoIterator<Item = FontInfo>) -> Self {
|
||||||
let mut book = Self::new();
|
let mut book = Self::new();
|
||||||
for font in fonts {
|
for info in infos {
|
||||||
book.push(font.info().clone());
|
book.push(info);
|
||||||
}
|
}
|
||||||
book
|
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.
|
/// Insert metadata into the font book.
|
||||||
pub fn push(&mut self, info: FontInfo) {
|
pub fn push(&mut self, info: FontInfo) {
|
||||||
let index = self.infos.len();
|
let index = self.infos.len();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user