OSDN Git Service

recent commits (around 6047ee0 and later) makes SyncTeX unusable, so I manually rever...
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Wed, 4 Feb 2015 01:25:36 +0000 (10:25 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Wed, 4 Feb 2015 01:25:36 +0000 (10:25 +0900)
src/ltj-base.lua
src/ltj-direction.lua
src/ltj-jfmglue.lua
src/ltj-jfont.lua
src/ltj-setwidth.lua
src/luatexja.lua

index f80301a..f5535d6 100644 (file)
@@ -563,7 +563,6 @@ do
    ltjb.save_cache = save_cache
 end
 
-
 ----
 do
    local tex_set_attr, tex_get_attr = tex.setattribute, tex.getattribute
@@ -573,7 +572,6 @@ do
       end
    end
 end
-
 ----
 
 ltjb._error_set_break = _error_set_break
index 03b7295..d94c546 100644 (file)
@@ -63,21 +63,6 @@ end
 
 local page_direction
 --
-local dir_pool
-do
-   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)
-      setfield(w, 'user_id', DIR)
-      setfield(w, 'type', 110)
-      setfield(w, 'next', nil)
-      dir_pool[i] = function () return node_copy(w) end
-   end
-end
-
-
 local function adjust_badness(hd)
    if not node_next(hd) and getid(hd)==id_whatsit and getsubtype(hd)==sid_user
    and getfield(hd, 'user_id')==DIR then
@@ -181,7 +166,11 @@ do
          v = get_adjust_dir_count()
       end
       local h = to_direct(tex_nest[lv].head)
-      local w = dir_pool[v]()
+      local w = node_new(id_whatsit, sid_user)
+      setfield(w, 'next', nil)
+      setfield(w, 'user_id', DIR)
+      setfield(w, 'type', 110)
+      set_attr(w, attr_dir, v)
       insert_after(h, h, w)
       tex_nest[lv].tail = to_node(node_tail(w))
       ensure_tex_attr(attr_icflag, 0)
@@ -221,7 +210,12 @@ do
            node_set_attr(w, attr_dir, v)
            if lv==0 then page_direction = v end
         else
-           Dnode.write(dir_pool[v]())
+           local w = node_new(id_whatsit, sid_user)
+           setfield(w, 'next', nil)
+           setfield(w, 'user_id', DIR)
+           setfield(w, 'type', 110)
+           set_attr(w, attr_dir, v)
+           Dnode.write(w)
            if lv==0 then page_direction = v end
         end
          ensure_tex_attr(attr_icflag, 0)
@@ -245,8 +239,11 @@ local function create_dir_whatsit(hd, gc, new_dir)
       ensure_tex_attr(attr_icflag, 0)
       return hd
    else
-      local w = dir_pool[new_dir]()
+      local w = node_new(id_whatsit, sid_user)
       setfield(w, 'next', hd)
+      setfield(w, 'user_id', DIR)
+      setfield(w, 'type', 110)
+      set_attr(w, attr_dir, new_dir)
       set_attr(w, attr_icflag, PROCESSED_BEGIN_FLAG)
       set_attr(hd, attr_icflag,
               get_attr_icflag(hd) + PROCESSED_BEGIN_FLAG)
@@ -281,7 +278,7 @@ do
    local function create_dir_whatsit_parbox(h, gc)
       stop_time_measure('tex_linebreak')
       -- start 側は ltj-debug.lua に
-      local new_dir =  ltjs.list_dir
+      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) )
       end
@@ -932,7 +929,12 @@ do
         end
         for box_rule in traverse(h) do
            if getid(box_rule)<id_rule then
-              h = insert_before(h, box_rule, dir_pool[list_dir]())
+              local w = node_new(id_whatsit, sid_user)
+              setfield(w, 'next', nil)
+              setfield(w, 'user_id', DIR)
+              setfield(w, 'type', 110)
+              set_attr(w, attr_dir, list_dir)
+              h = insert_before(h, box_rule, w)
            end
         end
         ensure_tex_attr(attr_dir, 0)
@@ -1058,8 +1060,8 @@ do
             insert_after(db_head, db_tail, nn)
             db_tail = nn
          else
-           setfield(db, 'head', nn)
-            db_head, db_tail = nn, nn
+            setfield(db, 'head', nn)
+           db_head, db_tail = nn, nn
          end
       end
    end
index b080005..8d564dc 100644 (file)
@@ -76,21 +76,15 @@ local sid_end_thread = node.subtype('pdf_end_thread')
 local ITALIC       = luatexja.icflag_table.ITALIC
 local PACKED       = luatexja.icflag_table.PACKED
 local KINSOKU      = luatexja.icflag_table.KINSOKU
+local FROM_JFM     = luatexja.icflag_table.FROM_JFM
 local PROCESSED    = luatexja.icflag_table.PROCESSED
 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 attr_icflag = luatexbase.attributes['ltj@icflag']
