+do
+ -- these function are called from ltj-latex.sty
+ local fenc_list, kyenc_list, ktenc_list = {}, {}, {}
+ function add_fenc_list(enc) fenc_list[enc] = 'true ' end
+ function add_kyenc_list(enc) kyenc_list[enc] = 'true ' end
+ function add_ktenc_list(enc) ktenc_list[enc] = 'true ' end
+ function is_kyenc(enc)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (kyenc_list[enc] or 'false '))
+ end
+ function is_ktenc(enc)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (ktenc_list[enc] or 'false '))
+ end
+ function is_kenc(enc)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if'
+ .. (kyenc_list[enc] or ktenc_list[enc] or 'false '))
+ end
+
+ local kfam_list, Nkfam_list = {}, {}
+ function add_kfam(fam)
+ kfam_list[fam]=true
+ end
+ function search_kfam(fam, use_fd)
+ if kfam_list[fam] then
+ tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
+ elseif Nkfam_list[fam] then
+ tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
+ elseif use_fd then
+ for i,_ in pairs(kyenc_list) do
+ if kpse.find_file(string.lower(i)..fam..'.fd') then
+ tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
+ end
+ end
+ for i,_ in pairs(ktenc_list) do
+ if kpse.find_file(string.lower(i)..fam..'.fd') then
+ tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
+ end
+ end
+ Nkfam_list[fam]=true; tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
+ else
+ tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
+ end
+ end
+ local ffam_list, Nffam_list = {}, {}
+ function is_ffam(fam)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (ffam_list[fam] or 'false '))
+ end
+ function add_ffam(fam)
+ ffam_list[fam]='true '
+ end
+ function search_ffam_declared()
+ local s = ''
+ for i,_ in pairs(fenc_list) do
+ s = s .. '\\cdp@elt{' .. i .. '}'
+ end
+ tex.sprint(cat_lp, s)
+ end
+ function search_ffam_fd(fam)
+ if Nffam_list[fam] then
+ tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
+ else
+ for i,_ in pairs(fenc_list) do
+ if kpse.find_file(string.lower(i)..fam..'.fd') then
+ tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
+ end
+ end
+ Nffam_list[fam]=true; tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
+ end
+ end
+
+end
+------------------------------------------------------------------------
+-- ALTERNATE FONTS
+------------------------------------------------------------------------
+alt_font_table = {}
+local alt_font_table = alt_font_table
+local attr_curaltfnt = {}
+local ucs_out = 0x110000
+
+------ for TeX interface
+-- EXT
+function set_alt_font(b,e,ind,bfnt)
+ -- ind: 新フォント, bfnt: 基底フォント
+ if b>e then b, e = e, b end
+ if b*e<=0 then
+ ltjb.package_error('luatexja',
+ 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
+ 'I take the intersection with [0x80, 0x10ffff].')
+ b, e = math.max(0x80,b),math.min(ucs_out-1,e)
+ elseif e<0 then -- b<e<0
+ -- do nothing
+ elseif b<0x80 or e>=ucs_out then
+ ltjb.package_warning('luatexja',
+ 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
+ 'I take the intersection with [0x80, 0x10ffff].')
+ b, e = math.max(0x80,b), math.min(ucs_out-1,e)
+ end
+ if not alt_font_table[bfnt] then alt_font_table[bfnt]={} end
+ local t = alt_font_table[bfnt]
+ local ac = font_getfont(ind).characters
+ if bfnt==ind then ind = nil end -- ind == bfnt の場合はテーブルから削除
+ if e>=0 then -- character range
+ for i=b, e do
+ if ac[i]then t[i]=ind end
+ end
+ else
+ b, e = -e, -b
+ local tx = font_metric_table[bfnt].chars
+ for i,v in pairs(tx) do
+ if b<=v and v<=e and ac[i] then t[i]=ind end
+ end
+ end
+end