alexheretic / ab-glyph

Rust API for loading, scaling, positioning and rasterizing OpenType font glyphs
Apache License 2.0
372 stars 24 forks source link

How to get `fonts_in_collection` #53

Closed keiya01 closed 2 years ago

keiya01 commented 2 years ago

I want to load multiple font data. When load font data, output the following error.

thread 'main' panicked at 'Invalid glyph_ver_side_bearing', /Users/keiya/.cargo/registry/src/github.com-1ecc6299db9ec823/ab_glyph-0.2.12/src/ttfp.rs:334:1

I'm using try_from_slice_and_index to load some font data. But I don't know how to get next index. If fonts_in_collection is exported, I should be able to get next index.

Is there the way to get fonts collection length like the following ?

let i = owned_ttf_parser::fonts_in_collection().unwrap_or(0);
match FontRef::try_from_slice_and_index(data, i) {
    Ok(font) => Ok(font),
    Err(_) => Err(Error::InvalidFontBytes),
}

Thank you.