From b4b022940b908d8fe490b9f4f68bc60dcfb76cd2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 19 Dec 2022 01:16:35 +0100 Subject: Syntax and example sections --- src/font/book.rs | 4 ++-- src/font/mod.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/font') diff --git a/src/font/book.rs b/src/font/book.rs index 2ad30f1d..38dfee1d 100644 --- a/src/font/book.rs +++ b/src/font/book.rs @@ -170,7 +170,7 @@ bitflags::bitflags! { impl FontInfo { /// Compute metadata for all fonts in the given data. - pub fn from_data(data: &[u8]) -> impl Iterator + '_ { + pub fn iter(data: &[u8]) -> impl Iterator + '_ { let count = ttf_parser::fonts_in_collection(data).unwrap_or(1); (0..count).filter_map(move |index| { let ttf = ttf_parser::Face::parse(data, index).ok()?; @@ -179,7 +179,7 @@ impl FontInfo { } /// Compute metadata for a single ttf-parser face. - pub fn from_ttf(ttf: &ttf_parser::Face) -> Option { + pub(super) fn from_ttf(ttf: &ttf_parser::Face) -> Option { // We cannot use Name ID 16 "Typographic Family", because for some // fonts it groups together more than just Style / Weight / Stretch // variants (e.g. Display variants of Noto fonts) and then some diff --git a/src/font/mod.rs b/src/font/mod.rs index 98875d8f..13189b6d 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -69,6 +69,12 @@ impl Font { }))) } + /// Parse all fonts in the given data. + pub fn iter(data: Buffer) -> impl Iterator { + let count = ttf_parser::fonts_in_collection(&data).unwrap_or(1); + (0..count).filter_map(move |index| Self::new(data.clone(), index)) + } + /// The underlying buffer. pub fn data(&self) -> &Buffer { &self.0.data -- cgit v1.2.3