2 -- src/ltj-direction.lua
5 luatexja.load_module('base'); local ltjb = luatexja.base
6 luatexja.load_module('stack'); local ltjs = luatexja.stack
7 luatexja.load_module('rmlgbm'); local ltjr = luatexja.rmlgbm
8 luatexja.direction = {}
10 local attr_dir = luatexbase.attributes['ltj@dir']
11 local attr_icflag = luatexbase.attributes['ltj@icflag']
13 local Dnode = node.direct or node
14 local nullfunc = function (n) return n end
15 local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
16 local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
17 local has_attr = Dnode.has_attribute
18 local set_attr = Dnode.set_attribute
19 local insert_before = Dnode.insert_before
20 local insert_after = Dnode.insert_after
21 local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end
22 local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end
23 local getlist = (Dnode ~= node) and Dnode.getlist or function(n) return n.head end
24 local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end
25 local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end
26 local node_new = Dnode.new
27 local node_tail = Dnode.tail
28 local node_free = Dnode.free
29 local node_remove = Dnode.remove
30 local node_next = (Dnode ~= node) and Dnode.getnext or node.next
31 local traverse = Dnode.traverse
32 local traverse_id = Dnode.traverse_id
33 local start_time_measure, stop_time_measure
34 = ltjb.start_time_measure, ltjb.stop_time_measure
36 local id_kern = node.id('kern')
37 local id_hlist = node.id('hlist')
38 local id_vlist = node.id('vlist')
39 local id_whatsit = node.id('whatsit')
40 local sid_save = node.subtype('pdf_save')
41 local sid_restore = node.subtype('pdf_restore')
42 local sid_matrix = node.subtype('pdf_setmatrix')
43 local sid_user = node.subtype('user_defined')
45 local tex_nest = tex.nest
46 local tex_getcount = tex.getcount
47 local tex_set_attr = tex.setattribute
48 local PROCESSED = luatexja.icflag_table.PROCESSED
49 local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG
50 local PACKED = luatexja.icflag_table.PACKED
51 local STCK = luatexja.userid_table.STCK
52 local DIR = luatexja.userid_table.DIR
53 local dir_tate = luatexja.dir_table.dir_tate
54 local dir_yoko = luatexja.dir_table.dir_yoko
55 local dir_dtou = luatexja.dir_table.dir_dtou
56 local dir_node_auto = luatexja.dir_table.dir_node_auto
57 local dir_node_manual = luatexja.dir_table.dir_node_manual
63 function get_dir_count()
64 return tex_getcount('ltj@dir@count')
66 luatexja.direction.get_dir_count = get_dir_count
68 local node_next = node.next
69 local node_set_attr = node.set_attribute
70 local function set_list_direction(v, name)
71 local lv, w = tex_nest[tex_nest.ptr], tex.lists.page_head
72 if lv.mode == 1 and w then
73 if w.id==id_whatsit and w.subtype==sid_user
74 and w.user_id==DIR then
75 node_set_attr(w, attr_dir, v)
78 local w = node_next(lv.head)
81 if getid(w)==id_whatsit and getsubtype(w)==sid_user
82 and getfield(w, 'user_id')==DIR then
83 set_attr(w, attr_dir, v)
87 "Use `\\" .. name .. "' at top of list",
88 'Direction change command by LuaTeX-ja is available\n'
89 .. 'only when the current list is null.')
92 local w = node_new(id_whatsit, sid_user)
93 setfield(w, 'next', hd)
94 setfield(w, 'user_id', DIR)
95 setfield(w, 'type', 110)
96 set_attr(w, attr_dir, v)
99 tex_set_attr('global', attr_icflag, 0)
101 tex_set_attr('global', attr_dir, 0)
103 luatexja.direction.set_list_direction = set_list_direction
106 -- ボックスに dir whatsit を追加
107 local function create_dir_whatsit(hd, gc, new_dir)
108 local w = node_new(id_whatsit, sid_user)
109 setfield(w, 'next', hd)
110 setfield(w, 'user_id', DIR)
111 setfield(w, 'type', 110)
112 set_attr(w, attr_dir, new_dir)
113 tex_set_attr('global', attr_dir, 0)
114 set_attr(w, attr_icflag, PROCESSED_BEGIN_FLAG)
115 set_attr(hd, attr_icflag, (has_attr(hd, attr_icflag) or 0) + PROCESSED_BEGIN_FLAG)
116 tex_set_attr('global', attr_icflag, 0)
120 -- hpack_filter, vpack_filter, post_line_break_filter
121 -- の結果を組方向を明示するため,先頭に dir_node を設置
123 local function create_dir_whatsit_hpack(h, gc)
124 local hd = to_direct(h)
125 if gc=='fin_row' or gc == 'preamble' then
127 set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
128 tex_set_attr('global', attr_icflag, 0)
132 return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir))
136 luatexbase.add_to_callback('hpack_filter',
137 create_dir_whatsit_hpack, 'ltj.create_dir_whatsit', 10000)
141 local function create_dir_whatsit_parbox(h, gc)
142 stop_time_measure('tex_linebreak')
143 -- start 側は ltj-debug.lua に
144 local new_dir, hd = ltjs.list_dir, to_direct(h)
145 for line in traverse_id(id_hlist, hd) do
146 set_attr(line, attr_dir, new_dir)
148 tex_set_attr('global', attr_dir, 0)
149 return to_node(create_dir_whatsit(hd, gc, new_dir))
151 luatexbase.add_to_callback('post_linebreak_filter',
152 create_dir_whatsit_parbox, 'ltj.create_dir_whatsit', 10000)
155 local create_dir_whatsit_vbox
158 local id_glue, sid_parskip = node.id('glue'), 3
159 create_dir_whatsit_vbox = function (hd, gc)
160 ltjs.list_dir = get_dir_count()
161 -- remove dir whatsit
162 for x in traverse_id(id_whatsit, hd) do
163 if getsubtype(x)==sid_user and getfield(x, 'user_id')==DIR then
168 ltjs.list_dir =has_attr(hd,attr_dir)
169 local x = node_next(hd)
170 if getid(x)==id_glue and getsubtype(x)==sid_parskip then
171 node_remove(hd,x); node_free(x)
175 hd = node_remove(hd, wh[i]); node_free(wh[i]); wh[i] = nil
177 if gc=='fin_row' or gc == 'preamble' then
179 set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
180 tex_set_attr('global', attr_icflag, 0)
183 elseif gc=='vtop' then
184 local w = create_dir_whatsit(hd, gc, ltjs.list_dir)
185 -- move dir whatsit after hd
186 local n = getfield(hd, 'next')
187 setfield(hd, 'next', w); setfield(w, 'next', n)
190 return create_dir_whatsit(hd, gc, ltjs.list_dir)
195 -- dir_node に包む方法を書いたテーブル
198 local get_h =function (w,h,d) return h end
199 local get_d =function (w,h,d) return d end
200 local get_h_d =function (w,h,d) return h+d end
201 local get_h_d_neg =function (w,h,d) return -h-d end
202 local get_h_neg =function (w,h,d) return -h end
203 local get_d_neg =function (w,h,d) return -d end
204 local get_w_half =function (w,h,d) return 0.5*w end
205 local get_w_neg_half =function (w,h,d) return -0.5*w end
206 local get_w_neg =function (w,h,d) return -w end
207 local get_w =function (w,h,d) return w end
208 local zero = function() return 0 end
210 [dir_yoko] = { -- yoko を
211 [dir_tate] = { -- tate 中で組む
216 { 'whatsit', sid_save },
217 { 'rotate', '0 1 -1 0' },
218 { 'kern', get_w_neg_half },
220 { 'kern', get_w_neg_half },
221 { 'whatsit', sid_restore },
224 { 'whatsit', sid_save },
225 { 'rotate', '0 1 -1 0' },
227 { 'box' , get_w_neg },
228 { 'kern', get_h_d_neg},
229 { 'whatsit', sid_restore },
232 [dir_dtou] = { -- dtou 中で組む
237 { 'whatsit', sid_save },
238 { 'rotate', '0 -1 1 0' },
239 { 'kern', get_w_neg },
240 { 'box', get_d_neg },
241 { 'whatsit', sid_restore },
244 { 'whatsit', sid_save },
245 { 'rotate', '0 -1 1 0' },
246 { 'kern', get_h_d_neg },
248 { 'whatsit', sid_restore },
252 [dir_tate] = { -- tate を
253 [dir_yoko] = { -- yoko 中で組む
258 { 'whatsit', sid_save },
259 { 'rotate', '0 -1 1 0' },
260 { 'kern', get_w_neg },
261 { 'box' , get_d_neg },
262 { 'whatsit', sid_restore },
265 { 'whatsit', sid_save },
266 { 'rotate', '0 -1 1 0' },
267 { 'kern', get_h_d_neg },
269 { 'whatsit', sid_restore },
272 [dir_dtou] = { -- dtou 中で組む
277 { 'whatsit', sid_save },
278 { 'rotate', '-1 0 0 -1' },
279 { 'kern', get_w_neg },
281 { 'whatsit', sid_restore },
284 { 'whatsit', sid_save },
285 { 'rotate', '-1 0 0 -1' },
286 { 'kern', get_h_d_neg },
287 { 'box', get_w_neg },
288 { 'whatsit', sid_restore },
292 [dir_dtou] = { -- dtou を
293 [dir_yoko] = { -- yoko 中で組む
298 { 'whatsit', sid_save },
299 { 'rotate', '0 1 -1 0' },
302 { 'kern', get_w_neg },
303 { 'whatsit', sid_restore },
307 { 'whatsit', sid_save },
308 { 'rotate', '0 1 -1 0' },
309 { 'box', get_w_neg },
310 { 'kern', get_h_d_neg },
311 { 'whatsit', sid_restore },
314 [dir_tate] = { -- tate 中で組む
319 { 'whatsit', sid_save },
320 { 'rotate', '-1 0 0 -1' },
321 { 'kern', get_w_neg },
323 { 'whatsit', sid_restore },
326 { 'whatsit', sid_save },
327 { 'rotate', ' -1 0 0 -1' },
328 { 'kern', get_h_d_neg },
329 { 'box', get_w_neg },
330 { 'whatsit', sid_restore },
337 -- b に DIR whatsit があればその内容を attr_dir にうつす (1st ret val)
338 -- 2nd ret val はその DIR whatsit
339 local function get_box_dir(b, default)
340 start_time_measure('get_box_dir')
341 local dir = has_attr(b, attr_dir) or 0
342 local bh = getfield(b,'head')
343 -- b は insert node となりうるので getlist() は使えない
346 if bh and getid(bh)==id_whatsit
347 and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then
350 dir = has_attr(bh, attr_dir)
351 set_attr(b, attr_dir, dir)
352 tex_set_attr('global', attr_dir, 0)
357 stop_time_measure('get_box_dir')
358 return (dir==0 and default or dir), c
362 local getbox = tex.getbox
363 local function check_dir(reg_num)
364 start_time_measure('box_primitive_hook')
365 local list_dir = get_dir_count()
366 local b = tex.getbox(tex_getcount('ltj@tempcnta'))
368 local box_dir = get_box_dir(to_direct(b), dir_yoko)
369 if box_dir%dir_node_auto ~= list_dir%dir_node_auto then
370 --print('unbox', reg_num, box_dir, list_dir)
373 "Incompatible direction list can't be unboxed",
374 'I refuse to unbox a box in differrent direction.')
377 stop_time_measure('box_primitive_hook')
379 luatexja.direction.check_dir = check_dir
382 -- dir_node に包まれている「本来の中身」を取り出し,
384 local function unwrap_dir_node(b, head, box_dir)
385 -- b: dir_node, head: the head of list, box_dir:
386 -- return values are (new head), (next of b), (contents), (dir of contents)
387 local bh = getlist(b)
388 local bc = node_next(node_next(node_next(bh)))
393 nh = insert_before(head, b, bc)
394 nh, nb = node_remove(nh, b)
395 setfield(b, 'next', nil)
396 setfield(b, 'head', nil)
399 local shift_old, b_dir, wh = nil, get_box_dir(bc, 0)
401 Dnode.flush_list(getfield(wh, 'value'))
402 setfield(wh, 'value', nil)
405 local info = dir_node_aux[b_dir][box_dir%dir_node_auto][getid(bc)]
406 for _,v in ipairs(info) do
409 getfield(bc,'width'), getfield(bc, 'height'), getfield(bc, 'depth'))
413 setfield(bc, 'shift', getfield(bc, 'shift') - shift_old)
414 return nh, nb, bc, b_dir
417 -- is_manual: 寸法変更に伴うものか?
418 local function create_dir_node(b, b_dir, new_dir, is_manual)
419 local info = dir_node_aux[b_dir][new_dir]
420 local w = getfield(b, 'width')
421 local h = getfield(b, 'height')
422 local d = getfield(b, 'depth')
423 local db = node_new(getid(b))
424 set_attr(db, attr_dir,
425 new_dir + (is_manual and dir_node_manual or dir_node_auto))
426 tex_set_attr('global', attr_dir, 0)
427 set_attr(db, attr_icflag, PROCESSED)
428 set_attr(b, attr_icflag, PROCESSED)
429 setfield(db, 'dir', getfield(b, 'dir'))
430 setfield(db, 'shift', 0)
431 setfield(db, 'width', info.width(w,h,d))
432 setfield(db, 'height', info.height(w,h,d))
433 setfield(db, 'depth', info.depth(w,h,d))
438 local make_dir_whatsit, process_dir_node
440 make_dir_whatsit = function (head, b, new_dir, origin)
441 -- head: list head, b: box
442 -- origin: コール元 (for debug)
443 -- return value: (new head), (next of b), (new b), (is_b_dir_node)
444 -- (new b): b か dir_node に被せられた b
445 local bh = getlist(b)
446 local box_dir, dn = get_box_dir(b, ltjs.list_dir)
447 -- 既に b の中身にあるwhatsit
448 if box_dir==new_dir then
449 return head, node_next(b), b, false
450 elseif box_dir%dir_node_auto == new_dir then
451 local bc = node_next(node_next(node_next(bh)))
452 local _, dnc = get_box_dir(b, 0)
453 if dnc then -- free all other dir_node
454 Dnode.flush_list(getfield(dnc, 'value'))
455 setfield(dnc, 'value', nil)
457 set_attr(b, attr_dir, box_dir%dir_node_auto + dir_node_auto)
458 return head, node_next(b), b, true
460 local nh, nb, ret, flag
461 if box_dir>= dir_node_auto then -- unwrap
463 head, nb, b, b_dir = unwrap_dir_node(b, head, box_dir)
465 if b_dir==new_dir then -- no need to create new dir_node
466 return head, nb, b, false
467 else box_dir = b_dir end
470 local dnh = getfield(dn, 'value')
471 for x in traverse(dnh) do
472 if has_attr(x, attr_dir)%dir_node_auto == new_dir then
473 setfield(dn, 'value', to_node(node_remove(dnh, x)))
477 Dnode.flush_list(dnh)
478 db = db or create_dir_node(b, box_dir, new_dir, false)
479 local w = getfield(b, 'width')
480 local h = getfield(b, 'height')
481 local d = getfield(b, 'depth')
482 nh, nb = insert_before(head, b, db), nil
483 nh, nb = node_remove(nh, b)
484 local db_head, db_tail = nil
485 for _,v in ipairs(dir_node_aux[box_dir][new_dir][getid(b)]) do
486 local cmd, arg, nn = v[1], v[2]
488 nn = node_new(id_kern)
489 setfield(nn, 'kern', arg(w, h, d))
490 elseif cmd=='whatsit' then
491 nn = node_new(id_whatsit, arg)
492 elseif cmd=='rotate' then
493 nn = node_new(id_whatsit, sid_matrix)
494 setfield(nn, 'data', arg)
495 elseif cmd=='box' then
496 nn = b; setfield(b, 'next', nil)
497 setfield(nn, 'shift', getfield(nn, 'shift') + arg(w,h,d))
500 insert_after(db_head, db_tail, nn)
503 db_head, db_tail = nn, nn
505 setfield(db, 'head', db_head)
508 return nh, nb, ret, flag
511 process_dir_node = function (hd, gc)
512 local x, new_dir = hd, ltjs.list_dir or dir_yoko
515 if (xid==id_hlist and has_attr(x, attr_icflag)%PROCESSED_BEGIN_FLAG~=PACKED)
516 or xid==id_vlist then
517 hd, x = make_dir_whatsit(hd, x, new_dir, 'process_dir_node:' .. gc)
526 local node_prev = (Dnode~=node) and Dnode.getprev or node.prev
527 local function lastbox_hook()
528 start_time_measure('box_primitive_hook')
529 local bn = tex_nest[tex_nest.ptr].tail
531 local b, head = to_direct(bn), to_direct(tex_nest[tex_nest.ptr].head)
533 if bid==id_hlist or bid==id_vlist then
534 local box_dir = get_box_dir(b, 0)
535 if box_dir>= dir_node_auto then -- unwrap
536 local p = node_prev(b)
537 local dummy1, dummy2, nb = unwrap_dir_node(b, nil, box_dir)
538 setfield(p, 'next', nb); tex_nest[tex_nest.ptr].tail = to_node(nb)
539 setfield(b, 'next', nil); setfield(b, 'head', nil)
544 stop_time_measure('box_primitive_hook')
547 luatexja.direction.make_dir_whatsit = make_dir_whatsit
548 luatexja.direction.lastbox_hook = lastbox_hook
551 -- \wd, \ht, \dp の代わり
553 local getbox, setdimen = tex.getbox, tex.setdimen
554 local function get_box_dim_common(key, s, l_dir)
555 local s_dir, wh = get_box_dir(s, dir_yoko)
556 if s_dir ~= l_dir then
557 local not_found = true
558 for x in traverse(getfield(wh, 'value')) do
559 if l_dir == has_attr(x, attr_dir)%dir_node_auto then
560 setdimen('ltj@tempdima', getfield(x, key))
561 not_found = false; break
565 local w = getfield(s, 'width')
566 local h = getfield(s, 'height')
567 local d = getfield(s, 'depth')
568 setdimen('ltj@tempdima',
569 dir_node_aux[s_dir][l_dir][key](w,h,d))
572 setdimen('ltj@tempdima', getfield(s, key))
575 local function get_box_dim(key, n)
576 local gt = tex.globaldefs; tex.globaldefs = 0
579 local l_dir = get_dir_count()
581 local b_dir = has_attr(s, attr_dir) or 0
582 if b_dir<dir_node_auto then
583 get_box_dim_common(key, s, l_dir)
584 elseif b_dir%dir_node_auto==l_dir then
585 setdimen('ltj@tempdima', getfield(s, key))
587 get_box_dim_common(key,
588 node_next(node_next(node_next(getlist(s)))), l_dir)
591 setdimen('ltj@tempdima', 0)
595 luatexja.direction.get_box_dim = get_box_dim
597 -- return value: (changed dimen of box itself?)
598 local function set_box_dim_common(key, s, l_dir)
599 local s_dir, wh = get_box_dir(s, dir_yoko)
600 if s_dir ~= l_dir then
602 wh = create_dir_whatsit(getlist(s), 'set_box_dim', s_dir)
603 setfield(s, 'head', wh)
606 local dnh = getfield(wh, 'value')
607 for x in traverse(dnh) do
608 if has_attr(x, attr_dir)%dir_node_auto==l_dir then
613 db = create_dir_node(s, s_dir, l_dir, true)
614 setfield(db, 'next', dnh)
615 setfield(wh, 'value',to_node(db))
617 setfield(db, key, tex.getdimen('ltj@tempdima'))
620 setfield(s, key, tex.getdimen('ltj@tempdima'))
622 -- change dimension of dir_nodes which are created "automatically"
624 = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
625 for x in traverse(getfield(wh, 'value')) do
626 local x_dir = has_attr(x, attr_dir)
627 if x_dir<dir_node_manual then
628 local info = dir_node_aux[s_dir][x_dir%dir_node_auto]
629 setfield(x, 'width', info.width(bw,bh,bd))
630 setfield(x, 'height', info.height(bw,bh,bd))
631 setfield(x, 'depth', info.depth(bw,bh,bd))
638 local function set_box_dim(key)
639 local n = tex_getcount('ltj@tempcnta')
642 local l_dir = get_dir_count()
644 local b_dir = has_attr(s, attr_dir) or 0
645 if b_dir<dir_node_auto then
646 set_box_dim_common(key, s, l_dir)
647 elseif b_dir%dir_node_auto == l_dir then
648 setfield(s, key, tex.getdimen('ltj@tempdima'))
649 if b_dir<dir_node_manual then
650 set_attr(s, attr_dir, b_dir%dir_node_auto + dir_node_manual)
653 local sid, sl = getid(s), getlist(s)
654 local b = node_next(node_next(node_next(sl)))
655 local info = dir_node_aux[get_box_dir(b)][b_dir%dir_node_auto]
657 for _,v in ipairs(info[sid]) do
660 getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth'))
664 if set_box_dim_common(key, b, l_dir) then
666 = getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth')
667 -- re-calculate shift
668 for i,v in ipairs(info[sid]) do
669 if getid(sl)==id_kern then
670 setfield(sl, 'kern', v[2](bw,bh,bd) )
671 elseif getid(sl)==sid then
672 local d = getfield(sl, 'shift')
673 setfield(sl, 'shift',
674 getfield(sl, 'shift') - shift_old + v[2](bw,bh,bd) )
678 -- re-calculate dimension of s, if s is created "automatically"
679 if b_dir<dir_node_manual then
680 setfield(s, 'width', info.width(bw,bh,bd))
681 setfield(s, 'height', info.height(bw,bh,bd))
682 setfield(s, 'depth', info.depth(bw,bh,bd))
688 luatexja.direction.set_box_dim = set_box_dim
691 -- \ifydir, \iftdir, \ifddir
693 local cat_lp = luatexbase.catcodetables['latex-package']
694 local getbox = tex.getbox
695 local function dir_conditional(n, mode)
700 local b_dir = get_box_dir(s, dir_yoko)
701 if b_dir<dir_node_auto then
704 local b_dir = get_box_dir(
705 node_next(node_next(node_next(getlist(s)))), dir_yoko)
709 tex.sprint(cat_lp, '\\if' .. tostring(res))
711 luatexja.direction.dir_conditional = dir_conditional
715 local font_vert_table = {} -- key: fontnumber
717 local font_vert_basename = {} -- key: basename
718 local function add_feature_table(tname, src, dest)
719 for i,v in pairs(src) do
720 if type(v.slookups)=='table' then
721 local s = v.slookups[tname]
722 if s and not dest[i] then
729 local function prepare_vert_data(n, id)
730 -- test if already loaded
731 if type(id)=='number' then -- sometimes id is an integer
732 font_vert_table[n] = font_vert_table[id]; return
733 elseif (not id) or font_vert_table[n] then return
735 local fname = id.filename
736 local bname = file.basename(fname)
738 font_vert_table[n] = {}; return
739 elseif font_vert_basename[bname] then
740 font_vert_table[n] = font_vert_basename[bname]; return
743 local a = id.resources.sequences
745 local s = id.shared.rawdata.descriptions
746 for i,v in pairs(a) do
747 if v.features.vert or v.features.vrt2 then
748 add_feature_table(v.subtables[1], s, vtable)
752 font_vert_basename[bname] = vtable
753 font_vert_table[n] = vtable
756 function luatexja.direction.get_vert_glyph(n, chr)
757 local fn = font_vert_table[n]
758 return fn and fn[chr] or chr
760 luatexbase.add_to_callback('luatexja.define_font',
761 function (res, name, size, id)
762 prepare_vert_data(id, res)
764 'prepare_vert_data', 1)
766 local function a (n, dat) font_vert_table[n] = dat end
767 luatexja.rmlgbm.vert_addfunc = a
771 -- PACKED の hbox から文字を取り出す
772 -- luatexja.jfmglue.check_box などで使用
774 local function glyph_from_packed(h)
776 return (getid(b)==id_kern)
777 and node_next(node_next(node_next(node_next(b)))) or b
779 luatexja.direction.glyph_from_packed = glyph_from_packed
782 -- adjust and insertion
783 local id_adjust = node.id('adjust')
784 function luatexja.direction.check_adjust_direction()
785 start_time_measure('box_primitive_hook')
786 local list_dir = tex_getcount('ltj@adjdir@count')
787 local a = tex_nest[tex_nest.ptr].tail
788 local ad = to_direct(a)
789 if a and getid(ad)==id_adjust then
790 local adj_dir = get_box_dir(ad)
791 if list_dir~=adj_dir then
794 'Direction Incompatible',
795 "\\vadjust's argument and outer vlist must have same direction.")
799 stop_time_measure('box_primitive_hook')
804 local split_dir_whatsit
805 local function dir_adjust_vpack(h, gc)
806 start_time_measure('direction_vpack')
807 local hd = to_direct(h)
808 if gc=='split_keep' then
809 -- supply dir_whatsit
810 hd = create_dir_whatsit_vbox(hd, gc)
811 split_dir_whatsit = hd
812 elseif gc=='split_off' then
815 if bh and getid(bh)==id_whatsit
816 and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then
817 ltjs.list_dir = has_attr(bh, attr_dir); break
821 if split_dir_whatsit then
822 -- adjust direction of 'split_keep'
823 set_attr(split_dir_whatsit, attr_dir, ltjs.list_dir)
824 tex_set_attr('global', attr_dir, 0)
826 split_dir_whatsit=nil
828 hd = process_dir_node(create_dir_whatsit_vbox(hd, gc), gc)
829 split_dir_whatsit=nil
831 stop_time_measure('direction_vpack')
834 luatexbase.add_to_callback('vpack_filter',
836 'ltj.direction', 10000)
840 local function dir_adjust_pre_output(h, gc)
841 return to_node(create_dir_whatsit_vbox(to_direct(h), gc))
843 luatexbase.add_to_callback('pre_output_filter',
844 dir_adjust_pre_output,
845 'ltj.direction', 10000)