From d452ba546ab15163fe51317453bef5a01552dd00 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Thu, 24 Sep 2015 10:40:00 +0900 Subject: [PATCH] Changed the value type of ksp_{natural,stretch,shrink} to a float. --- doc/luatexja.dtx | 31 ++++++++-------- src/jfm-ujis.lua | 100 ++++++++++++++++++++++++++-------------------------- src/ltj-jfmglue.lua | 20 +++++------ src/ltj-jfont.lua | 23 +++++++++--- 4 files changed, 95 insertions(+), 79 deletions(-) diff --git a/doc/luatexja.dtx b/doc/luatexja.dtx index 6743fcd..0c159e4 100644 --- a/doc/luatexja.dtx +++ b/doc/luatexja.dtx @@ -4464,24 +4464,24 @@ we specify to $0.25/(0.5+0.25)=1/3$. 度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」 ことを意味する.省略時の値 は0であり,範囲外の値が指定されたときの動作は未定義である. -\item[ksp\_natural=\textrm{, }% - ksp\_stretch=\textrm{, }ksp\_shrink=]\leavevmode +\item[ksp\_natural=\textrm{, }% + ksp\_stretch=\textrm{, }ksp\_shrink=]\leavevmode JFMによって本来挿入されるグルーの他に \Param{kanjiskip}分の空白を自然長(\texttt{ksp\_natural}),伸び量(\texttt{ksp\_stretch}), 縮み量(\texttt{ksp\_shrink})ごとに挿入する\footnote{本来\Param{xkanjiskip}が挿入される場所においては \Param{xkanjiskip}分の空白を自然長・伸び量・縮み量ごとに.追加できる.}% -ための指定である. +ための指定である.いずれも省略された場合のデフォルト値は0(追加しない)である. 例えば,\LuaTeX-jaの横組標準JFMの \texttt{jfm-ujis.lua} では, \begin{itemize} \item 通常の文字「あ」と開き括弧類の間に入るグルーは,自然長・縮み量半角,伸び量0のグルー -となっているが,\texttt{ksp\_stretch=true} のおかげで,さらに\Param{kanjiskip}の伸び量だけ -伸びることが許される. +となっているが,さらに\Param{kanjiskip}の伸び量に \texttt{ksp\_stretch}(ここでは1)を掛け + た分だけ伸びることが許される. \item 同様に,閉じ括弧類(全角コンマ「,」も含む)と通常の文字「う」「え」の間にも 自然長・縮み量半角,伸び量0のグルー -となっているが,\texttt{ksp\_stretch=true} のおかげで,さらに\Param{kanjiskip}の伸び量だけ -伸びることが許される. +となっているが,さらに\Param{kanjiskip}の伸び量に \texttt{ksp\_stretch}(ここでは1)を掛け + た分だけ伸びることが許される. \end{itemize} となっている.従って,以下のような組版結果を得る. @@ -4503,22 +4503,25 @@ An integer in $[-2,2]$ (treated as 0 if omitted), and this is used only in line adjustment with priority by \Pkg{luatexja-adjust} (see Subsection~\ref{ssec-adj}). Higher value means the glue is easy to stretch, and is also easy to shrink. -\item[ksp\_natural=\textrm{, }% - ksp\_stretch=\textrm{, }ksp\_shrink=]\leavevmode +\item[ksp\_natural=\textrm{, }% + ksp\_stretch=\textrm{, }ksp\_shrink=]\leavevmode These keys specifies whether the natural width of \Param{kanjiskip} (the stretch/shrink part, respectively) will be inserted in addition to the original -JFM glue. +JFM glue. Default values of them are all 0. As an example, in \texttt{jfm-ujis.lua}, the standard JFM in horizontal writing, we have \begin{itemize} \item Between an ordinal letter ``あ'' and an ideographic opening bracket, we have a glue whose natural part and shrink part are both half-width, while its stretch part is - zero. However, because of \texttt{ksp\_stretch=true}, this glue can be stretched - as much as \Param{kanjiskip}. + zero. However, this glue also can be stretched + as much as the stretch part of \Param{kanjiskip} times the value of + \texttt{ksp\_stretch} key (1 in this case). \item Between an ideographic closeing brackets (the ideographic comma ``,'' - is included) and an ordinal letter, we have the same glue. Again, because of -\texttt{ksp\_stretch=true}, this glue can be stretched as much as \Param{kanjiskip}. + is included) and an ordinal letter, we have the same glue. + Again, this glue also can be stretched + as much as the stretch part of \Param{kanjiskip} times the value of + \texttt{ksp\_stretch} key (1 in this case). \end{itemize} Hence we have the following result: diff --git a/src/jfm-ujis.lua b/src/jfm-ujis.lua index b9536bc..4f3a568 100644 --- a/src/jfm-ujis.lua +++ b/src/jfm-ujis.lua @@ -18,13 +18,13 @@ luatexja.jfont.define_jfm { glue = { -- [index] = { width, stretch, shrink, [priority, [ratio]], -- ksp_nat=t/f, ksp_stretch=t/f, ksp_shrink=t/f } - [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true }, - [2] = { 0, 0, 0, ksp_shrink=true }, + [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=1 }, + [2] = { 0, 0, 0, ksp_shrink=1 }, [3] = { 0.25, 0.0, 0.25, priority=1, ratio=1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [6] = { 0, 0, 0, ksp_shrink=true }, - [7] = { 0, 0, 0, ksp_shrink=true }, - [8] = { 0, 0, 0, ksp_shrink=true }, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [6] = { 0, 0, 0, ksp_shrink=1 }, + [7] = { 0, 0, 0, ksp_shrink=1 }, + [8] = { 0, 0, 0, ksp_shrink=1 }, } }, @@ -37,15 +37,15 @@ luatexja.jfont.define_jfm { width = 0.5, height = 0.88, depth = 0.12, italic=0.0, glue = { -- 3 のみ四分,あとは0 - [0] = { 0, 0, 0, ksp_shrink=true }, - [1] = { 0, 0, 0, ksp_shrink=true }, - [2] = { 0, 0, 0, ksp_shrink=true }, + [0] = { 0, 0, 0, ksp_shrink=1 }, + [1] = { 0, 0, 0, ksp_shrink=1 }, + [2] = { 0, 0, 0, ksp_shrink=1 }, [3] = { 0.25, 0.0, 0.25, priority=1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [5] = { 0, 0, 0, ksp_shrink=true }, - [6] = { 0, 0, 0, ksp_shrink=true }, - [7] = { 0, 0, 0, ksp_shrink=true }, - [8] = { 0, 0, 0, ksp_shrink=true }, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [5] = { 0, 0, 0, ksp_shrink=1 }, + [6] = { 0, 0, 0, ksp_shrink=1 }, + [7] = { 0, 0, 0, ksp_shrink=1 }, + [8] = { 0, 0, 0, ksp_shrink=1 }, } }, @@ -58,15 +58,15 @@ luatexja.jfont.define_jfm { width = 0.5, height = 0.88, depth = 0.12, italic=0.0, glue = { -- 3 は四分, 2, 4, 9 は0, あとは0.5 - [0] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [1] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [2] = { 0, 0, 0, ksp_shrink=true}, + [0] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [1] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [2] = { 0, 0, 0, ksp_shrink=1}, [3] = { 0.25, 0.0, 0.25, priority=1, ratio=1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [5] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [6] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [7] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [8] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [5] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [6] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [7] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [8] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, } }, @@ -95,13 +95,13 @@ luatexja.jfont.define_jfm { width = 0.5, height = 0.88, depth = 0.12, italic=0.0, glue = { -- 3 は.75, 2, 4 は0, あとは0.5 - [0] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [1] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [3] = { 0.75, 0.0, 0.25, priority=1, ratio=1/3, ksp_stretch=true }, - [5] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [6] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [7] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, - [8] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true }, + [0] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [1] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [3] = { 0.75, 0.0, 0.25, priority=1, ratio=1./3, ksp_stretch=1 }, + [5] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [6] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [7] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, + [8] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=1 }, } }, @@ -110,11 +110,11 @@ luatexja.jfont.define_jfm { align = 'left', left = 0.0, down = 0.0, width = 1.0, height = 0.88, depth = 0.12, italic=0.0, glue = { - [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true }, - [2] = { 0, 0, 0, ksp_shrink=true }, + [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=1 }, + [2] = { 0, 0, 0, ksp_shrink=1 }, [3] = { 0.25, 0.0, 0.25, priority=1, ratio=1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [6] = { 0, 0, 0, ksp_shrink=true }, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [6] = { 0, 0, 0, ksp_shrink=1 }, }, kern = { [5] = 0.0 @@ -126,14 +126,14 @@ luatexja.jfont.define_jfm { align = 'left', left = 0.0, down = 0.0, width = 1.0, height = 0.88, depth = 0.12, italic=0.0, glue = { - [0] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true }, - [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true }, - [2] = { 0, 0, 0, ksp_shrink=true }, + [0] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=1 }, + [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=1 }, + [2] = { 0, 0, 0, ksp_shrink=1 }, [3] = { 0.75, 0.0, 0.25, priority=1, ratio=1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [6] = { 0, 0, 0, ksp_shrink=true }, - [7] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true }, - [8] = { 0, 0, 0, ksp_shrink=true }, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [6] = { 0, 0, 0, ksp_shrink=1 }, + [7] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=1 }, + [8] = { 0, 0, 0, ksp_shrink=1 }, }, kern = { [5] = 0.0 @@ -165,13 +165,13 @@ luatexja.jfont.define_jfm { align = 'left', left = 0.0, down = 0.0, width = 0.5, height = 0.88, depth = 0.12, italic=0.0, glue = { - [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true }, - [2] = { 0, 0, 0, ksp_shrink=true }, + [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=1 }, + [2] = { 0, 0, 0, ksp_shrink=1 }, [3] = { 0.25, 0.0, 0.25, priority=1, ratio=1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [6] = { 0, 0, 0, ksp_shrink=true}, - [7] = { 0, 0, 0, ksp_shrink=true }, - [8] = { 0, 0, 0, ksp_shrink=true}, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [6] = { 0, 0, 0, ksp_shrink=1}, + [7] = { 0, 0, 0, ksp_shrink=1 }, + [8] = { 0, 0, 0, ksp_shrink=1}, } }, @@ -197,11 +197,11 @@ luatexja.jfont.define_jfm { align = 'left', left = 0.0, down = 0.0, width = 1.0, height = 0.88, depth = 0.12, italic=0.0, glue = { - [1] = { 0.5 , 0.0, 0.5, 0, 1, ksp_stretch=true }, - [2] = { 0, 0, 0, ksp_shrink=true }, + [1] = { 0.5 , 0.0, 0.5, 0, 1, ksp_stretch=1 }, + [2] = { 0, 0, 0, ksp_shrink=1 }, [3] = { 0.25, 0.0, 0.25, 1, 1 }, - [4] = { 0, 0, 0, ksp_shrink=true }, - [6] = { 0, 0, 0, ksp_shrink=true }, + [4] = { 0, 0, 0, ksp_shrink=1 }, + [6] = { 0, 0, 0, ksp_shrink=1 }, }, kern = { [8] = 0.0 diff --git a/src/ltj-jfmglue.lua b/src/ltj-jfmglue.lua index 8633b22..25b2e06 100644 --- a/src/ltj-jfmglue.lua +++ b/src/ltj-jfmglue.lua @@ -790,9 +790,9 @@ do local gx = node_new(id_glue_spec); setfield(gx, 'stretch_order', 0); setfield(gx, 'shrink_order', 0) local bk = qm.kanjiskip or null_skip_table - setfield(gx, 'width', bn and bk[1] or 0) - setfield(gx, 'stretch', bp and bk[2] or 0) - setfield(gx, 'shrink', bh and bk[3] or 0) + setfield(gx, 'width', bn and (bn*bk[1]) or 0) + setfield(gx, 'stretch', bp and (bp*bk[2]) or 0) + setfield(gx, 'shrink', bh and (bh*bk[3]) or 0) setfield(g, 'spec', gx) set_attr(g, attr_icflag, KANJI_SKIP_JFM) return g @@ -803,9 +803,9 @@ do local gx = node_new(id_glue_spec); setfield(gx, 'stretch_order', 0); setfield(gx, 'shrink_order', 0) local ks = getfield(kanji_skip, 'spec') - setfield(gx, 'width', bn and getfield(ks, 'width') or 0) - setfield(gx, 'stretch', bp and getfield(ks, 'stretch') or 0) - setfield(gx, 'shrink', bh and getfield(ks, 'shrink') or 0) + setfield(gx, 'width', bn and (bn*getfield(ks, 'width')) or 0) + setfield(gx, 'stretch', bp and (bp*getfield(ks, 'stretch')) or 0) + setfield(gx, 'shrink', bh and (bh*getfield(ks, 'shrink')) or 0) setfield(g, 'spec', gx) set_attr(g, attr_icflag, KANJI_SKIP_JFM) return g @@ -817,10 +817,10 @@ do if Np.auto_kspc or Nq.auto_kspc then local pm, qm = Np.met, Nq.met if (pm.char_type==qm.char_type) and (qm.var==pm.var) then - return get_kanjiskip_low(true, qm, true, true, true) + return get_kanjiskip_low(true, qm, 1, 1, 1) else - local gb = get_kanjiskip_low(true, qm, true, true, true) - local ga = get_kanjiskip_low(true, pm, true, true, true) + local gb = get_kanjiskip_low(true, qm, 1, 1, 1) + local ga = get_kanjiskip_low(true, pm, 1, 1, 1) return calc_ja_ja_aux(gb, ga, 0, 1) end else @@ -899,7 +899,7 @@ do get_xkanjiskip = function(Nn) if (Nq.xspc>=2) and (Np.xspc%2==1) and (Nq.auto_xspc or Np.auto_xspc) then - return get_xkanjiskip_low(true, Nn.met, true, true, true) + return get_xkanjiskip_low(true, Nn.met, 1, 1, 1) else local g = node_copy(zero_glue) set_attr(g, attr_icflag, xkanjiskip_jfm_flag and XKANJI_SKIP_JFM or XKANJI_SKIP) diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 7e4b3f1..68c2c2a 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -52,6 +52,17 @@ local jfm_file_name, jfm_var local defjfm_res local jfm_dir, is_def_jfont, is_vert_enabled +local function norm_val(a) + if (not a) or (a==0.) then + return nil + elseif a==true then + return 1 + else + return a + end +end + + function define_jfm(t) local real_char -- Does current character class have the 'real' character? if t.dir~=jfm_dir then @@ -112,9 +123,12 @@ function define_jfm(t) end v.kern = v.kern or {}; v.glue = v.glue or {} for j,x in pairs(v.glue) do + if v.kern[j] then defjfm_res= nil; return end x.ratio, x[5] = (x.ratio or (x[5] and 0.5*(1+x[5]) or 0.5)), nil x.priority, x[4] = (x.priority or x[4] or 0), nil - if v.kern[j] then defjfm_res= nil; return end + x.ksp_natural = norm_val(x.ksp_natural) + x.ksp_stretch = norm_val(x.ksp_stretch) + x.ksp_shrink = norm_val(x.ksp_shrink) end for j,x in pairs(v.kern) do if type(x)=='number' then @@ -149,7 +163,6 @@ do return new else return nil end end - update_jfm_cache = function (j,sz) if metrics[j].size_cache[sz] then return end --local TEMP = node_new(id_kern) @@ -167,9 +180,9 @@ do true, h, ratio=w.ratio/sz, priority=FROM_JFM + w.priority/sz, - ksp_natural = w.ksp_natural, - ksp_stretch = w.ksp_stretch, - ksp_shrink = w.ksp_shrink, + ksp_natural = w.ksp_natural and w.ksp_natural/sz, + ksp_stretch = w.ksp_stretch and w.ksp_stretch/sz, + ksp_shrink = w.ksp_shrink and w.ksp_shrink/sz, } setfield(h, 'width', w[1]) setfield(h, 'stretch', w[2]) -- 2.11.0