typo-adj.lmt /size: 2496 b    last modification: 2025-02-21 11:03
1if not modules then modules = { } end modules ['typo-adj'] = {
2    version   = 1.001,
3    optimize  = true,
4    comment   = "companion to typo-adj.mkxl",
5    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
6    copyright = "PRAGMA ADE / ConTeXt Development Team",
7    license   = "see context related readme files"
8}
9
10local hlist_code   <const> = nodes.nodecodes.hlist
11local penalty_code <const> = nodes.nodecodes.penalty
12
13local nuts         = nodes.nuts
14local getprev      = nuts.getprev
15local getid        = nuts.getid
16----- getattr      = nuts.getattribute
17local getdepth     = nuts.getdepth
18local newglue      = nuts.pool.glue
19local insertafter  = nuts.insertafter
20
21local texgetdimen  = tex.getdimen
22
23----- a_adjuster   = attributes.system("adjuster")
24
25local function correct_depth(head,tail)
26    local prev = getprev(tail)
27    if getid(prev) == penalty_code then -- linebreakpenalty
28        prev = getprev(prev)
29    end
30    if getid(prev) == hlist_code then -- line
31        local delta = getdepth(tail) - getdepth(prev)
32        if delta > 0 then
33            head = insertafter(head,prev,newglue(delta))
34        end
35        tex.prevdepth = getdepth(tail)
36    end
37    return head
38end
39
40local function block_baselineskip(head,tail)
41 -- tex.prevdepth = -1000 * 65536 -- ignoredepth
42    tex.prevdepth = texgetdimen("ignoredepthcriterion") -- todo: c_...
43    return head
44end
45
46local preactions = {
47    [1] = correct_depth,
48    [2] = block_baselineskip,
49}
50
51local postactions = {
52    [1] = correct_depth,
53    [2] = block_baselineskip,
54}
55
56-- function nodes.handlers.adjusters(head,where,tail)
57--     if where == "preadjust" then
58--         local a = getattr(tail,a_adjuster)
59--         if a then
60--             a = preactions[a]
61--             if a then
62--                 head = a(head,tail)
63--             end
64--         end
65--     elseif where == "postadjust" then
66--         local a = getattr(tail,a_adjuster)
67--         if a then
68--             a = postactions[a]
69--             if a then
70--                 head = a(head,tail)
71--             end
72--         end
73--     else
74--         -- can't happen
75--     end
76--     return head
77-- end
78
79function nodes.handlers.adjusters(head,where,tail,index)
80    if where == "preadjust" then
81        local a = preactions[index]
82        if a then
83            head = a(head,tail)
84        end
85    else -- if where == "postadjust" then
86        local a = postactions[index]
87        if a then
88            head = a(head,tail)
89        end
90    end
91    return head
92end
93