-local kanji_skip = node_new(id_glue)
-local xkanji_skip = node_new(id_glue)
-do
-   local KANJI_SKIP   = luatexja.icflag_table.KANJI_SKIP
-   local XKANJI_SKIP   = luatexja.icflag_table.XKANJI_SKIP
-   set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
-   set_attr(xkanji_skip, attr_icflag, XKANJI_SKIP)
-end
-
+local kanji_skip
+local xkanji_skip
 local table_current_stack
 local list_dir
 local capsule_glyph
@@ -647,18 +641,16 @@ end
 -------------------- 最下層の処理
 
 -- change penalties (or create a new penalty, if needed)
-local pen_skel = node_new(id_penalty)
-set_attr(pen_skel, attr_icflag, KINSOKU)
-
 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_copy(pen_skel)
+        local p = node_new(id_penalty)
         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)
       end
    else for _, v in pairs(Bp) do add_penalty(v,a) end
    end
@@ -668,11 +660,12 @@ 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_copy(pen_skel)
+        local p = node_new(id_penalty)
         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)
       end
    else for _, v in pairs(Bp) do add_penalty(v,a) end
    end
@@ -682,36 +675,30 @@ local function handle_penalty_suppress(post, pre, g)
    local a = (pre or 0) + (post or 0)
    if #Bp == 0 then
       if g and getid(g)==id_glue then
-        local p = node_copy(pen_skel)
+        local p = node_new(id_penalty)
         setfield(p, 'penalty', 10000); 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
    end
 end
 
 -- 和文文字間の JFM glue を node 化
-local new_jfm_glue
-do
-   local FROM_JFM = luatexja.icflag_table.FROM_JFM
-   local glue_skel = {}
-   for i=FROM_JFM-2,FROM_JFM+2 do
-      glue_skel[i]= node_new(id_glue); set_attr(glue_skel[i], attr_icflag, i)
-   end
-   function new_jfm_glue(m, bc, ac)
-      -- bc, ac: char classes
-      local g = m.char_type[bc][ac]
-      if g then
-        if g[1] then
-           local f = node_copy(glue_skel[g[4]])
-           setfield(f, 'spec', node_copy(g[2]))
-           return f, g[3]
-        else
-           return node_copy(g[2]), g[3]
-        end
+local function new_jfm_glue(m, bc, ac)
+-- bc, ac: char classes
+   local g = m.char_type[bc][ac]
+   if g then
+      if g[1] then
+        local f = node_new(id_glue)
+        set_attr(f, attr_icflag, g[4])
+        setfield(f, 'spec', node_copy(g[2]))
+        return f, g[3]
+      else
+        return node_copy(g[2]), g[3]
       end
-      return nil, 0
    end
+   return nil, 0
 end
 
 -- Nq.last (kern w) .... (glue/kern g) Np.first
@@ -904,7 +891,7 @@ end
 local function handle_np_jachar(mode)
    local qid = Nq.id
    if qid==id_jglyph or ((qid==id_pbox or qid==id_pbox_w) and Nq.met) then
-      local g = non_ihb_flag and calc_ja_ja_glue() or get_kanjiskip() -- M->K
+       local g = non_ihb_flag and calc_ja_ja_glue() or get_kanjiskip() -- M->K
       handle_penalty_normal(Nq.post, Np.pre, g); real_insert(g)
    elseif Nq.met then  -- qid==id_hlist
       local g = non_ihb_flag and get_OA_skip() or get_kanjiskip() -- O_A->K
@@ -997,7 +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
@@ -1063,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
@@ -1089,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
@@ -1117,19 +1105,19 @@ function main(ahead, mode, dir)
    if Np then
       handle_list_head(par_indented)
       lp = calc_np(last,lp); while Np do
-        adjust_nq();
-        local pid, pm = Np.id, Np.met
-        -- 挿入部
-        if pid == id_jglyph then
-           handle_np_jachar(mode)
-        elseif pm then
-           if pid==id_hlist then handle_np_ja_hlist()
-           else handle_np_jachar() end
-        elseif Nq.met then
-           if Nq.id==id_hlist then handle_nq_ja_hlist()
-           else handle_nq_jachar() end
-        end
-        lp = calc_np(last,lp)
+        adjust_nq();
+        local pid, pm = Np.id, Np.met
+        -- 挿入部
+        if pid == id_jglyph then
+           handle_np_jachar(mode)
+        elseif pm then
+           if pid==id_hlist then handle_np_ja_hlist()
+           else handle_np_jachar() end
+        elseif Nq.met then
+           if Nq.id==id_hlist then handle_nq_ja_hlist()
+           else handle_nq_jachar() end
+        end
+        lp = calc_np(last,lp)
       end
       handle_list_tail(mode)
    end
index aa92ceb..8bf3355 100644 (file)
@@ -136,11 +136,6 @@ end
 
 local update_jfm_cache
 do
-   local node_copy = Dnode.copy
-   local kern_skel = node_new(id_kern)
-   set_attr(kern_skel, attr_icflag, FROM_JFM)
-   setfield(kern_skel, 'subtype', 1)
-
    local function mult_table(old,scale) -- modified from table.fastcopy
       if old then
         local new = { }
