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', nil)
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 not node_next(hd) and getid(hd)==id_whatsit and getsubtype(hd)==sid_user
133 and getfield(hd, 'user_id')==DIR then
134 -- avoid double whatsit
135 set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
136 tex_set_attr('global', attr_icflag, 0)
139 return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir))
143 luatexbase.add_to_callback('hpack_filter',
144 create_dir_whatsit_hpack, 'ltj.create_dir_whatsit', 10000)
148 local function create_dir_whatsit_parbox(h, gc)
149 stop_time_measure('tex_linebreak')
150 -- start 側は ltj-debug.lua に
151 local new_dir, hd = ltjs.list_dir, to_direct(h)
152 for line in traverse_id(id_hlist, hd) do
153 set_attr(line, attr_dir, new_dir)
155 tex_set_attr('global', attr_dir, 0)
156 return h --to_node(create_dir_whatsit(hd, gc, new_dir))
158 luatexbase.add_to_callback('post_linebreak_filter',
159 create_dir_whatsit_parbox, 'ltj.create_dir_whatsit', 10000)
162 local create_dir_whatsit_vbox
165 local id_glue, sid_parskip = node.id('glue'), 3
166 create_dir_whatsit_vbox = function (hd, gc)
167 ltjs.list_dir = get_dir_count()
168 -- remove dir whatsit
169 for x in traverse_id(id_whatsit, hd) do
170 if getsubtype(x)==sid_user and getfield(x, 'user_id')==DIR then
175 ltjs.list_dir =has_attr(hd,attr_dir)
176 local x = node_next(hd)
177 if getid(x)==id_glue and getsubtype(x)==sid_parskip then
178 node_remove(hd,x); node_free(x)
182 hd = node_remove(hd, wh[i]); node_free(wh[i]); wh[i] = nil
184 if gc=='fin_row' or gc == 'preamble' then
186 set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
187 tex_set_attr('global', attr_icflag, 0)
191 local n =node_next(hd)
192 if gc=='vtop' and n then
193 local w = create_dir_whatsit(hd, gc, ltjs.list_dir)
194 -- move dir whatsit after hd
195 setfield(hd, 'next', w); setfield(w, 'next', n)
198 return create_dir_whatsit(hd, gc, ltjs.list_dir)
204 -- dir_node に包む方法を書いたテーブル
207 local get_h =function (w,h,d) return h end
208 local get_d =function (w,h,d) return d end
209 local get_h_d =function (w,h,d) return h+d end
210 local get_h_d_neg =function (w,h,d) return -h-d end
211 local get_h_neg =function (w,h,d) return -h end
212 local get_d_neg =function (w,h,d) return -d end
213 local get_w_half =function (w,h,d) return 0.5*w end
214 local get_w_neg_half =function (w,h,d) return -0.5*w end
215 local get_w_neg =function (w,h,d) return -w end
216 local get_w =function (w,h,d) return w end
217 local zero = function() return 0 end
219 [dir_yoko] = { -- yoko を
220 [dir_tate] = { -- tate 中で組む
225 { 'whatsit', sid_save },
226 { 'rotate', '0 1 -1 0' },
227 { 'kern', get_w_neg_half },
229 { 'kern', get_w_neg_half },
230 { 'whatsit', sid_restore },
233 { 'whatsit', sid_save },
234 { 'rotate', '0 1 -1 0' },
236 { 'box' , get_w_neg },
237 { 'kern', get_h_d_neg},
238 { 'whatsit', sid_restore },
241 [dir_dtou] = { -- dtou 中で組む
246 { 'whatsit', sid_save },
247 { 'rotate', '0 -1 1 0' },
248 { 'kern', get_w_neg },
249 { 'box', get_d_neg },
250 { 'whatsit', sid_restore },
253 { 'whatsit', sid_save },
254 { 'rotate', '0 -1 1 0' },
255 { 'kern', get_h_d_neg },
257 { 'whatsit', sid_restore },
261 [dir_tate] = { -- tate を
262 [dir_yoko] = { -- yoko 中で組む
267 { 'whatsit', sid_save },
268 { 'rotate', '0 -1 1 0' },
269 { 'kern', get_w_neg },
270 { 'box' , get_d_neg },
271 { 'whatsit', sid_restore },
274 { 'whatsit', sid_save },
275 { 'rotate', '0 -1 1 0' },
276 { 'kern', get_h_d_neg },
278 { 'whatsit', sid_restore },
281 [dir_dtou] = { -- dtou 中で組む
286 { 'whatsit', sid_save },
287 { 'rotate', '-1 0 0 -1' },
288 { 'kern', get_w_neg },
290 { 'whatsit', sid_restore },
293 { 'whatsit', sid_save },
294 { 'rotate', '-1 0 0 -1' },
295 { 'kern', get_h_d_neg },
296 { 'box', get_w_neg },
297 { 'whatsit', sid_restore },
301 [dir_dtou] = { -- dtou を
302 [dir_yoko] = { -- yoko 中で組む
307 { 'whatsit', sid_save },
308 { 'rotate', '0 1 -1 0' },
311 { 'kern', get_w_neg },
312 { 'whatsit', sid_restore },
316 { 'whatsit', sid_save },
317 { 'rotate', '0 1 -1 0' },
318 { 'box', get_w_neg },
319 { 'kern', get_h_d_neg },
320 { 'whatsit', sid_restore },
323 [dir_tate] = { -- tate 中で組む
328 { 'whatsit', sid_save },
329 { 'rotate', '-1 0 0 -1' },
330 { 'kern', get_w_neg },
332 { 'whatsit', sid_restore },
335 { 'whatsit', sid_save },
336 { 'rotate', ' -1 0 0 -1' },
337 { 'kern', get_h_d_neg },
338 { 'box', get_w_neg },
339 { 'whatsit', sid_restore },
346 -- b に DIR whatsit があればその内容を attr_dir にうつす (1st ret val)
347 -- 2nd ret val はその DIR whatsit
348 local function get_box_dir(b, default)
349 start_time_measure('get_box_dir')
350 local dir = has_attr(b, attr_dir) or 0
351 local bh = getfield(b,'head')
352 -- b は insert node となりうるので getlist() は使えない
355 if bh and getid(bh)==id_whatsit
356 and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then
359 dir = has_attr(bh, attr_dir)
360 set_attr(b, attr_dir, dir)
361 tex_set_attr('global', attr_dir, 0)
366 stop_time_measure('get_box_dir')
367 return (dir==0 and default or dir), c
371 local getbox = tex.getbox
372 local function check_dir(reg_num)
373 start_time_measure('box_primitive_hook')
374 local list_dir = get_dir_count()
375 local b = tex.getbox(tex_getcount('ltj@tempcnta'))
377 local box_dir = get_box_dir(to_direct(b), dir_yoko)
378 if box_dir%dir_node_auto ~= list_dir%dir_node_auto then
381 "Incompatible direction list can't be unboxed",
382 'I refuse to unbox a box in differrent direction.')
385 stop_time_measure('box_primitive_hook')
387 luatexja.direction.check_dir = check_dir
390 -- dir_node に包まれている「本来の中身」を取り出し,
392 local function unwrap_dir_node(b, head, box_dir)
393 -- b: dir_node, head: the head of list, box_dir:
394 -- return values are (new head), (next of b), (contents), (dir of contents)
395 local bh = getlist(b)
396 local bc = node_next(node_next(node_next(bh)))
401 nh = insert_before(head, b, bc)
402 nh, nb = node_remove(nh, b)
403 setfield(b, 'next', nil)
404 setfield(b, 'head', nil)
407 local shift_old, b_dir, wh = nil, get_box_dir(bc, 0)
409 Dnode.flush_list(getfield(wh, 'value'))
410 setfield(wh, 'value', nil)
413 local info = dir_node_aux[b_dir][box_dir%dir_node_auto][getid(bc)]
414 for _,v in ipairs(info) do
417 getfield(bc,'width'), getfield(bc, 'height'), getfield(bc, 'depth'))
421 setfield(bc, 'shift', getfield(bc, 'shift') - shift_old)
422 return nh, nb, bc, b_dir
425 -- is_manual: 寸法変更に伴うものか?
426 local function create_dir_node(b, b_dir, new_dir, is_manual)
427 local info = dir_node_aux[b_dir][new_dir]
428 local w = getfield(b, 'width')
429 local h = getfield(b, 'height')
430 local d = getfield(b, 'depth')
431 local db = node_new(getid(b))
432 set_attr(db, attr_dir,
433 new_dir + (is_manual and dir_node_manual or dir_node_auto))
434 tex_set_attr('global', attr_dir, 0)
435 set_attr(db, attr_icflag, PROCESSED)
436 set_attr(b, attr_icflag, PROCESSED)
437 setfield(db, 'dir', getfield(b, 'dir'))
438 setfield(db, 'shift', 0)
439 setfield(db, 'width', info.width(w,h,d))
440 setfield(db, 'height', info.height(w,h,d))
441 setfield(db, 'depth', info.depth(w,h,d))
446 local make_dir_whatsit, process_dir_node
448 make_dir_whatsit = function (head, b, new_dir, origin)
449 -- head: list head, b: box
450 -- origin: コール元 (for debug)
451 -- return value: (new head), (next of b), (new b), (is_b_dir_node)
452 -- (new b): b か dir_node に被せられた b
453 local bh = getlist(b)
454 local box_dir, dn = get_box_dir(b, ltjs.list_dir)
455 -- 既に b の中身にあるwhatsit
456 if box_dir==new_dir then
457 return head, node_next(b), b, false
458 elseif box_dir%dir_node_auto == new_dir then
459 local bc = node_next(node_next(node_next(bh)))
460 local _, dnc = get_box_dir(b, 0)
461 if dnc then -- free all other dir_node
462 Dnode.flush_list(getfield(dnc, 'value'))
463 setfield(dnc, 'value', nil)
465 set_attr(b, attr_dir, box_dir%dir_node_auto + dir_node_auto)
466 return head, node_next(b), b, true
468 local nh, nb, ret, flag
469 if box_dir>= dir_node_auto then -- unwrap
471 head, nb, b, b_dir = unwrap_dir_node(b, head, box_dir)
473 if b_dir==new_dir then -- no need to create new dir_node
474 return head, nb, b, false
475 else box_dir = b_dir end
478 local dnh = getfield(dn, 'value')
479 for x in traverse(dnh) do
480 if has_attr(x, attr_dir)%dir_node_auto == new_dir then
481 setfield(dn, 'value', to_node(node_remove(dnh, x)))
485 Dnode.flush_list(dnh)
486 db = db or create_dir_node(b, box_dir, new_dir, false)
487 local w = getfield(b, 'width')
488 local h = getfield(b, 'height')
489 local d = getfield(b, 'depth')
490 nh, nb = insert_before(head, b, db), nil
491 nh, nb = node_remove(nh, b)
492 local db_head, db_tail = nil
493 for _,v in ipairs(dir_node_aux[box_dir][new_dir][getid(b)]) do
494 local cmd, arg, nn = v[1], v[2]
496 nn = node_new(id_kern)
497 setfield(nn, 'kern', arg(w, h, d))
498 elseif cmd=='whatsit' then
499 nn = node_new(id_whatsit, arg)
500 elseif cmd=='rotate' then
501 nn = node_new(id_whatsit, sid_matrix)
502 setfield(nn, 'data', arg)
503 elseif cmd=='box' then
504 nn = b; setfield(b, 'next', nil)
505 setfield(nn, 'shift', getfield(nn, 'shift') + arg(w,h,d))
508 insert_after(db_head, db_tail, nn)
511 db_head, db_tail = nn, nn
513 setfield(db, 'head', db_head)
516 return nh, nb, ret, flag
519 process_dir_node = function (hd, gc)
520 local x, new_dir = hd, ltjs.list_dir or dir_yoko
523 if (xid==id_hlist and has_attr(x, attr_icflag)%PROCESSED_BEGIN_FLAG~=PACKED)
524 or xid==id_vlist then
525 hd, x = make_dir_whatsit(hd, x, new_dir, 'process_dir_node:' .. gc)
534 local node_prev = (Dnode~=node) and Dnode.getprev or node.prev
535 local function lastbox_hook()
536 start_time_measure('box_primitive_hook')
537 local bn = tex_nest[tex_nest.ptr].tail
539 local b, head = to_direct(bn), to_direct(tex_nest[tex_nest.ptr].head)
541 if bid==id_hlist or bid==id_vlist then
542 local box_dir = get_box_dir(b, 0)
543 if box_dir>= dir_node_auto then -- unwrap
544 local p = node_prev(b)
545 local dummy1, dummy2, nb = unwrap_dir_node(b, nil, box_dir)
546 setfield(p, 'next', nb); tex_nest[tex_nest.ptr].tail = to_node(nb)
547 setfield(b, 'next', nil); setfield(b, 'head', nil)
552 stop_time_measure('box_primitive_hook')
555 luatexja.direction.make_dir_whatsit = make_dir_whatsit
556 luatexja.direction.lastbox_hook = lastbox_hook
559 -- \wd, \ht, \dp の代わり
561 local getbox, setdimen = tex.getbox, tex.setdimen
562 local function get_box_dim_common(key, s, l_dir)
563 local s_dir, wh = get_box_dir(s, dir_yoko)
564 if s_dir ~= l_dir then
565 local not_found = true
566 for x in traverse(getfield(wh, 'value')) do
567 if l_dir == has_attr(x, attr_dir)%dir_node_auto then
568 setdimen('ltj@tempdima', getfield(x, key))
569 not_found = false; break
573 local w = getfield(s, 'width')
574 local h = getfield(s, 'height')
575 local d = getfield(s, 'depth')
576 setdimen('ltj@tempdima',
577 dir_node_aux[s_dir][l_dir][key](w,h,d))
580 setdimen('ltj@tempdima', getfield(s, key))
583 local function get_box_dim(key, n)
584 local gt = tex.globaldefs; tex.globaldefs = 0
587 local l_dir = get_dir_count()
589 local b_dir = has_attr(s, attr_dir) or 0
590 if b_dir<dir_node_auto then
591 get_box_dim_common(key, s, l_dir)
592 elseif b_dir%dir_node_auto==l_dir then
593 setdimen('ltj@tempdima', getfield(s, key))
595 get_box_dim_common(key,
596 node_next(node_next(node_next(getlist(s)))), l_dir)
599 setdimen('ltj@tempdima', 0)
603 luatexja.direction.get_box_dim = get_box_dim
605 -- return value: (changed dimen of box itself?)
606 local function set_box_dim_common(key, s, l_dir)
607 local s_dir, wh = get_box_dir(s, dir_yoko)
608 if s_dir ~= l_dir then
610 wh = create_dir_whatsit(getlist(s), 'set_box_dim', s_dir)
611 setfield(s, 'head', wh)
614 local dnh = getfield(wh, 'value')
615 for x in traverse(dnh) do
616 if has_attr(x, attr_dir)%dir_node_auto==l_dir then
621 db = create_dir_node(s, s_dir, l_dir, true)
622 setfield(db, 'next', dnh)
623 setfield(wh, 'value',to_node(db))
625 setfield(db, key, tex.getdimen('ltj@tempdima'))
628 setfield(s, key, tex.getdimen('ltj@tempdima'))
630 -- change dimension of dir_nodes which are created "automatically"
632 = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
633 for x in traverse(getfield(wh, 'value')) do
634 local x_dir = has_attr(x, attr_dir)
635 if x_dir<dir_node_manual then
636 local info = dir_node_aux[s_dir][x_dir%dir_node_auto]
637 setfield(x, 'width', info.width(bw,bh,bd))
638 setfield(x, 'height', info.height(bw,bh,bd))
639 setfield(x, 'depth', info.depth(bw,bh,bd))
646 local function set_box_dim(key)
647 local n = tex_getcount('ltj@tempcnta')
650 local l_dir = get_dir_count()
652 local b_dir = has_attr(s, attr_dir) or 0
653 if b_dir<dir_node_auto then
654 set_box_dim_common(key, s, l_dir)
655 elseif b_dir%dir_node_auto == l_dir then
656 setfield(s, key, tex.getdimen('ltj@tempdima'))
657 if b_dir<dir_node_manual then
658 set_attr(s, attr_dir, b_dir%dir_node_auto + dir_node_manual)
661 local sid, sl = getid(s), getlist(s)
662 local b = node_next(node_next(node_next(sl)))
663 local info = dir_node_aux[get_box_dir(b)][b_dir%dir_node_auto]
665 for _,v in ipairs(info[sid]) do
668 getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth'))
672 if set_box_dim_common(key, b, l_dir) then
674 = getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth')
675 -- re-calculate shift
676 for i,v in ipairs(info[sid]) do
677 if getid(sl)==id_kern then
678 setfield(sl, 'kern', v[2](bw,bh,bd) )
679 elseif getid(sl)==sid then
680 local d = getfield(sl, 'shift')
681 setfield(sl, 'shift',
682 getfield(sl, 'shift') - shift_old + v[2](bw,bh,bd) )
686 -- re-calculate dimension of s, if s is created "automatically"
687 if b_dir<dir_node_manual then
688 setfield(s, 'width', info.width(bw,bh,bd))
689 setfield(s, 'height', info.height(bw,bh,bd))
690 setfield(s, 'depth', info.depth(bw,bh,bd))
696 luatexja.direction.set_box_dim = set_box_dim
699 -- \ifydir, \iftdir, \ifddir
701 local cat_lp = luatexbase.catcodetables['latex-package']
702 local getbox = tex.getbox
703 local function dir_conditional(n, mode)
708 local b_dir = get_box_dir(s, dir_yoko)
709 if b_dir<dir_node_auto then
712 local b_dir = get_box_dir(
713 node_next(node_next(node_next(getlist(s)))), dir_yoko)
717 tex.sprint(cat_lp, '\\if' .. tostring(res))
719 luatexja.direction.dir_conditional = dir_conditional
723 local font_vert_table = {} -- key: fontnumber
725 local font_vert_basename = {} -- key: basename
726 local function add_feature_table(tname, src, dest)
727 for i,v in pairs(src) do
728 if type(v.slookups)=='table' then
729 local s = v.slookups[tname]
730 if s and not dest[i] then
737 local function prepare_vert_data(n, id)
738 -- test if already loaded
739 if type(id)=='number' then -- sometimes id is an integer
740 font_vert_table[n] = font_vert_table[id]; return
741 elseif (not id) or font_vert_table[n] then return
743 local fname = id.filename
744 local bname = file.basename(fname)
746 font_vert_table[n] = {}; return
747 elseif font_vert_basename[bname] then
748 font_vert_table[n] = font_vert_basename[bname]; return
751 local a = id.resources.sequences
753 local s = id.shared.rawdata.descriptions
754 for i,v in pairs(a) do
755 if v.features.vert or v.features.vrt2 then
756 add_feature_table(v.subtables[1], s, vtable)
760 font_vert_basename[bname] = vtable
761 font_vert_table[n] = vtable
764 function luatexja.direction.get_vert_glyph(n, chr)
765 local fn = font_vert_table[n]
766 return fn and fn[chr] or chr
768 luatexbase.add_to_callback('luatexja.define_font',
769 function (res, name, size, id)
770 prepare_vert_data(id, res)
772 'prepare_vert_data', 1)
774 local function a (n, dat) font_vert_table[n] = dat end
775 luatexja.rmlgbm.vert_addfunc = a
779 -- PACKED の hbox から文字を取り出す
780 -- luatexja.jfmglue.check_box などで使用
782 local function glyph_from_packed(h)
784 return (getid(b)==id_kern)
785 and node_next(node_next(node_next(node_next(b)))) or b
787 luatexja.direction.glyph_from_packed = glyph_from_packed
790 -- adjust and insertion
791 local id_adjust = node.id('adjust')
792 function luatexja.direction.check_adjust_direction()
793 start_time_measure('box_primitive_hook')
794 local list_dir = tex_getcount('ltj@adjdir@count')
795 local a = tex_nest[tex_nest.ptr].tail
796 local ad = to_direct(a)
797 if a and getid(ad)==id_adjust then
798 local adj_dir = get_box_dir(ad)
799 if list_dir~=adj_dir then
802 'Direction Incompatible',
803 "\\vadjust's argument and outer vlist must have same direction.")
807 stop_time_measure('box_primitive_hook')
812 local split_dir_whatsit
813 local function dir_adjust_vpack(h, gc)
814 start_time_measure('direction_vpack')
815 local hd = to_direct(h)
816 if gc=='split_keep' then
817 -- supply dir_whatsit
818 hd = create_dir_whatsit_vbox(hd, gc)
819 split_dir_whatsit = hd
820 elseif gc=='split_off' then
823 if bh and getid(bh)==id_whatsit
824 and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR then
825 ltjs.list_dir = has_attr(bh, attr_dir); break
829 if split_dir_whatsit then
830 -- adjust direction of 'split_keep'
831 set_attr(split_dir_whatsit, attr_dir, ltjs.list_dir)
832 tex_set_attr('global', attr_dir, 0)
834 split_dir_whatsit=nil
836 hd = process_dir_node(create_dir_whatsit_vbox(hd, gc), gc)
837 split_dir_whatsit=nil
839 stop_time_measure('direction_vpack')
842 luatexbase.add_to_callback('vpack_filter',
844 'ltj.direction', 10000)
848 -- supply direction whatsit to the main vertical list "of the next page"
849 local function dir_adjust_pre_output(h, gc)
850 return to_node(create_dir_whatsit_vbox(to_direct(h), gc))
852 luatexbase.add_to_callback('pre_output_filter',
853 dir_adjust_pre_output,
854 'ltj.direction', 10000)
856 function luatexja.direction.remove_end_whatsit()
857 local h=tex.lists.page_head
859 h.id==id_whatsit and h.subtype==sid_user and
860 h.user_id == DIR then
861 tex.lists.page_head = nil
869 local function dir_adjust_buildpage(info)
871 local head = to_direct(tex.lists.contrib_head)
874 = make_dir_whatsit(head,
878 tex.lists.contrib_head = to_node(head)
881 luatexbase.add_to_callback('buildpage_filter',
882 dir_adjust_buildpage,
883 'ltj.direction', 10000)