OSDN Git Service

check_box: ignore JFM glue between 'boxbdd'
[luatex-ja/luatexja.git] / src / ltj-jfmglue.lua
index 895cf9c..ed06e29 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfmglue',
-  date = '2018/02/18',
+  date = '2019/07/26',
   description = 'Insertion process of JFM glues, [x]kanjiskip and others',
 })
 luatexja.jfmglue = luatexja.jfmglue or {}
@@ -191,7 +191,8 @@ local function check_box(box_ptr, box_end)
       end
       if pid==id_kern then
         local pa = get_attr_icflag(p)
-        if pa==IC_PROCESSED then
+        if (pa==IC_PROCESSED)or(pa==BOXBDD) then
+        --if (pa==IC_PROCESSED)or(pa==BOXBDD)or(getsubtype(p)==0) then
            -- do nothing
         elseif getsubtype(p)==2 then
            p = node_next(node_next(p));
@@ -221,7 +222,8 @@ local function check_box(box_ptr, box_end)
            first_char = p; find_first_char = false
         end
         last_char = p; found_visible_node = true
-      elseif pid==id_rule and get_attr_icflag(p)==PACKED then
+      elseif (pid==id_rule and get_attr_icflag(p)==PACKED)
+         or (pid==id_glue and get_attr_icflag(p)==BOXBDD) then
         -- do nothing
       elseif not (pid==id_ins   or pid==id_mark
                  or pid==id_adjust or pid==id_whatsit
@@ -267,12 +269,13 @@ luatexbase.create_callback("luatexja.jfmglue.whatsit_after", "data",
 
 -- calc next Np
 local calc_np 
-do
+do -- 001 -----------------------------------------------
 
 local traverse = node.direct.traverse
 local function check_next_ickern(lp)
    local lx = Np.nuc
-   while lp and getid(lp) == id_kern and ( getsubtype(lp)==3 or ITALIC == get_attr_icflag(lp)) do
+   while lp and getid(lp) == id_kern and ( getsubtype(lp)==0 or 
+     getsubtype(lp)==3 or ITALIC == get_attr_icflag(lp)) do
      set_attr(lp, attr_icflag, IC_PROCESSED);
      lx, lp = lp, node_next(lp)
    end
@@ -280,17 +283,19 @@ local function check_next_ickern(lp)
 end
 
 local function calc_np_pbox(lp, last)
-   local first, lpa, nc = (not Np.first), KINSOKU, nil
+   local first, nc = (not Np.first), nil
+   --local lpa = get_attr_icflag(lp)==PACKED and PACKED or KINSOKU -- KINSOKU: dummy
+   local lpa = get_attr_icflag(lp)
    Np.first = Np.first or lp; Np.id = id_pbox
    set_attr(lp, attr_icflag, get_attr_icflag(lp));
    while lp ~=last and (lpa>=PACKED) and (lpa<BOXBDD) do
       local lpi = getid(lp)
-      if lpi==id_hlist or lpi==id_vlist then
+      if lpa==PACKED then
+         if lpi==id_rule then lp = node_next(lp) end
+        nc, lp = lp, node_next(lp)
+      elseif lpi==id_hlist or lpi==id_vlist then
         head, lp, nc = ltjd_make_dir_whatsit(head, lp, list_dir, 'jfm pbox')
         Np.first = first and nc or Np.first
-      elseif (lpi==id_rule) and (lpa==PACKED) then
-         lp = node_next(lp)
-        nc, lp = lp, node_next(lp)
       else
         nc, lp = lp, node_next(lp)
       end
@@ -303,21 +308,40 @@ local function calc_np_pbox(lp, last)
    return lp
 end
 
-local ltjw_apply_ashift_math = ltjw.apply_ashift_math
-local ltjw_apply_ashift_disc = ltjw.apply_ashift_disc
-local min, max = math.min, math.max
-local function calc_np_aux_glyph_common(lp, acc_flag)
-   Np.nuc = lp
-   Np.first= (Np.first or lp)
-   if if_lang_ja(lp) then
+local calc_np_aux_glyph_common
+do -- 002 ---------------------------------------
+   local min, max = math.min, math.max
+   local getwhd = node.direct.getwhd
+   local attr_jchar_class = luatexbase.attributes['ltj@charclass']
+   local attr_jchar_code = luatexbase.attributes['ltj@charcode']
+   local identifiers = fonts.hashes.identifiers
+   local function calc_np_notdef(lp)
+      local ident = identifiers[getfont(lp)]
+      if not ident.descriptions[getchar(lp)] then
+        local ln = node_next(lp)
+        if (ident.shared and ident.shared.features and ident.shared.features.notdef)
+           and ln and getid(ln)==id_glyph then 
+           set_attr(lp, attr_icflag, PROCESSED)
+           set_attr(ln, attr_jchar_code, has_attr(lp, attr_jchar_code) or getchar(lp))
+           set_attr(ln, attr_jchar_class, has_attr(lp, attr_jchar_class) or 0)
+           Np.nuc, lp = ln, ln
+        end
+      end
+      return lp
+   end 
+function calc_np_aux_glyph_common(lp, acc_flag)
+   Np.nuc, Np.first = lp, (Np.first or lp)
+   if if_lang_ja(lp) then -- JAchar
       Np.id = id_jglyph
       local m, mc, cls = set_np_xspc_jachar(Np, lp)
       local npi, npf
+      local w, h, d = getwhd(lp)
+      if w==0 and h==0 and d==0 then lp = calc_np_notdef(lp) end
       lp, head, npi, npf = capsule_glyph(lp, m, mc[cls], head, tex_dir)
       Np.first = (Np.first~=Np.nuc) and Np.first or npf or npi
       Np.nuc = npi
       return true, check_next_ickern(lp);
-   else
+   else --ALchar
       Np.id = id_glyph
       set_np_xspc_alchar(Np, getchar(lp), lp, 1)
       -- loop
@@ -400,8 +424,11 @@ local function calc_np_aux_glyph_common(lp, acc_flag)
       return true, lp
    end
 end
+end -- 002 ---------------------------------------
 local calc_np_auxtable
-do
+do  -- 002 ---------------------------------------
+local ltjw_apply_ashift_math = ltjw.apply_ashift_math
+local ltjw_apply_ashift_disc = ltjw.apply_ashift_disc
 local node_end_of_math = node.direct.end_of_math
 local dir_tate = luatexja.dir_table.dir_tate
 local sid_start_link = node.subtype('pdf_start_link')
@@ -510,7 +537,7 @@ calc_np_auxtable = {
       return false, node_next(lp)
    end,
 }
-end
+end -- 002 ---------------------------------------
 calc_np_auxtable[id_rule]   = calc_np_auxtable.box_like
 calc_np_auxtable[15]        = calc_np_auxtable.box_like
 
@@ -548,7 +575,7 @@ function calc_np(last, lp)
    end
    Np=nil
 end
-end
+end -- 001 -----------------------------------------------
 
 -- extract informations from Np
 -- We think that "Np is a Japanese character" if Np.met~=nil,
@@ -606,9 +633,11 @@ do
         local f = (lig ==1) and nullfunc or node_tail
          local xc, xs = getcomponents(x), getsubtype(x)
         while xc and xs and xs%4>=2 do
-           x = f(xc); xc, xs = getcomponents(x), getsubtype(x)
+           x = f(xc);
+           if getid(x)==id_disc then x, xc, xs = nil, getfield(x,'replace'), 2
+           else xc, xs = getcomponents(x), getsubtype(x) end
         end
-        c = getchar(x)
+        c = x and getchar(x) or c
         Nx.pre  = table_current_stack[PRE + c]  or 0
         Nx.post = table_current_stack[POST + c] or 0
       else
@@ -722,7 +751,7 @@ local function new_jfm_glue(mc, bc, ac)
           return node_copy(g[1]), g.ratio, false, false, false
        else
         local f = node_new(id_glue)
-        set_attr(f, attr_icflag, g.priority)
+         set_attr(f, attr_icflag, g.priority)
         setglue(f, g.width, g.stretch, g.shrink)
         return f, g.ratio, g.kanjiskip_natural, g.kanjiskip_stretch, g.kanjiskip_shrink
       end
@@ -1341,4 +1370,4 @@ do
 end
 
 luatexja.jfmglue.after_hlist = after_hlist
-luatexja.jfmglue.check_box_high = check_box_high
\ No newline at end of file
+luatexja.jfmglue.check_box_high = check_box_high