summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/driv-ini.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkxl/driv-ini.lmt')
-rw-r--r--tex/context/base/mkxl/driv-ini.lmt145
1 files changed, 145 insertions, 0 deletions
diff --git a/tex/context/base/mkxl/driv-ini.lmt b/tex/context/base/mkxl/driv-ini.lmt
index 7b50a8cbf..729196e87 100644
--- a/tex/context/base/mkxl/driv-ini.lmt
+++ b/tex/context/base/mkxl/driv-ini.lmt
@@ -61,6 +61,150 @@ local defaulthandlers = {
outputfilename = dummy,
}
+local installwhatsits do
+
+ local leaderlevel = 0
+ local backends = backends
+
+ local function pushleaderlevel()
+ leaderlevel = leaderlevel + 1
+ end
+
+ local function popleaderlevel()
+ leaderlevel = leaderlevel - 1
+ end
+
+ local function flushlatelua(current,h,v)
+ -- Here we assume maganement by the lua function so currently we don't
+ -- check for leaderlevel.
+ return backends.latelua(current,h,v)
+ end
+
+ local function flushwriteout(current)
+ if leaderlevel == 0 then
+ backends.writeout(current)
+ end
+ end
+
+ local function flushopenout(current)
+ if leaderlevel == 0 then
+ backends.openout(current)
+ end
+ end
+
+ local function flushcloseout(current)
+ if leaderlevel == 0 then
+ backends.closeout(current)
+ end
+ end
+
+ local function flushsavepos(current,pos_h,pos_v)
+ local jp = job.positions
+ jp.lastx = pos_h
+ jp.lasty = pos_v
+ end
+
+ local function flushuserdefined()
+ -- nothing here
+ end
+
+ local whatsitcodes = nodes.whatsitcodes
+
+ local trace = true trackers.register("backends.whatsits",function(v) trace = v end)
+
+ installwhatsits = function(name,flushers)
+
+ -- latelua : specific
+ -- userdefined : special purpose, handled in callbacks
+ -- savepos : only used by generic packages
+ -- open : generic
+ -- close : generic
+ -- write : generic
+
+ -- An alternative is to have a first time setter.
+
+ local function checkagain(t, k)
+ local v = rawget(flushers,k) -- in case it's registered later
+ if not v then
+ if trace then
+ report("unsupported whatsit %a in driver %a",whatsitcodes[k] or k,name)
+ end
+ v = function() end
+ end
+ t[k] = v
+ return v
+ end
+
+ -- flushers.whatsit = setmetatableindex ( {
+ -- [whatsitcodes.literal] = flushers.literal,
+ -- [whatsitcodes.latelua] = flushlatelua,
+ -- [whatsitcodes.userdefined] = flushuserdefined,
+ -- [whatsitcodes.savepos] = flushsavepos,
+ -- [whatsitcodes.save] = flushers.save,
+ -- [whatsitcodes.restore] = flushers.restore,
+ -- [whatsitcodes.setmatrix] = flushers.setmatrix,
+ -- [whatsitcodes.open] = flushopenout,
+ -- [whatsitcodes.close] = flushcloseout,
+ -- [whatsitcodes.write] = flushwriteout,
+ -- [whatsitcodes.startmatrix] = flushers.startmatrix,
+ -- [whatsitcodes.stopmatrix] = flushers.stopmatrix,
+ -- [whatsitcodes.startscaling] = flushers.startscaling,
+ -- [whatsitcodes.stopscaling] = flushers.stopscaling,
+ -- [whatsitcodes.startrotation] = flushers.startrotation,
+ -- [whatsitcodes.stoprotation] = flushers.stoprotation,
+ -- [whatsitcodes.startmirroring] = flushers.startmirroring,
+ -- [whatsitcodes.stopmirroring] = flushers.stopmirroring,
+ -- [whatsitcodes.startclipping] = flushers.startclipping,
+ -- [whatsitcodes.stopclipping] = flushers.stopclipping,
+ -- [whatsitcodes.setstate] = flushers.setstate,
+ -- }, checkagain )
+
+ -- -- sparse
+
+ -- flushers.whatsit = setmetatableindex ( {
+ -- [whatsitcodes.latelua] = flushlatelua,
+ -- [whatsitcodes.userdefined] = flushuserdefined,
+ -- [whatsitcodes.savepos] = flushsavepos,
+ -- [whatsitcodes.open] = flushopenout,
+ -- [whatsitcodes.close] = flushcloseout,
+ -- [whatsitcodes.write] = flushwriteout,
+ -- }, checkagain )
+
+ -- -- delayed
+
+ local whatsit ; whatsit = setmetatableindex ( {
+ [whatsitcodes.literal] = flushers.literal or function(...) return checkagain(whatsit,whatsitcodes.literal )(...) end,
+ [whatsitcodes.latelua] = flushlatelua,
+ [whatsitcodes.userdefined] = flushuserdefined,
+ [whatsitcodes.savepos] = flushsavepos,
+ [whatsitcodes.save] = flushers.save or function(...) return checkagain(whatsit,whatsitcodes.save )(...) end,
+ [whatsitcodes.restore] = flushers.restore or function(...) return checkagain(whatsit,whatsitcodes.restore )(...) end,
+ [whatsitcodes.setmatrix] = flushers.setmatrix or function(...) return checkagain(whatsit,whatsitcodes.setmatrix )(...) end,
+ [whatsitcodes.open] = flushopenout,
+ [whatsitcodes.close] = flushcloseout,
+ [whatsitcodes.write] = flushwriteout,
+ [whatsitcodes.startmatrix] = flushers.startmatrix or function(...) return checkagain(whatsit,whatsitcodes.startmatrix )(...) end,
+ [whatsitcodes.stopmatrix] = flushers.stopmatrix or function(...) return checkagain(whatsit,whatsitcodes.stopmatrix )(...) end,
+ [whatsitcodes.startscaling] = flushers.startscaling or function(...) return checkagain(whatsit,whatsitcodes.startscaling )(...) end,
+ [whatsitcodes.stopscaling] = flushers.stopscaling or function(...) return checkagain(whatsit,whatsitcodes.stopscaling )(...) end,
+ [whatsitcodes.startrotation] = flushers.startrotation or function(...) return checkagain(whatsit,whatsitcodes.startrotation )(...) end,
+ [whatsitcodes.stoprotation] = flushers.stoprotation or function(...) return checkagain(whatsit,whatsitcodes.stoprotation )(...) end,
+ [whatsitcodes.startmirroring] = flushers.startmirroring or function(...) return checkagain(whatsit,whatsitcodes.startmirroring)(...) end,
+ [whatsitcodes.stopmirroring] = flushers.stopmirroring or function(...) return checkagain(whatsit,whatsitcodes.stopmirroring )(...) end,
+ [whatsitcodes.startclipping] = flushers.startclipping or function(...) return checkagain(whatsit,whatsitcodes.startclipping )(...) end,
+ [whatsitcodes.stopclipping] = flushers.stopclipping or function(...) return checkagain(whatsit,whatsitcodes.stopclippin )(...) end,
+ [whatsitcodes.setstate] = flushers.setstate or function(...) return checkagain(whatsit,whatsitcodes.setstate )(...) end,
+ }, checkagain)
+
+ flushers.whatsit = whatsit
+
+ flushers.pushleaderlevel = pushleaderlevel
+ flushers.popleaderlevel = popleaderlevel
+
+ end
+
+end
+
function drivers.install(specification)
local name = specification.name
if not name then
@@ -77,6 +221,7 @@ function drivers.install(specification)
report("no flushers for driver %a",name)
return
end
+ installwhatsits(name,flushers)
-- report("driver %a is installed",name)
setmetatableindex(actions, defaulthandlers)
setmetatableindex(flushers, function() return dummy end)