From: Hironori Kitagawa Date: Sat, 1 Oct 2022 04:08:36 +0000 (+0900) Subject: math X-Git-Tag: 20221002.0~6 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=f4fbd787ff849d32eeea043cded0414839a76ef7;p=luatex-ja%2Fluatexja.git math --- diff --git a/src/ltj-math.lua b/src/ltj-math.lua index 28a8fb0..ea2857f 100644 --- a/src/ltj-math.lua +++ b/src/ltj-math.lua @@ -102,7 +102,7 @@ local function conv_jchar_to_hbox(head, sty) setsub(p, cjh_A(getsub(p), sty+1)) setsup(p, cjh_A(getsup(p), sty+1)) elseif pid == id_choice then - setfield(p, 'display', cjh_A(getfield(p, 'display'), 0)) + setfield(p, 'display', cjh_A(getfield(p, 'display'), -1)) 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)) @@ -118,7 +118,9 @@ local function conv_jchar_to_hbox(head, sty) end elseif pid == id_style then local ps = getfield(p, 'style') - if ps == "display'" or ps == 'display' or ps == "text'" or ps == 'text' then + if ps == "display'" or ps == 'display' then + sty = -1 + elseif ps == "text'" or ps == 'text' then sty = 0 elseif ps == "script'" or ps == 'script' then sty = 1 @@ -137,6 +139,7 @@ local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct local setfont = node.direct.setfont local setchar = node.direct.setchar +local max = math.max cjh_A = function (p, sty) if not p then return nil else @@ -148,7 +151,7 @@ cjh_A = function (p, sty) elseif pid == id_mchar then local pc, fam = getchar (p), get_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, getcount(cnt_stack)) + local f = ltjs.get_stack_table(MJT + 0x100 * max(sty,0) + fam, -1, getcount(cnt_stack)) if f ~= -1 then local q = node_new(id_sub_box) local r = node_new(id_glyph, 256); setnext(r, nil); setfont(r, f, pc) diff --git a/src/ltj-setwidth.lua b/src/ltj-setwidth.lua index 3009433..2fa882f 100644 --- a/src/ltj-setwidth.lua +++ b/src/ltj-setwidth.lua @@ -244,8 +244,20 @@ end luatexja.setwidth.capsule_glyph_tate = capsule_glyph_tate do - local cap_math_aux = {[0]=1, [1]=0 } - setmetatable(cap_math_aux, {__index=function() return 0.5 end}) +local font_getfont = font.getfont +local cap_math_aux = { + [-1]=function() return 1 end, + [0]=function() return 1 end, + [1]=function() + local sf, tf = node.family_font(2,1), node.family_font(2,0) + return font_getfont(sf).size/font_getfont(tf).size + end, + [2]=function() + local ssf, tf = node.family_font(2,2), node.family_font(2,0) + return font_getfont(ssf).size/font_getfont(tf).size + end +} +setmetatable(cap_math_aux, {__index=function(t,k) return t[2] end}) local function capsule_glyph_math(p, met, char_data, sty) if not char_data then return nil end local fwidth, pwidth = char_data.width, getwidth(p) @@ -253,9 +265,9 @@ local function capsule_glyph_math(p, met, char_data, sty) fshift.down = char_data.down; fshift.left = char_data.left fshift = call_callback("luatexja.set_width", fshift, met, char_data) local fheight, fdepth = char_data.height, char_data.depth - print(utf.char(getchar(p)), get_attr(p,attr_ykblshift) or 0, get_attr(p,attr_yablshift) or 0, sty) local y_shift = - getfield(p, 'yoffset') - + cap_math_aux[sty]*((get_attr(p,attr_ykblshift) or 0) - (get_attr(p,attr_yablshift) or 0)) + + cap_math_aux[sty]()* + ((get_attr(p,attr_ykblshift) or 0) - (get_attr(p,attr_yablshift) or 0)) setfield(p, 'yoffset', -fshift.down) setfield(p, 'xoffset', getfield(p, 'xoffset') + char_data.align*(fwidth-pwidth) - fshift.left) local box = node_new(id_hlist, nil, p);