2 -- luatexja/jfmglue.lua
4 luatexbase.provides_module({
5 name = 'luatexja.jfmglue',
8 description = 'Insertion process of JFM glues and kanjiskip',
10 module('luatexja.jfmglue', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
13 require('luatexja.base'); local ltjb = luatexja.base
14 require('luatexja.stack'); local ltjs = luatexja.stack
15 require('luatexja.jfont'); local ltjf = luatexja.jfont
16 require('luatexja.pretreat'); local ltjp = luatexja.pretreat
18 local node_type = node.type
19 local node_new = node.new
20 local node_remove = node.remove
21 local node_prev = node.prev
22 local node_next = node.next
23 local node_copy = node.copy
24 local node_tail = node.tail
25 local node_free = node.free
26 local has_attr = node.has_attribute
27 local set_attr = node.set_attribute
28 local node_insert_before = node.insert_before
29 local node_insert_after = node.insert_after
30 local round = tex.round
32 local id_glyph = node.id('glyph')
33 local id_hlist = node.id('hlist')
34 local id_vlist = node.id('vlist')
35 local id_rule = node.id('rule')
36 local id_ins = node.id('ins')
37 local id_mark = node.id('mark')
38 local id_adjust = node.id('adjust')
39 local id_disc = node.id('disc')
40 local id_whatsit = node.id('whatsit')
41 local id_math = node.id('math')
42 local id_glue = node.id('glue')
43 local id_kern = node.id('kern')
44 local id_penalty = node.id('penalty')
46 local id_glue_spec = node.id('glue_spec')
47 local id_jglyph = node.id('glyph') + 256
48 local id_box_like = node.id('hlist') + 256
49 local id_pbox = node.id('hlist') + 512
50 local sid_user = node.subtype('user_defined')
60 local IC_PROCESSED = 9
66 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
67 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
68 local attr_icflag = luatexbase.attributes['ltj@icflag']
69 local attr_autospc = luatexbase.attributes['ltj@autospc']
70 local attr_autoxspc = luatexbase.attributes['ltj@autoxspc']
71 local max_dimen = 1073741823
75 -------------------- Helper functions
77 local function find_char_class(c,m)
78 return m.chars[c] or 0
81 local function get_zero_glue()
82 local g = node_new(id_glue_spec)
83 g.width = 0; g.stretch_order = 0; g.stretch = 0
84 g.shrink_order = 0; g.shrink = 0
88 local function skip_table_to_spec(n)
89 local g = node_new(id_glue_spec)
90 local st = ltjs.get_skip_table(n, ltjp.box_stack_level)
91 g.width = st.width; g.stretch = st.stretch; g.shrink = st.shrink
92 g.stretch_order = st.stretch_order; g.shrink_order = st.shrink_order
97 local function add_penalty(p,e)
98 if p.penalty>=10000 then
99 if e<=-10000 then p.penalty = 0 end
100 elseif p.penalty<=-10000 then
101 if e>=10000 then p.penalty = 0 end
103 p.penalty = p.penalty + e
104 if p.penalty>=10000 then p.penalty = 10000
105 elseif p.penalty<=-10000 then p.penalty = -10000 end
111 diffmet_rule = math.two_average
112 function math.two_add(a,b) return a+b end
113 function math.two_average(a,b) return (a+b)/2 end
115 -------------------- idea
116 -- 2 node の間に glue/kern/penalty を挿入する.
117 -- 基本方針: char node q と char node p の間
120 -- first: 最初の node,nuc: p,last: 最後の node
123 -- 実際の glue は Np.last, Nq.first の間に挿入される
124 -- Bp: Np.last, Nq.first の間の penalty node 達の配列
127 -- node x が non-char node のときは,x のみ
128 -- x が char_node のときは,
129 -- - x が \accent の第二引数だったとき
130 -- [kern2 kern y kern2] x の 3 node が核に加わる
131 -- - x の直後に \/ 由来 kern があったとき
132 -- その \/ 由来の kern が核に加わる
134 -- ins, mark, adjust, whatsit, penalty
136 -- Nq.last .. + .. Bp.first .... Bp[last] .... * .. Np.first
137 -- +: kern from LINEEND はここに入る
138 -- *: jfm glue はここに入る
140 local head -- the head of current list
141 local last -- the last node of current list
142 local lp -- 外側での list 走査時のカーソル
144 local Np, Nq, Bp, Bpn
145 local widow_Bp, widow_Bpn, widow_Np -- \jcharwidowpenalty 挿入位置管理用
147 local ihb_flag -- JFM グルー挿入抑止用 flag
148 -- on: \inhibitglue 指定時,hlist の周囲
150 -------------------- hlist 内の文字の検索
152 local first_char, last_char, find_first_char
154 local function check_box(box_ptr, box_end)
155 local p = box_ptr; local found_visible_node = false
157 find_first_char = false; first_char = nil; last_char = nil
160 while p and p~=box_end do
164 p = node_next(node_next(node_next(p))); pid = p.id
165 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
166 p = node_next(p); pid = p.id
169 if pid==id_glyph then
171 if find_first_char then
172 first_char = p; find_first_char = false
174 last_char = p; found_visible_node = true; p=node_next(p)
175 if (not p) or p==box_end then return found_visible_node end
178 if pid==id_hlist then
179 if has_attr(p, attr_icflag)==PACKED then
180 for q in node.traverse_id(id_glyph, p.head) do
181 if find_first_char then
182 first_char = q; find_first_char = false
184 last_char = q; found_visible_node = true; break
188 if check_box(p.head, nil) then found_visible_node = true end
189 else if find_first_char then
190 find_first_char = false
196 elseif not (pid==id_ins or pid==id_mark
197 or pid==id_adjust or pid==id_whatsit
198 or pid==id_penalty) then
199 found_visible_node = true
200 if find_first_char then
201 find_first_char = false
208 return found_visible_node
211 -------------------- Np の計算と情報取得
213 local function set_attr_icflag_processed(p)
214 local a = has_attr(p, attr_icflag) or 0
215 if a<=1 then set_attr(p, attr_icflag, PROCESSED) end
218 local function check_next_ickern()
219 if lp.id == id_kern and has_attr(lp, attr_icflag)==ITALIC then
220 set_attr(lp, attr_icflag, IC_PROCESSED); Np.last = lp; lp = node_next(lp)
221 else Np.last = Np.nuc end
224 local function calc_np_pbox()
225 Np.first = lp; Np.id = id_pbox
226 lpa = KINSOKU -- dummy
227 while lp~=last and lpa>=PACKED and lpa~=BOXBDD do
228 Np.nuc = lp; lp = node_next(lp); lpa = has_attr(lp, attr_icflag) or 0
233 local function calc_np()
234 -- We assume lp = node_next(Np.last)
235 local pBp = Bp; local lpi, lpa
236 Nq = Np; ihb_flag = false
237 for k in pairs(Np) do Np[k]=nil end
238 for k in pairs(Bp) do Bp[k]=nil end; Bpn = 0
240 lpi = lp.id; lpa = has_attr(lp, attr_icflag) or 0
241 if lp==last then Np = nil; return
242 elseif lpa>=PACKED then
243 if lpa == BOXBDD then
244 local lq = node_next(lp)
245 head = node_remove(head, lp); lp = lq
246 else calc_np_pbox(); return end -- id_pbox
247 elseif lpi == id_ins or lpi == id_mark or lpi == id_adjust then
248 set_attr_icflag_processed(lp); lp = node_next(lp)
249 elseif lpi == id_penalty then
250 table.insert(Bp, lp); Bpn = Bpn + 1
251 set_attr_icflag_processed(lp); lp = node_next(lp)
252 elseif lpi == id_whatsit then
253 if lp.subtype==sid_user and lp.user_id==30111 then
254 local lq = node_next(lp)
255 head = node_remove(head, lp); lp = lq; ihb_flag = true
257 set_attr_icflag_processed(lp); lp = node_next(lp)
259 else -- a `cluster' is found
261 if lpi == id_glyph then -- id_[j]glyph
262 if lp.font == has_attr(lp, attr_curjfnt) then Np.id = id_jglyph
263 else Np.id = id_glyph end
264 Np.nuc = lp; set_attr_icflag_processed(lp)
265 lp = node_next(lp); check_next_ickern(); return
266 elseif lpi == id_hlist then -- hlist
267 Np.last = lp; Np.nuc = lp; set_attr_icflag_processed(lp)
268 if lp.shift~=0 then Np.id = id_box_like
270 lp = node_next(lp); return
271 elseif lpi == id_vlist or lpi == id_rule then -- id_box_like
272 Np.nuc = lp; Np.last = lp; Np.id = id_box_like; break
273 elseif lpi == id_math then -- id_math
274 Np.nuc = lp; lp = node_next(lp)
275 while lp.id~=id_math do
276 set_attr_icflag_processed(lp); lp = node_next(lp)
278 elseif lpi == id_kern and lp.subtype==2 then -- id_kern
279 set_attr_icflag_processed(lp); lp = node_next(lp)
280 set_attr_icflag_processed(lp); lp = node_next(lp)
281 set_attr_icflag_processed(lp); lp = node_next(lp)
282 set_attr_icflag_processed(lp); Np.nuc = lp
283 if lp.font == has_attr(lp, attr_curjfnt) then Np.id = id_jglyph
284 else Np.id = id_glyph end
285 lp = node_next(lp); check_next_ickern(); return
286 else -- id_disc, id_glue, id_kern
291 set_attr_icflag_processed(lp); Np.last = lp; Np.id = lpi; lp = node_next(lp)
294 -- extract informations from Np
295 -- We think that "Np is a Japanese character" if Np.met~=nil,
296 -- "Np is an alphabetic character" if Np.pre~=nil,
297 -- "Np is not a character" otherwise.
300 local function set_np_xspc_jachar(c,x)
301 Np.class = has_attr(x, attr_jchar_class)
303 local z = ltjf.font_metric_table[x.font]
305 Np.met = ltjf.metrics[z.jfm]
307 Np.pre = ltjs.get_penalty_table('pre', c, 0, ltjp.box_stack_level)
308 Np.post = ltjs.get_penalty_table('post', c, 0, ltjp.box_stack_level)
309 z = find_char_class('lineend', Np.met)
310 local y = Np.met.size_cache[Np.size].char_type[Np.class]
311 if y.kern and y.kern[z] then
316 y = ltjs.get_penalty_table('xsp', c, 3, ltjp.box_stack_level)
317 Np.xspc_before = (y>=2)
318 Np.xspc_after = (y%2==1)
319 Np.auto_kspc = (has_attr(x, attr_autospc)==1)
320 Np.auto_xspc = (has_attr(x, attr_autoxspc)==1)
324 local ligature_head = 1
325 local ligature_tail = 2
326 local function set_np_xspc_alchar(c,x, lig)
328 if lig == ligature_head then
329 while x.components and x.subtype and math.floor(x.subtype/2)%2==1 do
330 x = x.components; c = x.char
333 while x.components and x.subtype and math.floor(x.subtype/2)%2==1 do
334 x = node_tail(x.components); c = x.char
337 Np.pre = ltjs.get_penalty_table('pre', c, 0, ltjp.box_stack_level)
338 Np.post = ltjs.get_penalty_table('post', c, 0, ltjp.box_stack_level)
340 Np.pre = 0; Np.post = 0
343 local y = ltjs.get_penalty_table('xsp', c, 3, ltjp.box_stack_level)
344 Np.xspc_before = (y%2==1)
345 Np.xspc_after = (y>=2)
346 Np.auto_xspc = (has_attr(x, attr_autoxspc)==1)
350 local function extract_np()
352 if Np.id == id_jglyph then
353 set_np_xspc_jachar(x.char, x)
354 elseif Np.id == id_glyph then
355 set_np_xspc_alchar(x.char, x, ligature_head)
356 elseif Np.id == id_hlist then
357 find_first_char = true; first_char = nil; last_char = nil
358 if check_box(x.head, nil) then
360 if first_char.font == has_attr(first_char, attr_curjfnt) then
361 set_np_xspc_jachar(first_char.char,first_char)
363 set_np_xspc_alchar(first_char.char,first_char, ligature_head)
367 elseif Np.id == id_pbox then -- mikann
368 find_first_char = true; first_char = nil; last_char = nil
369 if check_box(Np.first, node_next(Np.last)) then
371 if first_char.font == has_attr(first_char, attr_curjfnt) then
372 set_np_xspc_jachar(first_char.char,first_char)
374 set_np_xspc_alchar(first_char.char,first_char, ligature_head)
378 elseif Np.id == id_disc then
379 find_first_char = true; first_char = nil; last_char = nil
380 if check_box(x.replace, nil) then
382 if first_char.font == has_attr(first_char, attr_curjfnt) then
383 set_np_xspc_jachar(first_char.char,first_char)
385 set_np_xspc_alchar(first_char.char,first_char, ligature_head)
389 elseif Np.id == id_math then
390 set_np_xspc_alchar(-1, x)
394 -- change the information for the next loop
395 -- (will be done if Np is an alphabetic character or a hlist)
396 local function after_hlist()
398 if last_char.font == has_attr(last_char, attr_curjfnt) then
399 set_np_xspc_jachar(last_char.char,last_char, ligature_after)
401 set_np_xspc_alchar(last_char.char,last_char, ligature_after)
404 Np.pre = nil; Np.met = nil
407 local function after_alchar()
409 set_np_xspc_alchar(x.char,x, ligature_after)
413 -------------------- 最下層の処理
415 local function lineend_fix(g)
416 if g and g.id==id_kern then
418 elseif Nq.lend and Nq.lend~=0 then
420 g = node_new(id_kern); g.subtype = 1
421 g.kern = -Nq.lend; set_attr(g, attr_icflag, LINEEND)
422 elseif g.id==id_kern then
423 g.kern = g.kern - Nq.lend
425 g.spec.width = g.spec.width - Nq.lend
431 -- change penalties (or create a new penalty, if needed)
432 local function handle_penalty_normal(post, pre, g)
433 local a = (pre or 0) + (post or 0)
435 if (a~=0 and not(g and g.id==id_kern)) or (Nq.lend and Nq.lend~=0) then
436 local p = node_new(id_penalty)
437 if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
439 head = node_insert_before(head, Np.first, p)
440 Bp[1] = p; Bpn = 1; set_attr(p, attr_icflag, KINSOKU)
442 else for i, v in ipairs(Bp) do add_penalty(v,a) end
446 local function handle_penalty_always(post, pre, g)
447 local a = (pre or 0) + (post or 0)
449 if not (g and g.id==id_glue) or (Nq.lend and Nq.lend~=0) then
450 local p = node_new(id_penalty)
451 if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
453 head = node_insert_before(head, Np.first, p)
454 Bp[1] = p; Bpn = 1; set_attr(p, attr_icflag, KINSOKU)
456 else for i, v in ipairs(Bp) do add_penalty(v,a) end
460 local function handle_penalty_suppress(post, pre, g)
461 local a = (pre or 0) + (post or 0)
463 if g and g.id==id_glue then
464 local p = node_new(id_penalty)
465 p.penalty = 10000; head = node_insert_before(head, Np.first, p)
466 Bp[1] = p; Bpn = 1; set_attr(p, attr_icflag, KINSOKU)
468 else for i, v in ipairs(Bp) do add_penalty(v,a) end
472 -- 和文文字間の JFM glue を node 化
473 local function new_jfm_glue(Nn, bc, ac)
474 -- bc, ac: char classes
476 local z = Nn.met.size_cache[Nn.size].char_type[bc]
477 if z.glue and z.glue[ac] then
478 local h = node_new(id_glue_spec)
479 h.width = z.glue[ac][1]
480 h.stretch = z.glue[ac][2]
481 h.shrink = z.glue[ac][3]
482 h.stretch_order=0; h.shrink_order=0
483 g = node_new(id_glue)
484 g.subtype = 0; g.spec = h
485 elseif z.kern and z.kern[ac] then
486 g = node_new(id_kern)
487 g.subtype = 1; g.kern = z.kern[ac]
489 if g then set_attr(g, attr_icflag, FROM_JFM) end
493 -- Nq.last (kern w) .... (glue/kern g) Np.first
494 local function real_insert(w, g)
496 local h = node_new(id_kern)
497 set_attr(h, attr_icflag, LINE_END)
498 h.kern = Nq.lend; h.subtype = 1
499 head = node_insert_after(head, Nq.last, h)
502 head = node_insert_before(head, Np.first, g)
507 -------------------- 和文文字間空白量の決定
510 local function get_kanji_skip_from_jfm(Nn)
511 local i = Nn.met.size_cache[Nn.size].kanjiskip
513 return { i[1], i[2], i[3] }
517 local function get_kanjiskip()
518 local g = node_new(id_glue)
519 if Np.auto_kspc or Nq.auto_kspc then
520 if kanji_skip.width == max_dimen then
521 local gx = node_new(id_glue_spec);
522 gx.stretch_order = 0; gx.shrink_order = 0
523 local bk = get_kanji_skip_from_jfm(Nq)
525 if (Np.met==Nq.met) and (Nq.size==Np.size) and (Nq.var==Np.var) then
528 ak = get_kanji_skip_from_jfm(Np)
532 gx.width = round(diffmet_rule(bk[1], ak[1]))
533 gx.stretch = round(diffmet_rule(bk[2], ak[2]))
534 gx.shrink = -round(diffmet_rule(-bk[3], -ak[3]))
536 gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3]
539 gx.width = ak[1]; gx.stretch = ak[2]; gx.shrink = ak[3]
540 else gx = get_zero_glue() -- fallback
543 else g.spec=node_copy(kanji_skip) end
545 local gx = get_zero_glue()
548 set_attr(g, attr_icflag, KANJI_SKIP)
552 local function calc_ja_ja_aux(gb,ga)
556 if not ga then return gb end
557 local k = node.type(gb.id) .. node.type(ga.id)
558 if k == 'glueglue' then
560 gb.spec.width = round(diffmet_rule(gb.spec.width, ga.spec.width))
561 gb.spec.stretch = round(diffmet_rule(gb.spec.stretch,ga.spec.shrink))
562 gb.spec.shrink = -round(diffmet_rule(-gb.spec.shrink, -ga.spec.shrink))
565 elseif k == 'kernkern' then
567 gb.kern = round(diffmet_rule(gb.kern, ga.kern))
570 elseif k == 'kernglue' then
571 -- gb: kern, ga: glue
572 ga.spec.width = round(diffmet_rule(gb.kern,ga.spec.width))
573 ga.spec.stretch = round(diffmet_rule(ga.spec.stretch, 0))
574 ga.spec.shrink = -round(diffmet_rule(-ga.spec.shrink, 0))
578 -- gb: glue, ga: kern
579 gb.spec.width = round(diffmet_rule(ga.kern, gb.spec.width))
580 gb.spec.stretch = round(diffmet_rule(gb.spec.stretch, 0))
581 gb.spec.shrink = -round(diffmet_rule(-gb.spec.shrink, 0))
588 local function calc_ja_ja_glue()
589 if ihb_flag then return nil
590 elseif (Nq.size==Np.size) and (Nq.met==Np.met) and (Nq.var==Np.var) then
591 return new_jfm_glue(Nq, Nq.class, Np.class)
593 local g = new_jfm_glue(Nq, Nq.class,
594 find_char_class('diffmet',Nq.met))
595 local h = new_jfm_glue(Np, find_char_class('diffmet',Np.met),
597 return calc_ja_ja_aux(g,h)
601 -------------------- 和欧文間空白量の決定
604 local function get_xkanji_skip_from_jfm(Nn)
605 local i = Nn.met.size_cache[Nn.size].xkanjiskip
607 return { i[1], i[2], i[3] }
611 local function get_xkanjiskip(Nn)
612 local g = node_new(id_glue)
613 if Nq.xspc_after and Np.xspc_before and (Nq.auto_xspc or Np.auto_xspc) then
614 if xkanji_skip.width == max_dimen then
615 local gx = node_new(id_glue_spec);
616 gx.stretch_order = 0; gx.shrink_order = 0
617 local bk = get_xkanji_skip_from_jfm(Nn)
619 gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3]
620 else gx = get_zero_glue() -- fallback
623 else g.spec=node_copy(xkanji_skip) end
625 local gx = get_zero_glue()
628 set_attr(g, attr_icflag, XKANJI_SKIP)
633 -------------------- 隣接した「塊」間の処理
635 local function get_OA_skip()
637 return new_jfm_glue(Np, find_char_class('jcharbdd',Np.met), Np.class)
641 local function get_OB_skip()
643 return new_jfm_glue(Nq, Nq.class, find_char_class('jcharbdd',Nq.met))
648 -- (anything) .. jachar
649 local function handle_np_jachar()
651 if Nq.id==id_jglyph or (Nq.id==id_pbox and Nq.met) then
652 g = calc_ja_ja_glue() or get_kanjiskip() -- M->K
654 handle_penalty_normal(Nq.post, Np.pre, g); real_insert(Nq.lend, g)
655 elseif Nq.met then -- Nq.id==id_hlist
656 g = get_OA_skip() or get_kanjiskip() -- O_A->K
657 handle_penalty_normal(0, Np.pre, g); real_insert(0, g)
659 g = get_OA_skip() or get_xkanjiskip(Np) -- O_A->X
660 handle_penalty_normal(Nq.post, Np.pre, g); real_insert(0, g)
662 g = get_OA_skip() -- O_A
663 if Nq.id==id_glue then handle_penalty_normal(0, Np.pre, g)
664 elseif Nq.id==id_kern then handle_penalty_suppress(0, Np.pre, g)
665 else handle_penalty_always(0, Np.pre, g)
669 -- \jcharwidowpenalty 挿入予定箇所更新
670 if ltjs.get_penalty_table('kcat', Np.char, 0, ltjp.box_stack_level)%2~=1 then
671 widow_Np = Np; widow_Bp = Bp; widow_Bpn = Bpn
675 -- jachar .. (anything)
676 local function handle_nq_jachar()
679 g = get_OB_skip() or get_xkanjiskip(Nq) -- O_B->X
681 handle_penalty_normal(Nq.post, Np.pre, g); real_insert(Nq.lend, g)
683 g = get_OB_skip(); g = lineend_fix(g) -- O_B
684 if Np.id==id_glue then handle_penalty_normal(Nq.post, 0, g)
685 elseif Np.id==id_kern then handle_penalty_suppress(Nq.post, 0, g)
686 else handle_penalty_always(Nq.post, 0, g)
688 real_insert(Nq.lend, g)
692 -- (anything) .. (和文文字で終わる hlist)
693 local function handle_np_ja_hlist()
695 if Nq.id==id_jglyph or (Nq.id==id_pbox and Nq.met) then
696 g = get_OB_skip() or get_kanjiskip() -- O_B->K
698 handle_penalty_normal(Nq.post, 0, g); real_insert(Nq.lend, g)
699 elseif Nq.met then -- Nq.id==id_hlist
700 g = get_kanjiskip() -- K
701 handle_penalty_suppress(0, 0, g); real_insert(0, g)
703 g = get_xkanjiskip(Np) -- X
704 handle_penalty_suppress(0, 0, g); real_insert(0, g)
708 -- (和文文字で終わる hlist) .. (anything)
709 local function handle_nq_ja_hlist()
712 g = get_xkanjiskip(Nq) -- X
713 handle_penalty_suppress(0, 0, g); real_insert(0, g)
717 -------------------- 開始・終了時の処理
720 local function handle_list_tail()
723 -- the current list is to be line-breaked:
724 if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then
726 g = node_new(id_kern); g.subtype = 0; g.kern = Np.lend
727 set_attr(g, attr_icflag, BOXBDD)
728 node_insert_after(head, Np.last, g)
731 -- Insert \jcharwidowpenalty
732 Bp = widow_Bp; Np = widow_Np; Bpn = widow_Bpn
734 handle_penalty_normal(0,
735 ltjs.get_penalty_table('jwp', 0, 0, ltjp.box_stack_level))
738 -- the current list is the contents of a hbox
739 if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then
740 local g = new_jfm_glue(Np, Np.class, find_char_class('boxbdd',Np.met))
742 set_attr(g, attr_icflag, BOXBDD)
743 head = node_insert_after(head, Np.last, g)
746 head = node_remove(head, last) -- remove the sentinel
751 local function handle_list_head()
752 if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then
753 local g = new_jfm_glue(Np, find_char_class('boxbdd',Np.met), Np.class)
755 set_attr(g, attr_icflag, BOXBDD)
756 if g.id==id_glue and Bpn==0 then
757 local h = node_new(id_penalty)
758 h.penalty = 10000; set_attr(h, attr_icflag, BOXBDD)
760 head = node_insert_before(head, Np.first, g)
766 local function init_var()
767 lp = head; widow_Bp = nil; widow_Np = nil; Np = {}; Bp = {}
768 kanji_skip=skip_table_to_spec('kanjiskip')
769 xkanji_skip=skip_table_to_spec('xkanjiskip')
771 -- the current list is to be line-breaked:
772 -- hbox from \parindent is skipped.
773 while lp and (lp.id==id_whatsit or ((lp.id==id_hlist) and (lp.subtype==3))) do
777 -- the current list is the contents of a hbox:
779 last=node.tail(head); local g = node_new(id_kern)
780 node_insert_after(head, last, g); last = g
784 -------------------- 外部から呼ばれる関数
787 function main(ahead, amode)
788 if not ahead then return ahead end
789 head = ahead; mode = amode; init_var(); calc_np()
791 extract_np(); handle_list_head()
792 if Np.id==id_glyph then after_alchar()
793 elseif Np.id==id_hlist or Np.id==id_pbox or Np.id==id_disc then after_hlist()
796 if not mode then head = node_remove(head, last) end
803 if Np.id == id_jglyph then
806 if Np.id==id_hlist then handle_np_ja_hlist()
807 else handle_np_jachar() end
809 if Nq.id==id_hlist then handle_nq_ja_hlist()
810 else handle_nq_jachar() end
813 if Np.id==id_glyph then after_alchar()
814 elseif Np.id==id_hlist or Np.id==id_pbox or Np.id==id_disc then after_hlist()
819 -- adjust attr_icflag
820 tex.attribute[attr_icflag] = -(0x7FFFFFFF)
825 function create_inhibitglue_node()
826 local g=node_new(id_whatsit, sid_user)
827 g.user_id=30111; g.type=100; g.value=1; node.write(g)