OSDN Git Service

Cherry-picked several commits from kitagawa_tfont branch
[luatex-ja/luatexja.git] / src / ltj-adjust.lua
index 09125a1..729f186 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.adjust',
-  date = '2014/02/01',
+  date = '2014/02/02',
   description = 'Advanced line adjustment for LuaTeX-ja',
 })
 module('luatexja.adjust', package.seeall)
@@ -29,9 +29,9 @@ local node_traverse_id = Dnode.traverse_id
 local node_new = Dnode.new
 local node_copy = Dnode.copy
 local node_hpack = Dnode.hpack
-local node_next = Dnode.getnext
+local node_next = (Dnode ~= node) and Dnode.getnext or node.next
 local node_free = Dnode.free
-local node_prev = Dnode.getprev
+local node_prev = (Dnode ~= node) and Dnode.getprev or node.prev
 local node_tail = Dnode.tail
 local has_attr = Dnode.has_attribute
 local set_attr = Dnode.set_attribute
@@ -82,12 +82,14 @@ local function get_stretched(q, go, gs)
    local qs = getfield(q, 'spec')
    if not getfield(qs, 'writable') then return 0 end
    if gs == 1 then -- stretching
-      if getfield(qs, 'stretch_order') == go then 
-        return getfield(qs, 'stretch') 
+      if getfield(qs, 'stretch_order') == go then
+        return getfield(qs, 'stretch')
+      else return 0
       end
    else -- shrinking
       if getfield(qs, 'shrink_order') == go then 
         return getfield(qs, 'shrink')
+      else return 0
       end
    end
 end
@@ -172,8 +174,8 @@ end
 local function aw_step1(p, res, total)
    local head = getlist(p)
    local x = node_tail(head); if not x then return false end
+   -- x: \rightskip
    x = node_prev(x); if not x then return false end
-   -- 本当の行末の node を格納
    if getid(x) == id_glue and getsubtype(x) == 15 then 
       -- 段落最終行のときは,\penalty10000 \parfillskip が入るので,
       -- その前の node が本来の末尾文字となる
@@ -196,8 +198,8 @@ local function aw_step1(p, res, total)
      return false-- それ以外は対象外.
    end
    local xk = ltjf_font_metric_table[getfont(xc)]
-     xk = xk.char_type[has_attr(xc, attr_jchar_class) or 0]
-     xk = xk['end_' .. res.name] or 0
+   xk = xk.char_type[has_attr(xc, attr_jchar_class) or 0]
+   xk = xk['end_' .. res.name] or 0
 
    if xk>0 and total>=xk then
       total = total - xk