read_fonts/tables/gsub/
closure.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
//! Computing the closure over a set of glyphs
//!
//! This means taking a set of glyphs and updating it to include any other glyphs
//! reachable from those glyphs via substitution, recursively.

use std::collections::HashSet;

use font_types::GlyphId16;

use crate::{
    tables::layout::{
        ChainedSequenceContextFormat1, ChainedSequenceContextFormat2,
        ChainedSequenceContextFormat3, ExtensionLookup, SequenceContextFormat1,
        SequenceContextFormat2, SequenceContextFormat3, Subtables,
    },
    FontRead, ReadError,
};

use super::{
    AlternateSubstFormat1, ChainedSequenceContext, ClassDef, Gsub, LigatureSubstFormat1,
    MultipleSubstFormat1, ReverseChainSingleSubstFormat1, SequenceContext, SingleSubst,
    SingleSubstFormat1, SingleSubstFormat2, SubstitutionSubtables,
};

/// A trait for tables which participate in closure
pub(crate) trait GlyphClosure {
    /// Update the set of glyphs with any glyphs reachable via substitution.
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError>;
}

impl<'a> Gsub<'a> {
    /// Return the set of glyphs reachable from the input set via any substitution.
    pub fn closure_glyphs(
        &self,
        mut glyphs: HashSet<GlyphId16>,
    ) -> Result<HashSet<GlyphId16>, ReadError> {
        // we need to do this iteratively, since any glyph found in one pass
        // over the lookups could also be the target of substitutions.

        // we always call this once, and then keep calling if it produces
        // additional glyphs
        let mut prev_glyph_count = glyphs.len();
        self.closure_glyphs_once(&mut glyphs)?;
        let mut new_glyph_count = glyphs.len();

        while prev_glyph_count != new_glyph_count {
            prev_glyph_count = new_glyph_count;
            self.closure_glyphs_once(&mut glyphs)?;
            new_glyph_count = glyphs.len();
        }

        Ok(glyphs)
    }

    fn closure_glyphs_once(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        let lookups_to_use = self.find_reachable_lookups(glyphs)?;
        let lookup_list = self.lookup_list()?;
        for (i, lookup) in lookup_list.lookups().iter().enumerate() {
            if !lookups_to_use.contains(&(i as u16)) {
                continue;
            }
            let subtables = lookup?.subtables()?;
            subtables.add_reachable_glyphs(glyphs)?;
        }
        Ok(())
    }

    fn find_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
    ) -> Result<HashSet<u16>, ReadError> {
        let feature_list = self.feature_list()?;
        let lookup_list = self.lookup_list()?;
        // first we want to get the lookups that are directly referenced by a feature
        // (including in a feature variation table)
        let mut lookup_ids = HashSet::with_capacity(lookup_list.lookup_count() as _);
        let feature_variations = self
            .feature_variations()
            .transpose()?
            .map(|vars| {
                let data = vars.offset_data();
                vars.feature_variation_records()
                    .iter()
                    .filter_map(move |rec| {
                        rec.feature_table_substitution(data)
                            .transpose()
                            .ok()
                            .flatten()
                    })
                    .flat_map(|subs| {
                        subs.substitutions()
                            .iter()
                            .map(move |sub| sub.alternate_feature(subs.offset_data()))
                    })
            })
            .into_iter()
            .flatten();
        for feature in feature_list
            .feature_records()
            .iter()
            .map(|rec| rec.feature(feature_list.offset_data()))
            .chain(feature_variations)
        {
            lookup_ids.extend(feature?.lookup_list_indices().iter().map(|idx| idx.get()));
        }

        // and now we need to add lookups referenced by contextual lookups,
        // IFF they are reachable via the current set of glyphs:
        for lookup in lookup_list.lookups().iter() {
            let subtables = lookup?.subtables()?;
            match subtables {
                SubstitutionSubtables::Contextual(tables) => tables
                    .iter()
                    .try_for_each(|t| t?.add_reachable_lookups(glyphs, &mut lookup_ids)),
                SubstitutionSubtables::ChainContextual(tables) => tables
                    .iter()
                    .try_for_each(|t| t?.add_reachable_lookups(glyphs, &mut lookup_ids)),
                _ => Ok(()),
            }?;
        }
        Ok(lookup_ids)
    }
}

