OSDN Git Service

use getFOO/setFOO helpers instead of getfield/setfield
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 16 Aug 2022 07:21:59 +0000 (16:21 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 16 Aug 2022 07:21:59 +0000 (16:21 +0900)
Squashed commit of the following:

commit 3ecefd04fb3c2e0dea1764b813ed8840c033d0d0
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Tue Aug 16 16:20:02 2022 +0900

    removed trailing spaces

commit c0c3f5dfabdd5148288a5602ebe7caccb3bd2a8b
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Sun Aug 14 16:50:55 2022 +0900

    {g/s}etlist whenever possible

commit f9e21bbe9598663f8a19bb4152e65c3f7a6e71b4
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Sun Aug 14 14:23:09 2022 +0900

    node.direct.free -> node.direct.flush_node if possible

commit 908d5f6d2e51863129109ed661c4dbaa9b517f9c
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Sun Aug 14 07:58:42 2022 +0900

    fix memory leak of  luatexja.jfont.append_italic()

commit 52cce4c3dfc5c9adec707951d8c522bd349a8cb7
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Sat Aug 13 18:11:39 2022 +0900

    ltj-direction.lua: format change

commit 2dc75338b41e7f938b6c36ea1d1307aed1263096
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Sat Aug 13 11:51:00 2022 +0900

    more getfield(n, FOO) -> getFOO(n)

commit 68c576690e0aa423e3c0dd73d6c30ec9b9ddcb22
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Fri Aug 12 22:05:48 2022 +0900

    use {g,s}et{nucleus,sub,sup,shift,penalty,subtype, ...}

commit d49c708434627a038cf20bcb6a2bc8e323fe6109
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Fri Aug 12 18:14:16 2022 +0900

    Use helpers: setnext,{g/s}et{lang.kern}

commit ba1a9ceec35115400ff7ab8b1c71d9b7ceff8ee0
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Fri Aug 12 05:20:21 2022 +0900

    clear boxes which are unused

commit 43093c57ff8c9df3b891c8ca8b0b9b345cac1af3
Author: Hironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Date:   Thu Aug 11 16:10:15 2022 +0900

    WIP: unnecessary attribute list

16 files changed:
doc/luatexja.dtx
src/ltj-adjust.lua
src/ltj-direction.lua
src/ltj-inputbuf.lua
src/ltj-jfmglue.lua
src/ltj-jfont.lua
src/ltj-lineskip.lua
src/ltj-math.lua
src/ltj-otf.lua
src/ltj-pretreat.lua
src/ltj-ruby.lua
src/ltj-setwidth.lua
src/luatexja.lua
src/patches/lltjfont.sty
src/patches/lltjp-atbegshi.sty
src/patches/lltjp-everyshi.sty

index 58f2cc1..d2aefcf 100644 (file)
@@ -11912,12 +11912,16 @@ direction~whatsit内部のノードリストに,\textit{dir\_box}として格
        {\fboxsep0pt\fcolorbox{cyan}{white}%
     {\large\KOZM\ltjjachar"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})%"
   }
+  \def\DH#1#2#3#4{%
+       {\fboxsep0pt\fcolorbox{cyan}{white}%
+    {\large\ltjjachar"#1#2#3#4}}\ (\texttt{U+#1#2#3#4})%"
+  }
   \caption{\LuaTeX-ja標準で行われる縦組形への置換}
   \label{tab:vert_replace}\small\centering
   \begin{tabular}{*{3}{l@{}>{${}\longmapsto{}$}c@{}l}}
        \toprule
-       \D 3001&&\D FE11&\D 3002&&\D FE12&\D 3016&&\D FE17\\
-       \D 3017&&\D FE18&\D 2026&&\D FE19&\D 2025&&\D FE30\\
+       \D 3001&&\D FE11&\D 3002&&\D FE12&\D 3016&&\DH FE17\\
+       \D 3017&&\DH FE18&\D 2026&&\D FE19&\D 2025&&\D FE30\\
        \D 2014&&\D FE31&\D 2013&&\D FE32&\D FF3F&&\D FE33\\
        \D FF08&&\D FE35&\D FF09&&\D FE36&\D FF5B&&\D FE37\\
        \D FF5D&&\D FE38&\D 3014&&\D FE39&\D 3015&&\D FE3A\\
index 053b63a..eb1cecc 100644 (file)
@@ -12,18 +12,26 @@ luatexja.adjust = luatexja.adjust or {}
 local to_node = node.direct.tonode
 local to_direct = node.direct.todirect
 
-local setfield = node.direct.setfield
-local setglue = luatexja.setglue
 local getfield = node.direct.getfield
 local getlist = node.direct.getlist
 local getid = node.direct.getid
 local getfont = node.direct.getfont
 local getsubtype = node.direct.getsubtype
+local getlang = node.direct.getlang
+local getkern = node.direct.getkern
+local getshift = node.direct.getshift
+local getwidth = node.direct.getwidth    
+local getdepth = node.direct.getdepth
+local setfield = node.direct.setfield
+local setpenalty = node.direct.setpenalty
+local setglue = luatexja.setglue
+local setkern = node.direct.setkern
+local setlist = node.direct.setlist
 
 local node_traverse_id = node.direct.traverse_id
 local node_new = node.direct.new
 local node_next = node.direct.getnext
-local node_free = node.direct.free
+local node_free = node.direct.flush_node or node.direct.free
 local node_prev = node.direct.getprev
 local node_tail = node.direct.tail
 local has_attr = node.direct.has_attribute
@@ -130,7 +138,7 @@ function get_total_stretched(p)
    if not total_sh.order then
        total_sh.order, total_sh[-65536] = -1,0.1 -- dummy
    end
-   return getfield(p,'width') - dimensions(ph)
+   return getwidth(p) - dimensions(ph)
 end
 end
 
@@ -152,7 +160,7 @@ local function aw_step1(p, total)
        -- 無限大のグルーで処理が行われているときは処理中止.
        return total, false
    end
-   if xi == id_glyph and getfield(x, 'lang')==lang_ja then
+   if xi == id_glyph and getlang(x)==lang_ja then
       -- 和文文字
       xc = x
    elseif xi == id_hlist and get_attr_icflag(x) == PACKED then
@@ -186,7 +194,7 @@ local function aw_step1(p, total)
    end)
    if eadt[eadt_ratio[1][1]]~=0 then
       local kn = node_new(id_kern, 1)
-      setfield(kn, 'kern', eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND)
+      setkern(kn, eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND)
       insert_after(head, x, kn)
       return eadt_ratio[1][3], true
    else
@@ -196,6 +204,7 @@ end
 
 -- step 1 最終行用
 local min, max = math.min, math.max
+local setsubtype = node.direct.setsubtype
 local function aw_step1_last(p, total)
    local head = getlist(p)
    local x = node_tail(head); if not x then return total, false end
@@ -204,7 +213,7 @@ local function aw_step1_last(p, total)
    if getid(pf) ~= id_glue or getsubtype(pf) ~= 15 then return total, false end
    x = node_prev(node_prev(pf))
    local xi, xc = getid(x)
-   if xi == id_glyph and getfield(x, 'lang')==lang_ja then
+   if xi == id_glyph and getlang(x)==lang_ja then
       -- 和文文字
       xc = x
    elseif xi == id_hlist and get_attr_icflag(x) == PACKED then
@@ -235,11 +244,11 @@ local function aw_step1_last(p, total)
       return total, false
    end
    -- 続行条件2: min(eadt[1], 0)<= \parfillskip <= max(eadt[#eadt], 0)
-   local pfw = getfield(pf, 'width') 
+   local pfw = getwidth(pf)
      + (total>0 and getfield(pf, 'stretch') or -getfield(pf, 'shrink')) *getfield(p, 'glue_set') 
    if pfw<min(0,eadt[1]) or max(0,eadt[#eadt])<pfw then return total, false end
    -- \parfillskip を 0 にする
-   total = total + getfield(pf, 'width') 
+   total = total + getwidth(pf)
    total_st.order, total_sh.order = 0, 0
    if getfield(pf, 'stretch_order')==0 then 
       local i = at2pr_st[-1] 
@@ -253,7 +262,7 @@ local function aw_step1_last(p, total)
       total_sh[i] = total_sh[i] - getfield(pf, 'shrink') 
       total_sh.order = (total_sh[0]==0) and -1 or 0
    end
-   setfield(pf, 'subtype', 1); setglue(pf)
+   setsubtype(pf, 1); setglue(pf)
    local eadt_ratio = {}
    for i, v in ipairs(eadt) do
       local t = total - v
@@ -273,7 +282,7 @@ local function aw_step1_last(p, total)
    end)
    if eadt[eadt_ratio[1][1]]~=0 then
       local kn = node_new(id_kern, 1)
-      setfield(kn, 'kern', eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND)
+      setkern(kn, eadt[eadt_ratio[1][1]]); set_attr(kn, attr_icflag, LINEEND)
       insert_after(head, x, kn)
       return eadt_ratio[1][3], true
    else
@@ -289,9 +298,9 @@ local node_hpack = node.direct.hpack
 local function repack(p)
    local orig_of, orig_hfuzz, orig_hbad = tex.overfullrule, tex.hfuzz, tex.hbadness
    tex.overfullrule=0; tex.hfuzz=1073741823; tex.hbadness=10000
-   local f = node_hpack(getlist(p), getfield(p, 'width'), 'exactly')
+   local f = node_hpack(getlist(p), getwidth(p), 'exactly')
    tex.overfullrule=orig_of; tex.hfuzz=orig_hfuzz; tex.hbadness=orig_hbad
-   setfield(f, 'head', nil)
+   setlist(f, nil)
    setfield(p, 'glue_set', getfield(f, 'glue_set'))
    setfield(p, 'glue_order', getfield(f, 'glue_order'))
    setfield(p, 'glue_sign', getfield(f, 'glue_sign'))
@@ -358,27 +367,27 @@ do
          if not eadt then return end
          if eadt[1]~=0 then
             local x = node_new(id_kern, 1)
-            setfield(x, 'kern', eadt[1]); set_attr(x, attr_icflag, LINEEND)
+            setkern(x, eadt[1]); set_attr(x, attr_icflag, LINEEND)
             insert_before(head, np.first, x)
          end
          local eadt_num = #eadt
          for i=2,eadt_num do
             local x = node_new(id_penalty)
-            setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU)
+            setpenalty(x, 0); set_attr(x, attr_icflag, KINSOKU)
             insert_before(head, np.first, x); Bp[#Bp+1] = x
             local x = node_new(id_kern, 1)
-            setfield(x, 'kern', eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND)
+            setkern(x, eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND)
             insert_before(head, np.first, x)
          end
          if eadt_num>1 or eadt[1]~=0 then
             local x = node_new(id_penalty)
-            setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU)
+            setpenalty(x, 0); set_attr(x, attr_icflag, KINSOKU)
             insert_before(head, np.first, x); Bp[#Bp+1] = x
             local x = node_new(id_kern, 1)
-            setfield(x, 'kern', -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND)
+            setkern(x, -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND)
             insert_before(head, np.first, x)
             local x = node_new(id_penalty)
-            setfield(x, 'penalty', 10000); set_attr(x, attr_icflag, KINSOKU)
+            setpenalty(x, 10000); set_attr(x, attr_icflag, KINSOKU)
             insert_before(head, np.first, x); Bp[#Bp+1] = x
          end
       end
@@ -496,7 +505,7 @@ do
   local insert = table.insert
   local rangedimensions, max = node.direct.rangedimensions, math.max
   local function profile_inner(box, range, ind, vmirrored, adj)
-    local w_acc, d_before = getfield(box,'shift'), 0
+    local w_acc, d_before = getshift(box), 0
     local x = getlist(box); local xn = node_next(x)
     while x do
       local w, h, d
@@ -528,7 +537,7 @@ do
       end
       if lmin==1/0 then lmin = bw end
       return lmin, 
-         bw - lmin - getfield(before, 'depth')
+         bw - lmin - getdepth(before)
             - getfield(after, mirrored and 'depth' or 'height')
     end
   end
index 3dafb50..c564f87 100644 (file)
@@ -9,25 +9,30 @@ luatexja.direction = {}
 local attr_dir = luatexbase.attributes['ltj@dir']
 local attr_icflag = luatexbase.attributes['ltj@icflag']
 
+local dnode = node.direct
 local cat_lp = luatexbase.catcodetables['latex-package']
-local to_node = node.direct.tonode
-local to_direct = node.direct.todirect
-local has_attr = node.direct.has_attribute
-local set_attr = node.direct.set_attribute
-local insert_before = node.direct.insert_before
-local insert_after = node.direct.insert_after
-local getid = node.direct.getid
-local getsubtype = node.direct.getsubtype
-local getlist = node.direct.getlist
-local setfield = node.direct.setfield
-local getfield = node.direct.getfield
-local node_new = node.direct.new
-local node_tail = node.direct.tail
-local node_free = node.direct.free
-local node_remove = node.direct.remove
-local node_next = node.direct.getnext
-local traverse = node.direct.traverse
-local traverse_id = node.direct.traverse_id
+local to_node = dnode.tonode
+local to_direct = dnode.todirect
+local has_attr = dnode.has_attribute
+local set_attr = dnode.set_attribute
+local insert_before = dnode.insert_before
+local insert_after = dnode.insert_after
+local getid = dnode.getid
+local getsubtype = dnode.getsubtype
+local getlist = dnode.getlist
+local getfield = dnode.getfield
+local getwhd = dnode.getwhd
+local setfield = dnode.setfield
+local setwhd = dnode.setwhd
+local setnext = dnode.setnext
+local setlist = dnode.setlist
+
+local node_new = dnode.new
+local node_free = dnode.flush_node or dnode.free
+local node_remove = dnode.remove
+local node_next = dnode.getnext
+local traverse = dnode.traverse
+local traverse_id = dnode.traverse_id
 local start_time_measure, stop_time_measure
     = ltjb.start_time_measure, ltjb.stop_time_measure
 local abs = math.abs
@@ -37,8 +42,6 @@ local id_hlist   = node.id 'hlist'
 local id_vlist   = node.id 'vlist'
 local id_whatsit = node.id 'whatsit'
 local sid_save   = node.subtype 'pdf_save'
-local sid_restore= node.subtype 'pdf_restore'
-local sid_matrix = node.subtype 'pdf_setmatrix'
 local sid_user   = node.subtype 'user_defined'
 
 local tex_nest = tex.nest
@@ -63,14 +66,14 @@ local page_direction
 --
 local dir_pool
 do
-   local node_copy = node.direct.copy
+   local node_copy = dnode.copy
    dir_pool = {}
    for _,i in pairs({dir_tate, dir_yoko, dir_dtou, dir_utod}) do
       local w = node_new(id_whatsit, sid_user)
-      set_attr(w, attr_dir, i)
+      dnode.setattributelist(w, nil) 
+      set_attr(w, attr_dir, i); set_attr(w, attr_icflag, 0)
       setfield(w, 'user_id', DIR)
-      setfield(w, 'type', 110)
-      setfield(w, 'next', nil)
+      setfield(w, 'type', 110); setnext(w, nil)
       dir_pool[i] = function () return node_copy(w) end
    end
 end
@@ -221,7 +224,7 @@ do
                page_direction = v -- for first call of \yoko (in luatexja-core.sty)
             else
               if luatexja.debug then
-                luatexja.ext_show_node_list(node.direct.tonode(h),'>> ', texio.write_nl)
+                luatexja.ext_show_node_list(dnode.tonode(h),'>> ', texio.write_nl)
               end
               ltjb.package_error(
                  'luatexja',
@@ -283,7 +286,8 @@ do
          if hd  then
             for p in traverse_id(15, hd) do -- unset
                if get_box_dir(p, 0)==0 then
-                  setfield(p, 'head', create_dir_whatsit(getlist(p), 'fin_row', ltjs.list_dir))
+                  setfield(p, 'head', create_dir_whatsit(getfield(p, 'head'), 'fin_row', ltjs.list_dir))
+                  -- We cannot use setlist and getlist, since they don't support unset_node
                end
             end
             set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
@@ -307,7 +311,7 @@ do
       -- start 側は ltj-debug.lua に
       local new_dir = ltjs.list_dir
       for line in traverse_id(id_hlist, to_direct(h)) do
-         setfield(line, 'head', create_dir_whatsit(getlist(line), gc, new_dir) )
+         setlist(line, create_dir_whatsit(getlist(line), gc, new_dir) )
       end
       ensure_tex_attr(attr_dir, 0)
       return h
@@ -351,7 +355,7 @@ do
          local n = node_next(hd)
          local w = create_dir_whatsit(hd, gc, ltjs.list_dir)
          -- move dir whatsit after hd
-         setfield(hd, 'next', w); setfield(w, 'next', n); 
+         setnext(hd, w); setnext(w, n)
          return hd
       else return create_dir_whatsit(hd, gc, ltjs.list_dir)
       end
@@ -361,6 +365,10 @@ end
 -- dir_node に包む方法を書いたテーブル
 local dir_node_aux
 do
+   local setkern = dnode.setkern
+   local setshift = dnode.setshift
+   local sid_restore= node.subtype 'pdf_restore'
+   local sid_matrix = node.subtype 'pdf_setmatrix'
    local floor = math.floor
    local get_h =function (w,h,d) return h end
    local get_d =function (w,h,d) return d end
@@ -372,6 +380,21 @@ do
    local get_w_neg =function (w,h,d) return -w end
    local get_w =function (w,h,d) return w end
    local zero = function() return 0 end
+   local function gen_kern(arg, b, w,h,d,dw,dh,dd)
+      local nn = node_new(id_kern)
+      setkern(nn, arg(w, h, d, dw, dh, dd)); return nn
+   end
+   local function gen_whatsit(arg)
+      return node_new(id_whatsit, arg)
+   end
+   local function gen_rotate(arg)
+      local nn = node_new(id_whatsit, sid_matrix)
+      setfield(nn, 'data', arg); return nn
+   end
+   local function gen_box(arg, b, w,h,d,dw,dh,dd)
+      local nn = b; setnext(b, nil)
+      setshift(nn, arg(w, h, d, dw, dh, dd)); return nn
+   end
    dir_node_aux = {
       [dir_yoko] = { -- yoko を
          [dir_tate] = { -- tate 中で組む
@@ -379,20 +402,20 @@ do
             height = get_w_half,
             depth  = get_w_half_rem,
             [id_hlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 1 -1 0' },
-               { 'kern', function(w,h,d,nw,nh,nd) return -nd end },
-               { 'box' , get_h},
-               { 'kern', function(w,h,d,nw,nh,nd) return nd-w end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 1 -1 0' },
+               { gen_kern, function(w,h,d,nw,nh,nd) return -nd end },
+               { gen_box , get_h},
+               { gen_kern, function(w,h,d,nw,nh,nd) return nd-w end },
+               { gen_whatsit, sid_restore },
             },
             [id_vlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 1 -1 0' },
-               { 'kern' , zero },
-               { 'box' , function(w,h,d,nw,nh,nd) return -nh-nd end },
-               { 'kern', get_h_d_neg},
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 1 -1 0' },
+               { gen_kern , zero },
+               { gen_box , function(w,h,d,nw,nh,nd) return -nh-nd end },
+               { gen_kern, get_h_d_neg},
+               { gen_whatsit, sid_restore },
             },
          },
          [dir_dtou] = { -- dtou 中で組む
@@ -400,19 +423,19 @@ do
             height = get_w,
             depth  = zero,
             [id_hlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 -1 1 0' },
-               { 'kern', function(w,h,d,nw,nh,nd) return -nh end },
-               { 'box', get_d_neg },
-               { 'kern', function(w,h,d,nw,nh,nd) return nh-w end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 -1 1 0' },
+               { gen_kern, function(w,h,d,nw,nh,nd) return -nh end },
+               { gen_box, get_d_neg },
+               { gen_kern, function(w,h,d,nw,nh,nd) return nh-w end },
+               { gen_whatsit, sid_restore },
             },
             [id_vlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 -1 1 0' },
-               { 'kern', get_h_d_neg },
-               { 'box', zero },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 -1 1 0' },
+               { gen_kern, get_h_d_neg },
+               { gen_box, zero },
+               { gen_whatsit, sid_restore },
             },
          },
       },
@@ -422,19 +445,19 @@ do
             height = get_w,
             depth  = zero,
             [id_hlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 -1 1 0' },
-               { 'kern', function (w,h,d,nw,nh,nd) return -nh end },
-               { 'box' , get_d_neg },
-               { 'kern', function (w,h,d,nw,nh,nd) return nh-w end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 -1 1 0' },
+               { gen_kern, function (w,h,d,nw,nh,nd) return -nh end },
+               { gen_box , get_d_neg },
+               { gen_kern, function (w,h,d,nw,nh,nd) return nh-w end },
+               { gen_whatsit, sid_restore },
             },
             [id_vlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 -1 1 0' },
-               { 'kern', get_h_d_neg },
-               { 'box', zero },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 -1 1 0' },
+               { gen_kern, get_h_d_neg },
+               { gen_box, zero },
+               { gen_whatsit, sid_restore },
             },
          },
          [dir_dtou] = { -- dtou 中で組む
@@ -442,18 +465,18 @@ do
             height = get_d,
             depth  = get_h,
             [id_hlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '-1 0 0 -1' },
-               { 'kern', get_w_neg },
-               { 'box',  function (w,h,d,nw,nh,nd) return h-nd end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '-1 0 0 -1' },
+               { gen_kern, get_w_neg },
+               { gen_box,  function (w,h,d,nw,nh,nd) return h-nd end },
+               { gen_whatsit, sid_restore },
             },
             [id_vlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '-1 0 0 -1' },
-               { 'kern', get_h_d_neg },
-               { 'box', get_w_neg },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '-1 0 0 -1' },
+               { gen_kern, get_h_d_neg },
+               { gen_box, get_w_neg },
+               { gen_whatsit, sid_restore },
             },
          },
       },
@@ -463,20 +486,20 @@ do
             height = get_w,
             depth  = zero,
             [id_hlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '0 1 -1 0' },
-               { 'kern', function (w,h,d,nw,nh,nd) return -nd end },
-               { 'box', get_h },
-               { 'kern', function (w,h,d,nw,nh,nd) return nd-w end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 1 -1 0' },
+               { gen_kern, function (w,h,d,nw,nh,nd) return -nd end },
+               { gen_box, get_h },
+               { gen_kern, function (w,h,d,nw,nh,nd) return nd-w end },
+               { gen_whatsit, sid_restore },
             },
             [id_vlist] = {
-               { 'kern', zero },
-               { 'whatsit', sid_save },
-               { 'rotate', '0 1 -1 0' },
-               { 'box', function (w,h,d,nw,nh,nd) return -nd-nh end },
-               { 'kern', get_h_d_neg },
-               { 'whatsit', sid_restore },
+               { gen_kern, zero },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '0 1 -1 0' },
+               { gen_box, function (w,h,d,nw,nh,nd) return -nd-nh end },
+               { gen_kern, get_h_d_neg },
+               { gen_whatsit, sid_restore },
             },
          },
          [dir_tate] = { -- tate 中で組む
@@ -484,19 +507,19 @@ do
             height = get_d,
             depth  = get_h,
             [id_hlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', '-1 0 0 -1' },
-               { 'kern', get_w_neg },
-               { 'box', function (w,h,d,nw,nh,nd) return h-nd end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, '-1 0 0 -1' },
+               { gen_kern, get_w_neg },
+               { gen_box, function (w,h,d,nw,nh,nd) return h-nd end },
+               { gen_whatsit, sid_restore },
             },
             [id_vlist] = {
-               { 'whatsit', sid_save },
-               { 'rotate', ' -1 0 0 -1' },
-               { 'kern', function (w,h,d,nw,nh,nd) return -nh-nd end },
-               { 'box', get_w_neg },
-               { 'kern', function (w,h,d,nw,nh,nd) return nh+nd-h-d end },
-               { 'whatsit', sid_restore },
+               { gen_whatsit, sid_save },
+               { gen_rotate, ' -1 0 0 -1' },
+               { gen_kern, function (w,h,d,nw,nh,nd) return -nh-nd end },
+               { gen_box, get_w_neg },
+               { gen_kern, function (w,h,d,nw,nh,nd) return nh+nd-h-d end },
+               { gen_whatsit, sid_restore },
             },
          },
       },
@@ -508,8 +531,7 @@ end
 function get_box_dir(b, default)
    start_time_measure 'get_box_dir'
    local dir = has_attr(b, attr_dir) or 0
-   local bh = getfield(b,'head')
-   -- b は insert node となりうるので getlist() は使えない
+   local bh = getfield(b, 'head') -- We cannot use getlist since b may be an unset_node.
    local c
    if bh~=0 then -- bh != nil
       for bh in traverse_id(id_whatsit, bh) do
@@ -548,7 +570,7 @@ do
                      local d = hd
                      nh, hd = node_remove(nh, hd)
                      if is_copy==true and (not dir_backup) then
-                        dir_backup = d; setfield(dir_backup, 'next', nil)
+                        dir_backup = d; setnext(dir_backup, nil)
                      else
                         node_free(d)
                      end
@@ -556,7 +578,7 @@ do
                   hd = node_next(hd)
                end
             end
-            setfield(bd, 'head', nh)
+            setlist(bd, nh)
          end
       end
       if luatexja.global_temp and tex.globaldefs~=luatexja.global_temp then
@@ -569,8 +591,8 @@ do
       if b then
          local bd = to_direct(b)
          if dir_backup then
-            setfield(dir_backup, 'next', getlist(bd))
-            setfield(bd, 'head', dir_backup)
+            setnext(dir_backup, getlist(bd))
+            setlist(bd, dir_backup)
             dir_backup = nil
          end
       end
@@ -587,23 +609,26 @@ local function unwrap_dir_node(b, head, box_dir)
    if head then
       nh = insert_before(head, b, bh)
       nh, nb = node_remove(nh, b)
-      setfield(b, 'next', nil)
-      node_free(b)
+      setnext(b, nil); node_free(b)
    end
    local shift_old, b_dir, wh = nil, get_box_dir(bh, 0)
    if wh then
-      node.direct.flush_list(getfield(wh, 'value'))
+      dnode.flush_list(getfield(wh, 'value'))
       setfield(wh, 'value', nil)
    end
    return nh, nb, bh, b_dir
 end
 
 -- is_manual: 寸法変更に伴うものか?
-local function create_dir_node(b, b_dir, new_dir, is_manual)
+local create_dir_node
+do
+    local getdir = dnode.getdir
+    local setdir = dnode.setdir
+    local setshift = dnode.setshift
+
+create_dir_node = function(b, b_dir, new_dir, is_manual)
    local info = dir_node_aux[b_dir%dir_math_mod][new_dir%dir_math_mod]
-   local w = getfield(b, 'width')
-   local h = getfield(b, 'height')
-   local d = getfield(b, 'depth')
+   local w, h, d = getwhd(b)
    local db = node_new(getid(b)) -- dir_node
    set_attr(db, attr_dir,
             new_dir + (is_manual and dir_node_manual or dir_node_auto))
@@ -611,13 +636,11 @@ local function create_dir_node(b, b_dir, new_dir, is_manual)
    set_attr(b, attr_icflag, PROCESSED)
    ensure_tex_attr(attr_dir, 0)
    ensure_tex_attr(attr_icflag, 0)
-   setfield(db, 'dir', getfield(b, 'dir'))
-   setfield(db, 'shift', 0)
-   setfield(db, 'width',  info.width(w,h,d))
-   setfield(db, 'height', info.height(w,h,d))
-   setfield(db, 'depth',  info.depth(w,h,d))
+   setdir(db, getdir(b)); setshift(db, 0)
+   setwhd(db, info.width(w,h,d), info.height(w,h,d), info.depth(w,h,d))
    return db
 end
+end
 
 -- 異方向のボックスの処理
 local make_dir_whatsit, process_dir_node
@@ -633,14 +656,14 @@ do
       -- 既に b の中身にあるwhatsit
       if (box_dir<dir_node_auto) and (not dn) then
         bh = create_dir_whatsit(bh, 'make_dir_whatsit', dir_yoko)
-        dn = bh; setfield(b, 'head', bh)
+        dn = bh; setlist(b, bh)
       end
       if box_dir%dir_math_mod==new_dir then
          if box_dir>=dir_node_auto then
             -- dir_node としてカプセル化されている
             local _, dnc = get_box_dir(b, 0)
             if dnc then -- free all other dir_node
-               node.direct.flush_list(getfield(dnc, 'value'))
+               dnode.flush_list(getfield(dnc, 'value'))
                setfield(dnc, 'value', nil)
             end
             set_attr(b, attr_dir, box_dir%dir_math_mod + dir_node_auto)
@@ -670,18 +693,13 @@ do
                db=x; break
             end
          end
-         node.direct.flush_list(getfield(dn, 'value'))
+         dnode.flush_list(getfield(dn, 'value'))
          setfield(dn, 'value', nil)
          db = db or create_dir_node(b, box_dir, new_dir, false)
-         local w = getfield(b, 'width')
-         local h = getfield(b, 'height')
-         local d = getfield(b, 'depth')
-         local dn_w = getfield(db, 'width')
-         local dn_h = getfield(db, 'height')
-         local dn_d = getfield(db, 'depth')
+         local w, h, d = getwhd(b)
          nh, nb =  insert_before(head, b, db), nil
          nh, nb = node_remove(nh, b)
-         setfield(b, 'next', nil); setfield(db, 'head', b)
+         setnext(b, nil); setlist(db, b)
          ret, flag = db, true
          return nh, nb, ret, flag
       end
@@ -701,7 +719,7 @@ do
    end
 
    -- lastbox
-   local node_prev = (node.direct~=node) and node.direct.getprev or node.prev
+   local node_prev = dnode.getprev
    local id_glue = node.id 'glue'
    local function lastbox_hook()
       start_time_measure 'box_primitive_hook'
@@ -715,20 +733,20 @@ do
             if p and getid(p)==id_glue and getsubtype(p)==12 then -- tabskip
                local np = node_next(p); local npid = getid(np)
                if npid==id_hlist or npid==id_vlist then
-                  setfield(b, 'head', create_dir_whatsit(p, 'align', get_box_dir(np, 0)))
+                  setlist(b, create_dir_whatsit(p, 'align', get_box_dir(np, 0)))
                end
             end
             local box_dir =  get_box_dir(b, 0)
             if box_dir>= dir_node_auto then -- unwrap dir_node
                local p = node_prev(b)
                local dummy1, dummy2, nb = unwrap_dir_node(b, nil, box_dir)
-               setfield(p, 'next', nb);  tex_nest[tex_nest.ptr].tail = to_node(nb)
-               setfield(b, 'next', nil); setfield(b, 'head', nil)
+               setnext(p, nb);  tex_nest[tex_nest.ptr].tail = to_node(nb)
+               setnext(b, nil); setlist(b, nil)
                node_free(b); b = nb
             end
             local _, wh =  get_box_dir(b, 0) -- clean dir_node attached to the box
             if wh then
-               node.direct.flush_list(getfield(wh, 'value'))
+               dnode.flush_list(getfield(wh, 'value'))
                setfield(wh, 'value', nil)
             end
          end
@@ -756,9 +774,7 @@ do
             end
          end
          if not_found then
-            local w = getfield(s, 'width')
-            local h = getfield(s, 'height')
-            local d = getfield(s, 'depth')
+            local w, h, d = getwhd(s)
             setdimen('ltj@tempdima',
                          dir_node_aux[s_dir][l_dir][key](w,h,d))
          end
@@ -797,7 +813,7 @@ do
       if s_dir ~= l_dir then
          if not wh then
             wh = create_dir_whatsit(getlist(s), 'set_box_dim', s_dir)
-            setfield(s, 'head', wh)
+            setlist(s, wh)
          end
          local db
          local dnh = getfield(wh, 'value')
@@ -808,7 +824,7 @@ do
          end
          if not db then
             db = create_dir_node(s, s_dir, l_dir, true)
-            setfield(db, 'next', dnh)
+            setnext(db, dnh)
             setfield(wh, 'value',to_node(db))
          end
          setfield(db, key, scan_dimen())
@@ -817,15 +833,12 @@ do
          setfield(s, key, scan_dimen())
          if wh then
             -- change dimension of dir_nodes which are created "automatically"
-               local bw, bh, bd
-                  = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
+               local bw, bh, bd = getwhd(s)
             for x in traverse(getfield(wh, 'value')) do
                local x_dir = has_attr(x, attr_dir)
                if x_dir<dir_node_manual then
                   local info = dir_node_aux[s_dir][x_dir%dir_node_auto]
-                  setfield(x, 'width',  info.width(bw,bh,bd))
-                  setfield(x, 'height', info.height(bw,bh,bd))
-                  setfield(x, 'depth',  info.depth(bw,bh,bd))
+                  setwhd(x, info.width(bw,bh,bd), info.height(bw,bh,bd), info.depth(bw,bh,bd))
                end
             end
          end
@@ -849,16 +862,12 @@ do
          else
             local sid, b = getid(s), getlist(s)
             local info = dir_node_aux[get_box_dir(b,dir_yoko)%dir_math_mod][b_dir%dir_node_auto]
-            local bw, bh, bd
-               = getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth')
-            local sw, sh, sd
-               = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
+            local bw, bh, bd = getwhd(b)
+            local sw, sh, sd = getwhd(s)
             if set_box_dim_common(key, b, l_dir) and b_dir<dir_node_manual then
                -- re-calculate dimension of s, if s is created "automatically"
                if b_dir<dir_node_manual then
-                  setfield(s, 'width',  info.width(bw,bh,bd))
-                  setfield(s, 'height', info.height(bw,bh,bd))
-                  setfield(s, 'depth',  info.depth(bw,bh,bd))
+                  setwhd(s, info.width(bw,bh,bd), info.height(bw,bh,bd), info.depth(bw,bh,bd))
                end
             end
          end
@@ -889,7 +898,7 @@ do
 end
 
 do
-   local getbox, setbox, copy_list = tex.getbox, tex.setbox, node.direct.copy_list
+   local getbox, setbox, copy_list = tex.getbox, tex.setbox, dnode.copy_list
    -- raise, lower
    function luatexja.direction.raise_box()
       start_time_measure 'box_primitive_hook'
@@ -923,6 +932,7 @@ end
 -- adjust
 do
    local id_adjust = node.id 'adjust'
+   local last_node = dnode.last_node 
    local scan_keyword = token.scan_keyword
    function luatexja.direction.adjust_begin()
       if scan_keyword 'pre' then tex.sprint(cat_lp, '\\ltj@@vadjust@pre')
@@ -940,7 +950,7 @@ do
                'luatexja',
                'Direction Incompatible',
                "\\vadjust's argument and outer vlist must have same direction.")
-            node.direct.last_node()
+            node_free(last_node())
          end
       end
       stop_time_measure 'box_primitive_hook'
@@ -960,7 +970,7 @@ do
           a = node.tail(tex.lists.page_head); ad = to_direct(a)
       end
       if a and getid(ad)==id_ins then
-         local h = getfield(ad, 'head')
+         local h = getlist(ad)
          if getid(h)==id_whatsit and
             getsubtype(h)==sid_user and getfield(h, 'user_id')==DIR then
                local n = h; h = node_remove(h,h)
@@ -972,7 +982,7 @@ do
             end
          end
          ensure_tex_attr(attr_dir, 0)
-         setfield(ad, 'head', h)
+         setlist(ad, h)
       end
       stop_time_measure 'box_primitive_hook'
    end
@@ -995,7 +1005,7 @@ do
             and node_next(bh) then
             ltjs.list_dir = has_attr(bh, attr_dir)
             local q = node_next(p)
-            setfield(p, 'head', node_remove(bh,bh,bh))
+            setlist(p, (node_remove(bh,bh,bh)))
             split_dir_head = bh
          end
       end
@@ -1053,38 +1063,22 @@ do
    local function finalize_dir_node(db,new_dir)
       local b = getlist(db)
       while b and ((getid(b)~=id_hlist) and (getid(b)~=id_vlist)) do
-         local ob = b; b = node_remove(b,b); setfield(db, 'head', b);
+         local ob = b; b = node_remove(b,b); setlist(db, b);
          node_free(ob)
       end
       finalize_inner(b)
-      local w = getfield(b, 'width')
-      local h = getfield(b, 'height')
-      local d = getfield(b, 'depth')
-      local dn_w = getfield(db, 'width')
-      local dn_h = getfield(db, 'height')
-      local dn_d = getfield(db, 'depth')
+      local w, h, d = getwhd(b)
+      local dw, dh, dd = getwhd(db)
       local db_head, db_tail
       local t = dir_node_aux[get_box_dir(b, dir_yoko)%dir_math_mod][new_dir]
       t = t and t[getid(b)]; if not t then return end
       for _,v in ipairs(t) do
-         local cmd, arg, nn = v[1], v[2]
-         if cmd=='kern' then
-            nn = node_new(id_kern, 1)
-            setfield(nn, 'kern', arg(w, h, d, dn_w, dn_h, dn_d))
-         elseif cmd=='whatsit' then
-            nn = node_new(id_whatsit, arg)
-         elseif cmd=='rotate' then
-            nn = node_new(id_whatsit, sid_matrix)
-            setfield(nn, 'data', arg)
-         elseif cmd=='box' then
-            nn = b; setfield(b, 'next', nil)
-            setfield(nn, 'shift', arg(w, h, d, dn_w, dn_h, dn_d))
-         end
+         local nn = v[1](v[2], b, w, h, d, dw, dh, dd)
          if db_head then
             insert_after(db_head, db_tail, nn)
             db_tail = nn
          else
-            setfield(db, 'head', nn)
+            setlist(db, nn)
             db_head, db_tail = nn, nn
          end
       end
@@ -1092,6 +1086,7 @@ do
 
    tex.setattribute(attr_dir, dir_yoko)
    local shipout_temp =  node_new(id_hlist)
+   dnode.setattributelist(shipout_temp, nil) 
    tex.setattribute(attr_dir, 0)
 
    finalize_inner = function (box)
@@ -1107,17 +1102,17 @@ do
          end
       end
    end
-   local copy = node.direct.copy
+   local copy = dnode.copy
    function luatexja.direction.shipout_lthook (head)
       start_time_measure 'box_primitive_hook'
       local a = to_direct(head)
       local a_dir = get_box_dir(a, dir_yoko)
       if a_dir~=dir_yoko then
          local b = create_dir_node(a, a_dir, dir_yoko, false)
-         setfield(b, 'head', a); a = b
+         setlist(b, a); a = b
       end
-      setfield(shipout_temp, 'head', a); finalize_inner(shipout_temp)
-      a = copy(getlist(shipout_temp)); setfield(shipout_temp, 'head',nil)
+      setlist(shipout_temp, a); finalize_inner(shipout_temp)
+      a = copy(getlist(shipout_temp)); setlist(shipout_temp, nil)
       stop_time_measure 'box_primitive_hook'
       return to_node(a)
    end
index 7f39b9b..12ac83a 100644 (file)
@@ -8,8 +8,6 @@ luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
 local utflen = utf.len
 local utfbyte = utf.byte
 local utfchar = utf.char
-local node_new = node.new
-local node_free = node.free
 local id_glyph = node.id 'glyph'
 local getcatcode, getcount = tex.getcatcode, tex.getcount
 local ltjc_is_japanese_char_curlist = ltjc.is_japanese_char_curlist
index 22c32eb..db90fed 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfmglue',
-  date = '2022-02-09',
+  date = '2022-08-16',
   description = 'Insertion process of JFM glues, [x]kanjiskip and others',
 })
 luatexja.jfmglue = luatexja.jfmglue or {}
