4 luatexbase.provides_module({
5 name = 'luatexja.stack',
8 description = 'LuaTeX-ja stack system',
10 module('luatexja.stack', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
13 local node_new = node.new
14 local id_whatsit = node.id('whatsit')
15 local sid_user = node.subtype('user_defined')
17 local charprop_stack_table={}; charprop_stack_table[0]={}
19 function get_stack_level()
20 local i = tex.getcount('ltj@@stack')
21 local j = tex.currentgrouplevel
22 if j > tex.getcount('ltj@@group@level') then
23 i = i+1 -- new stack level
24 tex.setcount('ltj@@group@level', j)
25 for k,v in pairs(charprop_stack_table) do -- clear the stack above i
26 if k>=i then charprop_stack_table[k]=nil end
28 charprop_stack_table[i] = table.fastcopy(charprop_stack_table[i-1])
29 tex.setcount('ltj@@stack', i)
30 local g = node_new(id_whatsit, sid_user)
31 g.user_id=30112; g.type=100; g.value=j; node.write(g)
37 function set_stack_table(g,m,c,p,lb,ub)
38 local i = get_stack_level()
40 ltj.error('Invalid code (' .. p .. '), should in the range '
41 .. tostring(lb) .. '..' .. tostring(ub) .. '.',
42 {"I'm going to use 0 instead of that illegal code value."})
44 elseif c<-1 or c>0x10FFFF then
45 ltj.error('Invalid character code (' .. c
46 .. '), should in the range -1.."10FFFF.',{})
48 elseif not charprop_stack_table[i][c] then
49 charprop_stack_table[i][c] = {}
51 charprop_stack_table[i][c][m] = p
53 for j,v in pairs(charprop_stack_table) do
54 if not charprop_stack_table[j][c] then charprop_stack_table[j][c] = {} end
55 charprop_stack_table[j][c][m] = p
60 -- EXT: store \ltj@tempskipa
61 function set_stack_skip(g,c)
62 local i = get_stack_level()
63 local sp = tex.getskip('ltj@tempskipa')
64 if not charprop_stack_table[i][c] then
65 charprop_stack_table[i][c] = {}
67 charprop_stack_table[i][c].width = sp.width
68 charprop_stack_table[i][c].stretch = sp.stretch
69 charprop_stack_table[i][c].shrink = sp.shrink
70 charprop_stack_table[i][c].stretch_order = sp.stretch_order
71 charprop_stack_table[i][c].shrink_order = sp.shrink_order
73 for j,v in pairs(charprop_stack_table) do
74 if not charprop_stack_table[j][c] then charprop_stack_table[j][c] = {} end
75 charprop_stack_table[j][c].width = sp.width
76 charprop_stack_table[j][c].stretch = sp.stretch
77 charprop_stack_table[j][c].shrink = sp.shrink
78 charprop_stack_table[j][c].stretch_order = sp.stretch_order
79 charprop_stack_table[j][c].shrink_order = sp.shrink_order
84 -- mode: nil iff it is called in callbacks
85 function get_skip_table(m, idx)
86 local i = charprop_stack_table[idx][m]
87 return i or { width = 0, stretch = 0, shrink = 0,
88 stretch_order = 0, shrink_order = 0 }
91 function get_penalty_table(m,c,d, idx)
92 local i = charprop_stack_table[idx][c]