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 {
26 first_code_point,
27 glyphs,
28 })
29 }
30
31 pub fn glyph_index(&self, code_point: u32) -> Option<GlyphId> {
33 let idx = code_point.checked_sub(self.first_code_point)?;
34 self.glyphs.get(idx)
35 }
36
37 pub fn codepoints(&self, mut f: impl FnMut(u32)) {
39 for i in 0..self.glyphs.len() {
40 if let Some(code_point) = self.first_code_point.checked_add(i) {
41 f(code_point);
42 }
43 }
44 }
45}