--
luatexbase.provides_module({
name = 'luatexja.jfmglue',
- date = '2013/12/05',
+ date = '2014/1/12',
description = 'Insertion process of JFM glues and kanjiskip',
})
module('luatexja.jfmglue', package.seeall)
-local err, warn, info, log = luatexbase.errwarinf(_NAME)
+local err, warn, info, log = luatexbase .errwarinf(_NAME)
luatexja.load_module('stack'); local ltjs = luatexja.stack
luatexja.load_module('jfont'); local ltjf = luatexja.jfont
local node_new = node.new
local node_copy = node.copy
-local ligature_head = 1
-local ligature_tail = 2
-
local id_glyph = node.id('glyph')
local id_hlist = node.id('hlist')
local id_vlist = node.id('vlist')
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)
+ set_np_xspc_alchar(Nx, first_char.char,first_char, 1)
end
else -- math_node
set_np_xspc_alchar(Nx, -1,first_char)
-- We clear `predefined' entries of Np before pairs() loop,
-- because using only pairs() loop is slower.
Np.post, Np.pre, Np.xspc = nil, nil, nil
- Np.first, Np.id, Np.last, Np.met = nil, nil, nil
- Np.auto_kspc, Np.auto_xspc, Np.char, Np.class, Np.nuc = nil, nil, nil, nil, nil
+ Np.first, Np.id, Np.last, Np.met, Np.class= nil, nil, nil, nil
+ Np.auto_kspc, Np.auto_xspc, Np.char, Np.nuc = nil, nil, nil, nil
for k in pairs(Np) do Np[k] = nil end
for k = 1,#Bp do Bp[k] = nil end
function set_np_xspc_jachar(Nx, x)
local m = ltjf_font_metric_table[x.font]
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.met, Nx.char = m, c; Nx.class = cls;
+ if cls~=0 then set_attr(x, attr_jchar_class, cls) end
Nx.pre = table_current_stack[PRE + c] or 0
Nx.post = table_current_stack[POST + c] or 0
Nx.xspc = table_current_stack[XSP + c] or 3
function extract_np()
local x, i = Np.nuc, Np.id;
if i == id_jglyph then return set_np_xspc_jachar(Np, x)
- elseif i == id_glyph then return set_np_xspc_alchar(Np, x.char, x, ligature_head)
+ elseif i == id_glyph then return set_np_xspc_alchar(Np, x.char, x, 1)
elseif i == id_hlist then Np.last_char = check_box_high(Np, x.head, nil)
elseif i == id_pbox then Np.last_char = check_box_high(Np, Np.first, node_next(Np.last))
elseif i == id_disc then Np.last_char = check_box_high(Np, x.replace, nil)
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)
+ set_np_xspc_alchar(Nx, s.char, s, 2)
end
else
set_np_xspc_alchar(Nx, -1, s)
function after_alchar(Nx)
local x = Nx.nuc
- return set_np_xspc_alchar(Nx, x.char,x, ligature_tail)
+ return set_np_xspc_alchar(Nx, x.char,x, 2)
end
end
-- MAIN PROCESS STEP 1: replace fonts
------------------------------------------------------------------------
local wt
-
-local function suppress_hyphenate_ja(head)
- local non_math, p = true, head
- wt = {}
- while p do
- local pid = p.id
- if pid == id_glyph then
- if (has_attr(p, attr_icflag) or 0)<=0 and ltjc_is_ucs_in_japanese_char(p) then
- local pc = p.char
- local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or p.font, pc)
- p.font = pf; set_attr(p, attr_curjfnt, pf)
- p.subtype = floor(p.subtype*0.5)*2
- set_attr(p, attr_orig_char, pc)
- end
- elseif pid == id_math then
- p = node_next(p) -- skip math on
+do
+ local head
+ local end_math = node.end_of_math or
+ function(p)
while p and p.id~=id_math do p = node_next(p) end
- elseif pid == id_whatsit and p.subtype==sid_user and p.user_id==STCK then
+ return p
+ end
+
+ local suppress_hyphenate_ja_aux = {}
+ suppress_hyphenate_ja_aux[id_glyph] = function(p)
+ if (has_attr(p, attr_icflag) or 0)<=0 and ltjc_is_ucs_in_japanese_char(p) then
+ local pc = p.char
+ local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or p.font, pc)
+ p.font = pf; set_attr(p, attr_curjfnt, pf)
+ p.subtype = floor(p.subtype*0.5)*2
+ set_attr(p, attr_orig_char, pc)
+ end
+ return p
+ end
+ suppress_hyphenate_ja_aux[id_math] = function(p) return end_math(node_next(p)) end
+ suppress_hyphenate_ja_aux[id_whatsit] = function(p)
+ if p.subtype==sid_user and p.user_id==STCK then
wt[#wt+1] = p; head = node_remove(head, p)
end
- p = node_next(p)
+ return p
end
- lang.hyphenate(head)
- return head
+
+ local function suppress_hyphenate_ja (h)
+ local p = h
+ wt, head = {}, h
+ while p do
+ local pfunc = suppress_hyphenate_ja_aux[p.id]
+ if pfunc then p = pfunc(p) end
+ p = node_next(p)
+ end
+ lang.hyphenate(head)
+ return head
+ end
+
+ luatexbase.add_to_callback('hyphenate',
+ function (head,tail)
+ return suppress_hyphenate_ja(head)
+ end,'ltj.hyphenate')
end
-- mode: true iff this function is called from hpack_filter
function (head)
return set_box_stack_level(head, false)
end,'ltj.pre_linebreak_filter_pre',1)
-luatexbase.add_to_callback('hyphenate',
- function (head,tail)
- return suppress_hyphenate_ja(head)
- end,'ltj.hyphenate')
luatexja.pretreat = {
set_box_stack_level = set_box_stack_level,