OSDN Git Service

Changed the syntax of JFM file (but the old way is still supported)
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 20 Sep 2015 00:10:11 +0000 (09:10 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 20 Sep 2015 00:10:11 +0000 (09:10 +0900)
Note that luatexja-adjust is broken with this implementation...

doc/luatexja.dtx
src/jfm-ujis.lua
src/ltj-jfmglue.lua
src/ltj-jfont.lua

index 16bb397..1e2ae1b 100644 (file)
 \DeclareRobustCommand\epTeX{\ensuremath{\varepsilon}-\pTeX}
 
 %%%%%%%% other macros
-\newlist{cslist}{description}{1}
+\newlist{cslist}{description}{2}
 \setlist[cslist]{%
     style=nextline,font=\mdseries\ttfamily,
     before*=\def\<{\char`\<}\def\>{\char`\>}\def\{{\char`\{}\def\}{\char`\}},
+    topsep=\medskipamount,
 %<ja> leftmargin=2\zw,
 %<en> leftmargin=2em,
 }
@@ -4418,38 +4419,23 @@ Furthermore, the glyph is shifted according to values of fields
 \label{fig-pos-tate}
 \end{figure}
 
-\item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [<ratio>]\}, ...\}}]
+\item[kern={\{[$j$]=<kern>, [$j'$]=\{<kern>, [ratio=<ratio>]\}, ...\}}]
 
-\item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [<priority>], [<ratio>]\}, ...\}}]\
+\item[glue={\{[$j$]=\{<width>, <stretch>, <shrink>, [ratio=<ratio>, ...]\}, ...\}}]\leavevmode
 %<*ja>
 
-文字クラス$i$の文字と$j$の文字の間に挿入されるkernやglueの量を指定する.
+文字クラス$i$の文字と$j$の文字の間に挿入されるカーンやグルーの量を指定する.
 
-             <priority>は \Pkg{luatexja-adjust} による優先順位付き
-            行長調整(\ref{ssec-adj}節)が有効なときのみ意味を持つ.
-このフィールドは省略可能であり,行調整処理におけるこのglueの優先
-             度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
-             ことを意味する.省略時の値
-             は0であり,範囲外の値が指定されたときの動作は未定義である.
-
-<ratio>も省略可能フィールドであり,$-1$から$+1$の実数値をとる.省略時の値は0である.
-\begin{itemize}
-\item $-1$はこのグルーが「前の文字」由来であることを示す.
-\item $+1$はこのグルーが「後の文字」由来であることを示す.
-\item それ以外の値は,「前の文字」由来のグルーと「後の文字」由来の
-グルーが混合されていることを示す.
-\end{itemize}
-なお,このフィールドの値は\Param{differentjfm}の値が
+<ratio>は,グルーの自然長のうちどれだけの割合が「後の文字」由来かを示す量で,
+$0$から$+1$の実数値をとる.省略時の値は$0.5$である.
+このフィールドの値は\Param{differentjfm}の値が
 \texttt{pleft},~\texttt{pright},~\texttt{paverage}の値のときのみ実際に用いられる.
 
 例えば,\cite{x4051}では,句点と中点の間には,
 句点由来の二分空きと中点由来の四分空きが挿入されるが,この場合には
 \begin{itemize}
 \item <width>には$0.5+0.25=0.75$を指定する.
-\item <ratio>には次の値を指定する.
-\[
- -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13
-\]
+\item <ratio>には$0.25/(0.5+0.25)=1/3$を指定する.
 \end{itemize}
 %</ja>
 %<*en>
@@ -4458,22 +4444,45 @@ Furthermore, the glyph is shifted according to values of fields
 Specifies the width of kern or glue which will be inserted
 between characters in character class~$i$ and those in character class~$j$.
 
