font-imp-tex.lua /size: 3406 b    last modification: 2020-07-01 14:35
1if not modules then modules = { } end modules ['font-imp-tex'] = {
2    version   = 1.001,
3    comment   = "companion to font-ini.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local next = next
10
11local fonts              = fonts
12local otf                = fonts.handlers.otf
13local registerotffeature = otf.features.register
14local addotffeature      = otf.addfeature
15
16-- tlig (we need numbers for some fonts so ...)
17
18local specification = {
19    type     = "ligature",
20    order    = { "tlig" },
21    prepend  = true,
22    data     = {
23     -- endash        = "hyphen hyphen",
24     -- emdash        = "hyphen hyphen hyphen",
25        [0x2013]      = { 0x002D, 0x002D },
26        [0x2014]      = { 0x002D, 0x002D, 0x002D },
27     -- quotedblleft  = "quoteleft quoteleft",
28     -- quotedblright = "quoteright quoteright",
29     -- quotedblleft  = "grave grave",
30     -- quotedblright = "quotesingle quotesingle",
31     -- quotedblbase  = "comma comma",
32    },
33}
34
35addotffeature("tlig",specification)
36
37registerotffeature {
38    -- this makes it a known feature (in tables)
39    name        = "tlig",
40    description = "tex ligatures",
41}
42
43-- trep
44
45local specification = {
46    type      = "substitution",
47    order     = { "trep" },
48    prepend   = true,
49    data      = {
50     -- [0x0022] = 0x201D,
51        [0x0027] = 0x2019,
52     -- [0x0060] = 0x2018,
53    },
54}
55
56addotffeature("trep",specification)
57
58registerotffeature {
59    -- this makes it a known feature (in tables)
60    name        = "trep",
61    description = "tex replacements",
62}
63
64-- some day this will be moved to font-imp-scripts.lua
65
66-- anum
67
68local anum_arabic = {
69    [0x0030] = 0x0660,
70    [0x0031] = 0x0661,
71    [0x0032] = 0x0662,
72    [0x0033] = 0x0663,
73    [0x0034] = 0x0664,
74    [0x0035] = 0x0665,
75    [0x0036] = 0x0666,
76    [0x0037] = 0x0667,
77    [0x0038] = 0x0668,
78    [0x0039] = 0x0669,
79}
80
81local anum_persian = {
82    [0x0030] = 0x06F0,
83    [0x0031] = 0x06F1,
84    [0x0032] = 0x06F2,
85    [0x0033] = 0x06F3,
86    [0x0034] = 0x06F4,
87    [0x0035] = 0x06F5,
88    [0x0036] = 0x06F6,
89    [0x0037] = 0x06F7,
90    [0x0038] = 0x06F8,
91    [0x0039] = 0x06F9,
92}
93
94local function valid(data)
95    local features = data.resources.features
96    if features then
97        for k, v in next, features do
98            for k, v in next, v do
99                if v.arab then
100                    return true
101                end
102            end
103        end
104    end
105end
106
107local specification = {
108    {
109        type     = "substitution",
110        features = { arab = { urd = true, dflt = true } },
111        order    = { "anum" },
112        data     = anum_arabic,
113        valid    = valid,
114    },
115    {
116        type     = "substitution",
117        features = { arab = { urd = true } },
118        order    = { "anum" },
119        data     = anum_persian,
120        valid    = valid,
121    },
122}
123
124addotffeature("anum",specification)
125
126registerotffeature {
127    -- this makes it a known feature (in tables)
128    name        = "anum",
129    description = "arabic digits",
130}
131
132-- -- example:
133--
134-- fonts.handlers.otf.addfeature {
135--     name     = "hangulfix",
136--     type     = "substitution",
137--     features = { ["hang"] = { ["*"] = true } },
138--     data     = {
139--         [0x1160] = 0x119E,
140--     },
141--     order    = { "hangulfix" },
142--     flags    = { },
143--     prepend  = true,
144-- })
145