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
21 local round = tex.round
23 local id_penalty = node.id('penalty')
24 local id_glyph = node.id('glyph')
25 local id_glue_spec = node.id('glue_spec')
26 local id_glue = node.id('glue')
27 local id_kern = node.id('kern')
28 local id_hlist = node.id('hlist')
29 local id_vlist = node.id('vlist')
30 local id_rule = node.id('rule')
31 local id_math = node.id('math')
32 local id_whatsit = node.id('whatsit')
33 local sid_user = node.subtype('user_defined')
35 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
36 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
37 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
38 local attr_icflag = luatexbase.attributes['ltj@icflag']
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 local 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][chr_code].{pre|post|xsp}
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 .. ' ' .. pt .. ' ' .. p.subtype
221 if pt == 'glyph' then
222 s = base .. ' ' .. utf.char(p.char) .. ' ' .. tostring(p.font)
223 .. ' (' .. print_scaled(p.height) .. '+'
224 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
226 elseif pt=='hlist' then
227 s = base .. '(' .. print_scaled(p.height) .. '+'
228 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
230 s = s .. ', shifted ' .. print_scaled(p.shift)
232 if p.glue_sign >= 1 then
233 s = s .. ' glue set '
234 if p.glue_sign == 2 then s = s .. '-' end
235 s = s .. tostring(math.floor(p.glue_set*10000)/10000)
236 if p.glue_order == 0 then
240 for i = 2, p.glue_order do s = s .. 'l' end
243 if has_attr(p, attr_icflag, PACKED) then
248 debug_depth=debug_depth.. '.'
250 debug_show_node_X(q, print_fn); q = node_next(q)
253 elseif pt == 'glue' then
254 s = base .. ' ' .. print_spec(p.spec)
255 if has_attr(p, attr_icflag)==FROM_JFM then
256 s = s .. ' (from JFM)'
257 elseif has_attr(p, attr_icflag)==KANJI_SKIP then
258 s = s .. ' (kanjiskip)'
259 elseif has_attr(p, attr_icflag)==XKANJI_SKIP then
260 s = s .. ' (xkanjiskip)'
263 elseif pt == 'kern' then
264 s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
266 s = s .. ' (for accent)'
267 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
268 s = s .. ' (italic correction)'
269 -- elseif has_attr(p, attr_icflag)==ITALIC then
270 -- s = s .. ' (italic correction)'
271 elseif has_attr(p, attr_icflag)==FROM_JFM then
272 s = s .. ' (from JFM)'
273 elseif has_attr(p, attr_icflag)==LINE_END then
274 s = s .. " (from 'lineend' in JFM)"
277 elseif pt == 'penalty' then
278 s = base .. ' ' .. tostring(p.penalty)
279 if has_attr(p, attr_icflag)==KINSOKU then
280 s = s .. ' (for kinsoku)'
283 elseif pt == 'whatsit' then
284 s = base .. ' subtype: ' .. tostring(p.subtype)
285 if p.subtype==sid_user then
286 s = s .. ' user_id: ' .. p.user_id .. ' ' .. p.value
288 s = s .. node.subtype(p.subtype)
292 elseif pt=='noad' then
293 s = base ; print_fn(s)
295 debug_depth = k .. 'N'; debug_show_node_X(p.nucleus, print_fn);
298 debug_depth = k .. '^'; debug_show_node_X(p.sup, print_fn);
301 debug_depth = k .. '_'; debug_show_node_X(p.sub, print_fn);
304 elseif pt=='math_char' then
305 s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utf.char(p.char)
307 elseif pt=='sub_box' then
310 debug_depth = k .. '.'; debug_show_node_X(p.head, print_fn);
321 luatexbase.add_to_callback('pre_linebreak_filter',
322 function (head,groupcode)
323 return main_process(head, true, tex.textdir)
324 end,'ltj.pre_linebreak_filter',
325 luatexbase.priority_in_callback('pre_linebreak_filter',
326 'luaotfload.pre_linebreak_filter') + 1)
327 luatexbase.add_to_callback('hpack_filter',
328 function (head,groupcode,size,packtype, dir)
329 return main_process(head, false, dir)
330 end,'ltj.hpack_filter',
331 luatexbase.priority_in_callback('hpack_filter',
332 'luaotfload.hpack_filter') + 1)