font-imp-math.lua /size: 3948 b    last modification: 2021-10-28 13:50
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-- requested for latex but not supported unless really needed in context:
20--
21-- registerotffeature {
22--     name         = "ignoremathconstants",
23--     description  = "ignore math constants table",
24--     initializers = {
25--         base = function(tfmdata,value)
26--             if value then
27--                 tfmdata.mathparameters = nil
28--             end
29--         end
30--     }
31-- }
32
33-- tfmdata.properties.mathnolimitsmode = tonumber(value) or 0
34
35local splitter  = lpeg.splitat(",",tonumber)
36local lpegmatch = lpeg.match
37
38local function initialize(tfmdata,value)
39    local mathparameters = tfmdata.mathparameters
40    if mathparameters then
41        local sup, sub
42        if type(value) == "string" then
43            sup, sub = lpegmatch(splitter,value)
44            if not sup then
45                sub, sup = 0, 0
46            elseif not sub then
47                sub, sup = sup, 0
48            end
49        elseif type(value) == "number" then
50            sup, sub = 0, value
51        end
52        if sup then
53            mathparameters.NoLimitSupFactor = sup
54        end
55        if sub then
56            mathparameters.NoLimitSubFactor = sub
57        end
58    end
59end
60
61registerotffeature {
62    name         = "mathnolimitsmode",
63    description  = "influence nolimits placement",
64    initializers = {
65        base = initialize,
66        node = initialize,
67    }
68}
69
70local function initialize(tfmdata,value)
71    tfmdata.properties.nostackmath = value and true
72end
73
74registerotffeature {
75    name        = "nostackmath",
76    description = "disable math stacking mechanism",
77    initializers = {
78        base = initialize,
79        node = initialize,
80    }
81}
82
83function fonts.helpers.mathscriptslots(tfmdata,textcode)
84    local rawdata           = tfmdata.shared.rawdata
85    local rawresources      = rawdata and rawdata.resources
86    local rawfeatures       = rawresources and rawresources.features
87    local basesubstitutions = rawfeatures and rawfeatures.gsub
88    local sequences         = basesubstitutions and tfmdata.resources.sequences
89    if sequences then
90        local characters = tfmdata.characters
91        if characters[textcode] then
92            for s=1,#sequences do
93                local sequence  = sequences[s]
94                local sfeatures = sequence.features
95                if sfeatures and sfeatures.ssty then
96                    local steps = sequence.steps
97                    for i=1,#steps do
98                        local coverage = steps[i].coverage
99                        if coverage then
100                            local okay = coverage[textcode]
101                            if okay then
102                                return okay
103                            end
104                        end
105                    end
106                end
107            end
108        end
109    end
110end
111
112local function initialize(tfmdata,value)
113    if value then
114        local rawdata       = tfmdata.shared.rawdata
115        local rawresources  = rawdata and rawdata.resources
116        local mathconstants = rawresources.mathconstants
117        if mathconstants then
118            tfmdata.properties.oldmath = true
119        end
120    end
121end
122
123local specification = {
124    name         = "oldmath",
125    description  = "deal with fake opentype fonts",
126    initializers = {
127        base = initialize,
128        node = initialize,
129    }
130}
131
132registerotffeature(specification)
133