2 require('luatexja.rmlgbm'); local ltjr = luatexja.rmlgbm -- must be 1st
3 require('luatexja.base'); local ltjb = luatexja.base
4 require('luatexja.charrange'); local ltjc = luatexja.charrange
5 require('luatexja.jfont'); local ltjf = luatexja.jfont
6 require('luatexja.inputbuf'); local ltji = luatexja.inputbuf
7 require('luatexja.jfmglue'); local ltjj = luatexja.jfmglue
8 require('luatexja.pretreat'); local ltjp = luatexja.pretreat
9 require('luatexja.stack'); local ltjs = luatexja.stack
10 require('luatexja.setwidth'); local ltjw = luatexja.setwidth
12 local node_type = node.type
13 local node_new = node.new
14 local node_prev = node.prev
15 local node_next = node.next
16 local has_attr = node.has_attribute
17 local node_insert_before = node.insert_before
18 local node_insert_after = node.insert_after
19 local node_hpack = node.hpack
20 local round = tex.round
22 local id_penalty = node.id('penalty')
23 local id_glyph = node.id('glyph')
24 local id_glue_spec = node.id('glue_spec')
25 local id_glue = node.id('glue')
26 local id_kern = node.id('kern')
27 local id_hlist = node.id('hlist')
28 local id_vlist = node.id('vlist')
29 local id_rule = node.id('rule')
30 local id_math = node.id('math')
31 local id_whatsit = node.id('whatsit')
32 local sid_user = node.subtype('user_defined')
34 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
35 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
36 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
37 local attr_icflag = luatexbase.attributes['ltj@icflag']
47 local IC_PROCESSED = 9
50 ------------------------------------------------------------------------
52 -- ltj.ext_... : called from \directlua{}
53 -- ltj.int_... : called from other Lua codes, but not from \directlua{}
54 -- (other) : only called from this file
57 function ltj.error(s,t)
58 tex.error('LuaTeX-ja error: ' .. s ,t)
61 -- Three aux. functions, bollowed from tex.web
63 local function print_scaled(s)
69 out=out..tostring(math.floor(s/unity)) .. '.'
72 if delta>unity then s=s+32768-50000 end
73 out=out .. tostring(math.floor(s/unity))
80 local function print_glue(d,order)
81 local out=print_scaled(d)
85 out=out..'l'; order=order-1
93 local function print_spec(p)
94 local out=print_scaled(p.width)..'pt'
96 out=out..' plus '..print_glue(p.stretch,p.stretch_order)
99 out=out..' minus '..print_glue(p.shrink,p.shrink_order)
104 function math.two_add(a,b) return a+b end
105 function math.two_average(a,b) return (a+b)/2 end
107 ---- table: charprop_stack_table [stack_level][chr_code].{pre|post|xsp}
109 ------------------------------------------------------------------------
110 -- CODE FOR GETTING/SETTING PARAMETERS
111 ------------------------------------------------------------------------
113 -- EXT: print parameters that don't need arguments
114 function ltj.ext_get_parameter_unary(k)
115 if k == 'yalbaselineshift' then
116 tex.write(print_scaled(tex.getattribute('ltj@yablshift'))..'pt')
117 elseif k == 'yjabaselineshift' then
118 tex.write(print_scaled(tex.getattribute('ltj@ykblshift'))..'pt')
119 elseif k == 'kanjiskip' then
120 tex.write(print_spec(ltjs.get_skip_table('kanjiskip', tex.getcount('ltj@@stack'))))
121 elseif k == 'xkanjiskip' then
122 tex.write(print_spec(ltjs.get_skip_table('xkanjiskip', tex.getcount('ltj@@stack'))))
123 elseif k == 'jcharwidowpenalty' then
124 tex.write(ltjs.get_penalty_table('jwp', 0, 0, tex.getcount('ltj@@stack')))
125 elseif k == 'autospacing' then
126 tex.write(tex.getattribute('ltj@autospc'))
127 elseif k == 'autoxspacing' then
128 tex.write(tex.getattribute('ltj@autoxspc'))
129 elseif k == 'differentjfm' then
130 if luatexja.jfmglue.diffmet_rule == math.max then
132 elseif luatexja.jfmglue.diffmet_rule == math.min then
134 elseif luatexja.jfmglue.diffmet_rule == math.two_average then
136 elseif luatexja.jfmglue.diffmet_rule == math.two_add then
138 else -- This can't happen.
144 -- EXT: print parameters that need arguments
145 function ltj.ext_get_parameter_binary(k,c)
146 if k == 'jacharrange' then
148 ltjb.package_error('luatexja',
149 'invalid character range number (' .. c .. ')',
150 'A character range number should be in the range 0..216,\n'..
151 'So I changed this one to zero.')
154 tex.write(ltjc.get_range_setting(c))
156 if c<0 or c>0x10FFFF then
157 ltjb.package_error('luatexja',
158 'bad character code (' .. c .. ')',
159 'A character number must be between -1 and 0x10ffff.\n'..
160 "(-1 is used for denoting `math boundary')\n"..
161 'So I changed this one to zero.')
164 if k == 'prebreakpenalty' then
165 tex.write(ltjs.get_penalty_table('pre', c, 0, tex.getcount('ltj@@stack')))
166 elseif k == 'postbreakpenalty' then
167 tex.write(ltjs.get_penalty_table('post', c, 0, tex.getcount('ltj@@stack')))
168 elseif k == 'kcatcode' then
169 tex.write(ltjs.get_penalty_table('kcat', c, 0, tex.getcount('ltj@@stack')))
170 elseif k == 'chartorange' then
171 tex.write(ltjc.char_to_range(c))
172 elseif k == 'jaxspmode' or k == 'alxspmode' then
173 tex.write(ltjs.get_penalty_table('xsp', c, 3, tex.getcount('ltj@@stack')))
178 -- EXT: print \global if necessary
179 function ltj.ext_print_global()
180 if ltj.isglobal=='global' then tex.sprint('\\global') end
184 -- mode = true iff main_process is called from pre_linebreak_filter
185 local function main_process(head, mode, dir)
187 p = ltjj.main(p,mode)
188 p = ltjw.set_ja_width(p, dir)
195 function ltj.ext_show_node_list(head,depth,print_fn)
199 debug_show_node_X(head, print_fn); head = node_next(head)
202 print_fn(debug_depth .. ' (null list)')
205 function ltj.ext_show_node(head,depth,print_fn)
208 debug_show_node_X(head, print_fn)
210 print_fn(debug_depth .. ' (null list)')
213 function debug_show_node_X(p,print_fn)
214 local k = debug_depth
216 local pt=node_type(p.id)
217 local base = debug_depth .. string.format('%X', has_attr(p,attr_icflag) or 0)
218 .. ' ' .. pt .. ' ' .. p.subtype
219 if pt == 'glyph' then
220 s = base .. ' ' .. utf.char(p.char) .. ' ' .. tostring(p.font)
221 .. ' (' .. print_scaled(p.height) .. '+'
222 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
224 elseif pt=='hlist' then
225 s = base .. '(' .. print_scaled(p.height) .. '+'
226 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
227 if p.glue_sign >= 1 then
228 s = s .. ' glue set '
229 if p.glue_sign == 2 then s = s .. '-' end
230 s = s .. tostring(math.floor(p.glue_set*10000)/10000)
231 if p.glue_order == 0 then
235 for i = 2, p.glue_order do s = s .. 'l' end
238 if has_attr(p, attr_icflag, PACKED) then
243 debug_depth=debug_depth.. '.'
245 debug_show_node_X(q, print_fn); q = node_next(q)
248 elseif pt == 'glue' then
249 s = base .. ' ' .. print_spec(p.spec)
250 if has_attr(p, attr_icflag)==FROM_JFM then
251 s = s .. ' (from JFM)'
252 elseif has_attr(p, attr_icflag)==KANJI_SKIP then
253 s = s .. ' (kanjiskip)'
254 elseif has_attr(p, attr_icflag)==XKANJI_SKIP then
255 s = s .. ' (xkanjiskip)'
258 elseif pt == 'kern' then
259 s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
261 s = s .. ' (for accent)'
262 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
263 s = s .. ' (italic correction)'
264 -- elseif has_attr(p, attr_icflag)==ITALIC then
265 -- s = s .. ' (italic correction)'
266 elseif has_attr(p, attr_icflag)==FROM_JFM then
267 s = s .. ' (from JFM)'
268 elseif has_attr(p, attr_icflag)==LINE_END then
269 s = s .. " (from 'lineend' in JFM)"
272 elseif pt == 'penalty' then
273 s = base .. ' ' .. tostring(p.penalty)
274 if has_attr(p, attr_icflag)==KINSOKU then
275 s = s .. ' (for kinsoku)'
278 elseif pt == 'whatsit' then
279 s = base .. ' subtype: ' .. tostring(p.subtype)
280 if p.subtype==sid_user then
281 s = s .. ' user_id: ' .. p.user_id .. ' ' .. p.value
283 s = s .. node.subtype(p.subtype)
295 luatexbase.add_to_callback('pre_linebreak_filter',
296 function (head,groupcode)
297 return main_process(head, true, tex.textdir)
298 end,'ltj.pre_linebreak_filter',
299 luatexbase.priority_in_callback('pre_linebreak_filter',
300 'luaotfload.pre_linebreak_filter') + 1)
301 luatexbase.add_to_callback('hpack_filter',
302 function (head,groupcode,size,packtype, dir)
303 return main_process(head, false, dir)
304 end,'ltj.hpack_filter',
305 luatexbase.priority_in_callback('hpack_filter',
306 'luaotfload.hpack_filter') + 1)