OSDN Git Service

Implemented \ifydir{<num>} etc.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 18 May 2014 20:50:28 +0000 (05:50 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 18 May 2014 20:50:28 +0000 (05:50 +0900)
doc/luatexja.dtx
src/ltj-direction.lua
src/ltj-pretreat.lua
src/luatexja-core.sty
src/luatexja.lua

index 6d3a676..271315a 100644 (file)
@@ -857,8 +857,8 @@ plfonts.dtx} and \texttt{pldefs.ltx}):
 
 \begin{itemize}
 %<*en>
-\item The font encoding for Japanese fonts (in horizontal direction) is \texttt{JY3}.\\
-\texttt{JT3} is used for Japanese fonts in vertical diraction.
+\item The font encoding for Japanese fonts (fot horizontal direction) is \texttt{JY3}.\\
+\texttt{JT3} is used for Japanese fonts for vertical diraction.
 %</en>
 %<*ja>
 \item 和文フォントのエンコーディングとしては,横組用には \texttt{JY3},縦組用には\ 
@@ -2770,27 +2770,30 @@ Down-TO-Upの意味なのだろう.\verb+\dtou+ を使用する機会はない
 
 \begin{cslist}
 
- \item[ltjgetwd<num>\textrm{, }\textbackslash ltjgetht<num>\textrm{, }%
-  \textbackslash ltjgetdp<num>
+ \item[ltjgetwd\{<num>\}\textrm{, }\textbackslash ltjgetht\{<num>\}\textrm{, }%
+  \textbackslash ltjgetdp\{<num>\}
 現在の組方向に応じたボックスの寸法の取得を行う.結果は内部長さであるため,
 {\let\item=\origitem
 \begin{verbatim}
-\dimexpr 2\ltjgetwd42-3pt\relax, \the\ltjgetwd1701
+\dimexpr 2\ltjgetwd{42}-3pt\relax, \the\ltjgetwd{1701}
 \end{verbatim}
-のように \verb+\wd+<num> の代わりとして扱うことができる.使用例は以下の通りである.
+のように \verb+\wd+<num> の代わりとして扱うことができる.引数が1桁の場合は,
+\verb+\ltjgetwd3+ のように引数をグループで括らなくても良いが,そうでない場合は
+(通常の命令への引数のように)\verb+\ltjgetwd{42}+ とグループに括る必要がある.
+使用例は以下の通りである.
 \begin{LTXexample}[width=0.3\textwidth]
 \parindent0pt
 \setbox32767=\hbox{\yoko よこぐみ}
 \fboxsep=0mm\fbox{\copy32767}
 \vbox{\hsize=20mm 
-\yoko YOKO \the\ltjgetwd32767, \\
-  \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
+\yoko YOKO \the\ltjgetwd{32767}, \\
+  \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
 \vbox{\hsize=20mm\raggedleft
-\tate TATE \the\ltjgetwd32767, \\
-  \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
+\tate TATE \the\ltjgetwd{32767}, \\
+  \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
 \vbox{\hsize=20mm\raggedleft
-\dtou DTOU \the\ltjgetwd32767, \\
-  \the\ltjgetht32767, \\ \the\ltjgetdp32767.}
+\dtou DTOU \the\ltjgetwd{32767}, \\
+  \the\ltjgetht{32767}, \\ \the\ltjgetdp{32767}.}
 \end{LTXexample}}
 
  \item[ltjsetwd<num>=<dimen>\textrm{, }\textbackslash ltjsetht<num>=<dimen>\textrm{, }%
@@ -2799,16 +2802,30 @@ Down-TO-Upの意味なのだろう.\verb+\dtou+ を使用する機会はない
 実装しているので,次の4通りは全て同じ意味である.
 {\let\item=\origitem
 \begin{verbatim}
- \ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
+\ltjsetwd42 20pt,  \ltjsetwd42=20pt,  \ltjsetwd=42 20pt,  \ltjsetwd=42=20pt
 \end{verbatim}
 }%
 
-
 設定値は組方向ごとに独立して記録される.
 
+\end{cslist} 
 
+\subsection{組方向の取得・条件判断}
+「現在の組方向」や「<num>番のボックスの組方向」は,以下の命令によって
+知ることができる.
+
+\begin{cslist}
+ \item[ifydir\textrm{, }\textbackslash iftdir\textrm{, }\textbackslash ifddir]
+現在の組方向が横組(\verb+\yoko+),縦組(\verb+\tate+),\verb+\dtou+ 方向であるかを
+それぞれ判定する.
+
+ \item[ifybox\{<num>\}\textrm{, }\textbackslash iftbox\{<num>\}\textrm{, }%
+  \textbackslash ifdbox\{<num>\}]
+<num>番のレジスタの中身が横組ボックス,縦組ボックス,\verb+\dtou+ 方向の
+ボックスか否かをそれぞれ判定する.
+
+\end{cslist}
 
-\end{cslist} 
 %</ja>
 
 %<en>\section{Font Metric and Japanese Font}
@@ -5521,6 +5538,7 @@ Here the following is the list of dimensions and attributes which are used in \L
 \begin{list}{}{%
 \def\makelabel{\ttfamily}\advance\leftmargin1\zw
 \def\dim#1{\item[\textbackslash #1\ \textrm{(dimension)}]}
+\def\cnt#1{\item[\textbackslash #1\ \textrm{(counter)}]}
 \def\attr#1{\item[\textbackslash #1\ \textrm{(attribute)}]}
 }
 
@@ -5582,10 +5600,18 @@ Current number of Japanese font family for math formulas.
 
 \attr{ltj@curjfnt}
 %<*en>
-The font index of current Japanese font.
+The font index of current Japanese font for horizontal direction.
 %</en>
 %<*ja>
-現在の和文フォントのフォント番号.
+現在の横組用和文フォントのフォント番号.
+%</ja>
+
+\attr{ltj@curtfnt}
+%<*en>
+The font index of current Japanese font for vertical direction.
+%</en>
+%<*ja>
+現在の縦組用和文フォントのフォント番号.
 %</ja>
 
 \attr{ltj@charclass}
@@ -5612,6 +5638,9 @@ The amount of shifting the baseline of Japanese fonts in scaled point ($2^{-16}\
 スケールド・ポイント($2^{-16}\,\textrm{pt}$)を単位とした和文フォントのベースラインの移動量.
 %</ja>
 
+\attr{ltj@tablshift}
+\attr{ltj@tkblshift}
+
 \attr{ltj@autospc}
 %<*en>
 Whether the auto insertion of \Param{\hyperlink{fld:kanjiskip}{kanjiskip}} is allowed at the node.
@@ -5695,18 +5724,42 @@ $i$は7より小さい自然数.
 これら7つの属性レジスタは,どの文字ブロックが\textbf{JAchar}のブロックとして
 扱われるかを示すビットベクトルを格納する.
 %</ja>
+
+\cnt{ltj@dir@count}
+%<*ja>
+現在の組方向を表す.
+%</ja>
+\begin{description}
+\item[\textit{dir\_dtou} (1)]
+\item[\textit{dir\_tate} (3)]
+\item[\textit{dir\_yoko} (4)]
+\end{description}
+
+\attr{ltj@dir}
+%<*ja>
+ボックスにおける組方向を示す.上記の3つの値(1,~3,~4)の他に,
+それらに次を加えた値(17,~19, 20, 33, 35,~36)もとり得る.
+%</ja>
+\begin{description}
+\item[\textit{dir\_node\_auto} (16)]
+\item[\textit{dir\_node\_manual} (32)]
+\end{description}
+
+
 \end{list}
 
 %<*en>
 Furthermore, \LuaTeX-ja uses several user-defined whatsit nodes for
-inrernal processing. All those nodes store a natural number (hence the node's
-\texttt{type} is 100). 
+inrernal processing. All those nodes except \emph{direction} whatsits 
+store a natural number (hence its \texttt{type} is 100). 
+\emph{direction} whatsits store a node list, hence its \texttt{type} is 110.
 Their \texttt{user\_id} (used for distinguish user-defined whatsits) 
 are allocated by \texttt{luatexbase.newuserwhatsitid}.
 %</en>
 %<*ja>
 さらに,\LuaTeX-jaはいくつかのuser-defined whatsit nodeを内部処理に用いる.
-これらのwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
+\textit{direction} whatsitはノードリストを格納するが,
+それ以外のwhatsitノードの \texttt{type} は100であり,ノードは自然数を格納している.
 user-defined whatsitを識別するための \texttt{user\_id} は\ 
 \texttt{luatexbase.newuserwhatsitid} により確保されており,
 下の見出しは単なる識別用でしかない.
@@ -5772,6 +5825,9 @@ for its label before the actual contents. So \dots
 「段落の開始」を意味するノード.
 list環境,itemize環境などにおいて,\verb+\item+ で始まる各項目は……
 %</ja>
+
+\item[\textit{direction}]
+
 \end{description}
 
 %<*en>
index f3d6cc4..7e0b654 100644 (file)
@@ -621,6 +621,29 @@ do
    luatexja.direction.set_box_dim = set_box_dim
 end
 
+-- \ifydir, \iftdir, \ifddir
+do
+   local cat_lp = luatexbase.catcodetables['latex-package']
+   local getbox = tex.getbox
+   local function dir_conditional(n, mode)
+      local s = getbox(n)
+      local res = false
+      if s then
+         s = to_direct(s)
+         local b_dir = get_box_dir(s, dir_yoko)
+         if b_dir<dir_node_auto then
+           res = (b_dir==mode)
+         else
+           local b_dir = get_box_dir(
+              node_next(node_next(node_next(getlist(s)))), dir_yoko)
+           res = (b_dir==mode)
+         end
+      end
+      tex.sprint(cat_lp, '\\if' .. tostring(res))
+   end
+   luatexja.direction.dir_conditional = dir_conditional
+end
+
 -- 縦書き用字形への変換テーブル
 local font_vert_table = {} -- key: fontnumber
 do
index 19c2049..080cf89 100644 (file)
@@ -49,7 +49,6 @@ local ltjf_replace_altfont = ltjf.replace_altfont
 local attr_orig_char = luatexbase.attributes['ltj@origchar']
 local STCK  = luatexja.userid_table.STCK
 local DIR   = luatexja.userid_table.DIR
-local DNODE = luatexja.userid_table.DNODE
 local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG
 
 local dir_tate = luatexja.dir_table.dir_tate
@@ -87,8 +86,6 @@ do
               ltjs.list_dir = has_attr(p, attr_dir)
            end
            wtd[#wtd+1] = p; head = node_remove(head, p)
-         elseif uid==DNODE then
-           wtd[#wtd+1] = p; head = node_remove(head, p)
          end
       end
       return p
index 5e676dd..bfac233 100644 (file)
   \ltj@dir@count=1\ydirfalse\tdirfalse\ddirtrue}
 \yoko
 
-%%%%%%%% \ifybox, \iftbox
-%%%%%%%% \ltjgetwd{<box_num>} etc. 
-\def\ltjgetwd{\expandafter\expandafter\expandafter\ltj@@getwd\ltj@grab@num}
-\def\ltjgetht{\expandafter\expandafter\expandafter\ltj@@getht\ltj@grab@num}
-\def\ltjgetdp{\expandafter\expandafter\expandafter\ltj@@getdp\ltj@grab@num}
+%%%%%%%% \ltjgetwd<box_num> etc.
+%\def\ltjgetwd{\expandafter\expandafter\expandafter\ltj@@getwd\ltj@grab@num}
+%\def\ltjgetht{\expandafter\expandafter\expandafter\ltj@@getht\ltj@grab@num}
+%\def\ltjgetdp{\expandafter\expandafter\expandafter\ltj@@getdp\ltj@grab@num}
 \def\ltj@@getwd#1{%
   \directlua{luatexja.direction.get_box_dim('width', \the\numexpr#1\relax)}%
   \ltj@tempdima%
   \directlua{luatexja.direction.get_box_dim('depth', \the\numexpr#1\relax)}%
   \ltj@tempdima%
 }
+\let\ltjgetwd=\ltj@@getwd\let\ltjgetht=\ltj@@getht\let\ltjgetdp=\ltj@@getdp
 
+%%%%%%%% \ltjsetwd<box_num>=<dimen> etc.
 \protected\def\ltjsetwd{\begingroup
   \ltj@reset@globaldefs\afterassignment\ltj@@setwd@a\ltj@tempcnta}
 \def\ltj@@setwd@a{\afterassignment\ltj@@setwd@b\ltj@tempdima}
   \directlua{luatexja.direction.set_box_dim('depth')}%
   \ltj@restore@globaldefs\endgroup}
 
-
+%%%%%%%% \ifybox, \iftbox, \ifdbox
+\def\ltj@@box@cond#1#2\fi{\fi\csname if#1\endcsname}
+\def\ifybox#1{\directlua{luatexja.direction.dir_conditional(\the\numexpr #1\relax, 4)}%
+  \ltj@@box@cond{true}\else\ltj@@box@cond{false}\fi}
+\def\iftbox#1{\directlua{luatexja.direction.dir_conditional(\the\numexpr #1\relax, 3)}%
+  \ltj@@box@cond{true}\else\ltj@@box@cond{false}\fi}
+\def\ifdbox#1{\directlua{luatexja.direction.dir_conditional(\the\numexpr #1\relax, 1)}%
+  \ltj@@box@cond{true}\else\ltj@@box@cond{false}\fi}
 
 %%------------------ Load module for the format
 
index 4dc1d6b..6ca1b67 100644 (file)
@@ -59,7 +59,6 @@ userid_table.IHB  = luatexbase.newuserwhatsitid('inhibitglue',  'luatexja') -- \
 userid_table.STCK = luatexbase.newuserwhatsitid('stack_marker', 'luatexja') -- スタック管理
 userid_table.BPAR = luatexbase.newuserwhatsitid('begin_par',    'luatexja') -- 「段落始め」
 userid_table.DIR  = luatexbase.newuserwhatsitid('direction',    'luatexja') -- 組方向
-userid_table.DNODE= luatexbase.newuserwhatsitid('dir_node',    'luatexja')  -- dir_node
 
 local dir_table = {}
 luatexja.dir_table = dir_table