@@ -19,23 +19,29 @@ local pairs = pairs
 --local to_node = node.direct.tonode
 --local to_direct = node.direct.todirect
 
-local setfield = node.direct.setfield
-local setglue = luatexja.setglue
 local getfield = node.direct.getfield
 local getid = node.direct.getid
 local getfont = node.direct.getfont
 local getlist = node.direct.getlist
 local getchar = node.direct.getchar
+local getglue = luatexja.getglue
 local getsubtype = node.direct.getsubtype
+local getshift = node.direct.getshift
+local getwidth = node.direct.getwidth
+local getdepth = node.direct.getdepth
+local getpenalty = node.direct.getpenalty
+local setfield = node.direct.setfield
+local setglue = luatexja.setglue
+local setshift = node.direct.setshift
 local if_lang_ja
 do
     local lang_ja = luatexja.lang_ja
     local getlang = node.direct.getlang
     -- glyph with font number 0 (\nullfont) is always considered an ALchar node
-    if_lang_ja = getlang 
-      and function (n) return (getlang(n)==lang_ja)and(getfont(n)~=0) end
-      or  function (n) return (getfield(n,'lang')==lang_ja)and(getfont(n)~=0) end
+    if_lang_ja = function (n) return (getlang(n)==lang_ja)and(getfont(n)~=0) end
 end
