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 (32 lines) | stat: -rw-r--r-- 1,075 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
"""ttLib.Substitution: Converting Substitution rules to TrueType."""


def lookup_type(self, forFea=False):
    """Mixin to determine the GSUB lookup type of a fontFeatures.Substitution object

    Returns: integer GSUB lookup type."""
    if self.reverse:
        return 8
    if not self.replacement:
        return 2  # Deletion but treat as mult sub
    if (
        (self.has_context and not forFea)
        or len(self.lookups) > 0
        and any([x is not None for x in self.lookups])
    ):
        return 6  # Chaining
    # if self.input == self.replacement: # It's an ignore
    # return 6
    if len(self.input) == 1 and len(self.replacement) == 1:
        if self.force_alt or (len(self.input[0]) == 1 and len(self.replacement[0]) > 1):
            return 3  # Alternate
        else:
            return 1  # Single
    if len(self.input) > 1 and len(self.replacement) == 1:
        return 4  # Ligature

    if len(self.input) > 1 and len(self.replacement) > 1:
        return 9  # Not directly expressible!

    if len(self.replacement) > 1:
        return 2