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.math'); local ltjm = luatexja.math
9 require('luatexja.pretreat'); local ltjp = luatexja.pretreat
10 require('luatexja.stack'); local ltjs = luatexja.stack
11 require('luatexja.setwidth'); local ltjw = luatexja.setwidth
13 local node_type = node.type
14 local node_new = node.new
15 local node_prev = node.prev
16 local node_next = node.next
17 local has_attr = node.has_attribute
18 local node_insert_before = node.insert_before
19 local node_insert_after = node.insert_after
20 local node_hpack = node.hpack
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']
38 local attr_uniqid = luatexbase.attributes['ltj@uniqid']
39 local cat_lp = luatexbase.catcodetables['latex-package']
49 local IC_PROCESSED = 9
52 ------------------------------------------------------------------------
54 -- ltj.ext_... : called from \directlua{}
55 -- ltj.int_... : called from other Lua codes, but not from \directlua{}
56 -- (other) : only called from this file
59 function ltj.error(s,t)
60 tex.error('LuaTeX-ja error: ' .. s ,t)
63 -- Three aux. functions, bollowed from tex.web
65 function print_scaled(s)
71 out=out..tostring(math.floor(s/unity)) .. '.'
74 if delta>unity then s=s+32768-50000 end
75 out=out .. tostring(math.floor(s/unity))
82 local function print_glue(d,order)
83 local out=print_scaled(d)
87 out=out..'l'; order=order-1
95 local function print_spec(p)
96 local out=print_scaled(p.width)..'pt'
98 out=out..' plus '..print_glue(p.stretch,p.stretch_order)
101 out=out..' minus '..print_glue(p.shrink,p.shrink_order)
106 function math.two_add(a,b) return a+b end
107 function math.two_average(a,b) return (a+b)/2 end
109 ---- table: charprop_stack_table [stack_level].{pre|post|xsp}[chr_code]
111 ------------------------------------------------------------------------
112 -- CODE FOR GETTING/SETTING PARAMETERS
113 ------------------------------------------------------------------------
115 -- EXT: print parameters that don't need arguments
116 function ltj.ext_get_parameter_unary(k)
117 if k == 'yalbaselineshift' then
118 tex.write(print_scaled(tex.getattribute('ltj@yablshift'))..'pt')
119 elseif k == 'yjabaselineshift' then
120 tex.write(print_scaled(tex.getattribute('ltj@ykblshift'))..'pt')
121 elseif k == 'kanjiskip' then
122 tex.write(print_spec(ltjs.get_skip_table('kanjiskip', tex.getcount('ltj@@stack'))))
123 elseif k == 'xkanjiskip' then
124 tex.write(print_spec(ltjs.get_skip_table('xkanjiskip', tex.getcount('ltj@@stack'))))
125 elseif k == 'jcharwidowpenalty' then
126 tex.write(ltjs.get_penalty_table('jwp', 0, 0, tex.getcount('ltj@@stack')))
127 elseif k == 'autospacing' then
128 tex.write(tex.getattribute('ltj@autospc'))
129 elseif k == 'autoxspacing' then
130 tex.write(tex.getattribute('ltj@autoxspc'))
131 elseif k == 'differentjfm' then
132 if luatexja.jfmglue.diffmet_rule == math.max then
134 elseif luatexja.jfmglue.diffmet_rule == math.min then
136 elseif luatexja.jfmglue.diffmet_rule == math.two_average then
138 elseif luatexja.jfmglue.diffmet_rule == math.two_add then
140 else -- This can't happen.
146 -- EXT: print parameters that need arguments
147 function ltj.ext_get_parameter_binary(k,c)
148 if k == 'jacharrange' then
150 ltjb.package_error('luatexja',
151 'invalid character range number (' .. c .. ')',
152 'A character range number should be in the range 0..216,\n'..
153 'So I changed this one to zero.')
156 tex.write(ltjc.get_range_setting(c))
158 if c<0 or c>0x10FFFF then
159 ltjb.package_error('luatexja',
160 'bad character code (' .. c .. ')',
161 'A character number must be between -1 and 0x10ffff.\n'..
162 "(-1 is used for denoting `math boundary')\n"..
163 'So I changed this one to zero.')
166 if k == 'prebreakpenalty' then
167 tex.write(ltjs.get_penalty_table('pre', c, 0, tex.getcount('ltj@@stack')))
168 elseif k == 'postbreakpenalty' then
169 tex.write(ltjs.get_penalty_table('post', c, 0, tex.getcount('ltj@@stack')))
170 elseif k == 'kcatcode' then
171 tex.write(ltjs.get_penalty_table('kcat', c, 0, tex.getcount('ltj@@stack')))
172 elseif k == 'chartorange' then
173 tex.write(ltjc.char_to_range(c))
174 elseif k == 'jaxspmode' or k == 'alxspmode' then
175 tex.write(ltjs.get_penalty_table('xsp', c, 3, tex.getcount('ltj@@stack')))
180 -- EXT: print \global if necessary
181 function ltj.ext_print_global()
182 if ltj.isglobal=='global' then tex.sprint(cat_lp, '\\global') end
186 -- mode = true iff main_process is called from pre_linebreak_filter
187 local function main_process(head, mode, dir)
189 p = ltjj.main(p,mode)
190 p = ltjw.set_ja_width(p, dir)
197 function ltj.ext_show_node_list(head,depth,print_fn)
201 debug_show_node_X(head, print_fn); head = node_next(head)
204 print_fn(debug_depth .. ' (null list)')
207 function ltj.ext_show_node(head,depth,print_fn)
210 debug_show_node_X(head, print_fn)
212 print_fn(debug_depth .. ' (null list)')
215 function debug_show_node_X(p,print_fn)
216 local k = debug_depth
218 local pt=node_type(p.id)
219 local base = debug_depth .. string.format('%X', has_attr(p,attr_icflag) or 0)
220 .. ' ' .. string.format('%X', has_attr(p, attr_uniqid) or 0)
221 .. ' ' .. node.type(p.id) .. ' ' .. tostring(p.subtype )
222 if pt == 'glyph' then
223 s = base .. ' ' .. utf.char(p.char) .. ' ' .. tostring(p.font)
224 .. ' (' .. print_scaled(p.height) .. '+'
225 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
227 elseif pt=='hlist' or pt=='vlist' then
228 s = base .. '(' .. print_scaled(p.height) .. '+'
229 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width) .. p.dir
231 s = s .. ', shifted ' .. print_scaled(p.shift)
233 if p.glue_sign >= 1 then
234 s = s .. ' glue set '
235 if p.glue_sign == 2 then s = s .. '-' end
236 s = s .. tostring(math.floor(p.glue_set*10000)/10000)
237 if p.glue_order == 0 then
241 for i = 2, p.glue_order do s = s .. 'l' end
244 if has_attr(p, attr_icflag, PACKED) then
249 debug_depth=debug_depth.. '.'
251 debug_show_node_X(q, print_fn); q = node_next(q)
254 elseif pt == 'glue' then
255 s = base .. ' ' .. print_spec(p.spec)
256 if has_attr(p, attr_icflag)==FROM_JFM then
257 s = s .. ' (from JFM)'
258 elseif has_attr(p, attr_icflag)==KANJI_SKIP then
259 s = s .. ' (kanjiskip)'
260 elseif has_attr(p, attr_icflag)==XKANJI_SKIP then
261 s = s .. ' (xkanjiskip)'
264 elseif pt == 'kern' then
265 s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
267 s = s .. ' (for accent)'
268 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
269 s = s .. ' (italic correction)'
270 -- elseif has_attr(p, attr_icflag)==ITALIC then
271 -- s = s .. ' (italic correction)'
272 elseif has_attr(p, attr_icflag)==FROM_JFM then
273 s = s .. ' (from JFM)'
274 elseif has_attr(p, attr_icflag)==LINE_END then
275 s = s .. " (from 'lineend' in JFM)"
278 elseif pt == 'penalty' then
279 s = base .. ' ' .. tostring(p.penalty)
280 if has_attr(p, attr_icflag)==KINSOKU then
281 s = s .. ' (for kinsoku)'
284 elseif pt == 'whatsit' then
285 s = base .. ' subtype: ' .. tostring(p.subtype)
286 if p.subtype==sid_user then
287 if p.type ~= 110 then
288 s = s .. ' user_id: ' .. p.user_id .. ' ' .. p.value
290 s = s .. ' user_id: ' .. p.user_id .. ' (node list)'
293 s = s .. node.subtype(p.subtype)
296 -------- math node --------
297 elseif pt=='noad' then
298 s = base ; print_fn(s)
300 debug_depth = k .. 'N'; debug_show_node_X(p.nucleus, print_fn);
303 debug_depth = k .. '^'; debug_show_node_X(p.sup, print_fn);
306 debug_depth = k .. '_'; debug_show_node_X(p.sub, print_fn);
309 elseif pt=='math_char' then
310 s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utf.char(p.char)
312 elseif pt=='sub_box' then
315 debug_depth = k .. '.'; debug_show_node_X(p.head, print_fn);
326 luatexbase.add_to_callback('pre_linebreak_filter',
327 function (head,groupcode)
328 return main_process(head, true, tex.textdir)
329 end,'ltj.pre_linebreak_filter',
330 luatexbase.priority_in_callback('pre_linebreak_filter',
331 'luaotfload.pre_linebreak_filter') + 1)
332 luatexbase.add_to_callback('hpack_filter',
333 function (head,groupcode,size,packtype, dir)
334 return main_process(head, false, dir)
335 end,'ltj.hpack_filter',
336 luatexbase.priority_in_callback('hpack_filter',
337 'luaotfload.hpack_filter') + 1)