4 luatexja.load_module 'base'; local ltjb = luatexja.base
5 luatexja.load_module 'direction'; local ltjd = luatexja.direction
6 luatexja.lineskip = luatexja.lineskip or {}
8 local to_direct = node.direct.todirect
9 local to_node = node.direct.tonode
10 local ltjl = luatexja.lineskip
11 local id_glue = node.id 'glue'
12 local id_penalty = node.id 'penalty'
13 local id_hlist = node.id 'hlist'
14 local getlist = node.direct.getlist
15 local node_new = node.direct.new
16 local node_prev = node.direct.getprev
17 local node_next = node.direct.getnext
18 local getid = node.direct.getid
19 local getsubtype = node.direct.getsubtype
20 local getdepth = node.direct.getdepth
21 local getheight = node.direct.getheight
22 local texget = tex.get
24 local node_getglue = node.getglue
25 local setglue = node.direct.setglue
26 local setsubtype = node.direct.setsubtype
27 local function copy_glue (new_glue, old_glue_name, subtype, new_w)
28 setsubtype(new_glue, subtype)
29 local w,st,sp,sto,spo = texget(old_glue_name, true)
30 setglue(new_glue, new_w or w, st, sp, sto, spo)
32 ltjl.copy_glue = copy_glue
34 function ltjl.p_dummy(before, after)
37 function ltjl.l_dummy(dist, g, adj, normal, bw, loc)
38 if dist < tex.lineskiplimit then
39 copy_glue(g, 'lineskip', 1, texget('lineskip', false) + adj)
41 copy_glue(g, 'baselineskip', 2, normal)
45 local ltj_profiler, ltj_skip = ltjl.p_dummy, ltjl.l_dummy
46 function ltjl.setting(profiler, skip_method)
47 ltj_profiler = ltjl['p_'..tostring(profiler)] or ltjl.p_dummy
48 ltj_skip = ltjl['l_'..tostring(skip_method)] or ltjl.l_dummy
52 local traverse_id = node.direct.traverse_id
53 local function adjust_glue(nh)
54 local h = to_direct(nh)
55 local bw = texget('baselineskip',false)
56 for x in traverse_id(id_glue, h) do
57 local xs = getsubtype(x)
58 if (xs==1) or (xs==2) then
59 local p, n = node_prev(x), node_next(x)
62 while (id_glue<=pid) and (pid<=id_penalty) and node_prev(p) do
63 p = node_prev(p); pid = getid(p)
65 if pid==id_hlist and getid(n)==id_hlist then
66 local normal = bw - getdepth(p) - getheight(n)
67 local lmin, adj = ltj_profiler(p, n, false, bw)
68 ltj_skip(lmin or normal, x, adj, normal, bw)
75 ltjb.add_to_callback('post_linebreak_filter', adjust_glue, 'ltj.lineskip', 10000)
79 local p_dummy = ltjl.p_dummy
80 local make_dir_whatsit = luatexja.direction.make_dir_whatsit
81 local get_dir_count = luatexja.direction.get_dir_count
82 local getwhd = node.direct.getwhd
83 local setnext = node.direct.setnext
84 local getnest = tex.getnest
86 local function dir_adjust_append_vlist(b, loc, prev, mirrored)
87 local old_b = to_direct(b)
88 local new_b = loc=='box' and
89 make_dir_whatsit(old_b, old_b, get_dir_count(), 'append_vlist') or old_b
90 local _, ht, dp = getwhd(new_b)
91 if prev > -65536000 then
92 local bw = texget('baselineskip', false)
93 local normal = bw - prev - (mirrored and dp or ht)
94 local lmin, adj = nil, 0
95 local tail = to_direct(getnest().tail)
96 if p_dummy~=ltj_profiler then
97 while tail and (id_glue<=getid(tail)) and (getid(tail)<=id_penalty) do
98 tail = node_prev(tail)
102 if getid(tail)==id_hlist and getid(new_b)==id_hlist then
103 if getdepth(tail)==prev then
104 lmin, adj = ltj_profiler(tail, new_b, mirrored, bw)
108 local g = node_new(id_glue)
109 ltj_skip(lmin or normal, g, adj, normal, bw, loc)
110 setnext(g, new_b); return to_node(g), (mirrored and ht or dp)
111 else return to_node(new_b), (mirrored and ht or dp)
114 ltjb.add_to_callback('append_to_vlist_filter', dir_adjust_append_vlist, 'ltj.lineskip', 10000)