- for q in node.traverse_id(id_glue, p.head) do
- local a, ic = get_stretched(q, go, gs), get_attr_icflag(q)
- --print(ic)
- if type(res[ic]) == 'number' then res[ic] = res[ic] + a
- else res[0] = res[0] + a
+ local head = p.head
+ 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 を共有しているが,
+ -- それはここでは望ましくないので,各 glue ごとに異なる spec を使う.
+ -- JFM グルーはそれぞれ異なる glue_spec を用いているので,問題ない.
+ res[ic] = res[ic] + a
+ if ic == KANJI_SKIP or ic == XKANJI_SKIP then
+ if q.spec ~= spec_zero_glue then
+ local ts, g;
+ q.spec, ts = node_copy(q.spec), q.spec
+ g = node.copy(q); q.spec = ts
+ node.insert_before(head, q, g);
+ head = node.remove(head, q); node.free(q); q = g
+ end
+ end
+ else
+ res[0] = res[0] + a
+ end