OSDN Git Service

Optimized ltj-pretreat.lua and updated test12-ltjtarticle.tex.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 10 Jun 2014 23:06:17 +0000 (08:06 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 10 Jun 2014 23:06:17 +0000 (08:06 +0900)
src/ltj-direction.lua
src/ltj-pretreat.lua
src/luatexja-core.sty
test/test12-ltjtarticle.pdf
test/test12-ltjtarticle.tex
test/test51-vtest.pdf
test/test52-vtest-ins.pdf

index 9e585f1..f16df90 100644 (file)
@@ -799,6 +799,22 @@ function luatexja.direction.check_adjust_direction()
    stop_time_measure('box_primitive_hook')
 end
 
+-- setbox
+local id_adjust = node.id('adjust')
+function luatexja.direction.hook_empty_box()
+   start_time_measure('box_primitive_hook')
+   local reg_num =  tex_getcount('ltj@tempcnta')
+   local list_dir = get_dir_count()
+   local h = tex.getbox(reg_num)
+   if h then
+      if not h.head then
+         h.head = to_node(create_dir_whatsit(nil, nil, get_dir_count()))
+         luatexja.ext_show_node(h, '> ', print)
+      end
+   end
+   stop_time_measure('box_primitive_hook')
+end
+
 -- vsplit
 do
    local split_dir_whatsit
index 080cf89..5182cb8 100644 (file)
@@ -26,6 +26,7 @@ local floor = math.floor
 local has_attr = Dnode.has_attribute
 local set_attr = Dnode.set_attribute
 local node_traverse = Dnode.traverse
+local node_traverse_id = Dnode.traverse_id
 local node_remove =luatexja.Dnode_remove -- Dnode.remove
 local node_next = (Dnode ~= node) and Dnode.getnext or node.next
 local node_prev = (Dnode ~= node) and Dnode.getprev or node.prev
@@ -56,50 +57,51 @@ local dir_tate = luatexja.dir_table.dir_tate
 ------------------------------------------------------------------------
 -- MAIN PROCESS STEP 1: replace fonts
 ------------------------------------------------------------------------
-local wt, wtd
+local wt, wtd = {}, {}
 do
    local start_time_measure, stop_time_measure 
       = ltjb.start_time_measure, ltjb.stop_time_measure
    local head
    local is_dir_tate
-   local suppress_hyphenate_ja_aux = {}
-   suppress_hyphenate_ja_aux[id_glyph] = function(p)
+   local suppress_hyphenate_ja_aux_glyph = function(p)
       if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p) then
          local pc = getchar(p)
-        local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc)
-        setfield(p, 'font', pf);  set_attr(p, attr_curjfnt, pf)
+         local pof, pcj = getfont(p), has_attr(p, attr_curjfnt)
+        local pf = ltjf_replace_altfont(pcj or pof, pc)
+         if pof~=pf then setfield(p, 'font', pf) end
+         if pcj~=pf then set_attr(p, attr_curjfnt, pf) end
         setfield(p, 'subtype', floor(getsubtype(p)*0.5)*2)
          set_attr(p, attr_orig_char, pc)
       end
-      return p
    end
-   suppress_hyphenate_ja_aux[id_math] = function(p)
-      return node_end_of_math(node_next(p)) end
-   suppress_hyphenate_ja_aux[50] = function(p) return p end
-   suppress_hyphenate_ja_aux[id_whatsit] = function(p)
+   local suppress_hyphenate_ja_aux_whatsit = function(p)
       if getsubtype(p)==sid_user then 
          local uid = getfield(p, 'user_id')
          if uid==STCK then
