From: Hironori Kitagawa Date: Sat, 11 Mar 2023 07:33:37 +0000 (+0900) Subject: new 'ltjpci' switch in \jfont and \tfont: protect CJK compatibility ideographs from... X-Git-Tag: 20230409.0~13 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=1772444748c647b18b773526d488e812cce0f2d6;p=luatex-ja%2Fluatexja.git new 'ltjpci' switch in \jfont and \tfont: protect CJK compatibility ideographs from normalization --- diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index a14edd2..263297c 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -3,7 +3,7 @@ -- luatexbase.provides_module({ name = 'luatexja.jfont', - date = '2022-08-20', + date = '2023-03-11', description = 'Loader for Japanese fonts', }) @@ -43,7 +43,7 @@ local font_metric_table = ltju.font_metric_table -- [font number] -> jfm_name, j luatexbase.create_callback("luatexja.load_jfm", "data", function (ft, jn) return ft end) -local jfm_spec, jfm_name, jfm_var, jfm_ksp +local jfm_spec, jfm_name, jfm_var, jfm_ksp, jfm_pci local defjfm_res local jfm_dir, is_def_jfont, vert_activated, auto_enable_vrt2 @@ -323,7 +323,7 @@ do update_jfm_cache(j, f.size); check_callback_order() local sz = metrics[j].size_cache[f.size] local fmtable = { jfm = j, size = f.size, var = jfm_var, - with_kanjiskip = jfm_ksp, + with_kanjiskip = jfm_ksp, protect_compat_ig = jfm_pci, zw = sz.zw, zh = sz.zh, chars = sz.chars, char_type = sz.char_type, kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip, @@ -451,6 +451,7 @@ do -- print('NN>', name) end jfm_ksp = (is_feature_specified(name,'ltjksp')~=false) + jfm_pci = (is_feature_specified(name,'ltjpci')~=false) if jfm_dir == 'tate' then vert_activated = (is_feature_specified(name,'vert')~=false) and (is_feature_specified(name,'vrt2')~=false) auto_enable_vrt2 @@ -623,7 +624,6 @@ function luatexja.jfont.replace_altfont(pf, pc) local a = alt_font_table[pf] return a and a[pc] or pf end - ------ for LaTeX interface local alt_font_table_latex = {} diff --git a/src/ltj-pretreat.lua b/src/ltj-pretreat.lua index 508de5b..9940960 100644 --- a/src/ltj-pretreat.lua +++ b/src/ltj-pretreat.lua @@ -110,9 +110,6 @@ do setfield(b, 'type', 100); setfield(b, 'user_id', JA_AL_BDD); insert_before(head, p, b) end - local pf = get_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 elseif prev_chartype==2 then @@ -144,6 +141,12 @@ local font_getfont = font.getfont local traverse_id = node.direct.traverse_id local cnt_stack = luatexbase.registernumber 'ltj@@stack' local texget, getvalue = tex.get, node.direct.getdata +-- + local compat_ig = {} + for i=0xf900, 0xfaff do compat_ig[i] = true end + for i=0x2f800, 0x2fa1f do compat_ig[i] = true end + local protect_glyph = node.direct.protect_glyph +-- function set_box_stack_level(head, mode) local box_set = 0 if mode then @@ -160,11 +163,25 @@ function set_box_stack_level(head, mode) if ltjs.list_dir == dir_tate then for p in 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( get_attr(p, attr_curtfnt) or getfont(p) , ltjs_orig_char_table[p]) + local pf, pc = get_attr(p, attr_curtfnt), ltjs_orig_char_table[p] + local nf = ltjf_replace_altfont( (pf and pf>0 and pf) or getfont(p), pc) setfont(p, nf) + if compat_ig[pc] and ltjf_font_metric_table[nf].protect_compat_ig then + protect_glyph(p) + end 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 + pc = ltjf_font_metric_table[nf].vform[pc]; if pc then setchar(p, pc) end + end + end + end + else + for p in traverse_id(id_glyph,to_direct(head)) do + if has_attr(p, attr_icflag, 0) and getlang(p)==lang_ja then + local pf, pc = get_attr(p, attr_curjfnt), ltjs_orig_char_table[p] + local nf = ltjf_replace_altfont( (pf and pf>0 and pf) or getfont(p), pc) + setfont(p, nf) + if compat_ig[pc] and ltjf_font_metric_table[nf].protect_compat_ig then + protect_glyph(p) end end end