1if not modules then modules = { } end modules ['font-imp-ligatures'] = {
2 version = 1.001,
3 comment = "companion to font-ini.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11local lpegmatch = lpeg.match
12local utfsplit = utf.split
13local settings_to_array = utilities.parsers.settings_to_array
14
15local fonts = fonts
16local otf = fonts.handlers.otf
17local registerotffeature = otf.features.register
18local addotffeature = otf.addfeature
19
20
21
22local lookups = { }
23local protect = { }
24local revert = { }
25local zwjchar = 0x200C
26local zwj = { zwjchar }
27
28addotffeature {
29 name = "blockligatures",
30 type = "chainsubstitution",
31 nocheck = true,
32 prepend = true,
33 future = true,
34 lookups = {
35 {
36 type = "multiple",
37 data = lookups,
38 },
39 },
40 data = {
41 rules = protect,
42 }
43}
44
45addotffeature {
46 name = "blockligatures",
47 type = "chainsubstitution",
48 nocheck = true,
49 append = true,
50 overload = false,
51 lookups = {
52 {
53 type = "ligature",
54 data = lookups,
55 },
56 },
57 data = {
58 rules = revert,
59 }
60}
61
62registerotffeature {
63 name = 'blockligatures',
64 description = 'block certain ligatures',
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
118local function blockligatures(str)
119 local t = settings_to_array(str)
120 for i=1,#t do
121 local ti = t[i]
122 local current = utfsplit(ti)
123 if #current > 1 then
124 local one = current[1]
125 local two = current[2]
126 lookups[one] = { one, zwjchar }
127 local one = { one }
128 local two = { two }
129 local new = #protect + 1
130 protect[new] = {
131 current = { one, two },
132 lookups = { 1, false },
133 }
134 revert[new] = {
135 current = { one, zwj },
136 after = { two },
137 lookups = { 1, false },
138 }
139 end
140 end
141end
142
143
144
145otf.helpers.blockligatures = blockligatures
146
147
148
149
150if context then
151
152 interfaces.implement {
153 name = "blockligatures",
154 arguments = "string",
155 actions = blockligatures,
156 }
157
158end
159 |