-<priority> is 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 shretch,
-and is also easy to shrink.
-
-<ratio> is also an optional value between $-1$ and 1. For example,
+<ratio> specifies how much the glue is originated in the ``right'' character.
+It is a real number between 0 and 1, and treated as 0.5 if omitted. For example,
 The width of a glue between an ideographic full stop ``。''
 and a fullwidth middle dot ``・'' is three-fourth of fullwidth,
 namely halfwidth from the ideographic full stop, and
 quarter-width from the fullwidth middle dot.  In this case,
-we specify <ratio> to
-\[
-  -1\cdot \frac{0.5}{0.5+0.25} + 1 \cdot \frac{0.25}{0.5+0.25} = -\frac13.
-\]
+we specify <ratio> to $0.25/(0.5+0.25)=1/3$.
 %</en>
 
+%<*ja>
+グルーの指定においては,上記に加えて各 \texttt{[$j$]} の各サブテーブル内に
+次のキーを指定できる,
+\begin{cslist}[style=standard]
+\item[priority=<priority>]
+             \Pkg{luatexja-adjust} による優先順位付き
+            行長調整(\ref{ssec-adj}節)の際に使われる値であり,
+行調整処理におけるこのglueの優先
+             度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」
+             ことを意味する.省略時の値
+             は0であり,範囲外の値が指定されたときの動作は未定義である.
+\item[ksp\_natural=<bool>]
+\item[ksp\_stretch=<bool>]
+\item[ksp\_shrink=<bool>]
+\end{cslist}
+%</ja>
+%<*en>
+In case of glue, one can specify following additional keys in each \texttt{[$j$]}
+            subtable:
+\begin{cslist}[style=standard]
+\item[priority=<priority>]
+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=<bool>]
+\item[ksp\_stretch=<bool>]
+\item[ksp\_shrink=<bool>]
+\end{cslist}
+%</en>
 
 \item[end\_stretch=<kern>, end\_shrink=<kern>]
 %<*ja>
index a69ce5c..10a21a3 100644 (file)
 luatexja.jfont.define_jfm {
    dir = 'yoko',
    zw = 1.0, zh = 1.0,
-   kanjiskip =  {0.0, 0.25, 0},
-   xkanjiskip = {0.25, 0.25, .125},
+   kanjiskip =  { 0.0, 0.25, 0 },
+   xkanjiskip = { 0.25, 0.25, .125 },
    [0] = {
       align = 'left', left = 0.0, down = 0.0,
       width = 1.0, height = 0.88, depth = 0.12, italic=0.0,
       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,  0, 1, ksp_stretch=true },
-        [2] = { 0, 0, 0 , ksp_shrink=true },
-        [3] = { 0.25, 0.0, 0.25, 1, 1 },
-        [4] = {0, 0, 0},
-        [6] = {0, 0, 0},
-        [7] = {0, 0, 0},
-         [8] = {0, 0, 0},
-        [9] = {0, 0, 0},
+        [1] = { 0.5 , 0.0, 0.5, rario=1, ksp_stretch=true },
+        [2] = { 0, 0, 0, ksp_shrink=true },
+        [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 },
+        [99] = { 0, 0, 0 },
       }
    },
 
@@ -38,16 +38,16 @@ 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},
-        [2] = {0, 0, 0},
-        [3] = { 0.25, 0.0, 0.25, 1 },
-        [4] = {0, 0, 0},
-        [5] = {0, 0, 0},
-        [6] = {0, 0, 0},
-        [7] = {0, 0, 0},
-         [8] = {0, 0, 0},
-        [9] = {0, 0, 0},
+         [0] = { 0, 0, 0, ksp_shrink=true },
+         [1] = { 0, 0, 0, ksp_shrink=true },
+        [2] = { 0, 0, 0, ksp_shrink=true },
+        [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 },
+        [99] = { 0, 0, 0 },
       }
    },
 
@@ -60,16 +60,16 @@ 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, 0, -1, ksp_stretch=true },
-        [1] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-         [2] = {0, 0, 0},
-        [3] = { 0.25, 0.0, 0.25, 1, 1 },
-         [4] = {0, 0, 0},
-        [5] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [6] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [7] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [8] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-         [9] = {0, 0, 0},
+        [0] = { 0.5 , 0.0, 0.5, rario=0, ksp_stretch=true },
+        [1] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true },
+         [2] = { 0, 0, 0, ksp_shrink=true},
+        [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 },
+         [99] = { 0, 0, 0 },
       }
    },
 