+local setpenalty = node.direct.setpenalty
+local setkern = node.direct.setkern
   
 local has_attr = node.direct.has_attribute
 local set_attr = node.direct.set_attribute
@@ -48,7 +54,7 @@ local ltjf_find_char_class = ltjf.find_char_class
 local node_new = luatexja.dnode_new
 local node_copy = node.direct.copy
 local node_tail = node.direct.tail
-local node_free = node.direct.free
+local node_free = node.direct.flush_node or node.direct.free
 local node_remove = node.direct.remove
 local node_inherit_attr = luatexja.node_inherit_attr
 
@@ -131,8 +137,6 @@ end
 -- penalty 値の計算
 local add_penalty
 do
-local setpenalty = node.direct.setpenalty or function(n, a) setfield(n,'penalty',a) end
-local getpenalty = node.direct.getpenalty or function(n) return getfield(n,'penalty') end
 function add_penalty(p,e)
    local pp = getpenalty(p)
    if (pp>-10000) and (pp<10000) then
@@ -206,7 +210,7 @@ local function check_box(box_ptr, box_end)
             if find_first_char then first_char = s; find_first_char = false end
             last_char = s; found_visible_node = true
          else
-            if getfield(p, 'shift')==0 then
+            if getshift(p)==0 then
                last_char = nil
                if check_box(getlist(p), nil) then found_visible_node = true end
                find_first_char = false
