File: Chaining.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 (44 lines) | stat: -rw-r--r-- 1,413 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
38
39
40
41
42
43
44
def shaper_inputs(self):
    return self.input


def __find_masked_ix(buf, ix):
    # This probably could be done better...
    for i in range(len(buf.items)):
        if buf.mask[i] == ix:
            return i
    return -1


def _do_apply(self, buf, ix, namedclasses={}):
    from fontFeatures import RoutineReference

    # Save buffer mask
    flags = buf.flags
    markFilteringSet = buf.markFilteringSet
    markAttachmentSet = buf.markAttachmentSet

    if ix + len(self.lookups) - 1 > len(buf.mask):
        return

    old_unmasked_indexes = [buf.mask[ix + i] for i in range(len(self.lookups))]
    for i, lookups in enumerate(self.lookups):
        if not lookups:
            continue
        for routine in lookups:
            assert isinstance(routine, RoutineReference)
            routine = routine.routine
            # Adjust mask and recompute index?
            unmasked_ix = old_unmasked_indexes[i]
            for rule in routine.rules:
                buf.set_mask(
                    rule.flags, routine.markFilteringSet, routine.markAttachmentSet
                )
                newix = __find_masked_ix(buf, unmasked_ix)
                if rule.would_apply_at_position(
                    buf, newix, namedclasses
                ) and rule._do_apply(buf, newix):
                    break

    buf.set_mask(flags, markFilteringSet, markAttachmentSet)
    return len(self.input) - 1