X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-setwidth.lua;h=ebd7393b55b1affce9b1989c60c206d15cfcd09d;hb=a693b63eadfcabe5f4f513a4cc90302f2360b18b;hp=6e65fd3a16a3e20715fdca22d55e3db5d3c89171;hpb=72ac1fbce6745896b98e48ead84394aaabfe68e8;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-setwidth.lua b/src/ltj-setwidth.lua index 6e65fd3..ebd7393 100644 --- a/src/ltj-setwidth.lua +++ b/src/ltj-setwidth.lua @@ -6,7 +6,6 @@ luatexja.load_module('base'); local ltjb = luatexja.base luatexja.load_module('jfont'); local ltjf = luatexja.jfont local Dnode = node.direct or node - 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 @@ -17,7 +16,7 @@ local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n. local node_traverse = Dnode.traverse local node_new = Dnode.new -local node_remove = Dnode.remove +local node_remove = luatexja.Dnode_remove -- Dnode.remove local node_tail = Dnode.tail local node_next = Dnode.getnext local has_attr = Dnode.has_attribute @@ -55,7 +54,8 @@ do end end -local ltjw = {} +local head, dir +local ltjw = {} --export luatexja.setwidth = ltjw luatexbase.create_callback("luatexja.set_width", "data", @@ -67,7 +67,7 @@ local call_callback = luatexbase.call_callback local fshift = { down = 0, left = 0} -- mode: true iff p will be always encapsuled by a hbox -local function capsule_glyph(p, dir, mode, met, class) +local function capsule_glyph(p, met, class) local char_data = met.char_type[class] if not char_data then return node_next(p) end local fwidth, pwidth = char_data.width, getfield(p, 'width') @@ -75,40 +75,65 @@ local function capsule_glyph(p, dir, mode, met, class) fshift.down = char_data.down; fshift.left = char_data.left fshift = call_callback("luatexja.set_width", fshift, met, class) local fheight, fdepth = char_data.height, char_data.depth - if (mode or pwidth ~= fwidth or getfield(p, 'height') ~= fheight or getfield(p, 'depth') ~= fdepth) then - local y_shift, ca - = - getfield(p, 'yoffset') + (has_attr(p,attr_ykblshift) or 0), char_data.align + if (pwidth ~= fwidth or getfield(p, 'height') ~= fheight or getfield(p, 'depth') ~= fdepth) then + local y_shift + = - getfield(p, 'yoffset') + (has_attr(p,attr_ykblshift) or 0) local q - ltjw.head, q = node_remove(ltjw.head, p) + head, q = node_remove(head, p) setfield(p, 'yoffset', -fshift.down); setfield(p, 'next', nil) - if ca~='left' then - setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left - + (((ca=='right') and fwidth - pwidth) or round((fwidth - pwidth)*0.5))) - else - setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left) - end - local box = node_new(id_hlist); + setfield(p, 'xoffset', getfield(p, 'xoffset') + char_data.align*(fwidth-pwidth)) + local box = node_new(id_hlist) setfield(box, 'width', fwidth) setfield(box, 'height', fheight) setfield(box, 'depth', fdepth) setfield(box, 'head', p) setfield(box, 'shift', y_shift) - setfield(box, 'dir', dir or 'TLT') + setfield(box, 'dir', dir) set_attr(box, attr_icflag, PACKED + get_pr_begin_flag(p)) - ltjw.head = q and node_insert_before(ltjw.head, q, box) - or node_insert_after(ltjw.head, node_tail(ltjw.head), box) + head = q and node_insert_before(head, q, box) + or node_insert_after(head, node_tail(head), box) return q else set_attr(p, attr_icflag, PROCESSED + get_pr_begin_flag(p)) setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left) - setfield(p, 'yoffset', getfield(p, 'yoffset') - (has_attr(p, attr_ykblshift) or 0) - fshift.down) + setfield(p, 'yoffset', getfield(p, 'yoffset') + - (has_attr(p, attr_ykblshift) or 0) - fshift.down) return node_next(p) end end luatexja.setwidth.capsule_glyph = capsule_glyph -function luatexja.setwidth.set_ja_width(ahead, dir) - local p = ahead; ltjw.head = p +local function capsule_glyph_math(p, met, class) + local char_data = met.char_type[class] + if not char_data then return nil end + local fwidth, pwidth = char_data.width, getfield(p, 'width') + fwidth = (fwidth ~= 'prop') and fwidth or pwidth + fshift.down = char_data.down; fshift.left = char_data.left + fshift = call_callback("luatexja.set_width", fshift, met, class) + local fheight, fdepth = char_data.height, char_data.depth + local y_shift, ca + = - getfield(p, 'yoffset') + (has_attr(p,attr_ykblshift) or 0), char_data.align + setfield(p, 'yoffset', -fshift.down) + if ca~='left' then + setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left + + (((ca=='right') and fwidth - pwidth) or round((fwidth - pwidth)*0.5))) + else + setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left) + end + local box = node_new(id_hlist); + setfield(box, 'width', fwidth) + setfield(box, 'height', fheight) + setfield(box, 'depth', fdepth) + setfield(box, 'head', p) + setfield(box, 'shift', y_shift) + setfield(box, 'dir', tex.mathdir) + set_attr(box, attr_icflag, PACKED + get_pr_begin_flag(p)) + return box +end +luatexja.setwidth.capsule_glyph_math = capsule_glyph_math + +function luatexja.setwidth.set_ja_width(ahead, adir) + local p = ahead; head = p; dir = adir or 'TLT' local m = false -- is in math mode? while p do local pid = getid(p) @@ -116,7 +141,7 @@ function luatexja.setwidth.set_ja_width(ahead, dir) and ((has_attr(p, attr_icflag) or 0)%PROCESSED_BEGIN_FLAG)<=0 then local pf = getfont(p) if pf == has_attr(p, attr_curjfnt) then - p = capsule_glyph(p, dir, false, ltjf_font_metric_table[pf], + p = capsule_glyph(p, ltjf_font_metric_table[pf], has_attr(p, attr_jchar_class)) else set_attr(p, attr_icflag, PROCESSED + get_pr_begin_flag(p)) @@ -147,6 +172,6 @@ function luatexja.setwidth.set_ja_width(ahead, dir) end -- adjust attr_icflag tex.setattribute('global', attr_icflag, 0) - return ltjw.head + return head end