ttf_parser/tables/cmap/
format10.rs

1// https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-10-trimmed-array
2
3use crate::parser::Stream;
4
5pub fn parse(data: &[u8], code_point: u32) -> Option<u16> {
6    let mut s = Stream::new(data);
7    s.skip::<u16>(); // format
8    s.skip::<u16>(); // reserved
9    s.skip::<u32>(); // length
10    s.skip::<u32>(); // language
11    let first_code_point: u32 = s.read()?;
12    let count: u32 = s.read()?;
13    let glyphs = s.read_array32::<u16>(count)?;
14
15    let idx = code_point.checked_sub(first_code_point)?;
16    glyphs.get(idx)
17}
18
19pub fn codepoints(data: &[u8], mut f: impl FnMut(u32)) -> Option<()> {
20    let mut s = Stream::new(data);
21    s.skip::<u16>(); // format
22    s.skip::<u16>(); // reserved
23    s.skip::<u32>(); // length
24    s.skip::<u32>(); // language
25    let first_code_point: u32 = s.read()?;
26    let count: u32 = s.read()?;
27
28    for i in 0..count {
29        let code_point = first_code_point.checked_add(i)?;
30        f(code_point);
31    }
32
33    Some(())
34}