diff options
Diffstat (limited to 'macros/luatex/generic/luatexja/src/ltj-math.lua')
-rw-r--r-- | macros/luatex/generic/luatexja/src/ltj-math.lua | 127 |
1 files changed, 59 insertions, 68 deletions
diff --git a/macros/luatex/generic/luatexja/src/ltj-math.lua b/macros/luatex/generic/luatexja/src/ltj-math.lua index b6ef1a9dd3..2a7c0444c7 100644 --- a/macros/luatex/generic/luatexja/src/ltj-math.lua +++ b/macros/luatex/generic/luatexja/src/ltj-math.lua @@ -2,12 +2,12 @@ -- ltj-math.lua -- -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 -luatexja.load_module('setwidth'); local ltjw = luatexja.setwidth +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 +luatexja.load_module 'setwidth'; local ltjw = luatexja.setwidth local setfield = node.direct.setfield local getfield = node.direct.getfield @@ -36,20 +36,20 @@ local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] local attr_jfam = luatexbase.attributes['jfam'] local attr_yablshift = luatexbase.attributes['ltj@yablshift'] -local id_glyph = node.id('glyph') -local id_hlist = node.id('hlist') -local id_vlist = node.id('vlist') -local id_mchar = node.id('math_char') -local id_sub_box = node.id('sub_box') -local id_radical = node.id('radical') -local id_choice = node.id('choice') -local id_accent = node.id('accent') -local id_style = node.id('style') -local id_frac = node.id('fraction') -local id_simple = node.id('noad') -local id_sub_mlist = node.id('sub_mlist') -local id_whatsit = node.id('whatsit') -local sid_user = node.subtype('user_defined') +local id_glyph = node.id 'glyph' +local id_hlist = node.id 'hlist' +local id_vlist = node.id 'vlist' +local id_mchar = node.id 'math_char' +local id_sub_box = node.id 'sub_box' +local id_radical = node.id 'radical' +local id_choice = node.id 'choice' +local id_accent = node.id 'accent' +local id_style = node.id 'style' +local id_frac = node.id 'fraction' +local id_simple = node.id 'noad' +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 @@ -66,56 +66,54 @@ local list_dir -- vcenter noad は軸に揃えるため,欧文ベースライン補正がかかる 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 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); set_attr(d, attr_icflag, 0) + node_free(hd); setfield(h, 'head', nil); node_free(h) + setfield(sb, 'head', d); set_attr(d, attr_icflag, 0) end end return sb end -local conv_jchar_to_hbox_A - +local cjhh_A -- sty : 0 (display or text), 1 (script), >=2 (scriptscript) 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 - 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)) + if getsubtype(p)==12 then + conv_vcenter(getfield(p, 'nucleus')) + else + setfield(p, 'nucleus', cjh_A(getfield(p, 'nucleus'), sty)) + end + setfield(p, 'sub', cjh_A(getfield(p, 'sub'), sty+1)) + setfield(p, 'sup', cjh_A(getfield(p, 'sup'), sty+1)) elseif pid == id_choice then - setfield(p, 'display', conv_jchar_to_hbox_A(getfield(p, 'display'), 0)) - setfield(p, 'text', conv_jchar_to_hbox_A(getfield(p, 'text'), 0)) - setfield(p, 'script', conv_jchar_to_hbox_A(getfield(p, 'script'), 1)) - setfield(p, 'scriptscript', conv_jchar_to_hbox_A(getfield(p, 'scriptscript'), 2)) + setfield(p, 'display', cjh_A(getfield(p, 'display'), 0)) + setfield(p, 'text', cjh_A(getfield(p, 'text'), 0)) + setfield(p, 'script', cjh_A(getfield(p, 'script'), 1)) + setfield(p, 'scriptscript', cjh_A(getfield(p, 'scriptscript'), 2)) elseif pid == id_frac then - setfield(p, 'num', conv_jchar_to_hbox_A(getfield(p, 'num'), sty+1)) - setfield(p, 'denom', conv_jchar_to_hbox_A(getfield(p, 'denom'), sty+1)) + setfield(p, 'num', cjh_A(getfield(p, 'num'), sty+1)) + setfield(p, 'denom', cjh_A(getfield(p, 'denom'), sty+1)) elseif pid == id_radical then - setfield(p, 'nucleus', conv_jchar_to_hbox_A(getfield(p, 'nucleus'), sty)) - 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)) - if getfield(p, 'degree') then - setfield(p, 'degree', conv_jchar_to_hbox_A(getfield(p, 'degree'), sty + 1)) - end + setfield(p, 'nucleus', cjh_A(getfield(p, 'nucleus'), sty)) + setfield(p, 'sub', cjh_A(getfield(p, 'sub'), sty+1)) + setfield(p, 'sup', cjh_A(getfield(p, 'sup'), sty+1)) + if getfield(p, 'degree') then + setfield(p, 'degree', cjh_A(getfield(p, 'degree'), sty + 1)) + end elseif pid == id_style then - local ps = getfield(p, 'style') - if ps == "display'" or ps == 'display' - or ps == "text'" or ps == 'text' then - sty = 0 - elseif ps == "script'" or ps == 'script' then - sty = 1 - else sty = 2 - end + local ps = getfield(p, 'style') + if ps == "display'" or ps == 'display' or ps == "text'" or ps == 'text' then + sty = 0 + elseif ps == "script'" or ps == 'script' then + sty = 1 + else sty = 2 + end end end return head @@ -127,8 +125,7 @@ local MJSS = luatexja.stack_table_index.MJSS local capsule_glyph_math = ltjw.capsule_glyph_math local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct -conv_jchar_to_hbox_A = -function (p, sty) +cjh_A = function (p, sty) if not p then return nil else local pid = getid(p) @@ -137,29 +134,24 @@ function (p, sty) setfield(p, 'head', conv_jchar_to_hbox(getfield(p, 'head'), sty)) end elseif pid == id_mchar then - local fam = has_attr(p, attr_jfam) or -1 - local pc = getchar(p) + local pc, fam = getchar (p), has_attr(p, attr_jfam) or -1 if (not is_math_letters[pc]) and is_ucs_in_japanese_char(p) and fam>=0 then local f = ltjs.get_stack_table(MJT + 0x100 * sty + fam, -1, tex_getcount('ltj@@stack')) if f ~= -1 then local q = node_new(id_sub_box) local r = node_new(id_glyph); setfield(r, 'next', nil) setfield(r, 'char', pc); setfield(r, 'font', f); setfield(r, 'subtype', 256) - local k = has_attr(r,attr_ykblshift) or 0 - set_attr(r, attr_ykblshift, 0) + local k = has_attr(r,attr_ykblshift) or 0; set_attr(r, attr_ykblshift, 0) -- ltj-setwidth 内で実際の位置補正はおこなうので,補正量を退避 local met = ltjf_font_metric_table[f] r = capsule_glyph_math(r, met, met.char_type[ltjf_find_char_class(pc, met)]); - setfield(q, 'head', r); node_free(p); p=q; - set_attr(r, attr_yablshift, k) + setfield(q, 'head', r); node_free(p); p=q; set_attr(r, attr_yablshift, k) end end elseif pid == id_sub_box and getfield(p, 'head') then -- \hbox で直に与えられた内容は上下位置を補正する必要はない - 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) + 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 @@ -168,8 +160,7 @@ end do local function mlist_callback_ltja(n) local 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 + 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); if not n then return nil end end |