X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-ruby.lua;h=1237cea46287c6277f6929177658f0a4b004a3f6;hb=d177010c46e52e722b4752eded1ae4a6807953df;hp=4f9789917eb9aeb9c87722605758d5edb905fe65;hpb=2e0ee42f453ba189b6f6c7e7dac3ec714789fe90;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-ruby.lua b/src/ltj-ruby.lua index 4f97899..1237cea 100644 --- a/src/ltj-ruby.lua +++ b/src/ltj-ruby.lua @@ -3,7 +3,7 @@ -- luatexbase.provides_module({ name = 'luatexja.ruby', - date = '2015/01/14', + date = '2017/05/05', description = 'Ruby annotation', }) module('luatexja.ruby', package.seeall) @@ -11,25 +11,24 @@ local err, warn, info, log = luatexbase.errwarinf(_NAME) luatexja.load_module('stack'); local ltjs = luatexja.stack -local Dnode = node.direct or node -local nullfunc = function(n) return n end -local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc -local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc - -local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end -local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end -local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end -local getfont = (Dnode ~= node) and Dnode.getfont or function(n) return n.font end -local getlist = (Dnode ~= node) and Dnode.getlist or function(n) return n.head end -local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end -local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end - -local node_new = Dnode.new -local node_remove = Dnode.remove -local node_next = (Dnode ~= node) and Dnode.getnext or node.next -local node_copy, node_free, node_tail = Dnode.copy, Dnode.free, Dnode.tail -local has_attr, set_attr = Dnode.has_attribute, Dnode.set_attribute -local insert_before, insert_after = Dnode.insert_before, Dnode.insert_after +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 getid = node.direct.getid +local getfont = node.direct.getfont +local getlist = node.direct.getlist +local getchar = node.direct.getchar +local getsubtype = node.direct.getsubtype + +local node_new = node.direct.new +local node_remove = node.direct.remove +local node_next = node.direct.getnext +local node_copy, node_free, node_tail = node.direct.copy, node.direct.free, node.direct.tail +local has_attr, set_attr = node.direct.has_attribute, node.direct.set_attribute +local insert_before, insert_after = node.direct.insert_before, node.direct.insert_after local id_hlist = node.id('hlist') local id_vlist = node.id('vlist') @@ -38,7 +37,6 @@ local id_whatsit = node.id('whatsit') local id_glue = node.id('glue') local id_kern = node.id('kern') local id_penalty = node.id('penalty') -local id_glue_spec = node.id('glue_spec') local sid_user = node.subtype('user_defined') local ltjs_get_stack_table = luatexja.stack.get_stack_table local id_pbox_w = 258 -- cluster which consists of a whatsit @@ -74,13 +72,11 @@ local RUBY_POST = luatexja.userid_table.RUBY_POST ---------------------------------------------------------------- -- TeX interface 0 ---------------------------------------------------------------- -if Dnode ~= node then - function cpbox() return node_copy(Dnode.getbox(0)) end -else - function cpbox() return node.copy(tex.box[0]) end +do + local getbox = node.direct.getbox + function cpbox() return node_copy(getbox(0)) end end - ---------------------------------------------------------------- -- 補助関数群 1 ---------------------------------------------------------------- @@ -147,7 +143,7 @@ end -- ルビ文字を格納しているボックスでの設定ではない! local concat do - local node_prev = (Dnode ~= node) and Dnode.getprev or node.prev + local node_prev = node.direct.getprev function concat(f, b) if f then if b then @@ -158,12 +154,8 @@ do setfield(node_tail(h), 'next', nh) setfield(f, 'head', nil); node_free(f) setfield(b, 'head', nil); node_free(b) - print('<<>>') - luatexja.ext_show_node_list(to_node(h), '', print) - print('<<>>') local g = luatexja.jfmglue.main(h,false) - luatexja.ext_show_node_list(to_node(g), '', print) - return Dnode.hpack(g) + return node.direct.hpack(g) else return f end @@ -213,51 +205,33 @@ 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) - local ks = node_new(id_glue_spec) - setfield(ks, 'width', getfield(hx, 'kern')) - setfield(ks, 'stretch_order', 2) - setfield(ks, 'stretch', round(middle*65536)) - setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0) - setfield(k, 'subtype', 0); setfield(k, 'spec', ks) + setglue(k, getfield(hx, 'kern'), round(middle*65536), 0, + 2, 0) + setfield(k, 'subtype', 0); h = insert_after(h, hx, k); h = node_remove(h, hx); node_free(hx); hx = k else -- glue - local old_spec = getfield(hx, 'spec') - local ks = node_copy(old_spec) - setfield(ks, 'stretch_order', 2) - setfield(ks, 'stretch', round(middle*65536)) - setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0) - setfield(hx, 'spec', ks) - -- decrease old_spec's reference count - local b = node_new(id_glue) - setfield(b, 'spec', old_spec); node_free(b) + setglue(hx, getfield(hx, 'width'), round(middle*65536), 0, + 2, 0) end end hx = node_next(hx) end -- 先頭の空白を挿入 local k = node_new(id_glue); - local ks = node_new(id_glue_spec) - setfield(ks, 'width', prenw) - setfield(ks, 'stretch_order', 2); setfield(ks, 'stretch', round(pre*65536)) - setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0) - setfield(k, 'subtype', 0); setfield(k, 'spec', ks) + setglue(k, prenw, round(pre*65536), 0, 2, 0) h = insert_before(h, h, k); -- 末尾の空白を挿入 local k = node_new(id_glue); - local ks = node_new(id_glue_spec); - setfield(ks, 'width', postnw) - setfield(ks, 'stretch_order', 2); setfield(ks, 'stretch', round(post*65536)) - setfield(ks, 'shrink_order', 0); setfield(ks, 'shrink', 0) - setfield(k, 'subtype', 0);setfield(k, 'spec', ks) + setglue(k, postnw, round(post*65536), 0, 2, 0) insert_after(h, node_tail(h), k); -- hpack setfield(box, 'head', nil); node_free(box) - box = Dnode.hpack(h, new_width, 'exactly') + box = node.direct.hpack(h, new_width, 'exactly') setfield(box, 'height', hh) setfield(box, 'depth', hd) return box @@ -291,7 +265,7 @@ local function texiface_low(rst, rtlr, rtlp) _, n = insert_after(wv, n, rtlp[i]) end -- w.value: (whatsit) .. r1 .. p1 .. r2 .. p2 - Dnode.write(w); return w,wv + node.direct.write(w); return w,wv end -- rst: table @@ -360,7 +334,7 @@ local function enlarge_parent(r, p, ppre, pmid, ppost, mapre, mapost, intmode) local rwidth = rwidth - pre_intrusion - post_intrusion setfield(r, 'width', rwidth) setfield(p, 'width', rwidth) - local ps = getfield(getlist(p), 'spec') + local ps = getlist(p) setfield(ps, 'width', getfield(ps, 'width') - pre_intrusion) return r, p, post_intrusion end @@ -385,30 +359,30 @@ local function new_ruby_box(r, p, ppre, pmid, ppost, local need_repack = false -- margin が大きくなりすぎた時の処理 if round(rpre*getfield(r, 'glue_set')*65536) > max_margin then - local ps = getfield(getlist(r), 'spec'); need_repack = true + local ps = getlist(r); need_repack = true setfield(ps, 'width', max_margin) setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る end if round(rpost*getfield(r, 'glue_set')*65536) > max_margin then - local ps = getfield(node_tail(getlist(r)), 'spec'); need_repack = true + local ps = node_tail(getlist(r)); need_repack = true setfield(ps, 'width', max_margin) setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る end if need_repack then local rt = r - r = Dnode.hpack(getlist(r), getfield(r, 'width'), 'exactly') + r = node.direct.hpack(getlist(r), getfield(r, 'width'), 'exactly') 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); insert_after(r, k, p); setfield(p, 'next', nil) - a = Dnode.vpack(r); setfield(a, 'shift', 0) + a = node.direct.vpack(r); setfield(a, 'shift', 0) set_attr(a, attr_ruby, post_intrusion) if rsmash or getfield(a, 'height')