ttf_parser/tables/cmap/
format10.rs1use crate::parser::{LazyArray32, Stream};
2use crate::GlyphId;
3
4#[derive(Clone, Copy, Debug)]
7pub struct Subtable10<'a> {
8 pub first_code_point: u32,
10 pub glyphs: LazyArray32<'a, GlyphId>,
12}
13
14impl<'a> Subtable10<'a> {
15 pub fn parse(data: &'a [u8]) -> Option<Self> {
17 let mut s = Stream::new(data);
18 s.skip::<u16>(); s.skip::<u16>(); s.skip::<u32>(); s.skip::<u32>(); let first_code_point = s.read::<u32>()?;
23 let count = s.read::<u32>()?;
24 let glyphs = s.read_array32::<GlyphId>(count)?;
25 Some(Self { first_code_point, glyphs })
26 }
27
28 pub fn glyph_index(&self, code_point: u32) -> Option<GlyphId> {
30 let idx = code_point.checked_sub(self.first_code_point)?;
31 self.glyphs.get(idx)
32 }
33
34 pub fn codepoints(&self, mut f: impl FnMut(u32)) {
36 for i in 0..self.glyphs.len() {
37 if let Some(code_point) = self.first_code_point.checked_add(i) {
38 f(code_point);
39 }
40 }
41 }
42}