X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-direction.lua;h=e29503bef4ad5a6f0034e9e69041114a5cebf066;hb=0526b27bf88ed7f2adedef267f4d9226f6f5a692;hp=a80d9d10654afb9a20f51d5bf78dd63f28edefd3;hpb=2be20f06df9aaf9db388f28295415d643790def4;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-direction.lua b/src/ltj-direction.lua index a80d9d1..e29503b 100644 --- a/src/ltj-direction.lua +++ b/src/ltj-direction.lua @@ -148,13 +148,35 @@ do flag = 0; break end end - if flag==1 then -- move dir_whatsit w - return 1,w -- TODO + if flag==1 then -- dir_whatsit already exists + return 1,w else return flag end end end + function luatexja.direction.set_list_direction_hook(v) + local lv = tex_nest.ptr -- must be >= 1 + if not v then + v = get_dir_count() + if abs(tex_nest[lv-1].mode) == ltjs.mmode and v == dir_tate then + v = dir_utod + end + elseif v=='adj' then + v = get_adjust_dir_count() + end + local h = to_direct(tex_nest[lv].head) + local w = node_new(id_whatsit, sid_user) + setfield(w, 'next', nil) + setfield(w, 'user_id', DIR) + setfield(w, 'type', 110) + set_attr(w, attr_dir, v) + insert_after(h, h, w) + tex_nest[lv].tail = to_node(node_tail(w)) + tex_set_attr('global', attr_icflag, 0) + tex_set_attr('global', attr_dir, 0) + end + local function set_list_direction(v, name) local lv = tex_nest.ptr if not v then @@ -461,14 +483,20 @@ local function get_box_dir(b, default) local bh = getfield(b,'head') -- b は insert node となりうるので getlist() は使えない local c - for i=1,2 do - if bh and getid(bh)==id_whatsit - and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then + for bh in traverse_id(id_whatsit, bh) do + if getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then c = bh - dir = (dir==0) and has_attr(bh, attr_dir) or dir + dir = (dir==0) and has_attr(bh, attr_dir) or dir end - bh = node_next(bh) end + -- for i=1,2 do + -- if bh and getid(bh)==id_whatsit + -- and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then + -- c = bh + -- dir = (dir==0) and has_attr(bh, attr_dir) or dir + -- end + -- bh = node_next(bh) + -- end stop_time_measure('get_box_dir') return (dir==0 and default or dir), c end @@ -838,7 +866,7 @@ do local box_dir = get_box_dir(sd, dir_yoko) if box_dir%dir_math_mod ~= list_dir then setbox( - 'ltj@afbox', + 'ltj@afbox', to_node(copy_list(make_dir_whatsit(sd, sd, list_dir, 'box_move'))) -- copy_list しないとリストの整合性が崩れる……? ) @@ -854,29 +882,64 @@ do local function glyph_from_packed(h) local b = getlist(h) return (getid(b)==id_kern or (getid(b)==id_whatsit and getsubtype(b)==sid_save) ) - and node_next(node_next(node_next(node_next(b)))) or b + and node_next(node_next(node_next(b))) or b end luatexja.direction.glyph_from_packed = glyph_from_packed end --- adjust and insertion -local id_adjust = node.id('adjust') -function luatexja.direction.check_adjust_direction() - start_time_measure('box_primitive_hook') - local list_dir = get_adjust_dir_count() - local a = tex_nest[tex_nest.ptr].tail - local ad = to_direct(a) - if a and getid(ad)==id_adjust then - local adj_dir = get_box_dir(ad) - if list_dir~=adj_dir then - ltjb.package_error( - 'luatexja', - 'Direction Incompatible', - "\\vadjust's argument and outer vlist must have same direction.") - Dnode.last_node() +-- adjust +do + local id_adjust = node.id('adjust') + function luatexja.direction.check_adjust_direction() + start_time_measure('box_primitive_hook') + local list_dir = get_adjust_dir_count() + local a = tex_nest[tex_nest.ptr].tail + local ad = to_direct(a) + if a and getid(ad)==id_adjust then + local adj_dir = get_box_dir(ad) + if list_dir~=adj_dir then + ltjb.package_error( + 'luatexja', + 'Direction Incompatible', + "\\vadjust's argument and outer vlist must have same direction.") + Dnode.last_node() + end end + stop_time_measure('box_primitive_hook') + end +end + +-- insert +do + local id_ins = node.id('ins') + local id_rule = node.id('rule') + function luatexja.direction.populate_insertion_dir_whatsit() + start_time_measure('box_primitive_hook') + local list_dir = get_dir_count() + local a = tex_nest[tex_nest.ptr].tail + local ad = to_direct(a) + if a and getid(ad)==id_ins then + local h = getfield(ad, 'head') + if getid(h)==id_whatsit and + getsubtype(h)==sid_user and getfield(h, 'user_id')==DIR then + local n = h; h = node_remove(h,h) + node_free(n) + end + for box_rule in traverse(h) do + if getid(box_rule)