Skip to content

Commit 4bfaf5f

Browse files
Parse cmap table 6
1 parent 1dd870b commit 4bfaf5f

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/font/grammar.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,14 @@ pub struct CMapFormat4 {
186186

187187
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
188188
pub struct CMapFormat6 {
189-
pub length: u16,
190189
pub language: u16,
191190
pub first_code: u16,
192-
pub entry_count: u16,
193191
pub glyph_index_array: Vec<u16>,
194192
}
195193

196194
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
197195
pub struct CMapFormat8 {
198196
// pub reserved: u16,
199-
pub length: u32,
200197
pub language: u32,
201198
pub is_32: [u8; 65536],
202199
pub groups: Vec<CMapIndividualGroup>,

src/font/parser.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BTreeMap;
22

33
use super::grammar::{
4-
CMapFormat0, CMapFormat4, CMapSubtable, ComponentGlyph, ComponentGlyphArgument,
4+
CMapFormat0, CMapFormat4, CMapFormat6, CMapSubtable, ComponentGlyph, ComponentGlyphArgument,
55
ComponentGlyphFlag, ComponentGlyphTransformation, F2Dot14, FWord, Fixed, FontDirectory, Glyph,
66
GlyphDescription, GlyphTable, HHeaTable, HMtxTable, HeadTable, LongDateTime,
77
LongHorizontalMetric, MaxPTable, OffsetSubTable, ScalarType, SimpleGlyphFlag, TableRecord,
@@ -306,6 +306,7 @@ impl<'a> TrueTypeFontParser<'a> {
306306
let subtable = match format {
307307
0 => CMapSubtable::Zero(self.parse_cmap_subtable_format_0()?),
308308
4 => CMapSubtable::Four(self.parse_cmap_subtable_format_4()?),
309+
6 => CMapSubtable::Six(self.parse_cmap_subtable_format_6()?),
309310
_ => todo!(),
310311
};
311312

@@ -326,8 +327,8 @@ impl<'a> TrueTypeFontParser<'a> {
326327

327328
length
328329
}
329-
4 => self.read_u16()? as usize,
330-
2 | 6 | 8 | 10 | 12 | 13 | 14 => todo!(),
330+
4 | 6 => self.read_u16()? as usize,
331+
2 | 8 | 10 | 12 | 13 | 14 => todo!(),
331332
foreign => bail!("Unexpected cmap format: {}.", foreign),
332333
};
333334

@@ -383,6 +384,19 @@ impl<'a> TrueTypeFontParser<'a> {
383384
})
384385
}
385386

387+
fn parse_cmap_subtable_format_6(&mut self) -> Result<CMapFormat6> {
388+
let language = self.read_u16()?;
389+
let first_code = self.read_u16()?;
390+
let entry_count = self.read_u16()?;
391+
let glyph_index_array = self.read_list(entry_count as usize, Self::read_u16)?;
392+
393+
Ok(CMapFormat6 {
394+
language,
395+
first_code,
396+
glyph_index_array,
397+
})
398+
}
399+
386400
fn parse_glyph_table(&mut self, num_glyphs: u16) -> Result<GlyphTable> {
387401
let mut glyphs = Vec::with_capacity(num_glyphs as usize);
388402

0 commit comments

Comments
 (0)