summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/font-imp-math.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkxl/font-imp-math.lmt')
-rw-r--r--Master/texmf-dist/tex/context/base/mkxl/font-imp-math.lmt226
1 files changed, 226 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkxl/font-imp-math.lmt b/Master/texmf-dist/tex/context/base/mkxl/font-imp-math.lmt
new file mode 100644
index 00000000000..277190f2410
--- /dev/null
+++ b/Master/texmf-dist/tex/context/base/mkxl/font-imp-math.lmt
@@ -0,0 +1,226 @@
+if not modules then modules = { } end modules ['font-imp-math'] = {
+ version = 1.001,
+ comment = "companion to font-ini.mkiv and hand-ini.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local next, type, tonumber = next, type, tonumber
+
+local fonts = fonts
+local helpers = fonts.helpers
+local registerotffeature = fonts.handlers.otf.features.register
+
+local setmetatableindex = table.setmetatableindex
+
+local texconditionals = tex.conditionals
+
+-- tfmdata.properties.mathnolimitsmode = tonumber(value) or 0
+
+local splitter = lpeg.splitat(",",tonumber)
+local lpegmatch = lpeg.match
+
+local function initialize(tfmdata,value)
+ local mathparameters = tfmdata.mathparameters
+ if mathparameters then
+ local sup, sub
+ if type(value) == "string" then
+ sup, sub = lpegmatch(splitter,value)
+ if not sup then
+ sub, sup = 0, 0
+ elseif not sub then
+ sub, sup = sup, 0
+ end
+ elseif type(value) == "number" then
+ sup, sub = 0, value
+ end
+ if sup then
+ mathparameters.NoLimitSupFactor = sup
+ end
+ if sub then
+ mathparameters.NoLimitSubFactor = sub
+ end
+ end
+end
+
+registerotffeature {
+ name = "mathnolimitsmode",
+ description = "influence nolimits placement",
+ initializers = {
+ base = initialize,
+ node = initialize,
+ }
+}
+
+-- this will become a mode in the engine
+
+local function initialize(tfmdata,value)
+ tfmdata.properties.nostackmath = value and true
+end
+
+registerotffeature {
+ name = "nostackmath",
+ description = "disable math stacking mechanism",
+ initializers = {
+ base = initialize,
+ node = initialize,
+ }
+}
+
+-- A quick and dirty and low level implementation but okay for testing:
+
+function fonts.helpers.mathscriptslots(tfmdata,textcode)
+ local rawdata = tfmdata.shared.rawdata
+ local rawresources = rawdata and rawdata.resources
+ local rawfeatures = rawresources and rawresources.features
+ local basesubstitutions = rawfeatures and rawfeatures.gsub
+ local sequences = basesubstitutions and tfmdata.resources.sequences
+ if sequences then
+ local characters = tfmdata.characters
+ if characters[textcode] then
+ for s=1,#sequences do
+ local sequence = sequences[s]
+ local sfeatures = sequence.features
+ if sfeatures and sfeatures.ssty then
+ local steps = sequence.steps
+ for i=1,#steps do
+ local coverage = steps[i].coverage
+ if coverage then
+ local okay = coverage[textcode]
+ if okay then
+ return okay
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+local function manipulate(tfmdata,key,value)
+ if texconditionals["c_font_compact"] then
+ local rawdata = tfmdata.shared.rawdata
+ local rawresources = rawdata and rawdata.resources
+ local rawfeatures = rawresources and rawresources.features
+ local basesubstitutions = rawfeatures and rawfeatures.gsub
+ local sequences = basesubstitutions and tfmdata.resources.sequences
+
+ if sequences then
+ local characters = tfmdata.characters
+ for s=1,#sequences do
+ local sequence = sequences[s]
+ local sfeatures = sequence.features
+ if sfeatures and sfeatures.ssty then
+ local steps = sequence.steps
+ for i=1,#steps do
+ local coverage = steps[i].coverage
+ if coverage then
+ for textcode, v in next, coverage do
+ local textdata = characters[textcode]
+ if textdata then
+ local scriptcode = v[1]
+ local scriptscriptcode = v[2]
+ local scriptdata = characters[scriptcode]
+ local scriptscriptdata = characters[scriptscriptcode]
+ if scriptdata then
+ textdata.smaller = scriptcode
+ end
+ if scriptscriptdata then
+ scriptdata.smaller = scriptscriptcode
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+local function initialize(tfmdata,key,value)
+ if texconditionals["c_font_compact"] then
+ local rawdata = tfmdata.shared.rawdata
+ local rawresources = rawdata and rawdata.resources
+ local mathconstants = rawresources.mathconstants
+ if mathconstants then
+ local parameters = tfmdata.parameters
+ parameters.textscale = 1000
+ parameters.scriptscale = mathconstants.ScriptPercentScaleDown * 10
+ parameters.scriptscriptscale = mathconstants.ScriptScriptPercentScaleDown * 10
+ end
+ end
+end
+
+local specification = {
+ name = "compactmath",
+ description = "use one math font",
+ manipulators = {
+ base = manipulate,
+ node = manipulate,
+ },
+ initializers = {
+ base = initialize,
+ node = initialize,
+ }
+}
+
+registerotffeature(specification)
+
+-- The problem is that the traditional code path doesn't add an italic to the subscript,
+-- simply because it assumes that the width has that already subtracted. So, we cannot
+-- compensate in the following way. We're stuck with the fact that the texgyre fonts
+-- assume a traditional tex engine.
+
+-- local function manipulate(tfmdata,key,value)
+-- if value == "correct" then
+-- local chardata = characters.data
+-- for unicode, data in next, tfmdata.characters do
+-- local italic = data.italic
+-- if italic then
+-- -- todo: only letters
+-- data.width = (data.width or 0) + italic
+-- local cd = chardata[unicode]
+-- if cd then
+-- local visual = cd.visual
+-- if visual == "it" or visual == "bi" then
+-- italic = -italic
+-- else
+-- italic = 0
+-- end
+-- else
+-- italic = 0
+-- end
+-- data.italic = italic
+-- end
+-- end
+-- end
+-- end
+
+local function initialize(tfmdata,key,value)
+ if value then
+ local rawdata = tfmdata.shared.rawdata
+ local rawresources = rawdata and rawdata.resources
+ local mathconstants = rawresources.mathconstants
+ if mathconstants then
+ tfmdata.properties.oldmath = true
+ end
+ end
+end
+
+local specification = {
+ name = "oldmath",
+ description = "deal with fake opentype fonts",
+ -- manipulators = {
+ -- base = manipulate,
+ -- node = manipulate,
+ -- },
+ initializers = {
+ base = initialize,
+ node = initialize,
+ }
+}
+
+registerotffeature(specification)