--- replace fonts.define.read()
-local ljft_dr_orig = fonts.define.read
-function fonts.define.read(name, size, id)
- extract_metric(name)
- -- In the present imple., we don't remove "jfm=..." from name.
- return ljft_dr_orig(name, size, id)
+-- ここから先は 新 \selectfont の内部でしか実行されない
+do
+ local alt_font_base, alt_font_base_num
+ local aftl_base
+ -- EXT
+ function does_alt_set(bbase)
+ aftl_base = alt_font_table_latex[bbase]
+ tex.sprint(cat_lp, '\\if' .. (aftl_base and 'true' or 'false'))
+ end
+ -- EXT
+ function print_aftl_address()
+ tex.sprint(cat_lp, ';ltjaltfont' .. tostring(aftl_base):sub(8))
+ end
+
+-- EXT
+ function output_alt_font_cmd(bbase)
+ alt_font_base = bbase
+ alt_font_base_num = tex.getattribute(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
+ tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux{' .. i .. '}')
+ end
+ end
+ end
+
+-- EXT
+ function pickup_alt_font_a(size_str)
+ local t = alt_font_table_latex[alt_font_base]
+ if t then
+ for i,v in pairs(t) do
+ tex.sprint(cat_lp, '\\expandafter\\ltj@pickup@altfont@copy'
+ .. '\\csname ' .. i .. '/' .. size_str .. '\\endcsname{' .. i .. '}')
+ end
+ end
+ end
+
+ local function pickup_alt_font_class(class, afnt_num, afnt_chars)
+ local t = alt_font_table[alt_font_base_num]
+ local tx = font_metric_table[alt_font_base_num].chars
+ for i,v in pairs(tx) do
+ if v==class and afnt_chars[i] then t[i]=afnt_num end
+ end
+ end
+
+-- EXT
+ function pickup_alt_font_b(afnt_num, afnt_base)
+ local t = alt_font_table[alt_font_base_num]
+ local ac = font_getfont(afnt_num).characters
+ if not t then t = {}; alt_font_table[alt_font_base_num] = t end
+ for i,v in pairs(alt_font_table_latex[alt_font_base]) do
+ if i == afnt_base then
+ for j,_ in pairs(v) do
+ if j>=0 then
+ if ac[j] then t[j]=afnt_num end
+ else -- -n (n>=1) means that the character class n,
+ -- which is defined in the JFM
+ pickup_alt_font_class(-j, afnt_num, ac)
+ end
+ end
+ return
+ end
+ end
+ end
+