local getlist = node.direct.getlist
local getchar = node.direct.getchar
local getsubtype = node.direct.getsubtype
-
+local if_lang_ja
+do
+ local lang_ja = luatexja.lang_ja
+ local getlang = node.direct.getlang
+ if_lang_ja = getlang
+ and function (n) return getlang(n)==lang_ja end
+ or function (n) return getfield(n,'lang')==lang_ja end
+end
+
local has_attr = node.direct.has_attribute
local set_attr = node.direct.set_attribute
local insert_before = node.direct.insert_before
local id_pbox = 257 -- already processed nodes (by \unhbox)
local id_pbox_w = 258 -- cluster which consists of a whatsit
local sid_user = node.subtype('user_defined')
-local lang_ja = luatexja.lang_ja
local sid_start_link = node.subtype('pdf_start_link')
local sid_start_thread = node.subtype('pdf_start_thread')
local first_char = first_char
if first_char then
if getid(first_char)==id_glyph then
- if getfield(first_char, 'lang') == lang_ja then
+ if if_lang_ja(first_char) then
set_np_xspc_jachar_hbox(Nx, first_char)
else
set_np_xspc_alchar(Nx, getchar(first_char),first_char, 1)
local function calc_np_aux_glyph_common(lp, acc_flag)
Np.nuc = lp
Np.first= (Np.first or lp)
- if getfield(lp, 'lang') == lang_ja then
+ if if_lang_ja(lp) then
Np.id = id_jglyph
local m, mc, cls = set_np_xspc_jachar(Np, lp)
local npi, npf
lp=lx; break
else
local lid = getid(lx)
- if lid==id_glyph and getfield(lx, 'lang') ~= lang_ja then
+ if lid==id_glyph and not if_lang_ja(lx) then
-- 欧文文字
last_glyph = lx; set_attr(lx, attr_icflag, PROCESSED); Np.last = lx
y_adjust = has_attr(lx,attr_ablshift) or 0
local s = Nx.last_char
if s then
if getid(s)==id_glyph then
- if getfield(s, 'lang') == lang_ja then
+ if if_lang_ja(s) then
set_np_xspc_jachar_hbox(Nx, s)
else
set_np_xspc_alchar(Nx, getchar(s), s, 2)
local getchar = node.direct.getchar
local getfield = node.direct.getfield
local getsubtype = node.direct.getsubtype
+local getlang = node.direct.getlang or function (n) return getfield(n,'lang') end
local pairs = pairs
local floor = math.floor
local dir_tate = luatexja.dir_table.dir_tate
local lang_ja = luatexja.lang_ja
+local setlang = node.direct.setlang or function(n,l) setfield(n,'lang',l) end
+local setfont = node.direct.setfont or function(n,l) setfield(n,'font',l) end
+local setchar = node.direct.setchar or function(n,l) setfield(n,'char',l) end
+
------------------------------------------------------------------------
-- MAIN PROCESS STEP 1: replace fonts
------------------------------------------------------------------------
while pid==id_glyph do
local pc = getchar(p)
if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p, pc) then
- setfield(p, 'font',
- ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc))
- setfield(p, 'lang', lang_ja)
+ setfont(p, ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc))
+ setlang(p, lang_ja)
ltjs_orig_char_table[p] = pc
end
p = node_next(p); pid = getid(p)
end
if ltjs.list_dir == dir_tate then
for p in node.direct.traverse_id(id_glyph,to_direct(head)) do
- if (has_attr(p, attr_icflag) or 0)<=0 and getfield(p, 'lang')==lang_ja then
+ if (has_attr(p, attr_icflag) or 0)<=0 and getlang(p)==lang_ja then
local pc = ltjs_orig_char_table[p]
local nf = ltjf_replace_altfont( has_attr(p, attr_curtfnt) or getfont(p) , pc)
- setfield(p, 'font', nf)
+ setfont(p, nf)
if ltjf_font_metric_table[nf].vert_activated then
local pc = getchar(p)
pc = (ltjf_font_extra_info[nf] and ltjf_font_extra_info[nf][pc] and ltjf_font_extra_info[nf][pc].vform)
- if pc and font_getfont(nf).characters[pc] then setfield(p, 'char', pc) end
+ if pc and font_getfont(nf).characters[pc] then setchar(p, pc) end
end
end
end
local getlist = node.direct.getlist
local getchar = node.direct.getchar
local getsubtype = node.direct.getsubtype
+local getwhd = node.direct.getwhd or function(n)
+ return getfield(n,'width'), getfield(n,'height'),getfield(n,'depth') end
+local setwhd = node.direct.setwhd or function(n,w,h,d)
+ setfield(n,'width',w); setfield(n,'height',h); setfield(n,'depth',d) end
+local setchar = node.direct.setchar or function(n,c) setfield(n,'char',c) end
+local setoffsets = node.direct.setoffsets or function(n,x,y)
+ setfield(n,'xoffset',x); setfield(n,'yoffset',y) end
+local getoffsets = node.direct.getoffsets or function(n)
+ return getfield(n,'xoffset'), getfield(n,'yoffset') end
local node_traverse_id = node.direct.traverse_id
local node_traverse = node.direct.traverse
local kbl = has_attr(p, attr_ykblshift) or 0
--
-- f*: whd specified in JFM
- local fwidth, pwidth = char_data.width, getfield(p, 'width')
- fwidth = fwidth or pwidth
- local fheight, pheight = char_data.height, getfield(p, 'height')
- fheight = fheight or pheight
- local fdepth, pdepth = char_data.depth,getfield(p, 'depth')
- fdepth = fdepth or pdepth
+ local pwidth, pheight,pdepth = getwhd(p)
+ local fwidth = char_data.width or pwidth
+ local fheight= char_data.height or pheight
+ local fdepth = char_data.depth or pdepth
if pwidth==fwidth then
-- 補正後glyph node は ht: p.height - kbl - down, dp: p.depth + min(0, kbl+down) を持つ
-- 設定されるべき寸法: ht: fheight - kbl, dp: fdepth + kbl
local ht_diff = fheight + fshift.down - pheight
local dp_diff = fdepth + kbl - pdepth - min(kbl + fshift.down, 0)
if ht_diff == 0 and dp_diff ==0 then -- offset only
- set_attr(p, attr_icflag, PROCESSED)
- setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left)
- setfield(p, 'yoffset', getfield(p, 'yoffset') - kbl - fshift.down)
+ set_attr(p, attr_icflag, PROCESSED)
+ local xo, yo = getoffsets(p)
+ setoffsets(p, xo - fshift.left, yo - kbl - fshift.down)
return node_next(p), head, p
elseif ht_diff >= 0 and dp_diff >=0 then -- rule
local box = node_new(id_rule,rule_subtype)
- setfield(p, 'yoffset', getfield(p, 'yoffset') - kbl - fshift.down)
- setfield(box, 'width', 0)
- setfield(box, 'height', fheight - kbl)
- setfield(box, 'depth', fdepth + kbl)
+ local xo, yo = getoffsets(p)
+ setoffsets(p, xo, yo - kbl - fshift.down)
+ setwhd(box, 0, fheight - kbl, fdepth + kbl)
setfield(box, 'dir', dir)
set_attr(box, attr_icflag, PACKED)
set_attr(p, attr_icflag, PROCESSED)
setfield(p, 'xoffset', getfield(p, 'xoffset')
+ char_data.align*(fwidth-pwidth) - fshift.left)
local box = node_new(id_hlist)
- setfield(box, 'width', fwidth)
- setfield(box, 'height', fheight)
- setfield(box, 'depth', fdepth)
+ setwhd(box, fwidth, fheight, fdepth)
setfield(box, 'head', p)
setfield(box, 'shift', kbl)
setfield(box, 'dir', dir)
do
local pf = getfont(p)
local pc = getchar(p)
- setfield(p, 'char', pc)
+ setchar(p, pc)
pwidth = ltjf_font_extra_info[pf] and ltjf_font_extra_info[pf][pc]
and ltjf_font_extra_info[pf][pc].vwidth
and ltjf_font_extra_info[pf][pc].vwidth * met.size or (ascent+descent)
local q
head, q = node_remove(head, p)
local box = node_new(id_hlist)
- setfield(box, 'width', fwidth)
- setfield(box, 'height', fheight)
- setfield(box, 'depth', fdepth)
+ setwhd(box, fwidth, fheight, fdepth)
setfield(box, 'shift', y_shift)
setfield(box, 'dir', dir)
setfield(p, 'yoffset', -fshift.down)
setfield(p, 'xoffset', getfield(p, 'xoffset') + char_data.align*(fwidth-pwidth) - fshift.left)
local box = node_new(id_hlist);
- setfield(box, 'width', fwidth)
- setfield(box, 'height', fheight)
- setfield(box, 'depth', fdepth)
+ setfield(box, fwidth, fheight, fdepth)
setfield(box, 'head', p)
setfield(box, 'shift', y_shift)
setfield(box, 'dir', tex.mathdir)