@@ -80,16 +80,16 @@ luatexja.jfont.define_jfm {
       --end_stretch = 0.25,
       glue = {
 -- 3 のみ 0.5,あとは0.25
-        [0] = { 0.25, 0.0, 0.25, 1, 1 },
-        [1] = { 0.25, 0.0, 0.25, 1, 1 },
-        [2] = { 0.25, 0.0, 0.25, 1, 1 },
-        [3] = { 0.5 , 0.0, 0.5 , 1, 0 },
-        [4] = { 0.25, 0.0, 0.25, 1, 1 },
-        [5] = { 0.25, 0.0, 0.25, 1, 1 },
-        [6] = { 0.25, 0.0, 0.25, 1, 1 },
-        [7] = { 0.25, 0.0, 0.25, 1, 1 },
-        [8] = { 0.25, 0.0, 0.25, 1, 1 },
-        [9] = { 0.25, 0.0, 0.25, 1, 1 },
+        [0] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [1] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [2] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [3] = { 0.5 , 0.0, 0.5 , priority=1 },
+        [4] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [5] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [6] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [7] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [8] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
+        [99] = { 0.25, 0.0, 0.25, priority=1, ratio=1 },
       }
    },
 
@@ -99,14 +99,14 @@ 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, 0, -1, ksp_stretch=true },
-        [1] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [3] = { 0.75, 0.0, 0.25, 1, -1/3 },
-        [5] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [6] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [7] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-        [8] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
-         [9] = { 0.5 , 0.0, 0.5, 0, -1, ksp_stretch=true },
+        [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 },
+         [99] = { 0.5 , 0.0, 0.5, ratio=0, ksp_stretch=true },
       }
    },
 
@@ -115,12 +115,12 @@ 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},
-        [3] = { 0.25, 0.0, 0.25, 1, 1 },
-        [4] = {0, 0, 0},
-        [6] = {0, 0, 0},
-        [9] = {0, 0, 0},
+        [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true },
+        [2] = { 0, 0, 0, ksp_shrink=true },
+        [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 },
+        [99] = { 0, 0, 0 },
       },
       kern = {
         [5] = 0.0
@@ -132,15 +132,15 @@ 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, 0, 1, ksp_stretch=true },
-        [1] = { 0.5 , 0.0, 0.5, 0, 1, ksp_stretch=true },
-        [2] = {0, 0, 0},
-        [3] = { 0.75, 0.0, 0.25, 1, 1 },
-        [4] = {0, 0, 0},
-        [6] = {0, 0, 0},
-        [7] = { 0.5 , 0.0, 0.5, 0, 1, ksp_stretch=true},
-        [8] = {0, 0, 0},
-        [9] = {0, 0, 0},
+         [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 },
+        [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 },
+        [99] = { 0, 0, 0 },
       },
       kern = {
         [5] = 0.0
@@ -172,14 +172,14 @@ 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, 0, 1, ksp_stretch=true },
-        [2] = {0, 0, 0},
-        [3] = { 0.25, 0.0, 0.25, 1, 1 },
-        [4] = {0, 0, 0},
-        [6] = {0, 0, 0},
-        [7] = {0, 0, 0},
-         [8] = {0, 0, 0},
-        [9] = {0, 0, 0},
+        [1] = { 0.5 , 0.0, 0.5, ratio=1, ksp_stretch=true },
+        [2] = { 0, 0, 0, ksp_shrink=true },
+        [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},
+        [99] = { 0, 0, 0 },
       }
    },
 
@@ -206,11 +206,11 @@ luatexja.jfont.define_jfm {
       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},
+        [2] = { 0, 0, 0, ksp_shrink=true },
         [3] = { 0.25, 0.0, 0.25, 1, 1 },
