- return false-- それ以外は対象外.
- end
- local xk = ltjf_font_metric_table --
- [xc.font].size_cache.char_type[has_attr(xc, attr_jchar_class) or 0]
- ['end_' .. res.name] or 0
- --print(res.name, total, xk, unicode.utf8.char(xc.char))
-
- if xk>0 and total>=xk then
- --print("ADDED")
- total = total - xk
- local kn = node.new(id_kern)
- kn.kern = (res.name=='shrink' and -1 or 1) * xk
- set_attr(kn, attr_icflag, FROM_JFM)
- node.insert_after(p.head, x, kn)
- return true
- else return false
+ return total, false-- それ以外は対象外.
+ end
+ -- 続行条件1:無限の伸縮度を持つグルーは \parfillskipのみ
+ if total>0 and total_st.order>0 then
+ if total_st.order ~= getfield(pf, 'stretch_order') then return total, false end
+ if total_st[total_st.order*65536] ~= getfield(pf, 'stretch') then return total, false end
+ for i=total_st.order-1, 1, -1 do
+ if total_st[i*65536] ~= 0 then return total, false end
+ end
+ end
+ if total<0 and total_sh.order>0 then
+ if total_sh.order ~= getfield(pf, 'shrink_order') then return total, false end
+ if total_sh[total_sh.order*65536] ~= getfield(pf, 'shrink') then return total, false end
+ for i=total_sh.order-1, 1, -1 do
+ if total_sh[i*65536] ~= 0 then return total, false end
+ end
+ end
+ local eadt = ltjf_font_metric_table[getfont(xc)]
+ .char_type[has_attr(xc, attr_jchar_class) or 0].end_adjust
+ if not eadt then
+ return total, false
+ end
+ -- 続行条件2: min(eadt[1], 0)<= \parfillskip <= max(eadt[#eadt], 0)
+ local pfw = getfield(pf, 'width')
+ + (total>0 and getfield(pf, 'stretch') or -getfield(pf, 'shrink')) *getfield(p, 'glue_set')
+ if pfw<min(0,eadt[1]) or max(0,eadt[#eadt])<pfw then return total, false end
+ -- \parfillskip を 0 にする
+ total = total + getfield(pf, 'width')
+ total_st.order, total_sh.order = 0, 0
+ if getfield(pf, 'stretch_order')==0 then
+ local i = at2pr_st[-1]
+ total_st[0] = total_st[0] - getfield(pf, 'stretch')
+ total_st[i] = total_st[i] - getfield(pf, 'stretch')
+ total_st.order = (total_st[0]==0) and -1 or 0
+ end
+ if getfield(pf, 'shrink_order')==0 then
+ local i = at2pr_sh[-1]
+ total_sh[0] = total_sh[0] - getfield(pf, 'shrink')
+ total_sh[i] = total_sh[i] - getfield(pf, 'shrink')
+ total_sh.order = (total_sh[0]==0) and -1 or 0
+ end
+ setfield(pf, 'subtype', 1); setglue(pf)
+ local eadt_ratio = {}
+ for i, v in ipairs(eadt) do
+ local t = total - v
+ if t>0 then
+ eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v}
+ else
+ eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v}
+ end
+ end
+ table.sort(eadt_ratio,
+ function (a,b)
+ for i=2,4 do
+ local at, bt = abs(a[i]), abs(b[i])
+ if at~=bt then return at<bt end
+ end
+ return a[4]<b[4]
+ end)
+ if eadt[eadt_ratio[1][1]]~=0 then
+ local kn = node_new(id_kern, 1)
+ setfield(kn, 'kern', eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND)
+ insert_after(head, x, kn)
+ return eadt_ratio[1][3], true
+ else
+ return total, false