From 073ead8a8b0dfaa0eac7f9d746412c40328e57b4 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Sun, 12 Mar 2023 17:52:04 +0900 Subject: [PATCH] small cleanup --- src/ltj-direction.lua | 7 +++---- src/ltj-jfont.lua | 19 ++++++++++++++++--- src/ltj-pretreat.lua | 37 ++++++++++--------------------------- src/ltj-rmlgbm.lua | 8 +++----- src/ltj-setwidth.lua | 7 +++---- 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/ltj-direction.lua b/src/ltj-direction.lua index 0fbe0c6..6576ace 100644 --- a/src/ltj-direction.lua +++ b/src/ltj-direction.lua @@ -1008,8 +1008,8 @@ do local n = h; h = node_remove(h,h) node_free(n) end - for box_rule in traverse(h) do - if getid(box_rule)=dir_node_auto then -- n is dir_node diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 263297c..d32d9c3 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -620,9 +620,22 @@ function luatexja.jfont.clear_alt_font(bfnt) end ------ used in ltjp.suppress_hyphenate_ja callback -function luatexja.jfont.replace_altfont(pf, pc) - local a = alt_font_table[pf] - return a and a[pc] or pf +do + local compat_ig = {} + for i=0xf900, 0xfaff do compat_ig[i] = true end + for i=0x2f800, 0x2fa1f do compat_ig[i] = true end + local protect_glyph = node.direct.protect_glyph +-- + local getfont, setfont = node.direct.getfont, node.direct.setfont + function luatexja.jfont.replace_altfont(a, pc, p) + local pf = get_attr(p, a); pf = (pf and pf>0 and pf) or getfont(p) + local af = alt_font_table[pf] + pf = af and af[pc] or pf; setfont(p, pf) + if compat_ig[pc] and font_metric_table[pf].protect_compat_ig then + protect_glyph(p) + end + return pf + end end ------ for LaTeX interface diff --git a/src/ltj-pretreat.lua b/src/ltj-pretreat.lua index 9940960..fc26f8d 100644 --- a/src/ltj-pretreat.lua +++ b/src/ltj-pretreat.lua @@ -110,7 +110,7 @@ do setfield(b, 'type', 100); setfield(b, 'user_id', JA_AL_BDD); insert_before(head, p, b) end - setlang(p, lang_ja) + setlang(p, lang_ja); ltjs_orig_char_table[p], prev_chartype = pc, 2 elseif prev_chartype==2 then local b = node_new(id_whatsit,sid_user); @@ -137,16 +137,9 @@ local set_box_stack_level do local ltjs_report_stack_level = ltjs.report_stack_level local ltjf_font_metric_table = ltjf.font_metric_table -local font_getfont = font.getfont -local traverse_id = node.direct.traverse_id +local traverse_glyph = node.direct.traverse_glyph local cnt_stack = luatexbase.registernumber 'ltj@@stack' local texget, getvalue = tex.get, node.direct.getdata --- - local compat_ig = {} - for i=0xf900, 0xfaff do compat_ig[i] = true end - for i=0x2f800, 0x2fa1f do compat_ig[i] = true end - local protect_glyph = node.direct.protect_glyph --- function set_box_stack_level(head, mode) local box_set = 0 if mode then @@ -161,28 +154,18 @@ function set_box_stack_level(head, mode) ltjs_report_stack_level(getcount(cnt_stack) + box_set) for _,p in pairs(wtd) do node_free(p) end if ltjs.list_dir == dir_tate then - for p in traverse_id(id_glyph,to_direct(head)) do - if has_attr(p, attr_icflag, 0) and getlang(p)==lang_ja then - local pf, pc = get_attr(p, attr_curtfnt), ltjs_orig_char_table[p] - local nf = ltjf_replace_altfont( (pf and pf>0 and pf) or getfont(p), pc) - setfont(p, nf) - if compat_ig[pc] and ltjf_font_metric_table[nf].protect_compat_ig then - protect_glyph(p) - end - if ltjf_font_metric_table[nf].vert_activated then - pc = ltjf_font_metric_table[nf].vform[pc]; if pc then setchar(p, pc) end + for p, _, pc in traverse_glyph(to_direct(head)) do + if getlang(p)==lang_ja and has_attr(p, attr_icflag, 0) then + local pf = ltjf_replace_altfont(attr_curtfnt, pc, p) + if ltjf_font_metric_table[pf].vert_activated then + pc = ltjf_font_metric_table[pf].vform[pc]; if pc then setchar(p, pc) end end end end else - for p in traverse_id(id_glyph,to_direct(head)) do - if has_attr(p, attr_icflag, 0) and getlang(p)==lang_ja then - local pf, pc = get_attr(p, attr_curjfnt), ltjs_orig_char_table[p] - local nf = ltjf_replace_altfont( (pf and pf>0 and pf) or getfont(p), pc) - setfont(p, nf) - if compat_ig[pc] and ltjf_font_metric_table[nf].protect_compat_ig then - protect_glyph(p) - end + for p, _, pc in traverse_glyph(to_direct(head)) do + if getlang(p)==lang_ja and has_attr(p, attr_icflag, 0) then + ltjf_replace_altfont(attr_curjfnt, pc, p) end end end diff --git a/src/ltj-rmlgbm.lua b/src/ltj-rmlgbm.lua index 36fb7f7..33e5d28 100644 --- a/src/ltj-rmlgbm.lua +++ b/src/ltj-rmlgbm.lua @@ -222,7 +222,7 @@ end -- local cidf_vert_processor do - local traverse_id, is_node = node.direct.traverse_id, node.is_node + local traverse_glyph, is_node = node.direct.traverse_glyph, node.is_node local to_direct = node.direct.todirect local id_glyph = node.id 'glyph' local getfont = node.direct.getfont @@ -235,10 +235,8 @@ do if head and luatexja.jfont.font_metric_table[fnum] and luatexja.jfont.font_metric_table[fnum].vert_activated then local vt = fontdata.ltj_vert_table local nh = is_node(head) and to_direct(head) or head - for n in traverse_id(id_glyph, head) do - if getfont(n)==fnum then - local c = getchar(n); setchar(n, vt[c] or c) - end + for n, f, c in traverse_glyph(head) do + if f==fnum then setchar(n, vt[c] or c) end end return head, false end diff --git a/src/ltj-setwidth.lua b/src/ltj-setwidth.lua index dd83d7e..38dec61 100644 --- a/src/ltj-setwidth.lua +++ b/src/ltj-setwidth.lua @@ -33,7 +33,6 @@ local setheight = node.direct.setheight local setdepth = node.direct.setdepth local setlist = node.direct.setlist -local node_traverse_id = node.direct.traverse_id local node_traverse = node.direct.traverse local node_copy = node.direct.copy local node_remove = node.direct.remove @@ -281,8 +280,7 @@ end -- 数式の位置補正 function luatexja.setwidth.apply_ashift_math(head, last, attr_ablshift) - for p in node_traverse(head) do - local pid = getid(p) + for p, pid in node_traverse(head) do if p==last then return elseif (get_attr(p, attr_icflag) or 0) ~= PROCESSED then @@ -309,11 +307,12 @@ do local attr_tablshift = luatexbase.attributes['ltj@tablshift'] local attr_ablshift local disc, tex_dir + local traverse_glyph = node.direct.traverse_glyph local function ashift_disc_inner(field) local head = getfield(disc, field) if not head then return end local y_adjust, node_depth, adj_depth = 0, 0, 0 - for lp in node_traverse_id(id_glyph, head) do + for lp in traverse_glyph(head) do y_adjust = get_attr(lp,attr_ablshift) or 0 local ld = getdepth(lp) node_depth = max(ld + min(y_adjust, 0), node_depth) -- 2.11.0