Skip to main content

harfrust/aat/
kern.rs

1use crate::aat::layout::DELETED_GLYPH;
2use alloc::boxed::Box;
3use read_fonts::{
4    tables::{
5        aat,
6        kern::{Subtable, Subtable0, Subtable2, Subtable3, SubtableKind},
7    },
8    types::{GlyphId, GlyphId16},
9};
10
11use crate::aat::common::{
12    set_digest, AatApplyContext, ClassCache, SafeToBreakAccel, SafeToBreakSubtable, START_OF_TEXT,
13};
14use crate::aat::kerx::SimpleKerning;
15use crate::buffer::*;
16use crate::ot::apply::{ApplyContext, SkippingIterator};
17use crate::ot::gpos::attach_type;
18use crate::ot::layout::LayoutTableKind;
19use crate::ot::lookup_flags;
20use crate::plan::ShapePlan;
21use crate::set_digest::SetDigest;
22use crate::LayoutData;
23use crate::Mask;
24use crate::Scale;
25use crate::U32Set;
26
27pub(crate) fn get_class(machine: &aat::StateTable, glyph_id: GlyphId, cache: &ClassCache) -> u8 {
28    if let Some(klass) = cache.get(glyph_id.to_u32()) {
29        return klass as u8;
30    }
31    let klass = machine
32        .class(GlyphId16::new(glyph_id.to_u32() as u16))
33        .unwrap_or(aat::class::OUT_OF_BOUNDS);
34    cache.set(glyph_id.to_u32(), klass as u32);
35    klass
36}
37
38// Only tracing messages read the subtable index.
39#[cfg_attr(not(feature = "tracing"), allow(clippy::unused_enumerate_index))]
40pub fn apply(
41    plan: &ShapePlan,
42    layout: LayoutData<'_>,
43    scale: Scale,
44    buffer: &mut Buffer,
45    #[cfg(feature = "tracing")] font: &crate::ShaperFont<'_, '_>,
46) -> Option<()> {
47    let mut c = AatApplyContext::new(
48        plan,
49        layout,
50        scale,
51        buffer,
52        #[cfg(feature = "tracing")]
53        font,
54    );
55
56    if !buffer_message!(c.buffer, font, "start table kern") {
57        return None;
58    }
59
60    c.setup_buffer_glyph_set();
61
62    let cache = layout.aat.kern_cache()?;
63    let subtable_caches = &cache.subtables;
64    c.setup_buffer_digest(subtable_caches.len());
65    let safe_to_break = &cache.safe_to_break;
66
67    let mut seen_cross_stream = false;
68    for (_index, subtable_cache) in subtable_caches.iter().enumerate() {
69        let subtable = &subtable_cache.subtable;
70        #[cfg(feature = "tracing")]
71        let message_index = _index;
72
73        if subtable.is_variable() {
74            continue;
75        }
76
77        if c.buffer.direction.is_horizontal() != subtable.is_horizontal() {
78            continue;
79        }
80
81        c.first_set = Some(&subtable_cache.first_set);
82        c.first_digest = subtable_cache.first_digest.clone();
83        c.second_set = Some(&subtable_cache.second_set);
84        c.machine_class_cache = Some(&subtable_cache.class_cache);
85        c.start_end_safe_to_break = subtable_cache.start_end_safe_to_break;
86        c.safe_to_break = safe_to_break.subtable(subtable_cache.safe_to_break)?;
87
88        if !c.buffer_intersects_machine() {
89            message!(
90                c,
91                "skipped subtable {} because no glyph matches",
92                message_index
93            );
94            continue;
95        }
96
97        let reverse = c.buffer.direction.is_backward();
98        let is_cross_stream = subtable.is_cross_stream();
99        message_continue!(c, "start subtable {}", message_index);
100
101        if !seen_cross_stream && is_cross_stream {
102            seen_cross_stream = true;
103
104            // Attach all glyphs into a chain.
105            for pos in &mut c.buffer.pos {
106                pos.set_attach_type(attach_type::CURSIVE);
107                pos.set_attach_chain(if c.buffer.direction.is_forward() {
108                    -1
109                } else {
110                    1
111                });
112                // We intentionally don't set BufferScratchFlags::HAS_GPOS_ATTACHMENT,
113                // since there needs to be a non-zero attachment for post-positioning to
114                // be needed.
115            }
116        }
117
118        let Some(kind) = &subtable_cache.kind else {
119            continue;
120        };
121
122        if reverse != c.buffer_is_reversed {
123            c.reverse_buffer();
124        }
125
126        match kind {
127            SubtableKind::Format0(format0) if plan.requested_kerning => {
128                apply_simple_kerning(&mut c, format0, is_cross_stream);
129            }
130            SubtableKind::Format1(format1) => {
131                if apply_state_machine_kerning(&mut c, format1, is_cross_stream).is_none() {
132                    c.buffer.index_failed();
133                }
134            }
135            SubtableKind::Format2(format2) if plan.requested_kerning => {
136                apply_simple_kerning(&mut c, format2, is_cross_stream);
137            }
138            SubtableKind::Format3(format3) if plan.requested_kerning => {
139                apply_simple_kerning(&mut c, format3, is_cross_stream);
140            }
141            _ => {}
142        }
143        message!(c, "end subtable {}", message_index);
144    }
145    if c.buffer_is_reversed {
146        c.reverse_buffer();
147    }
148    buffer_message!(c.buffer, font, "end table kern");
149    Some(())
150}
151
152fn machine_kern<F>(
153    layout: LayoutData<'_>,
154    scale: Scale,
155    buffer: &mut Buffer,
156    #[cfg(feature = "tracing")] font: &crate::ShaperFont<'_, '_>,
157    kern_mask: Mask,
158    cross_stream: bool,
159    get_kerning: F,
160) where
161    F: Fn(u32, u32) -> i32,
162{
163    if !buffer_message!(buffer, font, "start kern") {
164        return;
165    }
166    buffer.unsafe_to_concat(None, None);
167    let mut ctx = ApplyContext::new(
168        LayoutTableKind::Gpos,
169        layout,
170        scale,
171        buffer,
172        #[cfg(feature = "tracing")]
173        font,
174    );
175    ctx.set_lookup_mask(kern_mask);
176    ctx.lookup_props = u32::from(lookup_flags::IGNORE_MARKS);
177    ctx.update_matchers();
178
179    let horizontal = ctx.buffer.direction.is_horizontal();
180    let use_x_scale = horizontal ^ cross_stream;
181    let mut i = 0;
182    let mut iter = SkippingIterator::new(&mut ctx, false);
183    while i < iter.buffer.len {
184        if iter
185            .buffer
186            .info
187            .get(i)
188            .is_none_or(|info| info.mask & kern_mask == 0)
189        {
190            i += 1;
191            continue;
192        }
193
194        iter.reset_fast(i);
195
196        let mut unsafe_to = 0;
197        if !iter.next(Some(&mut unsafe_to)) {
198            i = unsafe_to;
199            continue;
200        }
201
202        let j = iter.index();
203
204        let info = &iter.buffer.info;
205        let (Some(first), Some(second)) = (info.get(i), info.get(j)) else {
206            i = j;
207            continue;
208        };
209        let kern = get_kerning(first.glyph_id, second.glyph_id);
210        let kern = if use_x_scale {
211            scale.scale_x(kern)
212        } else {
213            scale.scale_y(kern)
214        };
215        let pos = &mut iter.buffer.pos;
216        if kern != 0 {
217            apply_pair_kerning(pos, i, j, kern, horizontal, cross_stream);
218            if cross_stream {
219                iter.buffer.scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
220            }
221
222            iter.buffer.unsafe_to_break(Some(i), Some(j + 1));
223        }
224
225        i = j;
226    }
227    buffer_message!(iter.buffer, font, "end kern");
228}
229
230/// Applies a pair kerning value, splitting it across the two glyphs unless
231/// it is cross-stream, in which case only the second glyph moves.
232pub(super) fn apply_pair_kerning(
233    pos: &mut [GlyphPosition],
234    i: usize,
235    j: usize,
236    kern: i32,
237    horizontal: bool,
238    cross_stream: bool,
239) -> Option<()> {
240    if cross_stream {
241        let second = pos.get_mut(j)?;
242        if horizontal {
243            second.y_offset = kern;
244        } else {
245            second.x_offset = kern;
246        }
247        return Some(());
248    }
249    let kern1 = kern >> 1;
250    let kern2 = kern - kern1;
251    let first = pos.get_mut(i)?;
252    if horizontal {
253        first.x_advance = first.x_advance.saturating_add(kern1);
254    } else {
255        first.y_advance = first.y_advance.saturating_add(kern1);
256    }
257    let second = pos.get_mut(j)?;
258    if horizontal {
259        second.x_advance = second.x_advance.saturating_add(kern2);
260        second.x_offset = second.x_offset.saturating_add(kern2);
261    } else {
262        second.y_advance = second.y_advance.saturating_add(kern2);
263        second.y_offset = second.y_offset.saturating_add(kern2);
264    }
265    Some(())
266}
267
268fn apply_simple_kerning<T: SimpleKerning>(
269    c: &mut AatApplyContext,
270    subtable: &T,
271    is_cross_stream: bool,
272) {
273    let first_set = c.first_set.as_ref().unwrap();
274    let second_set = c.second_set.as_ref().unwrap();
275
276    machine_kern(
277        c.layout,
278        c.scale,
279        c.buffer,
280        #[cfg(feature = "tracing")]
281        c.font,
282        c.plan.kern_mask,
283        is_cross_stream,
284        |left, right| {
285            if !first_set.contains(left) || !second_set.contains(right) {
286                0
287            } else {
288                subtable
289                    .simple_kerning(left.into(), right.into())
290                    .unwrap_or(0)
291            }
292        },
293    );
294}
295
296struct StateMachineDriver {
297    stack: [usize; 8],
298    depth: usize,
299}
300
301pub trait CollectGlyphs {
302    /// For each valid index, read the value of type `T`.
303    /// If `filter(&value)` returns true, insert the index into `set`.
304    fn collect_glyphs_filtered<F>(&self, _set: &mut U32Set, _num_glyphs: u32, _filter: F)
305    where
306        F: Fn(u8) -> bool;
307}
308
309impl CollectGlyphs for aat::ClassSubtable<'_> {
310    fn collect_glyphs_filtered<F>(&self, set: &mut U32Set, _num_glyphs: u32, filter: F)
311    where
312        F: Fn(u8) -> bool,
313    {
314        let first_glyph = self.first_glyph() as u32;
315        let class_array = self.class_array();
316        for (i, class) in class_array.iter().enumerate() {
317            let gid = first_glyph + i as u32;
318            if filter(*class) {
319                set.insert(gid);
320            }
321        }
322    }
323}
324
325fn collect_initial_glyphs(machine: &aat::StateTable, glyphs: &mut U32Set, num_glyphs: u32) {
326    let mut classes = U32Set::default();
327
328    let class_table = machine.header.class_table().ok();
329    let Some(class_table) = class_table else {
330        return;
331    };
332
333    let n_classes = machine.header.state_size();
334    for i in 0..n_classes {
335        if let Ok(entry) = machine.entry(START_OF_TEXT, i as u8) {
336            if entry.new_state == START_OF_TEXT
337                && !entry.is_action_initiable()
338                && !entry.is_actionable()
339            {
340                continue;
341            }
342            classes.insert(i as u32);
343        }
344    }
345
346    // And glyphs in those classes.
347
348    let filter = |class: u8| classes.contains(class as u32);
349
350    if filter(aat::class::DELETED_GLYPH) {
351        glyphs.insert(DELETED_GLYPH);
352    }
353
354    class_table.collect_glyphs_filtered(glyphs, num_glyphs, filter);
355}
356
357fn collect_start_end_safe_to_break(machine: &aat::StateTable) -> u64 {
358    let mut result = 0u64;
359    for state in 0..64 {
360        let bit = if let Ok(entry) = machine.entry(state, aat::class::END_OF_TEXT) {
361            !entry.is_actionable()
362        } else {
363            true
364        };
365        if bit {
366            result |= 1 << state;
367        }
368    }
369    result
370}
371
372fn apply_state_machine_kerning(
373    c: &mut AatApplyContext,
374    subtable: &aat::StateTable,
375    is_cross_stream: bool,
376) -> Option<()> {
377    let mut driver = StateMachineDriver {
378        stack: [0; 8],
379        depth: 0,
380    };
381
382    let mut state = START_OF_TEXT;
383    // Condition 3 below, precomputed for the start-of-text state: no
384    // end-of-text action can fire if we stop while in the start state.
385    let start_state_safe_to_break_eot = (c.start_end_safe_to_break & (1 << START_OF_TEXT)) != 0;
386    c.buffer.idx = 0;
387    'drive: loop {
388        let class = if c.buffer.idx < c.buffer.len {
389            get_class(
390                subtable,
391                c.buffer.cur(0)?.as_glyph(),
392                c.machine_class_cache.unwrap(),
393            )
394        } else {
395            aat::class::END_OF_TEXT
396        };
397
398        let Ok(entry) = subtable.entry(state, class) else {
399            break;
400        };
401
402        let next_state = entry.new_state;
403
404        // Fast path for when transitioning from start-state to start-state with
405        // no action and advancing. Do so as long as the class remains the same.
406        // This is common with runs of non-actionable glyphs.
407        if state == START_OF_TEXT
408            && next_state == START_OF_TEXT
409            && start_state_safe_to_break_eot
410            && !entry.is_actionable()
411            && entry.has_advance()
412        {
413            let old_class = class;
414            loop {
415                state_machine_transition(c, subtable, &entry, is_cross_stream, &mut driver);
416                if c.buffer.idx >= c.buffer.len {
417                    break 'drive;
418                }
419                c.buffer.max_ops -= 1;
420                c.buffer.next_glyph();
421
422                let new_class = if c.buffer.idx < c.buffer.len {
423                    get_class(
424                        subtable,
425                        c.buffer.cur(0)?.as_glyph(),
426                        c.machine_class_cache.unwrap(),
427                    )
428                } else {
429                    aat::class::END_OF_TEXT
430                };
431                if new_class != old_class {
432                    break;
433                }
434            }
435            if c.buffer.idx >= c.buffer.len {
436                break 'drive;
437            }
438            continue 'drive;
439        }
440
441        // Conditions under which it's guaranteed safe-to-break before current glyph:
442        //
443        // 1. There was no action in this transition; and
444        //
445        // 2. If we break before current glyph, the results will be the same. That
446        //    is guaranteed if:
447        //
448        //    2a. We were already in start-of-text state; or
449        //
450        //    2b. We are epsilon-transitioning to start-of-text state; or
451        //
452        //    2c. Starting from start-of-text state seeing current glyph:
453        //
454        //        2c'. There won't be any actions; and
455        //
456        //        2c". We would end up in the same state that we were going to end up
457        //             in now, including whether epsilon-transitioning.
458        //
459        //    and
460        //
461        // 3. If we break before current glyph, there won't be any end-of-text action
462        //    after previous glyph.
463        //
464        // This triples the transitions we need to look up, but is worth returning
465        // granular unsafe-to-break results. See eg.:
466        //
467        //   https://github.com/harfbuzz/harfbuzz/issues/2860
468
469        let is_safe_to_break =
470            // 1
471            !entry.is_actionable() &&
472
473            // 2
474            (
475                state == START_OF_TEXT
476                || (!entry.has_advance() && next_state == START_OF_TEXT)
477                // 2c, 2c', 2c"
478                || c.safe_to_break.wouldbe_matches(u16::from(class), next_state, entry.has_advance())
479            ) &&
480
481            // 3
482            (
483                if state < 64 {
484                    (c.start_end_safe_to_break & (1 << state)) != 0
485                } else {
486                    c.safe_to_break.eot_safe_high(state)
487                }
488            )
489        ;
490
491        if !is_safe_to_break && c.buffer.backtrack_len() > 0 && c.buffer.idx < c.buffer.len {
492            c.buffer.unsafe_to_break_from_outbuffer(
493                Some(c.buffer.backtrack_len() - 1),
494                Some(c.buffer.idx + 1),
495            );
496        }
497
498        state_machine_transition(c, subtable, &entry, is_cross_stream, &mut driver);
499
500        state = next_state;
501
502        if c.buffer.idx >= c.buffer.len {
503            break;
504        }
505
506        c.buffer.max_ops -= 1;
507        if entry.has_advance() || c.buffer.max_ops <= 0 {
508            c.buffer.next_glyph();
509        }
510    }
511    Some(())
512}
513
514#[inline(always)]
515fn state_machine_transition(
516    c: &mut AatApplyContext,
517    subtable: &aat::StateTable,
518    entry: &aat::StateEntry,
519    is_cross_stream: bool,
520    driver: &mut StateMachineDriver,
521) {
522    let scale = c.scale;
523    let use_x_scale = c.buffer.direction.is_horizontal() ^ is_cross_stream;
524    let buffer = &mut *c.buffer;
525    let kern_mask = c.plan.kern_mask;
526
527    if entry.has_push() {
528        if driver.depth < driver.stack.len() {
529            driver.stack[driver.depth] = buffer.idx;
530            driver.depth += 1;
531        } else {
532            driver.depth = 0; // Probably not what CoreText does, but better?
533        }
534    }
535
536    if entry.has_offset() && driver.depth != 0 {
537        let mut value_offset = entry.value_offset();
538        let Ok(mut value) = subtable.read_value::<i16>(value_offset as usize) else {
539            driver.depth = 0;
540            return;
541        };
542
543        // From Apple 'kern' spec:
544        // "Each pops one glyph from the kerning stack and applies the kerning value to it.
545        // The end of the list is marked by an odd value...
546        let mut last = false;
547        while !last && driver.depth != 0 {
548            driver.depth -= 1;
549            let idx = driver.stack[driver.depth];
550            let mut v = value as i32;
551            value_offset = value_offset.wrapping_add(2);
552            value = subtable
553                .read_value::<i16>(value_offset as usize)
554                .unwrap_or(0);
555            if idx >= buffer.len {
556                continue;
557            }
558
559            // "The end of the list is marked by an odd value..."
560            last = v & 1 != 0;
561            v &= !1;
562            let scaled_v = if use_x_scale {
563                scale.scale_x(v)
564            } else {
565                scale.scale_y(v)
566            };
567
568            // Testing shows that CoreText only applies kern (cross-stream or not)
569            // if none has been applied by previous subtables. That is, it does
570            // NOT seem to accumulate as otherwise implied by specs.
571
572            let mut has_gpos_attachment = false;
573            let (Some(info), Some(pos)) = (buffer.info.get(idx), buffer.pos.get_mut(idx)) else {
574                continue;
575            };
576            let glyph_mask = info.mask;
577
578            if buffer.direction.is_horizontal() {
579                if is_cross_stream {
580                    // The following flag is undocumented in the spec, but described
581                    // in the 'kern' table example.
582                    if v == -0x8000 {
583                        pos.set_attach_type(0);
584                        pos.set_attach_chain(0);
585                        pos.y_offset = 0;
586                    } else if pos.attach_type() != 0 {
587                        pos.y_offset = pos.y_offset.saturating_add(scaled_v);
588                        has_gpos_attachment = true;
589                    }
590                } else if glyph_mask & kern_mask != 0 {
591                    pos.x_advance = pos.x_advance.saturating_add(scaled_v);
592                    pos.x_offset = pos.x_offset.saturating_add(scaled_v);
593                }
594            } else {
595                if is_cross_stream {
596                    // CoreText doesn't do crossStream kerning in vertical. We do.
597                    if v == -0x8000 {
598                        pos.set_attach_type(0);
599                        pos.set_attach_chain(0);
600                        pos.x_offset = 0;
601                    } else if pos.attach_type() != 0 {
602                        pos.x_offset = pos.x_offset.saturating_add(scaled_v);
603                        has_gpos_attachment = true;
604                    }
605                } else if glyph_mask & kern_mask != 0 {
606                    if pos.y_offset == 0 {
607                        pos.y_advance = pos.y_advance.saturating_add(scaled_v);
608                        pos.y_offset = pos.y_offset.saturating_add(scaled_v);
609                    }
610                }
611            }
612
613            if has_gpos_attachment {
614                buffer.scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
615            }
616        }
617    }
618}
619
620trait KernStateEntryExt {
621    fn flags(&self) -> u16;
622
623    fn is_action_initiable(&self) -> bool {
624        self.flags() & 0x8000 != 0
625    }
626
627    fn is_actionable(&self) -> bool {
628        self.flags() & 0x3FFF != 0
629    }
630
631    fn has_offset(&self) -> bool {
632        self.flags() & 0x3FFF != 0
633    }
634
635    fn value_offset(&self) -> u16 {
636        self.flags() & 0x3FFF
637    }
638
639    fn has_advance(&self) -> bool {
640        self.flags() & 0x4000 == 0
641    }
642
643    fn has_push(&self) -> bool {
644        self.flags() & 0x8000 != 0
645    }
646}
647
648impl<T> KernStateEntryExt for aat::StateEntry<T> {
649    fn flags(&self) -> u16 {
650        self.flags
651    }
652}
653
654impl SimpleKerning for Subtable0<'_> {
655    fn simple_kerning(&self, left: GlyphId, right: GlyphId) -> Option<i32> {
656        self.kerning(left, right)
657    }
658    fn collect_glyphs(&self, first_set: &mut U32Set, second_set: &mut U32Set, _num_glyphs: u32) {
659        for &pair in self.pairs() {
660            first_set.insert(pair.left.get().to_u32());
661            second_set.insert(pair.right.get().to_u32());
662        }
663    }
664}
665
666impl SimpleKerning for Subtable2<'_> {
667    fn simple_kerning(&self, left: GlyphId, right: GlyphId) -> Option<i32> {
668        self.kerning(left, right)
669    }
670    fn collect_glyphs(&self, first_set: &mut U32Set, second_set: &mut U32Set, _num_glyphs: u32) {
671        let left_classes = &self.left_offset_table;
672        let right_classes = &self.right_offset_table;
673
674        let first_glyph = left_classes.first_glyph().to_u32();
675        let last_glyphs = first_glyph + left_classes.n_glyphs().saturating_sub(1) as u32;
676        first_set.insert_range(first_glyph..=last_glyphs);
677
678        let first_glyph = right_classes.first_glyph().to_u32();
679        let last_glyphs = first_glyph + right_classes.n_glyphs().saturating_sub(1) as u32;
680        second_set.insert_range(first_glyph..=last_glyphs);
681    }
682}
683
684impl SimpleKerning for Subtable3<'_> {
685    fn simple_kerning(&self, left: GlyphId, right: GlyphId) -> Option<i32> {
686        self.kerning(left, right)
687    }
688    fn collect_glyphs(&self, first_set: &mut U32Set, second_set: &mut U32Set, _num_glyphs: u32) {
689        first_set.insert_range(0..=self.glyph_count().saturating_sub(1) as u32);
690        second_set.insert_range(0..=self.glyph_count().saturating_sub(1) as u32);
691    }
692}
693
694pub(crate) struct KernSubtableCache<'a> {
695    start_end_safe_to_break: u64,
696    safe_to_break: SafeToBreakSubtable,
697    first_set: U32Set,
698    first_digest: SetDigest,
699    second_set: U32Set,
700    class_cache: Box<ClassCache>,
701    subtable: Subtable<'a>,
702    /// The parsed subtable, or `None` if it is unreadable.
703    kind: Option<SubtableKind<'a>>,
704}
705
706impl<'a> KernSubtableCache<'a> {
707    pub(crate) fn new(
708        subtable: &Subtable<'a>,
709        num_glyphs: u32,
710        safe_to_break: &mut SafeToBreakAccel,
711    ) -> Self {
712        let mut start_end_safe_to_break = 0u64;
713        let mut safe_to_break_subtable = safe_to_break.empty_subtable();
714        let mut first_set = U32Set::default();
715        let mut second_set = U32Set::default();
716        let kind = subtable.kind().ok();
717        if let Some(kind) = &kind {
718            match kind {
719                SubtableKind::Format0(format0) => {
720                    format0.collect_glyphs(&mut first_set, &mut second_set, num_glyphs);
721                }
722                SubtableKind::Format1(format1) => {
723                    start_end_safe_to_break = collect_start_end_safe_to_break(format1);
724                    safe_to_break_subtable = safe_to_break.build_legacy(
725                        format1,
726                        &KernStateEntryExt::is_actionable,
727                        &KernStateEntryExt::has_advance,
728                    );
729                    collect_initial_glyphs(format1, &mut first_set, num_glyphs);
730                }
731                SubtableKind::Format2(format2) => {
732                    format2.collect_glyphs(&mut first_set, &mut second_set, num_glyphs);
733                }
734                SubtableKind::Format3(format3) => {
735                    format3.collect_glyphs(&mut first_set, &mut second_set, num_glyphs);
736                }
737            }
738        }
739        KernSubtableCache {
740            start_end_safe_to_break,
741            safe_to_break: safe_to_break_subtable,
742            first_digest: set_digest(&first_set),
743            first_set,
744            second_set,
745            class_cache: Box::new(ClassCache::new()),
746            subtable: subtable.clone(),
747            kind,
748        }
749    }
750}