OSDN Git Service

luatexja-preset.sty: divided 'yu' option into 'yu-win' and 'yu-osx'
[luatex-ja/luatexja.git] / src / ltj-jfmglue.lua
index 8d8a7b7..7018c7a 100644 (file)
@@ -1,10 +1,9 @@
 --
--- luatexja/jfmglue.lua
+-- luatexja/ltj-jfmglue.lua
 --
 luatexbase.provides_module({
   name = 'luatexja.jfmglue',
-  date = '2012/07/19',
-  version = '0.5',
+  date = '2013/04/27',
   description = 'Insertion process of JFM glues and kanjiskip',
 })
 module('luatexja.jfmglue', package.seeall)
@@ -89,7 +88,7 @@ end
 local function slow_find_char_class(c, m, oc)
    local xc = c or oc
    local cls = ltjf_find_char_class(oc, m)
-   if xc ~= oc and  cls==0 then cls, xc = ltjf_find_char_class(-xc, m) end
+   if xc ~= oc and  cls==0 then cls = ltjf_find_char_class(-xc, m) end
    return cls, xc
 end
 
@@ -147,7 +146,7 @@ local first_char, last_char, find_first_char
 local function check_box(box_ptr, box_end)
    local p = box_ptr; local found_visible_node = false
    if not p then 
-      find_first_char = false; first_char = nil; last_char = nil
+      find_first_char = false; last_char = nil
       return true
    end
    while p and p~=box_end do
@@ -306,7 +305,7 @@ local calc_np_auxtable = {
          end,
    [id_whatsit] = function(lp) 
                  if lp.subtype==sid_user then
-                    if lp.user_id==30111 then
+                    if lp.user_id==luatexja.userid_table.IHB then
                        local lq = node_next(lp); 
                        head = node.remove(head, lp); node.free(lp); ihb_flag = true
                        return false, lq;
@@ -396,7 +395,7 @@ function calc_np(lp, last)
       local lpa = has_attr(lp, attr_icflag) or 0
        -- unbox 由来ノードの検出
       if lpa>=PACKED then
-         if lpa == BOXBDD then
+         if lpa%PROCESSED_BEGIN_FLAG == BOXBDD then
            local lq = node_next(lp) 
             head = node.remove(head, lp); node.free(lp); lp = lq
          else return calc_np_pbox(lp, last)
@@ -734,7 +733,7 @@ local function get_OA_skip()
    if not ihb_flag then
       local pm = Np.met
       return new_jfm_glue(pm, 
-        fast_find_char_class(((Nq.id == id_math and -1) or 'jcharbdd'), pm), Np.class)
+        fast_find_char_class(((Nq.id == id_math and -1) or (type(Nq.char)=='string' and Nq.char or 'jcharbdd')), pm), Np.class)
    else return nil
    end
 end
@@ -757,7 +756,7 @@ local function handle_np_jachar(mode)
       local g = get_OA_skip() or get_kanjiskip() -- O_A->K
       handle_penalty_normal(0, Np.pre, g); real_insert(g)
    elseif Nq.pre then 
-      local g = get_OA_skip() or get_xkanjiskip(Np) -- O_A->X
+     local g = get_OA_skip() or get_xkanjiskip(Np) -- O_A->X
       handle_penalty_normal((qid==id_hlist and 0 or Nq.post), Np.pre, g); real_insert(g)
    else
       local g = get_OA_skip() -- O_A
@@ -981,50 +980,50 @@ function main(ahead, mode)
    return cleanup(mode, last)
 end
 
--- \inhibitglue
-
-function create_inhibitglue_node()
-   local tn = node_new(id_whatsit, sid_user)
-   tn.user_id=30111; tn.type=100; tn.value=1
-   node.write(tn)
-end
-
--- Node for indicating beginning of a paragraph
--- (for ltjsclasses)
-function create_beginpar_node()
-   local tn = node_new(id_whatsit, sid_user)
-   tn.user_id=30114; tn.type=100; tn.value=1
-   node.write(tn)
-end
-
 do
+   local IHB  = luatexja.userid_table.IHB
+   local BPAR = luatexja.userid_table.BPAR
+
+   -- \inhibitglue
+   function create_inhibitglue_node()
+      local tn = node_new(id_whatsit, sid_user)
+      tn.user_id=IHB; tn.type=100; tn.value=1
+      node.write(tn)
+   end
 
-local function whatsit_callback(Np, lp, Nq)
-   if Np and Np.nuc then return Np 
-   elseif Np and lp.user_id == 30114 then
-      Np.first = lp; Np.nuc = lp; Np.last = lp
-      Np.char = 'parbdd'
-      Np.met = nil
-      Np.pre = 0; Np.post = 0
-      Np.xspc = 0
-      Np.auto_xspc = false
-      return Np
+   -- Node for indicating beginning of a paragraph
+   -- (for ltjsclasses)
+   function create_beginpar_node()
+      local tn = node_new(id_whatsit, sid_user)
+      tn.user_id=BPAR; tn.type=100; tn.value=1
+      node.write(tn)
    end
-end
 
+   local function whatsit_callback(Np, lp, Nq)
+      if Np and Np.nuc then return Np 
+      elseif Np and lp.user_id == BPAR then
+         Np.first = lp; Np.nuc = lp; Np.last = lp
+         Np.char = 'parbdd'
+         Np.met = nil
+         Np.pre = 0; Np.post = 0
+         Np.xspc = 0
+         Np.auto_xspc = false
+         return Np
+      end
+   end
 
-local function whatsit_after_callback(s, Nq, Np)
-   if not s and Nq.nuc.user_id == 30114 then
-      local x, y = node.prev(Nq.nuc), Nq.nuc
-      Nq.first, Nq.nuc, Nq.last = x, x, x
-      head = node.remove(head, y)
+   local function whatsit_after_callback(s, Nq, Np)
+      if not s and Nq.nuc.user_id == BPAR then
+         local x, y = node.prev(Nq.nuc), Nq.nuc
+         Nq.first, Nq.nuc, Nq.last = x, x, x
+         head = node.remove(head, y)
+      end
+      return s
    end
-   return s
-end
 
-luatexbase.add_to_callback("luatexja.jfmglue.whatsit_getinfo", whatsit_callback,
-                           "luatexja.beginpar.np_info", 1)
-luatexbase.add_to_callback("luatexja.jfmglue.whatsit_after", whatsit_after_callback,
-                           "luatexja.beginpar.np_info_after", 1)
+   luatexbase.add_to_callback("luatexja.jfmglue.whatsit_getinfo", whatsit_callback,
+                              "luatexja.beginpar.np_info", 1)
+   luatexbase.add_to_callback("luatexja.jfmglue.whatsit_after", whatsit_after_callback,
+                              "luatexja.beginpar.np_info_after", 1)
 
 end