OSDN Git Service

luatexja-preset: use CJKShape=NLC/JIS1990.
[luatex-ja/luatexja.git] / src / ltj-jfmglue.lua
index 7f4b95c..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
@@ -161,7 +160,9 @@ local function check_box(box_ptr, box_end)
               first_char = p; find_first_char = false
            end
            last_char = p; found_visible_node = true; p=node_next(p)
-           if (not p) or p==box_end then return found_visible_node end
+           if (not p) or p==box_end then 
+               return found_visible_node 
+            end
         until p.id~=id_glyph
         pid = p.id -- p must be non-nil
       end
@@ -220,7 +221,7 @@ function check_box_high(Nx, box_ptr, box_end)
    if check_box(box_ptr, box_end) then
       local first_char = first_char
       if first_char then
-         if first_char.id==glyph_node then
+         if first_char.id==id_glyph then
            if first_char.font == (has_attr(first_char, attr_curjfnt) or -1) then 
               set_np_xspc_jachar(Nx, first_char)
            else
@@ -278,7 +279,7 @@ end
 
 
 local calc_np_auxtable = {
-   [id_glyph] = function (lp) 
+   [id_glyph] = function (lp)
                   Np.first, Np.nuc = (Np.first or lp), lp;
                   Np.id = (lp.font == (has_attr(lp, attr_curjfnt) or -1)) and id_jglyph or id_glyph
                   --set_attr_icflag_processed(lp) treated in ltj-setwidth.lua
@@ -304,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;
@@ -354,7 +355,7 @@ local calc_np_auxtable = {
                  if lp.subtype==2 then
                     set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
                     set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
-                    set_attr(lp, attr_icflag, PROCESSED); Np = node_next(lp)
+                    set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
                     set_attr(lp, attr_icflag, PROCESSED); Np.nuc = lp
                     Np.id = (lp.font == (has_attr(lp, attr_curjfnt) or -1)) and id_jglyph or id_glyph
                     return true, check_next_ickern(node_next(lp)); 
@@ -392,9 +393,9 @@ function calc_np(lp, last)
    for k = 1,#Bp do Bp[k] = nil end
    while lp ~= last do
       local lpa = has_attr(lp, attr_icflag) or 0
-      -- unbox 由来ノードの検出
+       -- 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)
@@ -443,7 +444,7 @@ do
    function set_np_xspc_alchar(Nx, c,x, lig)
       if c~=-1 then
          local xc, xs = x.components, x.subtype
-        if lig == ligature_head then
+        if lig == 1 then
            while xc and xs and xs%4>=2 do
               x = xc; xc, xs = x.components, x.subtype
            end
@@ -484,7 +485,7 @@ do
    function after_hlist(Nx)
       local s = Nx.last_char
       if s then
-        if s.id==glyph_node then
+        if s.id==id_glyph then
            if s.font == (has_attr(s, attr_curjfnt) or -1) then 
               set_np_xspc_jachar(Nx, s)
            else
@@ -732,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
@@ -755,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
@@ -960,7 +961,8 @@ function main(ahead, mode)
    end
    lp = calc_np(lp, last)
    while Np do
-      extract_np(); adjust_nq()
+      extract_np();
+      adjust_nq(); 
       local pid, pm = Np.id, Np.met
       -- 挿入部
       if pid == id_jglyph then 
@@ -978,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
\ No newline at end of file
+end