impl<'a> GlyphClosure for SubstitutionSubtables<'a> {
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        match self {
            SubstitutionSubtables::Single(tables) => tables.add_reachable_glyphs(glyphs),
            SubstitutionSubtables::Multiple(tables) => tables.add_reachable_glyphs(glyphs),
            SubstitutionSubtables::Alternate(tables) => tables.add_reachable_glyphs(glyphs),
            SubstitutionSubtables::Ligature(tables) => tables.add_reachable_glyphs(glyphs),
            SubstitutionSubtables::Reverse(tables) => tables.add_reachable_glyphs(glyphs),
            _ => Ok(()),
        }
    }
}

impl<'a, T: FontRead<'a> + GlyphClosure + 'a, Ext: ExtensionLookup<'a, T> + 'a> GlyphClosure
    for Subtables<'a, T, Ext>
{
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        self.iter()
            .try_for_each(|t| t?.add_reachable_glyphs(glyphs))
    }
}

impl<'a> GlyphClosure for SingleSubst<'a> {
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        for (target, replacement) in self.iter_subs()? {
            if glyphs.contains(&target) {
                glyphs.insert(replacement);
            }
        }
        Ok(())
    }
}

impl<'a> SingleSubst<'a> {
    fn iter_subs(&self) -> Result<impl Iterator<Item = (GlyphId16, GlyphId16)> + '_, ReadError> {
        let (left, right) = match self {
            SingleSubst::Format1(t) => (Some(t.iter_subs()?), None),
            SingleSubst::Format2(t) => (None, Some(t.iter_subs()?)),
        };
        Ok(left
            .into_iter()
            .flatten()
            .chain(right.into_iter().flatten()))
    }
}

impl<'a> SingleSubstFormat1<'a> {
    fn iter_subs(&self) -> Result<impl Iterator<Item = (GlyphId16, GlyphId16)> + '_, ReadError> {
        let delta = self.delta_glyph_id();
        let coverage = self.coverage()?;
        Ok(coverage.iter().filter_map(move |gid| {
            let raw = (gid.to_u16() as i32).checked_add(delta as i32);
            let raw = raw.and_then(|raw| u16::try_from(raw).ok())?;
            Some((gid, GlyphId16::new(raw)))
        }))
    }
}

impl<'a> SingleSubstFormat2<'a> {
    fn iter_subs(&self) -> Result<impl Iterator<Item = (GlyphId16, GlyphId16)> + '_, ReadError> {
        let coverage = self.coverage()?;
        let subs = self.substitute_glyph_ids();
        Ok(coverage.iter().zip(subs.iter().map(|id| id.get())))
    }
}

impl<'a> GlyphClosure for MultipleSubstFormat1<'a> {
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        let coverage = self.coverage()?;
        let sequences = self.sequences();
        for (gid, replacements) in coverage.iter().zip(sequences.iter()) {
            let replacements = replacements?;
            if glyphs.contains(&gid) {
                glyphs.extend(
                    replacements
                        .substitute_glyph_ids()
                        .iter()
                        .map(|gid| gid.get()),
                );
            }
        }
        Ok(())
    }
}

impl<'a> GlyphClosure for AlternateSubstFormat1<'a> {
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        let coverage = self.coverage()?;
        let alts = self.alternate_sets();
        for (gid, alts) in coverage.iter().zip(alts.iter()) {
            let alts = alts?;
            if glyphs.contains(&gid) {
                glyphs.extend(alts.alternate_glyph_ids().iter().map(|gid| gid.get()));
            }
        }
        Ok(())
    }
}

impl<'a> GlyphClosure for LigatureSubstFormat1<'a> {
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        let coverage = self.coverage()?;
        let ligs = self.ligature_sets();
        for (gid, lig_set) in coverage.iter().zip(ligs.iter()) {
            let lig_set = lig_set?;
            if glyphs.contains(&gid) {
                for lig in lig_set.ligatures().iter() {
                    let lig = lig?;
                    if lig
                        .component_glyph_ids()
                        .iter()
                        .all(|gid| glyphs.contains(&gid.get()))
                    {
                        glyphs.insert(lig.ligature_glyph());
                    }
                }
            }
        }
        Ok(())
    }
}