@@ -177,8 +172,10 @@ do
               setfield(h, 'shrink_order', 0)
            end
            for k,w in pairs(v.kern) do
-              local g = node_copy(kern_skel)
+              local g = node_new(id_kern)
               setfield(g, 'kern', w[1])
+              setfield(g, 'subtype', 1)
+              set_attr(g, attr_icflag, FROM_JFM)
               v[k] = {false, g, w[2]/sz}
            end
         end
index 258d3f7..140480e 100644 (file)
@@ -74,9 +74,6 @@ local call_callback = luatexbase.call_callback
 local fshift =  { down = 0, left = 0}
 
 local min, max = math.min, math.max
-local pack_rule, pack_box = node_new(id_rule), node_new(id_hlist)
-set_attr(pack_rule, attr_icflag, PACKED)
-set_attr(pack_box, attr_icflag, PACKED)
 
 -- 和文文字の位置補正(横)
 local function capsule_glyph_yoko(p, met, class, head, dir)
@@ -101,13 +98,13 @@ local function capsule_glyph_yoko(p, met, class, head, dir)
         setfield(p, 'yoffset', getfield(p, 'yoffset') - kbl - fshift.down)
         return node_next(p), head, p
       elseif ht_diff >= 0 and dp_diff >=0 then -- rule
-        local box = node_copy(pack_rule)
+        local box = node_new(id_rule)
         setfield(p, 'yoffset', getfield(p, 'yoffset') - kbl - fshift.down)
         setfield(box, 'width', 0)
         setfield(box, 'height', fheight - kbl)
         setfield(box, 'depth', fdepth + kbl)
         setfield(box, 'dir', dir)
-        --set_attr(box, attr_icflag, PACKED)
+        set_attr(box, attr_icflag, PACKED)
         set_attr(p, attr_icflag, PACKED)
         head = p and node_insert_before(head, p, box)
            or node_insert_after(head, node_tail(head), box)
@@ -121,20 +118,19 @@ local function capsule_glyph_yoko(p, met, class, head, dir)
    setfield(p, 'next', nil)
    setfield(p, 'xoffset', getfield(p, 'xoffset')
               + char_data.align*(fwidth-pwidth) - fshift.left)
-   local box = node_copy(pack_box)
+   local box = node_new(id_hlist)
    setfield(box, 'width', fwidth)
    setfield(box, 'height', fheight)
    setfield(box, 'depth', fdepth)
    setfield(box, 'head', p)
    setfield(box, 'shift', kbl)
    setfield(box, 'dir', dir)
-   --set_attr(box, attr_icflag, PACKED)
+   set_attr(box, attr_icflag, PACKED)
    head = q and node_insert_before(head, q, box)
       or node_insert_after(head, node_tail(head), box)
    return q, head, box
 end
 
-
 luatexja.setwidth.capsule_glyph_yoko = capsule_glyph_yoko
 
 -- 和文文字の位置補正(縦)
@@ -162,7 +158,7 @@ local function capsule_glyph_tate(p, met, class, head, dir)
       = getfield(p, 'xoffset') + (has_attr(p,attr_tkblshift) or 0)
    local q
    head, q = node_remove(head, p)
-   local box = node_copy(pack_box)
+   local box = node_new(id_hlist)
    setfield(box, 'width', fwidth)
    setfield(box, 'height', fheight)
    setfield(box, 'depth', fdepth)
@@ -183,6 +179,8 @@ local function capsule_glyph_tate(p, met, class, head, dir)
    setfield(ws, 'next', wm);  setfield(wm, 'next', k2);
    setfield(k2, 'next', p);   setfield(p, 'next', k3);
    setfield(k3, 'next', wr);
+
+   set_attr(box, attr_icflag, PACKED)
    head = q and node_insert_before(head, q, box)
       or node_insert_after(head, node_tail(head), box)
    return q, head, box
@@ -201,13 +199,14 @@ local function capsule_glyph_math(p, met, class)
       = - getfield(p, 'yoffset') + (has_attr(p,attr_ykblshift) or 0), char_data.align
    setfield(p, 'yoffset', -fshift.down)
    setfield(p, 'xoffset', getfield(p, 'xoffset') + char_data.align*(fwidth-pwidth) - fshift.left)
-   local box = node_copy(pack_box)
+   local box = node_new(id_hlist);
    setfield(box, 'width', fwidth)
    setfield(box, 'height', fheight)
    setfield(box, 'depth', fdepth)
    setfield(box, 'head', p)
    setfield(box, 'shift', y_shift)
    setfield(box, 'dir', tex.mathdir)
+   set_attr(box, attr_icflag, PACKED)
    return box
 end
 luatexja.setwidth.capsule_glyph_math = capsule_glyph_math
index 3d83401..8cabf87 100644 (file)
@@ -284,8 +284,6 @@ do
    local nullfunc = function (n) return n end
    local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
    local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
-   local tex_set_attr = tex.setattribute
-   local tex_get_attr, node_copy = tex.getattribute, Dnode.copy
    local ensure_tex_attr = ltjb.ensure_tex_attr
 
    -- mode = true iff main_process is called from pre_linebreak_filter