OSDN Git Service

luatexja-adjust.sty に組み込み(ドキュメント途中)
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Thu, 26 Jul 2018 09:45:54 +0000 (18:45 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Thu, 26 Jul 2018 09:45:59 +0000 (18:45 +0900)
doc/luatexja.dtx
src/addons/luatexja-adjust.sty
src/ltj-adjust.lua
src/ltj-adjust_85.lua [deleted file]
test/test27-lineprofile.pdf
test/test27-lineprofile.tex

index 36fcbd8..f1acdf5 100644 (file)
@@ -635,7 +635,7 @@ and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
 %<en>The following packages are needed for the \LuaTeX-ja\ package.
 %<ja>\LuaTeX-jaパッケージの動作には次のパッケージ類が必要である.
 \begin{itemize}
-\item \LuaTeX\ beta-0.85.0 (or later)
+\item \LuaTeX\ 1.0.0 (or later)
 \item \Pkg{luaotfload} v2.6 (or later)
 \item \Pkg{adobemapping} (Adobe cmap and pdfmapping files)
 \item \Pkg{etoolbox}, \Pkg{everysel} (if you want to use \LuaTeX-ja with \LaTeXe)
@@ -644,9 +644,9 @@ and \emph{Japanese fonts} for fonts used in \textbf{JAchar}.
 %<en>\item \emph{IPAex fonts} (\url{http://ipafont.ipa.go.jp/})
 %<ja>\item \emph{IPAexフォント(\url{http://ipafont.ipa.go.jp/})}
 \end{itemize}
-%<en>In summary, \LuaTeX-ja version 20160404.0 (or~later) no longer supports \TeX~Live~2015.
+%<en>In summary, \LuaTeX-ja version 2018****.0 (or~later) no longer supports \TeX~Live~2016.
 %<*ja>
-要約すると,バージョン20160404.0以降の\LuaTeX-jaは\TeX~Live~2015以前では動作しない\footnote{%
+要約すると,バージョン2018****.0以降の\LuaTeX-jaは\TeX~Live~2016以前では動作しない\footnote{%
   もっとも,自分で\LuaTeX のバイナリをSubversionリポジトリからビルドしていれば話は別である.
 }.
 %</ja>
@@ -674,21 +674,6 @@ IPAex fonts are also available in these distributions.
 W32\TeX においてはIPAexフォントは \texttt{luatexja.tar.xz} 内にある.
 %</ja>
 
-% %<*ja>
-% 例えば\TeX~Live~2015を利用しているなら,\LuaTeX-jaは\TeX~Live manager (\texttt{tlmgr})を
-% 使ってインストールすることができる.
-% \begin{lstlisting}
-% $ tlmgr install luatexja
-% \end{lstlisting}
-% %</ja>
-% %<*en>
-% If you are using \TeX~Live~2015, you can install \LuaTeX-ja
-% from \TeX~Live manager (\texttt{tlmgr}):
-% \begin{lstlisting}
-% $ tlmgr install luatexja
-% \end{lstlisting}
-% %</en>
-
 %<en>\paragraph{Manual installation}
 %<ja>\paragraph{手動インストール方法}
 
@@ -6811,12 +6796,12 @@ for making the difference obvious.
 %<*ja>
 この追加パッケージは以下の機能を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい.
 \begin{description}
-\item[行末文字の位置調整]
+ \item[行末文字の位置調整]
   \pTeX では,(是非はともかく)「行末の読点はぶら下げか二分取りか全角取りのいずれかに」のように
   行末文字と実際の行末の位置関係を2通り以上にすることは面倒であった.
   和文フォントメトリックだけでは「常に行末の読点はぶら下げ」といったことしかできず,
   前の文に書いたことを実現するには
-\begin{lstlisting}
+  \begin{lstlisting}
 \def\。{%
   \penalty10000 % 禁則ペナルティ
   \hbox to0pt{。\hss}\penalty0 % ぶら下げの場合
@@ -6826,34 +6811,145 @@ for making the difference obvious.
 \end{lstlisting}
   のような命令を定義し,文中の全ての句点を \lstinline+\。+ で書くことが必要だった.
 
-\Pkg{luatexja-adjust}パッケージは,上で述べた行末文字と実際の行末との位置関係を
-2通り以上から自動的に選択する機能を提供する.
-\pdfTeX と同じように,「\TeX による行分割の後で行末文字の位置を補正する」方法と
-  「行分割の過程で行末文字の位置を考慮に入れる」方法を選べるようにした
-\Pkg{luatexja-adjust}パッケージの既定では前者).
+  \Pkg{luatexja-adjust}パッケージは,上で述べた行末文字と実際の行末との位置関係を
+  2通り以上から自動的に選択する機能を提供する.
+  \pdfTeX と同じように,「\TeX による行分割の後で行末文字の位置を補正する」方法と
+  「行分割の過程で行末文字の位置を考慮に入れる」方法を選べるようにした
+  (\Pkg{luatexja-adjust}パッケージの既定では前者).
   
-\item[優先順位付きの行長調整]
-\pTeX では,行長調整において優先度の概念が存在しなかったため,図
-\ref{fig:adj}上段における半角分の半端は,\autoref{fig:adj}中段のように,鍵
-括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し
-かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
-ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
-文字はベタ組で組まれる(\autoref{fig:adj}下段)ことになっている.
-\Pkg{luatexja-adjust}パッケージの提供する第2の機能は,
-\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
-の行長調整である.
-\begin{itemize}
- \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
-そのため,行分割の位置は変化することはない.
-
-\verb+\hbox{...}+ といった「途中で改行できない水平ボックス」では(たとえ幅が指定されていても)無効である.
- \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
-一般に変化する.そのため,既に組まれた段落を \cs{unhbox} などを利用して組み直す処理を
-行う場合には注意が必要である.
-\end{itemize}
+ \item[優先順位付きの行長調整]
+  \pTeX では,行長調整において優先度の概念が存在しなかったため,図
+  \ref{fig:adj}上段における半角分の半端は,\autoref{fig:adj}中段のように,鍵
+  括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し
+  かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい
+  ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文
+  文字はベタ組で組まれる(\autoref{fig:adj}下段)ことになっている.
+  \Pkg{luatexja-adjust}パッケージの提供する第2の機能は,
+  \cite{jlreq}や\cite{x4051}における規定のような,優先順位付き
+  の行長調整である.
+  \begin{itemize}
+   \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである.
+       そのため,行分割の位置は変化することはない.
+       
+       \verb+\hbox{...}+ といった「途中で改行できない水平ボックス」では(たとえ幅が指定されていても)無効である.
+   \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は
+       一般に変化する.そのため,既に組まれた段落を \cs{unhbox} などを利用して組み直す処理を
+       行う場合には注意が必要である.
+  \end{itemize}
+  
+ \item[「中身までみた」行送り計算]
+  複数行に渡る文章を組版するときには行間に空きが入ることが普通である.
+  \TeX では各行が一つずつの水平ボックスをなしていることを思い出すと,隣り合った
+  2つの行(つまり水平ボックス)の間の空きは次のようにして決まるのだった:
+  \begin{enumerate}
+   \item 「通常に組んだときの行間」$d$を,\cs{baselineskip}から
+       「前の行」の深さと「次の行」の高さを加えたものを引いた値とする.
+   \item $d\ge\cs{lineskiplimit}$の場合,
+       標準の行送り\cs{baselineskip}で組んでも十分な間隔があると判断され,
+       2行の間には長さ$d$の空白が挿入される.つまり行送りは\cs{baselineskip}.
+   \item {\catcode`\<=12$d<\cs{lineskiplimit}$}の場合,
+       2行の間には長さ\cs{lineskip}の空白が挿入される.
+       そのため(設定値によるが,多くの場合)行送りは\cs{baselineskip}より広がる.
+  \end{enumerate}
+
+  \begin{figure}[t]
+       \noindent\centering
+       \begin{minipage}[b]{18\zw}
+         \ltjenableadjust[profile=false, linestep=false]
+         ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
+         よって$b=\dfrac{1-\sqrt{5}}2$である.\\
+         これを②式に代入すると……
+         \par\vskip\abovecaptionskip
+         \ltjenableadjust[profile=false, linestep=false]
+         \par\centering\leavevmode{\small (a)}
+       \end{minipage}%
+       \kern2\zw
+       \begin{minipage}[b]{18\zw}
+         \ltjenableadjust[profile]
+         ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
+         よって$b=\dfrac{1-\sqrt{5}}2$である.\\
+         これを②式に代入すると……
+         \par\vskip\abovecaptionskip
+         \ltjenableadjust[profile=false, linestep=false]
+         \par\centering\leavevmode{\small (b)}
+       \end{minipage}\par
+         \caption{高い行が連続したときの状況}\label{fig:linegap1}
+  \end{figure}
+
+  以上で述べたことから,\TeX 標準では行送りの決定で「高さ・深さを取っているものが
+  行のどの水平位置にあるか」は一切考慮しない.そのため,
+  \autoref{fig:linegap1}~(a)のように「必要以上に行間が空いて見える」状況が起こる.
+
+  \Pkg{luatexja-adjust}パッケージでは,「通常に組んだときの行間」$d$を
+  各行の中身の文字・グルー・ボックスの寸法を勘案して計算するという方法を
+  利用できるようにした.この機能を使うと,\autoref{fig:linegap1}~(b)のように
+  行間の空きが必要以上に大きくなることを避けることができる.
+  \begin{itemize}
+       \item 段落中の隣り合った二行だけでなく,行間の空きは
+       新たに水平ボックス$h$を(内部・外部問わず)垂直モードで追加した時にも自動で挿入される.
+       その場合には,前段落で述べた「中身までみる」処理は
+       \begin{itemize}
+        \item 現在のリストにおける最後のノード
+         \footnote{最後のノードが\cs{parskip}によるグルーであった場合のみ
+               さらに一つ前のノードを参照する}が水平ボックス$h'$であり,かつ
+         \item \cs{prevdepth}の値とその$h'$の深さの値が一致している
+       \end{itemize}
+       場合にのみ発動するようにしている.
+       \item 行の中身に水平ボックス$h''$が入ってくることもあるが,その場合は$h''$の中身までは参照しない.
+       参照するようにしてしまうと,\cs{smash}など手動で行った高さ・深さ調整の意味がなくなってしまうからである.
+  \end{itemize}
+  
+  \begin{figure}[t]
+       \noindent\centering
+       \begin{minipage}[b]{16\zw}
+         \ltjenableadjust[profile]
+         ……だから,①より$\dfrac{a^2}{b}= \dfrac{1+\sqrt{5}}2$.\\
+         よって$b=\dfrac{1-\sqrt{5}}2$である.\\
+         これを②式に代入すると……
+         \par\vskip\abovecaptionskip
+         \ltjenableadjust[profile=false, linestep=false]
+         \par\centering\leavevmode{\small (a): 無効}
+       \end{minipage}%
+       \kern2\zw
+       \begin{minipage}[b]{16\zw}
+         \ltjsetparameter{linestep_factor=0.25}
+         \ltjenableadjust[profile, linestep]
+         ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
+         よって$b=\dfrac{1-\sqrt{5}}2$である.\\
+         これを②式に代入すると……
+         \par\vskip\abovecaptionskip
+         \ltjenableadjust[profile=false, linestep=false]
+         \par\centering\leavevmode{\small (b): $0.25$\cs{baselineskip}刻み}
+       \end{minipage}\par\medskip
+       \begin{minipage}[b]{16\zw}
+         \ltjsetparameter{linestep_factor=0.5}
+         \ltjenableadjust[profile, linestep]
+         ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
+         よって$b=\dfrac{1-\sqrt{5}}2$である.\\
+         これを②式に代入すると……
+         \par\vskip\abovecaptionskip
+         \ltjenableadjust[profile=false, linestep=false]
+         \par\centering\leavevmode{\small (c): 0.5\cs{baselineskip}刻み}
+       \end{minipage}%
+       \kern2\zw
+       \begin{minipage}[b]{16\zw}
+         \ltjsetparameter{linestep_factor=1}
+         \ltjenableadjust[profile, linestep]
+         ……だから,①より$\dfrac{a^2}{b} = \dfrac{1+\sqrt{5}}2$.\\
+         よって$b=\dfrac{1-\sqrt{5}}2$である.\\
+         これを②式に代入すると……
+         \par\vskip\abovecaptionskip
+         \ltjenableadjust[profile=false, linestep=false]
+         \par\centering\leavevmode{\small (d): \cs{baselineskip}刻み}
+       \end{minipage}\par
+         \caption{段階的な行送り増加}\label{fig:linegap2}
+  \end{figure}
+
+ \item[段階的な行送り増加]
+  ...
 \end{description}
 
-\Pkg{luatexja-adjust}パッケージは,上記で述べた2機能を有効化/無効化するための
+\Pkg{luatexja-adjust}パッケージは,上記で述べた4機能を有効化/無効化するための
 以下の命令を提供する.これらはすべてグローバルに効力を発揮する.
 
 \begin{cslist}
@@ -6863,9 +6959,13 @@ for making the difference obvious.
 \begin{description}
   \item[\texttt{lineend=[false,true,extended]}]
   行末文字の位置調整の機能を無効化(\texttt{false}),「行分割後に調整」の形で有効化(\texttt{true}),
-  「行分割の仮定で考慮」(\texttt{extended})する.
+  「行分割の仮定で考慮」の形で有効化(\texttt{extended})する.
   \item[\texttt{priority=[false,true]}]
-  優先順位付きの行長調整を無効化(\texttt{false}),または有効化(\texttt{true})する.
+  優先順位付きの行長調整を無効化(\texttt{false}),または有効化(\texttt{true}).
+  \item[\texttt{profile=[false,true]}]
+  「中身までみた」行送り計算を無効化(\texttt{false}),または有効化(\texttt{true}).
+  \item[\texttt{linestep=[false,true]}]
+  ...
 \end{description}
 両キーともキー名のみを指定した場合は値として\texttt{true}が指定されたものと扱われる.
 
@@ -6878,13 +6978,13 @@ for making the difference obvious.
 \item[\cs{ltjdisableadjust}]
 \Pkg{luatexja-adjust}パッケージの機能を無効化する.
 \begin{lstlisting}
-\ltjenableadjust[lineend=false,priority=false]
+\ltjenableadjust[lineend=false,priority=false,profile=false,linestep=false]
 \end{lstlisting}
 と同義.
 \end{cslist}
 
-また,優先順位付きの行長調整のために,次の2パラメータが\cs{ltjsetparameter}内で
-追加される.両パラメータともグローバルに効力を発揮する.
+また,優先順位付きの行長調整のために,次の3パラメータが\cs{ltjsetparameter}内で
+追加される.いずれもグローバルに効力を発揮する.
 \begin{cslist}[style=standard]
 \item[\DParam{stretch\_priority}\,=\{<list>\}]
 \Param{kanjiskip}, \Param{xkanjiskip},および「\textbf{JAglue}以外のグルー」を,
@@ -6903,12 +7003,16 @@ stretch_priority={kanjiskip=-35,xkanjiskip=-25,others=50}
 \item[\DParam{shrink\_priority}\,=\{<list>\}]
 同様に,「行を自然長より縮める」場合の調整に用いる優先度を指定する.
 それ以外は\Param{stretch\_priority}と指定の形式は変わらない.
+
+ \item[\DParam{linestep\_factor}\,=<float>]
+
 \end{cslist}
 初期値は\Param{stretch\_priority}, \Param{shrink\_priority}とも
 \begin{lstlisting}
 {kanjiskip=-35,xkanjiskip=-25,others=50}
 \end{lstlisting}
 であり,「優先度$-4$」と指定されているJFMグルーが最も伸び(縮み)にくいようになっている.
+また\Param{linestep\_factor}の初期値は0.5(つまり半行分)である.
 %</ja>
 
 \subsection{\Pkg{luatexja-ruby}}
index 1a80721..4376e69 100644 (file)
 \RequireLuaTeXjaSubmodule{adjust}
 
 \newcount\ltjadj@status@le
+\newcount\ltjadj@status@lp
 \newcount\ltjadj@status@pr
-\let\ltjadj@method@profile\@empty
-\let\ltjadj@method@lineskip\@empty
+\newcount\ltjadj@status@ls
 \let\ltj@adjust@temp=\relax
 \define@choicekey[ltj]{adjust}{lineend}[\@@temp\ltj@adjust@temp]%
 {false,true,extended}[true]{%
   \ifnum\ltj@adjust@temp=-1 \else\ltjadj@status@le=\ltj@adjust@temp\fi\relax}
 \define@boolkey[ltj]{adjust}{priority}[true]{%
   \ltjadj@status@pr=\ifltj@adjust@priority1\else0\fi\relax}
-\define@key[ltj]{adjust}{profile}[]{%
-  \def\ltjadj@method@profile{#1}\ltjadj@set@lineskip\relax}
-\define@key[ltj]{adjust}{lineskip}[]{%
-  \def\ltjadj@method@lineskip{#1}\ltjadj@set@lineskip\relax}
-\protected\def\ltjadj@set@lineskip{%
-  \directlua{luatexja.lineskip.setting('\ltjadj@method@profile','\ltjadj@method@lineskip')}\relax
-}
+\define@boolkey[ltj]{adjust}{profile}[true]{%
+  \ltjadj@status@lp=\ifltj@adjust@profile1\else0\fi\relax}
+\define@boolkey[ltj]{adjust}{linestep}[true]{%
+  \ltjadj@status@ls=\ifltj@adjust@linestep1\else0\fi\relax}
+
 \protected\def\@@ltjenableadjust[#1]{%
    \setkeys[ltj]{adjust}{#1}%
-   \directlua{luatexja.adjust.enable_cb(\the\ltjadj@status@le, \the\ltjadj@status@pr)}\ignorespaces
+   \directlua{luatexja.adjust.enable_cb(
+    \the\ltjadj@status@le, \the\ltjadj@status@pr,
+    \the\ltjadj@status@lp, \the\ltjadj@status@ls)}\ignorespaces
 }
-\protected\def\ltjdisableadjust{\ltjenableadjust[lineend=false,priority=false]}
+\protected\def\ltjdisableadjust{%
+  \ltjenableadjust[lineend=false,priority=false,profile=false,linestep=false]}
 \protected\def\ltjenableadjust{%
    \ltx@ifnextchar[{\@@ltjenableadjust}{\@@ltjenableadjust[lineend,priority]}}%]
 
   stretch_priority={kanjiskip=-35, xkanjiskip=-25, others=50},
    shrink_priority={kanjiskip=-35, xkanjiskip=-25, others=50},
 }
+\define@key[ltj]{japaram}{linestep_factor}{%
+  \directlua{luatexja.adjust.step_factor=#1}\relax}
 
 
 %%------------------ all done
index e349258..54af8cf 100644 (file)
@@ -402,7 +402,7 @@ do
       return to_node(head)
    end
    local is_reg = false
-   function enable_cb(status_le, status_pr)
+   function enable_cb(status_le, status_pr, status_lp, status_ls)
       if (status_le>0 or status_pr>0) and (not is_reg) then
         luatexbase.add_to_callback('post_linebreak_filter',
                                    adjust_width, 'Adjust width', 100)
@@ -427,9 +427,13 @@ do
          end
       end
       myaw_step2 = (status_pr>0) and aw_step2 or aw_step2_dummy
+      luatexja.lineskip.setting(
+         status_lp>0 and 'profile' or 'dummy',
+        status_ls>0 and 'step' or 'dummy'
+      )      
    end
    function disable_cb() -- only for compatibility
-       enable_cs(0)
+       enable_cs(0,0,0,0)
    end
    luatexja.adjust.enable_cb=enable_cb
    luatexja.adjust.disable_cb=disable_cb
@@ -440,7 +444,7 @@ luatexja.unary_pars.adjust = function(t)
 end
 
 -- -----------------------------------
-ltjl.step_factor = 0.5
+luatexja.adjust.step_factor = 0.5
 do
   local insert = table.insert
   local rangedimensions, max = node.direct.rangedimensions, math.max
@@ -499,11 +503,12 @@ do
 end
 
 do
+  local ltja = luatexja.adjust
   local copy_glue = ltjl.copy_glue
   local floor, max = math.floor, math.max
   function ltjl.l_step(dist, g, adj, normal, bw)
     if dist < tex.lineskiplimit then
-       local f = max(1, bw*ltjl.step_factor)
+       local f = max(1, bw*ltja.step_factor)
        copy_glue(g, tex.baselineskip, 1, normal - f * floor((dist-tex.lineskip.width)/f))
     else
        copy_glue(g, tex.baselineskip, 2, normal)
diff --git a/src/ltj-adjust_85.lua b/src/ltj-adjust_85.lua
deleted file mode 100644 (file)
index db85d8f..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
---
--- luatexja/otf.lua
---
-luatexja.load_module('jfont');     local ltjf = luatexja.jfont
-luatexja.load_module('jfmglue');   local ltjj = luatexja.jfmglue
-luatexja.load_module('stack');     local ltjs = luatexja.stack
-luatexja.load_module('direction'); local ltjd = luatexja.direction
-
-local to_node = node.direct.tonode
-local to_direct = node.direct.todirect
-
-local setfield = node.direct.setfield
-local setglue = luatexja.setglue
-local getfield = node.direct.getfield
-local is_zero_glue = node.direct.is_zero_glue or
-   function(g)
-      return (getfield(g,'width')==0)and (getfield(g,'stretch')==0)and(getfield(g,'shrink')==0)
-   end
-local getlist = node.direct.getlist
-local getid = node.direct.getid
-local getfont = node.direct.getfont
-local getsubtype = node.direct.getsubtype
-
-local node_traverse_id = node.direct.traverse_id
-local node_new = node.direct.new
-local node_copy = node.direct.copy
-local node_hpack = node.direct.hpack
-local node_next = node.direct.getnext
-local node_free = node.direct.free
-local node_prev = node.direct.getprev
-local node_tail = node.direct.tail
-local has_attr = node.direct.has_attribute
-local set_attr = node.direct.set_attribute
-local insert_after = node.direct.insert_after
-
-local id_glyph = node.id('glyph')
-local id_kern = node.id('kern')
-local id_hlist = node.id('hlist')
-local id_glue  = node.id('glue')
-local id_whatsit = node.id('whatsit')
-local attr_icflag = luatexbase.attributes['ltj@icflag']
-local attr_jchar_class = luatexbase.attributes['ltj@charclass']
-local lang_ja = luatexja.lang_ja
-
-local ltjf_font_metric_table = ltjf.font_metric_table
-local round, pairs = tex.round, pairs
-
-local PACKED       = luatexja.icflag_table.PACKED
-local FROM_JFM     = luatexja.icflag_table.FROM_JFM
-local KANJI_SKIP   = luatexja.icflag_table.KANJI_SKIP
-local KANJI_SKIP_JFM = luatexja.icflag_table.KANJI_SKIP_JFM
-local XKANJI_SKIP  = luatexja.icflag_table.XKANJI_SKIP
-local XKANJI_SKIP_JFM  = luatexja.icflag_table.XKANJI_SKIP_JFM
-
-local priority_table = {
-   FROM_JFM + 2,
-   FROM_JFM + 1,
-   FROM_JFM,
-   FROM_JFM - 1,
-   FROM_JFM - 2,
-   XKANJI_SKIP,
-   KANJI_SKIP
-}
-
-local get_attr_icflag
-do
-   local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG
-   get_attr_icflag = function(p)
-      return (has_attr(p, attr_icflag) or 0) % PROCESSED_BEGIN_FLAG
-   end
-end
-
--- box 内で伸縮された glue の合計値を計算
-
-local function get_stretched(q, go, gs)
-   if gs == 1 then -- stretching
-      if getfield(q, 'stretch_order') == go then
-        return getfield(q, 'stretch')
-      else return 0
-      end
-   else -- shrinking
-      if getfield(q, 'shrink_order') == go then
-        return getfield(q, 'shrink')
-      else return 0
-      end
-   end
-end
-
-local res = {}
-local gs_used_line = {}
-local function get_total_stretched(p, line)
-   local go, gf, gs
-      = getfield(p, 'glue_order'), getfield(p, 'glue_set'), getfield(p, 'glue_sign')
-   if go ~= 0 then return nil end
-   res[0], res.glue_set, res.name = 0, gf, (gs==1) and 'stretch' or 'shrink'
-   for i=1,#priority_table do res[priority_table[i]]=0 end
-   if gs ~= 1 and gs ~= 2 then return res, 0 end
-   local total = 0
-   for q in node_traverse_id(id_glue, getlist(p)) do
-      local a, ic = get_stretched(q, go, gs), get_attr_icflag(q)
-      if ic == KANJI_SKIP_JFM  then ic = KANJI_SKIP
-      elseif ic == XKANJI_SKIP_JFM  then ic = XKANJI_SKIP
-      end
-      if   type(res[ic]) == 'number' then
-        -- kanjiskip, xkanjiskip は段落内で spec を共有しているが,
-        -- それはここでは望ましくないので,各 glue ごとに異なる spec を使う.
-        -- 本当は各行ごとに glue_spec を共有させたかったが,安直にやると
-        -- ref_count が 0 なので Double-free が発生する.どうする?
-        -- JFM グルーはそれぞれ異なる glue_spec を用いているので,問題ない.
-        if (ic == KANJI_SKIP or ic == XKANJI_SKIP) and getsubtype(q)==0 then
-           local qs = getfield(q, 'spec')
-           if is_zero_glue(q) then
-              if (gs_used_line[qs] or 0)<line  then
-                 setfield(q, 'spec', node_copy(qs))
-                 local f = node_new(id_glue); setfield(f, 'spec', qs); node_free(f)
-                 -- decrese qs's reference count
-              else
-                 gs_used_line[qs] = line
-              end
-           end
-        end
-        res[ic], total = res[ic] + a, total + a
-      else
-        res[0], total = res[0]  + a, total + a
-      end
-   end
-   return res, total
-end
-
-local function clear_stretch(p, ic, name)
-   for q in node_traverse_id(id_glue, getlist(p)) do
-      local f = get_attr_icflag(q)
-      if (f == ic) or ((ic ==KANJI_SKIP) and (f == KANJI_SKIP_JFM))
-          or ((ic ==XKANJI_SKIP) and (f == XKANJI_SKIP_JFM)) then
-         local qs = getfield(q, 'spec')
-         if getfield(qs, 'writable') then
-            setfield(qs, name..'_order', 0)
-            setfield(qs, name, 0)
-         end
-      end
-   end
-end
-
-local set_stretch_table = {}
-local function set_stretch(p, after, before, ic, name)
-   if before > 0 then
-      local ratio = after/before
-      for i,_ in pairs(set_stretch_table) do
-         set_stretch_table[i] = nil
-      end
-      for q in node_traverse_id(id_glue, getlist(p)) do
-        local f = get_attr_icflag(q)
-         if (f == ic) or ((ic ==KANJI_SKIP) and (f == KANJI_SKIP_JFM))
-          or ((ic ==XKANJI_SKIP) and (f == XKANJI_SKIP_JFM)) then
-            local qs, do_flag = getfield(q, 'spec'), true
-            for i=1,#set_stretch_table do
-               if set_stretch_table[i]==qs then do_flag = false end
-            end
-            if getfield(qs, 'writable') and getfield(qs, name..'_order')==0 and do_flag then
-               setfield(q, name, getfield(qs, name)*ratio)
-               set_stretch_table[#set_stretch_table+1] = qs
-            end
-         end
-      end
-   end
-end
-
--- step 1: 行末に kern を挿入(句読点,中点用)
-local ltjd_glyph_from_packed = ltjd.glyph_from_packed
-local function aw_step1(p, res, total)
-   local head = getlist(p)
-   local x = node_tail(head); if not x then return false end
-   -- x: \rightskip
-   x = node_prev(x); if not x then return false end
-   local xi, xc = getid(x)
-   if xi == id_glue and getsubtype(x) == 15 then
-      -- 段落最終行のときは,\penalty10000 \parfillskip が入るので,
-      -- その前の node が本来の末尾文字となる
-      x = node_prev(node_prev(x)); xi = getid(x)
-   end
-   -- local xi = getid(x)
-   -- while (get_attr_icflag(x) == PACKED)
-   --    and  ((xi == id_penalty) or (xi == id_kern) or (xi == id_kern)) do
-   --       x = node_prev(x); xi = getid(x)
-   -- end
-   if xi == id_glyph and getfield(x, 'lang')==lang_ja then
-      -- 和文文字
-      xc = x
-   elseif xi == id_hlist and get_attr_icflag(x) == PACKED then
-      -- packed JAchar
-      xc = ltjd_glyph_from_packed(x)
-      while getid(xc) == id_whatsit do xc = node_next(xc) end -- これはなんのために?
-   else
-     return false-- それ以外は対象外.
-   end
-   local xk = ltjf_font_metric_table[getfont(xc)]
-     .char_type[has_attr(xc, attr_jchar_class) or 0]['end_' .. res.name] or 0
-
-   if xk>0 and total>=xk then
-      total = total - xk
-      local kn = node_new(id_kern)
-      setfield(kn, 'kern', (res.name=='shrink' and -1 or 1) * xk)
-      set_attr(kn, attr_icflag, FROM_JFM)
-      insert_after(head, x, kn)
-      return true
-   else return false
-   end
-end
-
--- step 2: 行中の glue を変える
-local function aw_step2(p, res, total, added_flag)
-   if total == 0 then -- もともと伸縮の必要なし
-      if added_flag then -- 行末に kern 追加したので,それによる補正
-        local f = node_hpack(getlist(p), getfield(p, 'width'), 'exactly')
-        setfield(f, 'head', nil)
-        setfield(p, 'glue_set', getfield(f, 'glue_set'))
-        setfield(p, 'glue_order', getfield(f, 'glue_order'))
-        setfield(p, 'glue_sign', getfield(f, 'glue_sign'))
-        node_free(f)
-        return
-      end
-   elseif total <= res[0] then -- 和文処理グルー以外で足りる
-      for _,v in pairs(priority_table) do clear_stretch(p, v, res.name) end
-      local f = node_hpack(getlist(p), getfield(p, 'width'), 'exactly')
-      setfield(f, 'head', nil)
-      setfield(p, 'glue_set', getfield(f, 'glue_set'))
-      setfield(p, 'glue_order', getfield(f, 'glue_order'))
-      setfield(p, 'glue_sign', getfield(f, 'glue_sign'))
-      node_free(f)
-   else
-      total = total - res[0]
-      for i = 1, #priority_table do
-         local v = priority_table[i]
-         if total <= res[v] then
-            for j = i+1,#priority_table do
-               clear_stretch(p, priority_table[j], res.name)
-            end
-            set_stretch(p, total, res[v], v, res.name); break
-         end
-         total = total - res[v]
-      end
-      local f = node_hpack(getlist(p), getfield(p, 'width'), 'exactly')
-      setfield(f, 'head', nil)
-      setfield(p, 'glue_set', getfield(f, 'glue_set'))
-      setfield(p, 'glue_order', getfield(f, 'glue_order'))
-      setfield(p, 'glue_sign', getfield(f, 'glue_sign'))
-      node_free(f)
-   end
-end
-
-
-local ltjs_fast_get_stack_skip = ltjs.fast_get_stack_skip
-local function adjust_width(head)
-   if not head then return head end
-   local line = 1
-   for p in node_traverse_id(id_hlist, to_direct(head)) do
-      line = line + 1
-      local res, total = get_total_stretched(p, line)
-        -- this is the same table as the table which is def'd in l. 92
-      if res and res.glue_set<1 then
-        total = round(total * res.glue_set)
-         aw_step2(p, res, total, aw_step1(p, res, total))
-      end
-   end
-   for i,_ in pairs(gs_used_line) do
-      gs_used_line[i]  = nil
-   end
-   return to_node(head)
-end
-
-do
-   luatexja.adjust = luatexja.adjust or {}
-   local is_reg = false
-   function luatexja.adjust.enable_cb()
-      if not is_reg then
-        luatexbase.add_to_callback('post_linebreak_filter',
-                                   adjust_width, 'Adjust width', 100)
-        is_reg = true
-      end
-   end
-   function luatexja.adjust.disable_cb()
-      if is_reg then
-        luatexbase.remove_from_callback('post_linebreak_filter', 'Adjust width')
-        is_reg = false
-      end
-   end
-end
-
-luatexja.unary_pars.adjust = function(t)
-   return is_reg and 1 or 0
-end
index 4ad2e86..082246d 100644 (file)
Binary files a/test/test27-lineprofile.pdf and b/test/test27-lineprofile.pdf differ
index f05c48b..91a8cd6 100644 (file)
@@ -2,12 +2,7 @@
 \usepackage[width=40\zw, lines=40,centering]{geometry}
 \usepackage{amsmath,luacode,xcolor,luatexja-adjust}
 \begin{document}
-% #1: null(TeX 既定) or profile(行の中身を考慮した行間測定)
-% #2: null(TeX 既定)
-%   or step(行送りが \baselineskip で十分でなかった場合,
-%            lineskip.step_factor * \baselineskip の倍数だけ広げて
-%            行間が \lineskip 以上になるようにする)
-\def\R#1#2{\directlua{luatexja.lineskip.setting('#1','#2')}%
+\def\R#1#2{\ltjenableadjust[profile=#1,linestep=#2]%
 \noindent\fbox{\parbox{25\zw}{%
 \baselineskip14pt\noindent
 \setbox2=\vtop{\noindent\hsize20\zw\textcolor{cyan!30!white}{%
@@ -57,9 +52,9 @@
 }}\newpage}
 
 
-\R{null}{null}
-\R{profile}{null}
-\R{null}{step}
-\R{profile}{step}
+\R{false}{false}
+\R{true}{false}
+\R{false}{true}
+\R{true}{true}
 
 \end{document}