OSDN Git Service

try to fix #42855 (not well tested)
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 12 Sep 2021 08:58:12 +0000 (17:58 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 12 Sep 2021 08:58:12 +0000 (17:58 +0900)
src/ltj-jfmglue.lua
src/ltj-setwidth.lua
src/luatexja.lua

index 7437492..2932625 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfmglue',
-  date = '2021-02-11',
+  date = '2021-09-12',
   description = 'Insertion process of JFM glues, [x]kanjiskip and others',
 })
 luatexja.jfmglue = luatexja.jfmglue or {}
@@ -45,11 +45,12 @@ local node_next = node.direct.getnext
 local ltjd_make_dir_whatsit = ltjd.make_dir_whatsit
 local ltjf_font_metric_table = ltjf.font_metric_table
 local ltjf_find_char_class = ltjf.find_char_class
-local node_new = node.direct.new
+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_remove = node.direct.remove
+local node_inherit_attr = luatexja.node_inherit_attr
 
 local id_glyph = node.id 'glyph'
 local id_hlist = node.id 'hlist'
@@ -689,7 +690,7 @@ local function handle_penalty_normal(post, pre, g)
    local a = (pre or 0) + (post or 0)
    if #Bp == 0 then
       if (a~=0 and not(g and getid(g)==id_kern)) then
-         local p = node_new(id_penalty)
+         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)
          Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
@@ -703,7 +704,7 @@ local function handle_penalty_always(post, pre, g)
    local a = (pre or 0) + (post or 0)
    if #Bp == 0 then
       if not (g and getid(g)==id_glue) or a~=0 then
-         local p = node_new(id_penalty)
+         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)
          Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
@@ -716,7 +717,7 @@ local function handle_penalty_suppress(post, pre, g)
    luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp)
    if #Bp == 0 then
       if g and getid(g)==id_glue then
-         local p = node_new(id_penalty)
+         local p = node_new(id_penalty, nil, Nq.nuc, Np.nuc)
          setfield(p, 'penalty', 10000); head = insert_before(head, Np.first, p)
          Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
       end
@@ -759,6 +760,7 @@ end
 -- Nq.last (kern w) .... (glue/kern g) Np.first
 local function real_insert(g)
    if g then
+      node_inherit_attr(g, Nq.nuc, Np.nuc)
       head  = insert_before(head, Np.first, g)
       Np.first = g
       local ngk = Np.gk
@@ -1151,7 +1153,7 @@ local function handle_list_head(par_indented)
          if g then
             set_attr(g, attr_icflag, BOXBDD)
             if getid(g)==id_glue and #Bp==0 then
-               local h = node_new(id_penalty)
+               local h = node_new(id_penalty, nil, Nq.nuc, Np.nuc)
                setfield(h, 'penalty', 10000); set_attr(h, attr_icflag, BOXBDD)
             end
             head = insert_before(head, Np.first, g)
index 03ec44f..2c8a6e8 100644 (file)
@@ -33,7 +33,6 @@ local getoffsets = node.direct.getoffsets or function(n)
 
 local node_traverse_id = node.direct.traverse_id
 local node_traverse = node.direct.traverse
-local node_new = node.direct.new
 local node_copy = node.direct.copy
 local node_remove = node.direct.remove
 local node_tail = node.direct.tail
@@ -43,6 +42,7 @@ local set_attr = node.direct.set_attribute
 local node_insert_before = node.direct.insert_before
 local node_insert_after = node.direct.insert_after
 local round = tex.round
+local node_new = luatexja.dnode_new
 
 local id_glyph  = node.id 'glyph'
 local id_kern   = node.id 'kern'
@@ -76,6 +76,7 @@ do
    end
 end
 
+
 local ltjw = {} --export
 luatexja.setwidth = ltjw
 
@@ -114,7 +115,7 @@ local function capsule_glyph_yoko(p, met, char_data, head, dir)
          setoffsets(p, xo - fshift.left, yo - kbl - fshift.down)
          return node_next(p), head, p
       elseif ht_diff >= 0 and dp_diff >=0 then -- rule
-         local box = node_new(id_rule,rule_subtype)
+         local box = node_new(id_rule,rule_subtype, p)
          local xo, yo = getoffsets(p)
          setoffsets(p, xo, yo - kbl - fshift.down)
          setwhd(box, 0, fheight - kbl, fdepth + kbl)
@@ -140,7 +141,7 @@ local function capsule_glyph_yoko(p, met, char_data, head, dir)
    setoffsets(p, xo + char_data.align*(fwidth-pwidth) - fshift.left,
               yo - fshift.down);
    setnext(p, nil)
-   local box = node_new(id_hlist)
+   local box = node_new(id_hlist, nil, p)
    setwhd(box, fwidth, fheight, fdepth)
    setfield(box, 'head', p)
    setfield(box, 'shift', kbl)
index 878f791..5647438 100644 (file)
@@ -12,6 +12,33 @@ luatexja.load_lua = load_lua
 function luatexja.load_module(name) require('ltj-' .. name.. '.lua') end
 
 do
+    local dnode = node.direct
+    local getfield, traverse = dnode.getfield, dnode.traverse
+    local node_new, set_attr, get_attr = dnode.new, dnode.set_attribute, dnode.get_attribute
+    local set_attrlist, get_attrlist = dnode.setattributelist, dnode.getattributelist
+    local unset_attr = dnode.unset_attribute
+    local attr_icflag = luatexbase.attributes['ltj@icflag']
+    local function node_inherit_attr(n, b, a)
+        if b or a then
+            local attrlist = get_attrlist(b or a)
+            local nic = get_attr(n, attr_icflag)
+            set_attrlist(n, attrlist); set_attr(n, attr_icflag, nic)
+            if b and a then
+                for na in traverse(attrlist) do
+                    local id = getfield(na, 'number')
+                    if id and id~=attr_icflag and getfield(na, 'value')~=get_attr(a, id) then
+                        unset_attr(n, id)
+                    end
+                end
+            end
+        end                        
+    end
+    luatexja.node_inherit_attr = node_inherit_attr
+    luatexja.dnode_new = function (id, subtype, b, a)
+        local n = node_new(id, subtype); node_inherit_attr(n, b, a); return n
+    end
+end
+do
    local setfield = node.direct.setfield
    luatexja.setglue = node.direct.setglue or
    function(g,w,st,sh,sto,sho)