OSDN Git Service

Fix a bug that xkanjiskip is inserted in \hbox{a\null}あ
[luatex-ja/luatexja.git] / src / ltj-jfmglue.lua
index 966eaf9..6f83853 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfmglue',
-  date = '2015/02/07'
+  date = '2015/02/07',
   description = 'Insertion process of JFM glues and kanjiskip',
 })
 module('luatexja.jfmglue', package.seeall)
@@ -222,6 +222,7 @@ local function check_box(box_ptr, box_end)
            last_char = s; found_visible_node = true
         else
            if getfield(p, 'shift')==0 then
+              last_char = nil
               if check_box(getlist(p), nil) then found_visible_node = true end
            else
               find_first_char = false; last_char = nil
@@ -1043,6 +1044,9 @@ do
       local is_dir_tate = list_dir==dir_tate
       capsule_glyph = is_dir_tate and ltjw.capsule_glyph_tate or ltjw.capsule_glyph_yoko
       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.
 
       do
         kanji_skip = node_new(id_glue); set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
@@ -1071,18 +1075,18 @@ do
                Np.width = getfield(lp, 'width')
             end
            lp=node_next(lp); lpi, lps = getid(lp), getsubtype(lp) end
-        return lp, node_tail(head), par_indented
+        return lp, node_tail(head), par_indented, TEMP
       else
-        return head, nil, 'boxbdd'
+        return head, nil, 'boxbdd', TEMP
       end
    end
 end
 
 local ensure_tex_attr = ltjb.ensure_tex_attr
-local function cleanup(mode)
+local function cleanup(mode, TEMP)
    -- adjust attr_icflag for avoiding error
    if tex.getattribute(attr_icflag)~=0 then ensure_tex_attr(attr_icflag, 0) end
-   node_free(kanji_skip); node_free(xkanji_skip)
+   node_free(kanji_skip); node_free(xkanji_skip); node_free(TEMP)
    
    if mode then
       local h = node_next(head)
@@ -1101,7 +1105,7 @@ end
 function main(ahead, mode, dir)
    if not ahead then return ahead end
    head = ahead;
-   local lp, last, par_indented = init_var(mode,dir)
+   local lp, last, par_indented, TEMP = init_var(mode,dir)
    lp = calc_np(last, lp)
    if Np then
       handle_list_head(par_indented)
@@ -1122,7 +1126,7 @@ function main(ahead, mode, dir)
       end
       handle_list_tail(mode)
    end
-   return cleanup(mode)
+   return cleanup(mode, TEMP)
 end
 end