File: test_unparse_sub.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 (46 lines) | stat: -rw-r--r-- 1,941 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
45
46
from fontFeatures import Substitution, FontFeatures
from fontTools.ttLib import TTFont
from fontFeatures.ttLib.GSUBUnparser import GSUBUnparser
from fontFeatures.ttLib import unparseLanguageSystems
import pprint
import unittest


class TestUnparse(unittest.TestCase):
    font = TTFont("fonts/Amiri-Regular.ttf")
    lookups = font["GSUB"].table.LookupList.Lookup
    ff = FontFeatures()
    unparser = GSUBUnparser(font["GSUB"], ff, [])

    def test_single(self):
        g, _ = self.unparser.unparseLookup(self.lookups[1], 1)  # part of locl
        self.assertEqual(g.rules[0].asFea(), "sub period by period.ara;")
        self.assertEqual(g.rules[1].asFea(), "sub guillemotleft by guillemotleft.ara;")

    def test_ligature(self):
        g, _ = self.unparser.unparseLookup(self.lookups[0], 0)  # part of ccmp
        self.assertEqual(g.rules[0].asFea(), "sub uni0627 uni065F by uni0673;")

    def test_multiple(self):
        g, _ = self.unparser.unparseLookup(self.lookups[10], 10)
        self.assertEqual(g.rules[0].asFea(), "sub uni08B6 by uni0628 smallmeem.above;")

    def test_ignore(self):
        g, _ = self.unparser.unparseLookup(self.lookups[47], 47)
        self.unparser.lookups = [None] * 47 + [g]
        assert self.unparser.lookups[47]
        g, _ = self.unparser.unparseLookup(self.lookups[48], 48)
        self.assertEqual(
            g.rules[0].asFea(),
            "ignore sub [uni0622 uni0627 uni0648 uni0671 uni0627.fina uni0671.fina] uni0644.init' uni0644.medi' [uni0647.fina uni06C1.fina];",
        )

    # def test_chaining(self):
    #     self.unparser.unparseLookups()
    #     g, _ = self.unparser.unparseLookup(
    #         self.lookups[33], 33
    #     )  # part of calt in quran.fea
    #     self.assertEqual(
    #         g.rules[0].asFea(),
    #         "sub uni0644' lookup SingleSubstitution32 uni0621' lookup SingleSubstitution31 uni0627' lookup SingleSubstitution32;",
    #     )