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 ltjl = luatexja.lineskip
10 local id_glue = node.id('glue')
11 local id_penalty = node.id('penalty')
12 local id_hlist = node.id('hlist')
13 local setfield = node.direct.setfield
14 local getfield = node.direct.getfield
15 local getlist = node.direct.getlist
16 local node_new = node.direct.new
17 local node_prev = node.direct.getprev
18 local node_next = node.direct.getnext
19 local getid = node.direct.getid
20 local getsubtype = node.direct.getsubtype
22 local node_getglue = node.getglue
23 local setglue = node.direct.setglue
24 local function copy_glue (new_glue, old_glue, subtype, new_w)
25 setfield(new_glue, 'subtype', subtype)
26 local w,st,sp,sto,spo = node_getglue(old_glue)
27 setglue(new_glue, new_w or w, st, sp, sto, spo)
29 ltjl.copy_glue = copy_glue
31 function ltjl.p_dummy(before, after)
34 function ltjl.l_dummy(dist, g, adj, normal, bw, loc)
35 if dist < tex.lineskiplimit then
36 copy_glue(g, tex.lineskip, 1, tex.lineskip.width + adj)
38 copy_glue(g, tex.baselineskip, 2, normal)
42 local ltj_profiler, ltj_skip = ltjl.p_dummy, ltjl.l_dummy
43 function ltjl.setting(profiler, skip_method)
44 ltj_profiler = ltjl['p_'..tostring(profiler)] or ltjl.p_dummy
45 ltj_skip = ltjl['l_'..tostring(skip_method)] or ltjl.l_dummy
49 local traverse_id = node.direct.traverse_id
50 local function adjust_glue(nh)
51 local h = to_direct(nh)
52 local bw = tex.baselineskip.width
53 for x in traverse_id(id_glue, h) do
54 local xs = getsubtype(x)
55 if (xs==1) or (xs==2) then
56 local p, n = node_prev(x), node_next(x)
59 while (id_glue<=pid) and (pid<=id_penalty) and node_prev(p) do
60 p = node_prev(p); pid = getid(p)
62 if pid==id_hlist and getid(n)==id_hlist then
63 local normal = bw - getfield(p, 'depth') - getfield(n, 'height')
64 local lmin, adj = ltj_profiler(p, n, false, bw)
65 ltj_skip(lmin or normal, x, adj, normal, bw)
72 ltjb.add_to_callback('post_linebreak_filter',
73 adjust_glue, 'ltj.lineskip', 10000)
77 local p_dummy = ltjl.p_dummy
78 local make_dir_whatsit = luatexja.direction.make_dir_whatsit
79 local get_dir_count = luatexja.direction.get_dir_count
80 local node_write = node.direct.write
82 local function dir_adjust_append_vlist(b, loc, prev, mirrored)
83 local old_b = to_direct(b)
84 local new_b = loc=='box' and
85 make_dir_whatsit(old_b, old_b, get_dir_count(), 'append_vlist') or old_b
86 if prev > -65536000 then
87 local bw = tex.baselineskip.width
88 local normal = bw - prev
89 - getfield(new_b, mirrored and 'depth' or 'height')
90 local lmin, adj = nil, 0
91 local tail = to_direct(tex.nest[tex.nest.ptr].tail)
92 if p_dummy~=ltj_profiler then
93 while tail and (id_glue<=getid(tail)) and (getid(tail)<=id_penalty) do
94 tail = node_prev(tail)
98 if getid(tail)==id_hlist and getid(new_b)==id_hlist then
99 if getfield(tail, 'depth')==prev then
100 lmin, adj = ltj_profiler(tail, new_b, mirrored, bw)
104 local g = node_new(id_glue)
105 ltj_skip(lmin or normal, g, adj, normal, bw, loc)
109 tex.prevdepth = getfield(new_b, mirrored and 'height' or 'depth')
110 return nil -- do nothing on tex side
112 ltjb.add_to_callback('append_to_vlist_filter',
113 dir_adjust_append_vlist,
114 'ltj.lineskip', 10000)