OSDN Git Service

Use everysel package for patching \selectfont.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Thu, 8 May 2014 08:58:13 +0000 (17:58 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Thu, 8 May 2014 08:58:13 +0000 (17:58 +0900)
src/luatexja-core.sty
src/patches/lltjdefs.sty
src/patches/lltjfont.sty

index 6f50e34..a725e0d 100644 (file)
 \ltj@origchar=0
 \ltj@charclass=0
 \ltj@curjfnt=-1
+\ltj@curtfnt=-1
 
 %%%%%%%% Attributes for character ranges
 \newcount\ltj@tempcnta
     \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
 
 % jatextfont = {<char_code>, <font_cs>}
+% only horizontal font is supported
 \define@key[ltj]{japaram}{jatextfont}{%
   \expandafter\ltj@@set@stackfont#1:{MJT}}
 \define@key[ltj]{japaram}{jascriptfont}{%
 % いつも global
 \def\ltj@@getjfontnumber#1{% result in \ltj@tempcntc 
   \ltj@reset@globaldefs
-  \begingroup\ltj@curjfnt=-1\relax
-  #1\directlua{luatexja.__temp = \the\ltj@curjfnt}\endgroup
+  \begingroup\ltj@curjfnt=-1 \ltj@curtfnt=-1\relax
+  #1\directlua{luatexja.__temp = -\the\ltj@curjfnt*\the\ltj@curtfnt}\endgroup
   \ltj@tempcntc=\directlua{tex.sprint(luatexja.__temp)}\relax
   \ifnum\ltj@tempcntc=-1
     \@PackageError{luatexja-core}%
     {\string#1 is not a control sequence that represents \MessageBreak
-     a Japanese font}{I'll use the current Japanese font instead.^^J}%
+     a Japanese font}{I'll use the current horizontal Japanese font instead.^^J}%
     \ltj@tempcntc=\ltj@curjfnt
   \fi\ltj@restore@globaldefs}
   
    \directlua{luatexja.jfont.clear_alt_font(\the\ltj@tempcntc)}}\ignorespaces}
 
 
+%%%%%%%% \yoko, \tate, \ifydir, \iftdir
+\newif\ifydir
+\newif\iftdir
+\protected\def\tate{%
+  \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
+  \ltj@dir=3 \tdirtrue\ydirfalse
+}
+\protected\def\yoko{%
+  \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
+  \ltj@dir=4 \ydirtrue\tdirfalse
+}
+\yoko
+
 %%------------------ Load module for the format
 
 \ifltj@in@latex                 %<*LaTeX>
 \ltj@overwrite@catcodetable\CatcodeTableLaTeXAtLetter
 \ltj@overwrite@catcodetable\CatcodeTableExpl
 
-%%%%%%%% \yoko, \tate, \ifydir, \iftdir
-\protected\def\tate{%
-  \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
-  \ltj@dir=3 
-}
-\protected\def\yoko{%
-  \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
-  \ltj@dir=4 
-}
-\yoko
-\newif\ifydir\ydirtrue
-\newif\iftdir\tdirfalse
-
 
 %%------------------ all done
 \ltj@core@AtEnd
index 716c385..af64356 100644 (file)
@@ -23,7 +23,6 @@
 \newcommand\kanjifamilydefault{\mcdefault}
 \newcommand\kanjiseriesdefault{\mddefault}
 \newcommand\kanjishapedefault{\updefault}
-\kanjiencoding{JY3}
 
 \DeclareKanjiFamily{JY3}{mc}{}
 \DeclareFontShape{JY3}{mc}{m}{n}{<-> s*[0.962216] \ltj@stdmcfont:jfm=ujis}{}
 \DeclareFontShape{JY3}{mc}{bx}{n}{<-> ssub*gt/m/n}{}
 \DeclareFontShape{JY3}{gt}{bx}{n}{<-> ssub*gt/m/n}{}
 
-\kanjiencoding{JT3}
-
 \DeclareKanjiFamily{JT3}{mc}{}
-\DeclareFontShape{JT3}{mc}{m}{n}{<-> s*[0.962216] \ltj@stdmcfont:jfm=ujis}{}
+\DeclareFontShape{JT3}{mc}{m}{n}{<-> s*[0.962216] \ltj@stdmcfont:jfm=ujisv}{}
 \DeclareKanjiFamily{JT3}{gt}{}
-\DeclareFontShape{JT3}{gt}{m}{n}{<-> s*[0.962216] \ltj@stdgtfont:jfm=ujis}{}
+\DeclareFontShape{JT3}{gt}{m}{n}{<-> s*[0.962216] \ltj@stdgtfont:jfm=ujisv}{}
 \DeclareFontShape{JT3}{mc}{bx}{n}{<-> ssub*gt/m/n}{}
 \DeclareFontShape{JT3}{gt}{bx}{n}{<-> ssub*gt/m/n}{}
+\KanjiEncodingPair{JY3}{JT3}
 
 \kanjiencoding{JY3}\selectfont\adjustbaseline
 
index 26db755..926c8fa 100644 (file)
         \usekanji{#2}{#3}{#4}{#5}%
         \global\let#1\getjfont
       \else
-        %\directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{#2}')}\ifin@%
-        %  \usekanji{#2}{#3}{#4}{#5}%
-        %  \let\font\tfont
-        %\else
+        \directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{#2}')}\ifin@%
+          \usekanji{#2}{#3}{#4}{#5}%
+          \global\let#1\gettfont
+        \else
           \useroman{#2}{#3}{#4}{#5}%
           \global\expandafter\let\expandafter#1\the\font
-        %\fi
+        \fi
       \fi
    \endgroup
   }
 }
 \newif\if@knjcmd
 \def\userelfont{\@knjcmdtrue}
-\DeclareRobustCommand\selectfont{%
-  \let\tmp@error@fontshape\error@fontshape
+
+
+\RequirePackage{everysel}
+\@EverySelectfont@Init
+\def\ltj@selectfont@patch{%
+ \let\tmp@error@fontshape\error@fontshape
   \let\error@fontshape\error@kfontshape
   \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
     \let\cy@encoding\k@encoding
       \@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
     \fi
   \fi
+%
+  \let\k@encoding\ct@encoding
+  \xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
+  \pickup@tfont
+  \font@name
+  \ltj@@does@alt@set{\curr@kfontshape}%
+    % alt fonts の定義
+    \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}%
+    % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
+    \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
+  \fi
+%
   \let\k@encoding\cy@encoding
   \xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
   \pickup@jfont
   \font@name
+  \ltj@@does@alt@set{\curr@kfontshape}%
+    % alt fonts の定義
+    \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}%
+    % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
+    \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
+  \fi
+%
   \edef\tmp@item{{\k@encoding}}\expandafter\def\expandafter\k@encoding\tmp@item
   \kenc@update
   \let\error@fontshape\tmp@error@fontshape
+%
   \if@knjcmd \@knjcmdfalse
     \expandafter\ifx
     \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\relax
       \expandafter\ifx
          \csname rel@\k@encoding/\k@family/\k@series/all\endcsname\relax
       \else
-         \csname rel@\k@encoding/\k@family/\k@series/all\endcsname
+         \csname rel@\k@encoding/\k@family/\k@series/all\endcsname\selectfont
+         % 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
       \fi
     \else
-       \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname
+       \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\selectfont
+       % 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
     \fi
   \fi
-  \xdef\font@name{\csname\curr@fontshape/\f@size\endcsname}%
-  \pickup@font
-  \font@name
-  \enc@update
-  \ifx\f@linespread\baselinestretch \else
-    \set@fontsize\baselinestretch\f@size\f@baselineskip
-  \fi
-  \size@update
-% ここからは altfont 用
-  \ltj@@does@alt@set{\curr@kfontshape}%
-    % alt fonts の定義
-    \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}%
-    % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
-    \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
-  \fi
 }
+\EverySelectfont{\ltj@selectfont@patch}
+\def\@EverySelectfont@Init{\let\@EverySelectfont@Init\undefined}
+
 \def\KanjiEncodingPair#1#2{\@namedef{t@enc@#1}{#2}\@namedef{y@enc@#2}{#1}}
-\KanjiEncodingPair{JY3}{JT3}
 \def\set@fontsize#1#2#3{%
     \@defaultunits\@tempdimb#2pt\relax\@nnil
     \edef\f@size{\strip@pt\@tempdimb}%
     \cvs\normalbaselineskip
     \chs\cwd
     \cHT\cht \advance\cHT\cdp
-  % \iftdir
-  %   \setbox\adjust@box\hbox{\tbaselineshift\z@ M}%
-  %   \adjust@dimen\ht\adjust@box
-  %   \advance\adjust@dimen\dp\adjust@box
-  %   \advance\adjust@dimen-\cHT
-  %   \divide\adjust@dimen\tw@
-  %   \advance\adjust@dimen\cdp
-  %   \advance\adjust@dimen-\dp\adjust@box
-  %   \tbaselineshift\adjust@dimen
-  % \fi
+    %\iftdir
+      \setbox0\hbox{\tate\ltjsetparameter{tjabaselineshift=\z@}あ}%
+      \setbox\adjust@box\hbox{\tate\ltjsetparameter{talbaselineshift=\z@}M}%
+      \adjust@dimen\ht\adjust@box
+      \advance\adjust@dimen\dp\adjust@box
+      \advance\adjust@dimen-\ht0
+      \divide\adjust@dimen\tw@
+      \advance\adjust@dimen0.5\dp0
+      \advance\adjust@dimen-\dp\adjust@box
+      \ltjsetparameter{talbaselineshift=\adjust@dimen}
+    %\fi
   }
 \DeclareRobustCommand\romanencoding[1]{%
     \expandafter\ifx\csname T@#1\endcsname\relax
   \directlua{luatexja.jfont.is_kyenc(\tmp@enc)}\ifin@%
     \let\cy@encoding\k@encoding
   \else
-    %\directlua{luatexja.jfont.is_ktenc(\tmp@enc)}\ifin@%
-    %  \let\ct@encoding\k@encoding
-    %\else
+    \directlua{luatexja.jfont.is_ktenc(\tmp@enc)}\ifin@%
+      \let\ct@encoding\k@encoding
+    \else
       \@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
-    %\fi
+    \fi
   \fi
 }
 \let\kenc@update\relax
        \let\extract@font\extract@afont
     \fi
     \let\getjfont\font@name}
+\def\pickup@tfont{%
+    \expandafter \ifx \font@name \relax
+       \let\extract@font\extract@tfont
+       \define@newfont
+       \let\extract@font\extract@afont
+    \fi
+    \let\gettfont\font@name}
 
 % 異なる和文 enc/fam/ser/shape からは異なるフォント番号が振られるように
 % わざと「ゴミをつける」
     \font@name%\global\zw=\zw\global\zh=\zh
     \csname \f@encoding+\f@family\endcsname
     \csname\curr@fontshape\endcsname}
+\def\extract@tfont{%
+   \get@external@font
+    \ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}%
+      \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
+    \fi
+    \expandafter\globaltfont\font@name\external@font\relax
+    \font@name%\global\zw=\zw\global\zh=\zh
+    \csname \f@encoding+\f@family\endcsname
+    \csname\curr@fontshape\endcsname}
 
 \let\ltj@@al@do@subst@correction=\do@subst@correction
 \def\ltj@@ja@do@subst@correction{%