@@ -311,6 +315,8 @@ do -- 002 ---------------------------------------
    local attr_jchar_class = luatexbase.attributes['ltj@charclass']
    local attr_jchar_code = luatexbase.attributes['ltj@charcode']
    local font_getfont = font.getfont
+   local setwhd = node.direct.setwhd
+   local setdir = node.direct.setdir
    local function calc_np_notdef(lp)
       if not font_getfont(getfont(lp)).characters[getchar(lp)] then
          local ln = node_next(lp)
@@ -342,8 +348,8 @@ function calc_np_aux_glyph_common(lp, acc_flag)
       local first_glyph, last_glyph = lp
       set_attr(lp, attr_icflag, PROCESSED); Np.last = lp
       local y_adjust = has_attr(lp,attr_ablshift) or 0
-      local node_depth = getfield(lp, 'depth') + min(y_adjust, 0)
-      local adj_depth = (y_adjust>0) and (getfield(lp, 'depth') + y_adjust) or 0
+      local node_depth = getdepth(lp) + min(y_adjust, 0)
+      local adj_depth = (y_adjust>0) and (getdepth(lp) + y_adjust) or 0
       setfield(lp, 'yoffset', getfield(lp, 'yoffset') - y_adjust); lp = node_next(lp)
       local lx=lp
       while lx do
@@ -355,8 +361,8 @@ function calc_np_aux_glyph_common(lp, acc_flag)
                -- 欧文文字
                last_glyph = lx; set_attr(lx, attr_icflag, PROCESSED); Np.last = lx
                y_adjust = has_attr(lx,attr_ablshift) or 0
-               node_depth = max(getfield(lx, 'depth') + min(y_adjust, 0), node_depth)
-               adj_depth = (y_adjust>0) and max(getfield(lx, 'depth') + y_adjust, adj_depth) or adj_depth
+               node_depth = max(getdepth(lx) + min(y_adjust, 0), node_depth)
+               adj_depth = (y_adjust>0) and max(getdepth(lx) + y_adjust, adj_depth) or adj_depth
                setfield(lx, 'yoffset', getfield(lx, 'yoffset') - y_adjust); lx = node_next(lx)
             elseif lid==id_kern then
                local ls = getsubtype(lx)
@@ -366,7 +372,7 @@ function calc_np_aux_glyph_common(lp, acc_flag)
                   if getid(lx)==id_glyph then
                      setfield(lx, 'yoffset', getfield(lx, 'yoffset') - (has_attr(lx,attr_ablshift) or 0))
                   else -- アクセントは上下にシフトされている
-                     setfield(lx, 'shift', getfield(lx, 'shift') + (has_attr(lx,attr_ablshift) or 0))
+                     setshift(lx, getshift(lx) + (has_attr(lx,attr_ablshift) or 0))
                   end
                   set_attr(lx, attr_icflag, PROCESSED)
                   lx = node_next(lx); set_attr(lx, attr_icflag, PROCESSED)
