- if gs ~= 1 and gs ~= 2 then return res end
- q = p.head
- --luatexja.ext_show_node_list(p.head, '>>> ', print)
- while q do
- if q.id==id_glue then
- local a, ic = get_stretched(q, go, gs), get_attr_icflag(q)
- if type(res[ic]) == 'number' then
- -- kanjiskip, xkanjiskip は段落内で spec を共有しているが,
- -- それはここでは望ましくないので,
- -- 各行ごとに異なる spec を使うようにする.
- -- JFM グルーはそれぞれ異なる glue_spec を用いているので,問題ない.
- res[ic] = res[ic] + a
- if ic == KANJI_SKIP then
- q.spec = node_copy(q.spec)
- elseif ic == XKANJI_SKIP then
- q.spec = node_copy(q.spec)
- end
- else
- res[0] = res[0] + a
- end
+ res[0], res.glue_set, res.name = 0, gf, (gs==1) and 'stretch' or 'shrink'
+ for i=1,#priority_table do res[priority_table[i]]=0 end
+ if gs ~= 1 and gs ~= 2 then return res, 0 end
+ local total = 0
+ for q in node_traverse_id(id_glue, getlist(p)) do
+ local a, ic = get_stretched(q, go, gs), get_attr_icflag(q)
+ if ic == KANJI_SKIP_JFM then ic = KANJI_SKIP
+ elseif ic == XKANJI_SKIP_JFM then ic = XKANJI_SKIP
+ end
+ if type(res[ic]) == 'number' then
+ -- kanjiskip, xkanjiskip は段落内で spec を共有しているが,
+ -- それはここでは望ましくないので,各 glue ごとに異なる spec を使う.
+ -- 本当は各行ごとに glue_spec を共有させたかったが,安直にやると
+ -- ref_count が 0 なので Double-free が発生する.どうする?
+ -- JFM グルーはそれぞれ異なる glue_spec を用いているので,問題ない.
+ if (ic == KANJI_SKIP or ic == XKANJI_SKIP) and getsubtype(q)==0 then
+ local qs = getfield(q, 'spec')
+ if is_zero_glue(q) then
+ if (gs_used_line[qs] or 0)<line then
+ setfield(q, 'spec', node_copy(qs))
+ local f = node_new(id_glue); setfield(f, 'spec', qs); node_free(f)
+ -- decrese qs's reference count
+ else
+ gs_used_line[qs] = line
+ end
+ end
+ end
+ res[ic], total = res[ic] + a, total + a
+ else
+ res[0], total = res[0] + a, total + a