-            wt[#wt+1] = p; head = node_remove(head, p)
+            wt[#wt+1] = p
          elseif uid==DIR then
            if has_attr(p, attr_icflag)<PROCESSED_BEGIN_FLAG  then
               ltjs.list_dir = has_attr(p, attr_dir)
            end
-           wtd[#wtd+1] = p; head = node_remove(head, p)
+            wtd[#wtd+1] = p
          end
       end
-      return p
    end
 
    local function suppress_hyphenate_ja (h)
       start_time_measure('ltj_hyphenate')
-      local p = to_direct(h)
-      wt, wtd, head = {}, {}, p
+      head = to_direct(h)
+      for i=1,#wt do wt[i]=nil end; for i=1,#wtd do wtd[i]=nil end
       ltjs.list_dir=ltjd.get_dir_count()
-      while p do
-        local pfunc = suppress_hyphenate_ja_aux[getid(p)]
-        if pfunc then p = pfunc(p) end
-        p = node_next(p)
+      for p in node_traverse_id(id_glyph, head) do --while p do
+        suppress_hyphenate_ja_aux_glyph(p)
+      end
+      for p in node_traverse_id(id_whatsit, head) do --while p do
+        suppress_hyphenate_ja_aux_whatsit(p)
+      end
+      for i=1,#wt  do head = node_remove(head, wt[i]) end
+      for i=1,#wtd do 
+         local q = wtd[i]; head = node_remove(head, q); node_free(q)
       end
       head = to_node(head)
       stop_time_measure('ltj_hyphenate'); start_time_measure('tex_hyphenate')
@@ -117,16 +119,14 @@ end
 -- mode: true iff this function is called from hpack_filter
 local function set_box_stack_level(head, mode)
    local box_set, cl = 0, tex.currentgrouplevel + 1
-   for _,p  in pairs(wt) do
+   for i=1,#wt do
+      local p = wt[i]
       if mode and getfield(p, 'value')==cl then box_set = 1 end; node_free(p)
    end
-   for _,p  in pairs(wtd) do
-      node_free(p)
-   end
    ltjs.report_stack_level(tex_getcount('ltj@@stack') + box_set)
    is_dir_tate = ltjs.list_dir == dir_tate
    if is_dir_tate then
-      for p in Dnode.traverse_id(id_glyph,to_direct(head)) do
+      for p in node_traverse_id(id_glyph,to_direct(head)) do
          if (has_attr(p, attr_icflag) or 0)<=0 and has_attr(p, attr_curjfnt)==getfont(p) then
             local pfn = has_attr(p, attr_curtfnt) or getfont(p)
             local pc = getchar(p)
index 78ccde5..fe0c140 100644 (file)
 \protected\def\ltj@@vadjust@check@dir{%
   \directlua{luatexja.direction.check_adjust_direction()}%
 }
+
+%%%% setbox
+\let\ltj@@orig@setbox=\setbox
+%\protected\def\setbox{%
+%  \afterassignment\ltj@@setbox@A\ltj@tempcnta
+%}
+\protected\def\ltj@@setbox@A{%
+  \afterassignment\ltj@@setbox@B
+  \ltj@@orig@setbox\ltj@tempcnta
+}
+\protected\def\ltj@@setbox@B{%
+  \directlua{luatexja.direction.hook_empty_box()}%
+}
 %%%% unhbox and unvbox
 \let\ltj@@orig@unhbox=\unhbox
 \let\ltj@@orig@unvbox=\unvbox
index 4faac91..a93eee3 100644 (file)
Binary files a/test/test12-ltjtarticle.pdf and b/test/test12-ltjtarticle.pdf differ
index bb7739a..110e3e5 100644 (file)
@@ -1,6 +1,6 @@
 %#!lualatex
 \documentclass{ltjtarticle}
-\usepackage[margin=20mm]{geometry}
+\usepackage[b5j,margin=40mm]{geometry}
 
 \makeatletter
 \newif\ifnot@advanceline
 
 古来から人類は発酵という形で酵素を利用してきた。今日では、酵素の利用は食品製造だけにとどまらず、化学工業製品の製造や日用品の機能向上など、広い分野に応用されている。医療においても、酵素量を検査して診断したり、酵素作用を調節する治療薬を用いるなど、酵素が深く関っている。
 
+\leavevmode\hfill  (Wikipedia日本語版の「酵素」より)
+
+\def\R{01234567890123456789}
+\def\S{\R\R\R\R\R\R\R\R\R\R\R\R\R\R\R\R\R\R\R\R\par}
+
+\S\S
 
 \end{document}
\ No newline at end of file
index 46dcbaa..2d452b0 100644 (file)
Binary files a/test/test51-vtest.pdf and b/test/test51-vtest.pdf differ
index 62e026c..63d22d7 100644 (file)
Binary files a/test/test52-vtest-ins.pdf and b/test/test52-vtest-ins.pdf differ