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 require('luatexja.base'); local ltjb = luatexja.base
15 local node_new = node.new
16 local id_whatsit = node.id('whatsit')
17 local sid_user = node.subtype('user_defined')
19 local charprop_stack_table={}; charprop_stack_table[0]={}
21 function get_stack_level()
22 local i = tex.getcount('ltj@@stack')
23 if tex.nest[tex.nest.ptr].mode == 127 or
24 tex.nest[tex.nest.ptr].mode == -127 then
25 local j = tex.currentgrouplevel
26 if j > tex.getcount('ltj@@group@level') then
27 i = i+1 -- new stack level
28 local gd = tex.globaldefs
29 if gd>0 then tex.globaldefs = 0 end
30 -- 'tex.globaldefs = 0' is local even if \globaldefs > 0.
31 tex.setcount('ltj@@group@level', j)
32 for k,v in pairs(charprop_stack_table) do -- clear the stack above i
33 if k>=i then charprop_stack_table[k]=nil end
35 charprop_stack_table[i] = table.fastcopy(charprop_stack_table[i-1])
36 tex.setcount('ltj@@stack', i)
37 if gd>0 then tex.globaldefs = gd end
38 local g = node_new(id_whatsit, sid_user)
39 g.user_id=30112; g.type=100; g.value=j; node.write(g)
46 function set_stack_table(g,m,c,p,lb,ub)
47 local i = get_stack_level()
49 ltjb.package_error('luatexja',
50 "invalid code (".. p .. ")",
51 {"The code should in the range "..tostring(lb) ..'..'.. tostring(ub) .. ".",
52 "I'm going to use 0 instead of that illegal code value."})
54 elseif c<-1 or c>0x10ffff then
55 ltjb.package_error('luatexja',
56 'bad character code (' .. c .. ')',
57 {'A character number must be between -1 and 0x10ffff.',
58 "(-1 is used for denoting `math boundary')",
59 'So I changed this one to zero.'})
61 elseif not charprop_stack_table[i][c] then
62 charprop_stack_table[i][c] = {}
64 charprop_stack_table[i][c][m] = p
66 for j,v in pairs(charprop_stack_table) do
67 if not charprop_stack_table[j][c] then charprop_stack_table[j][c] = {} end
68 charprop_stack_table[j][c][m] = p
74 function set_stack_font(g,m,c,p)
75 local i = get_stack_level()
77 ltjb.package_error('luatexja',
78 "invalid family number (".. p .. ")",
79 {"The family number should in the range 0 .. 255.",
80 "I'm going to use 0 instead of that illegal family number."})
82 elseif not charprop_stack_table[i][c] then
83 charprop_stack_table[i][c] = {}
85 charprop_stack_table[i][c][m] = p
87 for j,v in pairs(charprop_stack_table) do
88 if not charprop_stack_table[j][c] then charprop_stack_table[j][c] = {} end
89 charprop_stack_table[j][c][m] = p
94 -- EXT: store \ltj@tempskipa
95 function set_stack_skip(g,c,sp)
96 local i = get_stack_level()
97 if not sp then return end
98 if not charprop_stack_table[i][c] then
99 charprop_stack_table[i][c] = {}
101 charprop_stack_table[i][c].width = sp.width
102 charprop_stack_table[i][c].stretch = sp.stretch
103 charprop_stack_table[i][c].shrink = sp.shrink
104 charprop_stack_table[i][c].stretch_order = sp.stretch_order
105 charprop_stack_table[i][c].shrink_order = sp.shrink_order
107 for j,v in pairs(charprop_stack_table) do
108 if not charprop_stack_table[j][c] then charprop_stack_table[j][c] = {} end
109 charprop_stack_table[j][c].width = sp.width
110 charprop_stack_table[j][c].stretch = sp.stretch
111 charprop_stack_table[j][c].shrink = sp.shrink
112 charprop_stack_table[j][c].stretch_order = sp.stretch_order
113 charprop_stack_table[j][c].shrink_order = sp.shrink_order
118 -- mode: nil iff it is called in callbacks
119 function get_skip_table(m, idx)
120 local i = charprop_stack_table[idx][m]
121 return i or { width = 0, stretch = 0, shrink = 0,
122 stretch_order = 0, shrink_order = 0 }
125 function get_penalty_table(m,c,d, idx)
126 local i = charprop_stack_table[idx][c]