summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-02-06 23:28:44 +0000
committerKarl Berry <karl@freefriends.org>2014-02-06 23:28:44 +0000
commitc33fed8d37bc51a8a9ff5a5f1a806dac56765c8d (patch)
treef95a9e2a7ddf6ffa449a8d74ecaca762ab845c09 /Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua
parent55bbd0a3dd6e4f70a9cae6283e0e84b2aba02989 (diff)
luatexja (4feb14)
git-svn-id: svn://tug.org/texlive/trunk@32895 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua104
1 files changed, 59 insertions, 45 deletions
diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua
index 5f9e650c5ca..4aefe63bb46 100644
--- a/Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua
+++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-math.lua
@@ -8,11 +8,24 @@ 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 node_new = node.new
-local node_next = node.next
-local node_free = node.free
-local has_attr = node.has_attribute
-local set_attr = node.set_attribute
+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
+-- 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
+
+local nullfunc = function(n) return n end
+local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
+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_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']
@@ -46,38 +59,37 @@ local conv_jchar_to_hbox_A
-- sty : 0 (display or text), 1 (script), >=2 (scriptscript)
local function conv_jchar_to_hbox(head, sty)
- local p = head
- local bhead = head
- while p do
- if p.id == id_simple or p.id == id_accent then
- p.nucleus = conv_jchar_to_hbox_A(p.nucleus, sty)
- p.sub = conv_jchar_to_hbox_A(p.sub, sty + 1)
- p.sup = conv_jchar_to_hbox_A(p.sup, sty + 1)
- elseif p.id == id_choice then
- p.display = conv_jchar_to_hbox(p.display, 0)
- p.text = conv_jchar_to_hbox(p.text, 0)
- p.script = conv_jchar_to_hbox(p.script, 1)
- p.scriptscript = conv_jchar_to_hbox(p.scriptscript, 2)
- elseif p.id == id_frac then
- p.num = conv_jchar_to_hbox_A(p.num, sty + 1)
- p.denom = conv_jchar_to_hbox_A(p.denom, sty + 1)
- elseif p.id == id_radical then
- p.nucleus = conv_jchar_to_hbox_A(p.nucleus, sty)
- p.sub = conv_jchar_to_hbox_A(p.sub, sty + 1)
- p.sup = conv_jchar_to_hbox_A(p.sup, sty + 1)
- if p.degree then
- p.degree = conv_jchar_to_hbox_A(p.degree, sty + 1)
+ 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))
+ 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
+ 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))
+ 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))
+ 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
- elseif p.id == id_style then
- if p.style == "display'" or p.style == 'display'
- or p.style == "text'" or p.style == 'text' then
+ 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 p.style == "script'" or p.style == 'script' then
+ elseif ps == "script'" or ps == 'script' then
sty = 1
else sty = 2
end
end
- p = node.next(p)
end
return head
end
@@ -85,37 +97,39 @@ end
local MJT = luatexja.stack_table_index.MJT
local MJS = luatexja.stack_table_index.MJS
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)
if not p then return nil
else
- local pid = p.id
+ local pid = getid(p)
if pid == id_sub_mlist then
- if p.head then
- p.head = conv_jchar_to_hbox(p.head, sty)
+ if getfield(p, 'head') then
+ 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
- if (not is_math_letters[p.char]) and ltjc.is_ucs_in_japanese_char(p) and fam>=0 then
- local f = ltjs.get_penalty_table(MJT + 0x100 * sty + fam, -1, tex_getcount('ltj@@stack'))
+ local pc = getchar(p)
+ 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); r.next = nil
- r.char = p.char; r.font = f; r.subtype = 256
+ 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)
-- ltj-setwidth 内で実際の位置補正はおこなうので,補正量を退避
- ltjw.head = r;
local met = ltjf_font_metric_table[f]
- ltjw.capsule_glyph(r, tex.mathdir , true, met, ltjf_find_char_class(p.char, met));
- q.head = ltjw.head; node_free(p); p=q;
- set_attr(q.head, attr_yablshift, k)
+ r = capsule_glyph_math(r, met, ltjf_find_char_class(pc, met));
+ setfield(q, 'head', r); node_free(p); p=q;
+ set_attr(r, attr_yablshift, k)
end
end
- elseif pid == id_sub_box and p.head then
+ elseif pid == id_sub_box and getfield(p, 'head') then
-- \hbox で直に与えられた内容は上下位置を補正する必要はない
- set_attr(p.head, attr_icflag, PROCESSED)
+ set_attr(getfield(p, 'head'), attr_icflag, PROCESSED)
end
end
return p
@@ -123,7 +137,7 @@ end
luatexbase.add_to_callback('mlist_to_hlist',
function (n, display_type, penalties)
- local head = conv_jchar_to_hbox(n, 0);
+ local head = to_node(conv_jchar_to_hbox(to_direct(n), 0))
head = node.mlist_to_hlist(head, display_type, penalties)
return head
end,'ltj.mlist_to_hlist', 1)