Skip to content

Commit 23d6f01

Browse files
committed
use our own SequenceLookupRecord
1 parent 1e9b19a commit 23d6f01

File tree

2 files changed

+15
-51
lines changed

2 files changed

+15
-51
lines changed

src/hb/fonta/ot/contextual.rs

+11-48
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::hb::ot_layout_gsubgpos::{
66
};
77
use skrifa::raw::tables::layout::{
88
ChainedSequenceContextFormat1, ChainedSequenceContextFormat2, ChainedSequenceContextFormat3,
9-
SequenceContextFormat1, SequenceContextFormat2, SequenceContextFormat3,
9+
SequenceContextFormat1, SequenceContextFormat2, SequenceContextFormat3, SequenceLookupRecord,
1010
};
1111
use skrifa::raw::types::BigEndian;
12-
use ttf_parser::{opentype_layout::SequenceLookupRecord, GlyphId};
12+
use ttf_parser::GlyphId;
1313

1414
impl WouldApply for SequenceContextFormat1<'_> {
1515
fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
@@ -47,19 +47,7 @@ impl Apply for SequenceContextFormat1<'_> {
4747
let set = self.seq_rule_sets().get(index)?.ok()?;
4848
for rule in set.seq_rules().iter().filter_map(|rule| rule.ok()) {
4949
let input = rule.input_sequence();
50-
if apply_context(
51-
ctx,
52-
input,
53-
&match_glyph,
54-
rule.seq_lookup_records()
55-
.iter()
56-
.map(|rec| SequenceLookupRecord {
57-
sequence_index: rec.sequence_index(),
58-
lookup_list_index: rec.lookup_list_index(),
59-
}),
60-
)
61-
.is_some()
62-
{
50+
if apply_context(ctx, input, &match_glyph, rule.seq_lookup_records()).is_some() {
6351
return Some(());
6452
}
6553
}
@@ -107,12 +95,7 @@ impl Apply for SequenceContextFormat2<'_> {
10795
ctx,
10896
input,
10997
&match_class(&input_classes),
110-
rule.seq_lookup_records()
111-
.iter()
112-
.map(|rec| SequenceLookupRecord {
113-
sequence_index: rec.sequence_index(),
114-
lookup_list_index: rec.lookup_list_index(),
115-
}),
98+
rule.seq_lookup_records(),
11699
)
117100
.is_some()
118101
{
@@ -165,12 +148,7 @@ impl Apply for SequenceContextFormat3<'_> {
165148
input_coverages.len() - 1,
166149
&mut match_positions,
167150
match_end,
168-
self.seq_lookup_records()
169-
.iter()
170-
.map(|rec| SequenceLookupRecord {
171-
sequence_index: rec.sequence_index(),
172-
lookup_list_index: rec.lookup_list_index(),
173-
}),
151+
self.seq_lookup_records(),
174152
);
175153
Some(())
176154
} else {
@@ -225,12 +203,7 @@ impl Apply for ChainedSequenceContextFormat1<'_> {
225203
input,
226204
lookahead,
227205
[&match_glyph; 3],
228-
rule.seq_lookup_records()
229-
.iter()
230-
.map(|rec| SequenceLookupRecord {
231-
sequence_index: rec.sequence_index(),
232-
lookup_list_index: rec.lookup_list_index(),
233-
}),
206+
rule.seq_lookup_records(),
234207
)
235208
.is_some()
236209
{
@@ -310,12 +283,7 @@ impl Apply for ChainedSequenceContextFormat2<'_> {
310283
&match_class(&input_classes),
311284
&match_class(&lookahead_classes),
312285
],
313-
rule.seq_lookup_records()
314-
.iter()
315-
.map(|rec| SequenceLookupRecord {
316-
sequence_index: rec.sequence_index(),
317-
lookup_list_index: rec.lookup_list_index(),
318-
}),
286+
rule.seq_lookup_records(),
319287
)
320288
.is_some()
321289
{
@@ -426,12 +394,7 @@ impl Apply for ChainedSequenceContextFormat3<'_> {
426394
input_coverages.len() - 1,
427395
&mut match_positions,
428396
match_end,
429-
self.seq_lookup_records()
430-
.iter()
431-
.map(|rec| SequenceLookupRecord {
432-
sequence_index: rec.sequence_index(),
433-
lookup_list_index: rec.lookup_list_index(),
434-
}),
397+
self.seq_lookup_records(),
435398
);
436399

437400
Some(())
@@ -458,7 +421,7 @@ fn apply_context<T: ToU16>(
458421
ctx: &mut hb_ot_apply_context_t,
459422
input: &[T],
460423
match_func: &match_func_t,
461-
lookups: impl Iterator<Item = SequenceLookupRecord>,
424+
lookups: &[SequenceLookupRecord],
462425
) -> Option<()> {
463426
let match_func = |glyph, index| {
464427
let value = input.get(index as usize).unwrap().to_u16();
@@ -483,7 +446,7 @@ fn apply_context<T: ToU16>(
483446
usize::from(input.len()),
484447
&mut match_positions,
485448
match_end,
486-
lookups.into_iter(),
449+
lookups,
487450
);
488451
return Some(());
489452
}
@@ -497,7 +460,7 @@ fn apply_chain_context<T: ToU16>(
497460
input: &[T],
498461
lookahead: &[T],
499462
match_funcs: [&match_func_t; 3],
500-
lookups: impl Iterator<Item = SequenceLookupRecord>,
463+
lookups: &[SequenceLookupRecord],
501464
) -> Option<()> {
502465
// NOTE: Whenever something in this method changes, we also need to
503466
// change it in the `apply` implementation for ChainedContextLookup.

src/hb/ot_layout_gsubgpos.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Matching of glyph patterns.
22
3+
use skrifa::raw::tables::layout::SequenceLookupRecord;
34
use ttf_parser::opentype_layout::*;
45
use ttf_parser::GlyphId;
56

@@ -401,7 +402,7 @@ pub(super) fn apply_lookup(
401402
input_len: usize,
402403
match_positions: &mut smallvec::SmallVec<[usize; 4]>,
403404
match_end: usize,
404-
lookups: impl Iterator<Item = SequenceLookupRecord>,
405+
lookups: &[SequenceLookupRecord],
405406
) {
406407
let mut count = input_len + 1;
407408

@@ -428,7 +429,7 @@ pub(super) fn apply_lookup(
428429
break;
429430
}
430431

431-
let idx = usize::from(record.sequence_index);
432+
let idx = usize::from(record.sequence_index.get());
432433
if idx >= count {
433434
continue;
434435
}
@@ -448,7 +449,7 @@ pub(super) fn apply_lookup(
448449
break;
449450
}
450451

451-
if ctx.recurse(record.lookup_list_index).is_none() {
452+
if ctx.recurse(record.lookup_list_index.get()).is_none() {
452453
continue;
453454
}
454455

0 commit comments

Comments
 (0)