X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-jfmglue.lua;h=7f787417d4b36118472cfdf8d9100312dedd844e;hb=5cacff7566d354102546a09869ed303c5a6130d9;hp=b5816d1ae4b99c91cd0abb4cd71930e43df63a5d;hpb=c9d30939ae3f14256da39471808dcde3d3c32d7b;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-jfmglue.lua b/src/ltj-jfmglue.lua index b5816d1..7f78741 100644 --- a/src/ltj-jfmglue.lua +++ b/src/ltj-jfmglue.lua @@ -54,20 +54,16 @@ local sid_start_thread = node.subtype('pdf_start_thread') local sid_end_link = node.subtype('pdf_end_link') local sid_end_thread = node.subtype('pdf_end_thread') -local ITALIC = 1 -local PACKED = 2 --- 実装予定: non-packed jchar 3 -local KINSOKU = 3 -local FROM_JFM = 6 --- FROM_JFM: 4, 5, 6, 7, 8 →優先度高 --- 6 が標準 -local KANJI_SKIP = 9 -local XKANJI_SKIP = 10 -local PROCESSED = 11 -local IC_PROCESSED = 12 -local BOXBDD = 15 -local PROCESSED_BEGIN_FLAG = 32 - +local ITALIC = luatexja.icflag_table.ITALIC +local PACKED = luatexja.icflag_table.PACKED +local KINSOKU = luatexja.icflag_table.KINSOKU +local FROM_JFM = luatexja.icflag_table.FROM_JFM +local KANJI_SKIP = luatexja.icflag_table.KANJI_SKIP +local XKANJI_SKIP = luatexja.icflag_table.XKANJI_SKIP +local PROCESSED = luatexja.icflag_table.PROCESSED +local IC_PROCESSED = luatexja.icflag_table.IC_PROCESSED +local BOXBDD = luatexja.icflag_table.BOXBDD +local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG local kanji_skip local xkanji_skip @@ -98,9 +94,12 @@ local function slow_find_char_class(c, m, oc) return cls, xc end -local spec_zero_glue = node_new(id_glue_spec) +local zero_glue = node_new(id_glue) +spec_zero_glue = node_new(id_glue_spec) -- must be public, since mentioned from other sources +local spec_zero_glue = spec_zero_glue spec_zero_glue.width = 0; spec_zero_glue.stretch_order = 0; spec_zero_glue.stretch = 0 spec_zero_glue.shrink_order = 0; spec_zero_glue.shrink = 0 + zero_glue.spec = spec_zero_glue local function skip_table_to_spec(n) local g, st = node_new(id_glue_spec), ltjs.fast_get_skip_table(n) @@ -185,6 +184,11 @@ local function check_box(box_ptr, box_end) end end end + elseif pid==id_math then + if find_first_char then + first_char = p; find_first_char = false + end + last_char = p; found_visible_node = true elseif not (pid==id_ins or pid==id_mark or pid==id_adjust or pid==id_whatsit or pid==id_penalty) then @@ -203,11 +207,16 @@ end 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 + local first_char = first_char if first_char 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) + if first_char.id==glyph_node 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) + end + else -- math_node + set_np_xspc_alchar(Nx, -1,first_char) end end end @@ -396,9 +405,11 @@ do local cls, c = slow_find_char_class(has_attr(x, attr_orig_char), m, x.char) Nx.class = cls; set_attr(x, attr_jchar_class, cls) Nx.met, Nx.char = m, c - 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 + local t = ltjs.fast_get_penalty_table_parent(c) + Nx.pre = t.pre or 0 + Nx.post = t.post or 0 + Nx.xspc = t.xsp or 3 + Nx.kcat = t.kcat or 0 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 @@ -407,24 +418,28 @@ do local floor = math.floor function set_np_xspc_alchar(Nx, c,x, lig) if c~=-1 then - local xc, xs = x.components and x.subtype + local xc, xs = x.components, x.subtype if lig == ligature_head then - while xc and xs and x%4>=2 do - x = xc; c = x.char + while xc and xs and xs%4>=2 do + x = xc; xc, xs = x.components, x.subtype end + c = x.char else while xc and xs and xs%4>=2 do - x = node.tail(xc); c = x.char + x = node.tail(xc); xc, xs = x.components, x.subtype end + c = x.char end - Nx.pre = ltjs_fast_get_penalty_table('pre', c) or 0 - Nx.post = ltjs_fast_get_penalty_table('post', c) or 0 + local t = ltjs.fast_get_penalty_table_parent(c) + Nx.pre = t.pre or 0 + Nx.post = t.post or 0 + Nx.xspc = t.xsp or 3 Nx.char = 'jcharbdd' else Nx.pre, Nx.post, Nx.char = 0, 0, -1 + Nx.xspc = ltjs_fast_get_penalty_table('xsp', -1) or 3 end Nx.met = nil - 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 @@ -446,10 +461,14 @@ do function after_hlist(Nx) local s = Nx.last_char if s then - if s.font == (has_attr(s, attr_curjfnt) or -1) then - set_np_xspc_jachar(Nx, s) + if s.id==glyph_node 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) + end else - set_np_xspc_alchar(Nx, s.char, s, ligature_tail) + set_np_xspc_alchar(Nx, -1, s) end else Nx.pre, Nx.met = nil, nil @@ -511,13 +530,13 @@ local function handle_penalty_suppress(post, pre, g) end -- 和文文字間の JFM glue を node 化 -local function new_jfm_glue(Nn, bc, ac) +local function new_jfm_glue(m, bc, ac) -- bc, ac: char classes - local z = Nn.met.size_cache.char_type[bc] + local z = m.size_cache.char_type[bc] local g, d = z.glue[ac], 0 if g then g,d = node_copy(g[1]), g[2]; - g.spec = node.copy(g.spec); -- node_copy は spec を copy しない(参照を増やすのみ) + g.spec = node_copy(g.spec); -- node_copy は spec をコピーする else local k = z.kern[ac] if k then @@ -547,30 +566,30 @@ local function get_kanjiskip_normal() if Np.auto_kspc or Nq.auto_kspc then return node_copy(kanji_skip) else - local g = node_new(id_glue); --copy_attr(g, Nq.nuc) - g.spec = node_copy(spec_zero_glue) + local g = node_copy(zero_glue) set_attr(g, attr_icflag, KANJI_SKIP) return g end end local function get_kanjiskip_jfm() - local g = node_new(id_glue); --copy_attr(g, Nq.nuc) + local g if Np.auto_kspc or Nq.auto_kspc then - local gx = node_new(id_glue_spec); - gx.stretch_order, gx.shrink_order = 0, 0 - local pm, qm = Np.met, Nq.met - local bk = qm.size_cache.kanjiskip or {0, 0, 0} - if (pm.size_cache==qm.size_cache) and (qm.var==pm.var) then - gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3] - else - local ak = pm.size_cache.kanjiskip or {0, 0, 0} - gx.width = round(diffmet_rule(bk[1], ak[1])) - gx.stretch = round(diffmet_rule(bk[2], ak[2])) - gx.shrink = -round(diffmet_rule(-bk[3], -ak[3])) - end - g.spec = gx + g = node_new(id_glue); --copy_attr(g, Nq.nuc) + local gx = node_new(id_glue_spec); + gx.stretch_order, gx.shrink_order = 0, 0 + local pm, qm = Np.met, Nq.met + local bk = qm.size_cache.kanjiskip or {0, 0, 0} + if (pm.size_cache==qm.size_cache) and (qm.var==pm.var) then + gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3] + else + local ak = pm.size_cache.kanjiskip or {0, 0, 0} + gx.width = round(diffmet_rule(bk[1], ak[1])) + gx.stretch = round(diffmet_rule(bk[2], ak[2])) + gx.shrink = -round(diffmet_rule(-bk[3], -ak[3])) + end + g.spec = gx else - g.spec = node_copy(spec_zero_glue) + g = node_copy(zero_glue) end set_attr(g, attr_icflag, KANJI_SKIP) return g @@ -640,10 +659,14 @@ local function calc_ja_ja_glue() else local qm, pm = Nq.met, Np.met if (qm.size_cache==pm.size_cache) and (qm.var==pm.var) then - return new_jfm_glue(Nq, Nq.class, Np.class) + return new_jfm_glue(qm, Nq.class, Np.class) else - local gb, db = new_jfm_glue(Nq, Nq.class, ltjf_find_char_class(Np.char, qm)) - local ga, da = new_jfm_glue(Np, ltjf_find_char_class(Nq.char, pm), Np.class) + local npn, nqn = Np.nuc, Nq.nuc + local gb, db = new_jfm_glue(qm, Nq.class, + slow_find_char_class(has_attr(npn, attr_orig_char), qm, npn.char)) + local ga, da = new_jfm_glue(pm, + slow_find_char_class(has_attr(nqn, attr_orig_char), pm, nqn.char), + Np.class) return calc_ja_ja_aux(gb, ga, db, da); end end @@ -657,22 +680,22 @@ local function get_xkanjiskip_normal(Nn) if (Nq.xspc>=2) and (Np.xspc%2==1) and (Nq.auto_xspc or Np.auto_xspc) then return node_copy(xkanji_skip) else - local g = node_new(id_glue); --copy_attr(g, Nn.nuc) - g.spec = node_copy(spec_zero_glue) + local g = node_copy(zero_glue) set_attr(g, attr_icflag, XKANJI_SKIP) return g end end local function get_xkanjiskip_jfm(Nn) - local g = node_new(id_glue); --copy_attr(g, Nn.nuc) + local g if (Nq.xspc>=2) and (Np.xspc%2==1) and (Nq.auto_xspc or Np.auto_xspc) then + g = node_new(id_glue); --copy_attr(g, Nn.nuc) local gx = node_new(id_glue_spec); gx.stretch_order, gx.shrink_order = 0, 0 local bk = Nn.met.size_cache.xkanjiskip or {0, 0, 0} gx.width = bk[1]; gx.stretch = bk[2]; gx.shrink = bk[3] g.spec = gx else - g.spec = node_copy(spec_zero_glue) + g = node_copy(zero_glue) end set_attr(g, attr_icflag, XKANJI_SKIP) return g @@ -684,15 +707,17 @@ end local function get_OA_skip() if not ihb_flag then - return new_jfm_glue(Np, - fast_find_char_class(((Nq.id == id_math and -1) or 'jcharbdd'), Np.met), Np.class) + local pm = Np.met + return new_jfm_glue(pm, + fast_find_char_class(((Nq.id == id_math and -1) or 'jcharbdd'), pm), Np.class) else return nil end end local function get_OB_skip() if not ihb_flag then - return new_jfm_glue(Nq, Nq.class, - fast_find_char_class(((Np.id == id_math and -1) or'jcharbdd'), Nq.met)) + local qm = Nq.met + return new_jfm_glue(qm, Nq.class, + fast_find_char_class(((Np.id == id_math and -1) or'jcharbdd'), qm)) else return nil end end @@ -718,7 +743,7 @@ local function handle_np_jachar(mode) end real_insert(0, g) end - if mode and (ltjs_fast_get_penalty_table('kcat', Np.char) or 0)%2~=1 then + if mode and Np.kcat%2~=1 then widow_Np.first, widow_Bp, Bp = Np.first, Bp, widow_Bp end end @@ -788,8 +813,9 @@ local function handle_list_tail(mode) end else -- the current list is the contents of a hbox - if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then - local g = new_jfm_glue(Np, Np.class, fast_find_char_class('boxbdd',Np.met)) + local npi, pm = Np.id, Np.met + if npi == id_jglyph or (npi==id_pbox and pm) then + local g = new_jfm_glue(pm, Np.class, fast_find_char_class('boxbdd', pm)) if g then set_attr(g, attr_icflag, BOXBDD) head = node.insert_after(head, Np.last, g) @@ -800,9 +826,10 @@ end -- リスト先頭の処理 local function handle_list_head(par_indented) - if Np.id == id_jglyph or (Np.id==id_pbox and Np.met) then + local npi, pm = Np.id, Np.met + if npi == id_jglyph or (npi==id_pbox and pm) then if not ihb_flag then - local g = new_jfm_glue(Np, fast_find_char_class(par_indented, Np.met), Np.class) + local g = new_jfm_glue(pm, fast_find_char_class(par_indented, pm), Np.class) if g then set_attr(g, attr_icflag, BOXBDD) if g.id==id_glue and #Bp==0 then