typo-adj.lmt /size: 2490 b    last modification: 2024-01-16 10:22
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 nodecodes    = nodes.nodecodes
11local hlist_code   = nodecodes.hlist
12local penalty_code = nodecodes.penalty
13
14local nuts         = nodes.nuts
15local getprev      = nuts.getprev
16local getid        = nuts.getid
17----- getattr      = nuts.getattribute
18local getdepth     = nuts.getdepth
19local newglue      = nuts.pool.glue
20local insertafter  = nuts.insertafter
21
22local texgetdimen  = tex.getdimen
23
24----- a_adjuster   = attributes.system("adjuster")
25
26local function correct_depth(head,tail)
27    local prev = getprev(tail)
28    if getid(prev) == penalty_code then -- linebreakpenalty
29        prev = getprev(prev)
30    end
31    if getid(prev) == hlist_code then -- line
32        local delta = getdepth(tail) - getdepth(prev)
33        if delta > 0 then
34            head = insertafter(head,prev,newglue(delta))
35        end
36        tex.prevdepth = getdepth(tail)
37    end
38    return head
39end
40
41local function block_baselineskip(head,tail)
42 -- tex.prevdepth = -1000 * 65536 -- ignoredepth
43    tex.prevdepth = texgetdimen("ignoredepthcriterion")
44    return head
45end
46
47local preactions = {
48    [1] = correct_depth,
49    [2] = block_baselineskip,
50}
51
52local postactions = {
53    [1] = correct_depth,
54    [2] = block_baselineskip,
55}
56
57-- function nodes.handlers.adjusters(head,where,tail)
58--     if where == "preadjust" then
59--         local a = getattr(tail,a_adjuster)
60--         if a then
61--             a = preactions[a]
62--             if a then
63--                 head = a(head,tail)
64--             end
65--         end
66--     elseif where == "postadjust" then
67--         local a = getattr(tail,a_adjuster)
68--         if a then
69--             a = postactions[a]
70--             if a then
71--                 head = a(head,tail)
72--             end
73--         end
74--     else
75--         -- can't happen
76--     end
77--     return head
78-- end
79
80function nodes.handlers.adjusters(head,where,tail,index)
81    if where == "preadjust" then
82        local a = preactions[index]
83        if a then
84            head = a(head,tail)
85        end
86    else -- if where == "postadjust" then
87        local a = postactions[index]
88        if a then
89            head = a(head,tail)
90        end
91    end
92    return head
93end
94