-        [4] = {0, 0, 0},
-        [6] = {0, 0, 0},
-        [9] = {0, 0, 0},
+        [4] = { 0, 0, 0, ksp_shrink=true },
+        [6] = { 0, 0, 0, ksp_shrink=true },
+        [99] = {0, 0, 0},
       },
       kern = {
         [8] = 0.0
@@ -221,7 +221,7 @@ luatexja.jfont.define_jfm {
    [99] = { -- box末尾
       chars = {'boxbdd', 'parbdd'},
       glue = {
-        [3] = { 0.25, 0.0, 0.25, 1 },
+        [3] = { 0.25, 0.0, 0.25, priority=1 },
       }
    },
 
index 5d30dcb..464cb99 100644 (file)
@@ -688,21 +688,21 @@ local function new_jfm_glue(m, bc, ac, ks)
    if g then
       if g[1] then
         local f = node_new(id_glue)
-        set_attr(f, attr_icflag, g[4])
+        set_attr(f, attr_icflag, g.priority)
         local fs = node_copy(g[2])
         if g.ksp_natural then
            setfield(fs, 'width', getfield(fs,'width')+getfield(ks, 'width'))
         end
-        if g.ksp_stretch then
+        if false and g.ksp_stretch then
            setfield(fs, 'stretch', getfield(fs,'stretch')+getfield(ks, 'stretch'))
         end
         if g.ksp_shrink then
            setfield(fs, 'shrink', getfield(fs,'shrink')+getfield(ks, 'shrink'))
         end
         setfield(f, 'spec', fs)
-        return f, g[3]
+        return f, g.ratio
       else
-        return node_copy(g[2]), g[3]
+        return node_copy(g[2]), g.ratio
       end
    end
    return nil, 0
@@ -770,8 +770,8 @@ do
    local bk_ak = 2*id_kern - id_kern
 
    calc_ja_ja_aux = function (gb,ga, db, da)
-      local rbb, rab = 0.5*(1-db), 0.5*(1-da) -- 「前の文字」由来のグルーの割合
-      local rba, raa = 0.5*(1+db), 0.5*(1+da) -- 「前の文字」由来のグルーの割合
+      local rbb, rab = 1-db, 1-da -- 「前の文字」由来のグルーの割合
+      local rba, raa = db, da     -- 「後の文字」由来のグルーの割合
       if diffmet_rule ~= math.two_pleft and diffmet_rule ~= math.two_pright
           and diffmet_rule ~= math.two_paverage then
         rbb, rab, rba, raa = 1,0,0,1
index 99728ca..4b21f97 100644 (file)
@@ -111,14 +111,16 @@ function define_jfm(t)
            v.chars = nil
         end
         v.kern = v.kern or {}; v.glue = v.glue or {}
-        for j in pairs(v.glue) do
+        for j,x in pairs(v.glue) do
+           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
         end
         for j,x in pairs(v.kern) do
            if type(x)=='number' then
-               v.kern[j] = {x, 0}
+               v.kern[j] = {x, 0.5}
             elseif type(x)=='table' then
-               v.kern[j] = {x[1], x[2] or 0}
+               v.kern[j] = { x[1], ratio=x.ratio or x[2] or 0.5 }
             end
         end
         t.char_type[i] = v
@@ -162,8 +164,9 @@ do
            for k,w in pairs(v.glue) do
               local h = node_new(id_glue_spec)
               v[k] = {
-                 true, h, (w[5] and w[5]/sz or 0), 
-                 FROM_JFM + (w[4] and w[4]/sz or 0),
+                 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,
@@ -179,7 +182,7 @@ do
               setfield(g, 'kern', w[1])
               setfield(g, 'subtype', 1)
               set_attr(g, attr_icflag, FROM_JFM)
-              v[k] = {false, g, w[2]/sz}
+              v[k] = {false, g, ratio=w[2]/sz}
            end
         end
         v.glue, v.kern = nil, nil