font-imp-tex.lua /size: 3355 b    last modification: 2023-12-21 09:44
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-- We provide a few old and obsolete compatibility input features. We need numbers
17-- for some fonts so no names here. Do we also need them for afm fonts?
18
19local tlig = {
20    type     = "ligature",
21    order    = { "tlig" },
22    prepend  = true,
23    data     = {
24        [0x2013] = { 0x002D, 0x002D },
25        [0x2014] = { 0x002D, 0x002D, 0x002D },
26    },
27}
28
29local tquo = {
30    type     = "ligature",
31    order    = { "tquo" },
32    prepend  = true,
33    data     = {
34        [0x201C] = { 0x0060, 0x0060 },
35        [0x201D] = { 0x0027, 0x0027 },
36        [0x201E] = { 0x002C, 0x002C },
37    },
38}
39
40local trep = {
41    type      = "substitution",
42    order     = { "trep" },
43    prepend   = true,
44    data      = {
45     -- [0x0022] = 0x201D,
46        [0x0027] = 0x2019,
47     -- [0x0060] = 0x2018,
48    },
49}
50
51addotffeature("trep",trep) -- last
52addotffeature("tlig",tlig)
53addotffeature("tquo",tquo) -- first
54
55registerotffeature { name = "tlig", description = "tex ligatures" }
56registerotffeature { name = "tquo", description = "tex quotes" }
57registerotffeature { name = "trep", description = "tex replacements" }
58
59-- some day this will be moved to font-imp-scripts.lua
60
61-- anum
62
63local anum_arabic = {
64    [0x0030] = 0x0660,
65    [0x0031] = 0x0661,
66    [0x0032] = 0x0662,
67    [0x0033] = 0x0663,
68    [0x0034] = 0x0664,
69    [0x0035] = 0x0665,
70    [0x0036] = 0x0666,
71    [0x0037] = 0x0667,
72    [0x0038] = 0x0668,
73    [0x0039] = 0x0669,
74}
75
76local anum_persian = {
77    [0x0030] = 0x06F0,
78    [0x0031] = 0x06F1,
79    [0x0032] = 0x06F2,
80    [0x0033] = 0x06F3,
81    [0x0034] = 0x06F4,
82    [0x0035] = 0x06F5,
83    [0x0036] = 0x06F6,
84    [0x0037] = 0x06F7,
85    [0x0038] = 0x06F8,
86    [0x0039] = 0x06F9,
87}
88
89local function valid(data)
90    local features = data.resources.features
91    if features then
92        for k, v in next, features do
93            for k, v in next, v do
94                if v.arab then
95                    return true
96                end
97            end
98        end
99    end
100end
101
102local specification = {
103    {
104        type     = "substitution",
105        features = { arab = { urd = true, dflt = true } },
106        order    = { "anum" },
107        data     = anum_arabic,
108        valid    = valid,
109    },
110    {
111        type     = "substitution",
112        features = { arab = { urd = true } },
113        order    = { "anum" },
114        data     = anum_persian,
115        valid    = valid,
116    },
117}
118
119addotffeature("anum",specification)
120
121registerotffeature {
122    -- this makes it a known feature (in tables)
123    name        = "anum",
124    description = "arabic digits",
125}
126
127-- -- example:
128--
129-- fonts.handlers.otf.addfeature {
130--     name     = "hangulfix",
131--     type     = "substitution",
132--     features = { ["hang"] = { ["*"] = true } },
133--     data     = {
134--         [0x1160] = 0x119E,
135--     },
136--     order    = { "hangulfix" },
137--     flags    = { },
138--     prepend  = true,
139-- })
140