@@ -385,8 +391,7 @@ function calc_np_aux_glyph_common(lp, acc_flag)
       local r
       if adj_depth>node_depth then
             r = node_new(id_rule,3,first_glyph)
-            setfield(r, 'width', 0); setfield(r, 'height', 0)
-            setfield(r, 'depth',adj_depth); setfield(r, 'dir', tex_dir)
+            setwhd(r, 0, 0, adj_depth); setdir(r, tex_dir)
             set_attr(r, attr_icflag, PROCESSED)
       end
       if last_glyph then
@@ -436,7 +441,7 @@ calc_np_auxtable = {
       head, lp, op, flag = ltjd_make_dir_whatsit(head, lp, list_dir, 'jfm hlist')
       set_attr(op, attr_icflag, PROCESSED)
       Np.first = Np.first or op; Np.last = op; Np.nuc = op;
-      if (flag or getfield(op, 'shift')~=0) then
+      if (flag or getshift(op)~=0) then
          Np.id = id_box_like
       else
          Np.id = id_hlist
@@ -522,7 +527,7 @@ calc_np_auxtable = {
          if getid(lp)==id_glyph then -- アクセント本体
             setfield(lp, 'yoffset', getfield(lp, 'yoffset') - (has_attr(lp,attr_ablshift) or 0))
          else -- アクセントは上下にシフトされている
-            setfield(lp, 'shift', getfield(lp, 'shift') + (has_attr(lp,attr_ablshift) or 0))
+            setshift(lp, getshift(lp) + (has_attr(lp,attr_ablshift) or 0))
          end
          set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
          set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
@@ -692,7 +697,7 @@ local function handle_penalty_normal(post, pre, g)
       if (a~=0 and not(g and getid(g)==id_kern)) then
          local p = node_new(id_penalty, nil, Nq.nuc, Np.nuc)
          if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
-         setfield(p, 'penalty', a); head = insert_before(head, Np.first, p)
+         setpenalty(p, a); head = insert_before(head, Np.first, p)
          Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
       end
    else for _, v in pairs(Bp) do add_penalty(v,a) end
@@ -706,7 +711,7 @@ local function handle_penalty_always(post, pre, g)
       if not (g and getid(g)==id_glue) or a~=0 then
          local p = node_new(id_penalty, nil, Nq.nuc, Np.nuc)
          if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
-         setfield(p, 'penalty', a); head = insert_before(head, Np.first, p)
+         setpenalty(p, a); head = insert_before(head, Np.first, p)
          Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
       end
    else for _, v in pairs(Bp) do add_penalty(v,a) end
@@ -718,7 +723,7 @@ local function handle_penalty_suppress(post, pre, g)
    if #Bp == 0 then
       if g and getid(g)==id_glue then
          local p = node_new(id_penalty, nil, Nq.nuc, Np.nuc)
-         setfield(p, 'penalty', 10000); head = insert_before(head, Np.first, p)
+         setpenalty(p, 10000); head = insert_before(head, Np.first, p)
          Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
       end
    else 
@@ -733,7 +738,7 @@ local function handle_penalty_jwp()
       if a~=0 then
          local p = node_new(id_penalty, widow_Np.nuc)
          if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
-         setfield(p, 'penalty', a); head = insert_before(head, widow_Np.first, p)
+         setpenalty(p, a); head = insert_before(head, widow_Np.first, p)
          widow_Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
       end
    else for _, v in pairs(widow_Bp) do add_penalty(v,a) end
@@ -746,7 +751,7 @@ local function new_jfm_glue(mc, bc, ac)
    local g = mc[bc][ac]
    if g then
        if g[1] then
-          local k = node_new(id_kern, 1); setfield(k, 'kern', g[1]) 
+          local k = node_new(id_kern, 1); setkern(k, g[1]) 
           set_attr(k, attr_icflag, FROM_JFM)
           return k, g.ratio, false, false, false
        else
@@ -779,6 +784,7 @@ do
    local bg_ak = 2*id_glue - id_kern
    local bk_ag = 2*id_kern - id_glue
    local bk_ak = 2*id_kern - id_kern
+   local getkern = node.direct.getkern
 
    local function blend_diffmet(b, a, rb, ra)
       return round(luatexja.jfmglue.diffmet_rule((1-rb)*b+rb*a, (1-ra)*b+ra*a))
@@ -800,24 +806,24 @@ do
          db, da = 0, 1
       end
       if not gb then
-         if ga then gb = node_new(id_kern, 1); setfield(gb, 'kern', 0)
+         if ga then gb = node_new(id_kern, 1); setkern(gb, 0)
          else return nil end
       elseif not ga then
-         ga = node_new(id_kern, 1); setfield(ga, 'kern', 0)
+         ga = node_new(id_kern, 1); setkern(ga, 0)
       end
       local gbw, gaw, gbst, gast, gbsto, gasto, gbsh, gash, gbsho, gasho
       if getid(gb)==id_glue then
          gbw, gbst, gbsh, gbsto, gbsho = getglue(gb)
       else
-         gbw = getfield(gb, 'kern')
+         gbw = getkern(gb)
       end
       if getid(ga)==id_glue then
          gaw, gast, gash, gasto, gasho = getglue(ga)
       else
-         gaw = getfield(ga, 'kern')
+         gaw = getkern(ga)
       end
       if not (gbst or gast) then -- 両方とも kern
-         setfield(gb, 'kern', blend_diffmet(gbw, gaw, db, da))
+         setkern(gb, blend_diffmet(gbw, gaw, db, da))
          node_free(ga); return gb
       else
          local gr = gb
@@ -858,7 +864,7 @@ do
             local st = bp and (bp*getfield(kanji_skip, 'stretch')) or 0
             local sh = bh and (bh*getfield(kanji_skip, 'shrink')) or 0
             setglue(g,
-               bn and (bn*getfield(kanji_skip, 'width')) or 0,
+               bn and (bn*getwidth(kanji_skip)) or 0,
                st, sh, 
                (st==0) and 0 or getfield(kanji_skip, 'stretch_order'),
                (sh==0) and 0 or getfield(kanji_skip, 'shrink_order'))
@@ -942,13 +948,14 @@ do
          elseif flag then
             return node_copy(xkanji_skip)
          else
-            local g = node_new(id_glue);
+            local g = node_new(id_glue)
+            local w, st, sh, sto, sho = getglue(xkanji_skip) 
             setglue(g,
-               bn and (bn*getfield(xkanji_skip, 'width')) or 0,
-               bp and (bp*getfield(xkanji_skip, 'stretch')) or 0,
-               bh and (bh*getfield(xkanji_skip, 'shrink')) or 0,
-               bp and getfield(xkanji_skip, 'stretch_order') or 0,
-               bh and getfield(xkanji_skip, 'shrink_order') or 0)
+               bn and (bn*w) or 0,
+               bp and (bp*st) or 0,
+               bh and (bh*sh) or 0,
+               bp and sto or 0,
+               bh and sho or 0)
             set_attr(g, attr_icflag, XKANJI_SKIP_JFM)
             return g
          end
@@ -1153,7 +1160,7 @@ local function handle_list_head(par_indented)
             set_attr(g, attr_icflag, BOXBDD)
             if getid(g)==id_glue and #Bp==0 then
                local h = node_new(id_penalty, nil, Np.nuc)
-               setfield(h, 'penalty', 10000); set_attr(h, attr_icflag, BOXBDD)
+               setpenalty(h, 10000); set_attr(h, attr_icflag, BOXBDD)
             end
             head = insert_before(head, Np.first, g)
          end
@@ -1196,18 +1203,15 @@ do
       attr_ablshift = is_dir_tate and attr_tablshift or attr_yablshift
       local TEMP = node_new(id_glue) 
       -- TEMP is a dummy node, which will be freed at the end of the callback. 
-      -- ithout this node, set_attr(kanji_skip, ...) somehow creates an "orphaned"  attribute list.
-
+      -- Without this node, set_attr(kanji_skip, ...) somehow creates an "orphaned"  attribute list.
       do
           kanji_skip, kanjiskip_jfm_flag = skip_table_to_glue(KSK)
           set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
       end
-
       do
           xkanji_skip, xkanjiskip_jfm_flag = skip_table_to_glue(XSK)
           set_attr(xkanji_skip, attr_icflag, XKANJI_SKIP)
       end
-
       if mode then
          -- the current list is to be line-breaked:
          -- hbox from \parindent is skipped.
@@ -1218,7 +1222,7 @@ do
                or (lpi==id_local)) do
             if (lpi==id_hlist) and (lps==3) then
                Np.char, par_indented = 'parbdd', 'parbdd'
-               Np.width = getfield(lp, 'width')
+               Np.width = getwidth(lp)
             end
             lp=node_next(lp); lpi, lps = getid(lp), getsubtype(lp) end
          return lp, node_tail(head), par_indented, TEMP
@@ -1375,6 +1379,7 @@ do
    local attr_tablshift = luatexbase.attributes['ltj@tablshift']
    local getcount, abs, scan_keyword = tex.getcount, math.abs, token.scan_keyword
    local tex_nest = tex.nest
+   local tex_getattr = tex.getattribute
    local get_current_jfont
    do
        local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
@@ -1382,7 +1387,7 @@ do
        local dir_tate = luatexja.dir_table.dir_tate
        local get_dir_count = ltjd.get_dir_count        
        function get_current_jfont()
-           return tex.getattribute((get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)
+           return tex_getattr((get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)
        end
    end
    -- \insertxkanjiskip
@@ -1417,7 +1422,6 @@ do
        insert_k_skip_common(KSK, "kanjiskip", KANJI_SKIP, KANJI_SKIP_JFM)
    end
    -- callback
-   local getglue = luatexja.getglue
    local function special_jaglue(lx)
        local lxi = get_attr_icflag(lx)
        if lxi==SPECIAL_JAGLUE then
index a09b890..29a0413 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfont',
-  date = '2021-11-06',
+  date = '2022-08-16',
   description = 'Loader for Japanese fonts',
 })
 
@@ -18,11 +18,12 @@ local getid = node.direct.getid
 local to_direct = node.direct.todirect
 
 local node_new = node.direct.new
-local node_free = node.direct.free
+local node_free = node.direct.flush_node or node.direct.free
 local has_attr = node.direct.has_attribute
 local set_attr = node.direct.set_attribute
 local round = tex.round
 local font_getfont = font.getfont
+local setkern = node.direct.setkern
 
 local attr_icflag = luatexbase.attributes['ltj@icflag']
 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
@@ -1036,7 +1037,7 @@ do
                has_attr(p, (get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)
                ]
             local g = new_ic_kern()
-            setfield(g, 'kern', j.char_type[find_char_class(getchar(p), j)].italic)
+            setkern(g, j.char_type[find_char_class(getchar(p), j)].italic)
             node_write(g); ensure_tex_attr(attr_icflag, 0)
          else
             local f = getfont(p)
@@ -1044,7 +1045,7 @@ do
             if h then
                if h.characters[getchar(p)] and h.characters[getchar(p)].italic then
                   local g = new_ic_kern()
-                  setfield(g, 'kern', h.characters[getchar(p)].italic)
+                  setkern(g, h.characters[getchar(p)].italic)
                   node_write(g); ensure_tex_attr(attr_icflag, 0)
                end
             end
