File: Substitution.py

package info (click to toggle)
python-fontfeatures 1.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,096 kB
  • sloc: python: 9,112; makefile: 22
file content (37 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
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
import copy


def shaper_inputs(self):
    return self.input


def _do_apply(self, buf, ix, namedclasses={}):
    from fontFeatures.shaperLib.Rule import _expand_slot

    coverage = buf[ix : ix + len(self.input)]
    newstuff = []
    # Handle single subst first
    if len(self.input) == 1 and len(self.replacement) == 1:
        replacements = _expand_slot(self.replacement[0], namedclasses)
        if len(replacements) == 1:
            buf[ix].glyph = replacements[0]
        else:
            inputs = _expand_slot(self.input[0], namedclasses)
            buf[ix].glyph = replacements[inputs.index(buf[ix].glyph)]
        buf[ix].prep_glyph(buf.font)
        return

    delta = len(self.replacement) - 1
    for g in self.replacement:
        new_glyph = copy.copy(buf[ix])
        new_glyph.glyph = g[0]
        new_glyph.prep_glyph(buf.font)
        new_glyph.substituted = True
        if len(self.replacement) > 1 and len(coverage) == 1:
            new_glyph.multiplied = True
        if len(self.replacement) == 1 and len(coverage) > 1:
            new_glyph.ligated = True
        newstuff.append(new_glyph)
    buf[ix : ix + len(self.input)] = newstuff
    if delta > 0:
        return delta