flash_font/parser.rs
1use std::collections::HashSet;
2use ttf_parser::{Face, name_id};
3
4pub fn get_font_family_names(font_data: &[u8]) -> HashSet<String> {
5 let font_count = ttf_parser::fonts_in_collection(font_data).unwrap_or(1);
6
7 (0..font_count)
8 .filter_map(|index| Face::parse(font_data, index).ok())
9 .flat_map(|face| {
10 face.names()
11 .into_iter()
12 .filter(|name| name.name_id == name_id::FAMILY)
13 .filter_map(|name| name.to_string())
14 })
15 .collect()
16}