OSDN Git Service

use pre_shipout_filter hook if available
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 16 Mar 2021 09:18:28 +0000 (18:18 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 16 Mar 2021 09:18:28 +0000 (18:18 +0900)
src/ltj-base.sty
src/ltj-direction.lua
src/ltj-latex.sty
src/ltj-plain.sty
src/luatexja-core.sty
src/luatexja.lua

index 622b387..2ce01d7 100644 (file)
@@ -13,7 +13,7 @@
 
 \ifltj@in@latex                 %<*LaTeX>
   \NeedsTeXFormat{LaTeX2e}
-  \ProvidesPackage{ltj-base}[2020-08-04]
+  \ProvidesPackage{ltj-base}[2021-03-16]
 \fi                             %</LaTeX>
 
 %%------------------ Tiny helpers
 %% \ltj@q@mark
 \protected\def\ltj@q@mark{\ltj@q@mark@}
 
-%! etoolbox の \letcs, \cslet, \csletcs.
-%% \ltj@letcs
-\protected\def\ltj@letcs#1#2{
-  \expandafter\let\expandafter#1\csname#2\endcsname
-}
-
-%% \ltj@cslet
-\protected\def\ltj@cslet#1#2{
-  \expandafter\let\csname#1\endcsname#2
-}
-
+%! etoolbox の \csletcs.
 %% \ltj@csletcs
 \protected\def\ltj@csletcs#1#2{
   \expandafter\let\csname#1\expandafter\endcsname
   \else\expandafter\ltx@secondoftwo\fi
 }
 
-%% \ltj@if@empty{<stuff>}{<yes>}{<no>}
-%! <stuff> が空であるか.
-% Checks if <stuff> is empty.
-\long\def\ltj@if@empty#1{
-  \ltj@ifx{\ltj@@q@empty#1\ltj@@q@empty}
-}
 \protected\def\ltj@@q@empty{\ltj@@q@empty@}
 
 %% \ltj@if@blank{<stuff>}{<yes>}{<no>}
 %! plain であるか.
 \ltj@csletcs{ifltj@in@plain}{iffalse}
 
-%% \ltj@print{<message>}
-%! 端末への出力.
-\let\ltj@print\typeout
-
 \else                           %<*!LaTeX>
 
 %% \ifltj@in@plain
   \ltj@csletcs{ifltj@in@plain}{iffalse}
 \fi
 
-%% \ltj@print{<message>}
-\def\ltj@print#1{
-  \immediate\write16{#1}
-}
-
 \fi                             %</LaTeX>
 %%------------------ Value-token handling
 
   }
 }
 
-%% \ltj@safe@real{<real>}
-%! 実数. これは十進表記に限る.
-% For a real number given in decimal notation or a macro that
-% expands to such notation.
-\def\ltj@safe@real#1{
-  (tonumber("\luatexluaescapestring{#1}"))
-}
-
-%% \ltj@val@counter{<counter>}
-%! LaTeX カウンタの現在値.
-% For the current value of a LaTeX counter.
-\def\ltj@val@counter#1{
-  (\expandafter\number\csname c@#1\endcsname)
-}
-
-%% \ltj@val@skip{<skip>}
-% For the current value of a skip (or LaTeX-length) parameter.
-%! グルーレジスタ(LaTeX 長さ変数).
-%! 整形式のグルー値にも使える.
-\def\ltj@val@skip#1{
-  (luatexja.base.to_skip("\the\glueexpr#1\relax"))
-}
 %! 整形式の整数 → 数値 : \number#1
 %! 内部寸法 → 数値 : \number#1
 %! 整形式の寸法 → 数値 : \number\dimexpr#1\relax
   "\luatexluaescapestring{\detokenize{#1}}"
 }
 
