OSDN Git Service

sync with pLaTeX 2018-03-09
[luatex-ja/luatexja.git] / src / ltj-ruby.lua
index bf57c77..eb6a691 100644 (file)
@@ -3,13 +3,12 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.ruby',
-  date = '2015/09/18',
+  date = '2018/02/18',
   description = 'Ruby annotation',
 })
-module('luatexja.ruby', package.seeall)
-local err, warn, info, log = luatexbase.errwarinf(_NAME)
-
+luatexja.ruby = {}
 luatexja.load_module('stack');     local ltjs = luatexja.stack
+luatexja.load_module('base');      local ltjb = luatexja.base
 
 local to_node =  node.direct.tonode
 local to_direct =  node.direct.todirect
@@ -74,7 +73,7 @@ local RUBY_POST = luatexja.userid_table.RUBY_POST
 ----------------------------------------------------------------
 do
    local getbox = node.direct.getbox
-   function cpbox() return node_copy(getbox(0)) end
+   function luatexja.ruby.cpbox() return node_copy(getbox(0)) end
 end
 
 ----------------------------------------------------------------
@@ -119,9 +118,10 @@ end
 
 
 -- 実行回数 + ルビ中身 から uniq_id を作る関数
-old_break_info = {} -- public, 前 run 時の分割情報
+luatexja.ruby.old_break_info = {} -- public, 前 run 時の分割情報
+local old_break_info = old_break_info
 local cache_handle
-function read_old_break_info()
+function luatexja.ruby.read_old_break_info()
    if  tex.jobname then
       local fname = tex.jobname .. '.ltjruby'
       local real_file = kpse.find_file(fname)
@@ -205,7 +205,7 @@ do
          local hic = has_attr(hx, attr_icflag)
         if (hic == KANJI_SKIP) or (hic == KANJI_SKIP_JFM)
             or (hic == XKANJI_SKIP) or (hic == XKANJI_SKIP_JFM)
-            or ((hic<=FROM_JFM+2) and (hic>=FROM_JFM-2)) then
+            or ((hic<=FROM_JFM+63) and (hic>=FROM_JFM)) then
            -- この 5 種類の空白をのばす
               if getid(hx) == id_kern then
                  local k = node_new(id_glue)
@@ -215,7 +215,7 @@ do
                  h = insert_after(h, hx, k);
                  h = node_remove(h, hx); node_free(hx); hx = k
               else -- glue
-                 setglue(hx, getfield(hx, 'width'), round(middle*65536), 0,
+                  setglue(hx, getfield(hx, 'width'), round(middle*65536), 0,
                             2, 0)
               end
         end
@@ -269,11 +269,11 @@ local function texiface_low(rst, rtlr, rtlp)
 end
 
 -- rst: table
-function texiface(rst, rtlr, rtlp)
+function luatexja.ruby.texiface(rst, rtlr, rtlp)
    if #rtlr ~= #rtlp then
       for i=1, #rtlr do node_free(rtlr[i]) end
       for i=1, #rtlp do node_free(rtlp[i]) end
-      luatexja.base.package_error('luatexja-ruby',
+      ltjb.package_error('luatexja-ruby',
                                  'Group count mismatch between the ruby and\n' ..
                                     'the body (' .. #rtlr .. ' != ' .. #rtlp .. ').',
                                  '')
@@ -374,7 +374,7 @@ local function new_ruby_box(r, p, ppre, pmid, ppost,
         setfield(rt, 'head', nil); node_free(rt);
       end
    end
-   local a, k = node_new(id_rule), node_new(id_kern)
+   local a, k = node_new(id_rule), node_new(id_kern, 1)
    setfield(a, 'width', 0); setfield(a, 'height', 0)
    setfield(a, 'depth', 0); setfield(k, 'kern', rgap)
    insert_after(r, r, a); insert_after(r, a, k);
@@ -382,7 +382,7 @@ local function new_ruby_box(r, p, ppre, pmid, ppost,
    a = node.direct.vpack(r); setfield(a, 'shift', 0)
    set_attr(a, attr_ruby, post_intrusion)
    if rsmash or getfield(a, 'height')<getfield(p, 'height') then
-      local k = node_new(id_kern)
+      local k = node_new(id_kern, 1)
       setfield(k, 'kern', -getfield(a, 'height')+getfield(p, 'height'))
       setfield(a, 'head', k); insert_before(r, r, k)
       setfield(a, 'height', getfield(p, 'height'))
@@ -673,9 +673,9 @@ luatexbase.add_to_callback('hpack_filter', post_high_hbox, 'ltj.ruby.post_hbox',
 ----------------------------------------------------------------
 do
    local RIPRE  = luatexja.stack_table_index.RIPRE
-   local function whatsit_callback(Np, lp, Nq, bsl)
+   local function whatsit_callback(Np, lp, Nq)
       if Np.nuc then return Np
-      elseif getfield(lp, 'user_id') == RUBY_PRE then
+      elseif  getfield(lp, 'user_id') == RUBY_PRE then
          Np.first, Np.nuc, Np.last = lp, lp, lp
          local lpv = getfield(lp, 'value')
          local x = node_next(node_next(lpv))
@@ -711,6 +711,8 @@ do
             set_attr(lpv, attr_ruby_maxprep, 0)
          end
          return Np
+      else
+        return Np
       end
    end
    luatexbase.add_to_callback("luatexja.jfmglue.whatsit_getinfo", whatsit_callback,