From 445a8cc5658b9d4bd46426b59b006994a5ab6abd Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Mon, 5 Oct 2020 05:18:15 +0900 Subject: [PATCH] ltj-ruby.lua: argument --- src/ltj-ruby.lua | 86 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/src/ltj-ruby.lua b/src/ltj-ruby.lua index 1f311ea..d2d6ce0 100644 --- a/src/ltj-ruby.lua +++ b/src/ltj-ruby.lua @@ -129,6 +129,9 @@ function luatexja.ruby.read_old_break_info() local real_file = kpse.find_file(fname) if real_file then dofile(real_file) end cache_handle = io.open(fname, 'w') + if cache_handle then + cache_handle:write('local lrob=luatexja.ruby.old_break_info\n') + end end end local make_uniq_id @@ -143,12 +146,12 @@ end -- concatenation of boxes: reusing nodes -- ルビ組版が行われている段落/hboxでの設定が使われる. -- ルビ文字を格納しているボックスでの設定ではない! +local function get_attr_icflag(p) + return (has_attr(p, attr_icflag) or 0) % PROCESSED_BEGIN_FLAG +end local concat do local node_prev = node.direct.getprev - local function get_attr_icflag(p) - return (has_attr(p, attr_icflag) or 0) % PROCESSED_BEGIN_FLAG - end function concat(f, b) if f then if b then @@ -311,11 +314,13 @@ end ---------------------------------------------------------------- -- r, p の中身のノードは再利用される -local function enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode) +local function enlarge_parent(r, p, tmp_tbl, intmode) -- r: ルビ部分の格納された box,p: 同,親文字 local rwidth = getfield(r, 'width') local sumprot = rwidth - getfield(p, 'width') -- >0 local pre_intrusion, post_intrusion + local ppre, pmid, ppost = tmp_tbl.ppre, tmp_tbl.pmid, tmp_tbl.ppost + local mapre, mapost = tmp_tbl.mapre, tmp_tbl.mapost if intmode == 0 then -- とりあえず組んでから決める p = enlarge(p, rwidth, ppre, pmid, ppost, 0, 0) pre_intrusion = min(mapre, round(ppre*getfield(p, 'glue_set')*65536)) @@ -351,17 +356,18 @@ end -- ルビボックスの生成(単一グループ) -- returned value: , , local max_margin -local function new_ruby_box(r, p, ppre, pmid, ppost, - mapre, mapost, imode, rgap, bheight) +local function new_ruby_box(r, p, tmp_tbl) local post_intrusion = 0 - local intmode = imode%4 + local imode = tmp_tbl.imode + local ppre, pmid, ppost = tmp_tbl.ppre, tmp_tbl.pmid, tmp_tbl.ppost + local mapre, mapost = tmp_tbl.mapre, tmp_tbl.mapost local rpre, rmid, rpost, rsmash imode = floor(imode/262144); rsmash = (imode%2 ==1) imode = floor(imode/2); rpost = imode%8; imode = (imode-rpost)/8; rmid = imode%8; imode = (imode-rmid)/8; rpre = imode%8 if getfield(r, 'width') > getfield(p, 'width') then -- change the width of p - r, p, post_intrusion = enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode) + r, p, post_intrusion = enlarge_parent(r, p, tmp_tbl, imode%4) elseif getfield(r, 'width') < getfield(p, 'width') then -- change the width of r r = enlarge(r, getfield(p, 'width'), rpre, rmid, rpost, 0, 0) post_intrusion = 0 @@ -385,12 +391,10 @@ local function new_ruby_box(r, p, ppre, pmid, ppost, end local a, k = node_new(id_rule), node_new(id_kern, 1) setfield(a, 'width', 0); setfield(a, 'height', 0) - setfield(a, 'depth', 0); setfield(k, 'kern', rgap) + setfield(a, 'depth', 0); setfield(k, 'kern', tmp_tbl.rgap) insert_after(r, r, a); insert_after(r, a, k); insert_after(r, k, p); setfield(p, 'next', nil) - if bheight > 0 then - setfield(p, 'height', bheight) - end + if tmp_tbl.bheight > 0 then setfield(p, 'height', tmp_tbl.bheight) end a = node.direct.vpack(r); setfield(a, 'shift', 0) set_attr(a, attr_ruby, post_intrusion) if rsmash or getfield(a, 'height') ', print) + if getid(p)==id_glue then + local pi = get_attr_icflag(p) + if pi>=KANJI_SKIP and pi<=XKANJI_SKIP_JFM then + print(n, 'before ' .. luatexja.print_scaled(getfield(p, 'width'))) + end + end + p = getnext(n) + luatexja.ext_show_node(node.direct.tonode(p), 'A> ', print) + if getid(p)==id_glue then + local pi = get_attr_icflag(p) + if pi>=KANJI_SKIP and pi<=XKANJI_SKIP_JFM then + print(n, 'after ' .. luatexja.print_scaled(getfield(p, 'width'))) + end + end +end +end + local function pre_high(ahead) if not ahead then return ahead end local head = to_direct(ahead) @@ -523,6 +560,7 @@ local function pre_high(ahead) local n = first_whatsit(head) while n do if getsubtype(n) == sid_user and getfield(n, 'user_id') == RUBY_PRE then + local around_skip = get_around_skip(head, n) local nv = getfield(n, 'value') max_allow_pre = has_attr(nv, attr_ruby_maxprep) or 0 local atr = has_attr(n, attr_ruby) or 0 @@ -564,9 +602,7 @@ do local id = has_attr(wv, attr_ruby_id) if id>0 and cache_handle then cache_handle:write( - 'luatexja.ruby.old_break_info[' - .. tostring(id) .. ']=' .. num - .. '\n') + 'lrob[' .. tostring(id) .. ']=' .. num .. '\n') end end -- 2.11.0