-%% \ltj@luaescape{<text>}
-%! 非トークン化して Lua エスケープ.
-\def\ltj@luaescape#1{
-  \luatexluaescapestring{\detokenize{#1}}
-}
-%% \ltj@luaxescape{<text>}
-%! 非トークン化せずに(展開ありで) Lua エスケープ.
-%! つまり単なる \luatexescape.
-\let\ltj@luaxescape\luatexluaescapestring
-
-
 %%------------------ debug logging
 \ifdefined\LuaTeXjaDebugEnabled
 
 
 %% \ltj@afterbox <token><box>
 %% -> \setbox\ltj@afbox<box><token>
-%% from Sonja Maus, ``Looking Ahead for a <box>'',
-%%      TUGBoat, 11, No. 4, 1990.
+%% idea from the atbegshi package
 \newbox\ltj@afbox
 \directlua{luatexja.afbox_number=\the\ltj@afbox}
 \protected\def\ltj@afterbox#1{%
-  \def\ltj@afb@xarg{#1}%
-  \afterassignment\ltj@afb@x
-  \chardef\ltj@@next`.}
-\def\ltj@afb@x{\futurelet\ltj@@next\ltj@afb@xtest}
-\def\ltj@afb@xtest{%
-  \ifcase\ifx\ltj@@next\hbox\tw@\fi
-         \ifx\ltj@@next\vbox\tw@\fi
-         \ifx\ltj@@next\vtop\tw@\fi
-         \ifx\ltj@@next\box\@ne\fi
-         \ifx\ltj@@next\copy\@ne\fi
-         \ifx\ltj@@next\vsplit\@ne\fi
-         \ifx\ltj@@next\lastbox\@ne\fi
-         0% ``A <box> was ...'' error will be causes by \setbox later anyway.
-  \or\afterassignment\ltj@afb@xarg
-  \or\afterassignment\ltj@afb@xagarg
-  \fi
-  \setbox\ltj@afbox
+  \def\ltj@afbox@@arg{#1}\edef\ltj@afbox@@grouplevel{\number\currentgrouplevel}%
+  \afterassignment\ltj@afbox@@\setbox\ltj@afbox}
+\def\ltj@afbox@@{%
+  \ifnum\ltj@afbox@@grouplevel<\currentgrouplevel\expandafter\aftergroup\fi\ltj@afbox@@arg
 }
-\def\ltj@afb@xagarg{\aftergroup\ltj@afb@xarg}
 
 
 %%------------------ all done
index 4c6c3b6..f2f5d55 100644 (file)
@@ -1130,4 +1130,17 @@ do
       shipout(afbox)
       stop_time_measure 'box_primitive_hook'
    end
+   function luatexja.direction.shipout_lthook(head)
+      start_time_measure 'box_primitive_hook'
+      local a = to_direct(head)
+      local a_dir = get_box_dir(a, dir_yoko)
+      if a_dir~=dir_yoko then
+         local b = create_dir_node(a, a_dir, dir_yoko, false)
+         setfield(b, 'head', a); a = b
+      end
+      setfield(shipout_temp, 'head', a); finalize_inner(shipout_temp)
+      a = copy(getlist(shipout_temp)); setfield(shipout_temp, 'head',nil)
+      stop_time_measure 'box_primitive_hook'
+      return to_node(a)
+   end
 end
index 213f2f7..ec7aea3 100644 (file)
 \def\luatexjalatexLoaded{\endinput}
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{ltj-latex}[2020-12-29 LaTeX support of LuaTeX-ja]
-
-% cleanup at end of the document
-%\let\ltj@@orig@end=\@@end
-%\protected\def\@@end{%
-%  \directlua{luatexja.ext_cleanup()}\ltj@@orig@end}
+\ProvidesPackage{ltj-latex}[2021-03-16 LaTeX support of LuaTeX-ja]
 
 \endlinechar=13
 
 %%% LaTeX version detection
-\ifcsname tex_shipout:D\endcsname
-  \expandafter\let\csname tex_shipout:D\endcsname\ltj@shipout
-\fi
 \newif\ifltj@ltfilehook@avail
 \@ifl@t@r\fmtversion{2020-10-01}{%
   \@ifl@t@r\fmtversion{2020-10-02}%
       \else\ltj@ltfilehook@availtrue\fi
     }%
 }{}
+\@ifl@t@r\fmtversion{2021-05-01}{\count@=1 }{\count@=0 }
+\ifnum \count@<1
+  \protected\luadef\ltj@@lua@shipout\ltj@@lua@shipout@inner
+  \protected\def\ltj@shipout{\ltj@afterbox\ltj@@lua@shipout}
+  \let\shipout\ltj@shipout
+  \ifcsname tex_shipout:D\endcsname
+    \expandafter\let\csname tex_shipout:D\endcsname\ltj@shipout
+  \fi
+  \directlua{luatexja.direction.shipout_lthook = nil}
+\else
+  \directlua{%
+    luatexbase.add_to_callback('pre_shipout_filter',luatexja.direction.shipout_lthook, 'ltj.direction', 1)
+    luatexja.direction.shipout = nil
+  }
+\fi
 
 %%% patch for LaTeX
 \usepackage{lltjfont}
index 58baa9f..23298da 100644 (file)
 %! ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 % LuaTeX-ja macros against plain TeX
 
+\protected\luadef\ltj@@lua@shipout\ltj@@lua@shipout@inner
+\protected\def\ltj@shipout{\ltj@afterbox\ltj@@lua@shipout}
+\let\shipout\ltj@shipout
+\directlua{luatexja.direction.shipout_lthook = nil}
+
 \ifdefined\ltj@stdmcfont\else\def\ltj@stdmcfont{file:HaranoAjiMincho-Regular.otf}\fi
 \ifdefined\ltj@stdgtfont\else\def\ltj@stdgtfont{file:HaranoAjiGothic-Medium.otf}\fi
-%\ifdefined\ltj@stdmcfont\else\def\ltj@stdmcfont{IPAExMincho}\fi
-%\ifdefined\ltj@stdgtfont\else\def\ltj@stdgtfont{IPAExGothic}\fi
 \ifdefined\ltj@stdyokojfm\else\def\ltj@stdyokojfm{ujis}\fi
 \ifdefined\ltj@stdtatejfm\else\def\ltj@stdtatejfm{ujisv}\fi
 \newread\ltj@@cfgread
@@ -96,9 +99,6 @@
 \ltjsetparameter{jacharrange={-1, +2, +3, -4, -5, +6, +7, -8, +9}}
 
 \directlua{for x=128,255 do luatexja.math.is_math_letters[x] = true end}
-\let\ltj@@orig@end=\@@end
-\protected\def\@@end{%
-  \directlua{luatexja.ext_cleanup()}\ltj@@orig@end}
 
 \directlua{luatexja.jfont.register_vert_replace{
   [',']='、', ['.']='。', ['“']=0x301D, ['”']=0x301F,
index e1baefb..75cc048 100644 (file)
@@ -65,7 +65,7 @@
   \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
     \csname iftrue\endcsname
   \NeedsTeXFormat{LaTeX2e}
-  \ProvidesPackage{luatexja-core}[2021-01-02 Core of LuaTeX-ja]
+  \ProvidesPackage{luatexja-core}[2021-03-16 Core of LuaTeX-ja]
 \fi                             %</LaTeX>
 
 %% Load prerequisite packages.
   local t = lua.get_functions_table()
   t[\the\ltj@@lua@shipout@inner]=luatexja.direction.shipout
 }
-\protected\luadef\ltj@@lua@shipout\ltj@@lua@shipout@inner
-\protected\def\ltj@shipout{\ltj@afterbox\ltj@@lua@shipout}
-\ifprimitive\shipout\let\shipout\ltj@shipout\fi
 
 %%%% \unhbox and \unvbox
 \newluafunction\ltj@@lua@unboxcheckdir@inner
index 7c8d385..8c01db1 100644 (file)
@@ -332,11 +332,6 @@ do
    ltjb.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
 end
 
--- cleanup process
-function luatexja.ext_cleanup()
-   ltjf.cleanup_size_cache(); ltjd.remove_end_whatsit()
-end
-
 -- lastnodechar
 do
    local id_glyph = node.id('glyph')