diff --git a/src/ggg/chained_context.rs b/src/ggg/chained_context.rs index 8cf6f10..477ce0c 100644 --- a/src/ggg/chained_context.rs +++ b/src/ggg/chained_context.rs @@ -1,5 +1,5 @@ use super::{ClassDefinition, Coverage, SequenceLookupRecord}; -use crate::parser::{FromSlice, LazyArray16, LazyOffsetArray16, Stream}; +use crate::parser::{FromSlice, LazyArray16, LazyOffsetArray16, Offset, Offset16, Stream}; /// A [Chained Contextual Lookup Subtable]( /// https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#chseqctxt1). @@ -44,9 +44,16 @@ impl<'a> ChainedContextLookup<'a> { } 2 => { let coverage = Coverage::parse(s.read_at_offset16(data)?)?; - let backtrack_classes = ClassDefinition::parse(s.read_at_offset16(data)?)?; - let input_classes = ClassDefinition::parse(s.read_at_offset16(data)?)?; - let lookahead_classes = ClassDefinition::parse(s.read_at_offset16(data)?)?; + + let mut parse_func = || match s.read::>()? { + Some(offset) => Some(ClassDefinition::parse(data.get(offset.to_usize()..)?)?), + None => Some(ClassDefinition::Empty), + }; + + let backtrack_classes = parse_func()?; + let input_classes = parse_func()?; + let lookahead_classes = parse_func()?; + let count = s.read::()?; let offsets = s.read_array16(count)?; Some(Self::Format2 { diff --git a/src/ggg/mod.rs b/src/ggg/mod.rs index 1793e1d..8c6bd6a 100644 --- a/src/ggg/mod.rs +++ b/src/ggg/mod.rs @@ -132,6 +132,7 @@ pub enum ClassDefinition<'a> { Format2 { records: LazyArray16<'a, RangeRecord>, }, + Empty, } impl<'a> ClassDefinition<'a> { @@ -162,6 +163,7 @@ impl<'a> ClassDefinition<'a> { .checked_sub(start.0) .and_then(|index| classes.get(index)), Self::Format2 { records } => records.range(glyph).map(|record| record.value), + Self::Empty => Some(0), } .unwrap_or(0) }