Debian Codegraph @

Lib/fontFeatures/shaperLib/Substitution.py

raw
1 import copy
2
3
4 def shaper_inputs(self):
5 return self.input
6
7
8 def _do_apply(self, buf, ix, namedclasses={}):
9 from fontFeatures.shaperLib.Rule import _expand_slot
10
11 coverage = buf[ix : ix + len(self.input)]
12 newstuff = []
13 # Handle single subst first
14 if len(self.input) == 1 and len(self.replacement) == 1:
15 replacements = _expand_slot(self.replacement[0], namedclasses)
16 if len(replacements) == 1:
17 buf[ix].glyph = replacements[0]
18 else:
19 inputs = _expand_slot(self.input[0], namedclasses)
20 buf[ix].glyph = replacements[inputs.index(buf[ix].glyph)]
21 buf[ix].prep_glyph(buf.font)
22 return
23
24 delta = len(self.replacement) - 1
25 for g in self.replacement:
26 new_glyph = copy.copy(buf[ix])
27 new_glyph.glyph = g[0]
28 new_glyph.prep_glyph(buf.font)
29 new_glyph.substituted = True
30 if len(self.replacement) > 1 and len(coverage) == 1:
31 new_glyph.multiplied = True
32 if len(self.replacement) == 1 and len(coverage) > 1:
33 new_glyph.ligated = True
34 newstuff.append(new_glyph)
35 buf[ix : ix + len(self.input)] = newstuff
36 if delta > 0:
37 return delta