index ba08285..b506c90 100644 (file)
@@ -18,12 +18,15 @@ local node_prev = node.direct.getprev
 local node_next = node.direct.getnext
 local getid = node.direct.getid
 local getsubtype = node.direct.getsubtype
+local getdepth = node.direct.getdepth
+local getheight = node.direct.getheight
 local texget = tex.get
 
 local node_getglue = node.getglue
-local setglue = node.direct.setglue
+local setglue = luatexja.setglue
+local setsubtype = node.direct.setsubtype
 local function copy_glue (new_glue, old_glue_name, subtype, new_w)
-   setfield(new_glue, 'subtype', subtype)
+   setsubtype(new_glue, subtype)
    local w,st,sp,sto,spo = texget(old_glue_name, true)
    setglue(new_glue, new_w or w, st, sp, sto, spo)
 end
@@ -61,7 +64,7 @@ local function adjust_glue(nh)
              p = node_prev(p); pid = getid(p)
            end
            if pid==id_hlist and getid(n)==id_hlist then
-             local normal = bw - getfield(p, 'depth') - getfield(n, 'height')
+             local normal = bw - getdepth(p) - getheight(n)
              local lmin, adj = ltj_profiler(p, n, false, bw)
              ltj_skip(lmin or normal, x, adj, normal, bw)
            end
@@ -96,7 +99,7 @@ local function dir_adjust_append_vlist(b, loc, prev, mirrored)
       end
       if tail then
          if getid(tail)==id_hlist and getid(new_b)==id_hlist then
-            if getfield(tail, 'depth')==prev then 
+            if getdepth(tail)==prev then 
                lmin, adj = ltj_profiler(tail, new_b, mirrored, bw)
             end
          end
index 2a7c044..466596f 100644 (file)
@@ -14,8 +14,15 @@ local getfield = node.direct.getfield
 local getid = node.direct.getid
 local getsubtype = node.direct.getsubtype
 local getlist = node.direct.getlist
--- getlist cannot be used for sub_box nodes. Use instead λp. getfield(p, 'head')
 local getchar = node.direct.getchar
+local getnucleus = node.direct.getnucleus
+local getsup = node.direct.getsup
+local getsub = node.direct.getsub
+local setnext = node.direct.setnext
+local setnucleus = node.direct.setnucleus
+local setsup = node.direct.setsup
+local setsub = node.direct.setsub
+local setlist = node.direct.setlist
 
 local to_node = node.direct.tonode
 local to_direct = node.direct.todirect
@@ -24,7 +31,7 @@ local node_traverse = node.direct.traverse
 local node_new = node.direct.new
 local node_next = node.direct.getnext
 local node_remove = node.direct.remove
-local node_free = node.direct.free
+local node_free = node.direct.flush_node or node.direct.free
 local has_attr = node.direct.has_attribute
 local set_attr = node.direct.set_attribute
 local tex_getcount = tex.getcount
@@ -66,13 +73,13 @@ local list_dir
 
 -- vcenter noad は軸に揃えるため,欧文ベースライン補正がかかる
 local function conv_vcenter(sb)
-   local h = getfield(sb, 'head'); local hd = getlist(h)
+   local h = getlist(sb) ; 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); setlist(h, nil); node_free(h)
+         setlist(sb, d);  set_attr(d, attr_icflag, 0)
       end
    end
    return sb
@@ -85,12 +92,12 @@ local function conv_jchar_to_hbox(head, sty)
       local pid = getid(p)
       if pid == id_simple or pid == id_accent then
          if getsubtype(p)==12 then
-            conv_vcenter(getfield(p, 'nucleus'))
+            conv_vcenter(getnucleus(p))
          else
-            setfield(p, 'nucleus', cjh_A(getfield(p, 'nucleus'), sty))
+            setnucleus(p, cjh_A(getnucleus(p), sty))
          end
-         setfield(p, 'sub', cjh_A(getfield(p, 'sub'), sty+1))
-         setfield(p, 'sup', cjh_A(getfield(p, 'sup'), sty+1))
+         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, 'text', cjh_A(getfield(p, 'text'), 0))
@@ -100,9 +107,9 @@ local function conv_jchar_to_hbox(head, sty)
          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', 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))
+         setnucleus(p, cjh_A(getnucleus(p), sty))
+         setsub(p, cjh_A(getsub(p), sty+1))
+         setsup(p, cjh_A(getsup(p), sty+1))
          if getfield(p, 'degree') then
             setfield(p, 'degree', cjh_A(getfield(p, 'degree'), sty + 1))
          end
@@ -124,14 +131,16 @@ 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
+local setfont = node.direct.setfont
+local setchar = node.direct.setchar
 
 cjh_A = function (p, sty)
    if not p then return nil
    else
       local pid = getid(p)
       if pid == id_sub_mlist then
-         if getfield(p, 'head') then
-            setfield(p, 'head', conv_jchar_to_hbox(getfield(p, 'head'), sty))
+         if getlist(p) then
+            setlist(p, conv_jchar_to_hbox(getlist(p), sty))
          end
       elseif pid == id_mchar then
          local pc, fam = getchar (p), has_attr(p, attr_jfam) or -1
@@ -139,19 +148,19 @@ cjh_A = function (p, sty)
             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 r = node_new(id_glyph, 256); setnext(r, nil)
+               setchar(r, pc); setfont(r, f)
                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)
+               setlist(q, r); node_free(p); p=q; set_attr(r, attr_yablshift, k)
             end
          end
-      elseif pid == id_sub_box and getfield(p, 'head') then
+      elseif pid == id_sub_box and getlist(p) 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 = getlist(p); h = ltjd_make_dir_whatsit(h, h, list_dir, 'math')
+         setlist(p, h); set_attr(h, attr_icflag, PROCESSED)
       end
    end
    return p
index 770749f..dcfec33 100644 (file)
@@ -21,12 +21,16 @@ local getid = node.direct.getid
 local getfont = node.direct.getfont
 local getchar = node.direct.getchar
 local getsubtype = node.direct.getsubtype
+local setchar = node.direct.setchar
+local setfont = node.direct.setfont
+local setlang = node.direct.setlang
+
 local to_node = node.direct.tonode
 local to_direct = node.direct.todirect
 local node_new = node.direct.new
 local node_remove = node.direct.remove
 local node_next = node.direct.getnext
-local node_free = node.direct.free
+local node_free = node.direct.flush_node or node.direct.free
 local has_attr = node.direct.has_attribute
 local set_attr = node.direct.set_attribute
 local unset_attr = node.direct.unset_attribute
@@ -162,11 +166,10 @@ local function extract(head)
          if getsubtype(p)==sid_user then
             local puid = getfield(p, 'user_id')
             if puid==OTF then
-               local g = node_new(id_glyph)
-               setfield(g, 'subtype', 0)
-               setfield(g, 'char', getfield(p, 'value'))
-               local v = has_attr(p, attr_curfnt); setfield(g, 'font', v)
-               setfield(g, 'lang', lang_ja)
+               local g = node_new(id_glyph, 0)
+               setchar(g, getfield(p, 'value'))
+               setfont(g, has_attr(p, attr_curfnt))
+               setlang(g, lang_ja)
                set_attr(g, attr_kblshift, has_attr(p, attr_kblshift))
                head = node_insert_after(head, p, g)
                head = node_remove(head, p)
index 073cc1e..348378f 100644 (file)
@@ -17,7 +17,7 @@ local getfont =  node.direct.getfont
 local getchar =  node.direct.getchar
 local getfield =  node.direct.getfield
 local getsubtype =  node.direct.getsubtype
-local getlang = node.direct.getlang or function (n) return getfield(n,'lang') end
+local getlang = node.direct.getlang
 
 local pairs = pairs
 local floor = math.floor
@@ -26,7 +26,7 @@ local set_attr = node.direct.set_attribute
 local node_traverse = node.direct.traverse
 local node_remove = node.direct.remove
 local node_next =  node.direct.getnext
-local node_free = node.direct.free
+local node_free = node.direct.flush_node or node.direct.free
 local node_end_of_math = node.direct.end_of_math
 local tex_getcount = tex.getcount
 
@@ -51,9 +51,9 @@ local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG
 local dir_tate = luatexja.dir_table.dir_tate
 local lang_ja = luatexja.lang_ja
 
-local setlang = node.direct.setlang or function(n,l) setfield(n,'lang',l) end 
-local setfont = node.direct.setfont or function(n,l) setfield(n,'font',l) end 
-local setchar = node.direct.setchar or function(n,l) setfield(n,'char',l) end 
+local setlang = node.direct.setlang
+local setfont = node.direct.setfont
+local setchar = node.direct.setchar
 
 ------------------------------------------------------------------------
 -- MAIN PROCESS STEP 1: replace fonts
@@ -86,7 +86,7 @@ do
                 { __index = function() return node_next end, })
    local id_boundary = node.id('boundary')
    local node_new, insert_before = node.direct.new, node.direct.insert_before
-   local setsubtype = node.direct.setsubtype or function(n,l) setfield(n,'subtype',l) end 
+   local setsubtype = node.direct.setsubtype
    local function suppress_hyphenate_ja (h)
       start_time_measure('ltj_hyphenate')
       head = to_direct(h)
@@ -135,10 +135,13 @@ do
 end
 
 -- mode: true iff this function is called from hpack_filter
+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 function set_box_stack_level(head, mode)
+local traverse_id = node.direct.traverse_id
+function set_box_stack_level(head, mode)
    local box_set, cl = 0, tex.currentgrouplevel + 1
    if mode then
       for _,p  in pairs(wt) do
@@ -150,7 +153,7 @@ local function set_box_stack_level(head, mode)
    ltjs_report_stack_level(tex_getcount('ltj@@stack') + box_set)
    for _,p  in pairs(wtd) do node_free(p) end
    if ltjs.list_dir == dir_tate then
-      for p in node.direct.traverse_id(id_glyph,to_direct(head)) do
+      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 nf = ltjf_replace_altfont( has_attr(p, attr_curtfnt) or getfont(p) , ltjs_orig_char_table[p])
             setfont(p, nf)
@@ -163,6 +166,7 @@ local function set_box_stack_level(head, mode)
    end
    return head
 end
+end
 
 -- CALLBACKS
 ltjb.add_to_callback('hpack_filter',
index 7fa7ea9..782835d 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.ruby',
-  date = '2022-06-25',
+  date = '2022-08-14',
   description = 'Ruby annotation',
 })
 luatexja.ruby = {}
@@ -13,21 +13,36 @@ luatexja.load_module 'base';      local ltjb = luatexja.base
 local to_node =  node.direct.tonode
 local to_direct =  node.direct.todirect
 
-local setfield =  node.direct.setfield
-local setglue = luatexja.setglue
 local getfield =  node.direct.getfield
 local getid =  node.direct.getid
 local getfont =  node.direct.getfont
 local getlist =  node.direct.getlist
 local getchar =  node.direct.getchar
 local getsubtype =  node.direct.getsubtype
+local getkern = node.direct.getkern
+local getwidth =  node.direct.getwidth
+local getheight = node.direct.getheight
+local getdepth = node.direct.getdepth
+local getwhd = node.direct.getwhd
+local setfield =  node.direct.setfield
+local setglue = luatexja.setglue
+local setkern = node.direct.setkern
+local setnext = node.direct.setnext
+local setshift = node.direct.setshift
+local setwidth = node.direct.setwidth
+local setheight = node.direct.setheight
+local setdepth = node.direct.setdepth
+local setwhd = node.direct.setwhd
+local setlist = node.direct.setlist
 
 local node_new = node.direct.new
 local node_remove = node.direct.remove
 local node_next =  node.direct.getnext