impl GlyphClosure for ReverseChainSingleSubstFormat1<'_> {
    fn add_reachable_glyphs(&self, glyphs: &mut HashSet<GlyphId16>) -> Result<(), ReadError> {
        for coverage in self
            .backtrack_coverages()
            .iter()
            .chain(self.lookahead_coverages().iter())
        {
            if !coverage?.iter().any(|gid| glyphs.contains(&gid)) {
                return Ok(());
            }
        }

        for (gid, sub) in self.coverage()?.iter().zip(self.substitute_glyph_ids()) {
            if glyphs.contains(&gid) {
                glyphs.insert(sub.get());
            }
        }

        Ok(())
    }
}

impl SequenceContext<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        match self {
            SequenceContext::Format1(table) => table.add_reachable_lookups(glyphs, lookups),
            SequenceContext::Format2(table) => table.add_reachable_lookups(glyphs, lookups),
            SequenceContext::Format3(table) => table.add_reachable_lookups(glyphs, lookups),
        }
    }
}

impl SequenceContextFormat1<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        let coverage = self.coverage()?;
        for seq in coverage
            .iter()
            .zip(self.seq_rule_sets().iter())
            .filter_map(|(gid, seq)| seq.filter(|_| glyphs.contains(&gid)))
        {
            for rule in seq?.seq_rules().iter() {
                let rule = rule?;
                if rule
                    .input_sequence()
                    .iter()
                    .all(|gid| glyphs.contains(&gid.get()))
                {
                    lookups.extend(
                        rule.seq_lookup_records()
                            .iter()
                            .map(|rec| rec.lookup_list_index()),
                    );
                }
            }
        }
        Ok(())
    }
}

impl SequenceContextFormat2<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        let classdef = self.class_def()?;
        let our_classes = make_class_set(glyphs, &classdef);
        for seq in self
            .class_seq_rule_sets()
            .iter()
            .enumerate()
            .filter_map(|(i, seq)| seq.filter(|_| our_classes.contains(&(i as u16))))
        {
            for rule in seq?.class_seq_rules().iter() {
                let rule = rule?;
                if rule
                    .input_sequence()
                    .iter()
                    .all(|class_id| our_classes.contains(&class_id.get()))
                {
                    lookups.extend(
                        rule.seq_lookup_records()
                            .iter()
                            .map(|rec| rec.lookup_list_index()),
                    )
                }
            }
        }
        Ok(())
    }
}

impl SequenceContextFormat3<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        for coverage in self.coverages().iter() {
            if !coverage?.iter().any(|gid| glyphs.contains(&gid)) {
                return Ok(());
            }
        }
        lookups.extend(
            self.seq_lookup_records()
                .iter()
                .map(|rec| rec.lookup_list_index()),
        );
        Ok(())
    }
}

impl ChainedSequenceContext<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        match self {
            ChainedSequenceContext::Format1(table) => table.add_reachable_lookups(glyphs, lookups),
            ChainedSequenceContext::Format2(table) => table.add_reachable_lookups(glyphs, lookups),
            ChainedSequenceContext::Format3(table) => table.add_reachable_lookups(glyphs, lookups),
        }
    }
}

impl ChainedSequenceContextFormat1<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        let coverage = self.coverage()?;
        for seq in coverage
            .iter()
            .zip(self.chained_seq_rule_sets().iter())
            .filter_map(|(gid, seq)| seq.filter(|_| glyphs.contains(&gid)))
        {
            for rule in seq?.chained_seq_rules().iter() {
                let rule = rule?;
                if rule
                    .input_sequence()
                    .iter()
                    .chain(rule.backtrack_sequence())
                    .chain(rule.lookahead_sequence())
                    .all(|gid| glyphs.contains(&gid.get()))
                {
                    lookups.extend(
                        rule.seq_lookup_records()
                            .iter()
                            .map(|rec| rec.lookup_list_index()),
                    );
                }
            }
        }
        Ok(())
    }
}

