Skip to content

Commit

Permalink
Allow NULL offsets in ChainedContextLookup v2
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV authored Jun 16, 2024
1 parent 9bbd432 commit 46a0b9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ggg/chained_context.rs
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -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::<Option<Offset16>>()? {
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::<u16>()?;
let offsets = s.read_array16(count)?;
Some(Self::Format2 {
Expand Down
2 changes: 2 additions & 0 deletions src/ggg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum ClassDefinition<'a> {
Format2 {
records: LazyArray16<'a, RangeRecord>,
},
Empty,
}

impl<'a> ClassDefinition<'a> {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 46a0b9e

Please sign in to comment.