-local node_copy, node_free, node_tail = node.direct.copy, node.direct.free, node.direct.tail
+local node_copy, node_tail = node.direct.copy, node.direct.tail
+local node_free = node.direct.flush_node or node.direct.free
 local has_attr, set_attr = node.direct.has_attribute, node.direct.set_attribute
 local insert_before, insert_after = node.direct.insert_before, node.direct.insert_after
+local hpack = node.direct.hpack
 
 local id_hlist  = node.id 'hlist'
 local id_vlist  = node.id 'vlist'
@@ -157,25 +172,22 @@ do
             end
             set_attr(nh, attr_icflag,
               get_attr_icflag(nh) + PROCESSED_BEGIN_FLAG)
-            setfield(node_tail(h), 'next', nh)
-            setfield(f, 'head', nil); node_free(f)
-            setfield(b, 'head', nil); node_free(b)
+            setnext(node_tail(h), nh)
+            setlist(f, nil); node_free(f)
+            setlist(b, nil); node_free(b)
             local g = luatexja.jfmglue.main(h,false)
-            return node.direct.hpack(g)
+            return hpack(g)
          else
             return f
          end
       elseif b then
          return b
       else
-         local h = node_new(id_hlist)
-         setfield(h, 'subtype', 0)
-         setfield(h, 'width', 0)
-         setfield(h, 'height', 0)
-         setfield(h, 'depth', 0)
+         local h = node_new(id_hlist, 0)
+         setwhd(h, 0, 0, 0)
          setfield(h, 'glue_set', 0)
          setfield(h, 'glue_order', 0)
-         setfield(h, 'head', nil)
+         setlist(h, nil)
          return h
       end
    end
@@ -205,7 +217,7 @@ do
       -- pre, middle, post: 伸縮比率
       -- prenw, postnw: 前後の自然長 (sp)
       local h = getlist(box);
-      local hh, hd = getfield(box, 'height'), getfield(box, 'depth')
+      local _, hh, hd = getwhd(box)
       local hx = h
       while hx do
          local hic = has_attr(hx, attr_icflag) or 0
@@ -214,14 +226,13 @@ do
             or ((hic<=FROM_JFM+63) and (hic>=FROM_JFM)) then
             -- この 5 種類の空白をのばす
                if getid(hx) == id_kern then
