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 cat_lp = luatexbase.catcodetables['latex-package']
48 local IC_PROCESSED = 9
51 ------------------------------------------------------------------------
53 -- ltj.ext_... : called from \directlua{}
54 -- ltj.int_... : called from other Lua codes, but not from \directlua{}
55 -- (other) : only called from this file
58 function ltj.error(s,t)
59 tex.error('LuaTeX-ja error: ' .. s ,t)
62 -- Three aux. functions, bollowed from tex.web
64 function print_scaled(s)
70 out=out..tostring(math.floor(s/unity)) .. '.'
73 if delta>unity then s=s+32768-50000 end
74 out=out .. tostring(math.floor(s/unity))
81 local function print_glue(d,order)
82 local out=print_scaled(d)
86 out=out..'l'; order=order-1
94 local function print_spec(p)
95 local out=print_scaled(p.width)..'pt'
97 out=out..' plus '..print_glue(p.stretch,p.stretch_order)
100 out=out..' minus '..print_glue(p.shrink,p.shrink_order)
105 function math.two_add(a,b) return a+b end
106 function math.two_average(a,b) return (a+b)/2 end
108 ---- table: charprop_stack_table [stack_level].{pre|post|xsp}[chr_code]
110 ------------------------------------------------------------------------
111 -- CODE FOR GETTING/SETTING PARAMETERS
112 ------------------------------------------------------------------------
114 -- EXT: print parameters that don't need arguments
115 function ltj.ext_get_parameter_unary(k)
116 if k == 'yalbaselineshift' then
117 tex.write(print_scaled(tex.getattribute('ltj@yablshift'))..'pt')
118 elseif k == 'yjabaselineshift' then
119 tex.write(print_scaled(tex.getattribute('ltj@ykblshift'))..'pt')
120 elseif k == 'kanjiskip' then
121 tex.write(print_spec(ltjs.get_skip_table('kanjiskip', tex.getcount('ltj@@stack'))))
122 elseif k == 'xkanjiskip' then
123 tex.write(print_spec(ltjs.get_skip_table('xkanjiskip', tex.getcount('ltj@@stack'))))
124 elseif k == 'jcharwidowpenalty' then
125 tex.write(ltjs.get_penalty_table('jwp', 0, 0, tex.getcount('ltj@@stack')))
126 elseif k == 'autospacing' then
127 tex.write(tex.getattribute('ltj@autospc'))
128 elseif k == 'autoxspacing' then
129 tex.write(tex.getattribute('ltj@autoxspc'))
130 elseif k == 'differentjfm' then
131 if luatexja.jfmglue.diffmet_rule == math.max then
133 elseif luatexja.jfmglue.diffmet_rule == math.min then
135 elseif luatexja.jfmglue.diffmet_rule == math.two_average then
137 elseif luatexja.jfmglue.diffmet_rule == math.two_add then
139 else -- This can't happen.
145 -- EXT: print parameters that need arguments
146 function ltj.ext_get_parameter_binary(k,c)
147 if k == 'jacharrange' then
149 ltjb.package_error('luatexja',
150 'invalid character range number (' .. c .. ')',
151 'A character range number should be in the range 0..216,\n'..
152 'So I changed this one to zero.')
155 tex.write(ltjc.get_range_setting(c))
157 if c<0 or c>0x10FFFF then
158 ltjb.package_error('luatexja',
159 'bad character code (' .. c .. ')',
160 'A character number must be between -1 and 0x10ffff.\n'..
161 "(-1 is used for denoting `math boundary')\n"..
162 'So I changed this one to zero.')
165 if k == 'prebreakpenalty' then
166 tex.write(ltjs.get_penalty_table('pre', c, 0, tex.getcount('ltj@@stack')))
167 elseif k == 'postbreakpenalty' then
168 tex.write(ltjs.get_penalty_table('post', c, 0, tex.getcount('ltj@@stack')))
169 elseif k == 'kcatcode' then
170 tex.write(ltjs.get_penalty_table('kcat', c, 0, tex.getcount('ltj@@stack')))
171 elseif k == 'chartorange' then
172 tex.write(ltjc.char_to_range(c))
173 elseif k == 'jaxspmode' or k == 'alxspmode' then
174 tex.write(ltjs.get_penalty_table('xsp', c, 3, tex.getcount('ltj@@stack')))
179 -- EXT: print \global if necessary
180 function ltj.ext_print_global()
181 if ltj.isglobal=='global' then tex.sprint(cat_lp, '\\global') end
185 -- mode = true iff main_process is called from pre_linebreak_filter
186 local function main_process(head, mode, dir)
188 p = ltjj.main(p,mode)
189 p = ltjw.set_ja_width(p, dir)
196 function ltj.ext_show_node_list(head,depth,print_fn)
200 debug_show_node_X(head, print_fn); head = node_next(head)
203 print_fn(debug_depth .. ' (null list)')
206 function ltj.ext_show_node(head,depth,print_fn)
209 debug_show_node_X(head, print_fn)
211 print_fn(debug_depth .. ' (null list)')
214 function debug_show_node_X(p,print_fn)
215 local k = debug_depth
217 local pt=node_type(p.id)
218 local base = debug_depth .. string.format('%X', has_attr(p,attr_icflag) or 0)
219 .. ' ' .. pt .. ' ' .. tostring(p.subtype )
220 if pt == 'glyph' then
221 s = base .. ' ' .. utf.char(p.char) .. ' ' .. tostring(p.font)
222 .. ' (' .. print_scaled(p.height) .. '+'
223 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
225 elseif pt=='hlist' then
226 s = base .. '(' .. print_scaled(p.height) .. '+'
227 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
229 s = s .. ', shifted ' .. print_scaled(p.shift)
231 if p.glue_sign >= 1 then
232 s = s .. ' glue set '
233 if p.glue_sign == 2 then s = s .. '-' end
234 s = s .. tostring(math.floor(p.glue_set*10000)/10000)
235 if p.glue_order == 0 then
239 for i = 2, p.glue_order do s = s .. 'l' end
242 if has_attr(p, attr_icflag, PACKED) then
247 debug_depth=debug_depth.. '.'
249 debug_show_node_X(q, print_fn); q = node_next(q)
252 elseif pt == 'glue' then
253 s = base .. ' ' .. print_spec(p.spec)
254 if has_attr(p, attr_icflag)==FROM_JFM then
255 s = s .. ' (from JFM)'
256 elseif has_attr(p, attr_icflag)==KANJI_SKIP then
257 s = s .. ' (kanjiskip)'
258 elseif has_attr(p, attr_icflag)==XKANJI_SKIP then
259 s = s .. ' (xkanjiskip)'
262 elseif pt == 'kern' then
263 s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
265 s = s .. ' (for accent)'
266 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
267 s = s .. ' (italic correction)'
268 -- elseif has_attr(p, attr_icflag)==ITALIC then
269 -- s = s .. ' (italic correction)'
270 elseif has_attr(p, attr_icflag)==FROM_JFM then
271 s = s .. ' (from JFM)'
272 elseif has_attr(p, attr_icflag)==LINE_END then
273 s = s .. " (from 'lineend' in JFM)"
276 elseif pt == 'penalty' then
277 s = base .. ' ' .. tostring(p.penalty)
278 if has_attr(p, attr_icflag)==KINSOKU then
279 s = s .. ' (for kinsoku)'
282 elseif pt == 'whatsit' then
283 s = base .. ' subtype: ' .. tostring(p.subtype)
284 if p.subtype==sid_user then
285 s = s .. ' user_id: ' .. p.user_id .. ' ' .. p.value
287 s = s .. node.subtype(p.subtype)
290 -------- math node --------
291 elseif pt=='noad' then
292 s = base ; print_fn(s)
294 debug_depth = k .. 'N'; debug_show_node_X(p.nucleus, print_fn);
297 debug_depth = k .. '^'; debug_show_node_X(p.sup, print_fn);
300 debug_depth = k .. '_'; debug_show_node_X(p.sub, print_fn);
303 elseif pt=='math_char' then
304 s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utf.char(p.char)
306 elseif pt=='sub_box' then
309 debug_depth = k .. '.'; debug_show_node_X(p.head, print_fn);
320 luatexbase.add_to_callback('pre_linebreak_filter',
321 function (head,groupcode)
322 return main_process(head, true, tex.textdir)
323 end,'ltj.pre_linebreak_filter',
324 luatexbase.priority_in_callback('pre_linebreak_filter',
325 'luaotfload.pre_linebreak_filter') + 1)
326 luatexbase.add_to_callback('hpack_filter',
327 function (head,groupcode,size,packtype, dir)
328 return main_process(head, false, dir)
329 end,'ltj.hpack_filter',
330 luatexbase.priority_in_callback('hpack_filter',
331 'luaotfload.hpack_filter') + 1)