summaryrefslogtreecommitdiff
path: root/obsolete/macros/luatex/generic/fontloader-luaotfload/test-fontloader-2017-07-28.tex
blob: 5750fa345c7c8ed237ddd3f84066ad88b9ab5088 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
% !Mode:: "TeX:UTF-8:Main"
%needs a fontloader 2017-07-28 or later
%substitutions at word boundaries

\documentclass{article}

\usepackage{luacode,fontspec}
\begin{luacode*}
     fonts.handlers.otf.addfeature {
         name    = "test-a",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "substitution",
                 data = {
                     ["a"] = "A",
                     ["b"] = "B",
                     ["c"] = "C",
                     ["d"] = "D",
                 },
             },
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     before  = { { " ", 0xFFFC } },
                     current = { { "a" }, { "b" } },
                     lookups = { 2 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     after   = { { 0xFFFC, " " } },
                     lookups = { 2 },
                 },
                 {
                     current = { { "a" } },
                     after   = { { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" } },
                     after   = { { "d" } },
                     lookups = { 1 },
                 },
             },
         },
     }

     fonts.handlers.otf.addfeature {
         name    = "test-b",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     -- the space is redundant as 0xFFFC contains it
                     before  = { { " ", 0xFFFC } },
                     current = { { "a" }, { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     -- the space is redundant as 0xFFFC contains it
                     after   = { { 0xFFFC, " " } },
                     lookups = { 1 },
                 },
             },
         },
     }

     fonts.handlers.otf.addfeature {
         name    = "test-c",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     before  = { { " " } },
                     current = { { "a" }, { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     after   = { { " " } },
                     lookups = { 1 },
                 },
             },
         },
     }
\end{luacode*}


\setmainfont{Arial}[RawFeature=+test-a;]

\begin{document}
Substitutions at word boundaries (spaces):

ab ab abxcd abxcdcdcd

expected output:

1 1 1x2 1xCdCd2

\end{document}