impl ChainedSequenceContextFormat2<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        let input = self.input_class_def()?;
        let backtrack = self.backtrack_class_def()?;
        let lookahead = self.lookahead_class_def()?;

        let input_classes = make_class_set(glyphs, &input);
        let backtrack_classes = make_class_set(glyphs, &backtrack);
        let lookahead_classes = make_class_set(glyphs, &lookahead);
        for seq in self
            .chained_class_seq_rule_sets()
            .iter()
            .enumerate()
            .filter_map(|(i, seq)| seq.filter(|_| input_classes.contains(&(i as u16))))
        {
            for rule in seq?.chained_class_seq_rules().iter() {
                let rule = rule?;
                if rule
                    .input_sequence()
                    .iter()
                    .all(|cls| input_classes.contains(&cls.get()))
                    && rule
                        .backtrack_sequence()
                        .iter()
                        .all(|cls| backtrack_classes.contains(&cls.get()))
                    && rule
                        .lookahead_sequence()
                        .iter()
                        .all(|cls| lookahead_classes.contains(&cls.get()))
                {
                    lookups.extend(
                        rule.seq_lookup_records()
                            .iter()
                            .map(|rec| rec.lookup_list_index()),
                    )
                }
            }
        }
        Ok(())
    }
}

impl ChainedSequenceContextFormat3<'_> {
    fn add_reachable_lookups(
        &self,
        glyphs: &HashSet<GlyphId16>,
        lookups: &mut HashSet<u16>,
    ) -> Result<(), ReadError> {
        for coverage in self
            .backtrack_coverages()
            .iter()
            .chain(self.input_coverages().iter())
            .chain(self.lookahead_coverages().iter())
        {
            if !coverage?.iter().any(|gid| glyphs.contains(&gid)) {
                return Ok(());
            }
        }
        lookups.extend(
            self.seq_lookup_records()
                .iter()
                .map(|rec| rec.lookup_list_index()),
        );
        Ok(())
    }
}

fn make_class_set(glyphs: &HashSet<GlyphId16>, classdef: &ClassDef) -> HashSet<u16> {
    glyphs.iter().map(|gid| classdef.get(*gid)).collect()
}

#[cfg(test)]
mod tests {
    use std::collections::HashMap;

    use crate::{FontRef, TableProvider};

    use super::*;
    use font_test_data::closure as test_data;

    struct GlyphMap {
        to_gid: HashMap<&'static str, GlyphId16>,
        from_gid: HashMap<GlyphId16, &'static str>,
    }

    impl GlyphMap {
        fn new(raw_order: &'static str) -> GlyphMap {
            let to_gid: HashMap<_, _> = raw_order
                .split('\n')
                .map(|line| line.trim())
                .filter(|line| !(line.starts_with('#') || line.is_empty()))
                .enumerate()
                .map(|(gid, name)| (name, GlyphId16::new(gid.try_into().unwrap())))
                .collect();
            let from_gid = to_gid.iter().map(|(name, gid)| (*gid, *name)).collect();
            GlyphMap { from_gid, to_gid }
        }

        fn get_gid(&self, name: &str) -> Option<GlyphId16> {
            self.to_gid.get(name).copied()
        }

        fn get_name(&self, gid: GlyphId16) -> Option<&str> {
            self.from_gid.get(&gid).copied()
        }
    }

