X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-math.lua;h=15813fc644047c66077e6f61ded59c5b2d9d63ea;hb=0526b27bf88ed7f2adedef267f4d9226f6f5a692;hp=e32f432899f60b910daf5499e68653523b25de0f;hpb=d9e95ad2a91ff3a20a3fb1ddb542ca9f53bf5620;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-math.lua b/src/ltj-math.lua index e32f432..15813fc 100644 --- a/src/ltj-math.lua +++ b/src/ltj-math.lua @@ -3,6 +3,7 @@ -- luatexja.load_module('base'); local ltjb = luatexja.base +luatexja.load_module('direction'); local ltjd = luatexja.direction luatexja.load_module('charrange'); local ltjc = luatexja.charrange luatexja.load_module('jfont'); local ltjf = luatexja.jfont luatexja.load_module('stack'); local ltjs = luatexja.stack @@ -14,6 +15,7 @@ local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = 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 getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end +local getlist = (Dnode ~= node) and Dnode.getlist or function(n) return n.head end -- getlist cannot be used for sub_box nodes. Use instead λp. getfield(p, 'head') local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end @@ -24,12 +26,14 @@ local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc local node_traverse = Dnode.traverse local node_new = Dnode.new local node_next = (Dnode ~= node) and Dnode.getnext or node.next +local node_remove = Dnode.remove local node_free = Dnode.free local has_attr = Dnode.has_attribute local set_attr = Dnode.set_attribute local tex_getcount = tex.getcount local attr_jchar_class = luatexbase.attributes['ltj@charclass'] +local attr_dir = luatexbase.attributes['ltj@dir'] local attr_icflag = luatexbase.attributes['ltj@icflag'] local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] local attr_jfam = luatexbase.attributes['jfam'] @@ -50,14 +54,32 @@ local id_sub_mlist = node.id('sub_mlist') local id_whatsit = node.id('whatsit') local sid_user = node.subtype('user_defined') local DIR = luatexja.userid_table.DIR +local dir_node_auto = luatexja.dir_table.dir_node_auto local PROCESSED = luatexja.icflag_table.PROCESSED local ltjf_font_metric_table = ltjf.font_metric_table local ltjf_find_char_class = ltjf.find_char_class +local ltjd_get_dir_count = ltjd.get_dir_count +local ltjd_make_dir_whatsit = ltjd.make_dir_whatsit -- table of mathematical characters local is_math_letters = {} +local list_dir + +local function conv_vcenter(sb) + local h = getfield(sb, 'head');local hd = getlist(h) + if getid(hd)==id_whatsit and + getsubtype(hd)==sid_user and getfield(hd, 'user_id')==DIR then + local d = node_next(hd) + if getid(d)==id_vlist and has_attr(d, attr_dir)>=dir_node_auto then + node_free(hd); setfield(h, 'head', nil); node_free(h) + setfield(sb, 'head', d); h = d + end + end + set_attr(h, attr_icflag, PROCESSED) + return sb +end local conv_jchar_to_hbox_A @@ -66,7 +88,11 @@ local function conv_jchar_to_hbox(head, sty) for p in node_traverse(head) do local pid = getid(p) if pid == id_simple or pid == id_accent then - setfield(p, 'nucleus', conv_jchar_to_hbox_A(getfield(p, 'nucleus'), sty)) + if getsubtype(p)==12 then + conv_vcenter(getfield(p, 'nucleus')) + else + setfield(p, 'nucleus', conv_jchar_to_hbox_A(getfield(p, 'nucleus'), sty)) + end setfield(p, 'sub', conv_jchar_to_hbox_A(getfield(p, 'sub'), sty+1)) setfield(p, 'sup', conv_jchar_to_hbox_A(getfield(p, 'sup'), sty+1)) elseif pid == id_choice then @@ -133,7 +159,10 @@ function (p, sty) end elseif pid == id_sub_box and getfield(p, 'head') then -- \hbox で直に与えられた内容は上下位置を補正する必要はない - set_attr(getfield(p, 'head'), attr_icflag, PROCESSED) + local h = getfield(p, 'head') + h = ltjd_make_dir_whatsit(h, h, list_dir, 'math') + setfield(p, 'head', h) + set_attr(h, attr_icflag, PROCESSED) end end return p @@ -142,10 +171,11 @@ end local node_remove = Dnode.remove luatexbase.add_to_callback('mlist_to_hlist', function (n, display_type, penalties) - n = to_direct(n) + n = to_direct(n); list_dir = ltjd_get_dir_count() if getid(n)==id_whatsit and getsubtype(n)==sid_user and getfield(n, 'user_id') == DIR then - local old_n = n; n = node_remove(n, n); node_free(old_n) + local old_n = n; n = node_remove(n, n) + node_free(old_n) end return node.mlist_to_hlist( to_node(conv_jchar_to_hbox(n, 0)),