if not modules then modules = { } end modules ['node-ini'] = {
version = 1.001,
comment = "companion to node-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
--[[ldx--
Most of the code that had accumulated here is now separated in modules.
--ldx]]--
local next, type, tostring = next, type, tostring
local gsub = string.gsub
local concat, remove = table.concat, table.remove
local sortedhash, sortedkeys, swapped = table.sortedhash, table.sortedkeys, table.swapped
--[[ldx--
Access to nodes is what gives its power. Here we implement a
few helper functions. These functions are rather optimized.
--ldx]]--
nodes = nodes or { }
local nodes = nodes
nodes.handlers = nodes.handlers or { }
local mark = utilities.storage.mark
local allocate = utilities.storage.allocate
local formatcolumns = utilities.formatters.formatcolumns
local getsubtypes = node.subtypes
local getvalues = node.values
tex.magicconstants = { -- we use tex.constants for something else
running = -1073741824, -- null_flag
maxdimen = 1073741823, -- max_dimen
-- trueinch = 4736286, -- obsolete
}
do
local c = status.getconstants()
local t = { }
for k, v in next, c do
t[gsub(k,"_","")] = v
end
tex.magicconstants = table.setmetatableindex(t,c)
end
local listcodes = mark(getsubtypes("list"))
local rulecodes = mark(getsubtypes("rule"))
local dircodes = mark(getsubtypes("dir"))
local markcodes = mark(getsubtypes("mark"))
local glyphcodes = mark(getsubtypes("glyph"))
local disccodes = mark(getsubtypes("disc"))
local gluecodes = mark(getsubtypes("glue"))
local boundarycodes = mark(getsubtypes("boundary"))
local penaltycodes = mark(getsubtypes("penalty"))
local kerncodes = mark(getsubtypes("kern"))
local mathcodes = mark(getsubtypes("math"))
local noadcodes = mark(getsubtypes("noad"))
local radicalcodes = mark(getsubtypes("radical"))
local accentcodes = mark(getsubtypes("accent"))
local fencecodes = mark(getsubtypes("fence"))
----- fractioncodes = mark(getsubtypes("fraction"))
local parcodes = mark(getsubtypes("par"))
local fillvalues = mark(getvalues("fill"))
local dirvalues = mark(getvalues("dir"))
local mathvalues = mark(getvalues("math"))
local function simplified(t)
local r = { }
for k, v in next, t do
r[k] = gsub(v,"_","")
end
return r
end
local noadoptions = allocate {
set = 0x08,
unused_1 = 0x00 + 0x08,
unused_2 = 0x01 + 0x08,
axis = 0x02 + 0x08,
no_axis = 0x04 + 0x08,
exact = 0x10 + 0x08,
left = 0x11 + 0x08,
middle = 0x12 + 0x08,
right = 0x14 + 0x08,
}
local nodecodes = simplified(node.types())
gluecodes = allocate(swapped(gluecodes,gluecodes))
dircodes = allocate(swapped(dircodes,dircodes))
markcodes = allocate(swapped(markcodes,markcodes))
boundarycodes = allocate(swapped(boundarycodes,boundarycodes))
noadcodes = allocate(swapped(noadcodes,noadcodes))
radicalcodes = allocate(swapped(radicalcodes,radicalcodes))
nodecodes = allocate(swapped(nodecodes,nodecodes))
listcodes = allocate(swapped(listcodes,listcodes))
glyphcodes = allocate(swapped(glyphcodes,glyphcodes))
kerncodes = allocate(swapped(kerncodes,kerncodes))
penaltycodes = allocate(swapped(penaltycodes,penaltycodes))
mathcodes = allocate(swapped(mathcodes,mathcodes))
disccodes = allocate(swapped(disccodes,disccodes))
accentcodes = allocate(swapped(accentcodes,accentcodes))
fencecodes = allocate(swapped(fencecodes,fencecodes))
parcodes = allocate(swapped(parcodes,parcodes))
rulecodes = allocate(swapped(rulecodes,rulecodes))
noadoptions = allocate(swapped(noadoptions,noadoptions))
dirvalues = allocate(swapped(dirvalues,dirvalues))
fillvalues = allocate(swapped(fillvalues,fillvalues))
mathvalues = allocate(swapped(mathvalues,mathvalues))
nodes.gluecodes = gluecodes
nodes.dircodes = dircodes
nodes.markcodes = markcodes
nodes.boundarycodes = boundarycodes
nodes.noadcodes = noadcodes
nodes.listcodes = listcodes
nodes.glyphcodes = glyphcodes
nodes.kerncodes = kerncodes
nodes.penaltycodes = penaltycodes
nodes.mathcodes = mathcodes
nodes.disccodes = disccodes
nodes.accentcodes = accentcodes
nodes.radicalcodes = radicalcodes
nodes.fencecodes = fencecodes
nodes.parcodes = parcodes
nodes.rulecodes = rulecodes
nodes.noadoptions = noadoptions
nodes.fillvalues = fillvalues
nodes.fillcodes = fillvalues -- for now
nodes.dirvalues = dirvalues
nodes.mathvalues = mathvalues
nodes.nodecodes = nodecodes
local subtypes = allocate {
glue = gluecodes,
dir = dircodes,
mark = markcodes,
boundary = boundarycodes,
noad = noadcodes,
glyph = glyphcodes,
kern = kerncodes,
penalty = penaltycodes,
math = mathcodes,
disc = disccodes,
accent = accentcodes,
radical = radicalcodes,
fence = fencecodes,
par = parcodes,
rule = rulecodes,
vlist = listcodes,
hlist = listcodes,
-- list = listcodes,
-- parameter = parametercodes,
-- user = usercodes,
}
for k, v in table.sortedhash(subtypes) do
local i = nodecodes[k]
if i and not subtypes[i] then
subtypes[i] = v
end
end
nodes.subtypes = subtypes
-- a few more friendly aliases:
nodes.skipcodes = gluecodes
nodes.directioncodes = dircodes
nodes.discretionarycodes = disccodes
nodes.directionvalues = dirvalues
glyphcodes.glyph = glyphcodes.character
gluecodes.parfillrightskip = gluecodes.parfillrightskip or gluecodes.parfillskip
gluecodes.parfillskip = gluecodes.parfillskip or gluecodes.parfillrightskip
listcodes.row = listcodes.alignment
listcodes.column = listcodes.alignment
kerncodes.kerning = kerncodes.fontkern
kerncodes.italiccorrection = kerncodes.italiccorrection or 1 -- new
nodes.noadoptions = {
set = 0x08,
unused_1 = 0x00 + 0x08,
unused_2 = 0x01 + 0x08,
axis = 0x02 + 0x08,
no_axis = 0x04 + 0x08,
exact = 0x10 + 0x08,
left = 0x11 + 0x08,
middle = 0x12 + 0x08,
right = 0x14 + 0x08,
}
-- We use the real node code numbers.
local texsetintegervalue = tex.setintegervalue
for i=0,nodecodes.glyph do
texsetintegervalue(nodecodes[i] .. "nodecode",i,"immutable")
end
for i=0,#gluecodes do
texsetintegervalue(gluecodes[i] .. "subtypecode",i,"immutable")
end
nodes.specialskipcodes = {
[gluecodes.leftskip] = true,
[gluecodes.rightskip] = true,
[gluecodes.lefthangskip] = true,
[gluecodes.righthangskip] = true,
[gluecodes.parfillleftskip or parfillskip_code] = true,
[gluecodes.parfillrightskip or parfillskip_code] = true,
[gluecodes.indentskip] = true,
[gluecodes.correctionskip] = true,
}