ttf_parser/tables/cmap/
format13.rs

1// https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-13-many-to-one-range-mappings
2
3use core::convert::TryFrom;
4
5use crate::parser::Stream;
6
7pub fn parse(data: &[u8], code_point: u32) -> Option<u16> {
8    let mut s = Stream::new(data);
9    s.skip::<u16>(); // format
10    s.skip::<u16>(); // reserved
11    s.skip::<u32>(); // length
12    s.skip::<u32>(); // language
13    let count: u32 = s.read()?;
14    let groups = s.read_array32::<super::format12::SequentialMapGroup>(count)?;
15    for group in groups {
16        let start_char_code = group.start_char_code;
17        if code_point >= start_char_code && code_point <= group.end_char_code {
18            return u16::try_from(group.start_glyph_id).ok();
19        }
20    }
21
22    None
23}
24
25pub fn codepoints(data: &[u8], f: impl FnMut(u32)) -> Option<()> {
26    // Only the glyph id mapping differs for this table. The code points are the
27    // same as for format 12.
28    super::format12::codepoints(data, f)
29}