ttf_parser/tables/cmap/
format6.rs
1use core::convert::TryFrom;
4
5use crate::parser::Stream;
6
7pub fn parse(data: &[u8], code_point: u32) -> Option<u16> {
8 let code_point = u16::try_from(code_point).ok()?;
10
11 let mut s = Stream::new(data);
12 s.skip::<u16>(); s.skip::<u16>(); s.skip::<u16>(); let first_code_point: u16 = s.read()?;
16 let count: u16 = s.read()?;
17 let glyphs = s.read_array16::<u16>(count)?;
18
19 let idx = code_point.checked_sub(first_code_point)?;
20 glyphs.get(idx)
21}
22
23pub fn codepoints(data: &[u8], mut f: impl FnMut(u32)) -> Option<()> {
24 let mut s = Stream::new(data);
25 s.skip::<u16>(); s.skip::<u16>(); s.skip::<u16>(); let first_code_point: u16 = s.read()?;
29 let count: u16 = s.read()?;
30
31 for i in 0..count {
32 let code_point = first_code_point.checked_add(i)?;
33 f(u32::from(code_point));
34 }
35
36 Some(())
37}