4 luatexbase.provides_module({
5 name = 'luatexja.ruby',
9 module('luatexja.ruby', package.seeall)
10 local err, warn, info, log = luatexbase.errwarinf(_NAME)
12 luatexja.load_module('stack'); local ltjs = luatexja.stack
14 local Dnode = node.direct or node
16 local nullfunc = function(n) return n end
17 local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
18 local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
20 local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end
21 local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end
22 local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end
23 local getfont = (Dnode ~= node) and Dnode.getfont or function(n) return n.font end
24 local getlist = (Dnode ~= node) and Dnode.getlist or function(n) return n.head end
25 local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end
26 local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end
28 local node_new = Dnode.new
29 local node_remove = luatexja.Dnode_remove -- Dnode.remove
30 local node_next = (Dnode ~= node) and Dnode.getnext or node.next
31 local node_copy, node_free, node_tail = Dnode.copy, Dnode.free, Dnode.tail
32 local has_attr, set_attr = Dnode.has_attribute, Dnode.set_attribute
33 local insert_before, insert_after = Dnode.insert_before, Dnode.insert_after
35 local id_hlist = node.id('hlist')
36 local id_vlist = node.id('vlist')
37 local id_rule = node.id('rule')
38 local id_whatsit = node.id('whatsit')
39 local id_glue = node.id('glue')
40 local id_kern = node.id('kern')
41 local id_glue_spec = node.id('glue_spec')
42 local sid_user = node.subtype('user_defined')
43 local ltjs_get_stack_table = luatexja.stack.get_stack_table
44 local id_pbox_w = 258 -- cluster which consists of a whatsit
46 local attr_icflag = luatexbase.attributes['ltj@icflag']
47 -- ルビ処理用の attribute は他のやつの流用なので注意!
49 local attr_ruby_maxprep = luatexbase.attributes['ltj@charclass']
50 local attr_ruby_maxpostp = luatexbase.attributes['ltj@kcat0']
51 local attr_ruby_maxmargin = luatexbase.attributes['ltj@kcat1']
52 local attr_ruby_stretch = luatexbase.attributes['ltj@kcat2']
53 local attr_ruby_mode = luatexbase.attributes['ltj@kcat3']
54 local attr_ruby = luatexbase.attributes['ltj@rubyattr']
56 -- jfmglue 中では「2つ前のクラスタもルビ」のフラグ(true = 1)
57 -- (whatsit).value node ではルビ全角の値(sp単位)
58 -- 行分割前後では,「何番目のルビ関連ノード」か
60 local round, floor = tex.round, math.floor
61 local min, max = math.min, math.max
63 local FROM_JFM = luatexja.icflag_table.FROM_JFM
64 local PROCESSED = luatexja.icflag_table.PROCESSED
65 local KANJI_SKIP = luatexja.icflag_table.KANJI_SKIP
66 local KANJI_SKIP_JFM = luatexja.icflag_table.KANJI_SKIP_JFM
67 local XKANJI_SKIP = luatexja.icflag_table.XKANJI_SKIP
68 local XKANJI_SKIP_JFM= luatexja.icflag_table.XKANJI_SKIP_JFM
70 luatexja.userid_table.RUBY_PRE = luatexbase.newuserwhatsitid('ruby_pre', 'luatexja')
71 luatexja.userid_table.RUBY_POST = luatexbase.newuserwhatsitid('ruby_post', 'luatexja')
72 local RUBY_PRE = luatexja.userid_table.RUBY_PRE
73 local RUBY_POST = luatexja.userid_table.RUBY_POST
75 ----------------------------------------------------------------
77 ----------------------------------------------------------------
79 function cpbox() return node_copy(Dnode.getbox(0)) end
81 function cpbox() return node.copy(tex.box[0]) end
85 ----------------------------------------------------------------
87 ----------------------------------------------------------------
89 local function gauss(coef)
90 -- #coef 式,#coef 変数の連立1次方程式系を掃きだし法で解く.
96 coef[i], coef[j] = coef[j], coef[i]; break
101 local d = coef[i][i];
104 for k = 1, deg+1 do coef[j][k] = coef[j][k] - e*coef[i][k]/d end
106 for k = 1, deg+1 do coef[i][k] = coef[i][k]/d end
112 -- 実行回数 + ルビ中身 から uniq_id を作る関数
113 -- 未実装.これを使えば 2 回目以降の組版に 1 回目の情報が使える
116 -- concatenation of boxes: reusing nodes
117 -- ルビ組版が行われている段落/hboxでの設定が使われる.
118 -- ルビ文字を格納しているボックスでの設定ではない!
119 local function concat(f, b)
123 setfield(node_tail(h), 'next', getlist(b))
124 setfield(f, 'head', nil); node_free(f)
125 setfield(b, 'head', nil); node_free(b)
126 return Dnode.hpack(luatexja.jfmglue.main(h,false))
133 local h = node_new(id_hlist)
134 setfield(h, 'subtype', 0)
135 setfield(h, 'width', 0)
136 setfield(h, 'height', 0)
137 setfield(h, 'depth', 0)
138 setfield(h, 'glue_set', 0)
139 setfield(h, 'glue_order', 0)
140 setfield(h, 'head', nil)
145 local function expand_3bits(num)
146 local t = {}; local a = num
148 t[i] = a%8; a = floor(a/8)
152 ----------------------------------------------------------------
154 ----------------------------------------------------------------
156 -- box の中身のノードは再利用される
157 local function enlarge(box, new_width, pre, middle, post, prenw, postnw)
158 -- pre, middle, post: 伸縮比率
159 -- prenw, postnw: 前後の自然長 (sp)
160 local h = getlist(box); local hh, hd = getfield(box, 'height'), getfield(box, 'depth')
163 if has_attr(hx, attr_icflag) == KANJI_SKIP
164 or has_attr(hx, attr_icflag) == KANJI_SKIP_JFM
165 or has_attr(hx, attr_icflag) == XKANJI_SKIP
166 or has_attr(hx, attr_icflag) == XKANJI_SKIP_JFM
167 or has_attr(hx, attr_icflag) == FROM_JFM then
169 if getid(hx) == id_kern then
170 local k = node_new(id_glue)
171 local ks = node_new(id_glue_spec)
172 setfield(ks, 'width', getfield(hx, 'kern'))
173 setfield(ks, 'stretch_order', 2)
174 setfield(ks, 'stretch', round(middle*65536))
175 setfield(ks, 'shrink_order', 0)
176 setfield(ks, 'shrink', 0)
177 setfield(k, 'subtype', 0)
178 setfield(k, 'spec', ks)
179 h = insert_after(h, hx, k);
180 h = node_remove(h, hx); node_free(hx); hx = k
182 local ks = node_copy(getfield(hx, 'spec'))
183 setfield(ks, 'stretch_order', 2)
184 setfield(ks, 'stretch', round(middle*65536))
185 setfield(ks, 'shrink_order', 0)
186 setfield(ks, 'shrink', 0)
187 setfield(hx, 'spec', ks)
193 local k = node_new(id_glue);
194 local ks = node_new(id_glue_spec)
195 setfield(ks, 'width', prenw)
196 setfield(ks, 'stretch_order', 2)
197 setfield(ks, 'stretch', round(pre*65536))
198 setfield(ks, 'shrink_order', 0)
199 setfield(ks, 'shrink', 0)
200 setfield(k, 'subtype', 0)
201 setfield(k, 'spec', ks)
202 h = insert_before(h, h, k);
204 local k = node_new(id_glue);
205 local ks = node_new(id_glue_spec);
206 setfield(ks, 'width', postnw)
207 setfield(ks, 'stretch_order', 2)
208 setfield(ks, 'stretch', round(post*65536))
209 setfield(ks, 'shrink_order', 0)
210 setfield(ks, 'shrink', 0)
211 setfield(k, 'subtype', 0)
212 setfield(k, 'spec', ks)
213 insert_after(h, node_tail(h), k);
215 setfield(box, 'head', nil); node_free(box)
216 box = Dnode.hpack(h, new_width, 'exactly')
217 setfield(box, 'height', hh)
218 setfield(box, 'depth', hd)
222 ----------------------------------------------------------------
224 ----------------------------------------------------------------
226 -- rtlr: ルビ部分のボックスたち r1, r2, ...
227 -- rtlp: 親文字 のボックスたち p1, p2, ...
228 local function texiface_low(rst, rtlr, rtlp)
229 local w = node_new(id_whatsit, sid_user)
230 setfield(w, 'type', 110); setfield(w, 'user_id', RUBY_PRE)
231 local wv = node_new(id_whatsit, sid_user)
232 setfield(w, 'value', to_node(wv))
233 setfield(wv, 'type', 100)
234 setfield(wv, 'value', floor(#rtlr))
235 set_attr(wv, attr_ruby, rst.rubyzw)
236 set_attr(wv, attr_ruby_maxmargin, rst.maxmargin)
237 set_attr(wv, attr_ruby_maxprep, rst.intrusionpre)
238 set_attr(wv, attr_ruby_maxpostp, rst.intrusionpost)
239 set_attr(wv, attr_ruby_stretch, rst.stretch)
240 set_attr(wv, attr_ruby_mode, rst.mode)
243 _, n = insert_after(wv, n, rtlr[i])
244 _, n = insert_after(wv, n, rtlp[i])
246 -- w.value: (whatsit) .. r1 .. p1 .. r2 .. p2
251 function texiface(rst, rtlr, rtlp)
252 if #rtlr ~= #rtlp then
253 for i,v in pairs(rtlr) do node_free(v) end
254 for i,v in pairs(rtlp) do node_free(v) end
255 luatexja.base.package_error('luatexja-ruby',
256 'Group count mismatch between the ruby and\n' ..
257 'the body (' .. #rtlr .. ' != ' .. #rtlp .. ').',
262 if getfield(rtlr[i], 'width') > getfield(rtlp[i], 'width') then f = false; break end
264 if f then -- モノルビ * n
265 local r,p = {true}, {true}
267 r[1] = rtlr[i]; p[1] = rtlp[i]; texiface_low(rst, r, p)
270 texiface_low(rst, rtlr, rtlp)
276 ----------------------------------------------------------------
278 ----------------------------------------------------------------
280 -- r, p の中身のノードは再利用される
281 local function enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode)
282 -- r: ルビ部分の格納された box,p: 同,親文字
283 local rwidth = getfield(r, 'width')
284 local sumprot = rwidth - getfield(p, 'width') -- >0
285 local pre_intrusion, post_intrusion
286 if intmode == 0 then -- とりあえず組んでから決める
287 p = enlarge(p, rwidth, ppre, pmid, ppost, 0, 0)
288 pre_intrusion = min(mapre, round(ppre*getfield(p, 'glue_set')*65536))
289 post_intrusion = min(mapost, round(ppost*getfield(p, 'glue_set')*65536))
290 elseif intmode == 1 then
291 pre_intrusion = min(mapre, sumprot);
292 post_intrusion = min(mapost, max(sumprot-pre_intrusion, 0))
293 p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion)
294 elseif intmode == 2 then
295 post_intrusion = min(mapost, sumprot);
296 pre_intrusion = min(mapre, max(sumprot-post_intrusion, 0))
297 p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion)
299 local n = min(mapre, mapost)*2
301 pre_intrusion = n/2; post_intrusion = n/2
303 pre_intrusion = floor(sumprot/2); post_intrusion = sumprot - pre_intrusion
305 p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion)
306 pre_intrusion = min(mapre, pre_intrusion + round(ppre*getfield(p, 'glue_set')*65536))
307 post_intrusion = min(mapost, post_intrusion + round(ppost*getfield(p, 'glue_set')*65536))
309 setfield(r, 'shift', -pre_intrusion)
310 local rwidth = rwidth - pre_intrusion - post_intrusion
311 setfield(r, 'width', rwidth)
312 setfield(p, 'width', rwidth)
313 local ps = getfield(getlist(p), 'spec')
314 setfield(ps, 'width', getfield(ps, 'width') - pre_intrusion)
315 return r, p, post_intrusion
319 -- returned value: <new box>, <ruby width>, <post_intrusion>
321 local function new_ruby_box(r, p, ppre, pmid, ppost,
322 rpre, rmid, rpost, mapre, mapost, intmode)
323 local post_intrusion = 0
324 if getfield(r, 'width') > getfield(p, 'width') then -- change the width of p
325 r, p, post_intrusion = enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode)
326 elseif getfield(r, 'width') < getfield(p, 'width') then -- change the width of r
327 r = enlarge(r, getfield(p, 'width'), rpre, rmid, rpost, 0, 0)
329 local need_repack = false
330 -- margin が大きくなりすぎた時の処理
331 if round(rpre*getfield(r, 'glue_set')*65536) > max_margin then
332 local ps = getfield(getlist(r), 'spec'); need_repack = true
333 setfield(ps, 'width', max_margin)
334 setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
336 if round(rpost*getfield(r, 'glue_set')*65536) > max_margin then
337 local ps = getfield(node_tail(getlist(r)), 'spec'); need_repack = true
338 setfield(ps, 'width', max_margin)
339 setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
343 r = Dnode.hpack(getlist(r), getfield(r, 'width'), 'exactly')
344 setfield(rt, 'head', nil); node_free(rt);
347 local a = node_new(id_rule)
348 setfield(a, 'width', 0)
349 setfield(a, 'height', 0)
350 setfield(a, 'depth', 0)
351 insert_after(r, r, a); insert_after(r, a, p)
352 setfield(p, 'next', nil)
354 setfield(a, 'height', getfield(p, 'height'))
355 setfield(a, 'depth', getfield(p, 'depth'))
356 setfield(a, 'shift', -(getfield(r, 'height')+getfield(r, 'depth')))
357 return a, getfield(r, 'width'), post_intrusion
361 -- High-level routine in pre_linebreak_filter
362 local max_post_intrusion_backup
363 local max_allow_pre, max_allow_post
366 -- 中付き熟語ルビ,cmp containers
367 -- 「文字の構成を考えた」やつはどうしよう
368 local function pre_low_cal_box(w, cmp)
372 -- kf[i] : container 1--i からなる行末形
373 -- kf[cmp+i] : container i--cmp からなる行頭形
375 local wv = getfield(w, 'value')
376 local mdt -- nt*: node temp
377 local coef = {} -- 連立一次方程式の拡大係数行列
378 local rtb = expand_3bits(has_attr(wv, attr_ruby_stretch))
379 local rtc = expand_3bits(has_attr(wv, attr_ruby_mode))
380 local intmode = floor(has_attr(wv, attr_ruby_mode)/4)%4
382 -- node list 展開・行末形の計算
383 local nt, nta, ntb = wv, nil, nil -- nt*: node temp
385 nt = node_next(nt); rb[i] = nt; nta = concat(nta, node_copy(nt))
386 nt = node_next(nt); pb[i] = nt; ntb = concat(ntb, node_copy(nt))
388 for j = 1, 2*i do coef[i][j] = 1 end
389 for j = 2*i+1, 2*cmp+1 do coef[i][j] = 0 end
390 kf[i], coef[i][2*cmp+2]
391 = new_ruby_box(node_copy(nta), node_copy(ntb),
392 rtb[6], rtb[5], rtb[4], rtc[10], rtc[9], rtc[8],
393 max_allow_pre, 0, intmode)
395 node_free(nta); node_free(ntb)
401 for j = 1, 2*i-1 do coef[cmp+i][j] = 0 end
402 for j = 2*i, 2*cmp+1 do coef[cmp+i][j] = 1 end
403 nta = concat(node_copy(rb[i]), nta); ntb = concat(node_copy(pb[i]), ntb)
404 kf[cmp+i], coef[cmp+i][2*cmp+2], mdt
405 = new_ruby_box(node_copy(nta), node_copy(ntb),
406 rtb[9], rtb[8], rtb[7], rtc[10], rtc[9], rtc[8],
407 0, max_allow_post, intmode)
408 if max_post_intrusion_backup < mdt then max_post_intrusion_backup = mdt end
411 -- ここで,nta, ntb には全 container を連結した box が入っているので
414 for j = 1, 2*cmp+1 do coef[2*cmp+1][j] = 1 end
415 kf[2*cmp+1], coef[2*cmp+1][2*cmp+2], mdt
416 = new_ruby_box(nta, ntb,
417 rtb[3], rtb[2], rtb[1], rtc[10], rtc[9], rtc[8],
418 max_allow_pre, max_allow_post, intmode)
419 if max_post_intrusion_backup < mdt then max_post_intrusion_backup = mdt end
421 -- w.value の node list 更新.
423 Dnode.flush_list(node_next(wv))
424 for i = 1, 2*cmp+1 do setfield(nt, 'next', kf[i]); nt = kf[i] end
426 gauss(coef) -- 掃きだし法で連立方程式形 coef を解く
431 local function pre_low_app_node(head, w, cmp, coef, ht, dp)
433 local nt, ntb = node_new(id_glue), node_new(id_glue_spec)
434 setfield(ntb, 'width', coef[1][2*cmp+2])
435 setfield(ntb, 'stretch_order', 0); setfield(ntb, 'stretch', 0)
436 setfield(ntb, 'shrink_order', 0); setfield(ntb, 'shrink', 0)
437 setfield(nt, 'subtype', 0); setfield(nt, 'spec', ntb)
438 set_attr(nt, attr_ruby, 1); set_attr(w, attr_ruby, 2)
439 head = insert_before(head, w, nt)
443 local nta = node_new(id_rule);
444 setfield(nta, 'width', coef[i*2][2*cmp+2])
445 setfield(nta, 'height', ht); setfield(nta, 'depth', dp)
446 setfield(nta, 'subtype', 0)
447 insert_after(head, nt, nta)
448 set_attr(nta, attr_ruby, 2*i+1)
450 nt = node_new(id_glue)
451 local ntb = node_new(id_glue_spec);
452 setfield(ntb, 'width', coef[i*2+1][2*cmp+2])
453 setfield(ntb, 'stretch_order', 0); setfield(ntb, 'stretch', 0)
454 setfield(ntb, 'shrink_order', 0); setfield(ntb, 'shrink', 0)
455 setfield(nt, 'subtype', 0); setfield(nt, 'spec', ntb)
456 set_attr(nt, attr_ruby, 2*i+2)
457 insert_after(head, nta, nt)
459 tex.setattribute(attr_ruby, -0x7FFFFFFF)
460 setfield(w, 'user_id', RUBY_POST)
461 return head, node_next(nt)
464 local function pre_high(ahead)
465 if not ahead then return ahead end
466 local head = to_direct(ahead)
467 max_post_intrusion_backup = 0
470 if getid(n) == id_whatsit then
471 if getsubtype(n) == sid_user and getfield(n, 'user_id') == RUBY_PRE then
472 local nv = getfield(n, 'value')
473 max_allow_pre = has_attr(nv, attr_ruby_maxprep) or 0
474 if has_attr(n, attr_ruby) == 1 then
475 -- 直前のルビで intrusion がおこる可能性あり.安全策をとる.
476 max_allow_pre = max(0, max_allow_pre - max_post_intrusion_backup)
478 max_post_intrusion_backup = 0
479 max_allow_post = has_attr(nv, attr_ruby_maxpostp) or 0
480 max_margin = has_attr(nv, attr_ruby_maxmargin) or 0
481 local coef = pre_low_cal_box(n, getfield(nv, 'value'))
482 local s = node_tail(nv) --ルビ文字
483 head, n = pre_low_app_node(
484 head, n, getfield(nv, 'value'), coef,
485 getfield(s, 'height'), getfield(s, 'depth')
496 luatexbase.add_to_callback('pre_linebreak_filter', pre_high, 'ltj.ruby.pre', 100)
497 luatexbase.add_to_callback('hpack_filter', pre_high, 'ltj.ruby.pre', 100)
499 ----------------------------------------------------------------
501 ----------------------------------------------------------------
503 local function post_lown(rs, rw, ch)
504 -- ch: the head of `current' hlist
505 if #rs ==0 or not rw then return ch end
506 local hn = has_attr(rs[1], attr_ruby)
507 local fn = has_attr(rs[#rs], attr_ruby)
508 local cmp = getfield(getfield(rw, 'value'), 'value')
511 hn = node_tail(getfield(rw, 'value'))
512 node_remove(getfield(rw, 'value'), hn)
513 insert_after(ch, rs[#rs], hn)
514 set_attr(hn, attr_icflag, PROCESSED)
517 hn = getfield(rw, 'value')
518 for i = 1, deg do hn = node_next(hn) end;
519 node_remove(getfield(rw, 'value'), hn)
520 setfield(hn, 'next', nil)
521 insert_after(ch, rs[#rs], hn)
522 set_attr(hn, attr_icflag, PROCESSED)
525 local deg = (hn-1)/2;
526 if deg == 1 then deg = 2 end
527 hn = getfield(rw, 'value'); for i = 1, cmp+deg-1 do hn = node_next(hn) end
528 -- -1 is needed except the case hn = 3,
529 -- because a ending-line form is removed already from the list
530 node_remove(getfield(rw, 'value'), hn); setfield(hn, 'next', nil)
531 insert_after(ch, rs[#rs], hn)
532 set_attr(hn, attr_icflag, PROCESSED)
535 ch = node_remove(ch, rs[i]); node_free(rs[i])
538 if fn >= 2*cmp+1 then
539 --setfield(hn, 'next', nil);
546 local function post_high_break(head)
547 local h = to_direct(head);
548 local rs = {}; -- rs: sequence of ruby_nodes,
549 local rw = nil; -- rw: main whatsit
551 if getid(h) == id_hlist then
552 local ha = getlist(h); rs = {}
554 local hai = getid(ha)
555 local i = (((hai == id_glue and getsubtype(ha)==0)
556 or (hai == id_rule and getsubtype(ha)==0)
557 or (hai == id_whatsit and getsubtype(ha)==sid_user
558 and getfield(ha, 'user_id')==RUBY_POST))
559 and has_attr(ha, attr_ruby)) or 0
561 setfield(h, 'head', post_lown(rs, rw, getlist(h))); rs = {}; rw = nil
562 rs[1] = ha; ha = node_next(ha)
564 rs[#rs+1] = ha; ha = node_next(ha)
567 local hb, hc = node_remove(getlist(h), rw)
568 setfield(h, 'head', hb); ha = hc
573 setfield(h, 'head', post_lown(rs, rw, getlist(h)))
581 local function post_high_hbox(ahead)
582 local ha = to_direct(ahead); local head = ha
583 local rs = {}; -- rs: sequence of ruby_nodes,
584 local rw = nil; -- rw: main whatsit
586 local hai = getid(ha)
587 local i = (((hai == id_glue and getsubtype(ha)==0)
588 or (hai == id_rule and getsubtype(ha)==0)
589 or (hai == id_whatsit and getsubtype(ha)==sid_user
590 and getfield(ha, 'user_id', RUBY_POST)))
591 and has_attr(ha, attr_ruby)) or 0
593 head = post_lown(rs, rw, head); rs = {}; rw = nil
594 table.insert(rs, ha); ha = node_next(ha)
596 table.insert(rs, ha); ha = node_next(ha)
598 rw = ha; head, ha = node_remove(head, rw)
603 return to_node(post_lown(rs, rw, head))
606 luatexbase.add_to_callback('post_linebreak_filter', post_high_break, 'ltj.ruby.post_break', 100)
607 luatexbase.add_to_callback('hpack_filter', post_high_hbox, 'ltj.ruby.post_hbox', 101)
610 ----------------------------------------------------------------
611 -- for jfmglue callbacks
612 ----------------------------------------------------------------
614 local RIPRE = luatexja.stack_table_index.RIPRE
615 local function whatsit_callback(Np, lp, Nq, bsl)
616 if Np.nuc then return Np
617 elseif getfield(lp, 'user_id') == RUBY_PRE then
618 Np.first, Np.nuc, Np.last = lp, lp, lp
619 local lpv = getfield(lp, 'value')
620 local x = node_next(node_next(lpv))
621 Np.last_char = luatexja.jfmglue.check_box_high(Np, getlist(x), nil)
622 if Nq.id ~=id_pbox_w and type(Nq.char)=='number' then
623 if has_attr(lpv, attr_ruby_maxprep) < 0 then -- auto
624 local p = round((ltjs.table_current_stack[RIPRE + Nq.char] or 0)
625 *has_attr(lpv, attr_ruby))
626 if has_attr(lpv, attr_ruby_mode)%2 == 0 then -- intrusion 無効
629 set_attr(lpv, attr_ruby_maxprep, p)
632 set_attr(lp, attr_ruby, 1)
635 set_attr(getfield(lp, 'value'), attr_ruby_maxprep, 0)
640 luatexbase.add_to_callback("luatexja.jfmglue.whatsit_getinfo", whatsit_callback,
641 "luatexja.ruby.np_info", 1)
645 local RIPOST = luatexja.stack_table_index.RIPOST
646 local function whatsit_after_callback(s, Nq, Np, bsl)
647 if not s and getfield(Nq.nuc, 'user_id') == RUBY_PRE then
648 local nqnv = getfield(Nq.nuc, 'value')
649 local x = node_next(node_next(nqnv))
650 for i = 2, getfield(nqnv, 'value') do x = node_next(node_next(x)) end
651 Nq.last_char = luatexja.jfmglue.check_box_high(Nq, getlist(x), nil)
652 luatexja.jfmglue.after_hlist(Nq)
653 if Np and Np.id ~=id_pbox_w and type(Np.char)=='number' then
654 if has_attr(nqnv, attr_ruby_maxpostp) < 0 then -- auto
655 local p = round((ltjs.table_current_stack[RIPOST + Np.char] or 0)
656 *has_attr(nqnv, attr_ruby))
657 if has_attr(nqnv, attr_ruby_mode)%2 == 0 then -- intrusion 無効
660 if has_attr(nqnv, attr_ruby_mode)%4 >= 2 then
661 local q = has_attr(nqnv, attr_ruby_maxprep)
664 set_attr(nqnv, attr_ruby_maxprep, p)
667 set_attr(nqnv, attr_ruby_maxpostp, p)
669 Np.prev_ruby = true -- 前のクラスタがルビであったことのフラグ
670 else -- 直前が文字以外なら intrusion なし
671 local nqnv = getfield(Nq.nuc, 'value')
672 set_attr(nqnv, attr_ruby_maxpostp, 0)
673 if has_attr(nqnv, attr_ruby_mode)%4 >= 2 then
674 set_attr(nqnv, attr_ruby_maxprep, 0)
676 if Np and Np.id == id_pbox_w then
677 set_attr(getfield(Np.nuc, 'value'), attr_ruby_maxprep, 0)
685 luatexbase.add_to_callback("luatexja.jfmglue.whatsit_after", whatsit_after_callback,
686 "luatexja.ruby.np_info_after", 1)