From 230fe59e35208b77a89adf5a05e0b133bd1703a3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 5 Sep 2016 22:04:44 +0000 Subject: luatexja (5sep16) git-svn-id: svn://tug.org/texlive/trunk@41995 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/luatex/luatexja/README | 8 +- .../texmf-dist/doc/luatex/luatexja/luatexja-en.pdf | Bin 446031 -> 446443 bytes .../texmf-dist/doc/luatex/luatexja/luatexja-ja.pdf | Bin 822869 -> 839665 bytes Master/texmf-dist/doc/luatex/luatexja/luatexja.dtx | 314 ++++++++++---- .../tex/luatex/luatexja/addons/luatexja-adjust.sty | 41 +- Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua | 2 +- .../texmf-dist/tex/luatex/luatexja/ltj-adjust.lua | 472 ++++++++++++++------- .../tex/luatex/luatexja/ltj-direction.lua | 22 +- .../texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua | 40 +- .../texmf-dist/tex/luatex/luatexja/ltj-jfont.lua | 43 +- Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua | 4 +- Master/texmf-dist/tex/luatex/luatexja/luatexja.lua | 30 +- .../tex/luatex/luatexja/patches/lltjcore.sty | 2 +- 13 files changed, 719 insertions(+), 259 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/luatex/luatexja/README b/Master/texmf-dist/doc/luatex/luatexja/README index 0c8bc79e53b..619d9ce6659 100644 --- a/Master/texmf-dist/doc/luatex/luatexja/README +++ b/Master/texmf-dist/doc/luatex/luatexja/README @@ -1,4 +1,4 @@ -The LuaTeX-ja Package 20160828.0 +The LuaTeX-ja Package 20160905.0 -------------------------------- Copyright (c) 2011--2016 The LuaTeX-ja project License: modified BSD (see COPYING) @@ -34,9 +34,9 @@ Installation 2. If you must/want to install manually: a. Download the source archive from CTAN, - or tagged as 20160828.0 in the Git repository by + or tagged as 20160905.0 in the Git repository by + ;a=snapshot;h=refs/tags/20160905.0;sf=tgz> b. Extract the archive and process following three files by LuaLaTeX to generate classes for Japanese typesetting: @@ -81,4 +81,4 @@ Notes * src/*.{ins.dtx} and src/ltj-kinsoku_make.tex are not needed in regular use. -Last commit date: Sun Aug 28 15:42:51 2016 +0900 +Last commit date: Mon Sep 5 07:29:17 2016 +0900 diff --git a/Master/texmf-dist/doc/luatex/luatexja/luatexja-en.pdf b/Master/texmf-dist/doc/luatex/luatexja/luatexja-en.pdf index 399f8a7bb86..7e4af86671e 100644 Binary files a/Master/texmf-dist/doc/luatex/luatexja/luatexja-en.pdf and b/Master/texmf-dist/doc/luatex/luatexja/luatexja-en.pdf differ diff --git a/Master/texmf-dist/doc/luatex/luatexja/luatexja-ja.pdf b/Master/texmf-dist/doc/luatex/luatexja/luatexja-ja.pdf index 0d41f18a74e..8ba04870ac2 100644 Binary files a/Master/texmf-dist/doc/luatex/luatexja/luatexja-ja.pdf and b/Master/texmf-dist/doc/luatex/luatexja/luatexja-ja.pdf differ diff --git a/Master/texmf-dist/doc/luatex/luatexja/luatexja.dtx b/Master/texmf-dist/doc/luatex/luatexja/luatexja.dtx index d9a85b82b6e..9814a3548ea 100644 --- a/Master/texmf-dist/doc/luatex/luatexja/luatexja.dtx +++ b/Master/texmf-dist/doc/luatex/luatexja/luatexja.dtx @@ -165,7 +165,7 @@ \def\_{\leavevmode \kern .06em\vbox {\hrule \@width .333em}} \def\cs#1{\texttt{\upshape \texorpdfstring{\textbackslash\ltjsetparameter{autoxspacing=false}#1}{\textbackslash#1}}} - +\ltjsetparameter{alxspmode={`\\,allow}} %%%%%%%% \makeatother %%%%%%%% @@ -183,7 +183,6 @@ \protected\def\Pkg#1{\textsf{#1}} % packages/classes \ltjsetparameter{alxspmode={"200C,allow}} - \begin{document} \lstset{ vscmd=\IVSB @@ -4175,6 +4174,17 @@ floating-point numbers in design-size unit. \begin{cslist}[style=standard] +\item[version=$1\mathrel{\textrm{or}}2$] +%(optional, default value is~1) +%(任意,既定値は1) + +%<*en> +The version JFM. Currently 1~and~2 are supported +% +%<*ja> +JFMのバージョン.1または2がサポートされる. +% + \item[dir=] %(required) %(必須) @@ -4600,12 +4610,16 @@ we specify to $0.25/(0.5+0.25)=1/3$. 次のキーを指定できる, \begin{cslist}[style=standard] \item[priority=] - \Pkg{luatexja-adjust} による優先順位付き - 行長調整(\ref{ssec-adj}節)の際に使われる値であり, -行調整処理におけるこのglueの優先 - 度を$-2$から$+2$の間の整数で指定する.大きい値ほど「伸びやすく,縮みやすい」 - ことを意味する.省略時の値 - は0であり,範囲外の値が指定されたときの動作は未定義である. + \Pkg{luatexja-adjust}による優先順位付き + 行長調整(\ref{ssec-adj}節)において,このグルーの優先度を指定する.許される値は以下の通り: + \begin{description} + \item[バージョン1のとき] $-4$から$+3$の間の整数 + \item[バージョン2のとき] $-4$から$+3$の間の整数の2つ組\texttt{\{, \}}か, + または$-4$から$+3$の間の整数., はそれぞれこのグルーが伸びるときの優先度,縮むときの + 優先度であり,単に整数$i$が指定された場合は\texttt{\{$i$, $i$\}}であると解釈される. + \end{description} + ここで指定する値は,大きい値ほど「先に伸ばされる」「先に縮ませる」ことを意味しており,省略時の値 + は0である.範囲外の値が指定されたときの動作は未定義である. \item[kanjiskip\_natural=\textrm{, }% kanjiskip\_stretch=\textrm{, }kanjiskip\_shrink=]\leavevmode \label{pg:ksp_nat} @@ -4642,10 +4656,12 @@ In case of glue, one can specify following additional keys in each \texttt{[$j$] subtable: \begin{cslist}[style=standard] \item[priority=] -An integer in $[-2,2]$ (treated as 0 if omitted), and this is +An integer in $[-4,3]$ (treated as 0 if omitted), or +a pair of these integers \texttt{\{, \}} (version~2 only). +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. +and is also easy to shrink. \item[kanjiskip\_natural=\textrm{, }% kanjiskip\_stretch=\textrm{, }kanjiskip\_shrink=]\leavevmode @@ -4680,12 +4696,37 @@ Hence we have the following result: \item[end\_stretch=, end\_shrink=] %<*ja> -(任意) +(任意,バージョン1のみ) 優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が行 末に来た時に,行長を詰める調整・伸ばす調整のた めにこの文字と行末の間に挿入可能なカーンの大きさを指定する. % +%<*en> +(optional, version~1 only) +% + + \item[end\_adjust=\{, , ...\}] +%<*ja> +(任意,バージョン2のみ) + +優先順位付き行長調整が有効であり,かつ現在の文字クラスの文字が + 行末に来た時に,この文字と行末の間には指定された値のいずれかの大きさのカーンが + 挿入される(\autoref{ssec-adj}参照). + +バージョン1における +\begin{lstlisting}[escapechar=\$] + end_stretch = $a$, end_shrink = $b$ +\end{lstlisting} +という指定は,バージョン2では次の指定と同じになる. +\begin{lstlisting}[escapechar=\$] + end_adjust = {$-b$, 0.0, $a$} +\end{lstlisting} +もし真ん中の \texttt{0.0} がない場合は,$a$か$-b$かいずれかのカーンが常に行末に追加される. +% +%<*en> +(optional, version~2 only) +% \end{cslist} @@ -6878,38 +6919,106 @@ for making the difference obvious. (see Japanese version of this manual) % %<*ja> +この追加パッケージは以下の機能を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい. +\begin{description} +\item[行末文字の位置調整] + \pTeX では,(是非はともかく)「行末の読点はぶら下げか二分取りか全角取りのいずれかに」のように + 行末文字と実際の行末の位置関係を2通り以上にすることは面倒であった. + 和文フォントメトリックだけでは「常に行末の読点はぶら下げ」といったことしかできず, + 前の文に書いたことを実現するには +\begin{lstlisting} +\def\。{% + \penalty10000 % 禁則ペナルティ + \hbox to0pt{。\hss}\penalty0 % ぶら下げの場合 + \kern.5\zw\penalty0 % 二分取りの場合 + \kern.5\zw\penalty0 % 全角取りの場合 +} +\end{lstlisting} + のような命令を定義し,文中の全ての句点を \lstinline+\。+ で書くことが必要だった. + +\Pkg{luatexja-adjust}パッケージは,上で述べた行末文字と実際の行末との位置関係を +2通り以上から自動的に選択する機能を提供する. +\pdfTeX と同じように,「\TeX による行分割の後で行末文字の位置を補正する」方法と + 「行分割の過程で行末文字の位置を考慮に入れる」方法を選べるようにした( +\Pkg{luatexja-adjust}パッケージの既定では前者). + +\item[優先順位付きの行長調整] \pTeX では,行長調整において優先度の概念が存在しなかったため,図 \ref{fig-adj}上段における半角分の半端は,図\ref{fig-adj}中段のように,鍵 括弧周辺の空白と和文間空白(\Param{kanjiskip})の両方によって負担される.し かし,「日本語組版処理の要件」\cite{jlreq}やJIS~X~4051~\cite{x4051}におい ては,このような状況では半端は鍵括弧周辺の空白のみで負担し,その他の和文 -文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている.この追加 -パッケージは\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き -の行長調整を提供する.詳細な仕様については\ref{sec-adjspec}章を参照してほしい. +文字はベタ組で組まれる(図\ref{fig-adj}下段)ことになっている. +\Pkg{luatexja-adjust}パッケージの提供する第2の機能は, +\cite{jlreq}や\cite{x4051}における規定のような,優先順位付き +の行長調整である. \begin{itemize} \item 優先度付き行長調整は,段落を行分割した後に個々の行について行われるものである. そのため,行分割の位置は変化することはない. -また,\verb+\hbox to ... {...}+ のような「幅が指定されたhbox」では無効である. +\verb+\hbox{...}+ といった「途中で改行できない水平ボックス」では(たとえ幅が指定されていても)無効である. \item 優先度付き行長調整を行うと,和文処理グルーの自然長は変化しないが,伸び量や縮み量は 一般に変化する.そのため,既に組まれた段落を \cs{unhbox} などを利用して組み直す処理を 行う場合には注意が必要である. \end{itemize} +\end{description} - -\Pkg{luatexja-adjust} は,以下の命令を提供する.これらはすべてグローバルに効力を発揮する. +\Pkg{luatexja-adjust}パッケージは,上記で述べた2機能を有効化/無効化するための +以下の命令を提供する.これらはすべてグローバルに効力を発揮する. \begin{cslist} +\item[\cs{ltjenableadjust[...]}] +\verb+...+ に指定したkey-valueリストに従い,「行末文字の位置調整」「優先順位付きの行長調整」を有効化/無効化する. +指定できるキーは以下の通り. +\begin{description} + \item[\texttt{lineend=[false,true,extended]}] + 行末文字の位置調整の機能を無効化(\texttt{false}),「行分割後に調整」の形で有効化(\texttt{true}), + 「行分割の仮定で考慮」(\texttt{extended})する. + \item[\texttt{priority=[false,true]}] + 優先順位付きの行長調整を無効化(\texttt{false}),または有効化(\texttt{true})する. +\end{description} +両キーともキー名のみを指定した場合は値として\texttt{true}が指定されたものと扱われる. + +互換性の為,オプション無しでただ\cs{ltjenableadjust}が呼び出された場合は, +\begin{lstlisting} +\ltjenableadjust[lineend=true,priority=true] +\end{lstlisting} +と扱われる. + \item[\cs{ltjdisableadjust}] -優先順位付きの行長調整を無効化する. +\Pkg{luatexja-adjust}パッケージの機能を無効化する. +\begin{lstlisting} +\ltjenableadjust[lineend=false,priority=false] +\end{lstlisting} +と同義. +\end{cslist} -\item[\cs{ltjenableadjust}] -優先順位付きの行長調整を有効化する. +また,優先順位付きの行長調整のために,次の2パラメータが\cs{ltjsetparameter}内で +追加される.両パラメータともグローバルに効力を発揮する. +\begin{cslist}[style=standard] +\item[\DParam{stretch\_priority}\,=\{\}] +\Param{kanjiskip}, \Param{xkanjiskip},および「\textbf{JAglue}以外のグルー」を, +「行を自然長より伸ばす」場合の調整に用いる優先度を指定する. -\item[\textsf{adjust}\,=] \cs{ltjsetparameter} で指定可能な追加パラメータであり, -が\textit{true}なら \cs{ltjenableadjust} を, -そうでなければ \cs{ltjdisableadjust} を実行する. +指定方法は,の中にkey-value listの形で +\begin{lstlisting} +stretch_priority={kanjiskip=-35,xkanjiskip=-25,others=50} +\end{lstlisting} +のようにして行う.キー名\texttt{kanjiskip},~\texttt{xkanjiskip}については +そのままの意味であり, +\texttt{others}キーが「\textbf{JAglue}以外のグルー」を表す. +各キーの値は,JFMグルーにおける「優先度$i$」を$10i$に対応させた整数値であり, + 大きい方が先に伸ばされることを意味している. + +\item[\DParam{shrink\_priority}\,=\{\}] +同様に,「行を自然長より縮める」場合の調整に用いる優先度を指定する. +それ以外は\Param{stretch\_priority}と指定の形式は変わらない. \end{cslist} +初期値は\Param{stretch\_priority}, \Param{shrink\_priority}とも +\begin{lstlisting} +{kanjiskip=-35,xkanjiskip=-25,others=50} +\end{lstlisting} +であり,「優先度$-4$」と指定されているJFMグルーが最も伸び(縮み)にくいようになっている. % \subsection{\Pkg{luatexja-ruby}} @@ -9230,93 +9339,148 @@ the \texttt{lstlisting} environment or other environments/commands. %<*ja> \section{和文の行長補正方法} \label{sec-adjspec} -\Pkg{luatexja-adjust} で提供される優先順位付きの行長調整の詳細を述 -べる.大まかに述べると,次のようになる. +\Pkg{luatexja-adjust}で提供される優先順位付きの行長調整の詳細を大まかに述べると,次のようになる. \begin{itemize} +\item (\texttt{lineend=extended}の場合)\textbf{JAglue}の挿入処理のところで, + …… \item 通常の\TeX の行分割方法に従って,段落を行分割する.この段階では,行 長に半端が出た場合,その半端分は\textbf{JAglue}(\Param{xkanjiskip}, \Param{kanjiskip},JFMグルー)と それ以外のグルーの全てで(優先順位なく)負担される. \item その後,\texttt{post\_linebreak\_filter} callbackを使い,\emph{段 - 落中の各行ごとに},行末文字の位置を調整したり,優先度付きの行長調整 + 落中の各行ごとに},行末文字の位置を調整(\texttt{lineend=true}の場合)したり,優先度付きの行長調整 を実現するためにグルーの伸縮度を調整する. その処理においては,グルーの自然長と\textbf{JAglue}以外の グルーの伸び量・縮み量は変更せず,必要に応じて\textbf{JAglue}の伸び量・縮み量のみを 変更する設計とした. - -\Pkg{luatexja-adjust} の作用は,この処理を行うcallbackを追加するだけであり, - この章の残りではcallbackでの処理について解説する. \end{itemize} +この章の残りでは各処理について解説する. \paragraph{準備:合計伸縮量の計算} グルーの伸縮度(\texttt{plus} や \texttt{minus} で指定されている値)には, 有限値の他に,\texttt{fi},\texttt{fil},\texttt{fill},\texttt{filll}と -いう4つの無限大レベル(後ろの方ほど大きい)があり,行の調整に -\texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている場合は,そ -の行に対しての処理を中止}する. - -よって,以降,問題にしている行の行長調整は伸縮度が有限長のグルーを用いて -行われているとして良い.さらに,簡単のため,この行はグルーが広げられている -(自然長で組むと望ましい行長よりの短い)場合しか扱わない. +いう4つの無限大レベル(後ろの方ほど大きい)がある.行の調整に +\texttt{fi} などの\emph{無限大レベルの伸縮度が用いられている行では, +「行末文字の位置調整」のみ行い,「グルーの調整」は行わない.} まず,段落中の行中のグルーを \begin{itemize} \item \textbf{JAglue}ではないグルー \item JFMグルー(優先度\footnote{% \ref{ssec-jfm-str}節にあるように, - 各JFMグルーには$-2$から2までの優先度がついている.}% + 各JFMグルーには$-4$から3までの優先度がついている.場合によっては + 伸びと縮みで異なる優先度が付いているかもしれない.}% 別にまとめられる) \item 和欧文間空白(\Param{xkanjiskip}) \item 和文間空白(\Param{kanjiskip}) \end{itemize} -の$1+1+5+1=8$つに類別し,それぞれの種別ごとに -許容されている伸び量(\texttt{stretch}の値)の合計を計算する. -また,行長と自然長との差を\textit{total}とおく. - +の$1+1+8+1=10$つに類別する. +そして許容されている伸び量(\texttt{stretch}の値)の合計を +無限のレベルごとに +\begin{align*} + T^{+}_{l}&:= \sum_{\text{$\texttt{stretch\_order}(p) = l$}} \texttt{stretch}(p),& + l\in \{\text{(finite)}, \texttt{fi}, \texttt{fil}, \texttt{fill}, \texttt{filll}\} +\end{align*} +と計算する.さらに, +\begin{align*} +T^{+}&:=T^{+}_{L^+},&L^{+} = \max \{l\in + \{\text{(finite)}, \texttt{fi}, \texttt{fil}, \texttt{fill}, \texttt{filll}\}: + T^{+}_l\neq 0\} +\end{align*} +とおく.有限の伸び量については,上記の8種類の類別ごとにも合計を計算する. +さらに縮み量(\texttt{shrink}の値)についても同様の処理を行い,$T^{-}$を計算する. + +また,行長から自然長を引いた値を\textit{total}とおく. + +\subsection{行末文字の位置調整(行分割後の場合)} +行末が\textbf{JAchar}であり,この文字の属する文字クラスでは +\begin{quote} + \texttt{end\_adjust = \{$a_{1}$, $a_{2}$, ..., $a_{n}$\}} +\end{quote} +であったとする. +このとき,以下の条件を満たした場合, +この文字クラスに対する\texttt{end\_adjust}の値のいずれかだけこの文字の位置を移動させる. +\begin{description} + \item[最終行以外] 行長調整に無限大の伸縮度が用いられていない. + すなわち,$\textit{total}>0$ならば$L^{+}=(\text{finite})$であり, + $\textit{total}>0$ならば$L^{-}=(\text{finite})$である. + \item[最終行] 行長調整に無限大に伸び縮みするグルーが用いられたなら,それは\cs{parfillskip}のみであり, + かつ,次の不等式が成立する: + \[ + \min\{0,a_{1}\}\text{\cs{zw}}\leq (\text{\cs{parfillskip}の実際の長さ}) \leq \max\{0,a_{n}\}\text{\cs{zw}} + \] +\end{description} -\subsection{行末文字の位置調整} -行末が文字クラス$n$の\textbf{JAchar}であった場合, -それを動かすことによって,\textit{total}のうち -\textbf{JAglue}が負担する分を少なくしようとする. -この行末文字の左右の移動可能量は, -JFM中にある文字クラス$n$の定義の -\texttt{end\_stretch},~\texttt{end\_shrink}フィールドに -全角単位の値として記述されている. +各$1\leq i\leq n$に対して, +「行末に$a_{i}$全角だけのカーンを追加した時の,\textit{glue\_set}の値」を +$b_{i}$とおく.式で書くと, +\[ +\catcode`\<=12 +b_{i} = \begin{cases} + |\textit{total}-a_{i}\text{\cs{zw}}|/T^{+} + &(\textit{total}-a_{i}\text{\cs{zw}}\geq 0)\\ + |\textit{total}-a_{i}\text{\cs{zw}}|/T^{-} + &(\textit{total}-a_{i}\text{\cs{zw}}<0) +\end{cases}. +\] +$b_{i}$達の最小値を与えるような$i$を$j$としたとき\footnote{% + そのような$i$が2つ以上あるときは,$|\textit{total}-a_{i}\cdot \text{\cs{zw}}|$, + $|a_{i}|$, $a_i$の順で比較して一番小さくなるものが選ばれる. +}, +行末に大きさ$a_{j}$のカーンを追加する. +\textit{total}から$a_{j}$全角の大きさだけ引いておく. -例えば,行末文字が句点「。」であり,そこで用いられているJFM中に -\begin{lstlisting} - [2] = { - chars = { '。', ... }, width = 0.5, ..., - end_stretch = 0.5, end_shrink = 0.5, - }, -\end{lstlisting} -という指定があった場合,この行末の句点は -\begin{itemize} -\item 通常の\TeX の行分割処理で「半角以上の詰め」が行われていた場合, -この行中の\textbf{JAglue}の負担を軽減するため, -行末の句点を半角だけ右に移動する(ぶら下げ組を行う). -\item 通常の\TeX の行分割処理で「半角以上の空き」が行われていた場合, -逆に行末句点を半角左に移動させる(見た目的に全角取りとなる). -\item 以上のどちらでもない場合,行末句点の位置調整は行わない. -\end{itemize} -となる. +\subsection{行末文字の位置調整(行分割での考慮)} +\texttt{lineend=extended}が指定されている場合,\TeX による行分割が行われる前に +各\textbf{JAchar}の直後に,その文字が行末に来たときの位置補正用のノードを挿入していく. -行末文字を移動した場合,その分だけ\textit{total}の値を引いておく. +\ref{sec-jfmglue}章の用語を使って述べる. +前側のクラスタ\textit{Nq}が「和文A」「和文B」であり, +JFMによって\texttt{end\_adjust}の値が +\begin{quote} + \texttt{end\_adjust = \{$a_{1}$, $a_{2}$, ..., $a_{n}$\}} +\end{quote} +であったとする.このとき,次のクラスタ\textit{Np}の直前に以下のノード列を挿入する. +\textbf{JAglue}の挿入過程で禁則処理のために「\textit{Nq}と\textit{Np}の間のペナルティ値を増やす」ことが +行われることがあるが,以下で述べられている$(n+1)$個のペナルティはみなその処理対象になっている. +\begin{align*} + \Node{kern}{$a_{1}\text{\cs{zw}}$} + &\longrightarrow \Node{penalty}{$0$} \longrightarrow\Node{kern}{$(a_{2}-a_{1})\text{\cs{zw}}$} + \longrightarrow \Node{penalty}{$0$} \longrightarrow\Node{kern}{$(a_{3}-a_{2})\text{\cs{zw}}$}\\ + &\longrightarrow + \cdots \longrightarrow\Node{penalty}{$0$} \longrightarrow + \Node{kern}{$(a_{n}-a_{n-1})\text{\cs{zw}}$} + \longrightarrow \Node{penalty}{$0$} \longrightarrow + \Node{kern}{$-a_{n}\text{\cs{zw}}$} \longrightarrow \Node{penalty}{$10000$} +\end{align*} +$n$個あるペナルティの箇所が改行可能箇所である.いずれかで改行された場合は, +その前にあるカーン($n$箇所のうちどこで改行しても,合計の長さは$a_{i}$の形)は行末に残るが, +後ろのペナルティ・カーンは除去される.なお,$a_1=0$のときは最初の幅が$a_{1}\text{\cs{zw}}$のカーンは不要なので挿入されず, +さらにかつ$n=1$であった場合は後ろのペナルティも挿入されない. + +なお,段落の末尾には\cs{penalty10000}と\cs{parfillskip}由来のグルーが自動的に入るが, +これらとの兼ね合いのため\emph{最後のクラスタについては上記のノード挿入処理は行われない}. +段落最終行の行末文字の位置調整は,すでに述べた「行分割後の場合」における最終行の処理をそのまま用いている. \subsection{グルーの調整} -\textit{total}の分だけが,行中のグルーの伸び量に応じて負担されることになる. -負担するグルーの優先度は以下の順であり, -できるだけ\Param{kanjiskip}を自然長のままにすることを -試みている. +$|\textit{total}|$の分だけが,行中のグルーの伸び量,あるいは縮み量に応じて負担されることになる. +以下,$\textit{total}\geq 0$であると仮定して話を進めるが,負のときも同様である. +\Pkg{luatexja-adjust}の初期値では以下の順に伸び量を負担するようになっており, +(優先度$-4$のJFMグルーは例外として)できるだけ\Param{kanjiskip}を自然長のままにすることを +試みている.この順番は\Param{stretch\_priority}(縮み量については\Param{shrink\_priority}) +パラメータで変更可能である. \begin{enumerate}\def\labelenumi{(\Alph{enumi})} \item \textbf{JAglue}以外のグルー + \item 優先度3のJFMグルー \item 優先度2のJFMグルー \item 優先度1のJFMグルー \item 優先度0のJFMグルー \item 優先度$-1$のJFMグルー \item 優先度$-2$のJFMグルー \item \Param{xkanjiskip} + \item 優先度$-3$のJFMグルー \item \Param{kanjiskip} + \item 優先度$-4$のJFMグルー \end{enumerate} \begin{enumerate} \item 行末の\textbf{JAchar}を移動したことで$\textit{total}=0$となれば, @@ -9333,7 +9497,7 @@ JFM中にある文字クラス$n$の定義の \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する. これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される. \end{enumerate} -\item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(H)のどこまで負担すれば +\item \textit{total}が「(A)の伸び量の合計」以上ならば,(A)--(K)のどこまで負担すれば \textit{total}以上になるかを計算する. 例えば, \[\catcode`\<=12 @@ -9344,17 +9508,17 @@ JFM中にある文字クラス$n$の定義の \begin{itemize} \item (A),~(B)に属するグルーは各グルーで許された伸び量まで伸ばす. \item (C)に属するグルーはそれぞれ$p\times (\text{伸び量})$だけ伸びる. - \item (D)--(H)に属するグルーは自然長のまま. + \item (D)--(K)に属するグルーは自然長のまま. \end{itemize} 実際には,前に述べた「設計」に従い,次のように処理している: \begin{enumerate} \item (C)に属するグルーの伸び量を$p$倍する. -\item (D)--(H)に属するグルーの伸び量を0とする. +\item (D)--(K)に属するグルーの伸び量を0とする. \item 行が格納されているhboxの \texttt{glue\_set}, \texttt{glue\_sign}, \texttt{glue\_order}を再計算する. これによって,\textit{total}は\textbf{JAglue}以外のグルーによって負担される. \end{enumerate} -\item \textit{total}が(A)--(H)の伸び量の合計よりも大きい場合,どうしようもないので +\item \textit{total}が(A)--(K)の伸び量の合計よりも大きい場合,どうしようもないので \verb+^^;+何もしない. \end{enumerate} diff --git a/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty b/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty index c14c52e93ca..be15fbba183 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty +++ b/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-adjust.sty @@ -68,6 +68,7 @@ \fi % % Load core module if not yet. +% xkeyval.sty is already required in luatexja.sty. \ifx\luatexjacoreLoaded\@undefined \ifltj@in@latex %<*LaTeX> \RequirePackage{luatexja}[2016/05/15] @@ -90,13 +91,41 @@ \RequireLuaTeXjaSubmodule{adjust_85} \fi -% enable/disable ``advanced'' line adjustment -\protected\def\ltjdisableadjust{\directlua{luatexja.adjust.disable_cb()}} -\protected\def\ltjenableadjust{\directlua{luatexja.adjust.enable_cb()}} + +\newcount\ltjadj@status@le +\newcount\ltjadj@status@pr +\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} +\protected\def\@@ltjenableadjust[#1]{% + \setkeys[ltj]{adjust}{#1}% + \directlua{luatexja.adjust.enable_cb(\the\ltjadj@status@le, \the\ltjadj@status@pr)}\ignorespaces +} +\protected\def\ltjdisableadjust{\ltjenableadjust[lineend=false,priority=false]} +\protected\def\ltjenableadjust{% + \ltx@ifnextchar[{\@@ltjenableadjust}{\@@ltjenableadjust[lineend,priority]}}%] + \ltjenableadjust -% there is also a key for \ltjsetparameter, for same effect -\define@boolkey[ltj]{japaram}{adjust}[true]{% - \ifltj@japaram@adjust\ltjenableadjust\else\ltjdisableadjust\fi + +%%% 優先順位の設定 +\define@key[ltj]{adjpri}{kanjiskip}{% + \directlua{luatexja.adjust.priority_table[\the\count@][1] = token.scan_int()}#1\relax} +\define@key[ltj]{adjpri}{xkanjiskip}{% + \directlua{luatexja.adjust.priority_table[\the\count@][2] = token.scan_int()}#1\relax} +\define@key[ltj]{adjpri}{others}{% + \directlua{luatexja.adjust.priority_table[\the\count@][3] = token.scan_int()}#1\relax} +\define@key[ltj]{japaram}{stretch_priority}{% + \begingroup\count@=1 \setkeys[ltj]{adjpri}{#1}\relax + \directlua{luatexja.adjust.make_priority_table(1)}\endgroup} +\define@key[ltj]{japaram}{shrink_priority}{% + \begingroup\count@=2 \setkeys[ltj]{adjpri}{#1}\relax + \directlua{luatexja.adjust.make_priority_table(2)}\endgroup} +\ltjsetparameter{% + stretch_priority={kanjiskip=-35, xkanjiskip=-25, others=50}, + shrink_priority={kanjiskip=-35, xkanjiskip=-25, others=50}, } diff --git a/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua b/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua index a0d1675e127..72c1e9c6f8d 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua @@ -92,7 +92,7 @@ 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 = { --- 3 は.75, 2, 4 は0, あとは0.5 + -- 3 は.75, 2, 4 は0, あとは0.5 [0] = { 0.5 , 0.0, 0.5, ratio=0, kanjiskip_stretch=1 }, [1] = { 0.5 , 0.0, 0.5, ratio=0, kanjiskip_stretch=1 }, [3] = { 0.75, 0.0, 0.25, priority=1, ratio=1./3, kanjiskip_stretch=1 }, diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua index 821099da607..7131bbc7b77 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-adjust.lua @@ -5,6 +5,7 @@ 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 +luatexja.adjust = luatexja.adjust or {} local to_node = node.direct.tonode local to_direct = node.direct.todirect @@ -12,7 +13,6 @@ 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 local getlist = node.direct.getlist local getid = node.direct.getid local getfont = node.direct.getfont @@ -20,8 +20,6 @@ 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 @@ -35,30 +33,22 @@ 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 id_penalty = node.id('penalty') 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 ipairs, pairs = ipairs, pairs local PACKED = luatexja.icflag_table.PACKED +local LINEEND = luatexja.icflag_table.LINEEND 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 @@ -67,89 +57,99 @@ do 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 +local priority_num = { 0, 0 } +local at2pr = { {}, {} } +local at2pr_st, at2pr_sh = at2pr[1], at2pr[2] +do + local priority_table = {{},{}} + luatexja.adjust.priority_table = priority_table + local tmp = {} + local function cmp(a,b) return a[1]>b[1] end -- 大きいほうが先! + local function make_priority_table(glue_sign) + for i,_ in pairs(tmp) do tmp[i]=nil end + if glue_sign==2 then -- shrink + for i=0,63 do tmp[#tmp+1] = { (i%8)-4, FROM_JFM+i } end + else -- stretch + for i=0,63 do tmp[#tmp+1] = { math.floor(i/8)-4, FROM_JFM+i } end + end + local pt = priority_table[glue_sign] + tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP } + tmp[#tmp+1] = { pt[2]/10, XKANJI_SKIP_JFM } + tmp[#tmp+1] = { pt[1]/10, KANJI_SKIP } + tmp[#tmp+1] = { pt[1]/10, KANJI_SKIP_JFM } + tmp[#tmp+1] = { pt[3]/10, -1 } + table.sort(tmp, cmp) + local a, m, n = at2pr[glue_sign], 10000000, 0 + for i=1,#tmp do + if tmp[i][1] + local ph = getlist(p) + if not ph then return 0 end + for i,_ in pairs(total_st) do total_st[i]=nil; total_sh[i]=nil end + for i=1,priority_num[1] do total_st[i]=0 end + for i=1,priority_num[2] do total_sh[i]=0 end + for i=0,4 do total_st[i*65536]=0; total_sh[i*65536]=0 end + for q in node_traverse_id(id_glue, ph) do + local a = getfield(q, 'stretch_order') + if a==0 then + local b = at2pr_st[get_attr_icflag(q)]; + total_st[b] = total_st[b]+getfield(q, 'stretch') end - if type(res[ic]) == 'number' then - res[ic], total = res[ic] + a, total + a - else - res[0], total = res[0] + a, total + a + total_st[a*65536] = total_st[a]+getfield(q, 'stretch') + local a = getfield(q, 'shrink_order') + if a==0 then + local b = at2pr_sh[get_attr_icflag(q)]; + total_sh[b] = total_sh[b]+getfield(q, 'shrink') end + total_sh[a*65536] = total_sh[a]+getfield(q, 'shrink') 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 - setfield(q, name..'_order', 0) - setfield(q, name, 0) - end + for i=4,1,-1 do if total_st[i*65536]~=0 then total_st.order=i; break end; end + if not total_st.order then + total_st.order, total_st[-65536] = -1,0.1 -- dummy end -end - -local function set_stretch(p, after, before, ic, name) - if before > 0 then - local ratio = after/before - 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 - if getfield(q, name..'_order')==0 then - setfield(q, name, getfield(q, name)*ratio) - end - end - end + for i=4,1,-1 do if total_sh[i*65536]~=0 then total_sh.order=i; break end; end + if not total_sh.order then + total_sh.order, total_sh[-65536] = -1,0.1 -- dummy end + return getfield(p,'width') - dimensions(ph) +end end -- step 1: 行末に kern を挿入(句読点,中点用) +local abs = math.abs local ltjd_glyph_from_packed = ltjd.glyph_from_packed -local function aw_step1(p, res, total) +local function aw_step1(p, total) local head = getlist(p) - local x = node_tail(head); if not x then return false end + local x = node_tail(head); if not x then return total, false end -- x: \rightskip - x = node_prev(x); if not x then return false end + x = node_prev(x); if not x then return total, 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 + -- x may be penalty + while xi==id_penalty do + x = node_prev(x); if not x then return total, false end + xi = getid(x) + end + if (total>0 and total_st.order>0) or (total<0 and total_sh.order>0) then + -- 無限大のグルーで処理が行われているときは処理中止. + return total, false + end if xi == id_glyph and getfield(x, 'lang')==lang_ja then -- 和文文字 xc = x @@ -158,96 +158,280 @@ local function aw_step1(p, res, total) xc = ltjd_glyph_from_packed(x) while getid(xc) == id_whatsit do xc = node_next(xc) end -- これはなんのために? else - return false-- それ以外は対象外. + return total, false-- それ以外は対象外. + end + local eadt = ltjf_font_metric_table[getfont(xc)] + .char_type[has_attr(xc, attr_jchar_class) or 0].end_adjust + if not eadt then + return total, false + end + local eadt_ratio = {} + for i, v in ipairs(eadt) do + local t = total - v + if t>0 then + eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v} + else + eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v} + end + end + table.sort(eadt_ratio, + function (a,b) + for i=2,4 do + local at, bt = abs(a[i]), abs(b[i]) + if at~=bt then return at0 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) +-- step 1 最終行用 +local min, max = math.min, math.max +local function aw_step1_last(p, total) + local head = getlist(p) + local x = node_tail(head); if not x then return total, false end + -- x: \rightskip + pf = node_prev(x); if not x then return total, false end + if getid(pf) ~= id_glue or getsubtype(pf) ~= 15 then return total, false end + x = node_prev(node_prev(pf)); xi = getid(x) + local xi, xc = getid(x) + 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 total, false-- それ以外は対象外. + end + -- 続行条件1:無限の伸縮度を持つグルーは \parfillskipのみ + if total>0 and total_st.order>0 then + if total_st.order ~= getfield(pf, 'stretch_order') then return total, false end + if total_st[total_st.order*65536] ~= getfield(pf, 'stretch') then return total, false end + for i=total_st.order-1, 1, -1 do + if total_st[i*65536] ~= 0 then return total, false end + end + end + if total<0 and total_sh.order>0 then + if total_sh.order ~= getfield(pf, 'shrink_order') then return total, false end + if total_sh[total_sh.order*65536] ~= getfield(pf, 'shrink') then return total, false end + for i=total_sh.order-1, 1, -1 do + if total_sh[i*65536] ~= 0 then return total, false end + end + end + local eadt = ltjf_font_metric_table[getfont(xc)] + .char_type[has_attr(xc, attr_jchar_class) or 0].end_adjust + if not eadt then + return total, false + end + -- 続行条件2: min(eadt[1], 0)<= \parfillskip <= max(eadt[#eadt], 0) + local pfw = getfield(pf, 'width') + + (total>0 and getfield(pf, 'stretch') or -getfield(pf, 'shrink')) *getfield(p, 'glue_set') + if pfw0 then + eadt_ratio[i] = {i, t/total_st[65536*total_st.order], t, v} + else + eadt_ratio[i] = {i, t/total_sh[65536*total_sh.order], t, v} + end + end + table.sort(eadt_ratio, + function (a,b) + for i=2,4 do + local at, bt = abs(a[i]), abs(b[i]) + if at~=bt then return at 0 then + local ratio = after/before + for q in node_traverse_id(id_glue, getlist(p)) do + local f = ap[get_attr_icflag(q)] + if (f==ind) and getfield(q, name..'_order')==0 then + setfield(q, name, getfield(q, name)*ratio) 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 +function aw_step2(p, total, added_flag) + local name = (total>0) and 'stretch' or 'shrink' + local id = (total>0) and 1 or 2 + local res = total_stsh[id] + local pnum = priority_num[id] + if total==0 or res.order > 0 then + -- もともと伸縮の必要なしか,残りの伸縮量は無限大 + if added_flag then return repack(p) end + end + total = abs(total) + for i = 1, pnum do + if total <= res[i] then + local a = at2pr[id] + for j = i+1,pnum do + clear_stretch(p, j, a, name) + end + set_stretch(p, total, res[i], i, a, name); break + end + total = total - res[i] + end + return repack(p) +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)) +-- step 1': lineend=extended の場合(行分割時に考慮)) +local insert_lineend_kern +do + local insert_before = node.direct.insert_before + local KINSOKU = luatexja.icflag_table.KINSOKU + function insert_lineend_kern(head, nq, np, Bp) + if nq.met then + local eadt = nq.met.char_type[nq.class].end_adjust + if not eadt then return end + if eadt[1]~=0 then + local x = node_new(id_kern, 1) + setfield(x, 'kern', eadt[1]); set_attr(x, attr_icflag, LINEEND) + insert_before(head, np.first, x) + end + local eadt_num = #eadt + for i=2,eadt_num do + local x = node_new(id_penalty) + setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU) + insert_before(head, np.first, x); Bp[#Bp+1] = x + local x = node_new(id_kern, 1) + setfield(x, 'kern', eadt[i]-eadt[i-1]); set_attr(x, attr_icflag, LINEEND) + insert_before(head, np.first, x) + end + if eadt_num>1 or eadt[1]~=0 then + local x = node_new(id_penalty) + setfield(x, 'penalty', 0); set_attr(x, attr_icflag, KINSOKU) + insert_before(head, np.first, x); Bp[#Bp+1] = x + local x = node_new(id_kern, 1) + setfield(x, 'kern', -eadt[eadt_num]); set_attr(x, attr_icflag, LINEEND) + insert_before(head, np.first, x) + local x = node_new(id_penalty) + setfield(x, 'penalty', 10000); set_attr(x, attr_icflag, KINSOKU) + insert_before(head, np.first, x); Bp[#Bp+1] = x + end end end - return to_node(head) end +local adjust_width do - luatexja.adjust = luatexja.adjust or {} + local myaw_atep1, myaw_step2, myaw_step1_last + local dummy = function(p,t,n) return t, false end + local ltjs_fast_get_stack_skip = ltjs.fast_get_stack_skip + function adjust_width(head) + if not head then return head end + local last_p + for p in node_traverse_id(id_hlist, to_direct(head)) do + if last_p then + myaw_step2(last_p, myaw_step1(last_p, get_total_stretched(last_p))) + end + last_p = p + end + if last_p then + myaw_step2(last_p, myaw_step1_last(last_p, get_total_stretched(last_p))) + end + return to_node(head) + end local is_reg = false - function luatexja.adjust.enable_cb() - if not is_reg then + function enable_cb(status_le, status_pr) + 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) is_reg = true - end - end - function luatexja.adjust.disable_cb() - if is_reg then + elseif is_reg and (status_le==0 and status_pr==0) then luatexbase.remove_from_callback('post_linebreak_filter', 'Adjust width') is_reg = false end + if status_le==2 then + if not luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then + luatexbase.add_to_callback('luatexja.adjust_jfmglue', insert_lineend_kern, 'luatexja.adjust') + end + myaw_step1, myaw_step1_last = dummy, aw_step1_last + else + if status_le==0 then + myaw_step1, myaw_step1_last = dummy, dummy + else + myaw_step1, myaw_step1_last = aw_step1, aw_step1_last + end + if luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then + luatexbase.remove_from_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') + end + end + myaw_step2 = (status_pr>0) and aw_step2 or aw_step2_dummy + end + function disable_cb() -- only for compatibility + enable_cs(0) end + luatexja.adjust.enable_cb=enable_cb + luatexja.adjust.disable_cb=disable_cb end luatexja.unary_pars.adjust = function(t) diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua index 8a2af68374c..61d081929de 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-direction.lua @@ -266,15 +266,22 @@ end -- hpack_filter, vpack_filter, post_line_break_filter -- の結果を組方向を明示するため,先頭に dir_node を設置 +local get_box_dir do local function create_dir_whatsit_hpack(h, gc) local hd = to_direct(h) - if gc=='fin_row' or gc == 'preamble' then + if gc=='fin_row' then if hd then + for p in traverse_id(15, hd) do -- unset + if get_box_dir(p, 0)==0 then + setfield(p, 'head', create_dir_whatsit(getlist(p), 'fin_row', ltjs.list_dir)) + end + end set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG) ensure_tex_attr(attr_icflag, 0) end return h + elseif gc == 'preamble' then else adjust_badness(hd) return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir)) @@ -287,7 +294,7 @@ end do local function create_dir_whatsit_parbox(h, gc) - stop_time_measure('tex_linebreak') + stop_time_measure('tex_linebreak'); -- start 側は ltj-debug.lua に local new_dir = ltjs.list_dir for line in traverse_id(id_hlist, to_direct(h)) do @@ -490,7 +497,7 @@ end -- 1st ret val: b の組方向 -- 2nd ret val はその DIR whatsit -local function get_box_dir(b, default) +function get_box_dir(b, default) start_time_measure('get_box_dir') local dir = has_attr(b, attr_dir) or 0 local bh = getfield(b,'head') @@ -694,6 +701,7 @@ do -- lastbox local node_prev = (node.direct~=node) and node.direct.getprev or node.prev + local id_glue = node.id('glue') local function lastbox_hook() start_time_measure('box_primitive_hook') local bn = tex_nest[tex_nest.ptr].tail @@ -701,6 +709,14 @@ do local b, head = to_direct(bn), to_direct(tex_nest[tex_nest.ptr].head) local bid = getid(b) if bid==id_hlist or bid==id_vlist then + local p = getlist(b) + -- alignment の各行の中身が入ったボックス + if p and getid(p)==id_glue and getsubtype(p)==12 then -- tabskip + local np = node_next(p); local npid = getid(np) + if npid==id_hlist or npid==id_vlist then + setfield(b, 'head', create_dir_whatsit(p, 'align', get_box_dir(np, 0))) + end + end local box_dir = get_box_dir(b, 0) if box_dir>= dir_node_auto then -- unwrap dir_node local p = node_prev(b) diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua index bd40eccf06f..843c3f98af1 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfmglue.lua @@ -637,8 +637,11 @@ end -------------------- 最下層の処理 +luatexbase.create_callback('luatexja.adjust_jfmglue', 'simple', nullfunc) + -- change penalties (or create a new penalty, if needed) local function handle_penalty_normal(post, pre, g) + luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp) local a = (pre or 0) + (post or 0) if #Bp == 0 then if (a~=0 and not(g and getid(g)==id_kern)) then @@ -654,6 +657,7 @@ local function handle_penalty_normal(post, pre, g) end local function handle_penalty_always(post, pre, g) + luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp) local a = (pre or 0) + (post or 0) if #Bp == 0 then if not (g and getid(g)==id_glue) or a~=0 then @@ -669,7 +673,7 @@ local function handle_penalty_always(post, pre, g) end local function handle_penalty_suppress(post, pre, g) - local a = (pre or 0) + (post or 0) + luatexbase.call_callback('luatexja.adjust_jfmglue', head, Nq, Np, Bp) if #Bp == 0 then if g and getid(g)==id_glue then local p = node_new(id_penalty) @@ -677,7 +681,24 @@ local function handle_penalty_suppress(post, pre, g) Bp[1]=p set_attr(p, attr_icflag, KINSOKU) end - else for _, v in pairs(Bp) do add_penalty(v,a) end + else + local a = (pre or 0) + (post or 0) + for _, v in pairs(Bp) do add_penalty(v,a) end + end +end + +local function handle_penalty_jwp() + local a = table_current_stack[luatexja.stack_table_index.JWP] + if #widow_Bp == 0 then + if a~=0 then + local p = node_new(id_penalty) + if a<-10000 then a = -10000 elseif a>10000 then a = 10000 end + setfield(p, 'penalty', a) + head = insert_before(head, widow_Np.first, p) + widow_Bp[1]=p; + set_attr(p, attr_icflag, KINSOKU) + end + else for _, v in pairs(widow_Bp) do add_penalty(v,a) end end end @@ -1023,19 +1044,16 @@ end -------------------- 開始・終了時の処理 do - +local node_prev = node.direct.getprev -- リスト末尾の処理 -local JWP = luatexja.stack_table_index.JWP -local function handle_list_tail(mode) - adjust_nq(); Np = Nq +local function handle_list_tail(mode, last) + adjust_nq() if mode then -- the current list is to be line-breaked. -- Insert \jcharwidowpenalty - Bp = widow_Bp; Np = widow_Np - if Np.first then - handle_penalty_normal(0, table_current_stack[JWP] or 0) - end + if widow_Np.first then handle_penalty_jwp() end else + Np=Nq -- the current list is the contents of a hbox local npi, pm = Np.id, Np.met if npi == id_jglyph or (npi==id_pbox and pm) then @@ -1177,7 +1195,7 @@ function main(ahead, mode, dir) end lp = calc_np(last,lp) end - handle_list_tail(mode) + handle_list_tail(mode, last) end return cleanup(mode, TEMP) end diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua index 81fa6be78d5..7355c9eaa6a 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-jfont.lua @@ -61,6 +61,7 @@ function define_jfm(t) elseif type(t.zw)~='number' or type(t.zh)~='number' then defjfm_res= nil; return end + t.version = (type(t.version)=='number') and t.version or 1 t.char_type = {}; t.chars = {} for i,v in pairs(t) do if type(i) == 'number' then -- char_type @@ -103,11 +104,49 @@ function define_jfm(t) if type(v.down)~='number' then v.down = 0.0 end + if t.version>=2 then + if v.end_stretch then defjfm_res= nil; return end + if v.end_shrink then defjfm_res= nil; return end + if v.end_adjust then + if type(v.end_adjust)~='table' then + v.end_adjust = nil + elseif #(v.end_adjust)==0 then + v.end_adjust = nil + else + table.sort(v.end_adjust) + end + end + else + v.end_adjust = nil + if v.end_stretch and v.end_stretch~=0.0 then + v.end_adjust = (v.end_adjust or {}) + v.end_adjust[#(v.end_adjust)+1] = v.end_stretch + end + if v.end_shrink and v.end_ahrink~=0.0 then + v.end_adjust = (v.end_adjust or {}) + v.end_adjust[#(v.end_adjust)+1] = -v.end_shrink + end + if v.end_adjust then v.end_adjust[#(v.end_adjust)+1] = 0.0 end + 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 + do + local xp + xp, x[4] = (x.priority or x[4]), nil + if type(xp)=='table' and t.version>=2 then + if type(xp[1])~='number' or xp[1]<-4 or xp[1]>3 then defjfm_res=nil end -- stretch + if type(xp[2])~='number' or xp[2]<-4 or xp[2]>3 then defjfm_res=nil end -- shrink + xp = (xp[1]+4)*8+(xp[2]+4) + elseif xp and type(xp)~='number' then + defjfm_res = nil + else + xp = (xp or 0)*9+36 + if xp<0 or xp>=64 then defjfm_res=nil end + end + x.priority = xp + end x.kanjiskip_natural = norm_val(x.kanjiskip_natural) x.kanjiskip_stretch = norm_val(x.kanjiskip_stretch) x.kanjiskip_shrink = norm_val(x.kanjiskip_shrink) @@ -147,7 +186,6 @@ do end update_jfm_cache = function (j,sz) if metrics[j].size_cache[sz] then return end - --local TEMP = node_new(id_kern) local t = {} metrics[j].size_cache[sz] = t t.chars = metrics[j].chars @@ -181,7 +219,6 @@ do t.zw = round(metrics[j].zw*sz) t.zh = round(metrics[j].zh*sz) t.size = sz - --node_free(TEMP) end end diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua index 67474d31ce2..85f7568dbcf 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-ruby.lua @@ -205,7 +205,7 @@ do local hic = has_attr(hx, attr_icflag) if (hic == KANJI_SKIP) or (hic == KANJI_SKIP_JFM) or (hic == XKANJI_SKIP) or (hic == XKANJI_SKIP_JFM) - or ((hic<=FROM_JFM+2) and (hic>=FROM_JFM-2)) then + or ((hic<=FROM_JFM+63) and (hic>=FROM_JFM)) then -- この 5 種類の空白をのばす if getid(hx) == id_kern then local k = node_new(id_glue) @@ -215,7 +215,7 @@ do h = insert_after(h, hx, k); h = node_remove(h, hx); node_free(hx); hx = k else -- glue - setglue(hx, getfield(hx, 'width'), round(middle*65536), 0, + setglue(hx, getfield(hx, 'width'), round(middle*65536), 0, 2, 0) end end diff --git a/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua b/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua index 2cf00758fcf..a85e089eb54 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua +++ b/Master/texmf-dist/tex/luatex/luatexja/luatexja.lua @@ -30,6 +30,15 @@ do setfield(g,'stretch_order',sto or 0) setfield(g,'shrink_order', sho or 0) end + local getfield = node.direct.getfield + luatexja.getglue = node.direct.getglue or + function(g) + return getfield(g,'width'), + getfield(g,'stretch'), + getfield(g,'shrink'), + getfield(g,'stretch_order'), + getfield(g,'shrink_order') + end end --- 以下は全ファイルで共有される定数 @@ -38,17 +47,18 @@ luatexja.icflag_table = icflag_table icflag_table.ITALIC = 1 icflag_table.PACKED = 2 icflag_table.KINSOKU = 3 -icflag_table.FROM_JFM = 6 +icflag_table.FROM_JFM = 4 -- FROM_JFM: 4, 5, 6, 7, 8 →優先度高(伸びやすく,縮みやすい) -- 6 が標準 -icflag_table.KANJI_SKIP = 9 -icflag_table.KANJI_SKIP_JFM = 10 -icflag_table.XKANJI_SKIP = 11 -icflag_table.XKANJI_SKIP_JFM = 12 -icflag_table.PROCESSED = 13 -icflag_table.IC_PROCESSED = 14 -icflag_table.BOXBDD = 15 -icflag_table.PROCESSED_BEGIN_FLAG = 128 +icflag_table.KANJI_SKIP = 68 -- = 4+64 +icflag_table.KANJI_SKIP_JFM = 69 +icflag_table.XKANJI_SKIP = 70 +icflag_table.XKANJI_SKIP_JFM = 71 +icflag_table.LINEEND = 72 +icflag_table.PROCESSED = 73 +icflag_table.IC_PROCESSED = 74 +icflag_table.BOXBDD = 75 +icflag_table.PROCESSED_BEGIN_FLAG = 4096 -- sufficiently large power of 2 local stack_table_index = {} luatexja.stack_table_index = stack_table_index @@ -462,6 +472,8 @@ local function debug_show_node_X(p,print_fn, limit) s = s .. ' (for accent)' elseif get_attr_icflag(p)==icflag_table.IC_PROCESSED then s = s .. ' (italic correction)' + elseif get_attr_icflag(p)==icflag_table.LINEEND then + s = s .. ' (end-of-line)' -- elseif get_attr_icflag(p)==ITALIC then -- s = s .. ' (italic correction)' elseif get_attr_icflag(p)>icflag_table.KINSOKU diff --git a/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty b/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty index 703c00fe90b..a075947af0f 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty +++ b/Master/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty @@ -264,7 +264,7 @@ \@texttop \dimen@ \dp\@outputbox \unvbox \@outputbox - \ifnum\ltjgetparameter{direction}=4\else\hskip\z@\fi %%% LuaTeX-ja + \ifnum\ltjgetparameter{direction}=4\else\vbox{\hskip\z@}\fi %%% LuaTeX-ja \vskip -\dimen@ \@textbottom }% -- cgit v1.2.3