diff options
author | Norbert Preining <norbert@preining.info> | 2022-10-03 03:03:44 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-10-03 03:03:44 +0000 |
commit | 0ec122c100e39ea118fdb2c4b6223ece8053f439 (patch) | |
tree | d7077d4e42fc0d4e6f697738c3852c6967dd3b35 /macros/luatex/generic/luatexja/src/ltj-adjust.lua | |
parent | 097f244236b682cc77c6ecf25be4150091d8daf9 (diff) |
CTAN sync 202210030303
Diffstat (limited to 'macros/luatex/generic/luatexja/src/ltj-adjust.lua')
-rw-r--r-- | macros/luatex/generic/luatexja/src/ltj-adjust.lua | 142 |
1 files changed, 76 insertions, 66 deletions
diff --git a/macros/luatex/generic/luatexja/src/ltj-adjust.lua b/macros/luatex/generic/luatexja/src/ltj-adjust.lua index 053b63ab1a..89ad7816d2 100644 --- a/macros/luatex/generic/luatexja/src/ltj-adjust.lua +++ b/macros/luatex/generic/luatexja/src/ltj-adjust.lua @@ -12,21 +12,29 @@ luatexja.adjust = luatexja.adjust or {} local to_node = node.direct.tonode local to_direct = node.direct.todirect -local setfield = node.direct.setfield -local setglue = luatexja.setglue local getfield = node.direct.getfield local getlist = node.direct.getlist local getid = node.direct.getid local getfont = node.direct.getfont local getsubtype = node.direct.getsubtype +local getlang = node.direct.getlang +local getkern = node.direct.getkern +local getshift = node.direct.getshift +local getwidth = node.direct.getwidth +local getdepth = node.direct.getdepth +local setfield = node.direct.setfield +local setpenalty = node.direct.setpenalty +local setglue = node.direct.setglue +local setkern = node.direct.setkern +local setlist = node.direct.setlist local node_traverse_id = node.direct.traverse_id local node_new = node.direct.new local node_next = node.direct.getnext -local node_free = node.direct.free +local node_free = node.direct.flush_node or node.direct.free local node_prev = node.direct.getprev local node_tail = node.direct.tail -local has_attr = node.direct.has_attribute +local get_attr = node.direct.get_attribute local set_attr = node.direct.set_attribute local insert_after = node.direct.insert_after @@ -55,7 +63,7 @@ local get_attr_icflag do local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG get_attr_icflag = function(p) - return (has_attr(p, attr_icflag) or 0) % PROCESSED_BEGIN_FLAG + return (get_attr(p, attr_icflag) or 0) % PROCESSED_BEGIN_FLAG end end @@ -73,7 +81,7 @@ do for i=0,63 do tmp[#tmp+1] = { (i%8)-4, FROM_JFM+i } end else -- stretch for i=0,63 do tmp[#tmp+1] = { math.floor(i/8)-4, FROM_JFM+i } end - end + end local pt = priority_table[glue_sign] tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP } tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP_JFM } @@ -111,13 +119,13 @@ function get_total_stretched(p) for q in node_traverse_id(id_glue, ph) do local a = getfield(q, 'stretch_order') if a==0 then - local b = at2pr_st[get_attr_icflag(q)]; + local b = at2pr_st[get_attr_icflag(q)]; total_st[b] = total_st[b]+getfield(q, 'stretch') end total_st[a*65536] = total_st[a]+getfield(q, 'stretch') local a = getfield(q, 'shrink_order') if a==0 then - local b = at2pr_sh[get_attr_icflag(q)]; + local b = at2pr_sh[get_attr_icflag(q)]; total_sh[b] = total_sh[b]+getfield(q, 'shrink') end total_sh[a*65536] = total_sh[a]+getfield(q, 'shrink') @@ -130,7 +138,7 @@ function get_total_stretched(p) if not total_sh.order then total_sh.order, total_sh[-65536] = -1,0.1 -- dummy end - return getfield(p,'width') - dimensions(ph) + return getwidth(p) - dimensions(ph) end end @@ -152,7 +160,7 @@ local function aw_step1(p, total) -- 無限大のグルーで処理が行われているときは処理中止. return total, false end - if xi == id_glyph and getfield(x, 'lang')==lang_ja then + if xi == id_glyph and getlang(x)==lang_ja then -- 和文文字 xc = x elseif xi == id_hlist and get_attr_icflag(x) == PACKED then @@ -163,8 +171,8 @@ local function aw_step1(p, total) return total, false-- それ以外は対象外. 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 + .char_type[get_attr(xc, attr_jchar_class) or 0].end_adjust + if not eadt then return total, false end local eadt_ratio = {} @@ -176,8 +184,8 @@ local function aw_step1(p, total) eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v} end end - table.sort(eadt_ratio, - function (a,b) + 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 @@ -186,7 +194,7 @@ local function aw_step1(p, total) 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) + setkern(kn, eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND) insert_after(head, x, kn) return eadt_ratio[1][3], true else @@ -196,6 +204,7 @@ end -- step 1 最終行用 local min, max = math.min, math.max +local setsubtype = node.direct.setsubtype local function aw_step1_last(p, total) local head = getlist(p) local x = node_tail(head); if not x then return total, false end @@ -204,7 +213,7 @@ local function aw_step1_last(p, total) if getid(pf) ~= id_glue or getsubtype(pf) ~= 15 then return total, false end x = node_prev(node_prev(pf)) local xi, xc = getid(x) - if xi == id_glyph and getfield(x, 'lang')==lang_ja then + if xi == id_glyph and getlang(x)==lang_ja then -- 和文文字 xc = x elseif xi == id_hlist and get_attr_icflag(x) == PACKED then @@ -230,30 +239,30 @@ local function aw_step1_last(p, total) 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 + .char_type[get_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') + local pfw = getwidth(pf) + + (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 = total + getwidth(pf) 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') + 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') + 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) + setsubtype(pf, 1); setglue(pf) local eadt_ratio = {} for i, v in ipairs(eadt) do local t = total - v @@ -263,8 +272,8 @@ local function aw_step1_last(p, total) eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v} end end - table.sort(eadt_ratio, - function (a,b) + 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 @@ -273,7 +282,7 @@ local function aw_step1_last(p, total) 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) + setkern(kn, eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND) insert_after(head, x, kn) return eadt_ratio[1][3], true else @@ -289,9 +298,9 @@ local node_hpack = node.direct.hpack local function repack(p) local orig_of, orig_hfuzz, orig_hbad = tex.overfullrule, tex.hfuzz, tex.hbadness tex.overfullrule=0; tex.hfuzz=1073741823; tex.hbadness=10000 - local f = node_hpack(getlist(p), getfield(p, 'width'), 'exactly') + local f = node_hpack(getlist(p), getwidth(p), 'exactly') tex.overfullrule=orig_of; tex.hfuzz=orig_hfuzz; tex.hbadness=orig_hbad - setfield(f, 'head', nil) + setlist(f, nil) setfield(p, 'glue_set', getfield(f, 'glue_set')) setfield(p, 'glue_order', getfield(f, 'glue_order')) setfield(p, 'glue_sign', getfield(f, 'glue_sign')) @@ -328,14 +337,14 @@ function aw_step2(p, total, added_flag) local id = (total>0) and 1 or 2 local res = total_stsh[id] local pnum = priority_num[id] - if total==0 or res.order > 0 then + if total==0 or res.order > 0 then -- もともと伸縮の必要なしか,残りの伸縮量は無限大 if added_flag then return repack(p) end end total = abs(total) for i = 1, pnum do if total <= res[i] then - local a = at2pr[id] + local a = at2pr[id] for j = i+1,pnum do clear_stretch(p, j, a, name) end @@ -353,32 +362,32 @@ do local insert_before = node.direct.insert_before local KINSOKU = luatexja.icflag_table.KINSOKU insert_lineend_kern = function (head, nq, np, Bp) - if nq.met then + if nq.met then local eadt = nq.met.char_type[nq.class].end_adjust if not eadt then return end if eadt[1]~=0 then local x = node_new(id_kern, 1) - setfield(x, 'kern', eadt[1]); set_attr(x, attr_icflag, LINEEND) + setkern(x, eadt[1]); set_attr(x, attr_icflag, LINEEND) insert_before(head, np.first, x) end local eadt_num = #eadt for i=2,eadt_num do local x = node_new(id_penalty) - setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU) + setpenalty(x, 0); set_attr(x, attr_icflag, KINSOKU) insert_before(head, np.first, x); Bp[#Bp+1] = x local x = node_new(id_kern, 1) - setfield(x, 'kern', eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND) + setkern(x, eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND) insert_before(head, np.first, x) end if eadt_num>1 or eadt[1]~=0 then local x = node_new(id_penalty) - setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU) + setpenalty(x, 0); set_attr(x, attr_icflag, KINSOKU) insert_before(head, np.first, x); Bp[#Bp+1] = x local x = node_new(id_kern, 1) - setfield(x, 'kern', -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND) + setkern(x, -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND) insert_before(head, np.first, x) local x = node_new(id_penalty) - setfield(x, 'penalty', 10000); set_attr(x, attr_icflag, KINSOKU) + setpenalty(x, 10000); set_attr(x, attr_icflag, KINSOKU) insert_before(head, np.first, x); Bp[#Bp+1] = x end end @@ -389,7 +398,6 @@ local adjust_width do local myaw_step1, myaw_step2, myaw_step1_last local dummy = function(p,t,n) return t, false end - local ltjs_fast_get_stack_skip = ltjs.fast_get_stack_skip function adjust_width(head) if not head then return head end local last_p @@ -408,7 +416,7 @@ do local function enable_cb(status_le, status_pr, status_lp, status_ls) if (status_le>0 or status_pr>0) and (not is_reg) then ltjb.add_to_callback('post_linebreak_filter', - adjust_width, 'Adjust width', + adjust_width, 'Adjust width', luatexbase.priority_in_callback('post_linebreak_filter', 'ltj.lineskip')-1) is_reg = true elseif is_reg and (status_le==0 and status_pr==0) then @@ -493,28 +501,26 @@ luatexja.unary_pars.profile_hgap_factor = function(t) return luatexja.adjust.profile_hgap_factor end do - local insert = table.insert + local insert, texget = table.insert, tex.get local rangedimensions, max = node.direct.rangedimensions, math.max local function profile_inner(box, range, ind, vmirrored, adj) - local w_acc, d_before = getfield(box,'shift'), 0 + local w_acc, d_before = getshift(box), 0 local x = getlist(box); local xn = node_next(x) while x do local w, h, d - if xn then w, h, d= rangedimensions(box,x,xn) - else w, h, d= rangedimensions(box,x) end + if xn then w, h, d = rangedimensions(box,x,xn) + else w, h, d = rangedimensions(box,x) end if vmirrored then h=d end local w_new = w_acc + w - if w>=0 then - range:insert(ind, h, w_acc-adj, w_new) - else - range:insert(ind, h, w_new-adj, w_acc) + if w>=0 then range:insert(ind, h, w_acc-adj, w_new) + else range:insert(ind, h, w_new-adj, w_acc) end w_acc = w_new; x = xn; if x then xn = node_next(x) end end - end + end function ltjl.p_profile(before, after, mirrored, bw) - local range, tls - = init_range(), luatexja.adjust.profile_hgap_factor*tex.get('lineskip', false) + local range, tls + = init_range(), luatexja.adjust.profile_hgap_factor*texget('lineskip', false) profile_inner(before, range, 3, true, tls) profile_inner(after, range, 4, mirrored, tls) range = range:flatten() @@ -527,8 +533,8 @@ do if bw-h-d<lmin then lmin=bw-h-d end end if lmin==1/0 then lmin = bw end - return lmin, - bw - lmin - getfield(before, 'depth') + return lmin, + bw - lmin - getdepth(before) - getfield(after, mirrored and 'depth' or 'height') end end @@ -536,7 +542,7 @@ end do local ltja = luatexja.adjust - local copy_glue = ltjl.copy_glue + local copy_glue, texget = ltjl.copy_glue, tex.get local floor, max = math.floor, math.max function ltjl.l_step(dist, g, adj, normal, bw, loc) if loc=='alignment' then @@ -544,7 +550,7 @@ do end if dist < tex.lineskiplimit then local f = max(1, bw*ltja.step_factor) - copy_glue(g, 'baselineskip', 1, normal - f * floor((dist-tex.get('lineskip', false))/f)) + copy_glue(g, 'baselineskip', 1, normal - f * floor((dist-texget('lineskip', false))/f)) else copy_glue(g, 'baselineskip', 2, normal) end @@ -556,13 +562,15 @@ do local sid_user = node.subtype 'user_defined' local node_remove = node.direct.remove local node_write = node.direct.write + local getvalue = node.direct.getdata + local setvalue = node.direct.setdata local GHOST_JACHAR = luatexbase.newuserwhatsitid('ghost of a jachar', 'luatexja') luatexja.userid_table.GHOST_JACHAR = GHOST_JACHAR function ltja.create_ghost_jachar_node(cl) local tn = node_new(id_whatsit, sid_user) setfield(tn, 'user_id', GHOST_JACHAR) setfield(tn, 'type', 100) - setfield(tn, 'value', cl) + setvalue(tn, cl) node_write(tn) end local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] @@ -570,19 +578,21 @@ do local dir_tate = luatexja.dir_table.dir_tate local get_dir_count = ltjd.get_dir_count local ltjf_font_metric_table = ltjf.font_metric_table + local has_attr = node.direct.has_attribute local function get_current_metric(n) - local fn = has_attr(n, (get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt) + local fn = get_attr(n, (get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt) return fn and ltjf_font_metric_table[fn] end local function whatsit_callback(Np, lp, Nq) if Np and Np.nuc then return Np elseif Np and getfield(lp, 'user_id') == GHOST_JACHAR then Np.first = lp; Np.nuc = lp; Np.last = lp; Np.class = 0 - if getfield(lp,'value')<2 then + if getvalue(lp)<2 then if Nq and Nq.met then Np.met = Nq.met; else Np.met = get_current_metric(lp) end Np.pre = 0; Np.post = 0; Np.xspc = 3 else Np.met, Np.pre = nil, nil; end - Np.auto_kspc, Np.auto_xspc = (has_attr(lp, attr_autospc)==1), (has_attr(lp, attr_autoxspc)==1) + Np.auto_kspc, Np.auto_xspc + = not has_attr(lp, attr_autospc, 0), not has_attr(lp, attr_autoxspc, 0) return Np else return Np end end @@ -590,7 +600,7 @@ do if not s and getfield(Nq.nuc, 'user_id') == GHOST_JACHAR then local x, y = node_prev(Nq.nuc), Nq.nuc Nq.first, Nq.nuc, Nq.last = x, x, x - if getfield(y,'value')%2==0 then + if getvalue(y)%2==0 then if Np and Nq.met then Nq.met = Np.met; else Nq.met = get_current_metric(y) end Nq.pre = 0; Nq.post = 0; Nq.xspc = 3 else Nq.met, Nq.pre = nil, nil; end |