From a9ba82ab6f70a1857b2c79ec2800be25b30c86df Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Fri, 31 Mar 2023 18:22:56 +0900 Subject: [PATCH] support table in JFM features (#47727) --- src/ltj-jfont.lua | 29 ++++++++++++++++++++--------- test/test33-jfm_feature.tex | 29 +++++++++++++++++++---------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index d32d9c3..8cb0fa4 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -397,20 +397,31 @@ do local jf_field = C(jf_field_char^1) local jf_assignment = jf_field * ws * equals * ws * jf_field local jf_switch = P'-' * jf_field * Cc(false) + P'+'^-1 * jf_field * Cc(true) - local jf_feature_expr = Cg(jf_assignment + jf_switch) * ws * comma^0 * ws + local jf_feature_expr = + P{ + 'FE', + FE = Cg(V'AT'+ jf_assignment + jf_switch) * ws * comma^0 * ws, + AT = jf_field * ws * equals * ws * Cf(Ct'' * P'{' * ws * (V'FE')^0 * P'}', rawset), + } local jf_feature_list = ws * ( P'{' * ws * jf_feature_expr^0 * P'}' + jf_feature_expr^0 ) local jf_list = C((1-slash)^1) * (slash * Cf(Ct'' * jf_feature_list, rawset))^-1 local jf_value = (1 - semicolon)^1 + local norm + norm = function (t) + local flag + if type(t)=='table' then + for i,v in pairs(t) do + flag=true + if v=='true' then t[i]=true elseif v=='false' then t[i]=false + elseif type(v)=='table' then norm(v) end + end + return flag and t + end + end local function rem(name,value) if name=='jfm' then - local flag, t; jfm_name, t = lpegmatch(jf_list, value) - if type(t)=='table' then - for i,v in pairs(t) do - flag=true - if v=='true' then t[i]=true elseif v=='false' then t[i]=false end - end - end - luatexja.jfont.jfm_feature = flag and t + local t; jfm_name, t = lpegmatch(jf_list, value) + luatexja.jfont.jfm_feature = norm(t) elseif name=='jfmvar' then jfm_var = value end return '' end diff --git a/test/test33-jfm_feature.tex b/test/test33-jfm_feature.tex index da89897..cb2f54f 100644 --- a/test/test33-jfm_feature.tex +++ b/test/test33-jfm_feature.tex @@ -40,6 +40,7 @@ {\testOA \testF A quick brown fox 跳』\inhibitglue (躍)(した:) over the のろ……まな 犬. + A quick fox 跳』\inhibitglue (躍)(した:) over the のろ……まな 犬.ああああああ } @@ -47,22 +48,30 @@ \def\printjfmfeat#1{% \relax{\tentt\string#1}: \directlua{% - if myjfm then - for i,v in pairs(myjfm) do - tex.sprint('[{\string\\tentt ' .. i .. '}]${}={}$') - if type(v)=='string' then - tex.sprint('``{\string\\tentt ' .. tostring(v) .. "}'', ") - else - tex.sprint(tostring(v) ..', ') + local fn + fn = function (t) + for i,v in pairs(t) do + tex.sprint('[{\string\\tentt ' .. i .. '}]${}={}$') + if type(v)=='string' then + tex.sprint('``{\string\\tentt ' .. tostring(v) .. "}'', ") + elseif type(v)=='table' then + tex.sprint('$\string\\{$'); fn(v); tex.sprint('$\string\\}$, ') + else + tex.sprint(tostring(v) ..', ') + end end end - else tex.sprint('(nil)') - end + if myjfm then fn(myjfm) else tex.sprint('(nil)') end }\par } -\jfont\testP="KozMinPr6N-Regular:jfm=ujis/h,-p,l=g,z=true;jfm=testf/ -so , lw = tr ,q,-d,-po, l=f,z=h,e, hwid;trad" at 9pt +\jfont\testP=KozMinPr6N-Regular:jfm=ujis/h,-p,l=g,z=true;jfm=testf/q,-d,l=f,z=h,e,hwid;trad at 9pt \printjfmfeat\testP \testP イ医学 +\jfont\testQ=KozMinPr6N-Regular:jfm=testf/{+w,h={+a,-b,c=true,u=x,t={s,a}},-o,d={}};trad at 9pt +\printjfmfeat\testQ + +\jfont\testR=KozMinPr6N-Regular:jfm=testf/{};trad at 9pt +\printjfmfeat\testR \bye -- 2.11.0