OSDN Git Service

recent commits (around 6047ee0 and later) makes SyncTeX unusable, so I manually rever...
[luatex-ja/luatexja.git] / src / ltj-jfmglue.lua
index 4224996..8d564dc 100644 (file)
@@ -82,11 +82,9 @@ local IC_PROCESSED = luatexja.icflag_table.IC_PROCESSED
 local BOXBDD       = luatexja.icflag_table.BOXBDD
 local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG
 
-local kanji_skip = node_new(id_glue)
-local xkanji_skip = node_new(id_glue)
-set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
-set_attr(xkanji_skip, attr_icflag, XKANJI_SKIP)
-
+local attr_icflag = luatexbase.attributes['ltj@icflag']
+local kanji_skip
+local xkanji_skip
 local table_current_stack
 local list_dir
 local capsule_glyph
@@ -95,7 +93,6 @@ local attr_ablshift
 local set_np_xspc_jachar
 local set_np_xspc_jachar_hbox
 
-local attr_icflag = luatexbase.attributes['ltj@icflag']
 local ltjs_orig_char_table = ltjs.orig_char_table
 
 local function get_attr_icflag(p)
@@ -494,6 +491,7 @@ local calc_np_auxtable = {
    end,
    [id_kern] = function(lp)
       if getsubtype(lp)==2 then
+        Np.first = Np.first or lp
         set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
         set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
         set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
@@ -689,18 +687,18 @@ end
 -- 和文文字間の JFM glue を node 化
 local function new_jfm_glue(m, bc, ac)
 -- bc, ac: char classes
-   local g, d = m.char_type[bc][ac], 0
-   local n
+   local g = m.char_type[bc][ac]
    if g then
-      n,d = node_copy(g[2]), g[3]
       if g[1] then
         local f = node_new(id_glue)
         set_attr(f, attr_icflag, g[4])
-        setfield(f, 'spec', n)
-        return f, d
+        setfield(f, 'spec', node_copy(g[2]))
+        return f, g[3]
+      else
+        return node_copy(g[2]), g[3]
       end
    end
-   return n, d
+   return nil, 0
 end
 
 -- Nq.last (kern w) .... (glue/kern g) Np.first
@@ -986,8 +984,7 @@ local function handle_list_tail(mode)
       -- Insert \jcharwidowpenalty
       Bp = widow_Bp; Np = widow_Np
       if Np.first then
-        handle_penalty_normal(0,
-                              table_current_stack[JWP] or 0)
+        handle_penalty_normal(0, table_current_stack[JWP] or 0)
       end
    else
       -- the current list is the contents of a hbox
@@ -1053,10 +1050,12 @@ do
       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
 
+      kanji_skip = node_new(id_glue); set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
       setfield(kanji_skip, 'spec', skip_table_to_spec(KSK))
       get_kanjiskip = (getfield(getfield(kanji_skip, 'spec'), 'width') == 1073741823)
         and get_kanjiskip_jfm or get_kanjiskip_normal
 
+      xkanji_skip = node_new(id_glue); set_attr(xkanji_skip, attr_icflag, XKANJI_SKIP)
       setfield(xkanji_skip, 'spec', skip_table_to_spec(XSK))
       get_xkanjiskip = (getfield(getfield(xkanji_skip, 'spec'), 'width') == 1073741823)
         and get_xkanjiskip_jfm or get_xkanjiskip_normal
@@ -1079,12 +1078,11 @@ do
    end
 end
 
-local tex_set_attr = tex.setattribute
+local ensure_tex_attr = ltjb.ensure_tex_attr
 local function cleanup(mode)
    -- adjust attr_icflag for avoiding error
-   if tex.getattribute(attr_icflag)~=0 then tex_set_attr('global', attr_icflag, 0) end
-   node_free(getfield(kanji_skip, 'spec'))
-   node_free(getfield(xkanji_skip, 'spec'))
+   if tex.getattribute(attr_icflag)~=0 then ensure_tex_attr('global', attr_icflag, 0) end
+   node_free(kanji_skip); node_free(xkanji_skip)
    if mode then
       local h = node_next(head)
       if getid(h) == id_penalty and getfield(h, 'penalty') == 10000 then
@@ -1104,7 +1102,7 @@ function main(ahead, mode, dir)
    head = ahead;
    local lp, last, par_indented = init_var(mode,dir)
    lp = calc_np(last, lp)
-   if lp then
+   if Np then
       handle_list_head(par_indented)
       lp = calc_np(last,lp); while Np do
         adjust_nq();