-                  local k = node_new(id_glue)
-                  setglue(k, getfield(hx, 'kern'), round(middle*65536), 0,
+                  local k = node_new(id_glue, 0)
+                  setglue(k, getkern(hx), round(middle*65536), 0,
                              2, 0)
-                  setfield(k, 'subtype', 0);
                   h = insert_after(h, hx, k);
                   h = node_remove(h, hx); node_free(hx); hx = k
                else -- glue
-                  setglue(hx, getfield(hx, 'width'), round(middle*65536), 0,
+                  setglue(hx, getwidth(hx), round(middle*65536), 0,
                              2, 0)
                end
          end
@@ -236,10 +247,9 @@ do
       setglue(k, postnw, round(post*65536), 0, 2, 0)
       insert_after(h, node_tail(h), k);
       -- hpack
-      setfield(box, 'head', nil); node_free(box)
-      box = node.direct.hpack(h, new_width, 'exactly')
-      setfield(box, 'height', hh)
-      setfield(box, 'depth', hd)
+      setlist(box, nil); node_free(box)
+      box = hpack(h, new_width, 'exactly')
+      setheight(box, hh); setdepth(box, hd)
       return box
    end
 end
@@ -280,7 +290,7 @@ function luatexja.ruby.texiface(rst, rtlr, rtlp)
    else
       local f, eps = true, rst.eps
       for i = 1,#rtlr do
-         if getfield(rtlr[i], 'width') > getfield(rtlp[i], 'width') + eps then
+         if getwidth(rtlr[i]) > getwidth(rtlp[i]) + eps then
             f = false; break
          end
       end
@@ -304,8 +314,8 @@ end
 -- r, p の中身のノードは再利用される
 local function enlarge_parent(r, p, tmp_tbl, no_begin, no_end)
    -- r: ルビ部分の格納された box,p: 同,親文字
-   local rwidth = getfield(r, 'width')
-   local sumprot = rwidth - getfield(p, 'width') -- >0
+   local rwidth = getwidth(r)
+   local sumprot = rwidth - getwidth(p) -- >0
    local pre_intrusion, post_intrusion
    local ppre, pmid, ppost = tmp_tbl.ppre, tmp_tbl.pmid, tmp_tbl.ppost
    local mapre, mapost = tmp_tbl.mapre, tmp_tbl.mapost
@@ -338,12 +348,11 @@ local function enlarge_parent(r, p, tmp_tbl, no_begin, no_end)
       pre_intrusion = min(mapre, pre_intrusion + round(ppre*getfield(p, 'glue_set')*65536))
       post_intrusion = min(mapost, post_intrusion + round(ppost*getfield(p, 'glue_set')*65536))
    end
-   setfield(r, 'shift', -pre_intrusion)
+   setshift(r, -pre_intrusion)
    local rwidth = rwidth - pre_intrusion - post_intrusion
-   setfield(r, 'width', rwidth)
-   setfield(p, 'width', rwidth)
+   setwidth(r, rwidth); setwidth(p, rwidth)
    local ps = getlist(p)
-   setfield(ps, 'width', getfield(ps, 'width') - pre_intrusion)
+   setwidth(ps, getwidth(ps) - pre_intrusion)
    local orig_post_intrusion, post_jfmgk = post_intrusion, false
    if no_end then
        if orig_post_intrusion > tmp_tbl.after_jfmgk then
@@ -370,47 +379,46 @@ local function new_ruby_box(r, p, tmp_tbl, no_begin, no_end)
    imode = floor(imode/2); rpost = imode%8;
    imode = (imode-rpost)/8;  rmid  = imode%8;
    imode = (imode-rmid)/8;   rpre  = imode%8
-   if getfield(r, 'width') > getfield(p, 'width') then  -- change the width of p
+   if getwidth(r) > getwidth(p) then  -- change the width of p
       r, p, post_intrusion, post_jfmgk = enlarge_parent(r, p, tmp_tbl, no_begin, no_end)
-   elseif getfield(r, 'width') < getfield(p, 'width') then -- change the width of r
-      r = enlarge(r, getfield(p, 'width'), rpre, rmid, rpost, 0, 0)
+   elseif getwidth(r) < getwidth(p) then -- change the width of r
+      r = enlarge(r, getwidth(p), rpre, rmid, rpost, 0, 0)
       post_intrusion = 0
       local need_repack = false
       -- margin が大きくなりすぎた時の処理
       if round(rpre*getfield(r, 'glue_set')*65536) > max_margin then
          local ps = getlist(r); need_repack = true
-         setfield(ps, 'width', max_margin)
+         setwidth(ps, max_margin)
          setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
       end
       if round(rpost*getfield(r, 'glue_set')*65536) > max_margin then
          local ps = node_tail(getlist(r)); need_repack = true
-         setfield(ps, 'width', max_margin)
+         setwidth(ps, max_margin)
          setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
       end
       if need_repack then
          local rt = r
-         r = node.direct.hpack(getlist(r), getfield(r, 'width'), 'exactly')
-         setfield(rt, 'head', nil); node_free(rt);
+         r = hpack(getlist(r), getwidth(r), 'exactly')
+         setlist(rt, nil); node_free(rt);
       end
    end
    local a, k = node_new(id_rule), node_new(id_kern, 1)
-   setfield(a, 'width', 0); setfield(a, 'height', 0)
-   setfield(a, 'depth', 0); setfield(k, 'kern', tmp_tbl.intergap)
+   setwhd(a, 0, 0, 0); setkern(k, tmp_tbl.intergap)
    insert_after(r, r, a); insert_after(r, a, k);
-   insert_after(r, k, p); setfield(p, 'next', nil)
-   if tmp_tbl.rubydepth >= 0 then setfield(r, 'depth', tmp_tbl.rubydepth) end
-   if tmp_tbl.baseheight >= 0 then setfield(p, 'height', tmp_tbl.baseheight) end
-   a = node.direct.vpack(r); setfield(a, 'shift', 0)
+   insert_after(r, k, p); setnext(p, nil)
+   if tmp_tbl.rubydepth >= 0 then setdepth(r, tmp_tbl.rubydepth) end
+   if tmp_tbl.baseheight >= 0 then setheight(p, tmp_tbl.baseheight) end
+   a = node.direct.vpack(r); setshift(a, 0)
    set_attr(a, attr_ruby, post_intrusion)
    set_attr(a, attr_ruby_post_jfmgk, post_jfmgk and 1 or 0)
-   if rsmash or getfield(a, 'height')<getfield(p, 'height') then
+   if rsmash or getheight(a)<getheight(p) then
       local k = node_new(id_kern, 1)
-      setfield(k, 'kern', -getfield(a, 'height')+getfield(p, 'height'))
-      setfield(a, 'head', k); insert_before(r, r, k)
-      setfield(a, 'height', getfield(p, 'height'))
+      setkern(k, -getheight(a)+getheight(p))
+      setlist(a, k); insert_before(r, r, k)
+      setheight(a, getheight(p))
    end
 
-   return a, getfield(r, 'width'), post_intrusion, post_jfmgk
+   return a, getwidth(r), post_intrusion, post_jfmgk
 end
 
 
@@ -474,7 +482,7 @@ local function pre_low_cal_box(w, cmp)
    -- w.value の node list 更新.
    local nt = wv
    node.direct.flush_list(node_next(wv))
-   for i = 1, 2*cmp+1 do setfield(nt, 'next', kf[i]); nt = kf[i]  end
+   for i = 1, 2*cmp+1 do setnext(nt, kf[i]); nt = kf[i]  end
 
    if cmp==1 then     solve_1(coef)
    elseif cmp==2 then solve_2(coef)
@@ -506,10 +514,8 @@ local function pre_low_app_node(head, w, cmp, coef, ht, dp)
    nt = w
    for i = 1, cmp do
       -- rule
-      local nta = node_new(id_rule);
-      setfield(nta, 'width', coef[i*2][2*cmp+2])
-      setfield(nta, 'height', ht); setfield(nta, 'depth', dp)
-      setfield(nta, 'subtype', 0)
+      local nta = node_new(id_rule, 0);
+      setwhd(nta, coef[i*2][2*cmp+2], ht, dp)
       insert_after(head, nt, nta)
       set_attr(nta, attr_ruby, 2*i+1)
       -- glue
@@ -561,7 +567,7 @@ local function pre_high(ahead)
          local coef = pre_low_cal_box(n, rst.count)
          local s = node_tail(nv) --ルビ文字
          head, n = pre_low_app_node(
-            head, n, rst.count, coef, getfield(s, 'height'), getfield(s, 'depth')
+            head, n, rst.count, coef, getheight(s), getdepth(s)
          )
       else
          n = first_whatsit(node_next(n))
@@ -602,7 +608,7 @@ do
             local deg, hn = (fn-1)/2, wv
             for i = 1, deg do hn = node_next(hn) end;
             node_remove(wv, hn)
-            setfield(hn, 'next', nil)
+            setnext(hn, nil)
             insert_after(ch, rs[1], hn)
             set_attr(hn, attr_icflag,  PROCESSED)
             write_aux(wv, has_attr(hn, attr_ruby), has_attr(hn, attr_ruby_post_jfmgk))
@@ -612,7 +618,7 @@ do
          for i = 1, cmp+deg-1 do hn = node_next(hn) end
          -- -1 is needed except the case hn = 3,
          --   because a ending-line form is removed already from the list
-         node_remove(wv, hn); setfield(hn, 'next', nil)
+         node_remove(wv, hn); setnext(hn, nil)
          insert_after(ch, rs[1], hn)
          set_attr(hn, attr_icflag,  PROCESSED)
          if fn == 2*cmp-1 then
@@ -646,19 +652,19 @@ local function post_high_break(head)
          if i==0 then
             ha = node_next(ha)
          elseif i==1 then
-            setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
+            setlist(h, post_lown(rs, rw, cmp, getlist(h)))
             for i = 2, #rs do rs[i] = nil end -- rs[1] is set by the next statement
             rs[1], rw = ha, nil; ha = node_next(ha)
          elseif i==2 then
             rw = ha
             cmp = getfield(getfield(rw, 'value'), 'value').count
             local hb, hc =  node_remove(getlist(h), rw)
-            setfield(h, 'head', hb); ha = hc
+            setlist(h, hb); ha = hc
          else -- i>=3
             rs[#rs+1] = ha; ha = node_next(ha)
          end
       end
-      setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
+      setlist(h, post_lown(rs, rw, cmp, getlist(h)))
    end
    return head
 end
@@ -759,8 +765,8 @@ do
       local ic = get_attr_icflag(p)
       if ic and (ic>FROM_JFM) and (ic<KANJI_SKIP) then ic = FROM_JFM end
       if t.intrude_jfmgk[ic] then
-          if getid(p)==id_kern then t[index] = t[index] + getfield(p, 'kern')
-          else t[index] = t[index] + getfield(p, 'width') end
+          if getid(p)==id_kern then t[index] = t[index] + getkern(p)
+          else t[index] = t[index] + getwidth(p) end
       end
    end
    local RIPOST = luatexja.stack_table_index.RIPOST
index 0e8e39f..af474e8 100644 (file)
@@ -15,21 +15,23 @@ local getfont = node.direct.getfont
 local getlist = node.direct.getlist
 local getchar = node.direct.getchar
 local getsubtype = node.direct.getsubtype
-local getwidth = node.direct.getwidth or function(n) return getfield(n,'width') end
-local getdepth = node.direct.getdepth or function(n) return getfield(n,'depth') end
-local getwhd = node.direct.getwhd or function(n)
-  return getfield(n,'width'), getfield(n,'height'),getfield(n,'depth') end
+local getwidth = node.direct.getwidth
+local getshift = node.direct.getshift
+local getoffsets = node.direct.getoffsets
+local getheight = node.direct.getheight
+local getdepth = node.direct.getdepth
+local getwhd = node.direct.getwhd
 
-local setwhd = node.direct.setwhd or function(n,w,h,d)
-  setfield(n,'width',w); setfield(n,'height',h); setfield(n,'depth',d) end
-local setchar = node.direct.setchar or function(n,c) setfield(n,'char',c) end
-local setnext = node.direct.setnext or function(n,c) setfield(n,'next',c) end
-local setdir = node.direct.setdir or function(n,c) setfield(n,'dir',c) end
-local setkern = node.direct.setkern or function(n,c) setfield(n,'kern',c) end
-local setoffsets = node.direct.setoffsets or function(n,x,y)
-  setfield(n,'xoffset',x); setfield(n,'yoffset',y)  end
-local getoffsets = node.direct.getoffsets or function(n)
-  return getfield(n,'xoffset'), getfield(n,'yoffset')  end
+local setwhd = node.direct.setwhd
+local setchar = node.direct.setchar
+local setnext = node.direct.setnext
+local setdir = node.direct.setdir
+local setkern = node.direct.setkern
+local setshift = node.direct.setshift
+local setoffsets = node.direct.setoffsets
+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
@@ -142,8 +144,7 @@ local function capsule_glyph_yoko(p, met, char_data, head, dir)
    setnext(p, nil)
    local box = node_new(id_hlist, nil, p)
    setwhd(box, fwidth, fheight, fdepth)
-   setfield(box, 'head', p)
-   setfield(box, 'shift', kbl)
+   setlist(box, p); setshift(box, kbl)
    setdir(box, dir)
    set_attr(box, attr_icflag, PACKED)
    head = q and node_insert_before(head, q, box)
@@ -172,8 +173,7 @@ local function capsule_glyph_tate_rot(p, met, char_data, head, dir, asc)
    setnext(p, nil)
    local box = node_new(id_hlist, nil, p)
    setwhd(box, fwidth, fheight, fdepth)
-   setfield(box, 'head', p)
-   setfield(box, 'shift', kbl)
+   setlist(box, p); setshift(box, kbl)
    setdir(box, dir)
    set_attr(box, attr_icflag, PACKED)
    head = q and node_insert_before(head, q, box)
@@ -217,8 +217,7 @@ local function capsule_glyph_tate(p, met, char_data, head, dir)
    local q
    head, q = node_remove(head, p)
    local box = node_new(id_hlist, nil, p)
-   setwhd(box, fwidth, fheight, fdepth)
-   setfield(box, 'shift', y_shift)
+   setwhd(box, fwidth, fheight, fdepth); setshift(box, y_shift)
    setdir(box, dir)
    -- print(yo, ascender, char_data.align, fwidth-pwidth)
    setoffsets(p, -fshift.down,
@@ -230,7 +229,7 @@ local function capsule_glyph_tate(p, met, char_data, head, dir)
    local k2 = node_new(id_kern, 1); setkern(k2, pwnh)
    local k3 = node_new(id_kern, 1); setkern(k3, -getwidth(p)-pwnh)
    local wr = node_new(id_whatsit, sid_restore)
-   setfield(box, 'head', ws)
+   setlist(box, ws)
    setnext(ws, wm);  setnext(wm, k2);
    setnext(k2, p);   setnext(p,  k3);
    setnext(k3, wr);
@@ -256,8 +255,7 @@ local function capsule_glyph_math(p, met, char_data)
    setfield(p, 'xoffset', getfield(p, 'xoffset') + char_data.align*(fwidth-pwidth) - fshift.left)
    local box = node_new(id_hlist, nil, p);
    setwhd(box, fwidth, fheight, fdepth)
-   setfield(box, 'head', p)
-   setfield(box, 'shift', y_shift)
+   setlist(box, p); setshift(box, y_shift)
    setdir(box, tex.mathdir)
    set_attr(box, attr_icflag, PACKED)
    return box
@@ -272,11 +270,10 @@ function luatexja.setwidth.apply_ashift_math(head, last, attr_ablshift)
          return
       elseif (has_attr(p, attr_icflag) or 0) ~= PROCESSED then
          if pid==id_hlist or pid==id_vlist then
-            setfield(p, 'shift', getfield(p, 'shift') +  (has_attr(p,attr_ablshift) or 0)) 
+            setshift(p, getshift(p) +  (has_attr(p,attr_ablshift) or 0)) 
          elseif pid==id_rule then
             local v = has_attr(p,attr_ablshift) or 0
-            setfield(p, 'height', getfield(p, 'height')-v)
-            setfield(p, 'depth', getdepth(p)+v)
+            setheight(p, getheight(p)-v); setdepth(p, getdepth(p)+v)
             set_attr(p, attr_icflag, PROCESSED)
          elseif pid==id_glyph then
             -- 欧文文字; 和文文字は pid == id_hlist の場合で処理される
index 8da4251..b2561d7 100644 (file)
@@ -40,21 +40,36 @@ do
     end
 end
 do
-   local setfield = node.direct.setfield
+   local dnode = node.direct
+   local setfield = dnode.setfield
    luatexja.setglue = node.direct.setglue or
    function(g,w,st,sh,sto,sho)
       setfield(g,'width', w or 0); setfield(g,'stretch',st or 0); setfield(g,'shrink', sh or 0)
       setfield(g,'stretch_order',sto or 0)
       setfield(g,'shrink_order', sho or 0)
    end
-   local getfield = node.direct.getfield
+   for _,v in pairs({'char', 'depth', 'dir', 'font', 'height', 'kern', 'lang', 'next', 
+                      'nucleus', 'offsets', 'penalty', 'shift', 'sub', 'subtype', 'sup'}) do
+         if not dnode['set'..v] then 
+             dnode['set'..v] = function(n, ...) return setfield(n, v, ...) end
+         end
+   end
+   local getfield = dnode.getfield
    luatexja.getglue = node.direct.getglue or
    function(g)
       return getfield(g,'width'), getfield(g,'stretch'), getfield(g,'shrink'),
              getfield(g,'stretch_order'), getfield(g,'shrink_order')
    end
+   for _,v in pairs({'box', 'components', 'char', 'depth', 'font', 'height', 'kern', 'lang', 
+                     'list', 'next', 'nucleus', 'offsets', 'penalty', 'prev', 'shift', 'sub',
+                     'subtype', 'sup', 'whd', 'width', 'dir'}) do
+         if not dnode['get'..v] then 
+             dnode['get'..v] = function(n, ...) return getfield(n, v, ...) end
+         end
+    end
 end
 
+
 --- 以下は全ファイルで共有される定数
 local icflag_table = {}
 luatexja.icflag_table = icflag_table
index 1e9abe0..f1435f7 100644 (file)
       {Use \string\KanjiEncodingPair, falling back to `\reserved@b'...}%
     \expandafter\edef\reserved@a{\reserved@b}%
   \fi}
+
 \def\set@fontsize#1#2#3{%
     \@defaultunits\@tempdimb#2pt\relax\@nnil
     \edef\f@size{\strip@pt\@tempdimb}%
index c766ec4..12605ff 100644 (file)
@@ -3,7 +3,7 @@
 %
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{lltjp-atbegshi}[2021-04-29 Patching \string\shipout\space hooks for LuaTeX-ja]
+\ProvidesPackage{lltjp-atbegshi}[2022-08-12 Patching \string\shipout\space hooks for LuaTeX-ja]
 
 % concept: execute all hooks inside yoko direction \vbox
 
@@ -37,6 +37,7 @@
     % however, an infinite loop occurs if we uncomment the line below
     % so we can't.
     %\box_use:N \l__platex_shipout_dummy_box
+    \box_clear:N \l__platex_shipout_dummy_box
   }
 }
 
@@ -53,6 +54,7 @@
     \vbox_set:Nn \l__platex_shipout_dummy_box {
       \platex_direction_yoko: \__platex_original_shipout_execute_cont:
     }
+    \box_clear:N \l__platex_shipout_dummy_box
   }
 }
 \fi:
   {\setbox8\vbox\bgroup\yoko\let\AtBegShi@OrgProtect\protect}
 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
   {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox}%
-  {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox\egroup}
+  {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox\egroup\setbox8\box\voidb@x}
 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
   {%
     \begingroup
index e9510e2..c1c0744 100644 (file)
@@ -12,7 +12,7 @@
     \@EveryShipout@Hook
     \@EveryShipout@AtNextHook
     \global\setbox\luatexoutputbox=\box\luatexoutputbox
-  }%
+  }\setbox8\box\voidb@x%
   \gdef\@EveryShipout@AtNextHook{}%
   \@EveryShipout@Org@Shipout\box\luatexoutputbox
 }