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
31 local table_insert = table.insert
33 local id_glyph = node.id('glyph')
34 local id_hlist = node.id('hlist')
35 local id_vlist = node.id('vlist')
36 local id_rule = node.id('rule')
37 local id_ins = node.id('ins')
38 local id_mark = node.id('mark')
39 local id_adjust = node.id('adjust')
40 local id_disc = node.id('disc')
41 local id_whatsit = node.id('whatsit')
42 local id_math = node.id('math')
43 local id_glue = node.id('glue')
44 local id_kern = node.id('kern')
45 local id_penalty = node.id('penalty')
47 local id_glue_spec = node.id('glue_spec')
48 local id_jglyph = node.id('glyph') + 256
49 local id_box_like = node.id('hlist') + 256
50 local id_pbox = node.id('hlist') + 512
51 local sid_user = node.subtype('user_defined')
61 local IC_PROCESSED = 9
67 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
68 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
69 local attr_icflag = luatexbase.attributes['ltj@icflag']
70 local attr_autospc = luatexbase.attributes['ltj@autospc']
71 local attr_autoxspc = luatexbase.attributes['ltj@autoxspc']
72 local max_dimen = 1073741823
74 local ltjs_get_penalty_table = ltjs.get_penalty_table
75 local ltjs_get_skip_table = ltjs.get_skip_table
76 local ltjf_find_char_class = ltjf.find_char_class
77 local ltjf_font_metric_table = ltjf.font_metric_table
78 local ltjf_metrics = ltjf.metrics
80 local par_indented -- is the paragraph indented?
82 -------------------- Helper functions
84 -- This function is called only for acquiring `special' characters.
85 local function fast_find_char_class(c,m)
86 return m.chars[c] or 0
89 local spec_zero_glue = node_new(id_glue_spec)
90 spec_zero_glue.width = 0; spec_zero_glue.stretch_order = 0; spec_zero_glue.stretch = 0
91 spec_zero_glue.shrink_order = 0; spec_zero_glue.shrink = 0
93 local function get_zero_glue()
94 return node_copy(spec_zero_glue)
97 local function skip_table_to_spec(n)
98 local g = node_new(id_glue_spec)
99 local st = ltjs_get_skip_table(n, box_stack_level)
100 g.width = st.width; g.stretch = st.stretch; g.shrink = st.shrink
101 g.stretch_order = st.stretch_order; g.shrink_order = st.shrink_order
106 local function add_penalty(p,e)
107 if p.penalty>=10000 then
108 if e<=-10000 then p.penalty = 0 end
109 elseif p.penalty<=-10000 then
110 if e>=10000 then p.penalty = 0 end
112 p.penalty = p.penalty + e
113 if p.penalty>=10000 then p.penalty = 10000
114 elseif p.penalty<=-10000 then p.penalty = -10000 end
120 diffmet_rule = math.two_average
121 function math.two_add(a,b) return a+b end
122 function math.two_average(a,b) return (a+b)/2 end
124 -------------------- idea
125 -- 2 node の間に glue/kern/penalty を挿入する.
126 -- 基本方針: char node q と char node p の間
129 -- first: 最初の node,nuc: p,last: 最後の node
132 -- 実際の glue は Np.last, Nq.first の間に挿入される
133 -- Bp: Np.last, Nq.first の間の penalty node 達の配列
135 -- Np, Nq, Bp, widow_Bp について
137 -- 1回のループごとに Nq = Np, Np = (new table) となるのは効率が悪いので,
138 -- Np <-> Nq 入れ替え,その後 Np をクリアすることでテーブルを再利用.
139 -- 同様の関係は Bp, widow_Bp にも.
143 -- node x が non-char node のときは,x のみ
144 -- x が char_node のときは,
145 -- - x が \accent の第二引数だったとき
146 -- [kern2 kern y kern2] x の 3 node が核に加わる
147 -- - x の直後に \/ 由来 kern があったとき
148 -- その \/ 由来の kern が核に加わる
150 -- ins, mark, adjust, whatsit, penalty
152 -- Nq.last .. + .. Bp.first .... Bp[last] .... * .. Np.first
153 -- +: kern from LINEEND はここに入る
154 -- *: jfm glue はここに入る
156 local head -- the head of current list
157 local last -- the last node of current list
158 local lp -- 外側での list 走査時のカーソル
161 local widow_Bp, widow_Np -- \jcharwidowpenalty 挿入位置管理用
163 local ihb_flag -- JFM グルー挿入抑止用 flag
164 -- on: \inhibitglue 指定時,hlist の周囲
166 -------------------- hlist 内の文字の検索
168 local first_char, last_char, find_first_char
170 local function check_box(box_ptr, box_end)
171 local p = box_ptr; local found_visible_node = false
173 find_first_char = false; first_char = nil; last_char = nil
176 while p and p~=box_end do
180 p = node_next(node_next(node_next(p))); pid = p.id
181 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
182 p = node_next(p); pid = p.id
185 if pid==id_glyph then
187 if find_first_char then
188 first_char = p; find_first_char = false
190 last_char = p; found_visible_node = true; p=node_next(p)
191 if (not p) or p==box_end then return found_visible_node end
194 if pid==id_hlist then
195 if has_attr(p, attr_icflag)==PACKED then
196 for q in node.traverse_id(id_glyph, p.head) do
197 if find_first_char then
198 first_char = q; find_first_char = false
200 last_char = q; found_visible_node = true; break
204 if check_box(p.head, nil) then found_visible_node = true end
205 else if find_first_char then
206 find_first_char = false
212 elseif not (pid==id_ins or pid==id_mark
213 or pid==id_adjust or pid==id_whatsit
214 or pid==id_penalty) then
215 found_visible_node = true
216 if find_first_char then
217 find_first_char = false
224 return found_visible_node
227 -------------------- Np の計算と情報取得
229 local function set_attr_icflag_processed(p)
230 local a = has_attr(p, attr_icflag) or 0
231 if a<=1 then set_attr(p, attr_icflag, PROCESSED) end
234 local function check_next_ickern()
235 if lp.id == id_kern and has_attr(lp, attr_icflag)==ITALIC then
236 set_attr(lp, attr_icflag, IC_PROCESSED); Np.last = lp; lp = node_next(lp)
237 else Np.last = Np.nuc end
240 local function calc_np_pbox()
241 Np.first = lp; Np.id = id_pbox
242 lpa = KINSOKU -- dummy
243 while lp~=last and lpa>=PACKED and lpa~=BOXBDD do
244 Np.nuc = lp; lp = node_next(lp); lpa = has_attr(lp, attr_icflag) or 0
249 local calc_np_auxtable = {
250 [id_glyph] = function()
252 if lp.font == has_attr(lp, attr_curjfnt) then
257 Np.first = lp; Np.nuc = lp; set_attr_icflag_processed(lp)
258 lp = node_next(lp); check_next_ickern(); return true
260 [id_hlist] = function()
261 Np.first = lp; Np.last = lp; Np.nuc = lp;
262 set_attr_icflag_processed(lp)
268 lp = node_next(lp); return true
270 [id_vlist] = function()
271 Np.first = lp; Np.nuc = lp; Np.last = lp;
272 Np.id = id_box_like; set_attr_icflag_processed(lp);
273 lp = node_next(lp); return true
275 [id_rule] = function()
276 Np.first = lp; Np.nuc = lp; Np.last = lp;
277 Np.id = id_box_like; set_attr_icflag_processed(lp);
278 lp = node_next(lp); return true
280 [id_ins] = function()
281 set_attr_icflag_processed(lp); lp = node_next(lp)
284 [id_mark] = function()
285 set_attr_icflag_processed(lp); lp = node_next(lp)
288 [id_adjust] = function()
289 set_attr_icflag_processed(lp); lp = node_next(lp)
292 [id_disc] = function()
293 Np.first = lp; Np.nuc = lp; set_attr_icflag_processed(lp);
294 Np.last = lp; Np.id = id_disc; lp = node_next(lp); return true
296 [id_whatsit] = function()
297 if lp.subtype==sid_user and lp.user_id==30111 then
298 local lq = node_next(lp)
299 head = node_remove(head, lp); node_free(lp); lp = lq; ihb_flag = true
301 set_attr_icflag_processed(lp); lp = node_next(lp)
305 [id_math] = function()
306 Np.first = lp; Np.nuc = lp;
307 set_attr_icflag_processed(lp); lp = node_next(lp)
308 while lp.id~=id_math do
309 set_attr_icflag_processed(lp); lp = node_next(lp)
311 set_attr_icflag_processed(lp);
312 Np.last = lp; Np.id = id_math; lp = node_next(lp);
315 [id_glue] = function()
316 Np.first = lp; Np.nuc = lp; set_attr_icflag_processed(lp);
317 Np.last = lp; Np.id = id_glue; lp = node_next(lp); return true
319 [id_kern] = function()
321 if lp.subtype==2 then
322 set_attr_icflag_processed(lp); lp = node_next(lp)
323 set_attr_icflag_processed(lp); lp = node_next(lp)
324 set_attr_icflag_processed(lp); lp = node_next(lp)
325 set_attr_icflag_processed(lp); Np.nuc = lp
326 if lp.font == has_attr(lp, attr_curjfnt) then
331 lp = node_next(lp); check_next_ickern();
333 Np.id = id_kern; set_attr_icflag_processed(lp);
334 Np.last = lp; lp = node_next(lp)
338 [id_penalty] = function()
339 Bp[#Bp+1] = lp; set_attr_icflag_processed(lp);
340 lp = node_next(lp); return false
343 Np.first = lp; Np.nuc = lp; Np.last = lp;
344 Np.id = id_box_like; set_attr_icflag_processed(lp);
345 lp = node_next(lp); return true
349 local function calc_np()
350 -- We assume lp = node_next(Np.last)
352 Nr = Nq; for k in pairs(Nr) do Nr[k] = nil end
354 for k in pairs(Bp) do Bp[k] = nil end
357 lpa = has_attr(lp, attr_icflag) or 0
359 if lpa == BOXBDD then
360 local lq = node_next(lp)
361 head = node_remove(head, lp); node_free(lp); lp = lq
362 else calc_np_pbox(); return end -- id_pbox
363 elseif calc_np_auxtable[lp.id]() then return end
368 -- extract informations from Np
369 -- We think that "Np is a Japanese character" if Np.met~=nil,
370 -- "Np is an alphabetic character" if Np.pre~=nil,
371 -- "Np is not a character" otherwise.
374 local function set_np_xspc_jachar(x)
375 local z = ltjf_font_metric_table[x.font]
377 local cls = ltjf_find_char_class(c, z)
378 local m = ltjf_metrics[z.jfm]
379 set_attr(x, attr_jchar_class, cls)
385 Np.pre = ltjs_get_penalty_table('pre', c, 0, box_stack_level)
386 Np.post = ltjs_get_penalty_table('post', c, 0, box_stack_level)
387 z = fast_find_char_class('lineend', m)
388 local y = m.size_cache[Np.size].char_type[Np.class]
389 if y.kern and y.kern[z] then
394 y = ltjs_get_penalty_table('xsp', c, 3, box_stack_level)
395 Np.xspc_before = (y%2==1)
396 Np.xspc_after = (y>=2)
397 Np.auto_kspc = (has_attr(x, attr_autospc)==1)
398 Np.auto_xspc = (has_attr(x, attr_autoxspc)==1)
402 local ligature_head = 1
403 local ligature_tail = 2
404 local function set_np_xspc_alchar(c,x, lig)
406 if lig == ligature_head then
407 while x.components and x.subtype and math.floor(x.subtype/2)%2==1 do
408 x = x.components; c = x.char
411 while x.components and x.subtype and math.floor(x.subtype/2)%2==1 do
412 x = node_tail(x.components); c = x.char
415 Np.pre = ltjs_get_penalty_table('pre', c, 0, box_stack_level)
416 Np.post = ltjs_get_penalty_table('post', c, 0, box_stack_level)
418 Np.pre = 0; Np.post = 0
421 local y = ltjs_get_penalty_table('xsp', c, 3, box_stack_level)
422 Np.xspc_before = (y%2==1)
423 Np.xspc_after = (y>=2)
424 Np.auto_xspc = (has_attr(x, attr_autoxspc)==1)
428 local function extract_np()
430 if Np.id == id_jglyph then
431 set_np_xspc_jachar(x)
432 elseif Np.id == id_glyph then
433 set_np_xspc_alchar(x.char, x, ligature_head)
434 elseif Np.id == id_hlist then
435 find_first_char = true; first_char = nil; last_char = nil
436 if check_box(x.head, nil) then
438 if first_char.font == has_attr(first_char, attr_curjfnt) then
439 set_np_xspc_jachar(first_char)
441 set_np_xspc_alchar(first_char.char,first_char, ligature_head)
445 elseif Np.id == id_pbox then -- mikann
446 find_first_char = true; first_char = nil; last_char = nil
447 if check_box(Np.first, node_next(Np.last)) then
449 if first_char.font == has_attr(first_char, attr_curjfnt) then
450 set_np_xspc_jachar(first_char)
452 set_np_xspc_alchar(first_char.char,first_char, ligature_head)
456 elseif Np.id == id_disc then
457 find_first_char = true; first_char = nil; last_char = nil
458 if check_box(x.replace, nil) then
460 if first_char.font == has_attr(first_char, attr_curjfnt) then
461 set_np_xspc_jachar(first_char)
463 set_np_xspc_alchar(first_char.char,first_char, ligature_head)
467 elseif Np.id == id_math then
468 set_np_xspc_alchar(-1, x)
472 -- change the information for the next loop
473 -- (will be done if Np is an alphabetic character or a hlist)
474 local function after_hlist()
476 if last_char.font == has_attr(last_char, attr_curjfnt) then
477 set_np_xspc_jachar(last_char, ligature_tail)
479 set_np_xspc_alchar(last_char.char,last_char, ligature_tail)
482 Np.pre = nil; Np.met = nil
485 local function after_alchar()
487 set_np_xspc_alchar(x.char,x, ligature_tail)
491 -------------------- 最下層の処理
493 local function lineend_fix(g)
494 if g and g.id==id_kern then
496 elseif Nq.lend~=0 then
498 g = node_new(id_kern); g.subtype = 1
499 g.kern = -Nq.lend; set_attr(g, attr_icflag, LINEEND)
500 elseif g.id==id_kern then
501 g.kern = g.kern - Nq.lend
503 g.spec.width = g.spec.width - Nq.lend
509 -- change penalties (or create a new penalty, if needed)
510 local function handle_penalty_normal(post, pre, g)
511 local a = (pre or 0) + (post or 0)
513 if (a~=0 and not(g and g.id==id_kern)) or Nq.lend~=0 then
514 local p = node_new(id_penalty)
515 if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
517 head = node_insert_before(head, Np.first, p)
518 table_insert(Bp, p); set_attr(p, attr_icflag, KINSOKU)
520 else for i, v in pairs(Bp) do add_penalty(v,a) end
524 local function handle_penalty_always(post, pre, g)
525 local a = (pre or 0) + (post or 0)
527 if not (g and g.id==id_glue) or Nq.lend~=0 then
528 local p = node_new(id_penalty)
529 if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
531 head = node_insert_before(head, Np.first, p)
532 table_insert(Bp, p); set_attr(p, attr_icflag, KINSOKU)
534 else for i, v in pairs(Bp) do add_penalty(v,a) end
538 local function handle_penalty_suppress(post, pre, g)
539 local a = (pre or 0) + (post or 0)
541 if g and g.id==id_glue then
542 local p = node_new(id_penalty)
543 p.penalty = 10000; head = node_insert_before(head, Np.first, p)
544 table_insert(Bp, p); set_attr(p, attr_icflag, KINSOKU)
546 else for i, v in pairs(Bp) do add_penalty(v,a) end
550 -- 和文文字間の JFM glue を node 化
551 local function new_jfm_glue(Nn, bc, ac)
552 -- bc, ac: char classes
554 local z = Nn.met.size_cache[Nn.size].char_type[bc]
555 if z.glue and z.glue[ac] then
556 local h = node_new(id_glue_spec)
557 h.width = z.glue[ac][1]
558 h.stretch = z.glue[ac][2]
559 h.shrink = z.glue[ac][3]
560 h.stretch_order=0; h.shrink_order=0
561 g = node_new(id_glue)
562 g.subtype = 0; g.spec = h
563 elseif z.kern and z.kern[ac] then
564 g = node_new(id_kern)
565 g.subtype = 1; g.kern = z.kern[ac]
567 if g then set_attr(g, attr_icflag, FROM_JFM) end
571 -- Nq.last (kern w) .... (glue/kern g) Np.first
572 local function real_insert(w, g)
574 local h = node_new(id_kern)
575 set_attr(h, attr_icflag, LINE_END)
576 h.kern = w; h.subtype = 1
577 head = node_insert_after(head, Nq.last, h)
580 head = node_insert_before(head, Np.first, g)
585 -------------------- 和文文字間空白量の決定
588 local function get_kanji_skip_from_jfm(Nn)
589 local i = Nn.met.size_cache[Nn.size].kanjiskip
591 return { i[1], i[2], i[3] }
595 local function get_kanjiskip()
596 local g = node_new(id_glue)
597 if Np.auto_kspc or Nq.auto_kspc then
598 if kanji_skip.width == max_dimen then
599 local gx = node_new(id_glue_spec);
600 gx.stretch_order = 0; gx.shrink_order = 0
601 local bk = get_kanji_skip_from_jfm(Nq)
603 if (Np.met==Nq.met) and (Nq.size==Np.size) and (Nq.var==Np.var) then
606 ak = get_kanji_skip_from_jfm(Np)
610 gx.width = round(diffmet_rule(bk[1], ak[1]))
611 gx.stretch = round(diffmet_rule(bk[2], ak[2]))
612 gx.shrink = -round(diffmet_rule(-bk[3], -ak[3]))
614 gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3]
617 gx.width = ak[1]; gx.stretch = ak[2]; gx.shrink = ak[3]
618 else node_free(gx); gx = get_zero_glue() -- fallback
621 else g.spec=node_copy(kanji_skip); node_free(gx) end
623 g.spec = get_zero_glue(); node_free(gx)
625 set_attr(g, attr_icflag, KANJI_SKIP)
629 local function calc_ja_ja_aux(gb,ga)
633 if not ga then return gb end
634 local k = node.type(gb.id) .. node.type(ga.id)
635 if k == 'glueglue' then
637 gb.spec.width = round(diffmet_rule(gb.spec.width, ga.spec.width))
638 gb.spec.stretch = round(diffmet_rule(gb.spec.stretch,ga.spec.shrink))
639 gb.spec.shrink = -round(diffmet_rule(-gb.spec.shrink, -ga.spec.shrink))
642 elseif k == 'kernkern' then
644 gb.kern = round(diffmet_rule(gb.kern, ga.kern))
647 elseif k == 'kernglue' then
648 -- gb: kern, ga: glue
649 ga.spec.width = round(diffmet_rule(gb.kern,ga.spec.width))
650 ga.spec.stretch = round(diffmet_rule(ga.spec.stretch, 0))
651 ga.spec.shrink = -round(diffmet_rule(-ga.spec.shrink, 0))
655 -- gb: glue, ga: kern
656 gb.spec.width = round(diffmet_rule(ga.kern, gb.spec.width))
657 gb.spec.stretch = round(diffmet_rule(gb.spec.stretch, 0))
658 gb.spec.shrink = -round(diffmet_rule(-gb.spec.shrink, 0))
665 local function calc_ja_ja_glue()
666 if ihb_flag then return nil
667 elseif (Nq.size==Np.size) and (Nq.met==Np.met) and (Nq.var==Np.var) then
668 return new_jfm_glue(Nq, Nq.class, Np.class)
670 local g = new_jfm_glue(Nq, Nq.class,
671 fast_find_char_class('diffmet',Nq.met))
672 local h = new_jfm_glue(Np, fast_find_char_class('diffmet',Np.met),
674 return calc_ja_ja_aux(g,h)
678 -------------------- 和欧文間空白量の決定
681 local function get_xkanji_skip_from_jfm(Nn)
682 local i = Nn.met.size_cache[Nn.size].xkanjiskip
684 return { i[1], i[2], i[3] }
688 local function get_xkanjiskip(Nn)
689 local g = node_new(id_glue)
690 if Nq.xspc_after and Np.xspc_before and (Nq.auto_xspc or Np.auto_xspc) then
691 if xkanji_skip.width == max_dimen then
692 local gx = node_new(id_glue_spec);
693 gx.stretch_order = 0; gx.shrink_order = 0
694 local bk = get_xkanji_skip_from_jfm(Nn)
696 gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3]
697 else node_free(gx); gx = get_zero_glue() -- fallback
700 else g.spec=node_copy(xkanji_skip) end
702 g.spec = get_zero_glue()
704 set_attr(g, attr_icflag, XKANJI_SKIP)
709 -------------------- 隣接した「塊」間の処理
711 local function get_OA_skip()
714 if Nq.id == id_math then c = -1 else c = 'jcharbdd' end
715 return new_jfm_glue(Np, fast_find_char_class(c,Np.met), Np.class)
719 local function get_OB_skip()
722 if Np.id == id_math then c = -1 else c = 'jcharbdd' end
723 return new_jfm_glue(Nq, Nq.class, fast_find_char_class(c,Nq.met))
728 -- (anything) .. jachar
729 local function handle_np_jachar()
731 if Nq.id==id_jglyph or (Nq.id==id_pbox and Nq.met) then
732 g = calc_ja_ja_glue() or get_kanjiskip() -- M->K
734 handle_penalty_normal(Nq.post, Np.pre, g); real_insert(Nq.lend, g)
735 elseif Nq.met then -- Nq.id==id_hlist
736 g = get_OA_skip() or get_kanjiskip() -- O_A->K
737 handle_penalty_normal(0, Np.pre, g); real_insert(0, g)
739 g = get_OA_skip() or get_xkanjiskip(Np) -- O_A->X
740 handle_penalty_normal(Nq.post, Np.pre, g); real_insert(0, g)
742 g = get_OA_skip() -- O_A
743 if Nq.id==id_glue then handle_penalty_normal(0, Np.pre, g)
744 elseif Nq.id==id_kern then handle_penalty_suppress(0, Np.pre, g)
745 else handle_penalty_always(0, Np.pre, g)
749 -- \jcharwidowpenalty 挿入予定箇所更新
750 if mode and ltjs_get_penalty_table('kcat', Np.char, 0, box_stack_level)%2~=1 then
751 widow_Np.first = Np.first;
752 local Bpr = widow_Bp; widow_Bp = Bp; Bp = Bpr
756 -- jachar .. (anything)
757 local function handle_nq_jachar()
760 g = get_OB_skip() or get_xkanjiskip(Nq) -- O_B->X
762 handle_penalty_normal(Nq.post, Np.pre, g); real_insert(Nq.lend, g)
764 g = get_OB_skip(); g = lineend_fix(g) -- O_B
765 if Np.id==id_glue then handle_penalty_normal(Nq.post, 0, g)
766 elseif Np.id==id_kern then handle_penalty_suppress(Nq.post, 0, g)
767 else handle_penalty_always(Nq.post, 0, g)
769 real_insert(Nq.lend, g)
773 -- (anything) .. (和文文字で終わる hlist)
774 local function handle_np_ja_hlist()
776 if Nq.id==id_jglyph or (Nq.id==id_pbox and Nq.met) then
777 g = get_OB_skip() or get_kanjiskip() -- O_B->K
779 handle_penalty_normal(Nq.post, 0, g); real_insert(Nq.lend, g)
780 elseif Nq.met then -- Nq.id==id_hlist
781 g = get_kanjiskip() -- K
782 handle_penalty_suppress(0, 0, g); real_insert(0, g)
784 g = get_xkanjiskip(Np) -- X
785 handle_penalty_suppress(0, 0, g); real_insert(0, g)
789 -- (和文文字で終わる hlist) .. (anything)
790 local function handle_nq_ja_hlist()
793 g = get_xkanjiskip(Nq) -- X
794 handle_penalty_suppress(0, 0, g); real_insert(0, g)
798 -------------------- 開始・終了時の処理
801 local function handle_list_tail()
804 -- the current list is to be line-breaked:
805 if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then
807 g = node_new(id_kern); g.subtype = 0; g.kern = Np.lend
808 set_attr(g, attr_icflag, BOXBDD)
809 node_insert_after(head, Np.last, g)
812 -- Insert \jcharwidowpenalty
813 Bp = widow_Bp; Np = widow_Np; Nq.lend = 0
815 handle_penalty_normal(0,
816 ltjs_get_penalty_table('jwp', 0, 0, box_stack_level))
819 -- the current list is the contents of a hbox
820 if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then
821 local g = new_jfm_glue(Np, Np.class, fast_find_char_class('boxbdd',Np.met))
823 set_attr(g, attr_icflag, BOXBDD)
824 head = node_insert_after(head, Np.last, g)
827 head = node_remove(head, last); node_free(last);-- remove the sentinel
829 node_free(kanji_skip); node_free(xkanji_skip)
833 local function handle_list_head()
834 if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then
838 g = new_jfm_glue(Np, fast_find_char_class('parbdd',Np.met), Np.class)
840 g = new_jfm_glue(Np, fast_find_char_class('boxbdd',Np.met), Np.class)
843 set_attr(g, attr_icflag, BOXBDD)
844 if g.id==id_glue and #Bp==0 then
845 local h = node_new(id_penalty)
846 h.penalty = 10000; set_attr(h, attr_icflag, BOXBDD)
848 head = node_insert_before(head, Np.first, g)
855 local function init_var()
856 lp = head; Bp = {}; widow_Bp = {}; widow_Np = {first = nil}
858 box_stack_level = ltjp.box_stack_level
859 kanji_skip=skip_table_to_spec('kanjiskip')
860 xkanji_skip=skip_table_to_spec('xkanjiskip')
862 auto_kspc=nil, auto_xspc=nil, char=nil, class=nil,
863 first=nil, id=nil, last=nil, lend=0, met=nil, nuc=nil,
864 post=nil, pre=nil, var=nil, xspc_after=nil, xspc_before=nil,
867 auto_kspc=nil, auto_xspc=nil, char=nil, class=nil,
868 first=nil, id=nil, last=nil, lend=0, met=nil, nuc=nil,
869 post=nil, pre=nil, var=nil, xspc_after=nil, xspc_before=nil,
872 -- the current list is to be line-breaked:
873 -- hbox from \parindent is skipped.
874 while lp and ((lp.id==id_whatsit and lp.subtype~=sid_user)
875 or ((lp.id==id_hlist) and (lp.subtype==3))) do
876 if (lp.id==id_hlist) and (lp.subtype==3) then par_indented = true end
880 -- the current list is the contents of a hbox:
881 -- insert a sentinelEG
882 last=node.tail(head); local g = node_new(id_kern)
883 node_insert_after(head, last, g); last = g
887 -------------------- 外部から呼ばれる関数
890 function main(ahead, amode)
891 if not ahead then return ahead end
892 head = ahead; mode = amode; init_var(); calc_np()
894 extract_np(); handle_list_head()
895 if Np.id==id_glyph then after_alchar()
896 elseif Np.id==id_hlist or Np.id==id_pbox or Np.id==id_disc then after_hlist()
899 if not mode then head = node_remove(head, last); node_free(last) end
906 if Np.id == id_jglyph then
909 if Np.id==id_hlist then handle_np_ja_hlist()
910 else handle_np_jachar() end
912 if Nq.id==id_hlist then handle_nq_ja_hlist()
913 else handle_nq_jachar() end
916 if Np.id==id_glyph then after_alchar()
917 elseif Np.id==id_hlist or Np.id==id_pbox or Np.id==id_disc then after_hlist()
922 -- adjust attr_icflag
923 tex.attribute[attr_icflag] = -(0x7FFFFFFF)
928 local inhibitglue_node=node_new(id_whatsit, sid_user)
929 inhibitglue_node.user_id=30111; inhibitglue_node.type=100; inhibitglue_node.value=1
931 function create_inhibitglue_node()
932 node.write(node.copy(inhibitglue_node))