\newcount\ltj@tempcntb
\newcount\ltj@tempcntc
\newdimen\ltj@tempdima
-\newskip\ltj@tempskipa
-\newtoks\ltj@temptoks
+% \newskip\ltj@tempskipa unused
+% \newtoks\ltj@temptoks unused
\countdef\ltj@@count@zero=0 %
\luatexattributedef\ltj@@attr@zero=0 %
\def#1{\ltj@package@debug{#2}}
}
+%% \ltj@afterbox <token><box>
+%% -> \setbox\ltj@afbox<box><token>
+%% from Sonja Maus, ``Looking Ahead for a <box>'',
+%% TUGBoat, 11, No. 4, 1990.
+\newbox\ltj@afbox
+\protected\def\ltj@afterbox#1{%
+ \def\ltj@afb@xarg{#1}%
+ \afterassignment\ltj@afb@x
+ \chardef\next`.}
+\def\ltj@afb@x{\futurelet\next\ltj@afb@xtest}
+\def\ltj@afb@xtest{%
+ \ifcase\ifx\next\hbox\tw@\fi
+ \ifx\next\vbox\tw@\fi
+ \ifx\next\vtop\tw@\fi
+ \ifx\next\box\@ne\fi
+ \ifx\next\copy\@ne\fi
+ \ifx\next\vsplit\@ne\fi
+ \ifx\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@afb@xagarg{\aftergroup\ltj@afb@xarg}
+
+
%%------------------ all done
\ltj@base@AtEnd
\endinput
local function check_dir(reg_num)
start_time_measure('box_primitive_hook')
local list_dir = get_dir_count()
- local b = tex.getbox(tex_getcount('ltj@tempcnta'))
+ local b = getbox(tex_getcount('ltj@tempcnta'))
if b then
local box_dir = get_box_dir(to_direct(b), dir_yoko)
- if box_dir%dir_node_auto ~= list_dir%dir_node_auto then
- print('NEST', tex_nest.ptr, tex_getcount('ltj@tempcnta'))
- luatexja.ext_show_node_list(
- (tex_nest.ptr==0) and tex.lists.page_head or tex_nest[tex_nest.ptr].head,
- 'LIST' .. tostring(list_dir) .. '> ', print)
- luatexja.ext_show_node_list(b, 'BOX' .. tostring(box_dir) .. '> ', print)
+ if box_dir%dir_node_auto ~= list_dir then
+ -- print('NEST', tex_nest.ptr, tex_getcount('ltj@tempcnta'))
+ -- luatexja.ext_show_node_list(
+ -- (tex_nest.ptr==0) and tex.lists.page_head or tex_nest[tex_nest.ptr].head,
+ -- 'LIST' .. tostring(list_dir) .. '> ', print)
+ -- luatexja.ext_show_node_list(b, 'BOX' .. tostring(box_dir) .. '> ', print)
ltjb.package_error(
'luatexja',
"Incompatible direction list can't be unboxed",
'I refuse to unbox a box in differrent direction.')
end
end
- tex.globaldefs = luatexja.global_temp
+ if luatexja.global_temp and tex.globaldefs~=luatexja.global_temp then
+ tex.globaldefs = luatexja.global_temp
+ end
stop_time_measure('box_primitive_hook')
end
luatexja.direction.check_dir = check_dir
luatexja.direction.get_register_dir = get_register_dir
end
+-- raise, lower
+do
+ local getbox, setbox, copy_list = tex.getbox, tex.setbox, Dnode.copy_list
+ function luatexja.direction.raise_box()
+ start_time_measure('box_primitive_hook')
+ local list_dir = get_dir_count()
+ local s = getbox('ltj@afbox')
+ if s then
+ local sd = to_direct(s)
+ local box_dir = get_box_dir(sd, dir_yoko)
+ if box_dir%dir_node_auto ~= list_dir then
+ setbox(
+ 'ltj@afbox',
+ to_node(
+ copy_list(make_dir_whatsit(sd, sd, list_dir, 'box_move'))
+ -- without copy_list, we get a segfault
+ )
+ )
+ end
+ end
+ stop_time_measure('box_primitive_hook')
+ end
+end
+
-- 縦書き用字形への変換テーブル
local font_vert_table = {} -- key: fontnumber
do
set_stack_table(m+c, p)
end
--- EXT: store \ltj@tempskipa
+-- EXT: sp: glue_spec
function set_stack_skip(m,sp)
local i = get_stack_level()
if not sp then return end
\directlua{luatexja.direction.check_adjust_direction()}%
}
-%%%% hbox, vbox, vtop
+%%%% \hbox, \vbox, \vtop
\everyhbox{%
\directlua{luatexja.direction.set_list_direction()}%
\aftergroup\ltj@@reset@badness
}%
}
+%%%% \raise, \lower, \moveleft, \moveright
+\let\ltj@@orig@raise=\raise
+\let\ltj@@orig@lower=\lower
+\protected\def\raise{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima}
+\protected\def\lower{\ltj@reset@globaldefs\afterassignment\ltj@@raise\ltj@tempdima-}
+\protected\def\ltj@@raise{%
+ \ltj@restore@globaldefs
+ \edef\ltj@@raise@a{%
+ \noexpand\directlua{luatexja.direction.raise_box()}%
+ \ltj@@orig@raise\the\ltj@tempdima\noexpand\box\ltj@afbox
+ }\ltj@afterbox\ltj@@raise@a}
+\let\ltj@@orig@moveleft=\moveleft
+\let\ltj@@orig@moveright=\moveright
+\protected\def\moveleft{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima}
+\protected\def\moveright{\ltj@reset@globaldefs\afterassignment\ltj@@moveleft\ltj@tempdima-}
+\protected\def\ltj@@moveleft{%
+ \ltj@restore@globaldefs
+ \edef\ltj@@moveleft@a{%
+ \noexpand\directlua{luatexja.direction.raise_box()}%
+ \ltj@@orig@moveleft\the\ltj@tempdima\noexpand\box\ltj@afbox
+ }\ltj@afterbox\ltj@@moveleft@a}
+
%%%% unhbox and unvbox
\let\ltj@@orig@unhbox=\unhbox