X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-ruby.lua;h=6ab3d1c10fdc4dfaa493feb8f535395b3667cdae;hb=3fae82d64b193c794fdf2f1262d80bddc98ce5a8;hp=bf57c77208c16f2ca316a6e6ed0d1952db09d36e;hpb=0e8b59d4e986bb2c1e1af9746d649389325db9a1;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-ruby.lua b/src/ltj-ruby.lua index bf57c77..6ab3d1c 100644 --- a/src/ltj-ruby.lua +++ b/src/ltj-ruby.lua @@ -3,13 +3,12 @@ -- luatexbase.provides_module({ name = 'luatexja.ruby', - date = '2015/09/18', + date = '2018/09/29', description = 'Ruby annotation', }) -module('luatexja.ruby', package.seeall) -local err, warn, info, log = luatexbase.errwarinf(_NAME) - +luatexja.ruby = {} luatexja.load_module('stack'); local ltjs = luatexja.stack +luatexja.load_module('base'); local ltjb = luatexja.base local to_node = node.direct.tonode local to_direct = node.direct.todirect @@ -68,13 +67,14 @@ luatexja.userid_table.RUBY_PRE = luatexbase.newuserwhatsitid('ruby_pre', 'luate luatexja.userid_table.RUBY_POST = luatexbase.newuserwhatsitid('ruby_post', 'luatexja') local RUBY_PRE = luatexja.userid_table.RUBY_PRE local RUBY_POST = luatexja.userid_table.RUBY_POST +local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG ---------------------------------------------------------------- -- TeX interface 0 ---------------------------------------------------------------- do local getbox = node.direct.getbox - function cpbox() return node_copy(getbox(0)) end + function luatexja.ruby.cpbox() return node_copy(getbox(0)) end end ---------------------------------------------------------------- @@ -119,9 +119,10 @@ end -- 実行回数 + ルビ中身 から uniq_id を作る関数 -old_break_info = {} -- public, 前 run 時の分割情報 +luatexja.ruby.old_break_info = {} -- public, 前 run 時の分割情報 +local old_break_info = luatexja.ruby.old_break_info local cache_handle -function read_old_break_info() +function luatexja.ruby.read_old_break_info() if tex.jobname then local fname = tex.jobname .. '.ltjruby' local real_file = kpse.find_file(fname) @@ -144,6 +145,9 @@ 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 @@ -151,6 +155,8 @@ do if getid(nh)==id_whatsit and getsubtype(nh)==sid_user then nh=node_next(nh); node_free(node_prev(nh)) end + set_attr(nh, attr_icflag, + get_attr_icflag(nh) + PROCESSED_BEGIN_FLAG) setfield(node_tail(h), 'next', nh) setfield(f, 'head', nil); node_free(f) setfield(b, 'head', nil); node_free(b) @@ -202,10 +208,10 @@ do local hh, hd = getfield(box, 'height'), getfield(box, 'depth') local hx = h while hx do - local hic = has_attr(hx, attr_icflag) + local hic = has_attr(hx, attr_icflag) or 0 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 +221,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 @@ -252,6 +258,7 @@ local function texiface_low(rst, rtlr, rtlp) setfield(w, 'value', to_node(wv)) setfield(wv, 'type', 100) setfield(wv, 'value', floor(#rtlr)) + setfield(wv, 'user_id', RUBY_PRE) -- dummy set_attr(wv, attr_ruby, rst.rubyzw) set_attr(wv, attr_ruby_maxmargin, rst.maxmargin) set_attr(wv, attr_ruby_maxprep, rst.pre) @@ -269,11 +276,11 @@ local function texiface_low(rst, rtlr, rtlp) end -- rst: table -function texiface(rst, rtlr, rtlp) +function luatexja.ruby.texiface(rst, rtlr, rtlp) if #rtlr ~= #rtlp then for i=1, #rtlr do node_free(rtlr[i]) end for i=1, #rtlp do node_free(rtlp[i]) end - luatexja.base.package_error('luatexja-ruby', + ltjb.package_error('luatexja-ruby', 'Group count mismatch between the ruby and\n' .. 'the body (' .. #rtlr .. ' != ' .. #rtlp .. ').', '') @@ -374,7 +381,7 @@ local function new_ruby_box(r, p, ppre, pmid, ppost, setfield(rt, 'head', nil); node_free(rt); end end - local a, k = node_new(id_rule), node_new(id_kern) + 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) insert_after(r, r, a); insert_after(r, a, k); @@ -382,7 +389,7 @@ local function new_ruby_box(r, p, ppre, pmid, ppost, a = node.direct.vpack(r); setfield(a, 'shift', 0) set_attr(a, attr_ruby, post_intrusion) if rsmash or getfield(a, 'height')