Debian Codegraph @

tests/test_fea_context_sub.py

raw symbols SCIP
1 #Needs: fonts/Ambrosia.sfd
2
3 import sys, fontforge
4 import tempfile
5 import os
6 import re
7
8 font = fontforge.open(sys.argv[1])
9
10 #
11 # Test multiple lookups in a contextual substitution rule (Issue #5374)
12 #
13 font.addLookup("Single 1", "gsub_single", (), ())
14 font.addLookupSubtable("Single 1", "Single 1")
15 font["A"].addPosSub("Single 1", "B")
16
17 font.addLookup("Single 2", "gsub_single", (), (), "Single 1")
18 font.addLookupSubtable("Single 2", "Single 2")
19 font["C"].addPosSub("Single 2", "D")
20
21 font.addLookup("Contextual", "gsub_context", (), (("calt",(("dflt",("dflt")),)),), "Single 2")
22 font.addContextualSubtable("Contextual", "Contextual_sub", "glyph",
23 "A @<Single 1> C @<Single 2>")
24
25 with tempfile.TemporaryDirectory() as tmpdirname:
26 fea_full_name = os.path.join(tmpdirname, "Ambrosia.sfd")
27 font.generateFeatureFile(fea_full_name)
28
29 with open(fea_full_name) as fea_file:
30 rules = [line for line in fea_file
31 if re.search(r"sub \\A *' *lookup +Single1 +\\C *' *lookup +Single2", line)]
32
33 # Expect to find the rule inside the feature file
34 assert rules
35
36 #
37 # Test pair positioning in a contextual chaining lookup (Issue #5383)
38 #
39 kern_value = 532
40 font.addLookup("Pair 1", "gpos_pair", (), ())
41 font.addLookupSubtable("Pair 1", "Pair 1")
42 font["E"].addPosSub("Pair 1", "F", -kern_value)
43
44 font.addLookup("KernContextual", "gpos_contextchain", (), (("kern",(("dflt",("dflt")),)),), "Pair 1")
45 font.addContextualSubtable("KernContextual", "KernContextual_sub", "glyph",
46 "E | E @<Pair 1> F |")
47
48 with tempfile.TemporaryDirectory() as tmpdirname:
49 fea_full_name = os.path.join(tmpdirname, "Ambrosia.sfd")
50 font.generateFeatureFile(fea_full_name)
51
52 with open(fea_full_name) as fea_file:
53 # Check that the kerning value is present
54 rules = [line for line in fea_file if str(kern_value) in line]
55
56 # Expect to find the kerning rule inside the feature file
57 assert rules