if not modules then modules = { } end modules ['typo-adj'] = { version = 1.001, optimize = true, comment = "companion to typo-adj.mkxl", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" } local setdimen = tex.setdimen local setcount = tex.setcount local setmacro = tokens.setters.macro local expandmacro = token.expandmacro local nuts = nodes.nuts local getwhd = nuts.getwhd local getattr = nuts.getattr local getwidth = nuts.getwidth local setlist = nuts.setlist local setlink = nuts.setlink local setstate = nuts.setstate local takebox = nuts.takebox local new_kern = nuts.pool.kern local traverselist = node.direct.traverselist local traverseleader = node.direct.traverseleader local a_adaptive = attributes.private("adaptive") local registervalue = attributes.registervalue local getvalue = attributes.getvalue local hasvalues = attributes.hasvalues local texsetattribute = tex.setattribute local adaptive = nodes.adaptive or { } nodes.adaptive = adaptive local enabled = false local enableaction = nodes.tasks.enableaction function adaptive.set(settings) if not enabled then enableaction("vboxbuilders","nodes.adaptive.handle") enabled = true end texsetattribute(a_adaptive,registervalue(a_adaptive,settings)) end local function setadaptive(w,h,d,l,c) setdimen("d_adaptive_width",w) setdimen("d_adaptive_height",h) setdimen("d_adaptive_depth",d) setdimen("d_adaptive_line",l) setmacro("m_adaptive_color",c) end local methods = { -- overlay [1] = function(settings,hlist,list) local setups = settings.setups if setups and setups ~= "" then local w, h, d = getwhd(hlist) setadaptive(w,h,d,settings.rulethickness,settings.color) expandmacro("setup",true,setups) local l = takebox("b_adaptive_box") if l then setlist(hlist, setlink(l,new_kern(-getwidth(l)),list)) end end end } function adaptive.handle(n) if hasvalues(a_adaptive) then for _, _, _, l in traverselist(n) do for m, _, _, ll in traverseleader(l) do local settings = getvalue(a_adaptive,getattr(m,a_adaptive)) if settings then setstate(m,0) local action = methods[settings.method or 1] if action then action(settings,m,ll) end end end end end return n end interfaces.implement { name = "setadaptive", actions = adaptive.set, arguments = { { { "setups", "string" }, { "method", "integer" }, { "mp", "string" }, { "color", "string" }, { "rulethickness", "dimension" }, } } } nodes.tasks.prependaction("vboxbuilders", "normalizers", "nodes.adaptive.handle", nil, "nut", "disabled")