OSDN Git Service

small cleanup
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 12 Mar 2023 08:52:04 +0000 (17:52 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 12 Mar 2023 08:52:04 +0000 (17:52 +0900)
src/ltj-direction.lua
src/ltj-jfont.lua
src/ltj-pretreat.lua
src/ltj-rmlgbm.lua
src/ltj-setwidth.lua

index 0fbe0c6..6576ace 100644 (file)
@@ -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)<id_rule then
+         for box_rule, bi in traverse(h) do
+            if bi<id_rule then
                h = insert_before(h, box_rule, dir_pool[list_dir]())
             end
          end
@@ -1129,8 +1129,7 @@ do
    tex.setattribute(attr_dir, 0)
 
    finalize_inner = function (box)
-      for n in traverse(getlist(box)) do
-         local nid = getid(n)
+      for n, nid in traverse(getlist(box)) do
          if (nid==id_hlist or nid==id_vlist) then
             local ndir = get_box_dir(n, dir_yoko)
             if ndir>=dir_node_auto then -- n is dir_node
index 263297c..d32d9c3 100644 (file)
@@ -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
 
index 9940960..fc26f8d 100644 (file)
@@ -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
index 36fb7f7..33e5d28 100644 (file)
@@ -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
index dd83d7e..38dec61 100644 (file)
@@ -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)