Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

FileRef::fonts() would be more handy if Iterator would work like enumerate() #1236

Open
drott opened this issue Nov 13, 2024 · 1 comment
Open

Comments

@drott
Copy link
Contributor

drott commented Nov 13, 2024

FileRef::fonts() returns:

https://docs.rs/read-fonts/latest/src/read_fonts/lib.rs.html#201-207

pub fn fonts(
&self,
) -> impl Iterator<Item = Result<FontRef<'a>, ReadError>> + 'a + Clone

It would be slightly more handy if this was a flattened list of (FontRef, Option<u32>) containing the collection indices - otherwise one can't tell from each FontRef what it originates from.

@drott
Copy link
Contributor Author

drott commented Nov 14, 2024

Perhaps something like

let (iter_one, iter_two) = match fileref {
        Some(Font(font)) => (Some((Ok(font.clone()), None)), None),
        Some(Collection(collection)) => (
            None,
            Some(
                collection
                    .iter()
                    .enumerate()
                    .map(|entry| (entry.1, Some(entry.0 as i32))),
            ),
        ),
        None => (None, None),
    };
    let fonts = iter_two.into_iter().flatten().chain(iter_one);

But instead, perhaps the collection.iter() should already have the ttc indices so we don't have to generate them with enumerate().

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant