--
-- ltj-adjust.lua
--
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('jfont'); local ltjf = luatexja.jfont
-luatexja.load_module('jfmglue'); local ltjj = luatexja.jfmglue
-luatexja.load_module('stack'); local ltjs = luatexja.stack
-luatexja.load_module('direction'); local ltjd = luatexja.direction
-luatexja.load_module('lineskip'); local ltjl = luatexja.lineskip
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'jfont'; local ltjf = luatexja.jfont
+luatexja.load_module 'jfmglue'; local ltjj = luatexja.jfmglue
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
+luatexja.load_module 'direction'; local ltjd = luatexja.direction
+luatexja.load_module 'lineskip'; local ltjl = luatexja.lineskip
luatexja.adjust = luatexja.adjust or {}
local to_node = node.direct.tonode
local set_attr = node.direct.set_attribute
local insert_after = node.direct.insert_after
-local id_glyph = node.id('glyph')
-local id_kern = node.id('kern')
-local id_hlist = node.id('hlist')
-local id_glue = node.id('glue')
-local id_whatsit = node.id('whatsit')
-local id_penalty = node.id('penalty')
+local id_glyph = node.id 'glyph'
+local id_kern = node.id 'kern'
+local id_hlist = node.id 'hlist'
+local id_glue = node.id 'glue'
+local id_whatsit = node.id 'whatsit'
+local id_penalty = node.id 'penalty'
local attr_icflag = luatexbase.attributes['ltj@icflag']
local attr_jchar_class = luatexbase.attributes['ltj@charclass']
local lang_ja = luatexja.lang_ja
local function make_priority_table(glue_sign)
for i,_ in pairs(tmp) do tmp[i]=nil end
if glue_sign==2 then -- shrink
- for i=0,63 do tmp[#tmp+1] = { (i%8)-4, FROM_JFM+i } end
+ for i=0,63 do tmp[#tmp+1] = { (i%8)-4, FROM_JFM+i } end
else -- stretch
- for i=0,63 do tmp[#tmp+1] = { math.floor(i/8)-4, FROM_JFM+i } end
+ for i=0,63 do tmp[#tmp+1] = { math.floor(i/8)-4, FROM_JFM+i } end
end
local pt = priority_table[glue_sign]
tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP }
table.sort(tmp, cmp)
local a, m, n = at2pr[glue_sign], 10000000, 0
for i=1,#tmp do
- if tmp[i][1]<m then n,m = n+1,tmp[i][1] end
- a[tmp[i][2]] = n
+ if tmp[i][1]<m then n,m = n+1,tmp[i][1] end
+ a[tmp[i][2]] = n
end
local o = a[-1]
priority_num[glue_sign] = n
for q in node_traverse_id(id_glue, ph) do
local a = getfield(q, 'stretch_order')
if a==0 then
- local b = at2pr_st[get_attr_icflag(q)];
- total_st[b] = total_st[b]+getfield(q, 'stretch')
+ local b = at2pr_st[get_attr_icflag(q)];
+ total_st[b] = total_st[b]+getfield(q, 'stretch')
end
total_st[a*65536] = total_st[a]+getfield(q, 'stretch')
local a = getfield(q, 'shrink_order')
if a==0 then
- local b = at2pr_sh[get_attr_icflag(q)];
- total_sh[b] = total_sh[b]+getfield(q, 'shrink')
+ local b = at2pr_sh[get_attr_icflag(q)];
+ total_sh[b] = total_sh[b]+getfield(q, 'shrink')
end
total_sh[a*65536] = total_sh[a]+getfield(q, 'shrink')
end
for i, v in ipairs(eadt) do
local t = total - v
if t>0 then
- eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v}
+ eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v}
else
- eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v}
+ eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v}
end
end
table.sort(eadt_ratio,
function (a,b)
for i=2,4 do
- local at, bt = abs(a[i]), abs(b[i])
- if at~=bt then return at<bt end
+ local at, bt = abs(a[i]), abs(b[i])
+ if at~=bt then return at<bt end
end
return a[4]<b[4]
end)
if total_st.order ~= getfield(pf, 'stretch_order') then return total, false end
if total_st[total_st.order*65536] ~= getfield(pf, 'stretch') then return total, false end
for i=total_st.order-1, 1, -1 do
- if total_st[i*65536] ~= 0 then return total, false end
+ if total_st[i*65536] ~= 0 then return total, false end
end
end
if total<0 and total_sh.order>0 then
if total_sh.order ~= getfield(pf, 'shrink_order') then return total, false end
if total_sh[total_sh.order*65536] ~= getfield(pf, 'shrink') then return total, false end
for i=total_sh.order-1, 1, -1 do
- if total_sh[i*65536] ~= 0 then return total, false end
+ if total_sh[i*65536] ~= 0 then return total, false end
end
end
local eadt = ltjf_font_metric_table[getfont(xc)]
for i, v in ipairs(eadt) do
local t = total - v
if t>0 then
- eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v}
+ eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v}
else
- eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v}
+ eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v}
end
end
table.sort(eadt_ratio,
function (a,b)
for i=2,4 do
- local at, bt = abs(a[i]), abs(b[i])
- if at~=bt then return at<bt end
+ local at, bt = abs(a[i]), abs(b[i])
+ if at~=bt then return at<bt end
end
return a[4]<b[4]
end)
for q in node_traverse_id(id_glue, getlist(p)) do
local f = ap[get_attr_icflag(q)]
if f == ind then
- setfield(q, name..'_order', 0)
- setfield(q, name, 0)
+ setfield(q, name..'_order', 0); setfield(q, name, 0)
end
end
end
if before > 0 then
local ratio = after/before
for q in node_traverse_id(id_glue, getlist(p)) do
- local f = ap[get_attr_icflag(q)]
+ local f = ap[get_attr_icflag(q)]
if (f==ind) and getfield(q, name..'_order')==0 then
setfield(q, name, getfield(q, name)*ratio)
end
total = abs(total)
for i = 1, pnum do
if total <= res[i] then
- local a = at2pr[id]
+ local a = at2pr[id]
for j = i+1,pnum do
clear_stretch(p, j, a, name)
end
insert_lineend_kern = function (head, nq, np, Bp)
if nq.met then
local eadt = nq.met.char_type[nq.class].end_adjust
- if not eadt then return end
- if eadt[1]~=0 then
- local x = node_new(id_kern, 1)
- setfield(x, 'kern', eadt[1]); set_attr(x, attr_icflag, LINEEND)
- insert_before(head, np.first, x)
- end
- local eadt_num = #eadt
- for i=2,eadt_num do
- local x = node_new(id_penalty)
- setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU)
- insert_before(head, np.first, x); Bp[#Bp+1] = x
- local x = node_new(id_kern, 1)
- setfield(x, 'kern', eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND)
- insert_before(head, np.first, x)
- end
+ if not eadt then return end
+ if eadt[1]~=0 then
+ local x = node_new(id_kern, 1)
+ setfield(x, 'kern', eadt[1]); set_attr(x, attr_icflag, LINEEND)
+ insert_before(head, np.first, x)
+ end
+ local eadt_num = #eadt
+ for i=2,eadt_num do
+ local x = node_new(id_penalty)
+ setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU)
+ insert_before(head, np.first, x); Bp[#Bp+1] = x
+ local x = node_new(id_kern, 1)
+ setfield(x, 'kern', eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND)
+ insert_before(head, np.first, x)
+ end
if eadt_num>1 or eadt[1]~=0 then
- local x = node_new(id_penalty)
- setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU)
- insert_before(head, np.first, x); Bp[#Bp+1] = x
- local x = node_new(id_kern, 1)
- setfield(x, 'kern', -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND)
- insert_before(head, np.first, x)
- local x = node_new(id_penalty)
- setfield(x, 'penalty', 10000); set_attr(x, attr_icflag, KINSOKU)
- insert_before(head, np.first, x); Bp[#Bp+1] = x
- end
+ local x = node_new(id_penalty)
+ setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU)
+ insert_before(head, np.first, x); Bp[#Bp+1] = x
+ local x = node_new(id_kern, 1)
+ setfield(x, 'kern', -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND)
+ insert_before(head, np.first, x)
+ local x = node_new(id_penalty)
+ setfield(x, 'penalty', 10000); set_attr(x, attr_icflag, KINSOKU)
+ insert_before(head, np.first, x); Bp[#Bp+1] = x
+ end
end
end
end
if not head then return head end
local last_p
for p in node_traverse_id(id_hlist, to_direct(head)) do
- if last_p then
- myaw_step2(last_p, myaw_step1(last_p, get_total_stretched(last_p)))
- end
+ if last_p then
+ myaw_step2(last_p, myaw_step1(last_p, get_total_stretched(last_p)))
+ end
last_p = p
end
if last_p then
local is_reg = false
local function enable_cb(status_le, status_pr, status_lp, status_ls)
if (status_le>0 or status_pr>0) and (not is_reg) then
- ltjb.add_to_callback('post_linebreak_filter',
+ ltjb.add_to_callback('post_linebreak_filter',
adjust_width, 'Adjust width',
- luatexbase.priority_in_callback('post_linebreak_filter', 'ltj.lineskip')-1)
- is_reg = true
+ luatexbase.priority_in_callback('post_linebreak_filter', 'ltj.lineskip')-1)
+ is_reg = true
elseif is_reg and (status_le==0 and status_pr==0) then
- luatexbase.remove_from_callback('post_linebreak_filter', 'Adjust width')
- is_reg = false
+ luatexbase.remove_from_callback('post_linebreak_filter', 'Adjust width')
+ is_reg = false
end
if status_le==2 then
- if not luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then
- ltjb.add_to_callback('luatexja.adjust_jfmglue', insert_lineend_kern, 'luatexja.adjust')
- end
+ if not luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then
+ ltjb.add_to_callback('luatexja.adjust_jfmglue', insert_lineend_kern, 'luatexja.adjust')
+ end
myaw_step1, myaw_step1_last = dummy, aw_step1_last
else
if status_le==0 then
myaw_step1, myaw_step1_last = aw_step1, aw_step1_last
end
if luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then
- luatexbase.remove_from_callback('luatexja.adjust_jfmglue', 'luatexja.adjust')
+ luatexbase.remove_from_callback('luatexja.adjust_jfmglue', 'luatexja.adjust')
end
end
myaw_step2 = (status_pr>0) and aw_step2 or aw_step2_dummy
luatexja.lineskip.setting(
status_lp>0 and 'profile' or 'dummy',
- status_ls>0 and 'step' or 'dummy'
+ status_ls>0 and 'step' or 'dummy'
)
end
local function disable_cb() -- only for compatibility
ins(package[1], {b,e,[ind]=d})
end
local function flatten(package)
- local bd={} for i,_ in pairs(package[2]) do ins(bd,{i}) end
+ local bd = {} for i,_ in pairs(package[2]) do ins(bd,{i}) end
sort(bd, function (a,b) return a[1]<b[1] end)
local bdc=#bd; local t = package[1]
sort(t, function (a,b) return a[1]<b[1] end)
bd[j][k]=bd[j][k] and max(bd[j][k],w) or w
end
end
- j=j+1
+ j = j + 1
end
end
package[2]=nil; package[1]=nil; package.flatten, package.insert=nil, nil
if lmin==1/0 then lmin = bw end
return lmin,
bw - lmin - getfield(before, 'depth')
- - getfield(after, mirrored and 'depth' or 'height')
+ - getfield(after, mirrored and 'depth' or 'height')
end
end
end
--
luatexbase.provides_module({
name = 'luatexja.charrange',
- date = '2019/09/26',
+ date = '2020-07-30',
description = 'Handling the range of Japanese characters',
})
luatexja.charrange = {}
-luatexja.load_module('base'); local ltjb = luatexja.base
+luatexja.load_module 'base'; local ltjb = luatexja.base
local getchar = node.direct.getchar
local has_attr = node.direct.has_attribute
function luatexja.charrange.add_char_range(b,e,ind) -- ind: external range number
if not ind or ind<0 or ind>31*ATTR_RANGE then -- 0 はエラーにしない(隠し)
ltjb.package_error('luatexja',
- "invalid character range number (" .. ind .. ")",
- "A character range number should be in the range 1.."
+ "invalid character range number (" .. ind .. ")",
+ "A character range number should be in the range 1.."
.. 31*ATTR_RANGE .. ",\n" ..
- "ignored.")
+ "ignored.")
return
elseif b<0x80 or e>=ucs_out then
ltjb.package_warning('luatexja',
- 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
- 'I take the intersection with [0x80, 0x10ffff].')
- elseif b>e then
- local j=b; e=b; b=j
- end
+ 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
+ 'I take the intersection with [0x80, 0x10ffff].')
+ elseif b>e then b, e = e, b end
if ind == 31*ATTR_RANGE then ind=0 end
for i=math.max(0x80,b),math.min(ucs_out-1,e) do
jcr_table_main[i]=ind
-- EXT
function luatexja.charrange.toggle_char_range(g, i) -- i: external range number
if type(i)~='number' then
- ltjb.package_error('luatexja',
- "invalid character range number (" .. tostring(i).. ")",
- "A character range number must be a number, ignored.")
+ ltjb.package_error('luatexja',
+ "invalid character range number (" .. tostring(i).. ")",
+ "A character range number must be a number, ignored.")
elseif i==0 then return
else
local kc
local attr = kcat_attr_table[i]
local a = tex_getattr(attr)
tex.setattribute(g, attr,
- (floor(a/pow_table[i+1])*2+kc)*pow_table[i]+a%pow_table[i])
+ (floor(a/pow_table[i+1])*2+kc)*pow_table[i]+a%pow_table[i])
end
end
-- ltj-compat.lua
--
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('stack'); local ltjs = luatexja.stack
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
local stack_table_index = luatexja.stack_table_index
-- load jisx0208 table
local cache_outdate_fn = function (t) return t.version~=cache_ver end
local jisx0208 = ltjb.load_cache('ltj-jisx0208',cache_outdate_fn)
if not jisx0208 then -- make cache
- jisx0208 = require('ltj-jisx0208.lua')
+ jisx0208 = require 'ltj-jisx0208.lua'
ltjb.save_cache_luc('ltj-jisx0208', jisx0208)
end
local function to_kansuji(num)
if not num then num=0; return
elseif num<0 then
- num = -num; tex.write('-')
+ num = -num; tex.write '-'
end
local s = ""
while num~=0 do
s = utfchar(
- ltjs.get_stack_table(luatexja.stack_table_index.KSJ + num%10,
- '', tex.getcount('ltj@@stack'))) .. s
+ ltjs.get_stack_table(luatexja.stack_table_index.KSJ + num%10,
+ '', tex.getcount 'ltj@@stack')) .. s
num=math.floor(num/10)
end
tex.write(s)
end
+local function error_invalid_charcode(i)
+ ltjb.package_error('luatexja',
+ "invalid character code (".. tostring(i) .. ")",
+ "I'm going to use 0 instead of that illegal character code.")
+end
+
-- \ucs: 単なる identity
local function from_ucs(i)
- if type(i)~='number' then
- ltjb.package_error('luatexja',
- "invalid character code (".. tostring(i) .. ")",
- "I'm going to use 0 instead of that illegal character code.")
- i=0
- end
+ if type(i)~='number' then error_invalid_charcode(i); i=0 end
tex.write(i)
end
-- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
local function from_kuten(i)
- if type(i)~='number' then
- ltjb.package_error('luatexja',
- "invalid character code (".. tostring(i) .. ")",
- "I'm going to use 0 instead of that illegal character code.")
- i=0
- end
+ if type(i)~='number' then error_invalid_charcode(i); i=0 end
if (i%256==0)or(i%256>94) then
- tex.write('0')
+ tex.write '0'
else
tex.write(tostring(jisx0208.table_jisx0208_uptex[math.floor(i/256)*94+(i%256)-94] or 0))
end
-- \euc: EUC-JP による符号位置 => Unicode 符号位置
local function from_euc(i)
- if type(i)~='number' then
- ltjb.package_error('luatexja',
- "invalid character code (".. tostring(i) .. ")",
- "I'm going to use 0 instead of that illegal character code.")
- i=0
+ if type(i)~='number' then
+ error_invalid_charcode(i); i=0
elseif i>=0x10000 or i<0xa0a0 then
i=0
end
-- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
local function from_jis(i)
- if (type(i)~='number') or i>=0x10000 or i<0 then
- ltjb.package_error('luatexja',
- "invalid character code (".. tostring(i) .. ")",
- "I'm going to use 0 instead of that illegal character code.")
- i=0
- end
+ if type(i)~='number' then error_invalid_charcode(i); i=0 end
from_kuten(i-0x2020)
end
-- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
local function from_sjis(i)
if (type(i)~='number') or i>=0x10000 or i<0 then
- ltjb.package_error('luatexja',
- "invalid character code (".. tostring(i) .. ")",
- "I'm going to use 0 instead of that illegal character code.")
- tex.write('0'); return
+ error_invalid_charcode(i); tex.write '0'; return
end
local c2 = math.floor(i/256)
local c1 = i%256
{ [false]=15 } }
if c2 >= 0x81 then
if c2 >= 0xF0 then -- this if block won't be true
- if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
- c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
- else -- 78<=k<=94
- c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
- end
+ if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
+ c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
+ else -- 78<=k<=94
+ c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
+ end
else
- if c2<=0x9f then i=0x101 else i=0x181 end
- c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
+ if c2<=0x9f then i=0x101 else i=0x181 end
+ c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
end
if c1 < 0x9F then
- if c1>0x7f then i=0x40 else i=0x3f end
- c1 = c1 - i
+ if c1>0x7f then i=0x40 else i=0x3f end; c1 = c1 - i
else
- c1 = c1 - 0x9e
+ c1 = c1 - 0x9e
end
from_kuten(c2*256+c1)
end
luatexja.binary_pars.kansujichar = function(c, t)
if type(c)~='number' or c<0 or c>9 then
ltjb.package_error('luatexja',
- 'Invalid KANSUJI number (' .. tostring(c) .. ')',
- 'A KANSUJI number should be in the range 0..9.\n'..
- 'So I changed this one to zero.')
+ 'Invalid KANSUJI number (' .. tostring(c) .. ')',
+ 'A KANSUJI number should be in the range 0..9.\n'..
+ 'So I changed this one to zero.')
c=0
end
return ltjs.get_stack_table(stack_table_index.KSJ + c, 0, t)
local t = {
- from_euc = from_euc,
- from_kuten = from_kuten,
- from_jis = from_jis,
- from_sjis = from_sjis,
- from_ucs = from_ucs,
- to_kansuji = to_kansuji,
+ from_euc = from_euc, from_kuten = from_kuten,
+ from_jis = from_jis, from_sjis = from_sjis,
+ from_ucs = from_ucs, to_kansuji = to_kansuji,
}
luatexja.compat = t
-- src/ltj-direction.lua
--
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('stack'); local ltjs = luatexja.stack
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
luatexja.direction = {}
local attr_dir = luatexbase.attributes['ltj@dir']
local traverse = node.direct.traverse
local traverse_id = node.direct.traverse_id
local start_time_measure, stop_time_measure
- = ltjb.start_time_measure, ltjb.stop_time_measure
+ = ltjb.start_time_measure, ltjb.stop_time_measure
local abs = math.abs
-local id_kern = node.id('kern')
-local id_hlist = node.id('hlist')
-local id_vlist = node.id('vlist')
-local id_whatsit = node.id('whatsit')
-local sid_save = node.subtype('pdf_save')
-local sid_restore = node.subtype('pdf_restore')
-local sid_matrix = node.subtype('pdf_setmatrix')
-local sid_user = node.subtype('user_defined')
+local id_kern = node.id 'kern'
+local id_hlist = node.id 'hlist'
+local id_vlist = node.id 'vlist'
+local id_whatsit = node.id 'whatsit'
+local sid_save = node.subtype 'pdf_save'
+local sid_restore= node.subtype 'pdf_restore'
+local sid_matrix = node.subtype 'pdf_setmatrix'
+local sid_user = node.subtype 'user_defined'
local tex_nest = tex.nest
local tex_getcount = tex.getcount
do
local function get_dir_count_inner(h)
if h then
- if h.id==id_whatsit and h.subtype==sid_user and h.user_id==DIR then
- local ic = node.has_attribute(h, attr_icflag) or 0
- return (ic<PROCESSED_BEGIN_FLAG)
- and (node.has_attribute(h,attr_dir)%dir_node_auto) or 0
- else
- return 0
- end
+ if h.id==id_whatsit and h.subtype==sid_user and h.user_id==DIR then
+ return ((node.has_attribute(h, attr_icflag) or 0)<PROCESSED_BEGIN_FLAG)
+ and (node.has_attribute(h,attr_dir)%dir_node_auto) or 0
+ else
+ return 0
+ end
else
- return 0
+ return 0
end
end
function get_dir_count()
for i=tex_nest.ptr, 1, -1 do
- local h = tex_nest[i].head.next
- if h then
- local t = get_dir_count_inner(h)
- if t~=0 then return t end
- end
+ local h = tex_nest[i].head.next
+ if h then
+ local t = get_dir_count_inner(h)
+ if t~=0 then return t end
+ end
end
return page_direction
end
function get_adjust_dir_count()
for i=tex_nest.ptr, 1, -1 do
local v = tex_nest[i]
- local h, m = v.head.next, v.mode
- if abs(m)== ltjs.vmode and h then
- local t = get_dir_count_inner(h)
- if t~=0 then return t end
- end
+ local h, m = v.head.next, v.mode
+ if abs(m)== ltjs.vmode and h then
+ local t = get_dir_count_inner(h)
+ if t~=0 then return t end
+ end
end
return page_direction
end
local node_traverse = node.traverse
local STCK = luatexja.userid_table.STCK
local IHB = luatexja.userid_table.IHB
- local id_local = node.id('local_par')
- local id_dir = node.id('dir')
+ local id_local = node.id 'local_par'
+ local id_dir = node.id 'dir'
local function test_list(h, lv)
if not h then
- return 2 -- need to create dir_whatsit
+ return 2 -- need to create dir_whatsit
else
- local flag = 2 -- need to create dir_whatsit
- local w
- for p in node_traverse(h) do
- if p.id==id_whatsit then
- local ps = p.subtype
- if ps==sid_user then
- local uid= p.user_id
- if uid==DIR then
- flag = 1; w = w or p -- found
- elseif not(uid==IHB or uid==STCK) then
- flag = 0; break -- error
- end
- end
- elseif p.id~=id_local and p.id~=id_dir then
- flag = 0; break
- end
- end
- if flag==1 then -- dir_whatsit already exists
- return 1,w
- else
- return flag
- end
+ local flag = 2 -- need to create dir_whatsit
+ local w
+ for p in node_traverse(h) do
+ if p.id==id_whatsit then
+ if p.subtype==sid_user then
+ local uid= p.user_id
+ if uid==DIR then
+ flag = 1; w = w or p -- found
+ elseif not(uid==IHB or uid==STCK) then
+ return 0 -- error
+ end
+ end
+ elseif p.id~=id_local and p.id~=id_dir then
+ return 0 -- error
+ end
+ end
+ if flag==1 then -- dir_whatsit already exists
+ return 1, w
+ else
+ return flag
+ end
end
end
local node_next_node, node_tail_node = node.next, node.tail
local lv = tex_nest.ptr -- must be >= 1
if not v then
v = get_dir_count()
- if abs(tex_nest[lv-1].mode) == ltjs.mmode and v == dir_tate then
- v = dir_utod
- end
+ if abs(tex_nest[lv-1].mode) == ltjs.mmode and v == dir_tate then
+ v = dir_utod
+ end
elseif v=='adj' then
v = get_adjust_dir_count()
end
local lv = tex_nest.ptr
if not v then
v,name = get_dir_count(), nil
- if lv>=1 and abs(tex_nest[lv-1].mode) == ltjs.mmode and v == dir_tate then
- v = dir_utod
- end
+ if lv>=1 and abs(tex_nest[lv-1].mode) == ltjs.mmode and v == dir_tate then
+ v = dir_utod
+ end
elseif v=='adj' then
v,name = get_adjust_dir_count(), nil
end
local current_nest = tex_nest[lv]
if tex.currentgrouptype==6 then
- ltjb.package_error(
+ ltjb.package_error(
'luatexja',
"You can't use `\\" .. name .. "' in an align",
- "To change the direction in an align, \n"
- .. "you shold use \\hbox or \\vbox.")
+ "To change the direction in an align, \n"
+ .. "you shold use \\hbox or \\vbox.")
elseif current_nest.mode == ltjs.hmode or abs(current_nest.mode) == ltjs.mmode then
- ltjb.package_error(
+ ltjb.package_error(
'luatexja',
- "Improper `\\" .. name .. "'",
- 'You cannot change the direction in unrestricted horizontal mode \n'
- .. 'nor math modes.')
+ "Improper `\\" .. name .. "'",
+ 'You cannot change the direction in unrestricted horizontal mode \n'
+ .. 'nor math modes.')
else
- local h = (lv==0) and tex.lists.page_head or current_nest.head.next
- local flag,w = test_list(h,lv)
- if flag==0 then
- if lv==0 and not page_direction then
- page_direction = v -- for first call of \yoko (in luatexja-core.sty)
- else
+ local h = (lv==0) and tex.lists.page_head or current_nest.head.next
+ local flag,w = test_list(h,lv)
+ if flag==0 then
+ if lv==0 and not page_direction then
+ page_direction = v -- for first call of \yoko (in luatexja-core.sty)
+ else
if luatexja.debug then
luatexja.ext_show_node_list(node.direct.tonode(h),'>> ', texio.write_nl)
end
'luatexja',
"Use `\\" .. tostring(name) .. "' at top of list",
'Direction change command by LuaTeX-ja is available\n'
- .. 'only when the current list is null.')
- end
- elseif flag==1 then
- node_set_attr(w, attr_dir, v)
- if lv==0 then page_direction = v end
- elseif lv==0 then
- page_direction = v
- else -- flag == 2: need to create dir whatsit.
- local h = current_nest.head
- local hn = node.next(h)
- hn = (hn and hn.id==id_local) and hn or h
- local w = to_node(dir_pool[v]())
- insert_after_node(h,hn,w)
- current_nest.tail = node_tail_node(w)
- end
+ .. 'only when the current list is null.')
+ end
+ elseif flag==1 then
+ node_set_attr(w, attr_dir, v)
+ if lv==0 then page_direction = v end
+ elseif lv==0 then
+ page_direction = v
+ else -- flag == 2: need to create dir whatsit.
+ local h = current_nest.head
+ local hn = node.next(h)
+ hn = (hn and hn.id==id_local) and hn or h
+ local w = to_node(dir_pool[v]())
+ insert_after_node(h,hn,w)
+ current_nest.tail = node_tail_node(w)
+ end
ensure_tex_attr(attr_icflag, 0)
end
ensure_tex_attr(attr_dir, 0)
-- ボックスに dir whatsit を追加
local function create_dir_whatsit(hd, gc, new_dir)
if getid(hd)==id_whatsit and
- getsubtype(hd)==sid_user and getfield(hd, 'user_id')==DIR then
+ getsubtype(hd)==sid_user and getfield(hd, 'user_id')==DIR then
set_attr(hd, attr_icflag,
- get_attr_icflag(hd) + PROCESSED_BEGIN_FLAG)
+ get_attr_icflag(hd) + PROCESSED_BEGIN_FLAG)
local n =node_next(hd)
if n then
- set_attr(n, attr_icflag,
- get_attr_icflag(n) + PROCESSED_BEGIN_FLAG)
+ set_attr(n, attr_icflag,
+ get_attr_icflag(n) + PROCESSED_BEGIN_FLAG)
end
ensure_tex_attr(attr_icflag, 0)
return hd
setfield(w, 'next', hd)
set_attr(w, attr_icflag, PROCESSED_BEGIN_FLAG)
set_attr(hd, attr_icflag,
- get_attr_icflag(hd) + PROCESSED_BEGIN_FLAG)
+ get_attr_icflag(hd) + PROCESSED_BEGIN_FLAG)
ensure_tex_attr(attr_icflag, 0)
ensure_tex_attr(attr_dir, 0)
return w
local function create_dir_whatsit_hpack(h, gc)
local hd = to_direct(h)
if gc=='fin_row' then
- if hd then
- for p in traverse_id(15, hd) do -- unset
- if get_box_dir(p, 0)==0 then
+ if hd then
+ for p in traverse_id(15, hd) do -- unset
+ if get_box_dir(p, 0)==0 then
setfield(p, 'head', create_dir_whatsit(getlist(p), 'fin_row', ltjs.list_dir))
end
- end
- set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
- ensure_tex_attr(attr_icflag, 0)
- end
- return h
+ end
+ set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
+ ensure_tex_attr(attr_icflag, 0)
+ end
+ return h
elseif gc == 'preamble' then
else
- adjust_badness(hd)
- return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir))
+ adjust_badness(hd)
+ return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir))
end
end
ltjb.add_to_callback('hpack_filter',
- create_dir_whatsit_hpack, 'ltj.create_dir_whatsit', 10000)
+ create_dir_whatsit_hpack, 'ltj.create_dir_whatsit', 10000)
end
do
local function create_dir_whatsit_parbox(h, gc)
- stop_time_measure('tex_linebreak');
+ stop_time_measure 'tex_linebreak';
-- start 側は ltj-debug.lua に
local new_dir = ltjs.list_dir
for line in traverse_id(id_hlist, to_direct(h)) do
- setfield(line, 'head', create_dir_whatsit(getlist(line), gc, new_dir) )
+ setfield(line, 'head', create_dir_whatsit(getlist(line), gc, new_dir) )
end
ensure_tex_attr(attr_dir, 0)
return h
end
ltjb.add_to_callback('post_linebreak_filter',
- create_dir_whatsit_parbox, 'ltj.create_dir_whatsit', 10000)
+ create_dir_whatsit_parbox, 'ltj.create_dir_whatsit', 10000)
end
local create_dir_whatsit_vbox
do
local wh = {}
- local id_glue, sid_parskip = node.id('glue'), 3
+ local id_glue, sid_parskip = node.id 'glue', 3
create_dir_whatsit_vbox = function (hd, gc)
ltjs.list_dir = get_dir_count()
-- remove dir whatsit
for x in traverse_id(id_whatsit, hd) do
- if getsubtype(x)==sid_user and getfield(x, 'user_id')==DIR then
- wh[#wh+1]=x
- end
+ if getsubtype(x)==sid_user and getfield(x, 'user_id')==DIR then
+ wh[#wh+1]=x
+ end
end
if hd==wh[1] then
- ltjs.list_dir =has_attr(hd,attr_dir)
- local x = node_next(hd)
- if getid(x)==id_glue and getsubtype(x)==sid_parskip then
- node_remove(hd,x); node_free(x)
- end
+ ltjs.list_dir =has_attr(hd,attr_dir)
+ local x = node_next(hd)
+ if getid(x)==id_glue and getsubtype(x)==sid_parskip then
+ node_remove(hd,x); node_free(x)
+ end
end
for i=1,#wh do
- hd = node_remove(hd, wh[i]); node_free(wh[i]); wh[i] = nil
+ hd = node_remove(hd, wh[i]); node_free(wh[i]); wh[i] = nil
end
if gc=='fin_row' then -- gc == 'preamble' case is treated in dir_adjust_vpack
- if hd then
- set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
- ensure_tex_attr(attr_icflag, 0)
- end
- return hd
+ if hd then
+ set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
+ ensure_tex_attr(attr_icflag, 0)
+ end
+ return hd
else
- local n =node_next(hd)
- if gc=='vtop' then
- local w = create_dir_whatsit(hd, gc, ltjs.list_dir)
- -- move dir whatsit after hd
- setfield(hd, 'next', w); setfield(w, 'next', n)
- return hd
- else
- hd = create_dir_whatsit(hd, gc, ltjs.list_dir)
- return hd
- end
+ local n =node_next(hd)
+ if gc=='vtop' then
+ local w = create_dir_whatsit(hd, gc, ltjs.list_dir)
+ -- move dir whatsit after hd
+ setfield(hd, 'next', w); setfield(w, 'next', n)
+ return hd
+ else
+ hd = create_dir_whatsit(hd, gc, ltjs.list_dir)
+ return hd
+ end
end
end
end
local zero = function() return 0 end
dir_node_aux = {
[dir_yoko] = { -- yoko を
- [dir_tate] = { -- tate 中で組む
- width = get_h_d,
- height = get_w_half,
- depth = get_w_half_rem,
- [id_hlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 1 -1 0' },
- { 'kern', function(w,h,d,nw,nh,nd) return -nd end },
- { 'box' , get_h},
- { 'kern', function(w,h,d,nw,nh,nd) return nd-w end },
- { 'whatsit', sid_restore },
- },
- [id_vlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 1 -1 0' },
- { 'kern' , zero },
- { 'box' , function(w,h,d,nw,nh,nd) return -nh-nd end },
- { 'kern', get_h_d_neg},
- { 'whatsit', sid_restore },
- },
- },
- [dir_dtou] = { -- dtou 中で組む
- width = get_h_d,
- height = get_w,
- depth = zero,
- [id_hlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 -1 1 0' },
- { 'kern', function(w,h,d,nw,nh,nd) return -nh end },
- { 'box', get_d_neg },
- { 'kern', function(w,h,d,nw,nh,nd) return nh-w end },
- { 'whatsit', sid_restore },
- },
- [id_vlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 -1 1 0' },
- { 'kern', get_h_d_neg },
- { 'box', zero },
- { 'whatsit', sid_restore },
- },
- },
+ [dir_tate] = { -- tate 中で組む
+ width = get_h_d,
+ height = get_w_half,
+ depth = get_w_half_rem,
+ [id_hlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 1 -1 0' },
+ { 'kern', function(w,h,d,nw,nh,nd) return -nd end },
+ { 'box' , get_h},
+ { 'kern', function(w,h,d,nw,nh,nd) return nd-w end },
+ { 'whatsit', sid_restore },
+ },
+ [id_vlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 1 -1 0' },
+ { 'kern' , zero },
+ { 'box' , function(w,h,d,nw,nh,nd) return -nh-nd end },
+ { 'kern', get_h_d_neg},
+ { 'whatsit', sid_restore },
+ },
+ },
+ [dir_dtou] = { -- dtou 中で組む
+ width = get_h_d,
+ height = get_w,
+ depth = zero,
+ [id_hlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 -1 1 0' },
+ { 'kern', function(w,h,d,nw,nh,nd) return -nh end },
+ { 'box', get_d_neg },
+ { 'kern', function(w,h,d,nw,nh,nd) return nh-w end },
+ { 'whatsit', sid_restore },
+ },
+ [id_vlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 -1 1 0' },
+ { 'kern', get_h_d_neg },
+ { 'box', zero },
+ { 'whatsit', sid_restore },
+ },
+ },
},
[dir_tate] = { -- tate を
- [dir_yoko] = { -- yoko 中で組む
- width = get_h_d,
- height = get_w,
- depth = zero,
- [id_hlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 -1 1 0' },
- { 'kern', function (w,h,d,nw,nh,nd) return -nh end },
- { 'box' , get_d_neg },
- { 'kern', function (w,h,d,nw,nh,nd) return nh-w end },
- { 'whatsit', sid_restore },
- },
- [id_vlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 -1 1 0' },
- { 'kern', get_h_d_neg },
- { 'box', zero },
- { 'whatsit', sid_restore },
- },
- },
- [dir_dtou] = { -- dtou 中で組む
- width = get_w,
- height = get_d,
- depth = get_h,
- [id_hlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '-1 0 0 -1' },
- { 'kern', get_w_neg },
- { 'box', function (w,h,d,nw,nh,nd) return h-nd end },
- { 'whatsit', sid_restore },
- },
- [id_vlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '-1 0 0 -1' },
- { 'kern', get_h_d_neg },
- { 'box', get_w_neg },
- { 'whatsit', sid_restore },
- },
+ [dir_yoko] = { -- yoko 中で組む
+ width = get_h_d,
+ height = get_w,
+ depth = zero,
+ [id_hlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 -1 1 0' },
+ { 'kern', function (w,h,d,nw,nh,nd) return -nh end },
+ { 'box' , get_d_neg },
+ { 'kern', function (w,h,d,nw,nh,nd) return nh-w end },
+ { 'whatsit', sid_restore },
+ },
+ [id_vlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 -1 1 0' },
+ { 'kern', get_h_d_neg },
+ { 'box', zero },
+ { 'whatsit', sid_restore },
+ },
+ },
+ [dir_dtou] = { -- dtou 中で組む
+ width = get_w,
+ height = get_d,
+ depth = get_h,
+ [id_hlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '-1 0 0 -1' },
+ { 'kern', get_w_neg },
+ { 'box', function (w,h,d,nw,nh,nd) return h-nd end },
+ { 'whatsit', sid_restore },
+ },
+ [id_vlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '-1 0 0 -1' },
+ { 'kern', get_h_d_neg },
+ { 'box', get_w_neg },
+ { 'whatsit', sid_restore },
+ },
},
},
[dir_dtou] = { -- dtou を
- [dir_yoko] = { -- yoko 中で組む
- width = get_h_d,
- height = get_w,
- depth = zero,
- [id_hlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '0 1 -1 0' },
- { 'kern', function (w,h,d,nw,nh,nd) return -nd end },
- { 'box', get_h },
- { 'kern', function (w,h,d,nw,nh,nd) return nd-w end },
- { 'whatsit', sid_restore },
- },
- [id_vlist] = {
+ [dir_yoko] = { -- yoko 中で組む
+ width = get_h_d,
+ height = get_w,
+ depth = zero,
+ [id_hlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '0 1 -1 0' },
+ { 'kern', function (w,h,d,nw,nh,nd) return -nd end },
+ { 'box', get_h },
+ { 'kern', function (w,h,d,nw,nh,nd) return nd-w end },
+ { 'whatsit', sid_restore },
+ },
+ [id_vlist] = {
{ 'kern', zero },
- { 'whatsit', sid_save },
- { 'rotate', '0 1 -1 0' },
- { 'box', function (w,h,d,nw,nh,nd) return -nd-nh end },
- { 'kern', get_h_d_neg },
- { 'whatsit', sid_restore },
- },
- },
- [dir_tate] = { -- tate 中で組む
- width = get_w,
- height = get_d,
- depth = get_h,
- [id_hlist] = {
- { 'whatsit', sid_save },
- { 'rotate', '-1 0 0 -1' },
- { 'kern', get_w_neg },
- { 'box', function (w,h,d,nw,nh,nd) return h-nd end },
- { 'whatsit', sid_restore },
- },
- [id_vlist] = {
- { 'whatsit', sid_save },
- { 'rotate', ' -1 0 0 -1' },
- { 'kern', function (w,h,d,nw,nh,nd) return -nh-nd end },
- { 'box', get_w_neg },
- { 'kern', function (w,h,d,nw,nh,nd) return nh+nd-h-d end },
- { 'whatsit', sid_restore },
- },
- },
+ { 'whatsit', sid_save },
+ { 'rotate', '0 1 -1 0' },
+ { 'box', function (w,h,d,nw,nh,nd) return -nd-nh end },
+ { 'kern', get_h_d_neg },
+ { 'whatsit', sid_restore },
+ },
+ },
+ [dir_tate] = { -- tate 中で組む
+ width = get_w,
+ height = get_d,
+ depth = get_h,
+ [id_hlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', '-1 0 0 -1' },
+ { 'kern', get_w_neg },
+ { 'box', function (w,h,d,nw,nh,nd) return h-nd end },
+ { 'whatsit', sid_restore },
+ },
+ [id_vlist] = {
+ { 'whatsit', sid_save },
+ { 'rotate', ' -1 0 0 -1' },
+ { 'kern', function (w,h,d,nw,nh,nd) return -nh-nd end },
+ { 'box', get_w_neg },
+ { 'kern', function (w,h,d,nw,nh,nd) return nh+nd-h-d end },
+ { 'whatsit', sid_restore },
+ },
+ },
},
}
end
-- 1st ret val: b の組方向
-- 2nd ret val はその DIR whatsit
function get_box_dir(b, default)
- start_time_measure('get_box_dir')
+ start_time_measure 'get_box_dir'
local dir = has_attr(b, attr_dir) or 0
local bh = getfield(b,'head')
-- b は insert node となりうるので getlist() は使えない
if bh~=0 then -- bh != nil
for bh in traverse_id(id_whatsit, bh) do
if getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then
- c = bh
- dir = (dir==0) and has_attr(bh, attr_dir) or dir
+ c = bh; dir = (dir==0) and has_attr(bh, attr_dir) or dir
end
end
end
- -- for i=1,2 do
- -- if bh and getid(bh)==id_whatsit
- -- and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then
- -- c = bh
- -- dir = (dir==0) and has_attr(bh, attr_dir) or dir
- -- end
- -- bh = node_next(bh)
- -- end
- stop_time_measure('get_box_dir')
+ stop_time_measure 'get_box_dir'
return (dir==0 and default or dir), c
end
local getbox = tex.getbox
local dir_backup
function luatexja.direction.unbox_check_dir(is_copy)
- start_time_measure('box_primitive_hook')
+ start_time_measure 'box_primitive_hook'
local list_dir = get_dir_count()%dir_math_mod
- local b = getbox(tex_getcount('ltj@tempcnta'))
+ local b = getbox(tex_getcount 'ltj@tempcnta')
if b and getlist(to_direct(b)) then
- local box_dir = get_box_dir(to_direct(b), dir_yoko)
- if box_dir%dir_math_mod ~= list_dir then
- ltjb.package_error(
- 'luatexja',
- "Incompatible direction list can't be unboxed",
- 'I refuse to unbox a box in differrent direction.')
+ local box_dir = get_box_dir(to_direct(b), dir_yoko)
+ if box_dir%dir_math_mod ~= list_dir then
+ ltjb.package_error(
+ 'luatexja',
+ "Incompatible direction list can't be unboxed",
+ 'I refuse to unbox a box in differrent direction.')
tex.sprint(cat_lp, '\\@gobbletwo')
- else
- dir_backup = nil
- local bd = to_direct(b)
- local hd = getlist(bd)
- local nh = hd
- while hd do
- if getid(hd)==id_whatsit and getsubtype(hd)==sid_user
- and getfield(hd, 'user_id')==DIR then
- local d = hd
- nh, hd = node_remove(nh, hd)
- if is_copy and (not dir_backup) then
- dir_backup = d
- setfield(dir_backup, 'next', nil)
- else
- node_free(d)
- end
- else
- hd = node_next(hd)
- end
- end
- setfield(bd, 'head', nh)
- end
+ else
+ dir_backup = nil
+ local bd = to_direct(b)
+ local hd = getlist(bd)
+ local nh = hd
+ while hd do
+ if getid(hd)==id_whatsit and getsubtype(hd)==sid_user
+ and getfield(hd, 'user_id')==DIR then
+ local d = hd
+ nh, hd = node_remove(nh, hd)
+ if is_copy and (not dir_backup) then
+ dir_backup = d; setfield(dir_backup, 'next', nil)
+ else
+ node_free(d)
+ end
+ else
+ hd = node_next(hd)
+ end
+ end
+ setfield(bd, 'head', nh)
+ end
end
if luatexja.global_temp and tex.globaldefs~=luatexja.global_temp then
- tex.globaldefs = luatexja.global_temp
+ tex.globaldefs = luatexja.global_temp
end
- stop_time_measure('box_primitive_hook')
+ stop_time_measure 'box_primitive_hook'
end
function luatexja.direction.uncopy_restore_whatsit()
- local b = getbox(tex_getcount('ltj@tempcnta'))
+ local b = getbox(tex_getcount 'ltj@tempcnta')
if b then
- local bd = to_direct(b)
- if dir_backup then
- setfield(dir_backup, 'next', getlist(bd))
- setfield(bd, 'head', dir_backup)
- dir_backup = nil
- end
+ local bd = to_direct(b)
+ if dir_backup then
+ setfield(dir_backup, 'next', getlist(bd))
+ setfield(bd, 'head', dir_backup)
+ dir_backup = nil
+ end
end
end
end
local d = getfield(b, 'depth')
local db = node_new(getid(b)) -- dir_node
set_attr(db, attr_dir,
- new_dir + (is_manual and dir_node_manual or dir_node_auto))
+ new_dir + (is_manual and dir_node_manual or dir_node_auto))
set_attr(db, attr_icflag, PROCESSED)
set_attr(b, attr_icflag, PROCESSED)
ensure_tex_attr(attr_dir, 0)
local box_dir, dn = get_box_dir(b, ltjs.list_dir)
-- 既に b の中身にあるwhatsit
if (box_dir<dir_node_auto) and (not dn) then
- bh = create_dir_whatsit(bh, 'make_dir_whatsit', dir_yoko)
- dn = bh; setfield(b, 'head', bh)
+ bh = create_dir_whatsit(bh, 'make_dir_whatsit', dir_yoko)
+ dn = bh; setfield(b, 'head', bh)
end
if box_dir%dir_math_mod==new_dir then
- if box_dir>=dir_node_auto then
- -- dir_node としてカプセル化されている
- local _, dnc = get_box_dir(b, 0)
- if dnc then -- free all other dir_node
- node.direct.flush_list(getfield(dnc, 'value'))
- setfield(dnc, 'value', nil)
- end
- set_attr(b, attr_dir, box_dir%dir_math_mod + dir_node_auto)
- return head, node_next(b), b, true
- else
- -- 組方向が一緒 (up to math dir) のボックスなので,何もしなくて良い
- return head, node_next(b), b, false
- end
+ if box_dir>=dir_node_auto then
+ -- dir_node としてカプセル化されている
+ local _, dnc = get_box_dir(b, 0)
+ if dnc then -- free all other dir_node
+ node.direct.flush_list(getfield(dnc, 'value'))
+ setfield(dnc, 'value', nil)
+ end
+ set_attr(b, attr_dir, box_dir%dir_math_mod + dir_node_auto)
+ return head, node_next(b), b, true
+ else
+ -- 組方向が一緒 (up to math dir) のボックスなので,何もしなくて良い
+ return head, node_next(b), b, false
+ end
else
- -- 組方向を合わせる必要あり
+ -- 組方向を合わせる必要あり
local nh, nb, ret, flag
- if box_dir>= dir_node_auto then -- unwrap
- local b_dir
+ if box_dir>= dir_node_auto then -- unwrap
+ local b_dir
head, nb, b, b_dir = unwrap_dir_node(b, head, box_dir)
- bh = getlist(b)
- if b_dir%dir_math_mod==new_dir then
- -- dir_node の中身が周囲の組方向とあっている
- return head, nb, b, false
- else box_dir = b_dir end
- end
- box_dir = box_dir%dir_math_mod
- local db
- local dnh = getfield(dn, 'value')
- for x in traverse(dnh) do
- if has_attr(x, attr_dir)%dir_math_mod == new_dir then
- setfield(dn, 'value', to_node(node_remove(dnh, x)))
- db=x; break
- end
- end
- node.direct.flush_list(getfield(dn, 'value'))
- setfield(dn, 'value', nil)
- db = db or create_dir_node(b, box_dir, new_dir, false)
- local w = getfield(b, 'width')
- local h = getfield(b, 'height')
- local d = getfield(b, 'depth')
- local dn_w = getfield(db, 'width')
- local dn_h = getfield(db, 'height')
- local dn_d = getfield(db, 'depth')
- nh, nb = insert_before(head, b, db), nil
- nh, nb = node_remove(nh, b)
+ bh = getlist(b)
+ if b_dir%dir_math_mod==new_dir then
+ -- dir_node の中身が周囲の組方向とあっている
+ return head, nb, b, false
+ else box_dir = b_dir end
+ end
+ box_dir = box_dir%dir_math_mod
+ local db
+ local dnh = getfield(dn, 'value')
+ for x in traverse(dnh) do
+ if has_attr(x, attr_dir)%dir_math_mod == new_dir then
+ setfield(dn, 'value', to_node(node_remove(dnh, x)))
+ db=x; break
+ end
+ end
+ node.direct.flush_list(getfield(dn, 'value'))
+ setfield(dn, 'value', nil)
+ db = db or create_dir_node(b, box_dir, new_dir, false)
+ local w = getfield(b, 'width')
+ local h = getfield(b, 'height')
+ local d = getfield(b, 'depth')
+ local dn_w = getfield(db, 'width')
+ local dn_h = getfield(db, 'height')
+ local dn_d = getfield(db, 'depth')
+ nh, nb = insert_before(head, b, db), nil
+ nh, nb = node_remove(nh, b)
setfield(b, 'next', nil); setfield(db, 'head', b)
ret, flag = db, true
- return nh, nb, ret, flag
+ return nh, nb, ret, flag
end
end
process_dir_node = function (hd, gc)
local x, new_dir = hd, ltjs.list_dir or dir_yoko
while x do
- local xid = getid(x)
- if (xid==id_hlist and get_attr_icflag(x)~=PACKED)
- or xid==id_vlist then
- hd, x = make_dir_whatsit(hd, x, new_dir, 'process_dir_node:' .. gc)
- else
- x = node_next(x)
- end
+ local xid = getid(x)
+ if (xid==id_hlist and get_attr_icflag(x)~=PACKED)
+ or xid==id_vlist then
+ hd, x = make_dir_whatsit(hd, x, new_dir, 'process_dir_node:' .. gc)
+ else
+ x = node_next(x)
+ end
end
return hd
end
-- lastbox
local node_prev = (node.direct~=node) and node.direct.getprev or node.prev
- local id_glue = node.id('glue')
+ local id_glue = node.id 'glue'
local function lastbox_hook()
- start_time_measure('box_primitive_hook')
+ start_time_measure 'box_primitive_hook'
local bn = tex_nest[tex_nest.ptr].tail
if bn then
- local b, head = to_direct(bn), to_direct(tex_nest[tex_nest.ptr].head)
- local bid = getid(b)
- if bid==id_hlist or bid==id_vlist then
+ local b, head = to_direct(bn), to_direct(tex_nest[tex_nest.ptr].head)
+ local bid = getid(b)
+ if bid==id_hlist or bid==id_vlist then
local p = getlist(b)
- -- alignment の各行の中身が入ったボックス
+ -- alignment の各行の中身が入ったボックス
if p and getid(p)==id_glue and getsubtype(p)==12 then -- tabskip
- local np = node_next(p); local npid = getid(np)
- if npid==id_hlist or npid==id_vlist then
- setfield(b, 'head', create_dir_whatsit(p, 'align', get_box_dir(np, 0)))
- end
+ local np = node_next(p); local npid = getid(np)
+ if npid==id_hlist or npid==id_vlist then
+ setfield(b, 'head', create_dir_whatsit(p, 'align', get_box_dir(np, 0)))
+ end
+ end
+ local box_dir = get_box_dir(b, 0)
+ if box_dir>= dir_node_auto then -- unwrap dir_node
+ local p = node_prev(b)
+ local dummy1, dummy2, nb = unwrap_dir_node(b, nil, box_dir)
+ setfield(p, 'next', nb); tex_nest[tex_nest.ptr].tail = to_node(nb)
+ setfield(b, 'next', nil); setfield(b, 'head', nil)
+ node_free(b); b = nb
end
- local box_dir = get_box_dir(b, 0)
- if box_dir>= dir_node_auto then -- unwrap dir_node
- local p = node_prev(b)
- local dummy1, dummy2, nb = unwrap_dir_node(b, nil, box_dir)
- setfield(p, 'next', nb); tex_nest[tex_nest.ptr].tail = to_node(nb)
- setfield(b, 'next', nil); setfield(b, 'head', nil)
- node_free(b); b = nb
- end
- local _, wh = get_box_dir(b, 0) -- clean dir_node attached to the box
- if wh then
- node.direct.flush_list(getfield('value', wh))
- setfield(wh, 'value', nil)
- end
- end
+ local _, wh = get_box_dir(b, 0) -- clean dir_node attached to the box
+ if wh then
+ node.direct.flush_list(getfield('value', wh))
+ setfield(wh, 'value', nil)
+ end
+ end
end
- stop_time_measure('box_primitive_hook')
+ stop_time_measure 'box_primitive_hook'
end
luatexja.direction.make_dir_whatsit = make_dir_whatsit
setfield(wh, 'value',to_node(db))
end
setfield(db, key, scan_dimen())
- return false
+ return false
else
setfield(s, key, scan_dimen())
- if wh then
- -- change dimension of dir_nodes which are created "automatically"
- local bw, bh, bd
- = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
- for x in traverse(getfield(wh, 'value')) do
- local x_dir = has_attr(x, attr_dir)
- if x_dir<dir_node_manual then
- local info = dir_node_aux[s_dir][x_dir%dir_node_auto]
- setfield(x, 'width', info.width(bw,bh,bd))
- setfield(x, 'height', info.height(bw,bh,bd))
- setfield(x, 'depth', info.depth(bw,bh,bd))
- end
- end
- end
- return true
+ if wh then
+ -- change dimension of dir_nodes which are created "automatically"
+ local bw, bh, bd
+ = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
+ for x in traverse(getfield(wh, 'value')) do
+ local x_dir = has_attr(x, attr_dir)
+ if x_dir<dir_node_manual then
+ local info = dir_node_aux[s_dir][x_dir%dir_node_auto]
+ setfield(x, 'width', info.width(bw,bh,bd))
+ setfield(x, 'height', info.height(bw,bh,bd))
+ setfield(x, 'depth', info.depth(bw,bh,bd))
+ end
+ end
+ end
+ return true
end
end
local function set_box_dim(key)
local s = getbox(scan_int()); scan_keyword('=')
if s then
- local l_dir = (get_dir_count())%dir_math_mod
- s = to_direct(s)
+ local l_dir = (get_dir_count())%dir_math_mod
+ s = to_direct(s)
local b_dir = get_box_dir(s,dir_yoko)
if b_dir<dir_node_auto then
set_box_dim_common(key, s, l_dir)
- elseif b_dir%dir_math_mod == l_dir then
- -- s is dir_node
- setfield(s, key, scan_dimen())
- if b_dir<dir_node_manual then
- set_attr(s, attr_dir, b_dir%dir_node_auto + dir_node_manual)
- end
+ elseif b_dir%dir_math_mod == l_dir then
+ -- s is dir_node
+ setfield(s, key, scan_dimen())
+ if b_dir<dir_node_manual then
+ set_attr(s, attr_dir, b_dir%dir_node_auto + dir_node_manual)
+ end
else
- local sid, b = getid(s), getlist(s)
- local info = dir_node_aux[get_box_dir(b,dir_yoko)%dir_math_mod][b_dir%dir_node_auto]
- local bw, bh, bd
- = getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth')
- local sw, sh, sd
- = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
- if set_box_dim_common(key, b, l_dir) and b_dir<dir_node_manual then
- -- re-calculate dimension of s, if s is created "automatically"
- if b_dir<dir_node_manual then
- setfield(s, 'width', info.width(bw,bh,bd))
- setfield(s, 'height', info.height(bw,bh,bd))
- setfield(s, 'depth', info.depth(bw,bh,bd))
- end
- end
+ local sid, b = getid(s), getlist(s)
+ local info = dir_node_aux[get_box_dir(b,dir_yoko)%dir_math_mod][b_dir%dir_node_auto]
+ local bw, bh, bd
+ = getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth')
+ local sw, sh, sd
+ = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
+ if set_box_dim_common(key, b, l_dir) and b_dir<dir_node_manual then
+ -- re-calculate dimension of s, if s is created "automatically"
+ if b_dir<dir_node_manual then
+ setfield(s, 'width', info.width(bw,bh,bd))
+ setfield(s, 'height', info.height(bw,bh,bd))
+ setfield(s, 'depth', info.depth(bw,bh,bd))
+ end
+ end
end
end
end
s = to_direct(s)
local b_dir = get_box_dir(s, dir_yoko)
if b_dir<dir_node_auto then
- return b_dir
+ return b_dir
else
- local b_dir = get_box_dir(
- node_next(node_next(node_next(getlist(s)))), dir_yoko)
- return b_dir
+ local b_dir = get_box_dir(
+ node_next(node_next(node_next(getlist(s)))), dir_yoko)
+ return b_dir
end
else
return 0
local getbox, setbox, copy_list = tex.getbox, tex.setbox, node.direct.copy_list
-- raise, lower
function luatexja.direction.raise_box()
- start_time_measure('box_primitive_hook')
+ start_time_measure 'box_primitive_hook'
local list_dir = get_dir_count()
- local s = getbox('ltj@afbox')
+ local s = getbox 'ltj@afbox'
if s then
- local sd = to_direct(s)
- local box_dir = get_box_dir(sd, dir_yoko)
- if box_dir%dir_math_mod ~= list_dir then
- setbox(
- 'ltj@afbox',
- to_node(copy_list(make_dir_whatsit(sd, sd, list_dir, 'box_move')))
- -- copy_list しないとリストの整合性が崩れる……?
- )
- end
+ local sd = to_direct(s)
+ local box_dir = get_box_dir(sd, dir_yoko)
+ if box_dir%dir_math_mod ~= list_dir then
+ setbox(
+ 'ltj@afbox',
+ to_node(copy_list(make_dir_whatsit(sd, sd, list_dir, 'box_move')))
+ -- copy_list しないとリストの整合性が崩れる……?
+ )
+ end
end
- stop_time_measure('box_primitive_hook')
+ stop_time_measure 'box_primitive_hook'
end
end
local function glyph_from_packed(h)
local b = getlist(h)
return (getid(b)==id_kern or (getid(b)==id_whatsit and getsubtype(b)==sid_save) )
- and node_next(node_next(node_next(b))) or b
+ and node_next(node_next(node_next(b))) or b
end
luatexja.direction.glyph_from_packed = glyph_from_packed
end
-- adjust
do
- local id_adjust = node.id('adjust')
+ local id_adjust = node.id 'adjust'
function luatexja.direction.check_adjust_direction()
- start_time_measure('box_primitive_hook')
+ start_time_measure 'box_primitive_hook'
local list_dir = get_adjust_dir_count()
local a = tex_nest[tex_nest.ptr].tail
local ad = to_direct(a)
if a and getid(ad)==id_adjust then
- local adj_dir = get_box_dir(ad)
- if list_dir~=adj_dir then
- ltjb.package_error(
- 'luatexja',
- 'Direction Incompatible',
- "\\vadjust's argument and outer vlist must have same direction.")
- node.direct.last_node()
- end
+ local adj_dir = get_box_dir(ad)
+ if list_dir~=adj_dir then
+ ltjb.package_error(
+ 'luatexja',
+ 'Direction Incompatible',
+ "\\vadjust's argument and outer vlist must have same direction.")
+ node.direct.last_node()
+ end
end
- stop_time_measure('box_primitive_hook')
+ stop_time_measure 'box_primitive_hook'
end
end
-- insert
do
- local id_ins = node.id('ins')
- local id_rule = node.id('rule')
+ local id_ins = node.id 'ins'
+ local id_rule = node.id 'rule'
function luatexja.direction.populate_insertion_dir_whatsit()
- start_time_measure('box_primitive_hook')
+ start_time_measure 'box_primitive_hook'
local list_dir = get_dir_count()
local a = tex_nest[tex_nest.ptr].tail
local ad = to_direct(a)
if (not a) or getid(ad)~=id_ins then
- a = node.tail(tex.lists.page_head); ad = to_direct(a)
+ a = node.tail(tex.lists.page_head); ad = to_direct(a)
end
if a and getid(ad)==id_ins then
- local h = getfield(ad, 'head')
- if getid(h)==id_whatsit and
- getsubtype(h)==sid_user and getfield(h, 'user_id')==DIR then
- local n = h; h = node_remove(h,h)
- node_free(n)
- end
- for box_rule in traverse(h) do
- if getid(box_rule)<id_rule then
- h = insert_before(h, box_rule, dir_pool[list_dir]())
- end
- end
- ensure_tex_attr(attr_dir, 0)
- setfield(ad, 'head', h)
+ local h = getfield(ad, 'head')
+ if getid(h)==id_whatsit and
+ getsubtype(h)==sid_user and getfield(h, 'user_id')==DIR then
+ local n = h; h = node_remove(h,h)
+ node_free(n)
+ end
+ for box_rule in traverse(h) do
+ if getid(box_rule)<id_rule then
+ h = insert_before(h, box_rule, dir_pool[list_dir]())
+ end
+ end
+ ensure_tex_attr(attr_dir, 0)
+ setfield(ad, 'head', h)
end
- stop_time_measure('box_primitive_hook')
+ stop_time_measure 'box_primitive_hook'
end
end
local p = to_direct(tex_getbox(n))
split_dir_head = nil
if p then
- local bh = getlist(p)
- if getid(bh)==id_whatsit and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR
- and node_next(bh) then
- ltjs.list_dir = has_attr(bh, attr_dir)
- local q = node_next(p)
- setfield(p, 'head', node_remove(bh,bh,bh))
- split_dir_head = bh
- end
+ local bh = getlist(p)
+ if getid(bh)==id_whatsit and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR
+ and node_next(bh) then
+ ltjs.list_dir = has_attr(bh, attr_dir)
+ local q = node_next(p)
+ setfield(p, 'head', node_remove(bh,bh,bh))
+ split_dir_head = bh
+ end
end
sprint(cat_lp, '\\ltj@@orig@vsplit' .. tostring(n))
- end
+ end
local function dir_adjust_vpack(h, gc)
- start_time_measure('direction_vpack')
+ start_time_measure 'direction_vpack'
local hd = to_direct(h)
if gc=='split_keep' then
- -- supply dir_whatsit
- hd = create_dir_whatsit_vbox(hd, gc)
- split_dir_whatsit = hd
+ -- supply dir_whatsit
+ hd = create_dir_whatsit_vbox(hd, gc)
+ split_dir_whatsit = hd
elseif gc=='split_off' then
- if split_dir_head then
- ltjs.list_dir = has_attr(split_dir_head, attr_dir)
- hd = insert_before(hd, hd, split_dir_head)
- split_dir_head=nil
- end
- if split_dir_whatsit then
- -- adjust direction of 'split_keep'
- set_attr(split_dir_whatsit, attr_dir, ltjs.list_dir)
- end
- split_dir_whatsit=nil
+ if split_dir_head then
+ ltjs.list_dir = has_attr(split_dir_head, attr_dir)
+ hd = insert_before(hd, hd, split_dir_head)
+ split_dir_head=nil
+ end
+ if split_dir_whatsit then
+ -- adjust direction of 'split_keep'
+ set_attr(split_dir_whatsit, attr_dir, ltjs.list_dir)
+ end
+ split_dir_whatsit=nil
elseif gc=='preamble' then
- split_dir_whatsit=nil
+ split_dir_whatsit=nil
else
- adjust_badness(hd)
- -- hd = process_dir_node(create_dir_whatsit_vbox(hd, gc), gc)
- -- done in append_to_vpack callback
- hd = create_dir_whatsit_vbox(hd, gc)
- split_dir_whatsit=nil
+ adjust_badness(hd)
+ -- hd = process_dir_node(create_dir_whatsit_vbox(hd, gc), gc)
+ -- done in append_to_vpack callback
+ hd = create_dir_whatsit_vbox(hd, gc)
+ split_dir_whatsit=nil
end
- stop_time_measure('direction_vpack')
+ stop_time_measure 'direction_vpack'
return to_node(hd)
end
ltjb.add_to_callback('vpack_filter',
- dir_adjust_vpack,
- 'ltj.direction', 10000)
+ dir_adjust_vpack,
+ 'ltj.direction', 10000)
end
do
return to_node(create_dir_whatsit_vbox(to_direct(h), gc))
end
ltjb.add_to_callback('pre_output_filter',
- dir_adjust_pre_output,
- 'ltj.direction', 10000)
+ dir_adjust_pre_output,
+ 'ltj.direction', 10000)
function luatexja.direction.remove_end_whatsit()
local h=tex.lists.page_head
if h and (not h.next) and
- h.id==id_whatsit and h.subtype==sid_user and
+ h.id==id_whatsit and h.subtype==sid_user and
h.user_id == DIR then
- tex.lists.page_head = nil
- node.free(h)
+ tex.lists.page_head = nil
+ node.free(h)
end
end
end
if getid(b)==id_whatsit and getsubtype(b)==sid_user
and getfield(b, 'user_id')==DIR then
local ob = b; b = node_remove(b,b); setfield(db, 'head', b);
- node_free(ob)
+ node_free(ob)
end
finalize_inner(b)
local w = getfield(b, 'width')
db_tail = nn
else
setfield(db, 'head', nn)
- db_head, db_tail = nn, nn
+ db_head, db_tail = nn, nn
end
end
end
else
finalize_inner(n)
end
- end
+ end
end
end
local getbox = tex.getbox
finalize_inner(shipout_temp)
setbox('global', "AtBeginShipoutBox", copy(getlist(shipout_temp)))
setfield(shipout_temp, 'head',nil)
- -- garbage collect
- --local m = collectgarbage('count')
- --if m>lua_mem_kb+20480 then
- -- collectgarbage(); lua_mem_kb = collectgarbage('count')
- --end
- --print('Lua Memory Usage', lua_mem_kb)
end
end
-- ltj-inputbuf.lua
--
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('charrange'); local ltjc = luatexja.charrange
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
-require("unicode")
+require "unicode"
local utflen = utf.len
local utfbyte = utf.byte
local utfchar = utf.char
local node_new = node.new
local node_free = node.free
-local id_glyph = node.id('glyph')
+local id_glyph = node.id 'glyph'
local getcatcode, getcount = tex.getcatcode, tex.getcount
local ltjc_is_japanese_char_curlist = ltjc.is_japanese_char_curlist
local start_time_measure, stop_time_measure
= ltjb.start_time_measure, ltjb.stop_time_measure
local function add_comment(buffer)
- start_time_measure('inputbuf')
+ start_time_measure 'inputbuf'
local i = utflen(buffer)
while (i>0) and (getcatcode(utfbyte(buffer, i))==1
- or getcatcode(utfbyte(buffer, i))==2) do
+ or getcatcode(utfbyte(buffer, i))==2) do
i=i-1
end
if i>0 then
local c = utfbyte(buffer, i)
if c>=0x80 then
- local te = tex.endlinechar
- -- Is the catcode of endline character is 5 (end-of-line)?
- if (te ~= -1) and (getcatcode(te)==5) then
- local ct = getcatcode(c)
- if (ct==11) or (ct==12) then
- local lec = getcount('ltjlineendcomment')
+ local te = tex.endlinechar
+ -- Is the catcode of endline character is 5 (end-of-line)?
+ if (te ~= -1) and (getcatcode(te)==5) then
+ local ct = getcatcode(c)
+ if (ct==11) or (ct==12) then
+ local lec = getcount 'ltjlineendcomment'
-- Is the catcode of \ltjlineendcomment (new comment char) is 14 (comment)?
- if ltjc_is_japanese_char_curlist(c) and (getcatcode(lec)==14) then
- stop_time_measure('inputbuf')
- return buffer .. utfchar(lec)
+ if ltjc_is_japanese_char_curlist(c) and (getcatcode(lec)==14) then
+ stop_time_measure 'inputbuf'; return buffer .. utfchar(lec)
end
- end
+ end
end
end
end
- stop_time_measure('inputbuf')
+ stop_time_measure 'inputbuf'
return buffer
end
--
luatexbase.provides_module({
name = 'luatexja.jfmglue',
- date = '2020/01/23',
+ date = '2020-07-30',
description = 'Insertion process of JFM glues, [x]kanjiskip and others',
})
luatexja.jfmglue = luatexja.jfmglue or {}
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('stack'); local ltjs = luatexja.stack
-luatexja.load_module('jfont'); local ltjf = luatexja.jfont
-luatexja.load_module('direction'); local ltjd = luatexja.direction
-luatexja.load_module('setwidth'); local ltjw = luatexja.setwidth
-luatexja.load_module('lotf_aux'); local ltju = luatexja.lotf_aux
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
+luatexja.load_module 'jfont'; local ltjf = luatexja.jfont
+luatexja.load_module 'direction'; local ltjd = luatexja.direction
+luatexja.load_module 'setwidth'; local ltjw = luatexja.setwidth
+luatexja.load_module 'lotf_aux'; local ltju = luatexja.lotf_aux
local pairs = pairs
--local to_node = node.direct.tonode
local node_free = node.direct.free
local node_remove = node.direct.remove
-local id_glyph = node.id('glyph')
-local id_hlist = node.id('hlist')
-local id_vlist = node.id('vlist')
-local id_rule = node.id('rule')
-local id_ins = node.id('ins')
-local id_mark = node.id('mark')
-local id_adjust = node.id('adjust')
-local id_disc = node.id('disc')
-local id_whatsit = node.id('whatsit')
-local id_math = node.id('math')
-local id_glue = node.id('glue')
-local id_kern = node.id('kern')
-local id_penalty = node.id('penalty')
+local id_glyph = node.id 'glyph'
+local id_hlist = node.id 'hlist'
+local id_vlist = node.id 'vlist'
+local id_rule = node.id 'rule'
+local id_ins = node.id 'ins'
+local id_mark = node.id 'mark'
+local id_adjust = node.id 'adjust'
+local id_disc = node.id 'disc'
+local id_whatsit = node.id 'whatsit'
+local id_math = node.id 'math'
+local id_glue = node.id 'glue'
+local id_kern = node.id 'kern'
+local id_penalty = node.id 'penalty'
local id_jglyph = 512 -- Japanese character
local id_box_like = 256 -- vbox, shifted hbox
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 sid_user = node.subtype 'user_defined'
local ITALIC = luatexja.icflag_table.ITALIC
local PACKED = luatexja.icflag_table.PACKED
slow_find_char_class = function (c, m, oc)
local cls = ltjf_find_char_class(oc, m)
if oc~=c and c and cls==0 then
- return ltjf_find_char_class(c, m)
+ return ltjf_find_char_class(c, m)
else
- return cls
+ return cls
end
end
end
pp = pp + e
if pp>=10000 then setpenalty(p, 10000)
elseif pp<=-10000 then setpenalty(p, -10000)
- else setpenalty(p, pp) end
+ else setpenalty(p, pp) end
end
end
end
while p and p~=box_end do
local pid = getid(p)
if pid==id_kern and getsubtype(p)==2 then
- p = node_next(node_next(node_next(p))); pid = getid(p) -- p must be glyph_node
+ p = node_next(node_next(node_next(p))); pid = getid(p) -- p must be glyph_node
end
if pid==id_glyph then
- repeat
- if find_first_char then
- first_char = p; find_first_char = false
- end
- last_char = p; found_visible_node = true; p=node_next(p)
- if (not p) or p==box_end then
- return found_visible_node
- end
- until getid(p)~=id_glyph
- pid = getid(p) -- p must be non-nil
+ repeat
+ if find_first_char then first_char = p; find_first_char = false end
+ last_char = p; found_visible_node = true; p=node_next(p)
+ if (not p) or p==box_end then return found_visible_node end
+ until getid(p)~=id_glyph
+ pid = getid(p) -- p must be non-nil
end
if pid==id_kern then
- local pa = get_attr_icflag(p)
- if pa==IC_PROCESSED then
- -- do nothing
- elseif getsubtype(p)==2 then
- p = node_next(node_next(p));
- -- Note that another node_next will be executed outside this if-statement.
- else
- found_visible_node = true
- find_first_char = false; last_char = nil
- end
+ local pa = get_attr_icflag(p)
+ if pa==IC_PROCESSED then
+ -- do nothing
+ elseif getsubtype(p)==2 then
+ p = node_next(node_next(p));
+ -- Note that another node_next will be executed outside this if-statement.
+ else
+ found_visible_node = true
+ find_first_char = false; last_char = nil
+ end
elseif pid==id_hlist then
- if PACKED == get_attr_icflag(p) then
- local s = ltjd_glyph_from_packed(p)
- if find_first_char then
- first_char = s; find_first_char = false
- end
- last_char = s; found_visible_node = true
- else
- if getfield(p, 'shift')==0 then
- last_char = nil
- if check_box(getlist(p), nil) then found_visible_node = true end
- find_first_char = false
- else
- find_first_char = false; last_char = nil
- end
- end
+ if PACKED == get_attr_icflag(p) then
+ local s = ltjd_glyph_from_packed(p)
+ if find_first_char then first_char = s; find_first_char = false end
+ last_char = s; found_visible_node = true
+ else
+ if getfield(p, 'shift')==0 then
+ last_char = nil
+ if check_box(getlist(p), nil) then found_visible_node = true end
+ find_first_char = false
+ else
+ find_first_char = false; last_char = nil
+ 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
+ if find_first_char then 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
- -- do nothing
+ -- do nothing
elseif not (pid==id_ins or pid==id_mark
- or pid==id_adjust or pid==id_whatsit
- or pid==id_penalty) then
- found_visible_node = true
- find_first_char = false; last_char = nil
+ or pid==id_adjust or pid==id_whatsit
+ or pid==id_penalty) then
+ found_visible_node = true
+ find_first_char = false; last_char = nil
end
p = node_next(p)
end
local first_char = first_char
if first_char then
if getid(first_char)==id_glyph 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)
- end
- else -- math_node
- set_np_xspc_alchar(Nx, -1,first_char)
+ 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)
+ end
+ else -- math_node
+ set_np_xspc_alchar(Nx, -1,first_char)
end
end
end
-------------------- Np の計算と情報取得
luatexbase.create_callback("luatexja.jfmglue.whatsit_getinfo", "data",
- function (Np, lp, Nq)
- if Np.nuc then return Np
- else
- return Np -- your code
- end
- end)
+ function (Np, lp, Nq)
+ if Np.nuc then return Np
+ else
+ return Np -- your code
+ end
+ end)
luatexbase.create_callback("luatexja.jfmglue.whatsit_after", "data",
- function (stat, Nq, Np) return false end)
+ function (stat, Nq, Np) return false end)
-- calc next Np
local calc_np
local lpi = getid(lp)
if lpa==PACKED then
if lpi==id_rule then lp = node_next(lp) end
- nc, lp = lp, node_next(lp)
+ 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
+ head, lp, nc = ltjd_make_dir_whatsit(head, lp, list_dir, 'jfm pbox')
+ Np.first = first and nc or Np.first
else
- nc, lp = lp, node_next(lp)
+ nc, lp = lp, node_next(lp)
end
first, lpa = false, (lp and has_attr(lp, attr_icflag) or 0)
-- get_attr_icflag() ではいけない!
local font_getfont = font.getfont
local function calc_np_notdef(lp)
if not font_getfont(getfont(lp)).characters[getchar(lp)] then
- local ln = node_next(lp)
- if ltju.specified_feature(getfont(lp), '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
+ local ln = node_next(lp)
+ if ltju.specified_feature(getfont(lp), '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
setfield(lp, 'yoffset', getfield(lp, 'yoffset') - y_adjust)
lp = node_next(lp)
for lx in traverse(lp) do
- local lai = get_attr_icflag(lx)
- if lx==last or lai>=PACKED then
- lp=lx; break
- else
- local lid = getid(lx)
- 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
- node_depth = max(getfield(lx, 'depth') + min(y_adjust, 0), node_depth)
- adj_depth = (y_adjust>0) and max(getfield(lx, 'depth') + y_adjust, adj_depth) or adj_depth
- setfield(lx, 'yoffset', getfield(lx, 'yoffset') - y_adjust)
- elseif lid==id_kern then
- local ls = getsubtype(lx)
- if ls==2 then -- アクセント用の kern
- set_attr(lx, attr_icflag, PROCESSED)
- lx = node_next(lx) -- lx: アクセント本体
- if getid(lx)==id_glyph then
- setfield(lx, 'yoffset', getfield(lx, 'yoffset') - (has_attr(lx,attr_ablshift) or 0))
- else -- アクセントは上下にシフトされている
- setfield(lx, 'shift', getfield(lx, 'shift') + (has_attr(lx,attr_ablshift) or 0))
- end
- lx = node_next(node_next(lx))
- elseif ls==0 then
- Np.last = lx
- elseif (ls==3) or (lai==ITALIC) then
- Np.last = lx; set_attr(lx, attr_icflag, IC_PROCESSED)
- else
- lp=lx; break
- end
- else
- lp=lx; break
- end
- end
+ local lai = get_attr_icflag(lx)
+ if lx==last or lai>=PACKED then
+ lp=lx; break
+ else
+ local lid = getid(lx)
+ 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
+ node_depth = max(getfield(lx, 'depth') + min(y_adjust, 0), node_depth)
+ adj_depth = (y_adjust>0) and max(getfield(lx, 'depth') + y_adjust, adj_depth) or adj_depth
+ setfield(lx, 'yoffset', getfield(lx, 'yoffset') - y_adjust)
+ elseif lid==id_kern then
+ local ls = getsubtype(lx)
+ if ls==2 then -- アクセント用の kern
+ set_attr(lx, attr_icflag, PROCESSED)
+ lx = node_next(lx) -- lx: アクセント本体
+ if getid(lx)==id_glyph then
+ setfield(lx, 'yoffset', getfield(lx, 'yoffset') - (has_attr(lx,attr_ablshift) or 0))
+ else -- アクセントは上下にシフトされている
+ setfield(lx, 'shift', getfield(lx, 'shift') + (has_attr(lx,attr_ablshift) or 0))
+ end
+ lx = node_next(node_next(lx))
+ elseif ls==0 then
+ Np.last = lx
+ elseif (ls==3) or (lai==ITALIC) then
+ Np.last = lx; set_attr(lx, attr_icflag, IC_PROCESSED)
+ else
+ lp=lx; break
+ end
+ else
+ lp=lx; break
+ end
+ end
end
local r
if adj_depth>node_depth then
- r = node_new(id_rule,3)
- setfield(r, 'width', 0); setfield(r, 'height', 0)
- setfield(r, 'depth',adj_depth); setfield(r, 'dir', tex_dir)
- set_attr(r, attr_icflag, PROCESSED)
+ r = node_new(id_rule,3)
+ setfield(r, 'width', 0); setfield(r, 'height', 0)
+ setfield(r, 'depth',adj_depth); setfield(r, 'dir', tex_dir)
+ set_attr(r, attr_icflag, PROCESSED)
end
if last_glyph then
- Np.last_char = last_glyph
- if r then insert_after(head, first_glyph, r) end
+ Np.last_char = last_glyph
+ if r then insert_after(head, first_glyph, r) end
else
- local npn = Np.nuc
- Np.last_char = npn
- if r then
- local nf, nc = getfont(npn), getchar(npn)
- local ct = (font.getfont(nf) or font.fonts[nf] ).characters[nc]
- if not ct then -- variation selector
- node_free(r)
- elseif (ct.left_protruding or 0) == 0 then
- head = insert_before(head, npn, r)
- Np.first = acc_flag and Np.first or ((Np.first==npn) and r or npn)
- elseif (ct.right_protruding or 0) == 0 then
- insert_after(head, npn, r); Np.last, lp = r, r
- else
- ltjb.package_warning_no_line(
- 'luatexja',
- 'Check depth of glyph node ' .. tostring(npn) .. '(font=' .. nf
- .. ', char=' .. nc .. '), because its \\lpcode is ' .. tostring(ct.left_protruding)
- .. ' and its \\rpcode is ' .. tostring(ct.right_protruding)
- ); node_free(r)
- end
- end
+ local npn = Np.nuc
+ Np.last_char = npn
+ if r then
+ local nf, nc = getfont(npn), getchar(npn)
+ local ct = (font.getfont(nf) or font.fonts[nf] ).characters[nc]
+ if not ct then -- variation selector
+ node_free(r)
+ elseif (ct.left_protruding or 0) == 0 then
+ head = insert_before(head, npn, r)
+ Np.first = acc_flag and Np.first or ((Np.first==npn) and r or npn)
+ elseif (ct.right_protruding or 0) == 0 then
+ insert_after(head, npn, r); Np.last, lp = r, r
+ else
+ ltjb.package_warning_no_line(
+ 'luatexja',
+ 'Check depth of glyph node ' .. tostring(npn) .. '(font=' .. nf
+ .. ', char=' .. nc .. '), because its \\lpcode is ' .. tostring(ct.left_protruding)
+ .. ' and its \\rpcode is ' .. tostring(ct.right_protruding)
+ ); node_free(r)
+ end
+ end
end
return true, lp
end
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')
-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 sid_start_link = node.subtype 'pdf_start_link'
+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'
calc_np_auxtable = {
[id_glyph] = calc_np_aux_glyph_common,
[id_hlist] = function(lp)
set_attr(op, attr_icflag, PROCESSED)
Np.first = Np.first or op; Np.last = op; Np.nuc = op;
if (flag or getfield(op, 'shift')~=0) then
- Np.id = id_box_like
+ Np.id = id_box_like
else
- Np.id = id_hlist
- Np.last_char = check_box_high(Np, getlist(op), nil)
+ Np.id = id_hlist
+ Np.last_char = check_box_high(Np, getlist(op), nil)
end
return true, lp
end,
[id_whatsit] = function(lp)
local lps = getsubtype(lp)
if lps==sid_user then
- if getfield(lp, 'user_id')==luatexja.userid_table.IHB then
- local lq = node_next(lp);
- head = node_remove(head, lp); node_free(lp); non_ihb_flag = false
- return false, lq;
- elseif getfield(lp, 'user_id')==luatexja.userid_table.JA_AL_BDD then
- local lq = node_next(lp);
- head = node_remove(head, lp); node_free(lp)
- return false, lq;
- else
- set_attr(lp, attr_icflag, PROCESSED)
- luatexbase.call_callback("luatexja.jfmglue.whatsit_getinfo",
- Np, lp, Nq)
- if Np.nuc then
- Np.id = id_pbox_w; Np.first = Np.nuc; Np.last = Np.nuc;
- return true, node_next(lp)
- else
- return false, node_next(lp)
- end
- end
+ if getfield(lp, 'user_id')==luatexja.userid_table.IHB then
+ local lq = node_next(lp);
+ head = node_remove(head, lp); node_free(lp); non_ihb_flag = false
+ return false, lq;
+ elseif getfield(lp, 'user_id')==luatexja.userid_table.JA_AL_BDD then
+ local lq = node_next(lp);
+ head = node_remove(head, lp); node_free(lp)
+ return false, lq;
+ else
+ set_attr(lp, attr_icflag, PROCESSED)
+ luatexbase.call_callback("luatexja.jfmglue.whatsit_getinfo",
+ Np, lp, Nq)
+ if Np.nuc then
+ Np.id = id_pbox_w; Np.first = Np.nuc; Np.last = Np.nuc;
+ return true, node_next(lp)
+ else
+ return false, node_next(lp)
+ end
+ end
else
- -- we do special treatment for these whatsit nodes.
- if lps == sid_start_link or lps == sid_start_thread then
- Np.first = lp
- elseif lps == sid_end_link or lps == sid_end_thread then
- Np.first, Nq.last = nil, lp;
- end
- set_attr(lp, attr_icflag, PROCESSED)
- return false, node_next(lp)
+ -- we do special treatment for these whatsit nodes.
+ if lps == sid_start_link or lps == sid_start_thread then
+ Np.first = lp
+ elseif lps == sid_end_link or lps == sid_end_thread then
+ Np.first, Nq.last = nil, lp;
+ end
+ set_attr(lp, attr_icflag, PROCESSED)
+ return false, node_next(lp)
end
end,
[id_math] = function(lp)
end,
[id_kern] = function(lp)
if getsubtype(lp)==2 then
- Np.first = Np.first or lp
- set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
- if getid(lp)==id_glyph then -- アクセント本体
- setfield(lp, 'yoffset', getfield(lp, 'yoffset') - (has_attr(lp,attr_ablshift) or 0))
- else -- アクセントは上下にシフトされている
- setfield(lp, 'shift', getfield(lp, 'shift') + (has_attr(lp,attr_ablshift) or 0))
- end
- set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
- set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
- set_attr(lp, attr_icflag, PROCESSED);
- return calc_np_aux_glyph_common(lp, true)
+ Np.first = Np.first or lp
+ set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
+ if getid(lp)==id_glyph then -- アクセント本体
+ setfield(lp, 'yoffset', getfield(lp, 'yoffset') - (has_attr(lp,attr_ablshift) or 0))
+ else -- アクセントは上下にシフトされている
+ setfield(lp, 'shift', getfield(lp, 'shift') + (has_attr(lp,attr_ablshift) or 0))
+ end
+ set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
+ set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
+ set_attr(lp, attr_icflag, PROCESSED);
+ return calc_np_aux_glyph_common(lp, true)
else
- Np.first = Np.first or lp
- Np.id = id_kern; set_attr(lp, attr_icflag, PROCESSED)
- Np.last = lp; return true, node_next(lp)
+ Np.first = Np.first or lp
+ Np.id = id_kern; set_attr(lp, attr_icflag, PROCESSED)
+ Np.last = lp; return true, node_next(lp)
end
end,
[id_penalty] = function(lp)
-- unbox 由来ノードの検出
if lpa>=PACKED then
if lpa%PROCESSED_BEGIN_FLAG == BOXBDD then
- local lq = node_next(lp)
+ local lq = node_next(lp)
head = node_remove(head, lp); node_free(lp); lp = lq
else
- return calc_np_pbox(lp, last)
+ return calc_np_pbox(lp, last)
end -- id_pbox
else
- k, lp = (calc_np_auxtable[getid(lp)] or calc_np_aux_skip)(lp)
- if k then return lp end
+ k, lp = (calc_np_auxtable[getid(lp)] or calc_np_aux_skip)(lp)
+ if k then return lp end
end
end
Np=nil
local nullfunc = function(n) return n end
function set_np_xspc_alchar(Nx, c,x, lig)
if c~=-1 then
- local f = (lig ==1) and nullfunc or node_tail
+ 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);
- if getid(x)==id_disc then x, xc, xs = nil, getfield(x,'replace'), 2
- else xc, xs = getcomponents(x), getsubtype(x) end
- end
- 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
+ while xc and xs and xs%4>=2 do
+ 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 = 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
- Nx.pre, Nx.post = 0, 0
+ Nx.pre, Nx.post = 0, 0
end
Nx.met = nil
Nx.xspc = table_current_stack[XSP + c] or 3
Nx.auto_xspc = (has_attr(x, attr_autoxspc)==1)
end
local set_np_xspc_alchar = set_np_xspc_alchar
-
-- change the information for the next loop
-- (will be done if Nx is an alphabetic character or a hlist)
after_hlist = function (Nx)
local s = Nx.last_char
if s then
- if getid(s)==id_glyph then
- if if_lang_ja(s) then
- set_np_xspc_jachar_hbox(Nx, s)
- else
- set_np_xspc_alchar(Nx, getchar(s), s, 2)
- end
- else
- set_np_xspc_alchar(Nx, -1, s)
- end
+ if getid(s)==id_glyph then
+ if if_lang_ja(s) then
+ set_np_xspc_jachar_hbox(Nx, s)
+ else
+ set_np_xspc_alchar(Nx, getchar(s), s, 2)
+ end
+ else
+ set_np_xspc_alchar(Nx, -1, s)
+ end
else
- Nx.pre, Nx.met = nil, nil
+ Nx.pre, Nx.met = nil, nil
end
end
-
after_alchar = function (Nx)
local x = Nx.last_char
return set_np_xspc_alchar(Nx, getchar(x), x, 2)
local a = (pre or 0) + (post or 0)
if #Bp == 0 then
if (a~=0 and not(g and getid(g)==id_kern)) then
- local p = node_new(id_penalty)
- if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
- setfield(p, 'penalty', a)
- head = insert_before(head, Np.first, p)
- Bp[1]=p;
- set_attr(p, attr_icflag, KINSOKU)
+ local p = node_new(id_penalty)
+ if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
+ setfield(p, 'penalty', a); head = insert_before(head, Np.first, p)
+ Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
end
else for _, v in pairs(Bp) do add_penalty(v,a) end
end
local a = (pre or 0) + (post or 0)
if #Bp == 0 then
if not (g and getid(g)==id_glue) or a~=0 then
- local p = node_new(id_penalty)
- if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
- setfield(p, 'penalty', a)
- head = insert_before(head, Np.first, p)
- Bp[1]=p
- set_attr(p, attr_icflag, KINSOKU)
+ local p = node_new(id_penalty)
+ if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
+ setfield(p, 'penalty', a); head = insert_before(head, Np.first, p)
+ Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
end
else for _, v in pairs(Bp) do add_penalty(v,a) end
end
luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp)
if #Bp == 0 then
if g and getid(g)==id_glue then
- local p = node_new(id_penalty)
- setfield(p, 'penalty', 10000); head = insert_before(head, Np.first, p)
- Bp[1]=p
- set_attr(p, attr_icflag, KINSOKU)
+ local p = node_new(id_penalty)
+ setfield(p, 'penalty', 10000); head = insert_before(head, Np.first, p)
+ Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
end
else
local a = (pre or 0) + (post or 0)
local a = table_current_stack[luatexja.stack_table_index.JWP]
if #widow_Bp == 0 then
if a~=0 then
- local p = node_new(id_penalty)
- if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
- setfield(p, 'penalty', a)
- head = insert_before(head, widow_Np.first, p)
- widow_Bp[1]=p;
- set_attr(p, attr_icflag, KINSOKU)
+ local p = node_new(id_penalty)
+ if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end
+ setfield(p, 'penalty', a); head = insert_before(head, widow_Np.first, p)
+ widow_Bp[1]=p; set_attr(p, attr_icflag, KINSOKU)
end
else for _, v in pairs(widow_Bp) do add_penalty(v,a) end
end
local g = mc[bc][ac]
if g then
if g[1] then
- return node_copy(g[1]), g.ratio, false, false, false
+ return node_copy(g[1]), g.ratio, false, false, false
else
- local f = node_new(id_glue)
+ local f = node_new(id_glue)
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
+ setglue(f, g.width, g.stretch, g.shrink)
+ return f, g.ratio, g.kanjiskip_natural, g.kanjiskip_stretch, g.kanjiskip_shrink
end
end
return false, 0
calc_ja_ja_aux = function (gb, ga, db, da)
if luatexja.jfmglue.diffmet_rule ~= math.two_pleft and diffmet_rule ~= math.two_pright
and luatexja.jfmglue.diffmet_rule ~= math.two_paverage then
- db, da = 0, 1
+ db, da = 0, 1
end
if not gb then
- if ga then gb = node_new(id_kern, 1); setfield(gb, 'kern', 0)
- else return nil end
+ if ga then gb = node_new(id_kern, 1); setfield(gb, 'kern', 0)
+ else return nil end
elseif not ga then
- ga = node_new(id_kern, 1); setfield(ga, 'kern', 0)
+ ga = node_new(id_kern, 1); setfield(ga, 'kern', 0)
end
local gbw, gaw, gbst, gast, gbsto, gasto, gbsh, gash, gbsho, gasho
if getid(gb)==id_glue then
gbw, gbst, gbsh, gbsto, gbsho = getglue(gb)
else
- gbw = getfield(gb, 'kern')
+ gbw = getfield(gb, 'kern')
end
if getid(ga)==id_glue then
gaw, gast, gash, gasto, gasho = getglue(ga)
else
- gaw = getfield(ga, 'kern')
+ gaw = getfield(ga, 'kern')
end
if not (gbst or gast) then -- 両方とも kern
- setfield(gb, 'kern', blend_diffmet(gbw, gaw, db, da))
- node_free(ga); return gb
+ setfield(gb, 'kern', blend_diffmet(gbw, gaw, db, da))
+ node_free(ga); return gb
else
local gr = gb
if not gbst then gr = ga; node_free(gb) else node_free(ga) end
gbw = blend_diffmet(gbw or 0, gaw or 0, db, da) -- 結果の自然長
gbst, gbsto = blend_diffmet_inf(gbst, gast, gbsto, gasto, db, da) -- 伸び
gbsh, gbsho = blend_diffmet_inf(-(gbsh or 0), -(gash or 0), gbsho, gasho, db, da) -- -(縮み)
- setglue(gr, gbw, gbst, -gbsh, gbsto, gbsho)
- return gr
+ setglue(gr, gbw, gbst, -gbsh, gbsto, gbsho)
+ return gr
end
end
end
-- ノード kanji_skip のコピーで良い場合は nil が帰る
-- flag = true: JFM グルーに付随する kanjiskip 自然長/伸び/縮み分
if qm.with_kanjiskip and (bn or bp or bh) then
- if kanjiskip_jfm_flag then
- local g = node_new(id_glue);
- local bk = qm.kanjiskip or null_skip_table
- setglue(g, bn and (bn*bk[1]) or 0,
- bp and (bp*bk[2]) or 0,
- bh and (bh*bk[3]) or 0, 0, 0)
- set_attr(g, attr_icflag, KANJI_SKIP_JFM)
- return g
- elseif flag then
- local g = node_new(id_glue)
+ if kanjiskip_jfm_flag then
+ local g = node_new(id_glue);
+ local bk = qm.kanjiskip or null_skip_table
+ setglue(g, bn and (bn*bk[1]) or 0,
+ bp and (bp*bk[2]) or 0,
+ bh and (bh*bk[3]) or 0, 0, 0)
+ set_attr(g, attr_icflag, KANJI_SKIP_JFM)
+ return g
+ elseif flag then
+ local g = node_new(id_glue)
local st = bp and (bp*getfield(kanji_skip, 'stretch')) or 0
local sh = bh and (bh*getfield(kanji_skip, 'shrink')) or 0
- setglue(g,
- bn and (bn*getfield(kanji_skip, 'width')) or 0,
- st, sh,
- (st==0) and 0 or getfield(kanji_skip, 'stretch_order'),
- (sh==0) and 0 or getfield(kanji_skip, 'shrink_order'))
- set_attr(g, attr_icflag, KANJI_SKIP_JFM)
- return g
- end
+ setglue(g,
+ bn and (bn*getfield(kanji_skip, 'width')) or 0,
+ st, sh,
+ (st==0) and 0 or getfield(kanji_skip, 'stretch_order'),
+ (sh==0) and 0 or getfield(kanji_skip, 'shrink_order'))
+ set_attr(g, attr_icflag, KANJI_SKIP_JFM)
+ return g
+ end
end
end
get_kanjiskip = function()
- if Np.auto_kspc==0 or Nq.auto_kspc==0 then
- return nil
+ if Np.auto_kspc==0 or Nq.auto_kspc==0 then return nil
elseif Np.auto_kspc or Nq.auto_kspc then
- local pm, qm = Np.met, Nq.met
- if (pm.char_type==qm.char_type) and (qm.var==pm.var) then
- return get_kanjiskip_low(false, qm, 1, 1, 1) or node_copy(kanji_skip)
- else
- local gb = get_kanjiskip_low(false, qm, 1, 1, 1)
- if gb then
- return calc_ja_ja_aux(gb,
- get_kanjiskip_low(false, pm, 1, 1, 1) or node_copy(kanji_skip), 0, 1)
- else
- local ga = get_kanjiskip_low(false, pm, 1, 1, 1)
- return (ga and calc_ja_ja_aux(node_copy(kanji_skip), ga, 0, 1))
- or node_copy(kanji_skip)
- end
- end
+ local pm, qm = Np.met, Nq.met
+ if (pm.char_type==qm.char_type) and (qm.var==pm.var) then
+ return get_kanjiskip_low(false, qm, 1, 1, 1) or node_copy(kanji_skip)
+ else
+ local gb = get_kanjiskip_low(false, qm, 1, 1, 1)
+ if gb then
+ return calc_ja_ja_aux(gb,
+ get_kanjiskip_low(false, pm, 1, 1, 1) or node_copy(kanji_skip), 0, 1)
+ else
+ local ga = get_kanjiskip_low(false, pm, 1, 1, 1)
+ return (ga and calc_ja_ja_aux(node_copy(kanji_skip), ga, 0, 1))
+ or node_copy(kanji_skip)
+ end
+ end
else
- local g = node_new(id_glue)
- set_attr(g, attr_icflag, kanjiskip_jfm_flag and KANJI_SKIP_JFM or KANJI_SKIP)
- return g
+ local g = node_new(id_glue)
+ set_attr(g, attr_icflag, kanjiskip_jfm_flag and KANJI_SKIP_JFM or KANJI_SKIP)
+ return g
end
end
local qm, pm = Nq.met, Np.met
local qmc, pmc = qm.char_type, pm.char_type
if (qmc==pmc) and (qm.var==pm.var) then
- local g, _, kn, kp, kh = new_jfm_glue(qmc, Nq.class, Np.class)
- return g, (Np.auto_kspc or Nq.auto_kspc) and get_kanjiskip_low(true, qm, kn, kp, kh)
+ local g, _, kn, kp, kh = new_jfm_glue(qmc, Nq.class, Np.class)
+ return g, (Np.auto_kspc or Nq.auto_kspc) and get_kanjiskip_low(true, qm, kn, kp, kh)
else
- local npn, nqn = Np.nuc, Nq.nuc
- local gb, db, bn, bp, bh
- = new_jfm_glue(qmc, Nq.class,
- slow_find_char_class(Np.char,
- qm, getchar(npn)))
- local ga, da, an, ap, ah
- = new_jfm_glue(pmc,
- slow_find_char_class(Nq.char,
- pm, getchar(nqn)),
- Np.class)
- local g = calc_ja_ja_aux(gb, ga, db, da)
- local k
- --if (pmc==qmc) and (qm.var==pm.var) then
+ local npn, nqn = Np.nuc, Nq.nuc
+ local gb, db, bn, bp, bh
+ = new_jfm_glue(qmc, Nq.class,
+ slow_find_char_class(Np.char,
+ qm, getchar(npn)))
+ local ga, da, an, ap, ah
+ = new_jfm_glue(pmc,
+ slow_find_char_class(Nq.char,
+ pm, getchar(nqn)),
+ Np.class)
+ local g = calc_ja_ja_aux(gb, ga, db, da)
+ local k
gb = get_kanjiskip_low(true, qm, bn, bp, bh)
- ga = get_kanjiskip_low(true, pm, an, ap, ah)
- k = calc_ja_ja_aux(gb, ga, db, da)
- --end
- return g, k
+ ga = get_kanjiskip_low(true, pm, an, ap, ah)
+ k = calc_ja_ja_aux(gb, ga, db, da)
+ return g, k
end
end
end
get_xkanjiskip_low = function(flag, qm, bn, bp, bh)
if flag or (qm.with_kanjiskip and (bn or bp or bh)) then
- if xkanjiskip_jfm_flag then
- local g = node_new(id_glue);
- local bk = qm.xkanjiskip or null_skip_table
- setglue(g, bn and bk[1] or 0,
- bp and bk[2] or 0,
- bh and bk[3] or 0, 0, 0)
- set_attr(g, attr_icflag, XKANJI_SKIP_JFM)
- return g
- elseif flag then
- return node_copy(xkanji_skip)
- else
- local g = node_new(id_glue);
- setglue(g,
- bn and (bn*getfield(xkanji_skip, 'width')) or 0,
- bp and (bp*getfield(xkanji_skip, 'stretch')) or 0,
- bh and (bh*getfield(xkanji_skip, 'shrink')) or 0,
- bp and getfield(xkanji_skip, 'stretch_order') or 0,
- bh and getfield(xkanji_skip, 'shrink_order') or 0)
- set_attr(g, attr_icflag, XKANJI_SKIP_JFM)
- return g
- end
+ if xkanjiskip_jfm_flag then
+ local g = node_new(id_glue);
+ local bk = qm.xkanjiskip or null_skip_table
+ setglue(g, bn and bk[1] or 0,
+ bp and bk[2] or 0,
+ bh and bk[3] or 0, 0, 0)
+ set_attr(g, attr_icflag, XKANJI_SKIP_JFM)
+ return g
+ elseif flag then
+ return node_copy(xkanji_skip)
+ else
+ local g = node_new(id_glue);
+ setglue(g,
+ bn and (bn*getfield(xkanji_skip, 'width')) or 0,
+ bp and (bp*getfield(xkanji_skip, 'stretch')) or 0,
+ bh and (bh*getfield(xkanji_skip, 'shrink')) or 0,
+ bp and getfield(xkanji_skip, 'stretch_order') or 0,
+ bh and getfield(xkanji_skip, 'shrink_order') or 0)
+ set_attr(g, attr_icflag, XKANJI_SKIP_JFM)
+ return g
+ end
end
end
if Np.auto_xspc==0 or Nq.auto_xspc==0 then
return nil
elseif (Nq.xspc>=2) and (Np.xspc%2==1) and (Nq.auto_xspc or Np.auto_xspc) then
- return get_xkanjiskip_low(true, Nn.met, 1, 1, 1)
+ return get_xkanjiskip_low(true, Nn.met, 1, 1, 1)
else
- local g = node_new(id_glue)
- set_attr(g, attr_icflag, xkanjiskip_jfm_flag and XKANJI_SKIP_JFM or XKANJI_SKIP)
- return g
+ local g = node_new(id_glue)
+ set_attr(g, attr_icflag, xkanjiskip_jfm_flag and XKANJI_SKIP_JFM or XKANJI_SKIP)
+ return g
end
end
end
fast_find_char_class(
(Nq.id == id_math and -1 or (Nq.xspc>=2 and 'alchar' or 'nox_alchar')), pm),
Np.class)
- local k = ((Nq.xspc>=2) and (Np.xspc%2==1) and combine_spc('auto_xspc'))
+ local k = ((Nq.xspc>=2) and (Np.xspc%2==1) and combine_spc 'auto_xspc')
and get_xkanjiskip_low(false, pm, kn, kp, kh)
return g, k
end
fast_find_char_class(
(Np.id == id_math and -1 or (Np.xspc%2==1 and 'alchar' or 'nox_alchar')), qm)
)
- local k = ((Nq.xspc>=2) and (Np.xspc%2==1) and combine_spc('auto_xspc'))
- and get_xkanjiskip_low(false, qm, kn, kp, kh)
+ local k = ((Nq.xspc>=2) and (Np.xspc%2==1) and combine_spc 'auto_xspc')
+ and get_xkanjiskip_low(false, qm, kn, kp, kh)
return g, k
end
-local function get_OA_skip(is_kanji)
+local function get_OA_skip(insert_ksp)
local pm = Np.met
local g, _, kn, kp, kh = new_jfm_glue(
pm.char_type,
(((Nq.id==id_glue)or(Nq.id==id_kern)) and 'glue' or 'jcharbdd'), pm),
Np.class)
local k
- if is_kanji==0 then
- k = combine_spc('auto_kspc') and get_kanjiskip_low(true, pm, kn, kp, kh)
+ if insert_ksp then
+ k = (combine_spc 'auto_kspc') and get_kanjiskip_low(true, pm, kn, kp, kh)
end
return g, k
end
-local function get_OB_skip(is_kanji)
+local function get_OB_skip(insert_ksp)
local qm = Nq.met
local g, _, kn, kp, kh = new_jfm_glue(
qm.char_type, Nq.class,
fast_find_char_class(
(((Np.id==id_glue)or(Np.id==id_kern)) and 'glue' or 'jcharbdd'), qm))
local k
- if is_kanji==0 then
- k = combine_spc('auto_kspc') and get_kanjiskip_low(true, qm, kn, kp, kh)
+ if insert_ksp then
+ k = (combine_spc 'auto_kspc') and get_kanjiskip_low(true, qm, kn, kp, kh)
end
return g, k
end
real_insert(g); real_insert(k)
elseif Nq.met then -- qid==id_hlist
local g, k
- if non_ihb_flag then g, k = get_OA_skip(0) end -- O_A->K
+ if non_ihb_flag then g, k = get_OA_skip(true) end -- O_A->K
if not g then g = get_kanjiskip() end
handle_penalty_normal(0, Np.pre, g); real_insert(g); real_insert(k)
elseif Nq.pre then
local function handle_np_ja_hlist()
local qid = Nq.id
if qid==id_jglyph or ((qid==id_pbox or qid == id_pbox_w) and Nq.met) then
- local g = non_ihb_flag and get_OB_skip(0) or get_kanjiskip() -- O_B->K
+ local g = non_ihb_flag and get_OB_skip(true) or get_kanjiskip() -- O_B->K
handle_penalty_normal(Nq.post, 0, g); real_insert(g)
elseif Nq.met then -- Nq.id==id_hlist
local g = get_kanjiskip() -- K
[id_pbox] = function() after_hlist(Nq) end,
[id_disc] = function() after_hlist(Nq) end,
[id_pbox_w] = function()
- luatexbase.call_callback("luatexja.jfmglue.whatsit_after",
- false, Nq, Np)
- end,
+ luatexbase.call_callback("luatexja.jfmglue.whatsit_after",
+ false, Nq, Np)
+ end,
}
- adjust_nq=function()
+ adjust_nq = function()
local x = adjust_nq_aux[Nq.id]
if x then x() end
end
-- Insert \jcharwidowpenalty
if widow_Np.first then handle_penalty_jwp() end
else
- Np=Nq
+ Np = Nq
-- the current list is the contents of a hbox
local npi, pm = Np.id, Np.met
if npi == id_jglyph or (npi==id_pbox and pm) then
- local g = new_jfm_glue(pm.char_type, Np.class, fast_find_char_class('boxbdd', pm))
- if g then
- set_attr(g, attr_icflag, BOXBDD)
- head = insert_after(head, Np.last, g)
- end
+ local g = new_jfm_glue(pm.char_type, Np.class, fast_find_char_class('boxbdd', pm))
+ if g then
+ set_attr(g, attr_icflag, BOXBDD)
+ head = insert_after(head, Np.last, g)
+ end
end
end
end
-- リスト先頭の処理
local function handle_list_head(par_indented)
local npi, pm = Np.id, Np.met
- if npi == id_jglyph or (npi==id_pbox and pm) then
+ if npi == id_jglyph or (npi==id_pbox and pm) then
if non_ihb_flag then
- local g = new_jfm_glue(pm.char_type, fast_find_char_class(par_indented, pm), Np.class)
- if g then
- set_attr(g, attr_icflag, BOXBDD)
- if getid(g)==id_glue and #Bp==0 then
- local h = node_new(id_penalty)
- setfield(h, 'penalty', 10000); set_attr(h, attr_icflag, BOXBDD)
- end
- head = insert_before(head, Np.first, g)
- end
+ local g = new_jfm_glue(pm.char_type, fast_find_char_class(par_indented, pm), Np.class)
+ if g then
+ set_attr(g, attr_icflag, BOXBDD)
+ if getid(g)==id_glue and #Bp==0 then
+ local h = node_new(id_penalty)
+ setfield(h, 'penalty', 10000); set_attr(h, attr_icflag, BOXBDD)
+ end
+ head = insert_before(head, Np.first, g)
+ end
end
end
end
-- return value: (the initial cursor lp), (last node)
local init_var
do
- local id_local = node.id('local_par')
+ local id_local = node.id 'local_par'
local KANJI_SKIP = luatexja.icflag_table.KANJI_SKIP
local XKANJI_SKIP = luatexja.icflag_table.XKANJI_SKIP
local KSK = luatexja.stack_table_index.KSK
local table_pool = {
{}, {}, {first=nil},
{ auto_kspc=nil, auto_xspc=nil, char=nil, class=nil,
- first=nil, id=nil, last=nil, met=nil, nuc=nil,
- post=nil, pre=nil, xspc=nil, },
+ first=nil, id=nil, last=nil, met=nil, nuc=nil,
+ post=nil, pre=nil, xspc=nil, },
{ auto_kspc=nil, auto_xspc=nil, char=nil, class=nil,
- first=nil, id=nil, last=nil, met=nil, nuc=nil,
- post=nil, pre=nil, xspc=nil, },
+ first=nil, id=nil, last=nil, met=nil, nuc=nil,
+ post=nil, pre=nil, xspc=nil, },
}
init_var = function (mode,dir)
-- 1073741823: max_dimen
Bp, widow_Bp, widow_Np, Np, Nq
- = table_pool[1], table_pool[2], table_pool[3], table_pool[4], table_pool[5]
+ = table_pool[1], table_pool[2], table_pool[3], table_pool[4], table_pool[5]
for i=1,5 do for j,_ in pairs(table_pool[i]) do table_pool[i][j]=nil end end
table_current_stack = ltjs.table_current_stack
-- ithout this node, set_attr(kanji_skip, ...) somehow creates an "orphaned" attribute list.
do
- kanji_skip, kanjiskip_jfm_flag = skip_table_to_glue(KSK)
- set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
+ kanji_skip, kanjiskip_jfm_flag = skip_table_to_glue(KSK)
+ set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
end
do
- xkanji_skip, xkanjiskip_jfm_flag = skip_table_to_glue(XSK)
- set_attr(xkanji_skip, attr_icflag, XKANJI_SKIP)
+ xkanji_skip, xkanjiskip_jfm_flag = skip_table_to_glue(XSK)
+ set_attr(xkanji_skip, attr_icflag, XKANJI_SKIP)
end
if mode then
- -- the current list is to be line-breaked:
- -- hbox from \parindent is skipped.
- local lp, par_indented, lpi, lps = head, 'boxbdd', getid(head), getsubtype(head)
- while lp and
- ((lpi==id_whatsit and lps~=sid_user)
- or ((lpi==id_hlist) and (lps==3))
+ -- the current list is to be line-breaked:
+ -- hbox from \parindent is skipped.
+ local lp, par_indented, lpi, lps = head, 'boxbdd', getid(head), getsubtype(head)
+ while lp and
+ ((lpi==id_whatsit and lps~=sid_user)
+ or ((lpi==id_hlist) and (lps==3))
or (lpi==id_local)) do
- if (lpi==id_hlist) and (lps==3) then
+ if (lpi==id_hlist) and (lps==3) then
Np.char, par_indented = 'parbdd', 'parbdd'
Np.width = getfield(lp, 'width')
end
- lp=node_next(lp); lpi, lps = getid(lp), getsubtype(lp) end
- return lp, node_tail(head), par_indented, TEMP
+ lp=node_next(lp); lpi, lps = getid(lp), getsubtype(lp) end
+ return lp, node_tail(head), par_indented, TEMP
else
- return head, nil, 'boxbdd', TEMP
+ return head, nil, 'boxbdd', TEMP
end
end
end
if mode then
local h = node_next(head)
if getid(h) == id_penalty and getfield(h, 'penalty') == 10000 then
- h = node_next(h)
- if getid(h) == id_glue and getsubtype(h) == 15 and not node_next(h) then
- return false
- end
+ h = node_next(h)
+ if getid(h) == id_glue and getsubtype(h) == 15 and not node_next(h) then
+ return false
+ end
end
end
return head
handle_list_head(par_indented)
lp = calc_np(last,lp);
while Np do
- adjust_nq();
- local pid, pm = Np.id, Np.met
- -- 挿入部
- if pid == id_jglyph then
- handle_np_jachar(mode)
- elseif pm then
- if pid==id_hlist then handle_np_ja_hlist()
- else handle_np_jachar() end
- elseif Nq.met then
- if Nq.id==id_hlist then handle_nq_ja_hlist()
- else handle_nq_jachar() end
- end
- lp = calc_np(last,lp)
+ adjust_nq();
+ local pid, pm = Np.id, Np.met
+ -- 挿入部
+ if pid == id_jglyph then
+ handle_np_jachar(mode)
+ elseif pm then
+ if pid==id_hlist then handle_np_ja_hlist()
+ else handle_np_jachar() end
+ elseif Nq.met then
+ if Nq.id==id_hlist then handle_nq_ja_hlist()
+ else handle_nq_jachar() end
+ end
+ lp = calc_np(last,lp)
end
handle_list_tail(mode, last)
end
Np.first = lp; Np.nuc = lp; Np.last = lp
return Np
elseif Np and getfield(lp, 'user_id') == BOXB then
- Np.first = lp; Np.nuc = lp; Np.last = lp
- if Nq then
- if Nq.met then
- Np.class = fast_find_char_class('boxbdd', Nq.met)
+ Np.first = lp; Np.nuc = lp; Np.last = lp
+ if Nq then
+ if Nq.met then
+ Np.class = fast_find_char_class('boxbdd', Nq.met)
end
Np.met = Nq.met; Np.pre = 0; Np.post = 0; Np.xspc = 0
Np.auto_xspc, Np.auto_kspc = 0, 0
- end
+ end
return Np
else
- return Np
+ return Np
end
end
Nq.auto_xspc, Nq.auto_kspc = 0, 0
end
head = node_remove(head, y)
- node_free(y)
+ node_free(y)
end
return s
end
--
luatexbase.provides_module({
name = 'luatexja.jfont',
- date = '2020-06-14',
+ date = '2020-07-30',
description = 'Loader for Japanese fonts',
})
-luatexja.load_module('lotf_aux'); local ltju = luatexja.lotf_aux
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('charrange'); local ltjc = luatexja.charrange
-luatexja.load_module('rmlgbm'); local ltjr = luatexja.rmlgbm
-luatexja.load_module('direction'); local ltjd = luatexja.direction
+luatexja.load_module 'lotf_aux'; local ltju = luatexja.lotf_aux
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
+luatexja.load_module 'rmlgbm'; local ltjr = luatexja.rmlgbm
+luatexja.load_module 'direction'; local ltjd = luatexja.direction
local setfield = node.direct.setfield
local getid = node.direct.getid
kanjiskip_stretch = w.kanjiskip_stretch,
kanjiskip_shrink = w.kanjiskip_shrink,
round_threshold = w.round_threshold,
- }
+ }
end
for k,w in pairs(v.kern) do
local g = node_new(id_kern, 1)
'no JFM specified',
'To load and define a Japanese font, a JFM must be specified.'..
"The JFM 'ujis' will be used for now.")
- jfm_file_name='ujis'
+ jfm_file_name = 'ujis'
end
for j,v in ipairs(metrics) do
if v.name==jfm_file_name then return j end
local fmtable = { jfm = j, size = f.size, var = jfm_var,
with_kanjiskip = jfm_ksp,
zw = sz.zw, zh = sz.zh,
- chars = sz.chars, char_type = sz.char_type,
+ chars = sz.chars, char_type = sz.char_type,
kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip,
chars_cbcache = {},
vert_activated = vert_activated,
ltju.enable_feature(fn, ltju.exist_feature(fn, 'vrt2') and 'vrt2' or 'vert')
end
- --texio.write_nl('term and log',
- --'JFNT\t' .. identifiers[fn].name .. '\t' .. identifiers[fn].size .. '\t' .. fn, '')
-
fmtable = luatexbase.call_callback("luatexja.define_jfont", fmtable, fn)
font_metric_table[fn]=fmtable
tex.sprint(cat_lp, global_flag, '\\protected\\expandafter\\def\\csname ',
-- extract jfm_file_name and jfm_var
-- normalize position of 'jfm=' and 'jfmvar=' keys
local function extract_metric(name)
- do
- local nametemp
- nametemp = name:match('^{(.*)}$')
- if nametemp then name = nametemp
- else
- nametemp = name:match('^"(.*)"$')
- name = nametemp or name
- end
- end
+ name = (name:match '^{(.*)}$') or (name:match '^"(.*)"$') or name
jfm_file_name = ''; jfm_var = ''; jfm_ksp = true
local tmp, index = name:sub(1, 5), 1
if tmp == 'file:' or tmp == 'name:' or tmp == 'psft:' then
if l~=q then
name = name:sub(1,index-1) .. name:sub(q+1)
else
- name = name:sub(1,index-1)
- index = nil
+ name = name:sub(1,index-1); index = nil
end
elseif name:sub(index, index+6)=='jfmvar=' and q>index+6 then
jfm_var = name:sub(index+7, q-1)
if l~=q then
name = name:sub(1,index-1) .. name:sub(q+1)
else
- name = name:sub(1,index-1)
- index = nil
+ name = name:sub(1,index-1); index = nil
end
else
index = (l~=q) and (q+1) or nil
jfm_ksp = not (x=='-')
end
if jfm_dir == 'tate' then
- vert_activated = (not name:match('[:;]%-vert')) and (not name:match('[:;]%-vrt2'))
+ vert_activated = (not name:match '[:;]%-vert') and (not name:match '[:;]%-vrt2')
auto_enable_vrt2
- = (not name:match('[:;][+%-]?vert')) and (not name:match('[:;][+%-]?vrt2'))
+ = (not name:match '[:;][+%-]?vert') and (not name:match '[:;][+%-]?vrt2')
else
vert_activated, auto_enable_vrt2 = nil, nil
end
-- EXT
function luatexja.jfont.output_alt_font_cmd(dir, bbase)
alt_font_base = bbase
- if dir == 't' then
- alt_font_base_num = tex.getattribute(attr_curtfnt)
- else
- alt_font_base_num = tex.getattribute(attr_curjfnt)
- end
+ alt_font_base_num = tex.getattribute((dir == 't') and attr_curtfnt or attr_curjfnt)
local t = alt_font_table[alt_font_base_num]
if t then
for i,_ in pairs(t) do t[i]=nil end
end
t = alt_font_table_latex[bbase]
if t then
- for i,_ in pairs(t) do
+ for i,_ in pairs(t) do
tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux' .. dir .. '{' .. i .. '}')
end
end
if (not tfmdata) or (not tfmdata.filename) then return end
local bname = tfmdata.psname or nameonly(tfmdata.filename)
if not font_extra_basename[bname] then
- -- if the cache is present, read it
- --
+ -- if the cache is present, read it
+ --
local newtime = file_attributes(tfmdata.filename,"modification")
local v = "extra_" .. string.lower(bname)
local dest = load_cache(
v,
- function (t)
- return (t.lotf_version~=luaotfload.version)
- or (t.version~=cache_ver) or (t.modtime~=newtime)
- end
+ function (t)
+ return (t.lotf_version~=luaotfload.version)
+ or (t.version~=cache_ver) or (t.modtime~=newtime)
+ end
)
-- if the cache is not found or outdated, save the cache
if dest then
- font_extra_basename[bname] = dest[1] or {}
- local vheight, vorigin = dest[1].vheight, dest[1].vorigin
- local vhd, vod = vheight.default, vorigin.default
+ font_extra_basename[bname] = dest[1] or {}
+ local vheight, vorigin = dest[1].vheight, dest[1].vorigin
+ local vhd, vod = vheight.default, vorigin.default
setmetatable(vheight, {__index = function () return vhd end } )
setmetatable(vorigin, {__index = function () return vod end } )
else
local dest = ltju.get_vmet_table(tfmdata, nil)
dest = list_rotate_glyphs(tfmdata, dest)
font_extra_basename[bname] = dest or {}
- save_cache( v,
- {
- modtime = newtime,
- version = cache_ver,
- lotf_version = luaotfload.version,
- dest,
- })
+ save_cache(v,
+ { modtime = newtime,
+ version = cache_ver,
+ lotf_version = luaotfload.version,
+ dest,
+ })
end
return bname
end
local bname = res.psname or nameonly(res.filename)
local t = font_extra_basename[bname]
if not t then bname = prepare_extra_data_base(res) end
- font_extra_info[id] = t or font_extra_basename[bname]
+ font_extra_info[id] = t or font_extra_basename[bname]
end
end
luatexbase.add_to_callback(
'luaotfload.patch_font',
function (tfmdata)
- -- these function is executed one time per one fontfile
- prepare_extra_data_base(tfmdata); return tfmdata
+ -- these function is executed one time per one fontfile
+ prepare_extra_data_base(tfmdata); return tfmdata
end,
'ltj.prepare_extra_data', 1)
luatexbase.add_to_callback(
local t = font_getfont(fnum)
if not t then return fmtable end
for i,v in pairs(vert_form_table) do
- if t.characters[v] then vform[i] = v end
+ if t.characters[v] then vform[i] = v end
end
if ltju.specified_feature(fnum, 'jpotf') then
for i,v in pairs(vert_jpotf_table) do
end
if not ltju.exist_feature(fnum, 'vert') and not ltju.exist_feature(fnum, 'vrt2') then
-- 現在の (script, lang) で vert もvrt2 も有効にできない場合,
- -- 全 (script,lang) の vert を強制的に適用
+ -- 全 (script,lang) の vert を強制的に適用
ltju.loop_over_feat(t, vert_feat, function (i,k) vform[i] = vform[i] or k end, true)
end
-- vform の中身を vert 適用結果に変える
function (i,k)
for j,w in pairs(vform) do
if (i==j)and(w==k) then vform[j]=nil elseif w==i then vform[j] = k end
- end
+ end
end)
return fmtable
end, 'ltj.get_vert_form', 1
if cidinfo and cidinfo.registry and cidinfo.ordering then
local rd = ltjr_prepare_cid_font(cidinfo.registry, cidinfo.ordering)
if rd then
- local ru = rd.resources.unicodes -- defined by LuaTeX-ja
- local rc = rd.characters
+ local ru = rd.resources.unicodes -- defined by LuaTeX-ja
+ local rc = rd.characters
for i,v in pairs(tfmdata.characters) do
local w = ru[cidinfo.ordering .. "." .. tostring(v.index)]
if w then
-- ltj-pretreat.lua
--
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('charrange'); local ltjc = luatexja.charrange
-luatexja.load_module('stack'); local ltjs = luatexja.stack
-luatexja.load_module('jfont'); local ltjf = luatexja.jfont
-luatexja.load_module('direction'); local ltjd = luatexja.direction
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
+luatexja.load_module 'jfont'; local ltjf = luatexja.jfont
+luatexja.load_module 'direction'; local ltjd = luatexja.direction
local to_node = node.direct.tonode
local to_direct = node.direct.todirect
local suppress_hyphenate_ja_aux = {
[id_math] = function(p) return node_next(node_end_of_math(node_next(p))) end,
[id_whatsit] = function(p)
- if getsubtype(p)==sid_user then
- local uid = getfield(p, 'user_id')
- if uid==STCK then
- wt[#wt+1] = p; node_remove(head, p)
- elseif uid==DIR then
- if has_attr(p, attr_icflag)<PROCESSED_BEGIN_FLAG then
- ltjs.list_dir = has_attr(p, attr_dir)
- else -- こっちのケースは通常使用では起こらない
- wtd[#wtd+1] = p; node_remove(head, p)
- end
- end
- end
- return node_next(p)
+ if getsubtype(p)==sid_user then
+ local uid = getfield(p, 'user_id')
+ if uid==STCK then
+ wt[#wt+1] = p; node_remove(head, p)
+ elseif uid==DIR then
+ if has_attr(p, attr_icflag)<PROCESSED_BEGIN_FLAG then
+ ltjs.list_dir = has_attr(p, attr_dir)
+ else -- こっちのケースは通常使用では起こらない
+ wtd[#wtd+1] = p; node_remove(head, p)
+ end
+ end
+ end
+ return node_next(p)
end,
}
setmetatable(suppress_hyphenate_ja_aux,
- {
- __index = function() return node_next end,
- })
+ { __index = function() return node_next end, })
local id_boundary = node.id('boundary')
local node_new, insert_before = node.direct.new, node.direct.insert_before
local setsubtype = node.direct.setsubtype or function(n,l) setfield(n,'subtype',l) end
for i = 1,#wt do wt[i]=nil end
for i = 1,#wtd do wtd[i]=nil end
for i,_ in pairs(ltjs_orig_char_table) do
- ltjs_orig_char_table[i] = nil
+ ltjs_orig_char_table[i] = nil
end
ltjs.list_dir=ltjd_get_dir_count()
do
- local p = head
- while p do
- local pid, prev_chartype = getid(p), 0
- -- prev_chartype: 0: not char 1: ALchar 2: JAchar
- while pid==id_glyph do
- local pc = getchar(p)
- if has_attr(p, attr_icflag, 0) and is_ucs_in_japanese_char(p, pc) then
- if prev_chartype==1 then
+ local p = head
+ while p do
+ local pid, prev_chartype = getid(p), 0
+ -- prev_chartype: 0: not char 1: ALchar 2: JAchar
+ while pid==id_glyph do
+ local pc = getchar(p)
+ if has_attr(p, attr_icflag, 0) and is_ucs_in_japanese_char(p, pc) then
+ if prev_chartype==1 then
local b = node_new(id_whatsit,sid_user);
- setfield(b, 'type', 100); setfield(b, 'user_id', JA_AL_BDD);
- insert_before(head, p, b)
- end
+ setfield(b, 'type', 100); setfield(b, 'user_id', JA_AL_BDD);
+ insert_before(head, p, b)
+ end
local pf = has_attr(p, attr_curjfnt)
pf = (pf and pf>0 and pf) or getfont(p)
- setfont(p, ltjf_replace_altfont(pf, pc))
- setlang(p, lang_ja)
- ltjs_orig_char_table[p], prev_chartype = pc, 2
+ setfont(p, ltjf_replace_altfont(pf, pc))
+ setlang(p, lang_ja)
+ ltjs_orig_char_table[p], prev_chartype = pc, 2
elseif prev_chartype==2 then
- local b = node_new(id_whatsit,sid_user);
- setfield(b, 'type', 100); setfield(b, 'user_id', JA_AL_BDD);
- insert_before(head, p, b); prev_chartype = 1
+ local b = node_new(id_whatsit,sid_user);
+ setfield(b, 'type', 100); setfield(b, 'user_id', JA_AL_BDD);
+ insert_before(head, p, b); prev_chartype = 1
else prev_chartype = 1
- end
- p = node_next(p); pid = getid(p)
- end
- p = (suppress_hyphenate_ja_aux[pid])(p)
- end
+ end
+ p = node_next(p); pid = getid(p)
+ end
+ p = (suppress_hyphenate_ja_aux[pid])(p)
+ end
end
stop_time_measure('ltj_hyphenate'); start_time_measure('tex_hyphenate')
lang.hyphenate(h, nil)
return h
end
- ltjb.add_to_callback('hyphenate',
- function (head,tail)
- return suppress_hyphenate_ja(head)
- end,'ltj.hyphenate')
+ ltjb.add_to_callback('hyphenate', suppress_hyphenate_ja, 'ltj.hyphenate')
end
-- mode: true iff this function is called from hpack_filter
for _,p in pairs(wt) do node_free(p) end
end
ltjs_report_stack_level(tex_getcount('ltj@@stack') + box_set)
- for _,p in pairs(wtd) do
- node_free(p)
- end
+ for _,p in pairs(wtd) do node_free(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, 0) and getlang(p)==lang_ja then
- local nf = ltjf_replace_altfont( has_attr(p, attr_curtfnt) or getfont(p) , ltjs_orig_char_table[p])
- setfont(p, nf)
- if ltjf_font_metric_table[nf].vert_activated then
- local pc = getchar(p)
- pc = ltjf_font_metric_table[nf].vform[pc]
+ local nf = ltjf_replace_altfont( has_attr(p, attr_curtfnt) or getfont(p) , ltjs_orig_char_table[p])
+ setfont(p, nf)
+ if ltjf_font_metric_table[nf].vert_activated then
+ local pc = getchar(p); pc = ltjf_font_metric_table[nf].vform[pc]
if pc then setchar(p, pc) end
- end
- end
+ end
+ end
end
end
return head
ltjb.add_to_callback('hpack_filter',
function (head)
return set_box_stack_level(head, true)
- end,'ltj.set_stack_level',1)
+ end, 'ltj.set_stack_level', 1)
ltjb.add_to_callback('pre_linebreak_filter',
- function (head)
- return set_box_stack_level(head, false)
- end,'ltj.set_stack_level',1)
+ function (head)
+ return set_box_stack_level(head, false)
+ end, 'ltj.set_stack_level', 1)
luatexja.pretreat = {
set_box_stack_level = set_box_stack_level,
local cid_reg, cid_order, cid_supp, cid_name
local cid_replace = {
["Adobe-Japan1"] = {"UniJIS2004-UTF32", 23059, 7,
- function (i)
- if (231<=i and i<=632) or (8718<=i and i<=8719)
- or (12063<=i and i<=12087) then
- return 327680 -- 655360/2
- elseif 9758<=i and i<=9778 then
- return 218453 -- 655360/3
- elseif 9738<=i and i<=9757 then
- return 163840 -- 655360/4
- end
- end},
+ function (i)
+ if (231<=i and i<=632) or (8718<=i and i<=8719)
+ or (12063<=i and i<=12087) then
+ return 327680 -- 655360/2
+ elseif 9758<=i and i<=9778 then
+ return 218453 -- 655360/3
+ elseif 9738<=i and i<=9757 then
+ return 163840 -- 655360/4
+ end
+ end},
-- 基本的には JIS X 0213:2004 に沿ったマッピング
["Adobe-Korea1"] = {"UniKS-UTF32", 18351, 2,
- function (i)
- if 8094<=i and i<=8100 then
- return 327680 -- 655360/2
- end
- end},
+ function (i)
+ if 8094<=i and i<=8100 then
+ return 327680 -- 655360/2
+ end
+ end},
["Adobe-GB1"] = {"UniGB-UTF32", 30283, 5,
- function (i)
- if (814<=i and i<=939) or (i==7716)
- or (22355<=i and i<=22357) then
- return 327680 -- 655360/2
- end
- end},
+ function (i)
+ if (814<=i and i<=939) or (i==7716)
+ or (22355<=i and i<=22357) then
+ return 327680 -- 655360/2
+ end
+ end},
["Adobe-CNS1"] = {"UniCNS-UTF32", 19178, 7,
- function (i)
- if (13648<=i and i<=13742) or (i==17603) then
- return 327680 -- 655360/2
- end
- end},
+ function (i)
+ if (13648<=i and i<=13742) or (i==17603) then
+ return 327680 -- 655360/2
+ end
+ end},
["Adobe-KR"] = {"UniAKR-UTF32", 22896, 9,
- function (i)
- if i==3057 then
- return 655360*2
- elseif i==3058 then
- return 655360*3
- elseif i==12235 or i==12236 then
- return 163840 -- 655360/4
- end
- end},
+ function (i)
+ if i==3057 then
+ return 655360*2
+ elseif i==3058 then
+ return 655360*3
+ elseif i==12235 or i==12236 then
+ return 163840 -- 655360/4
+ end
+ end},
}
-- reading CID maps
else -- WMA l is in the form "<%x+>%s+<%x+>"
bucs, eucs, cid = string.match(line, "<(%x+)>%s+<(%x+)>%s+<?(%x+)>?")
cid = cid_dec(cid);
- bucs = tonumber(bucs, 16); eucs = tonumber(eucs, 16)
+ bucs = tonumber(bucs, 16); eucs = tonumber(eucs, 16)
for ucs = bucs, eucs do
if not tt[ucs] then
tt[ucs] = mke(cid); cidm[cid]=ucs
cidinfo = { ordering=cid_order, registry=cid_reg, supplement=kx[3] },
encodingbytes = 2, extend=1000, format = 'opentype',
direction = 0, characters = {}, parameters = {
- ascender = 655360*0.88,
- descender = 655360*0.12,
- },
- embedding = "no", cache = "yes", factor = 0, hfactor = 0, vfactor = 0,
- tounicode = 1,
- properties = { language = "dflt", script = "dflt" },
+ ascender = 655360*0.88,
+ descender = 655360*0.12,
+ },
+ embedding = "no", cache = "yes", factor = 0, hfactor = 0, vfactor = 0,
+ tounicode = 1,
+ properties = { language = "dflt", script = "dflt" },
}
cidfont_data[cid_name] = k
for i,v in ipairs(cidmo) do
if v==-1 then
tth[pricode], cidmo[i], pricode
- = { index = i }, pricode, pricode+1;
+ = { index = i }, pricode, pricode+1;
end
ttu[cid_order .. '.' .. i] = cidmo[i]
end
}
k.resources = {
unicodes = ttu,
- features = feat_dummy_vert,
- sequences = seq_dummy_vert,
+ features = feat_dummy_vert,
+ sequences = seq_dummy_vert,
}
k.descriptions = {}
cache_chars[cid_name] = { [655360] = k.characters }
for i = 0,kx[2] do cidm[i] = -1 end
open_cmap_file(kx[1] .. "-V", increment, tonumber, entry)
for i,v in pairs(tt) do
- ttv[i] = cidmo[v.index] -- "unicode" of vertical variant
+ ttv[i] = cidmo[v.index] -- "unicode" of vertical variant
end
-- tounicode エントリ
local cidp = {nil, nil}; tt, ttu, cidm = {}, {}, {}
open_cmap_file(cid_name .. "-UCS2",
- function(a)
- a[2] = a[2] +1 ; return a
- end,
- function(a)
- cidp[1] = string.upper(string.sub(a,1,string.len(a)-4))
- cidp[2] = tonumber(string.sub(a,-4),16)
- return cidp
- end,
- function(a) return a[1] ..string.format('%04X',a[2]) end)
+ function(a)
+ a[2] = a[2] +1 ; return a
+ end,
+ function(a)
+ cidp[1] = string.upper(string.sub(a,1,string.len(a)-4))
+ cidp[2] = tonumber(string.sub(a,-4),16)
+ return cidp
+ end,
+ function(a) return a[1] ..string.format('%04X',a[2]) end)
-- tt は cid -> tounicode になっているので cidm -> tounicode に変換
local kxf = kx[4]
for i,v in ipairs(cidmo) do
- k.characters[v].width = kxf(i)
- if v>=0xF0000 then
- k.characters[v].tounicode = tt[i]
- end
+ k.characters[v].width = kxf(i)
+ if v>=0xF0000 then
+ k.characters[v].tounicode = tt[i]
+ end
end
-- Save
if k and k.characters and k.characters[46] then
k.characters[46].width = math.floor(655360/14);
end
- ltjb.save_cache( "ltj-cid-auto-" .. string.lower(cid_name),
- {
- version = cache_ver,
- k,
- })
+ ltjb.save_cache("ltj-cid-auto-" .. string.lower(cid_name),
+ {version = cache_ver, k})
k.shared.rawdata.resources=k.resources
k.shared.rawdata.descriptions=k.descriptions
end
function (head, fnum)
local fontdata = font_getfont(fnum)
if head and luatexja.jfont.font_metric_table[fnum].vert_activated then
- local vt = fontdata.ltj_vert_table
- local nh = is_node(head) and to_direct(head) or head
+ local vt = fontdata.ltj_vert_table
+ local nh = is_node(head) and to_direct(head) or head
for n in traverse_id(id_glyph, head) do
if getfont(n)==fnum then
- local c = getchar(n); setchar(n, vt[c] or c)
+ local c = getchar(n); setchar(n, vt[c] or c)
end
end
return head, false
local function cid_cache_outdated(t) return t.version~=cache_ver end
local function read_cid_font()
local dat = ltjb.load_cache("ltj-cid-auto-" .. string.lower(cid_name),
- cid_cache_outdated )
+ cid_cache_outdated)
if dat then
dat[1].shared.rawdata.resources=dat[1].resources
dat[1].shared.rawdata.descriptions=dat[1].descriptions
cachedata.shared = {}
local shared = cachedata.shared
for k, v in pairs(s.shared) do
- shared[k] = v
+ shared[k] = v
end
end
-- character's default height (optimized for jfm-ujis.lua)
local def_depth = 0.12 * size -- and depth.
if not cache_chars[cid_name][size] then
- cache_chars[cid_name][size] = {}
- for k, v in pairs(cache_chars[cid_name][655360]) do
- cache_chars[cid_name][size][k] = {
- index = v.index, width = v.width * scale,
- height = def_height, depth = def_depth, tounicode = v.tounicode,
- }
- end
+ cache_chars[cid_name][size] = {}
+ for k, v in pairs(cache_chars[cid_name][655360]) do
+ cache_chars[cid_name][size][k] = {
+ index = v.index, width = v.width * scale,
+ height = def_height, depth = def_depth, tounicode = v.tounicode,
+ }
+ end
end
fontdata.characters = cache_chars[cid_name][size]
cachedata.characters = cache_chars[cid_name][size]
-- other parameters
do
local parameters = {}
- for k, v in pairs(s.parameters) do
- parameters[k] = v * scale
- end
- fontdata.parameters = parameters
- fontdata.size = size
- fontdata.resources = s.resources
- cachedata.parameters = parameters
- cachedata.size = size
- cachedata.resources = s.resources
+ for k, v in pairs(s.parameters) do parameters[k] = v * scale end
+ fontdata.parameters = parameters; fontdata.size = size; fontdata.resources = s.resources
+ cachedata.parameters = parameters; cachedata.size = size; cachedata.resources = s.resources
end
-- no embedding
local p = basename:find(":")
local q = basename:find("/[BI][BI]?")
if q and p and q<=p then
- basename = basename:gsub('/[BI][BI]?', '', 1)
- p = basename:find(":")
+ basename = basename:gsub('/[BI][BI]?', '', 1)
+ p = basename:find(":")
end
if p then
- local xname = basename:sub(p+1)
- p = 1
- while p do
- local q = xname:find(";", p+1) or xname:len()+1
- if xname:sub(p, p+3)=='cid=' and q>p+4 then
- s = xname:sub(p+4, q-1)
- end
- if xname:len()+1==q then p = nil else p = q + 1 end
- end
+ local xname = basename:sub(p+1)
+ p = 1
+ while p do
+ local q = xname:find(";", p+1) or xname:len()+1
+ if xname:sub(p, p+3)=='cid=' and q>p+4 then
+ s = xname:sub(p+4, q-1)
+ end
+ if xname:len()+1==q then p = nil else p = q + 1 end
+ end
end
cid_reg, cid_order = string.match(s, "^(.-)%-(.-)%-(%d-)$")
if not cid_reg then
cid_reg, cid_order = string.match(s, "^(.-)%-(.-)$")
end
if not prepare_cid_font(cid_reg, cid_order) then
- ltjb.package_error('luatexja',
- "bad cid key `" .. s .. "'",
- "I couldn't find any non-embedded font information for the CID\n" ..
- '`' .. s .. "'. For now, I'll use `Adobe-Japan1-6'.\n"..
- 'Please contact the LuaTeX-ja project team.')
- cid_name = "Adobe-Japan1"
+ ltjb.package_error('luatexja',
+ "bad cid key `" .. s .. "'",
+ "I couldn't find any non-embedded font information for the CID\n" ..
+ '`' .. s .. "'. For now, I'll use `Adobe-Japan1-6'.\n"..
+ 'Please contact the LuaTeX-ja project team.')
+ cid_name = "Adobe-Japan1"
end
return mk_rml(basename, size, id)
else
--
luatexbase.provides_module({
name = 'luatexja.ruby',
- date = '2018/09/29',
+ date = '2020-07-30',
description = 'Ruby annotation',
})
luatexja.ruby = {}
-luatexja.load_module('stack'); local ltjs = luatexja.stack
-luatexja.load_module('base'); local ltjb = luatexja.base
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
+luatexja.load_module 'base'; local ltjb = luatexja.base
local to_node = node.direct.tonode
local to_direct = node.direct.todirect
local has_attr, set_attr = node.direct.has_attribute, node.direct.set_attribute
local insert_before, insert_after = node.direct.insert_before, node.direct.insert_after
-local id_hlist = node.id('hlist')
-local id_vlist = node.id('vlist')
-local id_rule = node.id('rule')
-local id_whatsit = node.id('whatsit')
-local id_glue = node.id('glue')
-local id_kern = node.id('kern')
-local id_penalty = node.id('penalty')
-local sid_user = node.subtype('user_defined')
+local id_hlist = node.id 'hlist'
+local id_vlist = node.id 'vlist'
+local id_rule = node.id 'rule'
+local id_whatsit= node.id 'whatsit'
+local id_glue = node.id 'glue'
+local id_kern = node.id 'kern'
+local id_penalty= node.id 'penalty'
+local sid_user = node.subtype 'user_defined'
local ltjs_get_stack_table = luatexja.stack.get_stack_table
local id_pbox_w = 258 -- cluster which consists of a whatsit
local deg = #coef
for i = 1, deg do
if coef[i][i]==0 then
- for j = i+1, deg do
- if coef[j][i]~=0 then
+ for j = i+1, deg do
+ if coef[j][i]~=0 then
coef[i], coef[j] = coef[j], coef[i]; break
- end
- end
+ end
+ end
end
for j = 1,deg do
- local d = coef[i][i];
- if j~=i then
- local e = coef[j][i]
- for k = 1, deg+1 do coef[j][k] = coef[j][k] - e*coef[i][k]/d end
- else
- for k = 1, deg+1 do coef[i][k] = coef[i][k]/d end
- end
+ local d = coef[i][i];
+ if j~=i then
+ local e = coef[j][i]
+ for k = 1, deg+1 do coef[j][k] = coef[j][k] - e*coef[i][k]/d end
+ else
+ for k = 1, deg+1 do coef[i][k] = coef[i][k]/d end
+ end
end
end
end
end
function concat(f, b)
if f then
- if b then
- local h, nh = getlist(f), getlist(b)
- if getid(nh)==id_whatsit and getsubtype(nh)==sid_user then
- nh=node_next(nh); node_free(node_prev(nh))
- end
+ if b then
+ local h, nh = getlist(f), getlist(b)
+ if getid(nh)==id_whatsit and getsubtype(nh)==sid_user then
+ nh=node_next(nh); node_free(node_prev(nh))
+ end
set_attr(nh, attr_icflag,
- get_attr_icflag(nh) + PROCESSED_BEGIN_FLAG)
- setfield(node_tail(h), 'next', nh)
- setfield(f, 'head', nil); node_free(f)
- setfield(b, 'head', nil); node_free(b)
- local g = luatexja.jfmglue.main(h,false)
- return node.direct.hpack(g)
- else
- return f
- end
+ get_attr_icflag(nh) + PROCESSED_BEGIN_FLAG)
+ setfield(node_tail(h), 'next', nh)
+ setfield(f, 'head', nil); node_free(f)
+ setfield(b, 'head', nil); node_free(b)
+ local g = luatexja.jfmglue.main(h,false)
+ return node.direct.hpack(g)
+ else
+ return f
+ end
elseif b then
- return b
+ return b
else
- local h = node_new(id_hlist)
- setfield(h, 'subtype', 0)
- setfield(h, 'width', 0)
- setfield(h, 'height', 0)
- setfield(h, 'depth', 0)
- setfield(h, 'glue_set', 0)
- setfield(h, 'glue_order', 0)
- setfield(h, 'head', nil)
- return h
+ local h = node_new(id_hlist)
+ setfield(h, 'subtype', 0)
+ setfield(h, 'width', 0)
+ setfield(h, 'height', 0)
+ setfield(h, 'depth', 0)
+ setfield(h, 'glue_set', 0)
+ setfield(h, 'glue_order', 0)
+ setfield(h, 'head', nil)
+ return h
end
end
end
local hh, hd = getfield(box, 'height'), getfield(box, 'depth')
local hx = h
while hx do
- local hic = has_attr(hx, attr_icflag) or 0
- if (hic == KANJI_SKIP) or (hic == KANJI_SKIP_JFM)
+ local hic = has_attr(hx, attr_icflag) or 0
+ if (hic == KANJI_SKIP) or (hic == KANJI_SKIP_JFM)
or (hic == XKANJI_SKIP) or (hic == XKANJI_SKIP_JFM)
or ((hic<=FROM_JFM+63) and (hic>=FROM_JFM)) then
- -- この 5 種類の空白をのばす
- if getid(hx) == id_kern then
- local k = node_new(id_glue)
- setglue(k, getfield(hx, 'kern'), round(middle*65536), 0,
- 2, 0)
- setfield(k, 'subtype', 0);
- h = insert_after(h, hx, k);
- h = node_remove(h, hx); node_free(hx); hx = k
- else -- glue
+ -- この 5 種類の空白をのばす
+ if getid(hx) == id_kern then
+ local k = node_new(id_glue)
+ setglue(k, getfield(hx, 'kern'), round(middle*65536), 0,
+ 2, 0)
+ setfield(k, 'subtype', 0);
+ h = insert_after(h, hx, k);
+ h = node_remove(h, hx); node_free(hx); hx = k
+ else -- glue
setglue(hx, getfield(hx, 'width'), round(middle*65536), 0,
- 2, 0)
- end
- end
- hx = node_next(hx)
+ 2, 0)
+ end
+ end
+ hx = node_next(hx)
end
-- 先頭の空白を挿入
local k = node_new(id_glue);
for i=1, #rtlr do node_free(rtlr[i]) end
for i=1, #rtlp do node_free(rtlp[i]) end
ltjb.package_error('luatexja-ruby',
- 'Group count mismatch between the ruby and\n' ..
- 'the body (' .. #rtlr .. ' != ' .. #rtlp .. ').',
- '')
+ 'Group count mismatch between the ruby and\n' ..
+ 'the body (' .. #rtlr .. ' != ' .. #rtlp .. ').',
+ '')
else
local f = true
for i = 1,#rtlr do
- if getfield(rtlr[i], 'width') > getfield(rtlp[i], 'width') then
- f = false; break
- end
+ if getfield(rtlr[i], 'width') > getfield(rtlp[i], 'width') then
+ f = false; break
+ end
end
if f then -- モノルビ * n
- local r,p = {true}, {true}
- for i = 1,#rtlr do
- r[1] = rtlr[i]; p[1] = rtlp[i]; texiface_low(rst, r, p)
- end
+ local r,p = {true}, {true}
+ for i = 1,#rtlr do
+ r[1] = rtlr[i]; p[1] = rtlp[i]; texiface_low(rst, r, p)
+ end
else
- local w, wv = texiface_low(rst, rtlr, rtlp)
- local id = make_uniq_id(w)
- set_attr(wv, attr_ruby_id, id)
+ local w, wv = texiface_low(rst, rtlr, rtlp)
+ local id = make_uniq_id(w)
+ set_attr(wv, attr_ruby_id, id)
end
end
end
else -- intmode == 3
local n = min(mapre, mapost)*2
if n < sumprot then
- pre_intrusion = n/2; post_intrusion = n/2
+ pre_intrusion = n/2; post_intrusion = n/2
else
- pre_intrusion = floor(sumprot/2); post_intrusion = sumprot - pre_intrusion
+ pre_intrusion = floor(sumprot/2); post_intrusion = sumprot - pre_intrusion
end
p = enlarge(p, rwidth, ppre, pmid, ppost, pre_intrusion, post_intrusion)
pre_intrusion = min(mapre, pre_intrusion + round(ppre*getfield(p, 'glue_set')*65536))
-- returned value: <new box>, <ruby width>, <post_intrusion>
local max_margin
local function new_ruby_box(r, p, ppre, pmid, ppost,
- mapre, mapost, imode, rgap)
+ mapre, mapost, imode, rgap)
local post_intrusion = 0
local intmode = imode%4
local rpre, rmid, rpost, rsmash
local need_repack = false
-- margin が大きくなりすぎた時の処理
if round(rpre*getfield(r, 'glue_set')*65536) > max_margin then
- local ps = getlist(r); need_repack = true
- setfield(ps, 'width', max_margin)
+ local ps = getlist(r); need_repack = true
+ setfield(ps, 'width', max_margin)
setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
end
if round(rpost*getfield(r, 'glue_set')*65536) > max_margin then
- local ps = node_tail(getlist(r)); need_repack = true
- setfield(ps, 'width', max_margin)
+ local ps = node_tail(getlist(r)); need_repack = true
+ setfield(ps, 'width', max_margin)
setfield(ps, 'stretch', 1) -- 全く伸縮しないのも困る
end
if need_repack then
- local rt = r
- r = node.direct.hpack(getlist(r), getfield(r, 'width'), 'exactly')
- setfield(rt, 'head', nil); node_free(rt);
+ local rt = r
+ r = node.direct.hpack(getlist(r), getfield(r, 'width'), 'exactly')
+ setfield(rt, 'head', nil); node_free(rt);
end
end
local a, k = node_new(id_rule), node_new(id_kern, 1)
for j = 1, 2*i do coef[i][j] = 1 end
for j = 2*i+1, 2*cmp+1 do coef[i][j] = 0 end
kf[i], coef[i][2*cmp+2]
- = new_ruby_box(node_copy(nta), node_copy(ntb),
- rtb[6], rtb[5], rtb[4], max_allow_pre, 0, intmode, rgap)
+ = new_ruby_box(node_copy(nta), node_copy(ntb),
+ rtb[6], rtb[5], rtb[4], max_allow_pre, 0, intmode, rgap)
end
node_free(nta); node_free(ntb)
for j = 2*i, 2*cmp+1 do coef[cmp+i][j] = 1 end
nta = concat(node_copy(rb[i]), nta); ntb = concat(node_copy(pb[i]), ntb)
kf[cmp+i], coef[cmp+i][2*cmp+2]
- = new_ruby_box(node_copy(nta), node_copy(ntb),
- rtb[9], rtb[8], rtb[7], 0, max_allow_post, intmode, rgap)
+ = new_ruby_box(node_copy(nta), node_copy(ntb),
+ rtb[9], rtb[8], rtb[7], 0, max_allow_post, intmode, rgap)
end
-- ここで,nta, ntb には全 container を連結した box が入っているので
set_attr(nta, attr_ruby, 2*i+1)
-- glue
if i~=cmp or not next_cluster_array[w] then
- nt = node_new(id_glue); insert_after(head, nta, nt)
+ nt = node_new(id_glue); insert_after(head, nta, nt)
else
- nt = next_cluster_array[w]
+ nt = next_cluster_array[w]
end
setglue(nt, coef[i*2+1][2*cmp+2], 0, 0, 0, 0)
set_attr(nt, attr_ruby, 2*i+2)
local function write_aux(wv, num)
local id = has_attr(wv, attr_ruby_id)
if id>0 and cache_handle then
- cache_handle:write(
- 'luatexja.ruby.old_break_info['
- .. tostring(id) .. ']=' .. num
- .. '\n')
+ cache_handle:write(
+ 'luatexja.ruby.old_break_info['
+ .. tostring(id) .. ']=' .. num
+ .. '\n')
end
end
local fn = has_attr(rs[#rs], attr_ruby)
local wv = getfield(rw, 'value')
if hn==1 then
- if fn==2*cmp+2 then
- local hn = node_tail(wv)
- node_remove(wv, hn)
- insert_after(ch, rs[1], hn)
- set_attr(hn, attr_icflag, PROCESSED)
- write_aux(wv, has_attr(hn, attr_ruby))-- 行中形
- else
- local deg, hn = (fn-1)/2, wv
- for i = 1, deg do hn = node_next(hn) end;
- node_remove(wv, hn)
- setfield(hn, 'next', nil)
- insert_after(ch, rs[1], hn)
- set_attr(hn, attr_icflag, PROCESSED)
- write_aux(wv, has_attr(hn, attr_ruby))
- end
+ if fn==2*cmp+2 then
+ local hn = node_tail(wv)
+ node_remove(wv, hn)
+ insert_after(ch, rs[1], hn)
+ set_attr(hn, attr_icflag, PROCESSED)
+ write_aux(wv, has_attr(hn, attr_ruby))-- 行中形
+ else
+ local deg, hn = (fn-1)/2, wv
+ for i = 1, deg do hn = node_next(hn) end;
+ node_remove(wv, hn)
+ setfield(hn, 'next', nil)
+ insert_after(ch, rs[1], hn)
+ set_attr(hn, attr_icflag, PROCESSED)
+ write_aux(wv, has_attr(hn, attr_ruby))
+ end
else
- local deg, hn = max((hn-1)/2,2), wv
- for i = 1, cmp+deg-1 do hn = node_next(hn) end
- -- -1 is needed except the case hn = 3,
- -- because a ending-line form is removed already from the list
- node_remove(wv, hn); setfield(hn, 'next', nil)
- insert_after(ch, rs[1], hn)
- set_attr(hn, attr_icflag, PROCESSED)
- if fn == 2*cmp-1 then
- write_aux(wv, has_attr(hn, attr_ruby))
- end
+ local deg, hn = max((hn-1)/2,2), wv
+ for i = 1, cmp+deg-1 do hn = node_next(hn) end
+ -- -1 is needed except the case hn = 3,
+ -- because a ending-line form is removed already from the list
+ node_remove(wv, hn); setfield(hn, 'next', nil)
+ insert_after(ch, rs[1], hn)
+ set_attr(hn, attr_icflag, PROCESSED)
+ if fn == 2*cmp-1 then
+ write_aux(wv, has_attr(hn, attr_ruby))
+ end
end
for i = 1,#rs do
- local ri = rs[i]
- ch = node_remove(ch, ri); node_free(ri);
+ local ri = rs[i]
+ ch = node_remove(ch, ri); node_free(ri);
end
-- cleanup
if fn >= 2*cmp+1 then node_free(rw) end
for i = 1, #rs do rs[i] = nil end
local ha = getlist(h)
while ha do
- local hai = getid(ha)
- local i = ((hai == id_glue and getsubtype(ha)==0)
+ local hai = getid(ha)
+ local i = ((hai == id_glue and getsubtype(ha)==0)
or (hai == id_rule and getsubtype(ha)==0)
or (hai == id_whatsit and getsubtype(ha)==sid_user
and getfield(ha, 'user_id', RUBY_POST)))
and has_attr(ha, attr_ruby) or 0
- if i==0 then
+ if i==0 then
ha = node_next(ha)
elseif i==1 then
- setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
- for i = 2, #rs do rs[i] = nil end -- rs[1] is set by the next statement
- rs[1], rw = ha, nil; ha = node_next(ha)
- elseif i==2 then
- rw = ha
- cmp = getfield(getfield(rw, 'value'), 'value')
- local hb, hc = node_remove(getlist(h), rw)
- setfield(h, 'head', hb); ha = hc
- else -- i>=3
- rs[#rs+1] = ha; ha = node_next(ha)
- end
+ setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
+ for i = 2, #rs do rs[i] = nil end -- rs[1] is set by the next statement
+ rs[1], rw = ha, nil; ha = node_next(ha)
+ elseif i==2 then
+ rw = ha
+ cmp = getfield(getfield(rw, 'value'), 'value')
+ local hb, hc = node_remove(getlist(h), rw)
+ setfield(h, 'head', hb); ha = hc
+ else -- i>=3
+ rs[#rs+1] = ha; ha = node_next(ha)
+ end
end
setfield(h, 'head', post_lown(rs, rw, cmp, getlist(h)))
end
elseif i==1 then
head = post_lown(rs, rw, cmp, head)
for i = 2, #rs do rs[i] = nil end -- rs[1] is set by the next statement
- rs[1], rw = ha, nil; ha = node_next(ha)
+ rs[1], rw = ha, nil; ha = node_next(ha)
elseif i==2 then
rw = ha
- cmp = getfield(getfield(rw, 'value'), 'value')
- head, ha = node_remove(head, rw)
+ cmp = getfield(getfield(rw, 'value'), 'value')
+ head, ha = node_remove(head, rw)
else -- i >= 3
rs[#rs+1] = ha; ha = node_next(ha)
end
local RIPOST = luatexja.stack_table_index.RIPOST
local function whatsit_after_callback(s, Nq, Np)
if not s and getfield(Nq.nuc, 'user_id') == RUBY_PRE then
- if Np then
- local last_glue = node_new(id_glue)
- set_attr(last_glue, attr_icflag, 0)
- insert_before(Nq.nuc, Np.first, last_glue)
- Np.first = last_glue
- next_cluster_array[Nq.nuc] = last_glue -- ルビ処理用のグルー
- end
+ if Np then
+ local last_glue = node_new(id_glue)
+ set_attr(last_glue, attr_icflag, 0)
+ insert_before(Nq.nuc, Np.first, last_glue)
+ Np.first = last_glue
+ next_cluster_array[Nq.nuc] = last_glue -- ルビ処理用のグルー
+ end
local nqnv = getfield(Nq.nuc, 'value')
local x = node_next(node_next(nqnv))
for i = 2, getfield(nqnv, 'value') do x = node_next(node_next(x)) end
Nq.last_char = luatexja.jfmglue.check_box_high(Nq, getlist(x), nil)
luatexja.jfmglue.after_hlist(Nq)
if Np and Np.id ~=id_pbox_w and type(Np.char)=='number' then
- -- Np is a JAchar
- local rm = has_attr(nqnv, attr_ruby_mode)
+ -- Np is a JAchar
+ local rm = has_attr(nqnv, attr_ruby_mode)
if has_attr(nqnv, attr_ruby_maxpostp) < 0 then -- auto
local p = round((ltjs.table_current_stack[RIPOST + Np.char] or 0)
*has_attr(nqnv, attr_ruby))
set_attr(nqnv, attr_ruby_maxpostp, p)
end
Np.prev_ruby = has_attr(getfield(Nq.nuc, 'value'), attr_ruby_id)
- -- 前のクラスタがルビであったことのフラグ
+ -- 前のクラスタがルビであったことのフラグ
else -- 直前が文字以外
- local nqnv = getfield(Nq.nuc, 'value')
+ local nqnv = getfield(Nq.nuc, 'value')
if has_attr(nqnv, attr_ruby_maxpostp) < 0 then -- auto
- set_attr(nqnv, attr_ruby_maxpostp, 0)
- if has_attr(nqnv, attr_ruby_mode)%4 >= 2 then
- set_attr(nqnv, attr_ruby_maxprep, 0)
- end
- end
+ set_attr(nqnv, attr_ruby_maxpostp, 0)
+ if has_attr(nqnv, attr_ruby_mode)%4 >= 2 then
+ set_attr(nqnv, attr_ruby_maxprep, 0)
+ end
+ end
end
- return true
+ return true
else
- return s
+ return s
end
end
luatexbase.add_to_callback("luatexja.jfmglue.whatsit_after", whatsit_after_callback,
-- ltj-setwidth.lua
--
-luatexja.load_module('base'); local ltjb = luatexja.base
-luatexja.load_module('stack'); local ltjs = luatexja.stack
-luatexja.load_module('jfont'); local ltjf = luatexja.jfont
-luatexja.load_module('direction'); local ltjd = luatexja.direction
-luatexja.load_module('lotf_aux'); local ltju = luatexja.lotf_aux
+luatexja.load_module 'base'; local ltjb = luatexja.base
+luatexja.load_module 'stack'; local ltjs = luatexja.stack
+luatexja.load_module 'jfont'; local ltjf = luatexja.jfont
+luatexja.load_module 'direction'; local ltjd = luatexja.direction
+luatexja.load_module 'lotf_aux'; local ltju = luatexja.lotf_aux
local setfield = node.direct.setfield
local getfield = node.direct.getfield
local node_insert_after = node.direct.insert_after
local round = tex.round
-local id_glyph = node.id('glyph')
-local id_kern = node.id('kern')
-local id_hlist = node.id('hlist')
-local id_vlist = node.id('vlist')
-local id_rule = node.id('rule')
-local id_math = node.id('math')
-local id_whatsit = node.id('whatsit')
-local sid_save = node.subtype('pdf_save')
-local sid_restore = node.subtype('pdf_restore')
-local sid_matrix = node.subtype('pdf_setmatrix')
+local id_glyph = node.id 'glyph'
+local id_kern = node.id 'kern'
+local id_hlist = node.id 'hlist'
+local id_vlist = node.id 'vlist'
+local id_rule = node.id 'rule'
+local id_math = node.id 'math'
+local id_whatsit= node.id 'whatsit'
+local sid_save = node.subtype 'pdf_save'
+local sid_restore = node.subtype 'pdf_restore'
+local sid_matrix = node.subtype 'pdf_setmatrix'
local dir_tate = luatexja.dir_table.dir_tate
local attr_ykblshift = luatexbase.attributes['ltj@ykblshift']
luatexja.setwidth = ltjw
luatexbase.create_callback("luatexja.set_width", "data",
- function (fstable, fmtable, char_data)
- return fstable
- end)
+ function (fstable, fmtable, char_data)
+ return fstable
+ end)
local call_callback = luatexbase.call_callback
local fshift = { down = 0, left = 0 }
if ht_diff == 0 and dp_diff ==0 then -- offset only
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
+ 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)
+ local box = node_new(id_rule,rule_subtype)
local xo, yo = getoffsets(p)
- setoffsets(p, xo, yo - kbl - fshift.down)
- setwhd(box, 0, fheight - kbl, fdepth + kbl)
- setdir(box, dir)
- set_attr(box, attr_icflag, PACKED)
- set_attr(p, attr_icflag, PROCESSED)
- head = p and node_insert_before(head, p, box)
- or node_insert_after(head, node_tail(head), box)
- return node_next(p), head, p, box
+ setoffsets(p, xo, yo - kbl - fshift.down)
+ setwhd(box, 0, fheight - kbl, fdepth + kbl)
+ setdir(box, dir)
+ set_attr(box, attr_icflag, PACKED)
+ set_attr(p, attr_icflag, PROCESSED)
+ head = p and node_insert_before(head, p, box)
+ or node_insert_after(head, node_tail(head), box)
+ return node_next(p), head, p, box
end
end
if char_data.round_threshold then
local frac = pwidth / fwidth
local quot = floor(frac+0.5)
- if abs(frac-quot) <char_data.round_threshold then fwidth = fwidth * quot end
+ if abs(frac-quot) <char_data.round_threshold then fwidth = fwidth * quot end
end
end
local xo, yo = getoffsets(p)
local pf, pc = getfont(p), getchar(p)
local feir = ltjf_font_extra_info[pf]
if feir and feir.rotation and met.vert_activated then
- if feir.rotation[pc] and (has_attr(p, attr_vert_ori) or 0)<=0 then
- return capsule_glyph_tate_rot(p, met, char_data, head, dir,
+ if feir.rotation[pc] and (has_attr(p, attr_vert_ori) or 0)<=0 then
+ return capsule_glyph_tate_rot(p, met, char_data, head, dir,
0.5*(get_ascender(pf)-get_descender(pf)))
- end
+ end
end
pwidth, ascender = feir.vheight[pc]*met.size, feir.vorigin[pc]*met.size
end
for p in node_traverse(head) do
local pid = getid(p)
if p==last then
- return
+ return
elseif (has_attr(p, attr_icflag) or 0) ~= PROCESSED then
- if pid==id_hlist or pid==id_vlist then
- setfield(p, 'shift', getfield(p, 'shift') + (has_attr(p,attr_ablshift) or 0))
- elseif pid==id_rule then
- local v = has_attr(p,attr_ablshift) or 0
- setfield(p, 'height', getfield(p, 'height')-v)
- setfield(p, 'depth', getdepth(p)+v)
- set_attr(p, attr_icflag, PROCESSED)
- elseif pid==id_glyph then
- -- 欧文文字; 和文文字は pid == id_hlist の場合で処理される
- -- (see conv_jchar_to_hbox_A in ltj-math.lua)
- setfield(p, 'yoffset',
- getfield(p, 'yoffset') - (has_attr(p,attr_ablshift) or 0))
- end
+ if pid==id_hlist or pid==id_vlist then
+ setfield(p, 'shift', getfield(p, 'shift') + (has_attr(p,attr_ablshift) or 0))
+ elseif pid==id_rule then
+ local v = has_attr(p,attr_ablshift) or 0
+ setfield(p, 'height', getfield(p, 'height')-v)
+ setfield(p, 'depth', getdepth(p)+v)
+ set_attr(p, attr_icflag, PROCESSED)
+ elseif pid==id_glyph then
+ -- 欧文文字; 和文文字は pid == id_hlist の場合で処理される
+ -- (see conv_jchar_to_hbox_A in ltj-math.lua)
+ setfield(p, 'yoffset',
+ getfield(p, 'yoffset') - (has_attr(p,attr_ablshift) or 0))
+ end
set_attr(p, attr_icflag, PROCESSED)
end
end
if not head then return end
local y_adjust, node_depth, adj_depth = 0, 0, 0
for lp in node_traverse_id(id_glyph, head) do
- y_adjust = has_attr(lp,attr_ablshift) or 0
- local ld = getdepth(lp)
- node_depth = max(ld + min(y_adjust, 0), node_depth)
- adj_depth = (y_adjust>0) and max(ld + y_adjust, adj_depth) or adj_depth
- setfield(lp, 'yoffset', getfield(lp, 'yoffset') - y_adjust)
+ y_adjust = has_attr(lp,attr_ablshift) or 0
+ local ld = getdepth(lp)
+ node_depth = max(ld + min(y_adjust, 0), node_depth)
+ adj_depth = (y_adjust>0) and max(ld + y_adjust, adj_depth) or adj_depth
+ setfield(lp, 'yoffset', getfield(lp, 'yoffset') - y_adjust)
end
if adj_depth>node_depth then
- local r = node_new(id_rule,rule_subtype)
- setwhd(r, 0, 0, adj_depth); setdir(r, tex_dir)
- set_attr(r, attr_icflag, PROCESSED)
- if field=='post' then
- node_insert_after(head, head, r)
- else
- setfield(disc, field, (node_insert_before(head, head, r)))
- end
+ local r = node_new(id_rule,rule_subtype)
+ setwhd(r, 0, 0, adj_depth); setdir(r, tex_dir)
+ set_attr(r, attr_icflag, PROCESSED)
+ if field=='post' then
+ node_insert_after(head, head, r)
+ else
+ setfield(disc, field, (node_insert_before(head, head, r)))
+ end
end
end
function luatexja.setwidth.apply_ashift_disc(d, is_dir_tate, dir)
attr_ablshift = is_dir_tate and attr_tablshift or attr_yablshift
disc, tex_dir = d, dir
- ashift_disc_inner('pre')
- ashift_disc_inner('post')
- ashift_disc_inner('replace')
+ ashift_disc_inner 'pre'
+ ashift_disc_inner 'post'
+ ashift_disc_inner 'replace'
end
end
--
luatexbase.provides_module({
name = 'luatexja.stack',
- date = '2019/09/26',
+ date = '2020-07-30',
description = 'LuaTeX-ja stack system',
})
luatexja.stack = {}
local ltjs=luatexja.stack
-luatexja.load_module('base'); local ltjb = luatexja.base
+luatexja.load_module 'base'; local ltjb = luatexja.base
--------------------------------------------------------------------------------
-- stack table (obeys TeX's grouping)
--------------------------------------------------------------------------------
local node_new = node.new
-local id_whatsit = node.id('whatsit')
-local sid_user = node.subtype('user_defined')
+local id_whatsit = node.id 'whatsit'
+local sid_user = node.subtype 'user_defined'
local STCK = luatexja.userid_table.STCK
local fastcopy = table.fastcopy
local setcount, getcount = tex.setcount, tex.getcount
charprop_stack_table[0]={}
local function get_stack_level()
- local i = getcount('ltj@@stack')
+ local i = getcount 'ltj@@stack'
local j = tex.currentgrouplevel
- if j > getcount('ltj@@group@level') then
+ if j > getcount 'ltj@@group@level' then
i = i+1 -- new stack level
local gd = tex.globaldefs
if gd~=0 then tex.globaldefs = 0 end
-- 'tex.globaldefs = 0' is local even if \globaldefs > 0.
setcount('ltj@@group@level', j)
for k,v in pairs(charprop_stack_table) do -- clear the stack above i
- if k>=i then charprop_stack_table[k]=nil end
+ if k>=i then charprop_stack_table[k]=nil end
end
charprop_stack_table[i] = fastcopy(charprop_stack_table[i-1])
setcount('ltj@@stack', i)
if gd~=0 then tex.globaldefs = gd end
if tex.nest[tex.nest.ptr].mode == -ltjs.hmode then -- rest. hmode のみ
- local g = node_new(id_whatsit, sid_user)
- g.user_id=STCK; g.type=100; g.value=j; node.write(g)
+ local g = node_new(id_whatsit, sid_user)
+ g.user_id=STCK; g.type=100; g.value=j; node.write(g)
end
end
return i
local p = tonumber((getter or scan_int)())
if p<lb or p>ub then
ltjb.package_error('luatexja',
- "invalid code (".. tostring(p) .. ")",
- "The code should in the range "..tostring(lb) .. '..' ..
- tostring(ub) .. ".\n" ..
- "I'm going to use 0 instead of that illegal code value.")
+ "invalid code (".. tostring(p) .. ")",
+ "The code should in the range "..tostring(lb) .. '..' ..
+ tostring(ub) .. ".\n" ..
+ "I'm going to use 0 instead of that illegal code value.")
p=0
end
set_stack_table(m+ltjb.in_unicode(c, true), p)
function ltjs.set_stack_font(m,c,p)
if type(c)~='number' or c<0 or c>255 then
ltjb.package_error('luatexja',
- "invalid family number (".. tostring(c) .. ")",
- "The family number should in the range 0 .. 255.\n" ..
- "I'm going to use 0 instead of that illegal family number.")
+ "invalid family number (".. tostring(c) .. ")",
+ "The family number should in the range 0 .. 255.\n" ..
+ "I'm going to use 0 instead of that illegal family number.")
c=0
end
set_stack_table(m+c, p)
charprop_stack_table[i][m].shrink_order = sp.shrink_order
if luatexja.isglobal=='global' then
for j,v in pairs(charprop_stack_table) do
- if not charprop_stack_table[j][m] then charprop_stack_table[j][m] = {} end
- charprop_stack_table[j][m].width = sp.width
- charprop_stack_table[j][m].stretch = sp.stretch
- charprop_stack_table[j][m].shrink = sp.shrink
- charprop_stack_table[j][m].stretch_order = sp.stretch_order
- charprop_stack_table[j][m].shrink_order = sp.shrink_order
+ if not charprop_stack_table[j][m] then charprop_stack_table[j][m] = {} end
+ charprop_stack_table[j][m].width = sp.width
+ charprop_stack_table[j][m].stretch = sp.stretch
+ charprop_stack_table[j][m].shrink = sp.shrink
+ charprop_stack_table[j][m].stretch_order = sp.stretch_order
+ charprop_stack_table[j][m].shrink_order = sp.shrink_order
end
end
end
\def\@ltj@hook@family#1#2{ % #1: csname #2: contents
\ifcsname @#1hook\endcsname % LaTeX 2020-02-02
- \csappto{@#1hook}{#2}%
+ \csappto{@#1hook}{#2}%
\else % LaTeX 2019-10-01
- \ifcsname #1 \endcsname
- \expandafter\patchcmd\csname #1 \endcsname{\selectfont}{#2\selectfont}{}{}%
- \else
- \PackageWarningNoLine{luatexja}{%
- Patching to \expandafter\string\csname #1\endcsname\space failed%
- }%
- \fi
+ \ifcsname #1 \endcsname
+ \expandafter\patchcmd\csname #1 \endcsname{\selectfont}{#2\selectfont}{}{}%
+ \else
+ \PackageWarningNoLine{luatexja}{%
+ Patching to \expandafter\string\csname #1\endcsname\space failed%
+ }%
+ \fi
\fi
}
\@ltj@hook@family{rmfamily}{%
\every@math@size{}%
\fontsize{#6}\z@
\ltj@@is@kyenc{#2}\ifin@%
- \ltjselectfont@force@definetrue
+ \ltjselectfont@force@definetrue
\usekanji{#2}{#3}{#4}{#5}%
\global\let#1\getjfont
- \ltjselectfont@force@definefalse
+ \ltjselectfont@force@definefalse
\else
\ltj@@is@ktenc{#2}\ifin@%
- \ltjselectfont@force@definetrue
+ \ltjselectfont@force@definetrue
\usekanji{#2}{#3}{#4}{#5}%
\global\let#1\gettfont
- \ltjselectfont@force@definefalse
+ \ltjselectfont@force@definefalse
\else
\useroman{#2}{#3}{#4}{#5}%
\global\expandafter\let\expandafter#1\the\font
\xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
\pickup@jfont
\unless\ifnum\ltjgetparameter{direction}=3 \font@name
- \ltj@@does@alt@set{\curr@kfontshape}{%
+ \ltj@@does@alt@set{\curr@kfontshape}{%
% alt fonts の定義
\directlua{luatexja.jfont.output_alt_font_cmd('y', '\luatexluaescapestring{\curr@kfontshape}')}%
% 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
\bgroup
\def\ltj@@dir@patch#1#2#3{%
\global\csletcs{ltj@@orig@#1}{#1}%
- \protected\expandafter\xdef\csname #1\endcsname{%
- \csname ltj@@orig@#1\endcsname
+ \protected\expandafter\xdef\csname #1\endcsname{%
+ \csname ltj@@orig@#1\endcsname
\unexpanded{\ifnum#3<\z@\let\ltj@@protect\protect\set@typeset@protect}%
\unexpanded{\global\let\ltj@afont@name=\font@name}%
- \expandonce{\csname ltj@selectfont@#2\endcsname}%
+ \expandonce{\csname ltj@selectfont@#2\endcsname}%
\unexpanded{\global\let\font@name=\ltj@afont@name}%
\unexpanded{\let\protect\ltj@@protect\fi}%
- }%
+ }%
}
\ltj@@dir@patch{yoko}{yoko}{\ltj@curjfnt}
\ltj@@dir@patch{tate}{tate}{\ltj@curtfnt}
\else
\@tempswafalse
\def\cdp@elt##1{\ifcsname ##1+#1\endcsname%
- \@tempswatrue\def\cdp@elt####1\relax{}%
+ \@tempswatrue\def\cdp@elt####1\relax{}%
\fi}%
\directlua{luatexja.jfont.search_ffam_declared()}\relax%
\if@tempswz
}
\else % !!! pl 3, 4
\def\set@target@series@kanji#1{%
- \edef\k@series{#1}%
- \edef\k@series{\expandafter\series@drop@one@m\k@series mm\series@drop@one@m}%
+ \edef\k@series{#1}%
+ \edef\k@series{\expandafter\series@drop@one@m\k@series mm\series@drop@one@m}%
}
\fi\fi
\set@target@series@kanji{#2}%
\else
\begingroup\let\f@encoding\k@encoding\let\f@family\k@family
- \maybe@load@fontshape\endgroup
+ \maybe@load@fontshape\endgroup
\edef\reserved@a{\k@encoding /\k@family /#1/\k@shape}%
\ifcsname \reserved@a \endcsname
\set@target@series@kanji{#1}%
\fi
\else
\begingroup\let\f@encoding\k@encoding\let\f@family\k@family
- \maybe@load@fontshape\endgroup
+ \maybe@load@fontshape\endgroup
\edef\reserved@a{\k@encoding /\k@family /\k@series/#1}%
\ifcsname \reserved@a\endcsname
\edef\k@shape{#1}%
\let\extract@afont\extract@font
\def\pickup@jfont{%
\ifnum
- \unless\ifnum\ltjgetparameter{direction}=3 1\else
- \ifltjselectfont@force@define 1\else 0\fi\fi =1 %
+ \unless\ifnum\ltjgetparameter{direction}=3 1\else
+ \ifltjselectfont@force@define 1\else 0\fi\fi =1 %
\expandafter \ifx \font@name \relax
\let\extract@font\extract@jfont
\define@newfont
\fi
\let\getjfont\font@name
\else
- \begingroup\escapechar\m@ne
- \ifcsname ltj@@fontjfm/\expandafter\string\font@name\endcsname\else
- \let\extract@font\extract@jfont@onlyjfm
- \define@newfont
- \let\extract@font\extract@afont
- \fi
- \endgroup
- \csname ltj@@fontjfm/\expandafter\expandafter\expandafter\@gobble\expandafter\string\font@name\endcsname
+ \begingroup\escapechar\m@ne
+ \ifcsname ltj@@fontjfm/\expandafter\string\font@name\endcsname\else
+ \let\extract@font\extract@jfont@onlyjfm
+ \define@newfont
+ \let\extract@font\extract@afont
+ \fi
+ \endgroup
+ \csname ltj@@fontjfm/\expandafter\expandafter\expandafter\@gobble\expandafter\string\font@name\endcsname
\fi
}
\def\pickup@tfont{%
\ifnum
- \ifnum\ltjgetparameter{direction}=3 1\else
- \ifltjselectfont@force@define 1\else 0\fi\fi =1 %
+ \ifnum\ltjgetparameter{direction}=3 1\else
+ \ifltjselectfont@force@define 1\else 0\fi\fi =1 %
\expandafter \ifx \font@name \relax
\let\extract@font\extract@tfont
\define@newfont
\fi
\let\gettfont\font@name
\else
- \begingroup\escapechar\m@ne
- \ifcsname ltj@@fontjfm/\expandafter\string\font@name\endcsname\else
- \let\extract@font\extract@tfont@onlyjfm
- \define@newfont
- \let\extract@font\extract@afont
- \fi
- \endgroup
- \csname ltj@@fontjfm/\expandafter\expandafter\expandafter\@gobble\expandafter\string\font@name\endcsname
+ \begingroup\escapechar\m@ne
+ \ifcsname ltj@@fontjfm/\expandafter\string\font@name\endcsname\else
+ \let\extract@font\extract@tfont@onlyjfm
+ \define@newfont
+ \let\extract@font\extract@afont
+ \fi
+ \endgroup
+ \csname ltj@@fontjfm/\expandafter\expandafter\expandafter\@gobble\expandafter\string\font@name\endcsname
\fi
}
% わざと「ゴミをつける」
\def\ltj@@patch@external@font#1 at{%
\directlua{
- local s = '\luatexluaescapestring{#1}'
- local is_braced, is_quoted
- if s:sub(1,1)=='{' and s:sub(-1)=='}' then is_braced=true; s=s:sub(2,-2) end
- if s:sub(1,1)=='"' and s:sub(-1)=='"' then is_quoted=true; s=s:sub(2,-2) end
- s=s..luatexja.jfont.print_aftl_address()
- if is_braced then s='{'..s..'}' elseif is_quoted then s='"'..s..'"' end
- %print(s, is_quoted, is_braced)
+ local s = '\luatexluaescapestring{#1}'
+ local is_braced, is_quoted
+ if s:sub(1,1)=='{' and s:sub(-1)=='}' then is_braced=true; s=s:sub(2,-2) end
+ if s:sub(1,1)=='"' and s:sub(-1)=='"' then is_quoted=true; s=s:sub(2,-2) end
+ s=s..luatexja.jfont.print_aftl_address()
+ if is_braced then s='{'..s..'}' elseif is_quoted then s='"'..s..'"' end
+ %print(s, is_quoted, is_braced)
tex.sprint(-2, s)}%
\space at%
}
\def\extract@jfont{%
- \get@external@font
+ \get@external@font
\ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}{%
\edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
}%
\csname \f@encoding+\f@family\endcsname
\csname\curr@fontshape\endcsname}
\def\extract@tfont{%
- \get@external@font
+ \get@external@font
\ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}{%
\edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
}%
}
\luadef\ltj@@jfont@@jfmonly \ltj@@jfont@@jfmonly@@inner
\def\extract@jfont@onlyjfm{%
- \get@external@font
- \csxdef{ltj@@fontjfm/\expandafter\string\font@name}{%
- \ltj@@jfont@@jfmonly{\external@font}{yoko}%
- }}
+ \get@external@font
+ \csxdef{ltj@@fontjfm/\expandafter\string\font@name}{%
+ \ltj@@jfont@@jfmonly{\external@font}{yoko}%
+}}
\def\extract@tfont@onlyjfm{%
- \get@external@font
- \csxdef{ltj@@fontjfm/\expandafter\string\font@name}{%
- \ltj@@jfont@@jfmonly{\external@font}{tate}%
- }}
+ \get@external@font
+ \csxdef{ltj@@fontjfm/\expandafter\string\font@name}{%
+ \ltj@@jfont@@jfmonly{\external@font}{tate}%
+}}
\let\ltj@@al@do@subst@correction=\do@subst@correction
\def\ltj@@ja@do@subst@correction{%
\math@bgroup
\expandafter\ifx\csname M@\f@encoding\endcsname#1\else
#1\fi\ltj@tempcnta=#2
- \expandafter\ltj@@mathJapaneseFonts\string#1/\relax%
+ \expandafter\ltj@@mathJapaneseFonts\string#1/\relax%
\ifin@\jfam#2\relax\else\mathgroup#2\relax\fi
\expandafter\math@egroup\fi}%
\the\ltj@tempcnta,\the\ltj@tempcntb,
'\luatexluaescapestring{\ltj@temp@afont}',
'\luatexluaescapestring{\ltj@temp@bfont}')}%
- }
+}
%%%% \ClearAlternateKanjiFont<Benc><Bfam><Bser><Bshape>
% いつも global
\ltj@@getjfontnumber#1%
\directlua{luatexja.jfont.pickup_alt_font_b(\the\ltj@tempcntc,'\luatexluaescapestring{#2}')}%
}
-
-%%%% patch \@text@composite because of {y,t}albaselineshift
-
-% %% \pltx@isletter from plfonts.dtx
-% \def\pltx@mark{\pltx@mark@}
-% \let\pltx@scanstop\relax
-% \long\def\pltx@cond#1\fi{%
-% #1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
-% \long\def\pltx@isletter#1{%
-% \expandafter\pltx@isletter@i#1\pltx@scanstop}
-% \long\def\pltx@isletter@i#1\pltx@scanstop{%
-% \pltx@cond\ifx\pltx@mark#1\pltx@mark\fi{\@firstoftwo}%
-% {\pltx@isletter@ii\pltx@scanstop#1\pltx@scanstop{}#1\pltx@mark}}
-% \long\def\pltx@isletter@ii#1\pltx@scanstop#{%
-% \pltx@cond\ifx\pltx@mark#1\pltx@mark\fi%
-% {\pltx@isletter@iii}{\pltx@isletter@iv}}
-% \long\def\pltx@isletter@iii#1\pltx@mark{\@secondoftwo}
-% \long\def\pltx@isletter@iv#1#2#3\pltx@mark{%
-% \pltx@cond\ifx\pltx@mark#3\pltx@mark\fi{%
-% \pltx@cond{\ifnum0\ifcat A\noexpand#21\fi\ifcat=\noexpand#21\fi>\z@}\fi
-% {\@firstoftwo}{\@secondoftwo}%
-% }{\@secondoftwo}}
-%
-% \def\@text@composite@x#1#2{%
-% \ifx#1\relax
-% #2%
-% \else\pltx@isletter{#1}{#1}{%
-% \begingroup
-% \setbox\z@\hbox\bgroup%
-% \ltj@yablshift\z@ \ltj@tablshift\z@
-% #1%
-% \@tempcntb\directlua{luatexja.pltx_composite_last_node_char()}%)
-% \xdef\pltx@composite@temp{\noexpand\@tempcntb=\the\@tempcntb\relax}%
-% \aftergroup\pltx@composite@temp
-% \egroup
-% \ifnum\ltjgetparameter{direction}=3 %
-% \@tempdima=\ltj@tablshift sp\else\@tempdima=\ltj@yablshift sp\fi
-% \ifnum\@tempcntb<\z@\@tempcnta\z@\else
-% \@tempcnta=\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{\@tempcntb}}\relax
-% \ifnum\@tempcnta=\z@\@tempdima\z@\fi
-% \fi
-% \ifnum\@tempcnta>\z@
-% \ifodd\ltjgetparameter{alxspmode}{\@tempcntb}\else\leavevmode\hbox{}\fi
-% \begingroup\mathsurround\z@$%
-% \hbox{\lower\@tempdima\box\z@}
-% $\endgroup%
-% \ifnum\ltjgetparameter{alxspmode}{\@tempcntb}<2\hbox{}\fi
-% \else
-% \ifdim\@tempdima=\z@{\ltj@yablshift\z@ \ltj@tablshift\z@#1}%
-% \else\lower\@tempdima\box\z@\fi
-% \fi
-% \endgroup}%
-% \fi
-% }
-
\endinput