1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
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")
|