From 230fe59e35208b77a89adf5a05e0b133bd1703a3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 5 Sep 2016 22:04:44 +0000 Subject: luatexja (5sep16) git-svn-id: svn://tug.org/texlive/trunk@41995 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/luatex/luatexja/addons/luatexja-adjust.sty | 41 +- Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua | 2 +- .../texmf-dist/tex/luatex/luatexja/ltj-adjust.lua | 472 ++++++++++++++------- .../tex/luatex/luatexja/ltj-direction.lua | 22 +- .../texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua | 40 +- .../texmf-dist/tex/luatex/luatexja/ltj-jfont.lua | 43 +- Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua | 4 +- Master/texmf-dist/tex/luatex/luatexja/luatexja.lua | 30 +- .../tex/luatex/luatexja/patches/lltjcore.sty | 2 +- 9 files changed, 476 insertions(+), 180 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty b/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty index c14c52e93ca..be15fbba183 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty +++ b/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty @@ -68,6 +68,7 @@ \fi % % Load core module if not yet. +% xkeyval.sty is already required in luatexja.sty. \ifx\luatexjacoreLoaded\@undefined \ifltj@in@latex %<*LaTeX> \RequirePackage{luatexja}[2016/05/15] @@ -90,13 +91,41 @@ \RequireLuaTeXjaSubmodule{adjust_85} \fi -% enable/disable ``advanced'' line adjustment -\protected\def\ltjdisableadjust{\directlua{luatexja.adjust.disable_cb()}} -\protected\def\ltjenableadjust{\directlua{luatexja.adjust.enable_cb()}} + +\newcount\ltjadj@status@le +\newcount\ltjadj@status@pr +\let\ltj@adjust@temp=\relax +\define@choicekey[ltj]{adjust}{lineend}[\@@temp\ltj@adjust@temp]% +{false,true,extended}[true]{% + \ifnum\ltj@adjust@temp=-1 \else\ltjadj@status@le=\ltj@adjust@temp\fi\relax} +\define@boolkey[ltj]{adjust}{priority}[true]{% + \ltjadj@status@pr=\ifltj@adjust@priority1\else0\fi\relax} +\protected\def\@@ltjenableadjust[#1]{% + \setkeys[ltj]{adjust}{#1}% + \directlua{luatexja.adjust.enable_cb(\the\ltjadj@status@le, \the\ltjadj@status@pr)}\ignorespaces +} +\protected\def\ltjdisableadjust{\ltjenableadjust[lineend=false,priority=false]} +\protected\def\ltjenableadjust{% + \ltx@ifnextchar[{\@@ltjenableadjust}{\@@ltjenableadjust[lineend,priority]}}%] + \ltjenableadjust -% there is also a key for \ltjsetparameter, for same effect -\define@boolkey[ltj]{japaram}{adjust}[true]{% - \ifltj@japaram@adjust\ltjenableadjust\else\ltjdisableadjust\fi + +%%% 優先順位の設定 +\define@key[ltj]{adjpri}{kanjiskip}{% + \directlua{luatexja.adjust.priority_table[\the\count@][1] = token.scan_int()}#1\relax} +\define@key[ltj]{adjpri}{xkanjiskip}{% + \directlua{luatexja.adjust.priority_table[\the\count@][2] = token.scan_int()}#1\relax} +\define@key[ltj]{adjpri}{others}{% + \directlua{luatexja.adjust.priority_table[\the\count@][3] = token.scan_int()}#1\relax} +\define@key[ltj]{japaram}{stretch_priority}{% + \begingroup\count@=1 \setkeys[ltj]{adjpri}{#1}\relax + \directlua{luatexja.adjust.make_priority_table(1)}\endgroup} +\define@key[ltj]{japaram}{shrink_priority}{% + \begingroup\count@=2 \setkeys[ltj]{adjpri}{#1}\relax + \directlua{luatexja.adjust.make_priority_table(2)}\endgroup} +\ltjsetparameter{% + stretch_priority={kanjiskip=-35, xkanjiskip=-25, others=50}, + shrink_priority={kanjiskip=-35, xkanjiskip=-25, others=50}, } diff --git a/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua b/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua index a0d1675e127..72c1e9c6f8d 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua @@ -92,7 +92,7 @@ luatexja.jfont.define_jfm { align = 'left', left = 0.0, down = 0.0, width = 0.5, height = 0.88, depth = 0.12, italic=0.0, glue = { --- 3 は.75, 2, 4 は0, あとは0.5 + -- 3 は.75, 2, 4 は0, あとは0.5 [0] = { 0.5 , 0.0, 0.5, ratio=0, kanjiskip_stretch=1 }, [1] = { 0.5 , 0.0, 0.5, ratio=0, kanjiskip_stretch=1 }, [3] = { 0.75, 0.0, 0.25, priority=1, ratio=1./3, kanjiskip_stretch=1 }, diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua index 821099da607..7131bbc7b77 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua @@ -5,6 +5,7 @@ luatexja.load_module('jfont'); local ltjf = luatexja.jfont luatexja.load_module('jfmglue'); local ltjj = luatexja.jfmglue luatexja.load_module('stack'); local ltjs = luatexja.stack luatexja.load_module('direction'); local ltjd = luatexja.direction +luatexja.adjust = luatexja.adjust or {} local to_node = node.direct.tonode local to_direct = node.direct.todirect @@ -12,7 +13,6 @@ local to_direct = node.direct.todirect local setfield = node.direct.setfield local setglue = luatexja.setglue local getfield = node.direct.getfield -local is_zero_glue = node.direct.is_zero_glue local getlist = node.direct.getlist local getid = node.direct.getid local getfont = node.direct.getfont @@ -20,8 +20,6 @@ local getsubtype = node.direct.getsubtype local node_traverse_id = node.direct.traverse_id local node_new = node.direct.new -local node_copy = node.direct.copy -local node_hpack = node.direct.hpack local node_next = node.direct.getnext local node_free = node.direct.free local node_prev = node.direct.getprev @@ -35,30 +33,22 @@ local id_kern = node.id('kern') local id_hlist = node.id('hlist') local id_glue = node.id('glue') local id_whatsit = node.id('whatsit') +local id_penalty = node.id('penalty') local attr_icflag = luatexbase.attributes['ltj@icflag'] local attr_jchar_class = luatexbase.attributes['ltj@charclass'] local lang_ja = luatexja.lang_ja local ltjf_font_metric_table = ltjf.font_metric_table -local round, pairs = tex.round, pairs +local ipairs, pairs = ipairs, pairs local PACKED = luatexja.icflag_table.PACKED +local LINEEND = luatexja.icflag_table.LINEEND local FROM_JFM = luatexja.icflag_table.FROM_JFM local KANJI_SKIP = luatexja.icflag_table.KANJI_SKIP local KANJI_SKIP_JFM = luatexja.icflag_table.KANJI_SKIP_JFM local XKANJI_SKIP = luatexja.icflag_table.XKANJI_SKIP local XKANJI_SKIP_JFM = luatexja.icflag_table.XKANJI_SKIP_JFM -local priority_table = { - FROM_JFM + 2, - FROM_JFM + 1, - FROM_JFM, - FROM_JFM - 1, - FROM_JFM - 2, - XKANJI_SKIP, - KANJI_SKIP -} - local get_attr_icflag do local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG @@ -67,89 +57,99 @@ do end end --- box 内で伸縮された glue の合計値を計算 - -local function get_stretched(q, go, gs) - if gs == 1 then -- stretching - if getfield(q, 'stretch_order') == go then - return getfield(q, 'stretch') - else return 0 - end - else -- shrinking - if getfield(q, 'shrink_order') == go then - return getfield(q, 'shrink') - else return 0 +local priority_num = { 0, 0 } +local at2pr = { {}, {} } +local at2pr_st, at2pr_sh = at2pr[1], at2pr[2] +do + local priority_table = {{},{}} + luatexja.adjust.priority_table = priority_table + local tmp = {} + local function cmp(a,b) return a[1]>b[1] end -- 大きいほうが先! + local function make_priority_table(glue_sign) + for i,_ in pairs(tmp) do tmp[i]=nil end + if glue_sign==2 then -- shrink + 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 + local pt = priority_table[glue_sign] + tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP } + tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP_JFM } + tmp[#tmp+1] = { pt[1]/10, KANJI_SKIP } + tmp[#tmp+1] = { pt[1]/10, KANJI_SKIP_JFM } + tmp[#tmp+1] = { pt[3]/10, -1 } + table.sort(tmp, cmp) + local a, m, n = at2pr[glue_sign], 10000000, 0 + for i=1,#tmp do + if tmp[i][1] + local ph = getlist(p) + if not ph then return 0 end + for i,_ in pairs(total_st) do total_st[i]=nil; total_sh[i]=nil end + for i=1,priority_num[1] do total_st[i]=0 end + for i=1,priority_num[2] do total_sh[i]=0 end + for i=0,4 do total_st[i*65536]=0; total_sh[i*65536]=0 end + 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)]; + total_st[b] = total_st[b]+getfield(q, 'stretch') end - if type(res[ic]) == 'number' then - res[ic], total = res[ic] + a, total + a - else - res[0], total = res[0] + a, total + a + 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)]; + total_sh[b] = total_sh[b]+getfield(q, 'shrink') end + total_sh[a*65536] = total_sh[a]+getfield(q, 'shrink') end - return res, total -end - -local function clear_stretch(p, ic, name) - for q in node_traverse_id(id_glue, getlist(p)) do - local f = get_attr_icflag(q) - if (f == ic) or ((ic ==KANJI_SKIP) and (f == KANJI_SKIP_JFM)) - or ((ic ==XKANJI_SKIP) and (f == XKANJI_SKIP_JFM)) then - setfield(q, name..'_order', 0) - setfield(q, name, 0) - end + for i=4,1,-1 do if total_st[i*65536]~=0 then total_st.order=i; break end; end + if not total_st.order then + total_st.order, total_st[-65536] = -1,0.1 -- dummy end -end - -local function set_stretch(p, after, before, ic, name) - if before > 0 then - local ratio = after/before - for q in node_traverse_id(id_glue, getlist(p)) do - local f = get_attr_icflag(q) - if (f == ic) or ((ic ==KANJI_SKIP) and (f == KANJI_SKIP_JFM)) - or ((ic ==XKANJI_SKIP) and (f == XKANJI_SKIP_JFM)) then - if getfield(q, name..'_order')==0 then - setfield(q, name, getfield(q, name)*ratio) - end - end - end + for i=4,1,-1 do if total_sh[i*65536]~=0 then total_sh.order=i; break end; end + if not total_sh.order then + total_sh.order, total_sh[-65536] = -1,0.1 -- dummy end + return getfield(p,'width') - dimensions(ph) +end end -- step 1: 行末に kern を挿入(句読点,中点用) +local abs = math.abs local ltjd_glyph_from_packed = ltjd.glyph_from_packed -local function aw_step1(p, res, total) +local function aw_step1(p, total) local head = getlist(p) - local x = node_tail(head); if not x then return false end + local x = node_tail(head); if not x then return total, false end -- x: \rightskip - x = node_prev(x); if not x then return false end + x = node_prev(x); if not x then return total, false end local xi, xc = getid(x) - if xi == id_glue and getsubtype(x) == 15 then - -- 段落最終行のときは,\penalty10000 \parfillskip が入るので, - -- その前の node が本来の末尾文字となる - x = node_prev(node_prev(x)); xi = getid(x) - end - -- local xi = getid(x) - -- while (get_attr_icflag(x) == PACKED) - -- and ((xi == id_penalty) or (xi == id_kern) or (xi == id_kern)) do - -- x = node_prev(x); xi = getid(x) - -- end + -- x may be penalty + while xi==id_penalty do + x = node_prev(x); if not x then return total, false end + xi = getid(x) + end + if (total>0 and total_st.order>0) or (total<0 and total_sh.order>0) then + -- 無限大のグルーで処理が行われているときは処理中止. + return total, false + end if xi == id_glyph and getfield(x, 'lang')==lang_ja then -- 和文文字 xc = x @@ -158,96 +158,280 @@ local function aw_step1(p, res, total) xc = ltjd_glyph_from_packed(x) while getid(xc) == id_whatsit do xc = node_next(xc) end -- これはなんのために? else - return false-- それ以外は対象外. + 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 + return total, false + end + 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 at0 and total>=xk then - total = total - xk - local kn = node_new(id_kern) - setfield(kn, 'kern', (res.name=='shrink' and -1 or 1) * xk) - set_attr(kn, attr_icflag, FROM_JFM) +-- step 1 最終行用 +local min, max = math.min, math.max +local function aw_step1_last(p, total) + local head = getlist(p) + local x = node_tail(head); if not x then return total, false end + -- x: \rightskip + pf = node_prev(x); if not x then return total, false end + if getid(pf) ~= id_glue or getsubtype(pf) ~= 15 then return total, false end + x = node_prev(node_prev(pf)); xi = getid(x) + local xi, xc = getid(x) + if xi == id_glyph and getfield(x, 'lang')==lang_ja then + -- 和文文字 + xc = x + elseif xi == id_hlist and get_attr_icflag(x) == PACKED then + -- packed JAchar + xc = ltjd_glyph_from_packed(x) + while getid(xc) == id_whatsit do xc = node_next(xc) end -- これはなんのために? + else + 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 pfw0 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 0 then + local ratio = after/before + for q in node_traverse_id(id_glue, getlist(p)) do + local f = ap[get_attr_icflag(q)] + if (f==ind) and getfield(q, name..'_order')==0 then + setfield(q, name, getfield(q, name)*ratio) end - total = total - res[v] end - local f = node_hpack(getlist(p), getfield(p, 'width'), 'exactly') - setfield(f, 'head', 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')) - node_free(f) end end +function aw_step2(p, total, added_flag) + local name = (total>0) and 'stretch' or 'shrink' + 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 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] + for j = i+1,pnum do + clear_stretch(p, j, a, name) + end + set_stretch(p, total, res[i], i, a, name); break + end + total = total - res[i] + end + return repack(p) +end +end -local ltjs_fast_get_stack_skip = ltjs.fast_get_stack_skip -local function adjust_width(head) - if not head then return head end - local line = 1 - for p in node_traverse_id(id_hlist, to_direct(head)) do - line = line + 1 - local res, total = get_total_stretched(p, line) - -- this is the same table as the table which is def'd in l. 92 - if res and res.glue_set<1 then - total = round(total * res.glue_set) - aw_step2(p, res, total, aw_step1(p, res, total)) +-- step 1': lineend=extended の場合(行分割時に考慮)) +local insert_lineend_kern +do + local insert_before = node.direct.insert_before + local KINSOKU = luatexja.icflag_table.KINSOKU + function insert_lineend_kern(head, nq, np, Bp) + 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) + 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) + 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) + 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) + 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) + insert_before(head, np.first, x) + local x = node_new(id_penalty) + setfield(x, 'penalty', 10000); set_attr(x, attr_icflag, KINSOKU) + insert_before(head, np.first, x); Bp[#Bp+1] = x + end end end - return to_node(head) end +local adjust_width do - luatexja.adjust = luatexja.adjust or {} + local myaw_atep1, 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 + for p in node_traverse_id(id_hlist, to_direct(head)) do + if last_p then + myaw_step2(last_p, myaw_step1(last_p, get_total_stretched(last_p))) + end + last_p = p + end + if last_p then + myaw_step2(last_p, myaw_step1_last(last_p, get_total_stretched(last_p))) + end + return to_node(head) + end local is_reg = false - function luatexja.adjust.enable_cb() - if not is_reg then + function enable_cb(status_le, status_pr) + if (status_le>0 or status_pr>0) and (not is_reg) then luatexbase.add_to_callback('post_linebreak_filter', adjust_width, 'Adjust width', 100) is_reg = true - end - end - function luatexja.adjust.disable_cb() - if is_reg then + elseif is_reg and (status_le==0 and status_pr==0) then luatexbase.remove_from_callback('post_linebreak_filter', 'Adjust width') is_reg = false end + if status_le==2 then + if not luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then + luatexbase.add_to_callback('luatexja.adjust_jfmglue', insert_lineend_kern, 'luatexja.adjust') + end + myaw_step1, myaw_step1_last = dummy, aw_step1_last + else + if status_le==0 then + myaw_step1, myaw_step1_last = dummy, dummy + else + myaw_step1, myaw_step1_last = aw_step1, aw_step1_last + end + if luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then + luatexbase.remove_from_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') + end + end + myaw_step2 = (status_pr>0) and aw_step2 or aw_step2_dummy + end + function disable_cb() -- only for compatibility + enable_cs(0) end + luatexja.adjust.enable_cb=enable_cb + luatexja.adjust.disable_cb=disable_cb end luatexja.unary_pars.adjust = function(t) diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua index 8a2af68374c..61d081929de 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua @@ -266,15 +266,22 @@ end -- hpack_filter, vpack_filter, post_line_break_filter -- の結果を組方向を明示するため,先頭に dir_node を設置 +local get_box_dir do local function create_dir_whatsit_hpack(h, gc) local hd = to_direct(h) - if gc=='fin_row' or gc == 'preamble' then + if gc=='fin_row' then if hd then + for p in traverse_id(15, hd) do -- unset + if get_box_dir(p, 0)==0 then + setfield(p, 'head', create_dir_whatsit(getlist(p), 'fin_row', ltjs.list_dir)) + end + end set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG) ensure_tex_attr(attr_icflag, 0) end return h + elseif gc == 'preamble' then else adjust_badness(hd) return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir)) @@ -287,7 +294,7 @@ end do local function create_dir_whatsit_parbox(h, gc) - stop_time_measure('tex_linebreak') + stop_time_measure('tex_linebreak'); -- start 側は ltj-debug.lua に local new_dir = ltjs.list_dir for line in traverse_id(id_hlist, to_direct(h)) do @@ -490,7 +497,7 @@ end -- 1st ret val: b の組方向 -- 2nd ret val はその DIR whatsit -local function get_box_dir(b, default) +function get_box_dir(b, default) start_time_measure('get_box_dir') local dir = has_attr(b, attr_dir) or 0 local bh = getfield(b,'head') @@ -694,6 +701,7 @@ do -- lastbox local node_prev = (node.direct~=node) and node.direct.getprev or node.prev + local id_glue = node.id('glue') local function lastbox_hook() start_time_measure('box_primitive_hook') local bn = tex_nest[tex_nest.ptr].tail @@ -701,6 +709,14 @@ do local b, head = to_direct(bn), to_direct(tex_nest[tex_nest.ptr].head) local bid = getid(b) if bid==id_hlist or bid==id_vlist then + local p = getlist(b) + -- alignment の各行の中身が入ったボックス + if p and getid(p)==id_glue and getsubtype(p)==12 then -- tabskip + local np = node_next(p); local npid = getid(np) + if npid==id_hlist or npid==id_vlist then + setfield(b, 'head', create_dir_whatsit(p, 'align', get_box_dir(np, 0))) + end + end local box_dir = get_box_dir(b, 0) if box_dir>= dir_node_auto then -- unwrap dir_node local p = node_prev(b) diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua index bd40eccf06f..843c3f98af1 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua @@ -637,8 +637,11 @@ end -------------------- 最下層の処理 +luatexbase.create_callback('luatexja.adjust_jfmglue', 'simple', nullfunc) + -- change penalties (or create a new penalty, if needed) local function handle_penalty_normal(post, pre, g) + luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp) local a = (pre or 0) + (post or 0) if #Bp == 0 then if (a~=0 and not(g and getid(g)==id_kern)) then @@ -654,6 +657,7 @@ local function handle_penalty_normal(post, pre, g) end local function handle_penalty_always(post, pre, g) + luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp) local a = (pre or 0) + (post or 0) if #Bp == 0 then if not (g and getid(g)==id_glue) or a~=0 then @@ -669,7 +673,7 @@ local function handle_penalty_always(post, pre, g) end local function handle_penalty_suppress(post, pre, g) - local a = (pre or 0) + (post or 0) + luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp) if #Bp == 0 then if g and getid(g)==id_glue then local p = node_new(id_penalty) @@ -677,7 +681,24 @@ local function handle_penalty_suppress(post, pre, g) Bp[1]=p set_attr(p, attr_icflag, KINSOKU) end - else for _, v in pairs(Bp) do add_penalty(v,a) end + else + local a = (pre or 0) + (post or 0) + for _, v in pairs(Bp) do add_penalty(v,a) end + end +end + +local function handle_penalty_jwp() + local a = table_current_stack[luatexja.stack_table_index.JWP] + if #widow_Bp == 0 then + if a~=0 then + local p = node_new(id_penalty) + if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end + setfield(p, 'penalty', a) + head = insert_before(head, widow_Np.first, p) + widow_Bp[1]=p; + set_attr(p, attr_icflag, KINSOKU) + end + else for _, v in pairs(widow_Bp) do add_penalty(v,a) end end end @@ -1023,19 +1044,16 @@ end -------------------- 開始・終了時の処理 do - +local node_prev = node.direct.getprev -- リスト末尾の処理 -local JWP = luatexja.stack_table_index.JWP -local function handle_list_tail(mode) - adjust_nq(); Np = Nq +local function handle_list_tail(mode, last) + adjust_nq() if mode then -- the current list is to be line-breaked. -- Insert \jcharwidowpenalty - Bp = widow_Bp; Np = widow_Np - if Np.first then - handle_penalty_normal(0, table_current_stack[JWP] or 0) - end + if widow_Np.first then handle_penalty_jwp() end else + Np=Nq -- the current list is the contents of a hbox local npi, pm = Np.id, Np.met if npi == id_jglyph or (npi==id_pbox and pm) then @@ -1177,7 +1195,7 @@ function main(ahead, mode, dir) end lp = calc_np(last,lp) end - handle_list_tail(mode) + handle_list_tail(mode, last) end return cleanup(mode, TEMP) end diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua index 81fa6be78d5..7355c9eaa6a 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua @@ -61,6 +61,7 @@ function define_jfm(t) elseif type(t.zw)~='number' or type(t.zh)~='number' then defjfm_res= nil; return end + t.version = (type(t.version)=='number') and t.version or 1 t.char_type = {}; t.chars = {} for i,v in pairs(t) do if type(i) == 'number' then -- char_type @@ -103,11 +104,49 @@ function define_jfm(t) if type(v.down)~='number' then v.down = 0.0 end + if t.version>=2 then + if v.end_stretch then defjfm_res= nil; return end + if v.end_shrink then defjfm_res= nil; return end + if v.end_adjust then + if type(v.end_adjust)~='table' then + v.end_adjust = nil + elseif #(v.end_adjust)==0 then + v.end_adjust = nil + else + table.sort(v.end_adjust) + end + end + else + v.end_adjust = nil + if v.end_stretch and v.end_stretch~=0.0 then + v.end_adjust = (v.end_adjust or {}) + v.end_adjust[#(v.end_adjust)+1] = v.end_stretch + end + if v.end_shrink and v.end_ahrink~=0.0 then + v.end_adjust = (v.end_adjust or {}) + v.end_adjust[#(v.end_adjust)+1] = -v.end_shrink + end + if v.end_adjust then v.end_adjust[#(v.end_adjust)+1] = 0.0 end + end v.kern = v.kern or {}; v.glue = v.glue or {} for j,x in pairs(v.glue) do if v.kern[j] then defjfm_res= nil; return end x.ratio, x[5] = (x.ratio or (x[5] and 0.5*(1+x[5]) or 0.5)), nil - x.priority, x[4] = (x.priority or x[4] or 0), nil + do + local xp + xp, x[4] = (x.priority or x[4]), nil + if type(xp)=='table' and t.version>=2 then + if type(xp[1])~='number' or xp[1]<-4 or xp[1]>3 then defjfm_res=nil end -- stretch + if type(xp[2])~='number' or xp[2]<-4 or xp[2]>3 then defjfm_res=nil end -- shrink + xp = (xp[1]+4)*8+(xp[2]+4) + elseif xp and type(xp)~='number' then + defjfm_res = nil + else + xp = (xp or 0)*9+36 + if xp<0 or xp>=64 then defjfm_res=nil end + end + x.priority = xp + end x.kanjiskip_natural = norm_val(x.kanjiskip_natural) x.kanjiskip_stretch = norm_val(x.kanjiskip_stretch) x.kanjiskip_shrink = norm_val(x.kanjiskip_shrink) @@ -147,7 +186,6 @@ do end update_jfm_cache = function (j,sz) if metrics[j].size_cache[sz] then return end - --local TEMP = node_new(id_kern) local t = {} metrics[j].size_cache[sz] = t t.chars = metrics[j].chars @@ -181,7 +219,6 @@ do t.zw = round(metrics[j].zw*sz) t.zh = round(metrics[j].zh*sz) t.size = sz - --node_free(TEMP) end end diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua index 67474d31ce2..85f7568dbcf 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua @@ -205,7 +205,7 @@ do local hic = has_attr(hx, attr_icflag) if (hic == KANJI_SKIP) or (hic == KANJI_SKIP_JFM) or (hic == XKANJI_SKIP) or (hic == XKANJI_SKIP_JFM) - or ((hic<=FROM_JFM+2) and (hic>=FROM_JFM-2)) then + or ((hic<=FROM_JFM+63) and (hic>=FROM_JFM)) then -- この 5 種類の空白をのばす if getid(hx) == id_kern then local k = node_new(id_glue) @@ -215,7 +215,7 @@ do h = insert_after(h, hx, k); h = node_remove(h, hx); node_free(hx); hx = k else -- glue - setglue(hx, getfield(hx, 'width'), round(middle*65536), 0, + setglue(hx, getfield(hx, 'width'), round(middle*65536), 0, 2, 0) end end diff --git a/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua b/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua index 2cf00758fcf..a85e089eb54 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua @@ -30,6 +30,15 @@ do setfield(g,'stretch_order',sto or 0) setfield(g,'shrink_order', sho or 0) end + local getfield = node.direct.getfield + luatexja.getglue = node.direct.getglue or + function(g) + return getfield(g,'width'), + getfield(g,'stretch'), + getfield(g,'shrink'), + getfield(g,'stretch_order'), + getfield(g,'shrink_order') + end end --- 以下は全ファイルで共有される定数 @@ -38,17 +47,18 @@ luatexja.icflag_table = icflag_table icflag_table.ITALIC = 1 icflag_table.PACKED = 2 icflag_table.KINSOKU = 3 -icflag_table.FROM_JFM = 6 +icflag_table.FROM_JFM = 4 -- FROM_JFM: 4, 5, 6, 7, 8 →優先度高(伸びやすく,縮みやすい) -- 6 が標準 -icflag_table.KANJI_SKIP = 9 -icflag_table.KANJI_SKIP_JFM = 10 -icflag_table.XKANJI_SKIP = 11 -icflag_table.XKANJI_SKIP_JFM = 12 -icflag_table.PROCESSED = 13 -icflag_table.IC_PROCESSED = 14 -icflag_table.BOXBDD = 15 -icflag_table.PROCESSED_BEGIN_FLAG = 128 +icflag_table.KANJI_SKIP = 68 -- = 4+64 +icflag_table.KANJI_SKIP_JFM = 69 +icflag_table.XKANJI_SKIP = 70 +icflag_table.XKANJI_SKIP_JFM = 71 +icflag_table.LINEEND = 72 +icflag_table.PROCESSED = 73 +icflag_table.IC_PROCESSED = 74 +icflag_table.BOXBDD = 75 +icflag_table.PROCESSED_BEGIN_FLAG = 4096 -- sufficiently large power of 2 local stack_table_index = {} luatexja.stack_table_index = stack_table_index @@ -462,6 +472,8 @@ local function debug_show_node_X(p,print_fn, limit) s = s .. ' (for accent)' elseif get_attr_icflag(p)==icflag_table.IC_PROCESSED then s = s .. ' (italic correction)' + elseif get_attr_icflag(p)==icflag_table.LINEEND then + s = s .. ' (end-of-line)' -- elseif get_attr_icflag(p)==ITALIC then -- s = s .. ' (italic correction)' elseif get_attr_icflag(p)>icflag_table.KINSOKU diff --git a/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty b/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty index 703c00fe90b..a075947af0f 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty +++ b/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty @@ -264,7 +264,7 @@ \@texttop \dimen@ \dp\@outputbox \unvbox \@outputbox - \ifnum\ltjgetparameter{direction}=4\else\hskip\z@\fi %%% LuaTeX-ja + \ifnum\ltjgetparameter{direction}=4\else\vbox{\hskip\z@}\fi %%% LuaTeX-ja \vskip -\dimen@ \@textbottom }% -- cgit v1.2.3