font-imp-math.lua /size: 3594 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['font-imp-math'] = {
2    version   = 1.001,
3    comment   = "companion to font-ini.mkiv and hand-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
9if not context then return end
10
11local next, type, tonumber = next, type, tonumber
12
13local fonts              = fonts
14local helpers            = fonts.helpers
15local registerotffeature = fonts.handlers.otf.features.register
16
17local setmetatableindex  = table.setmetatableindex
18
19-- local splitter  = lpeg.splitat(",",tonumber)
20-- local lpegmatch = lpeg.match
21--
22-- local function initialize(tfmdata,value)
23--     local mathparameters = tfmdata.mathparameters
24--     if mathparameters then
25--         local sup, sub
26--         if type(value) == "string" then
27--             sup, sub = lpegmatch(splitter,value)
28--             if not sup then
29--                 sub, sup = 0, 0
30--             elseif not sub then
31--                 sub, sup = sup, 0
32--             end
33--         elseif type(value) == "number" then
34--             sup, sub = 0, value
35--         end
36--         if sup then
37--             mathparameters.NoLimitSupFactor = sup
38--         end
39--         if sub then
40--             mathparameters.NoLimitSubFactor = sub
41--         end
42--     end
43-- end
44--
45-- registerotffeature {
46--     name         = "mathnolimitsmode",
47--     description  = "influence nolimits placement",
48--     initializers = {
49--         base = initialize,
50--         node = initialize,
51--     }
52-- }
53
54local function initialize(tfmdata,value)
55    tfmdata.properties.nostackmath = value and true
56end
57
58registerotffeature {
59    name        = "nostackmath",
60    description = "disable math stacking mechanism",
61    initializers = {
62        base = initialize,
63        node = initialize,
64    }
65}
66
67function fonts.helpers.mathscriptslots(tfmdata,textcode)
68    local rawdata           = tfmdata.shared.rawdata
69    local rawresources      = rawdata and rawdata.resources
70    local rawfeatures       = rawresources and rawresources.features
71    local basesubstitutions = rawfeatures and rawfeatures.gsub
72    local sequences         = basesubstitutions and tfmdata.resources.sequences
73    if sequences then
74        local characters = tfmdata.characters
75        if characters[textcode] then
76            for s=1,#sequences do
77                local sequence  = sequences[s]
78                local sfeatures = sequence.features
79                if sfeatures and sfeatures.ssty then
80                    local steps = sequence.steps
81                    for i=1,#steps do
82                        local coverage = steps[i].coverage
83                        if coverage then
84                            local okay = coverage[textcode]
85                            if okay then
86                                return okay
87                            end
88                        end
89                    end
90                end
91            end
92        end
93    end
94end
95
96local function initialize(tfmdata,value)
97    if value then
98        local rawdata       = tfmdata.shared.rawdata
99        local rawresources  = rawdata and rawdata.resources
100        local mathconstants = rawresources.mathconstants
101        if mathconstants then
102            tfmdata.properties.oldmath = true
103        end
104    end
105end
106
107local specification = {
108    name         = "oldmath",
109    description  = "deal with fake opentype fonts",
110    initializers = {
111        base = initialize,
112        node = initialize,
113    }
114}
115
116registerotffeature(specification)
117