summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/typo-adj.lmt
blob: d902187e3d49481c8faf9d13b6bf11d0849af378 (plain)
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
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 nodecodes    = nodes.nodecodes
local hlist_code   = nodecodes.hlist
local penalty_code = nodecodes.penalty

local nuts         = nodes.nuts
local getprev      = nuts.getprev
local getid        = nuts.getid
----- getattr      = nuts.getattribute
local getdepth     = nuts.getdepth
local newglue      = nuts.pool.glue
local insertafter  = nuts.insertafter

local texgetdimen  = tex.getdimen

----- a_adjuster   = attributes.system("adjuster")

local function correct_depth(head,tail)
    local prev = getprev(tail)
    if getid(prev) == penalty_code then -- linebreakpenalty
        prev = getprev(prev)
    end
    if getid(prev) == hlist_code then -- line
        local delta = getdepth(tail) - getdepth(prev)
        if delta > 0 then
            head = insertafter(head,prev,newglue(delta))
        end
        tex.prevdepth = getdepth(tail)
    end
    return head
end

local function block_baselineskip(head,tail)
 -- tex.prevdepth = -1000 * 65536 -- ignoredepth
    tex.prevdepth = texgetdimen("ignoredepthcriterium")
    return head
end

local preactions = {
    [1] = correct_depth,
    [2] = block_baselineskip,
}

local postactions = {
    [1] = correct_depth,
    [2] = block_baselineskip,
}

-- function nodes.handlers.adjusters(head,where,tail)
--     if where == "preadjust" then
--         local a = getattr(tail,a_adjuster)
--         if a then
--             a = preactions[a]
--             if a then
--                 head = a(head,tail)
--             end
--         end
--     elseif where == "postadjust" then
--         local a = getattr(tail,a_adjuster)
--         if a then
--             a = postactions[a]
--             if a then
--                 head = a(head,tail)
--             end
--         end
--     else
--         -- can't happen
--     end
--     return head
-- end

function nodes.handlers.adjusters(head,where,tail,index)
    if where == "preadjust" then
        local a = preactions[index]
        if a then
            head = a(head,tail)
        end
    else -- if where == "postadjust" then
        local a = postactions[index]
        if a then
            head = a(head,tail)
        end
    end
    return head
end