X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-jfmglue.lua;h=8942064256516cf0336e4e18bf9823106774d55b;hb=80bbcf52bf096105cf1797a4422a38d400b3fa05;hp=321df94846c36144a6b8badaa4b7c3ffa75c6c53;hpb=f085560bb8c26829d23b3c20a3b628e8b0690c4b;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-jfmglue.lua b/src/ltj-jfmglue.lua index 321df94..8942064 100644 --- a/src/ltj-jfmglue.lua +++ b/src/ltj-jfmglue.lua @@ -19,7 +19,6 @@ local set_attr = node.set_attribute local insert_before = node.insert_before local node_next = node.next local round = tex.round -local uniq_id = 0 -- unique id local ltjs_fast_get_penalty_table = ltjs.fast_get_penalty_table local ltjf_font_metric_table = ltjf.font_metric_table local ltjf_find_char_class = ltjf.find_char_class @@ -65,6 +64,7 @@ local XKANJI_SKIP = 7 local PROCESSED = 8 local IC_PROCESSED = 9 local BOXBDD = 15 +local PROCESSED_BEGIN_FLAG = 16 local kanji_skip local xkanji_skip @@ -74,9 +74,12 @@ local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] local attr_icflag = luatexbase.attributes['ltj@icflag'] local attr_autospc = luatexbase.attributes['ltj@autospc'] local attr_autoxspc = luatexbase.attributes['ltj@autoxspc'] -local attr_uniqid = luatexbase.attributes['ltj@uniqid'] local max_dimen = 1073741823 +local function get_attr_icflag(p) + return (has_attr(p, attr_icflag) or 0)%PROCESSED_BEGIN_FLAG +end + -------------------- Helper functions local function copy_attr(new, old) @@ -188,10 +191,10 @@ local function check_box(box_ptr, box_end) until p.id~=id_glyph pid = p.id -- p must be non-nil end - if pid==id_kern and has_attr(p, attr_icflag)==IC_PROCESSED then + if pid==id_kern and get_attr_icflag(p)==IC_PROCESSED then p = node_next(p); elseif pid==id_hlist then - if PACKED == has_attr(p, attr_icflag) then + if PACKED == get_attr_icflag(p) then if find_first_char then first_char = p.head; find_first_char = false end @@ -225,7 +228,7 @@ function check_box_high(Nx, box_ptr, box_end) first_char = nil; last_char = nil; find_first_char = true if check_box(box_ptr, box_end) then if first_char then - if first_char.font == has_attr(first_char, attr_curjfnt) then + if first_char.font == (has_attr(first_char, attr_curjfnt) or -1) then set_np_xspc_jachar(Nx, first_char) else set_np_xspc_alchar(Nx, first_char.char,first_char, ligature_head) @@ -251,16 +254,14 @@ luatexbase.create_callback("luatexja.jfmglue.whatsit_after", "data", do local function set_attr_icflag_processed(p) - if (has_attr(p, attr_icflag) or 0)<= ITALIC then - set_attr(p, attr_uniqid, uniq_id) + if get_attr_icflag(p)<= ITALIC then set_attr(p, attr_icflag, PROCESSED) end end local function check_next_ickern(lp) - if lp.id == id_kern and ITALIC == has_attr(lp, attr_icflag) then - set_attr(lp, attr_icflag, IC_PROCESSED) - set_attr(lp, attr_uniqid, uniq_id) + if lp.id == id_kern and ITALIC == get_attr_icflag(lp) then + set_attr(lp, attr_icflag, IC_PROCESSED) Np.last = lp; return node_next(lp) else Np.last = Np.nuc; return lp @@ -268,13 +269,13 @@ local function check_next_ickern(lp) end local function calc_np_pbox(lp, last) - local uid = has_attr(lp, attr_uniqid) Np.first = Np.first or lp; Np.id = id_pbox local lpa = KINSOKU -- dummy= - while lp~=last and lpa>=PACKED and lpa~=BOXBDD - and uid == has_attr(lp, attr_uniqid) do - Np.nuc = lp; set_attr(lp, attr_uniqid, uniq_id) + set_attr(lp, attr_icflag, get_attr_icflag(lp)); + while lp~=last and lpa>=PACKED and lpa=PACKED then if lpa == BOXBDD then local lq = node_next(lp) @@ -407,16 +414,15 @@ do local attr_jchar_class = luatexbase.attributes['ltj@charclass'] function set_np_xspc_jachar(Nx, x) local m = ltjf_font_metric_table[x.font] - local c = has_attr(x, attr_orig_char) + local c = has_attr(x, attr_orig_char) or x.char local cls = ltjf_find_char_class(x.char, m) if c ~= x.char and cls==0 then cls = ltjf_find_char_class(-c, m) end Nx.class = cls; set_attr(x, attr_jchar_class, cls) Nx.lend = m.size_cache.char_type[cls].kern[fast_find_char_class('lineend', m)] or 0 Nx.met, Nx.var, Nx.char = m, m.var, c - Nx.pre = ltjs_fast_get_penalty_table('pre', c, 0) - Nx.post = ltjs_fast_get_penalty_table('post', c, 0) - local y = ltjs_fast_get_penalty_table('xsp', c, 3) - Nx.xspc_before, Nx.xspc_after = (y%2==1), (y>=2) + Nx.pre = ltjs_fast_get_penalty_table('pre', c) or 0 + Nx.post = ltjs_fast_get_penalty_table('post', c) or 0 + Nx.xspc = ltjs_fast_get_penalty_table('xsp', c) or 3 Nx.auto_kspc, Nx.auto_xspc = (has_attr(x, attr_autospc)==1), (has_attr(x, attr_autoxspc)==1) end local set_np_xspc_jachar = set_np_xspc_jachar @@ -434,15 +440,14 @@ do x = node.tail(x.components); c = x.char end end - Nx.pre = ltjs_fast_get_penalty_table('pre', c, 0) - Nx.post = ltjs_fast_get_penalty_table('post', c, 0) + Nx.pre = ltjs_fast_get_penalty_table('pre', c) or 0 + Nx.post = ltjs_fast_get_penalty_table('post', c) or 0 Nx.char = 'jcharbdd' else Nx.pre, Nx.post, Nx.char = 0, 0, -1 end Nx.met = nil - local y = ltjs_fast_get_penalty_table('xsp', c, 3) - Nx.xspc_before, Nx.xspc_after = (y%2==1), (y>=2) + Nx.xspc = ltjs_fast_get_penalty_table('xsp', c) or 3 Nx.auto_xspc = (has_attr(x, attr_autoxspc)==1) end local set_np_xspc_alchar = set_np_xspc_alchar @@ -464,7 +469,7 @@ do function after_hlist(Nx) local s = Nx.last_char if s then - if s.font == has_attr(s, attr_curjfnt) then + if s.font == (has_attr(s, attr_curjfnt) or -1) then set_np_xspc_jachar(Nx, s) else set_np_xspc_alchar(Nx, s.char, s, ligature_tail) @@ -492,7 +497,6 @@ local function lineend_fix(g) g = node_new(id_kern); --copy_attr(g, Nq.nuc); g.subtype = 1; g.kern = -Nq.lend; set_attr(g, attr_icflag, LINEEND) - set_attr(g, attr_uniqid, uniq_id) else g.spec.width = g.spec.width - Nq.lend end @@ -511,9 +515,7 @@ local function handle_penalty_normal(post, pre, g) head = insert_before(head, Np.first, p) Bp[1]=p; set_attr(p, attr_icflag, KINSOKU) - set_attr(p, attr_uniqid, uniq_id) end - --else for _, v in pairs(Bp) do v.penalty = v.penalty + a end else for _, v in pairs(Bp) do add_penalty(v,a) end end end @@ -527,8 +529,7 @@ local function handle_penalty_always(post, pre, g) p.penalty = a head = insert_before(head, Np.first, p) Bp[1]=p - set_attr(p, attr_icflag, KINSOKU) - set_attr(p, attr_uniqid, uniq_id) + set_attr(p, attr_icflag, KINSOKU) end else for _, v in pairs(Bp) do add_penalty(v,a) end end @@ -541,8 +542,7 @@ local function handle_penalty_suppress(post, pre, g) local p = node_new(id_penalty); --copy_attr(p, Nq.nuc) p.penalty = 10000; head = insert_before(head, Np.first, p) Bp[1]=p - set_attr(p, attr_icflag, KINSOKU) - set_attr(p, attr_uniqid, uniq_id) + set_attr(p, attr_icflag, KINSOKU) end else for _, v in pairs(Bp) do add_penalty(v,a) end end @@ -555,11 +555,10 @@ local function new_jfm_glue(Nn, bc, ac) local g = z.glue[ac] if g then g = node_copy(g); g.spec = node.copy(g.spec); - set_attr(g, attr_uniqid, uniq_id) elseif z.kern[ac] then g = node_new(id_kern); --copy_attr(g, Nn.nuc) g.subtype = 1; g.kern = z.kern[ac] - set_attr(g, attr_icflag, FROM_JFM); set_attr(g, attr_uniqid, uniq_id) + set_attr(g, attr_icflag, FROM_JFM); end return g end @@ -569,7 +568,6 @@ local function real_insert(w, g) if w~=0 then local h = node_new(id_kern); --copy_attr(h, Nq.nuc) set_attr(h, attr_icflag, LINE_END) - set_attr(h, attr_uniqid, uniq_id) h.kern = w; h.subtype = 1 head = node.insert_after(head, Nq.last, h) end @@ -589,7 +587,6 @@ local function get_kanjiskip_normal() local g = node_new(id_glue); --copy_attr(g, Nq.nuc) g.spec = (Np.auto_kspc or Nq.auto_kspc) and node_copy(kanji_skip) or get_zero_spec() set_attr(g, attr_icflag, KANJI_SKIP) - set_attr(g, attr_uniqid, uniq_id) return g end local function get_kanjiskip_jfm() @@ -622,7 +619,6 @@ local function get_kanjiskip_jfm() g.spec = get_zero_spec() end set_attr(g, attr_icflag, KANJI_SKIP) - set_attr(g, attr_uniqid, uniq_id) return g end @@ -679,18 +675,17 @@ local get_xkanjiskip local function get_xkanjiskip_normal(Nn) local g = node_new(id_glue); --copy_attr(g, Nn.nuc) local gx = node_new(id_glue_spec); g.spec = gx - if Nq.xspc_after and Np.xspc_before and (Nq.auto_xspc or Np.auto_xspc) then + if (Nq.xspc>=2) and (Np.xspc%2==1) and (Nq.auto_xspc or Np.auto_xspc) then g.spec = node_copy(xkanji_skip) else g.spec = get_zero_spec() end set_attr(g, attr_icflag, XKANJI_SKIP) - set_attr(g, attr_uniqid, uniq_id) return g end local function get_xkanjiskip_jfm(Nn) local g = node_new(id_glue); --copy_attr(g, Nn.nuc) - if Nq.xspc_after and Np.xspc_before and (Nq.auto_xspc or Np.auto_xspc) then + if (Nq.xspc>=2) and (Np.xspc%2==1) and (Nq.auto_xspc or Np.auto_xspc) then local gx = node_new(id_glue_spec); gx.stretch_order, gx.shrink_order = 0, 0 local bk = Nn.met.size_cache.xkanjiskip @@ -704,7 +699,6 @@ local function get_xkanjiskip_jfm(Nn) g.spec = get_zero_spec() end set_attr(g, attr_icflag, XKANJI_SKIP) - set_attr(g, attr_uniqid, uniq_id) return g end @@ -747,7 +741,7 @@ local function handle_np_jachar(mode) end real_insert(0, g) end - if mode and ltjs_fast_get_penalty_table('kcat', Np.char, 0)%2~=1 then + if mode and (ltjs_fast_get_penalty_table('kcat', Np.char) or 0)%2~=1 then widow_Np.first, widow_Bp, Bp = Np.first, Bp, widow_Bp end end @@ -820,7 +814,7 @@ local function handle_list_tail(mode) Bp = widow_Bp; Np = widow_Np; Nq.lend = 0 if Np.first then handle_penalty_normal(0, - ltjs_fast_get_penalty_table('jwp', 0, 0)) + ltjs_fast_get_penalty_table('jwp', 0) or 0) end else -- the current list is the contents of a hbox @@ -854,8 +848,6 @@ end -- initialize -- return value: (the initial cursor lp), (last node) local function init_var(mode) - uniq_id = uniq_id +1 - if uniq_id == 0x7FFFFFF then uniq_id = 0 end Bp, widow_Bp, widow_Np = {}, {}, {first = nil} kanji_skip=skip_table_to_spec('kanjiskip') get_kanjiskip = (kanji_skip.width == max_dimen) @@ -866,12 +858,12 @@ local function init_var(mode) Np = { auto_kspc=nil, auto_xspc=nil, char=nil, class=nil, first=nil, id=nil, last=nil, lend=0, met=nil, nuc=nil, - post=nil, pre=nil, xspc_after=nil, xspc_before=nil, + post=nil, pre=nil, xspc=nil, } Nq = { auto_kspc=nil, auto_xspc=nil, char=nil, class=nil, first=nil, id=nil, last=nil, lend=0, met=nil, nuc=nil, - post=nil, pre=nil, xspc_after=nil, xspc_before=nil, + post=nil, pre=nil, xspc=nil, } if mode then -- the current list is to be line-breaked: @@ -906,6 +898,8 @@ local function cleanup(mode, last) return head else head = node.remove(head, last); node.free(last);-- remove the sentinel + set_attr(head, attr_icflag, + get_attr_icflag(head) + PROCESSED_BEGIN_FLAG); return head end end @@ -966,8 +960,7 @@ local function whatsit_callback(Np, lp, Nq) Np.char = 'parbdd' Np.met = nil Np.pre = 0; Np.post = 0 - Np.xspc_before = false - Np.xspc_after = false + Np.xspc = 0 Np.auto_xspc = false return Np end