4 luatexbase.provides_module({
5 name = 'luatexja.jfont',
7 description = 'Loader for Japanese fonts',
10 luatexja.load_module 'lotf_aux'; local ltju = luatexja.lotf_aux
11 luatexja.load_module 'base'; local ltjb = luatexja.base
12 luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
13 luatexja.load_module 'rmlgbm'; local ltjr = luatexja.rmlgbm
14 luatexja.load_module 'direction'; local ltjd = luatexja.direction
16 local setfield = node.direct.setfield
17 local getid = node.direct.getid
18 local to_direct = node.direct.todirect
20 local node_new = node.direct.new
21 local node_free = node.direct.flush_node or node.direct.free
22 local get_attr = node.direct.get_attribute
23 local set_attr = node.direct.set_attribute
24 local round = tex.round
25 local font_getfont = font.getfont
26 local setkern = node.direct.setkern
28 local attr_icflag = luatexbase.attributes['ltj@icflag']
29 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
30 local attr_curtfnt = luatexbase.attributes['ltj@curtfnt']
31 local id_glyph = node.id('glyph')
32 local id_kern = node.id('kern')
33 local cat_lp = luatexbase.catcodetables['latex-package']
34 local FROM_JFM = luatexja.icflag_table.FROM_JFM
36 luatexja.jfont = luatexja.jfont or {}
37 ------------------------------------------------------------------------
39 ------------------------------------------------------------------------
41 local metrics = {} -- this table stores all metric informations
42 local font_metric_table = ltju.font_metric_table -- [font number] -> jfm_name, jfm_var, size
44 luatexbase.create_callback("luatexja.load_jfm", "data", function (ft, jn) return ft end)
46 local jfm_spec, jfm_name, jfm_var, jfm_ksp
48 local jfm_dir, is_def_jfont, vert_activated, auto_enable_vrt2
50 local function norm_val(a)
51 if (not a) or (a==0.) then
60 local fastcopy=table.fastcopy
61 function luatexja.jfont.define_jfm(to)
62 local t = fastcopy(to)
63 local real_char -- Does current character class have the 'real' character?
64 if t.dir~=jfm_dir then
65 defjfm_res= nil; return
66 elseif type(t.zw)~='number' or type(t.zh)~='number' then
67 defjfm_res= nil; return
69 t.version = (type(t.version)=='number') and t.version or 1
70 t.char_type = {}; t.chars = {}
71 for i,v in pairs(t) do
72 if type(i) == 'number' then -- char_type
74 if i ~= 0 then defjfm_res= nil; return end
76 for j,w in pairs(v.chars) do
77 if type(w) == 'number' and w~=-1 then
78 elseif type(w) == 'string' and utf.len(w)==1 then
80 elseif type(w) == 'string' and utf.len(w)==2 and utf.sub(w,2) == '*' then
81 w = utf.byte(utf.sub(w,1,1))
83 if not t.chars[w] then
86 defjfm_res= nil; return
91 if type(v.align)~='string' then
92 v.align = 'left' -- left
94 if type(v.width)~='number' then
97 if type(v.height)~='number' then
98 v.height = (jfm_dir=='tate') and 0.0 or nil
100 if type(v.depth)~='number' then
101 v.depth = (jfm_dir=='tate') and 0.0 or nil
103 if type(v.italic)~='number' then
106 if type(v.left)~='number' then
109 if type(v.down)~='number' then
112 v.round_threshold = ((t.version>=3)and(i==0)and(type(v.round_threshold)=='number'))
113 and v.round_threshold or nil
115 if v.end_stretch then defjfm_res= nil; return end
116 if v.end_shrink then defjfm_res= nil; return end
118 if type(v.end_adjust)~='table' then
120 elseif #(v.end_adjust)==0 then
123 table.sort(v.end_adjust)
128 if v.end_stretch and v.end_stretch~=0.0 then
129 v.end_adjust = (v.end_adjust or {})
130 v.end_adjust[#(v.end_adjust)+1] = v.end_stretch
132 if v.end_shrink and v.end_ahrink~=0.0 then
133 v.end_adjust = (v.end_adjust or {})
134 v.end_adjust[#(v.end_adjust)+1] = -v.end_shrink
136 if v.end_adjust then v.end_adjust[#(v.end_adjust)+1] = 0.0 end
138 v.kern = v.kern or {}; v.glue = v.glue or {}
139 for j,x in pairs(v.glue) do
140 if v.kern[j] then defjfm_res= nil; return end
141 x.ratio, x[5] = (x.ratio or (x[5] and 0.5*(1+x[5]) or 0.5)), nil
144 xp, x[4] = (x.priority or x[4]), nil
145 if type(xp)=='table' and t.version>=2 then
146 if type(xp[1])~='number' or xp[1]<-4 or xp[1]>3 then defjfm_res=nil end -- stretch
147 if type(xp[2])~='number' or xp[2]<-4 or xp[2]>3 then defjfm_res=nil end -- shrink
148 xp = (xp[1]+4)*8+(xp[2]+4)
149 elseif xp and type(xp)~='number' then
153 if xp<0 or xp>=64 then defjfm_res=nil end
157 x.kanjiskip_natural = norm_val(x.kanjiskip_natural)
158 x.kanjiskip_stretch = norm_val(x.kanjiskip_stretch)
159 x.kanjiskip_shrink = norm_val(x.kanjiskip_shrink)
161 for j,x in pairs(v.kern) do
162 if type(x)=='number' then
164 elseif type(x)=='table' then
165 v.kern[j] = { x[1], (x.ratio or (x[2] and 0.5*(1+x[2]) or 0.5)) }
173 -- In version 3, 'jcharbdd' is divided into
174 -- 'alchar': ALchar (or math boundary)
175 -- 'nox_alchar': ALchar (or math boundary), where xkanjiskip won't inserted
176 -- 'glue': glue/kern, 'jcharbdd': other cases (和文B, rule, ...)
177 t.chars.alchar = t.chars.jcharbdd
178 t.chars.nox_alchar = t.chars.jcharbdd
179 t.chars.glue = t.chars.jcharbdd
181 t = luatexbase.call_callback("luatexja.load_jfm", t, jfm_spec, luatexja.jfont.jfm_feature)
186 local update_jfm_cache
188 local floor = math.floor
189 local function myround(a) return floor(a+0.5) end
190 local mult_ignore_key = {
191 round_threshold=true, kanjiskip_natural=true, kanjiskip_stretch=true, kanjiskip_shrink=true,
192 ratio=true, priority=true
194 local function mult_table(old,scale) -- modified from table.fastcopy
197 for k,v in next, old do
198 if type(v) == "table" then
199 new[k] = mult_table(v,scale)
200 elseif type(v) == "number" and not mult_ignore_key[k] then
201 new[k] = myround(v*scale)
209 local size_cache_num = 1
210 update_jfm_cache = function (j,sz)
211 if metrics[j].size_cache[sz] then return metrics[j].size_cache[sz].index end
213 metrics[j].size_cache[sz] = t
214 t.chars = metrics[j].chars
215 t.char_type = mult_table(metrics[j].char_type, sz)
216 for i,v in pairs(t.char_type) do
217 v.align = (v.align=='left') and 0 or
218 ((v.align=='right') and 1 or 0.5)
219 if type(i) == 'number' then -- char_type
220 for k,w in pairs(v.glue) do
222 nil, w[1], w[2], w[3],
224 priority=FROM_JFM + w.priority,
225 kanjiskip_natural = w.kanjiskip_natural,
226 kanjiskip_stretch = w.kanjiskip_stretch,
227 kanjiskip_shrink = w.kanjiskip_shrink,
228 round_threshold = w.round_threshold,
231 for k,w in pairs(v.kern) do
232 v[k] = {w[1], ratio=w[2]/sz}
235 v.glue, v.kern = nil, nil
237 t.kanjiskip = mult_table(metrics[j].kanjiskip, sz)
238 t.xkanjiskip = mult_table(metrics[j].xkanjiskip,sz)
239 t.zw = round(metrics[j].zw*sz)
240 t.zh = round(metrics[j].zh*sz)
242 size_cache_num = size_cache_num + 1
243 t.index = size_cache_num
244 return size_cache_num
248 luatexbase.create_callback("luatexja.find_char_class", "data",
249 function (arg, fmtable, char)
252 local find_char_class
254 local start_time_measure = ltjb.start_time_measure
255 local stop_time_measure = ltjb.stop_time_measure
256 local fcc_temp = { chars_cbcache = {} }
258 fcc_temp.chars_cbcache,
260 __index = function () return 0 end,
262 function find_char_class(c,m)
263 -- c: character code, m:
264 local r = (m or fcc_temp).chars_cbcache[c]
267 luatexbase.call_callback("luatexja.find_char_class", 0, m, c)
268 m.chars_cbcache[c or 0] = r
275 ------------------------------------------------------------------------
276 -- LOADING JAPANESE FONTS
277 ------------------------------------------------------------------------
279 local load_jfont_metric, check_callback_order
280 local font_extra_info = {} -- defined later
282 local global_flag -- true if \globaljfont, false if \jfont
283 load_jfont_metric = function()
285 ltjb.package_error('luatexja', 'no JFM specified',
286 'To load and define a Japanese font, a JFM must be specified.'..
287 "The JFM 'ujis' will be used for now.")
288 jfm_name, jfm_spec = 'ujis', 'ujis'
290 for j,v in ipairs(metrics) do if v.name==jfm_spec then return j end end
291 luatexja.load_lua('jfm-' .. jfm_name .. '.lua')
293 defjfm_res.name = jfm_spec; table.insert(metrics, defjfm_res)
301 local utfbyte = utf.byte
302 function luatexja.jfont.jfontdefX(g, dir)
303 jfm_dir, is_def_jfont = dir, true
304 global_flag = g and '\\global' or ''
305 tex.sprint(cat_lp, '\\expandafter\\font\\ltj@temp')
308 luatexbase.create_callback("luatexja.define_jfont", "data", function (ft, fn) return ft end)
311 local fastcopy=table.fastcopy
312 function luatexja.jfont.jfontdefY()
313 local j = load_jfont_metric(jfm_dir)
314 local fn = token.get_next().mode; local f = font_getfont(fn)
316 ltjb.package_error('luatexja', "bad JFM `" .. jfm_name .. "'",
317 'The JFM file you specified is not valid JFM file.\n'..
318 'So defining Japanese font is cancelled.')
319 tex.sprint(cat_lp, global_flag, '\\expandafter\\let\\ltj@temp\\relax')
322 if not f then return end
323 update_jfm_cache(j, f.size); check_callback_order()
324 local sz = metrics[j].size_cache[f.size]
325 local fmtable = { jfm = j, size = f.size, var = jfm_var,
326 with_kanjiskip = jfm_ksp,
327 zw = sz.zw, zh = sz.zh,
328 chars = sz.chars, char_type = sz.char_type,
329 kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip,
331 vert_activated = vert_activated,
332 rotation = fastcopy(font_extra_info[fn].rotation),
334 if auto_enable_vrt2 then
335 local vert_name = ltju.exist_feature(fn, 'vrt2') and 'vrt2' or 'vert'
336 local rot = fmtable.rotation
337 ltju.enable_feature(fn, vert_name)
338 ltju.loop_over_feat(f, {[vert_name]=true}, function (i,k) rot[i] = nil end)
341 fmtable = luatexbase.call_callback("luatexja.define_jfont", fmtable, fn)
342 font_metric_table[fn]=fmtable
343 tex.sprint(cat_lp, global_flag, '\\protected\\expandafter\\def\\ltj@temp',
344 '{\\ltj@cur'.. (jfm_dir == 'yoko' and 'j' or 't') .. 'fnt', fn, '\\relax}')
350 local ltb = luatexbase
351 local to_be_checked = { 'pre_linebreak_filter', 'hpack_filter' }
352 check_callback_order = function()
353 for i,n in pairs(to_be_checked) do
354 local lotf_cb = ltb.priority_in_callback(n, 'luaotfload.letterspace')
355 local ltj_cb = ltb.priority_in_callback(n, 'ltj.main')
358 if ltj_cb<lotf_cb then
359 local f = ltb.remove_from_callback(n,'luaotfload.letterspace')
360 ltb.add_to_callback(n, f, 'luaotfload.letterspace',
361 ltb.priority_in_callback(n, 'luaotfload.node_processor') + 1)
369 local get_dir_count = ltjd.get_dir_count
370 local dir_tate = luatexja.dir_table.dir_tate
371 local tex_get_attr = tex.getattribute
373 function luatexja.jfont.get_zw()
374 local a = font_metric_table[
375 tex_get_attr((get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)]
376 return a and a.zw or 0
378 function luatexja.jfont.get_zh()
379 local a = font_metric_table[
380 tex_get_attr((get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)]
381 return a and a.zw or 0
386 local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V
387 local lpegmatch = lpeg.match
388 local C, Cc, Cf, Ct, Cg = lpeg.C, lpeg.Cc, lpeg.Cf, lpeg.Ct, lpeg.Cg
389 local Cs, B = lpeg.Cs, lpeg.B
390 local spacing = S" \t\v"
393 local semicolon = P';'
396 local jf_field_char = 1 - S'/{};,= \t\v'
397 local jf_field = C(jf_field_char^1)
398 local jf_assignment = jf_field * ws * equals * ws * jf_field
399 local jf_switch = P'-' * jf_field * Cc(false) + P'+'^-1 * jf_field * Cc(true)
400 local jf_feature_expr = Cg(jf_assignment + jf_switch) * ws * comma^0 * ws
401 local jf_feature_list = ws * ( P'{' * ws * jf_feature_expr^0 * P'}' + jf_feature_expr^0 )
402 local jf_list = C((1-slash)^1) * (slash * Cf(Ct'' * jf_feature_list, rawset))^-1
403 local jf_value = (1 - semicolon)^1
404 local function rem(name,value)
406 local flag, t; jfm_name, t = lpegmatch(jf_list, value)
407 if type(t)=='table' then
408 for i,v in pairs(t) do
410 if v=='true' then t[i]=true elseif v=='false' then t[i]=false end
413 luatexja.jfont.jfm_feature = flag and t
414 elseif name=='jfmvar' then jfm_var = value end
417 local jf_remainder = Cs( ( ( B(S':;') *
418 C(P'jfm' * P'var'^-1) * ws * equals * ws * C(jf_value) * semicolon^-1 ) / rem +1 )^0 )
420 local parser=luaotfload.parsers.font_request
421 function is_feature_specified(s,fname)
422 local t = lpegmatch(parser,s); return t and t.features and t.features[fname]
424 -- extract jfm_name, jfm_spec and jfm_var
425 -- normalize position of 'jfm=' and 'jfmvar=' keys
426 local function extract_jfm_spec(name)
427 name = (name:match '^{(.*)}$') or (name:match '^"(.*)"$') or name
428 jfm_spec, jfm_var = '', ''
429 local tmp, index = name:sub(1, 5), 1
430 if tmp == 'file:' or tmp == 'name:' or tmp == 'psft:' then
433 name = lpegmatch(jf_remainder, name)
435 if luatexja.jfont.jfm_feature then
436 local l, t2 = name:sub(-1), {}
437 for i,v in pairs(luatexja.jfont.jfm_feature) do
438 -- print(i,type(v),v)
439 t2[#t2+1] = (v==true) and i
440 or ((v==false) and ('-'..i) or (i..'='..tostring(v)))
442 table.sort(t2); jfm_spec = jfm_name .. '/{' .. table.concat(t2, ',') .. '}'
447 name = name .. ((l==':' or l==';') and '' or ';') .. 'jfm=' .. jfm_spec
449 name = name .. ';jfmvar=' .. jfm_var
451 -- print('NN>', name)
453 jfm_ksp = (is_feature_specified(name,'ltjksp')~=false)
454 if jfm_dir == 'tate' then
455 vert_activated = (is_feature_specified(name,'vert')~=false) and (is_feature_specified(name,'vrt2')~=false)
457 = (is_feature_specified(name,'vert')==nil) and (is_feature_specified(name,'vrt2')==nil)
459 vert_activated, auto_enable_vrt2 = nil, nil
464 -- define_font callback
466 local ltjr_font_callback = ltjr.font_callback
467 function luatexja.font_callback(name, size, id)
468 local new_name = is_def_jfont and extract_jfm_spec(name) or name
470 local res = ltjr_font_callback(new_name, size, id, otfl_fdr)
471 luatexbase.call_callback('luatexja.define_font', res, new_name, size, id)
472 -- this callback processes variation selector, so we execute it always
475 luatexbase.create_callback('luatexja.define_font', 'simple', function (n) return n end)
476 otfl_fdr= luatexbase.remove_from_callback('define_font', 'luaotfload.define_font')
477 luatexbase.add_to_callback('define_font',luatexja.font_callback,"luatexja.font_callback", 1)
479 local match, sp, scan_arg = string.match, tex.sp, token.scan_argument
480 local function load_jfmonly()
481 local spec, size = match(scan_arg(), '(.+)%s+at%s*([%.%w]*)')
482 local dir = scan_arg()
483 size = sp(size); extract_jfm_spec(spec)
485 local i = load_jfont_metric()
486 local j = -update_jfm_cache(i, size)
487 font_metric_table[j]=metrics[i].size_cache[size]
488 tex.sprint(cat_lp, '\\ltj@cur' .. (dir=='yoko' and 'j' or 't') .. 'fnt' .. tostring(j) .. '\\relax')
490 luatexja.jfont.load_jfmonly = load_jfmonly
493 ------------------------------------------------------------------------
495 ------------------------------------------------------------------------
497 local scan_arg = token.scan_argument
498 -- these function are called from ltj-latex.sty
499 local fenc_list, kyenc_list, ktenc_list = {}, {}, {}
500 function luatexja.jfont.add_fenc_list() fenc_list[scan_arg()] = 'true ' end
501 function luatexja.jfont.add_kyenc_list() kyenc_list[scan_arg()] = 'true ' end
502 function luatexja.jfont.add_ktenc_list() ktenc_list[scan_arg()] = 'true ' end
503 function luatexja.jfont.is_kyenc()
504 tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (kyenc_list[scan_arg()] or 'false '))
506 function luatexja.jfont.is_ktenc()
507 tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (ktenc_list[scan_arg()] or 'false '))
509 function luatexja.jfont.is_kenc()
510 local enc = scan_arg()
511 tex.sprint(cat_lp, '\\let\\ifin@\\if'
512 .. (kyenc_list[enc] or ktenc_list[enc] or 'false '))
515 local kfam_list, Nkfam_list = {}, {}
516 function luatexja.jfont.add_kfam()
517 kfam_list[scan_arg()]=true
519 function luatexja.jfont.search_kfam()
520 local fam = scan_arg()
521 local use_fd = (scan_arg() =='true')
522 if kfam_list[fam] then
523 tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
524 elseif Nkfam_list[fam] then
525 tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
527 for i,_ in pairs(kyenc_list) do
528 if kpse.find_file(string.lower(i)..fam..'.fd') then
529 tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
532 for i,_ in pairs(ktenc_list) do
533 if kpse.find_file(string.lower(i)..fam..'.fd') then
534 tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
537 Nkfam_list[fam]=true; tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
539 tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
542 local ffam_list, Nffam_list = {}, {}
543 function luatexja.jfont.is_ffam()
544 tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (ffam_list[scan_arg()] or 'false '))
546 function luatexja.jfont.add_ffam()
547 ffam_list[scan_arg()]='true '
549 function luatexja.jfont.search_ffam_declared()
551 for i,_ in pairs(fenc_list) do
552 s = s .. '\\cdp@elt{' .. i .. '}'
554 tex.sprint(cat_lp, s)
556 function luatexja.jfont.search_ffam_fd()
557 local fam = scan_arg()
558 if Nffam_list[fam] then
559 tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
561 for i,_ in pairs(fenc_list) do
562 if kpse.find_file(string.lower(i)..fam..'.fd') then
563 tex.sprint(cat_lp, '\\let\\ifin@\\iftrue '); return
566 Nffam_list[fam]=true; tex.sprint(cat_lp, '\\let\\ifin@\\iffalse '); return
571 ------------------------------------------------------------------------
573 ------------------------------------------------------------------------
574 local alt_font_table = {}
575 local attr_curaltfnt = {}
576 local ucs_out = 0x110000
578 ------ for TeX interface
580 function luatexja.jfont.set_alt_font(b,e,ind,bfnt)
581 -- ind: 新フォント, bfnt: 基底フォント
582 if b>e then b, e = e, b end
584 ltjb.package_error('luatexja',
585 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
586 'I take the intersection with [0x80, 0x10ffff].')
587 b, e = math.max(0x80,b),math.min(ucs_out-1,e)
588 elseif e<0 then -- b<e<0
590 elseif b<0x80 or e>=ucs_out then
591 ltjb.package_warning('luatexja',
592 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
593 'I take the intersection with [0x80, 0x10ffff].')
594 b, e = math.max(0x80,b), math.min(ucs_out-1,e)
596 if not alt_font_table[bfnt] then alt_font_table[bfnt]={} end
597 local t = alt_font_table[bfnt]
598 local ac = font_getfont(ind).characters
599 if bfnt==ind then ind = nil end -- ind == bfnt の場合はテーブルから削除
600 if e>=0 then -- character range
602 if ac[i]then t[i]=ind end
606 local tx = font_metric_table[bfnt].chars
607 for i,v in pairs(tx) do
608 if b<=v and v<=e and ac[i] then t[i]=ind end
614 function luatexja.jfont.clear_alt_font(bfnt)
615 if alt_font_table[bfnt] then
616 local t = alt_font_table[bfnt]
617 for i,_ in pairs(t) do t[i]=nil; end
621 ------ used in ltjp.suppress_hyphenate_ja callback
622 function luatexja.jfont.replace_altfont(pf, pc)
623 local a = alt_font_table[pf]
624 return a and a[pc] or pf
627 ------ for LaTeX interface
629 local alt_font_table_latex = {}
632 function luatexja.jfont.clear_alt_font_latex(bbase)
633 local t = alt_font_table_latex[bbase]
635 for j,v in pairs(t) do t[j] = nil end
640 function luatexja.jfont.set_alt_font_latex(b,e,ind,bbase)
641 -- ind: Alt font の enc/fam/ser/shape, bbase: 基底フォントの enc/fam/ser/shape
642 if b>e then b, e = e, b end
644 ltjb.package_error('luatexja',
645 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
646 'I take the intersection with [0x80, 0x10ffff].')
647 b, e = math.max(0x80,b),math.min(ucs_out-1,e)
648 elseif e<0 then -- b<e<0
650 elseif b<0x80 or e>=ucs_out then
651 ltjb.package_warning('luatexja',
652 'bad character range ([' .. b .. ',' .. e .. ']). ' ..
653 'I take the intersection with [0x80, 0x10ffff].')
654 b, e = math.max(0x80,b), math.min(ucs_out-1,e)
657 if not alt_font_table_latex[bbase] then alt_font_table_latex[bbase]={} end
658 local t = alt_font_table_latex[bbase]
659 if not t[ind] then t[ind] = {} end
661 for j,v in pairs(t) do
662 if v[i] then -- remove old entry
663 if j~=ind then v[i]=nil end; break
668 -- remove the empty tables
669 for j,v in pairs(t) do
670 local flag_clear = true
671 for k,_ in pairs(v) do flag_clear = false; break end
672 if flag_clear then t[j]=nil end
674 if ind==bbase then t[bbase] = nil end
677 -- ここから先は 新 \selectfont の内部でしか実行されない
679 local scan_arg = token.scan_argument
680 local alt_font_base, alt_font_base_num
683 function luatexja.jfont.does_alt_set()
684 aftl_base = alt_font_table_latex[scan_arg()]
685 tex.sprint(cat_lp, aftl_base and '\\@firstofone' or '\\@gobble')
688 function luatexja.jfont.print_aftl_address()
689 return ';ltjaltfont' .. tostring(aftl_base):sub(8)
693 function luatexja.jfont.output_alt_font_cmd(dir, bbase)
694 alt_font_base = bbase
695 alt_font_base_num = tex.getattribute((dir == 't') and attr_curtfnt or attr_curjfnt)
696 local t = alt_font_table[alt_font_base_num]
698 for i,_ in pairs(t) do t[i]=nil end
700 t = alt_font_table_latex[bbase]
702 for i,_ in pairs(t) do
703 tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux' .. dir .. '{' .. i .. '}')
709 function luatexja.jfont.pickup_alt_font_a(size_str)
710 local t = alt_font_table_latex[alt_font_base]
712 for i,v in pairs(t) do
713 tex.sprint(cat_lp, '\\expandafter\\ltj@pickup@altfont@copy'
714 .. '\\csname ' .. i .. '/' .. size_str .. '\\endcsname{' .. i .. '}')
719 local function pickup_alt_font_class(class, afnt_num, afnt_chars)
720 local t = alt_font_table[alt_font_base_num]
721 local tx = font_metric_table[alt_font_base_num].chars
722 for i,v in pairs(tx) do
723 if v==class and afnt_chars[i] then t[i]=afnt_num end
728 function luatexja.jfont.pickup_alt_font_b(afnt_num, afnt_base)
729 local t = alt_font_table[alt_font_base_num]
730 local ac = font_getfont(afnt_num).characters
731 if not t then t = {}; alt_font_table[alt_font_base_num] = t end
732 for i,v in pairs(alt_font_table_latex[alt_font_base]) do
733 if i == afnt_base then
734 for j,_ in pairs(v) do
736 if ac[j] then t[j]=afnt_num end
737 else -- -n (n>=1) means that the character class n,
738 -- which is defined in the JFM
739 pickup_alt_font_class(-j, afnt_num, ac)
748 ------------------------------------------------------------------------
750 ------------------------------------------------------------------------
752 function luatexja.jfont.cleanup_size_cache()
753 --local gs, ke = 0, 0
754 for _,n in pairs(metrics) do
755 for i,t in pairs(n.size_cache) do
756 for _,v in pairs(t.char_type) do
757 for k,w in pairs(v) do
758 if type(k)=='number' then
759 --if w[1] then gs = gs + 1 else ke = ke + 1 end
760 if w[1] then node_free(w[1]) end
770 ------------------------------------------------------------------------
772 ------------------------------------------------------------------------
773 luatexja.jfont.font_extra_info = font_extra_info -- key: fontnumber
774 local font_extra_basename = {} -- key: basename
776 local rotate_exception = {
777 [0xFF1A]= { ['zht'] = true, },
778 [0xFF1B]= { ['zht'] = true, },
780 luatexja.jfont.rotate_exception = rotate_exception
781 local list_rotate_glyphs
783 local ceil = math.ceil
784 -- output of function_uax50.lua
785 -- UAX#50 for Unicode 14.0.0
787 local t={ 0, 167, 168, 169, 170, 174, 175, 177, 178, 188, 191, 215, 216, 247, 248, 746, 748, 888, 890, 896, 900, 907, 908, 909, 910, 930, 931, 1328, 1329, 1367, 1369, 1419, 1421, 1424, 1425, 1480, 1488, 1515, 1519, 1525, 1536, 1806, 1807, 1867, 1869, 1970, 1984, 2043, 2045, 2094, 2096, 2111, 2112, 2140, 2142, 2143, 2144, 2155, 2160, 2191, 2192, 2194, 2200, 2436, 2437, 2445, 2447, 2449, 2451, 2473, 2474, 2481, 2482, 2483, 2486, 2490, 2492, 2501, 2503, 2505, 2507, 2511, 2519, 2520, 2524, 2526, 2527, 2532, 2534, 2559, 2561, 2564, 2565, 2571, 2575, 2577, 2579, 2601, 2602, 2609, 2610, 2612, 2613, 2615, 2616, 2618, 2620, 2621, 2622, 2627, 2631, 2633, 2635, 2638, 2641, 2642, 2649, 2653, 2654, 2655, 2662, 2679, 2689, 2692, 2693, 2702, 2703, 2706, 2707, 2729, 2730, 2737, 2738, 2740, 2741, 2746, 2748, 2758, 2759, 2762, 2763, 2766, 2768, 2769, 2784, 2788, 2790, 2802, 2809, 2816, 2817, 2820, 2821, 2829, 2831, 2833, 2835, 2857, 2858, 2865, 2866, 2868, 2869, 2874, 2876, 2885, 2887, 2889, 2891, 2894, 2901, 2904, 2908, 2910, 2911, 2916, 2918, 2936, 2946, 2948, 2949, 2955, 2958, 2961, 2962, 2966, 2969, 2971, 2972, 2973, 2974, 2976, 2979, 2981, 2984, 2987, 2990, 3002, 3006, 3011, 3014, 3017, 3018, 3022, 3024, 3025, 3031, 3032, 3046, 3067, 3072, 3085, 3086, 3089, 3090, 3113, 3114, 3130, 3132, 3141, 3142, 3145, 3146, 3150, 3157, 3159, 3160, 3163, 3165, 3166, 3168, 3172, 3174, 3184, 3191, 3213, 3214, 3217, 3218, 3241, 3242, 3252, 3253, 3258, 3260, 3269, 3270, 3273, 3274, 3278, 3285, 3287, 3293, 3295, 3296, 3300, 3302, 3312, 3313, 3315, 3328, 3341, 3342, 3345, 3346, 3397, 3398, 3401, 3402, 3408, 3412, 3428, 3430, 3456, 3457, 3460, 3461, 3479, 3482, 3506, 3507, 3516, 3517, 3518, 3520, 3527, 3530, 3531, 3535, 3541, 3542, 3543, 3544, 3552, 3558, 3568, 3570, 3573, 3585, 3643, 3647, 3676, 3713, 3715, 3716, 3717, 3718, 3723, 3724, 3748, 3749, 3750, 3751, 3774, 3776, 3781, 3782, 3783, 3784, 3790, 3792, 3802, 3804, 3808, 3840, 3912, 3913, 3949, 3953, 3992, 3993, 4029, 4030, 4045, 4046, 4059, 4096, 4294, 4295, 4296, 4301, 4302, 4304, 4352, 4608, 4681, 4682, 4686, 4688, 4695, 4696, 4697, 4698, 4702, 4704, 4745, 4746, 4750, 4752, 4785, 4786, 4790, 4792, 4799, 4800, 4801, 4802, 4806, 4808, 4823, 4824, 4881, 4882, 4886, 4888, 4955, 4957, 4989, 4992, 5018, 5024, 5110, 5112, 5118, 5120, 5121, 5760, 5789, 5792, 5881, 5888, 5910, 5919, 5943, 5952, 5972, 5984, 5997, 5998, 6001, 6002, 6004, 6016, 6110, 6112, 6122, 6128, 6138, 6144, 6170, 6176, 6265, 6272, 6315, 6400, 6431, 6432, 6444, 6448, 6460, 6464, 6465, 6468, 6510, 6512, 6517, 6528, 6572, 6576, 6602, 6608, 6619, 6622, 6684, 6686, 6751, 6752, 6781, 6783, 6794, 6800, 6810, 6816, 6830, 6832, 6863, 6912, 6989, 6992, 7039, 7040, 7156, 7164, 7224, 7227, 7242, 7245, 7305, 7312, 7355, 7357, 7368, 7376, 7419, 7424, 7958, 7960, 7966, 7968, 8006, 8008, 8014, 8016, 8024, 8025, 8026, 8027, 8028, 8029, 8030, 8031, 8062, 8064, 8117, 8118, 8133, 8134, 8148, 8150, 8156, 8157, 8176, 8178, 8181, 8182, 8191, 8192, 8214, 8215, 8224, 8226, 8240, 8242, 8251, 8253, 8258, 8259, 8263, 8266, 8273, 8274, 8293, 8294, 8306, 8308, 8335, 8336, 8349, 8352, 8385, 8400, 8413, 8417, 8418, 8421, 8433, 8450, 8451, 8458, 8463, 8464, 8467, 8469, 8470, 8472, 8478, 8484, 8485, 8486, 8487, 8488, 8489, 8490, 8494, 8495, 8501, 8512, 8517, 8523, 8524, 8526, 8527, 8586, 8588, 8592, 8734, 8735, 8756, 8758, 8960, 8968, 8972, 8992, 8996, 9001, 9003, 9004, 9085, 9115, 9150, 9166, 9167, 9168, 9169, 9180, 9186, 9251, 9252, 9472, 9632, 9754, 9760, 10088, 10102, 10132, 11026, 11056, 11088, 11098, 11124, 11126, 11158, 11160, 11192, 11218, 11219, 11244, 11248, 11264, 11508, 11513, 11558, 11559, 11560, 11565, 11566, 11568, 11624, 11631, 11633, 11647, 11671, 11680, 11687, 11688, 11695, 11696, 11703, 11704, 11711, 11712, 11719, 11720, 11727, 11728, 11735, 11736, 11743, 11744, 11856, 11858, 11870, 12296, 12306, 12308, 12320, 12336, 12337, 12448, 12449, 12540, 12541, 42192, 42540, 42560, 42744, 42752, 42955, 42960, 42962, 42963, 42964, 42965, 42970, 42994, 43053, 43056, 43066, 43072, 43128, 43136, 43206, 43214, 43226, 43232, 43348, 43359, 43360, 43392, 43470, 43471, 43482, 43486, 43519, 43520, 43575, 43584, 43598, 43600, 43610, 43612, 43715, 43739, 43767, 43777, 43783, 43785, 43791, 43793, 43799, 43808, 43815, 43816, 43823, 43824, 43884, 43888, 44014, 44016, 44026, 55296, 57344, 64256, 64263, 64275, 64280, 64285, 64311, 64312, 64317, 64318, 64319, 64320, 64322, 64323, 64325, 64326, 64451, 64467, 64912, 64914, 64968, 64975, 64976, 65008, 65040, 65056, 65072, 65097, 65104, 65112, 65119, 65123, 65127, 65136, 65141, 65142, 65277, 65279, 65280, 65288, 65290, 65293, 65294, 65306, 65311, 65339, 65340, 65341, 65342, 65343, 65344, 65371, 65471, 65474, 65480, 65482, 65488, 65490, 65496, 65498, 65501, 65507, 65508, 65512, 65519, 65529, 65532, 65536, 65548, 65549, 65575, 65576, 65595, 65596, 65598, 65599, 65614, 65616, 65630, 65664, 65787, 65792, 65795, 65799, 65844, 65847, 65935, 65936, 65949, 65952, 65953, 66000, 66046, 66176, 66205, 66208, 66257, 66272, 66300, 66304, 66340, 66349, 66379, 66384, 66427, 66432, 66462, 66463, 66500, 66504, 66518, 66560, 66718, 66720, 66730, 66736, 66772, 66776, 66812, 66816, 66856, 66864, 66916, 66927, 66939, 66940, 66955, 66956, 66963, 66964, 66966, 66967, 66978, 66979, 66994, 66995, 67002, 67003, 67005, 67072, 67383, 67392, 67414, 67424, 67432, 67456, 67462, 67463, 67505, 67506, 67515, 67584, 67590, 67592, 67593, 67594, 67638, 67639, 67641, 67644, 67645, 67647, 67670, 67671, 67743, 67751, 67760, 67808, 67827, 67828, 67830, 67835, 67868, 67871, 67898, 67903, 67904, 68000, 68024, 68028, 68048, 68050, 68100, 68101, 68103, 68108, 68116, 68117, 68120, 68121, 68150, 68152, 68155, 68159, 68169, 68176, 68185, 68192, 68256, 68288, 68327, 68331, 68343, 68352, 68406, 68409, 68438, 68440, 68467, 68472, 68498, 68505, 68509, 68521, 68528, 68608, 68681, 68736, 68787, 68800, 68851, 68858, 68904, 68912, 68922, 69216, 69247, 69248, 69290, 69291, 69294, 69296, 69298, 69376, 69416, 69424, 69466, 69488, 69514, 69552, 69580, 69600, 69623, 69632, 69710, 69714, 69750, 69759, 69827, 69837, 69838, 69840, 69865, 69872, 69882, 69888, 69941, 69942, 69960, 69968, 70007, 70016, 70112, 70113, 70133, 70144, 70162, 70163, 70207, 70272, 70279, 70280, 70281, 70282, 70286, 70287, 70302, 70303, 70314, 70320, 70379, 70384, 70394, 70400, 70404, 70405, 70413, 70415, 70417, 70419, 70441, 70442, 70449, 70450, 70452, 70453, 70458, 70459, 70469, 70471, 70473, 70475, 70478, 70480, 70481, 70487, 70488, 70493, 70500, 70502, 70509, 70512, 70517, 70656, 70748, 70749, 70754, 70784, 70856, 70864, 70874, 71168, 71237, 71248, 71258, 71264, 71277, 71296, 71354, 71360, 71370, 71424, 71451, 71453, 71468, 71472, 71495, 71680, 71740, 71840, 71923, 71935, 71943, 71945, 71946, 71948, 71956, 71957, 71959, 71960, 71990, 71991, 71993, 71995, 72007, 72016, 72026, 72096, 72104, 72106, 72152, 72154, 72165, 72384, 72441, 72704, 72713, 72714, 72759, 72760, 72774, 72784, 72813, 72816, 72848, 72850, 72872, 72873, 72887, 72960, 72967, 72968, 72970, 72971, 73015, 73018, 73019, 73020, 73022, 73023, 73032, 73040, 73050, 73056, 73062, 73063, 73065, 73066, 73103, 73104, 73106, 73107, 73113, 73120, 73130, 73440, 73465, 73648, 73649, 73664, 73714, 73727, 74650, 74752, 74863, 74864, 74869, 74880, 75076, 77712, 77811, 92160, 92729, 92736, 92767, 92768, 92778, 92782, 92863, 92864, 92874, 92880, 92910, 92912, 92918, 92928, 92998, 93008, 93018, 93019, 93026, 93027, 93048, 93053, 93072, 93760, 93851, 93952, 94027, 94031, 94088, 94095, 94112, 113664, 113771, 113776, 113789, 113792, 113801, 113808, 113818, 113820, 113828, 119296, 119366, 119808, 119893, 119894, 119965, 119966, 119968, 119970, 119971, 119973, 119975, 119977, 119981, 119982, 119994, 119995, 119996, 119997, 120004, 120005, 120070, 120071, 120075, 120077, 120085, 120086, 120093, 120094, 120122, 120123, 120127, 120128, 120133, 120134, 120135, 120138, 120145, 120146, 120486, 120488, 120780, 120782, 120832, 122624, 122655, 122880, 122887, 122888, 122905, 122907, 122914, 122915, 122917, 122918, 122923, 123136, 123181, 123184, 123198, 123200, 123210, 123214, 123216, 123536, 123567, 123584, 123642, 123647, 123648, 124896, 124903, 124904, 124908, 124909, 124911, 124912, 124927, 124928, 125125, 125127, 125143, 125184, 125260, 125264, 125274, 125278, 125280, 126065, 126133, 126209, 126270, 126464, 126468, 126469, 126496, 126497, 126499, 126500, 126501, 126503, 126504, 126505, 126515, 126516, 126520, 126521, 126522, 126523, 126524, 126530, 126531, 126535, 126536, 126537, 126538, 126539, 126540, 126541, 126544, 126545, 126547, 126548, 126549, 126551, 126552, 126553, 126554, 126555, 126556, 126557, 126558, 126559, 126560, 126561, 126563, 126564, 126565, 126567, 126571, 126572, 126579, 126580, 126584, 126585, 126589, 126590, 126591, 126592, 126602, 126603, 126620, 126625, 126628, 126629, 126634, 126635, 126652, 126704, 126706, 129024, 129036, 129040, 129096, 129104, 129114, 129120, 129160, 129168, 129198, 129200, 129202, 129792, 129939, 129940, 129995, 130032, 130042, 917505, 917506, 917536, 917632, 917760, 918000 }
788 local function rotate_in_uax50(i)
791 local mi = ceil((lo+hi)/2)
792 if t[mi]<=i then lo=mi else hi=mi-1 end
796 local function list_rorate_dup (i, v, dest)
799 for j,_ in pairs(v) do if dest[j] then f=true; break end end
801 dest[i]=f; for j,_ in pairs(v) do dest[j]=f end
803 list_rotate_glyphs = function (tfmdata, dest)
805 for i,_ in pairs(tfmdata.characters) do
806 if rotate_in_uax50(i) then rot[i] = true end
808 -- ↓「TeX Live 2019のLuaLaTeXで縦書きの三点リーダーが横書きになる」
809 -- (https://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=2722) により無効化
810 -- -- 同じグリフが複数の Unicode ポイントを持っている場合.
811 -- -- いずれかの Unicode ポイントで rot = true ならば全体で rotate
812 --ltju.loop_over_duplicates(tfmdata,
816 -- for j,_ in pairs(v) do if rot[j] then f=true; break end end
818 -- rot[i]=f; for j,_ in pairs(v) do rot[j]=f end
820 for i,_ in pairs(rot) do
821 dest = dest or {}; dest.rotation = dest.rotation or {}
822 dest.rotation[i] = rotate_exception[i] or true
830 local nameonly, lower = file.nameonly, string.lower
831 local lfs = require"lfs"
832 local file_attributes = lfs.attributes
833 local load_cache, save_cache = ltjb.load_cache, ltjb.save_cache
834 local function prepare_extra_data_base(tfmdata)
835 if (not tfmdata) or (not tfmdata.filename) then return end
836 local bname = tfmdata.psname or nameonly(tfmdata.filename)
837 if not font_extra_basename[bname] then
838 -- if the cache is present, read it
840 local newtime = file_attributes(tfmdata.filename,"modification")
841 local v = "extra_" .. string.lower(bname)
842 local dest = load_cache(
845 return (t.lotf_version~=luaotfload.version)
846 or (t.version~=cache_ver) or (t.modtime~=newtime)
849 -- if the cache is not found or outdated, save the cache
851 font_extra_basename[bname] = dest[1] or {}
852 local vheight, vorigin = dest[1].vheight, dest[1].vorigin
853 local vhd, vod = vheight.default, vorigin.default
854 setmetatable(vheight, {__index = function () return vhd end } )
855 setmetatable(vorigin, {__index = function () return vod end } )
857 local dest = ltju.get_vmet_table(tfmdata, nil)
858 dest = list_rotate_glyphs(tfmdata, dest)
859 font_extra_basename[bname] = dest or {}
863 lotf_version = luaotfload.version,
870 local dummytable = { } -- dummy
871 local dtvo, dtvh = {}, {}
872 setmetatable(dtvo, {__index = function () return 0.88 end } )
873 setmetatable(dtvh, {__index = function () return 1 end } )
874 ltjr.vert_addfunc = function(id, s)
875 if not dummytable.rotation then
876 dummytable = list_rotate_glyphs(s, dummytable)
877 dummytable.vorigin, dummytable.vheight = dtvo, dtvh
881 local function prepare_extra_data_font(id, res, name)
882 if type(res)=='table' and (res.psname or res.filename) then
883 if (res.embedding=='no') and (type(name)=='string') and (name:sub(1,5)=='psft:') then
884 font_extra_info[id] = res.resources.ltj_extra
886 local bname = res.psname or nameonly(res.filename)
887 local t = font_extra_basename[bname]
888 if not t then bname = prepare_extra_data_base(res) end
889 font_extra_info[id] = bname and (t or font_extra_basename[bname]) or dummytable
893 luatexbase.add_to_callback(
894 'luaotfload.patch_font',
896 -- these function is executed one time per one fontfile
897 prepare_extra_data_base(tfmdata); return tfmdata
899 'ltj.prepare_extra_data', 1)
900 luatexbase.add_to_callback(
901 'luatexja.define_font',
902 function (res, name, size, id)
903 prepare_extra_data_font(id, res, name)
905 'ltj.prepare_extra_data', 1)
907 for i=1,font.nextid()-1 do
908 local t = font.getfont(i)
910 prepare_extra_data_base(t)
911 prepare_extra_data_font(i,t)
916 ------------------------------------------------------------------------
917 -- make table of vertical glyphs which does not covered by vert feature
919 ------------------------------------------------------------------------
921 ------------------------------------------------------------------------
922 -- VERT VARIANT TABLE
923 ------------------------------------------------------------------------
924 local provides_feature = luaotfload.aux.provides_feature
925 local vert_form_table = {
926 [0x3001]=0xFE11, [0x3002]=0xFE12, [0x3016]=0xFE17, [0x3017]=0xFE18,
928 [0x2025]=0xFE30, [0x2014]=0xFE31, [0x2013]=0xFE32, [0xFF3F]=0xFE33,
929 [0xFF08]=0xFE35, [0xFF09]=0xFE36, [0xFF5B]=0xFE37, [0xFF5D]=0xFE38,
930 [0x3014]=0xFE39, [0x3015]=0xFE3A, [0x3010]=0xFE3B, [0x3011]=0xFE3C,
931 [0x300A]=0xFE3D, [0x300B]=0xFE3E, [0x3008]=0xFE3F, [0x3009]=0xFE40,
932 [0x300C]=0xFE41, [0x300D]=0xFE42, [0x300E]=0xFE43, [0x300F]=0xFE44,
933 [0xFF3B]=0xFE47, [0xFF3D]=0xFE48,
935 local vert_jpotf_table, vert_feat = {}, {vert=true}
936 local utfbyte, utfsub = utf.byte, utf.sub
937 luatexja.jfont.register_vert_replace = function(t)
938 for i,v in pairs(t) do
939 local ic = (type(i)=='number') and i or
940 ((type(i)=='string') and utfbyte(utfsub(i,1,1)) or nil)
942 vert_jpotf_table[ic] = (type(v)=='number') and v or
943 ((type(v)=='string') and utfbyte(utfsub(v,1,1)) or nil)
948 luatexbase.add_to_callback(
949 "luatexja.define_jfont",
950 function (fmtable, fnum)
951 local vform = {}; fmtable.vform = vform
952 local t = font_getfont(fnum)
953 if not t then return fmtable end
954 for i,v in pairs(vert_form_table) do
955 if t.characters[v] then vform[i] = v end
957 if ltju.specified_feature(fnum, 'jpotf') then
958 for i,v in pairs(vert_jpotf_table) do
959 if t.characters[v] then vform[i] = vform[v] or v end
962 if not ltju.exist_feature(fnum, 'vert') and not ltju.exist_feature(fnum, 'vrt2') then
963 -- 現在の (script, lang) で vert もvrt2 も有効にできない場合,
964 -- 全 (script,lang) の vert を強制的に適用
965 ltju.loop_over_feat(t, vert_feat, function (i,k) vform[i] = vform[i] or k end, true)
967 -- vform の中身を vert 適用結果に変える
968 ltju.loop_over_feat(t, vert_feat,
970 for j,w in pairs(vform) do
971 if (i==j)and(w==k) then vform[j]=nil elseif w==i then vform[j] = k end
975 end, 'ltj.get_vert_form', 1
979 ------------------------------------------------------------------------
980 -- supply tounicode entries
981 ------------------------------------------------------------------------
983 local ltjr_prepare_cid_font = ltjr.prepare_cid_font
984 luatexbase.add_to_callback(
985 'luaotfload.patch_font',
987 local cidinfo = tfmdata.cidinfo or (tfmdata.resource and tfmdata.resources.cidinfo)
988 if cidinfo and cidinfo.registry and cidinfo.ordering then
989 local rd = ltjr_prepare_cid_font(cidinfo.registry, cidinfo.ordering)
991 local ru = rd.resources.unicodes -- defined by LuaTeX-ja
992 local rc = rd.characters
993 for i,v in pairs(tfmdata.characters) do
994 local w = ru[cidinfo.ordering .. "." .. tostring(v.index)]
996 v.tounicode = v.tounicode or rc[w]. tounicode
1004 'ltj.supply_tounicode', 1)
1008 ------------------------------------------------------------------------
1010 ------------------------------------------------------------------------
1012 local getfont = node.direct.getfont
1013 local getchar = node.direct.getchar
1014 local get_dir_count = ltjd.get_dir_count
1015 local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct
1016 local ensure_tex_attr = ltjb.ensure_tex_attr
1017 local node_write = node.direct.write
1018 local fonts, getnest = font.fonts, tex.getnest
1019 local new_ic_kern = function(g) return node_new(id_kern,3) end
1020 local dir_tate = luatexja.dir_table.dir_tate
1021 -- EXT: italic correction
1022 function luatexja.jfont.append_italic()
1023 local p = to_direct(getnest().tail)
1024 local TEMP = node_new(id_kern)
1025 if p and getid(p)==id_glyph then
1026 if is_ucs_in_japanese_char(p) then
1027 local j = font_metric_table[
1028 get_attr(p, (get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt)
1030 local g = new_ic_kern()
1031 setkern(g, j.char_type[find_char_class(getchar(p), j)].italic)
1032 node_write(g); ensure_tex_attr(attr_icflag, 0)
1034 local f = getfont(p)
1035 local h = font_getfont(f) or fonts[f]
1037 if h.characters[getchar(p)] and h.characters[getchar(p)].italic then
1038 local g = new_ic_kern()
1039 setkern(g, h.characters[getchar(p)].italic)
1040 node_write(g); ensure_tex_attr(attr_icflag, 0)
1049 luatexja.jfont.metrics = metrics
1050 luatexja.jfont.font_metric_table = font_metric_table
1051 luatexja.jfont.find_char_class = find_char_class
1053 luatexja.jfont.update_jfm_cache = update_jfm_cache