+do
+ -- these function are called from ltj-latex.sty
+ local kyenc_list, ktenc_list = {}, {}
+ 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_list(enc, fam)
+ if not kfam_list[enc] then kfam_list[enc] = {} end
+ kfam_list[enc][fam] = 'true '
+ end
+ function add_Nkfam_list(enc, fam)
+ if not Nkfam_list[enc] then Nkfam_list[enc] = {} end
+ Nkfam_list[enc][fam] = 'true '
+ end
+ function is_kfam(enc, fam)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if'
+ .. (kfam_list[enc] and kfam_list[enc][fam] or 'false ')) end
+ function is_Nkfam(enc, fam)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if'
+ .. (Nkfam_list[enc] and Nkfam_list[enc][fam] or 'false ')) end
+
+ local ffam_list, Nffam_list = {}, {}
+ function add_ffam_list(enc, fam)
+ if not ffam_list[enc] then ffam_list[enc] = {} end
+ ffam_list[enc][fam] = 'true '
+ end
+ function add_Nffam_list(enc, fam)
+ if not Nffam_list[enc] then Nffam_list[enc] = {} end
+ Nffam_list[enc][fam] = 'true '
+ end
+ function is_ffam(enc, fam)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if'
+ .. (ffam_list[enc] and ffam_list[enc][fam] or 'false ')) end
+ function is_Nffam(enc, fam)
+ tex.sprint(cat_lp, '\\let\\ifin@\\if'
+ .. (Nffam_list[enc] and Nffam_list[enc][fam] or 'false ')) 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