    fn get_gsub(test_data: &'static [u8]) -> Gsub<'_> {
        let font = FontRef::new(test_data).unwrap();
        font.gsub().unwrap()
    }

    fn compute_closure(gsub: &Gsub, glyph_map: &GlyphMap, input: &[&str]) -> HashSet<GlyphId16> {
        let input_glyphs = input
            .iter()
            .map(|name| glyph_map.get_gid(name).unwrap())
            .collect();
        gsub.closure_glyphs(input_glyphs).unwrap()
    }

    /// assert a set of glyph ids matches a slice of names
    macro_rules! assert_closure_result {
        ($glyph_map:expr, $result:expr, $expected:expr) => {
            let result = $result
                .iter()
                .map(|gid| $glyph_map.get_name(*gid).unwrap())
                .collect::<HashSet<_>>();
            let expected = $expected.iter().copied().collect::<HashSet<_>>();
            if expected != result {
                let in_output = result.difference(&expected).collect::<Vec<_>>();
                let in_expected = expected.difference(&result).collect::<Vec<_>>();
                let mut msg = format!("Closure output does not match\n");
                if !in_expected.is_empty() {
                    msg.push_str(format!("missing {in_expected:?}\n").as_str());
                }
                if !in_output.is_empty() {
                    msg.push_str(format!("unexpected {in_output:?}").as_str());
                }
                panic!("{msg}")
            }
        };
    }

    #[test]
    fn smoke_test() {
        // tests various lookup types.
        // test input is font-test-data/test_data/fea/simple_closure.fea
        let gsub = get_gsub(test_data::SIMPLE);
        let glyph_map = GlyphMap::new(test_data::SIMPLE_GLYPHS);
        let result = compute_closure(&gsub, &glyph_map, &["a"]);

        assert_closure_result!(
            glyph_map,
            result,
            &["a", "A", "b", "c", "d", "a_a", "a.1", "a.2", "a.3"]
        );
    }

    #[test]
    fn recursive() {
        // a scenario in which one substitution adds glyphs that trigger additional
        // substitutions.
        //
        // test input is font-test-data/test_data/fea/recursive_closure.fea
        let gsub = get_gsub(test_data::RECURSIVE);
        let glyph_map = GlyphMap::new(test_data::RECURSIVE_GLYPHS);
        let result = compute_closure(&gsub, &glyph_map, &["a"]);
        assert_closure_result!(glyph_map, result, &["a", "b", "c", "d"]);
    }

    #[test]
    fn contextual_lookups() {
        let gsub = get_gsub(test_data::CONTEXTUAL);
        let glyph_map = GlyphMap::new(test_data::CONTEXTUAL_GLYPHS);

        // these match the lookups but not the context
        let nop = compute_closure(&gsub, &glyph_map, &["three", "four", "e", "f"]);
        assert_closure_result!(glyph_map, nop, &["three", "four", "e", "f"]);

        let gsub6f1 = compute_closure(
            &gsub,
            &glyph_map,
            &["one", "two", "three", "four", "five", "six", "seven"],
        );
        assert_closure_result!(
            glyph_map,
            gsub6f1,
            &["one", "two", "three", "four", "five", "six", "seven", "X", "Y"]
        );

        let gsub6f3 = compute_closure(&gsub, &glyph_map, &["space", "e"]);
        assert_closure_result!(glyph_map, gsub6f3, &["space", "e", "e.2"]);

        let gsub5f3 = compute_closure(&gsub, &glyph_map, &["f", "g"]);
        assert_closure_result!(glyph_map, gsub5f3, &["f", "g", "f.2"]);
    }

    #[test]
    fn recursive_context() {
        let gsub = get_gsub(test_data::RECURSIVE_CONTEXTUAL);
        let glyph_map = GlyphMap::new(test_data::RECURSIVE_CONTEXTUAL_GLYPHS);

        let nop = compute_closure(&gsub, &glyph_map, &["b", "B"]);
        assert_closure_result!(glyph_map, nop, &["b", "B"]);

        let full = compute_closure(&gsub, &glyph_map, &["a", "b", "c"]);
        assert_closure_result!(glyph_map, full, &["a", "b", "c", "B", "B.2", "B.3"]);

        let intermediate = compute_closure(&gsub, &glyph_map, &["a", "B.2"]);
        assert_closure_result!(glyph_map, intermediate, &["a", "B.2", "B.3"]);
    }

    #[test]
    fn feature_variations() {
        let gsub = get_gsub(test_data::VARIATIONS_CLOSURE);
        let glyph_map = GlyphMap::new(test_data::VARIATIONS_GLYPHS);

        let input = compute_closure(&gsub, &glyph_map, &["a"]);
        assert_closure_result!(glyph_map, input, &["a", "b", "c"]);
    }
}