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_getcount = tex.getcount
46 local tex_set_attr = tex.setattribute
47 local PROCESSED = luatexja.icflag_table.PROCESSED
48 local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG
49 local PACKED = luatexja.icflag_table.PACKED
50 local STCK = luatexja.userid_table.STCK
51 local DIR = luatexja.userid_table.DIR
52 local dir_tate = luatexja.dir_table.dir_tate
53 local dir_yoko = luatexja.dir_table.dir_yoko
54 local dir_dtou = luatexja.dir_table.dir_dtou
55 local dir_node_auto = luatexja.dir_table.dir_node_auto
56 local dir_node_manual = luatexja.dir_table.dir_node_manual
62 function get_dir_count()
63 return tex_getcount('ltj@dir@count')
65 luatexja.direction.get_dir_count = get_dir_count
67 local node_next = node.next
68 local node_set_attr = node.set_attribute
69 local function set_list_direction(v, name)
70 local lv, w = tex.nest[tex.nest.ptr], tex.lists.page_head
71 if lv.mode == 1 and w then
72 if w.id==id_whatsit and w.subtype==sid_user
73 and w.user_id==DIR then
74 node_set_attr(w, attr_dir, v)
77 local w = node_next(lv.head)
80 if getid(w)==id_whatsit and getsubtype(w)==sid_user
81 and getfield(w, 'user_id')==DIR then
82 set_attr(w, attr_dir, v)
86 "Use `\\" .. name .. "' at top of list",
87 'Direction change command by LuaTeX-ja is available\n'
88 .. 'only when the current list is null.')
91 local w = node_new(id_whatsit, sid_user)
92 setfield(w, 'next', hd)
93 setfield(w, 'user_id', DIR)
94 setfield(w, 'type', 110)
95 set_attr(w, attr_dir, v)
98 tex_set_attr('global', attr_icflag, 0)
100 tex_set_attr('global', attr_dir, 0)
102 luatexja.direction.set_list_direction = set_list_direction
105 function luatexja.direction.freeze_list_dir()
106 local w = to_direct(tex.nest[tex.nest.ptr].tail)
107 set_attr(w, attr_dir, -has_attr(w, attr_dir))
110 -- ボックスに dir whatsit を追加
111 local function create_dir_whatsit(hd, gc, new_dir)
112 local w = node_new(id_whatsit, sid_user)
113 setfield(w, 'next', hd)
114 setfield(w, 'user_id', DIR)
115 setfield(w, 'type', 110)
116 set_attr(w, attr_dir, new_dir)
117 tex_set_attr('global', attr_dir, 0)
118 set_attr(w, attr_icflag, PROCESSED_BEGIN_FLAG)
119 set_attr(hd, attr_icflag, (has_attr(hd, attr_icflag) or 0) + PROCESSED_BEGIN_FLAG)
120 tex_set_attr('global', attr_icflag, 0)
124 -- hpack_filter, vpack_filter, post_line_break_filter
125 -- の結果を組方向を明示するため,先頭に dir_node を設置
127 local function create_dir_whatsit_hpack(h, gc)
128 local hd = to_direct(h)
129 if gc=='fin_row' or gc == 'preamble' then
131 set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
132 tex_set_attr('global', attr_icflag, 0)
136 return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir))
140 luatexbase.add_to_callback('hpack_filter',
141 create_dir_whatsit_hpack, 'ltj.create_dir_whatsit', 10000)
144 local id_glue, sid_parskip = node.id('glue'), 3
145 local function create_dir_whatsit_vbox(h, gc)
146 local hd = to_direct(h)
147 ltjs.list_dir = get_dir_count()
148 -- remove dir whatsit
149 for x in traverse_id(id_whatsit, hd) do
150 if getsubtype(x)==sid_user and getfield(x, 'user_id')==DIR then
155 ltjs.list_dir =has_attr(hd,attr_dir)
156 local x = node_next(hd)
157 if getid(x)==id_glue and getsubtype(x)==sid_parskip then
158 node_remove(hd,x); node_free(x)
161 for i=1,#wh do hd = node_remove(hd, wh[i]); node_free(wh[i]); wh[i] = nil end
162 if gc=='fin_row' or gc == 'preamble' then
164 set_attr(hd, attr_icflag, PROCESSED_BEGIN_FLAG)
165 tex_set_attr('global', attr_icflag, 0)
168 elseif gc=='vtop' then
169 local w = create_dir_whatsit(hd, gc, ltjs.list_dir)
170 -- move dir whatsit after hd
171 local n = getfield(hd, 'next')
172 setfield(hd, 'next', w); setfield(w, 'next', n)
175 return to_node(create_dir_whatsit(hd, gc, ltjs.list_dir))
178 luatexbase.add_to_callback('vpack_filter',
179 create_dir_whatsit_vbox, 'ltj.create_dir_whatsit', 1)
181 local function create_dir_whatsit_parbox(h, gc)
182 stop_time_measure('tex_linebreak')
183 -- start 側は ltj-debug.lua に
184 local new_dir, hd = ltjs.list_dir, to_direct(h)
185 for line in traverse_id(id_hlist, hd) do
186 set_attr(line, attr_dir, new_dir)
188 tex_set_attr('global', attr_dir, 0)
189 return to_node(create_dir_whatsit(hd, gc, new_dir))
191 luatexbase.add_to_callback('post_linebreak_filter',
192 create_dir_whatsit_parbox, 'ltj.create_dir_whatsit', 10000)
196 -- dir_node に包む方法を書いたテーブル
199 local get_h =function (w,h,d) return h end
200 local get_d =function (w,h,d) return d end
201 local get_h_d =function (w,h,d) return h+d end
202 local get_h_d_neg =function (w,h,d) return -h-d end
203 local get_h_neg =function (w,h,d) return -h end
204 local get_d_neg =function (w,h,d) return -d end
205 local get_w_half =function (w,h,d) return 0.5*w end
206 local get_w_neg_half =function (w,h,d) return -0.5*w end
207 local get_w_neg =function (w,h,d) return -w end
208 local get_w =function (w,h,d) return w end
209 local zero = function() return 0 end
211 [dir_yoko] = { -- yoko を
212 [dir_tate] = { -- tate 中で組む
217 { 'whatsit', sid_save },
218 { 'rotate', '0 1 -1 0' },
219 { 'kern', get_w_neg_half },
221 { 'kern', get_w_neg_half },
222 { 'whatsit', sid_restore },
225 { 'whatsit', sid_save },
226 { 'rotate', '0 1 -1 0' },
228 { 'box' , get_w_neg },
229 { 'kern', get_h_d_neg},
230 { 'whatsit', sid_restore },
233 [dir_dtou] = { -- dtou 中で組む
238 { 'whatsit', sid_save },
239 { 'rotate', '0 -1 1 0' },
240 { 'kern', get_w_neg },
241 { 'box', get_d_neg },
242 { 'whatsit', sid_restore },
245 { 'whatsit', sid_save },
246 { 'rotate', '0 -1 1 0' },
247 { 'kern', get_h_d_neg },
249 { 'whatsit', sid_restore },
253 [dir_tate] = { -- tate を
254 [dir_yoko] = { -- yoko 中で組む
259 { 'whatsit', sid_save },
260 { 'rotate', '0 -1 1 0' },
261 { 'kern', get_w_neg },
262 { 'box' , get_d_neg },
263 { 'whatsit', sid_restore },
266 { 'whatsit', sid_save },
267 { 'rotate', '0 -1 1 0' },
268 { 'kern', get_h_d_neg },
270 { 'whatsit', sid_restore },
273 [dir_dtou] = { -- dtou 中で組む
278 { 'whatsit', sid_save },
279 { 'rotate', '-1 0 0 -1' },
280 { 'kern', get_w_neg },
282 { 'whatsit', sid_restore },
285 { 'whatsit', sid_save },
286 { 'rotate', '-1 0 0 -1' },
287 { 'kern', get_h_d_neg },
288 { 'box', get_w_neg },
289 { 'whatsit', sid_restore },
293 [dir_dtou] = { -- dtou を
294 [dir_yoko] = { -- yoko 中で組む
299 { 'whatsit', sid_save },
300 { 'rotate', '0 1 -1 0' },
303 { 'kern', get_w_neg },
304 { 'whatsit', sid_restore },
308 { 'whatsit', sid_save },
309 { 'rotate', '0 1 -1 0' },
310 { 'box', get_w_neg },
311 { 'kern', get_h_d_neg },
312 { 'whatsit', sid_restore },
315 [dir_tate] = { -- tate 中で組む
320 { 'whatsit', sid_save },
321 { 'rotate', '-1 0 0 -1' },
322 { 'kern', get_w_neg },
324 { 'whatsit', sid_restore },
327 { 'whatsit', sid_save },
328 { 'rotate', ' -1 0 0 -1' },
329 { 'kern', get_h_d_neg },
330 { 'box', get_w_neg },
331 { 'whatsit', sid_restore },
338 -- b に DIR whatsit があればその内容を attr_dir にうつす (1st ret val)
339 -- 2nd ret val はその DIR whatsit
340 local function get_box_dir(b, default)
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 return (dir==0 and default or dir), c
360 function luatexja.direction.check_dir(reg_num)
361 local list_dir = get_dir_count()
362 local b = tex.getbox(reg_num)
364 local box_dir = get_box_dir(to_direct(b), dir_yoko)
365 if box_dir%dir_node_auto ~= list_dir%dir_node_auto then
368 "Incompatible direction list can't be unboxed",
369 'I refuse to unbox a box in differrent direction.')
374 -- dir_node に包まれている「本来の中身」を取り出し,
376 local function unwrap_dir_node(b, head, box_dir)
377 -- b: dir_node, head: the head of list, box_dir:
378 -- return values are (new head), (next of b), (contents), (dir of contents)
379 local bh = getlist(b)
380 local bc = node_next(node_next(node_next(bh)))
385 nh = insert_before(head, b, bc)
386 nh, nb = node_remove(nh, b)
387 setfield(b, 'next', nil)
388 setfield(b, 'head', nil)
391 local shift_old, b_dir, wh = nil, get_box_dir(bc, 0)
393 Dnode.flush_list(getfield(wh, 'value'))
394 setfield(wh, 'value', nil)
397 local info = dir_node_aux[b_dir][box_dir%dir_node_auto][getid(bc)]
398 for _,v in ipairs(info) do
401 getfield(bc,'width'), getfield(bc, 'height'), getfield(bc, 'depth'))
405 setfield(bc, 'shift', getfield(bc, 'shift') - shift_old)
406 return nh, nb, bc, b_dir
409 -- is_manual: 寸法変更に伴うものか?
410 local function create_dir_node(b, b_dir, new_dir, is_manual)
411 local info = dir_node_aux[b_dir][new_dir]
412 local w = getfield(b, 'width')
413 local h = getfield(b, 'height')
414 local d = getfield(b, 'depth')
415 local db = node_new(getid(b))
416 set_attr(db, attr_dir,
417 new_dir + (is_manual and dir_node_manual or dir_node_auto))
418 tex_set_attr('global', attr_dir, 0)
419 set_attr(db, attr_icflag, PROCESSED)
420 set_attr(b, attr_icflag, PROCESSED)
421 setfield(db, 'dir', getfield(b, 'dir'))
422 setfield(db, 'shift', 0)
423 setfield(db, 'width', info.width(w,h,d))
424 setfield(db, 'height', info.height(w,h,d))
425 setfield(db, 'depth', info.depth(w,h,d))
430 local make_dir_whatsit
432 make_dir_whatsit = function (head, b, new_dir, origin)
433 -- head: list head, b: box
434 -- origin: コール元 (for debug)
435 -- return value: (new head), (next of b), (new b), (is_b_dir_node)
436 -- (new b): b か dir_node に被せられた b
437 local bh = getlist(b)
438 local box_dir, dn = get_box_dir(b, ltjs.list_dir)
439 -- 既に b の中身にあるwhatsit
440 if box_dir==new_dir then
441 return head, node_next(b), b, false
442 elseif box_dir%dir_node_auto == new_dir then
443 local bc = node_next(node_next(node_next(bh)))
444 local _, dnc = get_box_dir(b, 0)
445 if dnc then -- free all other dir_node
446 Dnode.flush_list(getfield(dnc, 'value'))
447 setfield(dnc, 'value', nil)
449 set_attr(b, attr_dir, box_dir%dir_node_auto + dir_node_auto)
450 return head, node_next(b), b, true
452 local nh, nb, ret, flag
453 if box_dir>= dir_node_auto then -- unwrap
455 head, nb, b, b_dir = unwrap_dir_node(b, head, box_dir)
457 if b_dir==new_dir then -- no need to create new dir_node
458 return head, nb, b, false
459 else box_dir = b_dir end
462 local dnh = getfield(dn, 'value')
463 for x in traverse(dnh) do
464 if has_attr(x, attr_dir)%dir_node_auto == new_dir then
465 setfield(dn, 'value', to_node(node_remove(dnh, x)))
469 Dnode.flush_list(dnh)
470 db = db or create_dir_node(b, box_dir, new_dir, false)
471 local w = getfield(b, 'width')
472 local h = getfield(b, 'height')
473 local d = getfield(b, 'depth')
474 nh, nb = insert_before(head, b, db), nil
475 nh, nb = node_remove(nh, b)
476 local db_head, db_tail = nil
477 for _,v in ipairs(dir_node_aux[box_dir][new_dir][getid(b)]) do
478 local cmd, arg, nn = v[1], v[2]
480 nn = node_new(id_kern)
481 setfield(nn, 'kern', arg(w, h, d))
482 elseif cmd=='whatsit' then
483 nn = node_new(id_whatsit, arg)
484 elseif cmd=='rotate' then
485 nn = node_new(id_whatsit, sid_matrix)
486 setfield(nn, 'data', arg)
487 elseif cmd=='box' then
488 nn = b; setfield(b, 'next', nil)
489 setfield(nn, 'shift', getfield(nn, 'shift') + arg(w,h,d))
492 insert_after(db_head, db_tail, nn)
495 db_head, db_tail = nn, nn
498 setfield(db, 'head', db_head)
501 return nh, nb, ret, flag
504 local function process_dir_node(head, gc)
505 start_time_measure('direction_vpack')
506 local h = to_direct(head)
507 local x, new_dir = h, ltjs.list_dir or dir_yoko
510 if (xid==id_hlist and has_attr(x, attr_icflag)%PROCESSED_BEGIN_FLAG~=PACKED)
511 or xid==id_vlist then
512 h, x = make_dir_whatsit(h, x, new_dir, 'process_dir_node:' .. gc)
517 stop_time_measure('direction_vpack')
520 luatexja.direction.make_dir_whatsit = make_dir_whatsit
521 luatexbase.add_to_callback('vpack_filter',
522 process_dir_node, 'ltj.dir_whatsit', 10001)
525 -- \wd, \ht, \dp の代わり
527 local getbox, setdimen = tex.getbox, tex.setdimen
528 local function get_box_dim_common(key, s, l_dir)
529 local s_dir, wh = get_box_dir(s, dir_yoko)
530 if s_dir ~= l_dir then
531 local not_found = true
532 for x in traverse(getfield(wh, 'value')) do
533 if l_dir == has_attr(x, attr_dir)%dir_node_auto then
534 setdimen('ltj@tempdima', getfield(x, key))
535 not_found = false; break
539 local w = getfield(s, 'width')
540 local h = getfield(s, 'height')
541 local d = getfield(s, 'depth')
542 setdimen('ltj@tempdima',
543 dir_node_aux[s_dir][l_dir][key](w,h,d))
546 setdimen('ltj@tempdima', getfield(s, key))
549 local function get_box_dim(key, n)
550 local gt = tex.globaldefs; tex.globaldefs = 0
553 local l_dir = get_dir_count()
555 local b_dir = has_attr(s, attr_dir) or 0
556 if b_dir<dir_node_auto then
557 get_box_dim_common(key, s, l_dir)
558 elseif b_dir%dir_node_auto==l_dir then
559 setdimen('ltj@tempdima', getfield(s, key))
561 get_box_dim_common(key,
562 node_next(node_next(node_next(getlist(s)))), l_dir)
565 setdimen('ltj@tempdima', 0)
569 luatexja.direction.get_box_dim = get_box_dim
571 -- return value: (changed dimen of box itself?)
572 local function set_box_dim_common(key, s, l_dir)
573 local s_dir, wh = get_box_dir(s, dir_yoko)
574 if s_dir ~= l_dir then
576 wh = create_dir_whatsit(getlist(s), 'set_box_dim', s_dir)
577 setfield(s, 'head', wh)
580 local dnh = getfield(wh, 'value')
581 for x in traverse(dnh) do
582 if has_attr(x, attr_dir)%dir_node_auto==l_dir then
587 db = create_dir_node(s, s_dir, l_dir, true)
588 setfield(db, 'next', dnh)
589 setfield(wh, 'value',to_node(db))
591 setfield(db, key, tex.getdimen('ltj@tempdima'))
594 setfield(s, key, tex.getdimen('ltj@tempdima'))
596 -- change dimension of dir_nodes which are created "automatically"
598 = getfield(s,'width'), getfield(s, 'height'), getfield(s, 'depth')
599 for x in traverse(getfield(wh, 'value')) do
600 local x_dir = has_attr(x, attr_dir)
601 if x_dir<dir_node_manual then
602 local info = dir_node_aux[s_dir][x_dir%dir_node_auto]
603 setfield(x, 'width', info.width(bw,bh,bd))
604 setfield(x, 'height', info.height(bw,bh,bd))
605 setfield(x, 'depth', info.depth(bw,bh,bd))
612 local function set_box_dim(key)
613 local n = tex_getcount('ltj@tempcnta')
616 local l_dir = get_dir_count()
618 local b_dir = has_attr(s, attr_dir) or 0
619 if b_dir<dir_node_auto then
620 set_box_dim_common(key, s, l_dir)
621 elseif b_dir%dir_node_auto == l_dir then
622 setfield(s, key, tex.getdimen('ltj@tempdima'))
623 if b_dir<dir_node_manual then
624 set_attr(s, attr_dir, b_dir%dir_node_auto + dir_node_manual)
627 local sid, sl = getid(s), getlist(s)
628 local b = node_next(node_next(node_next(sl)))
629 local info = dir_node_aux[get_box_dir(b)][b_dir%dir_node_auto]
631 for _,v in ipairs(info[sid]) do
634 getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth'))
638 if set_box_dim_common(key, b, l_dir) then
640 = getfield(b,'width'), getfield(b, 'height'), getfield(b, 'depth')
641 -- re-calculate shift
642 for i,v in ipairs(info[sid]) do
643 if getid(sl)==id_kern then
644 setfield(sl, 'kern', v[2](bw,bh,bd) )
645 elseif getid(sl)==sid then
646 local d = getfield(sl, 'shift')
647 setfield(sl, 'shift',
648 getfield(sl, 'shift') - shift_old + v[2](bw,bh,bd) )
652 -- re-calculate dimension of s, if s is created "automatically"
653 if b_dir<dir_node_manual then
654 setfield(s, 'width', info.width(bw,bh,bd))
655 setfield(s, 'height', info.height(bw,bh,bd))
656 setfield(s, 'depth', info.depth(bw,bh,bd))
662 luatexja.direction.set_box_dim = set_box_dim
665 -- \ifydir, \iftdir, \ifddir
667 local cat_lp = luatexbase.catcodetables['latex-package']
668 local getbox = tex.getbox
669 local function dir_conditional(n, mode)
674 local b_dir = get_box_dir(s, dir_yoko)
675 if b_dir<dir_node_auto then
678 local b_dir = get_box_dir(
679 node_next(node_next(node_next(getlist(s)))), dir_yoko)
683 tex.sprint(cat_lp, '\\if' .. tostring(res))
685 luatexja.direction.dir_conditional = dir_conditional
689 local font_vert_table = {} -- key: fontnumber
691 local font_vert_basename = {} -- key: basename
692 local function add_feature_table(tname, src, dest)
693 for i,v in pairs(src) do
694 if type(v.slookups)=='table' then
695 local s = v.slookups[tname]
696 if s and not dest[i] then
703 local function prepare_vert_data(n, id)
704 -- test if already loaded
705 if type(id)=='number' then -- sometimes id is an integer
706 font_vert_table[n] = font_vert_table[id]; return
707 elseif (not id) or font_vert_table[n] then return
709 local fname = id.filename
710 local bname = file.basename(fname)
712 font_vert_table[n] = {}; return
713 elseif font_vert_basename[bname] then
714 font_vert_table[n] = font_vert_basename[bname]; return
717 local a = id.resources.sequences
719 local s = id.shared.rawdata.descriptions
720 for i,v in pairs(a) do
721 if v.features.vert or v.features.vrt2 then
722 add_feature_table(v.subtables[1], s, vtable)
726 font_vert_basename[bname] = vtable
727 font_vert_table[n] = vtable
730 function luatexja.direction.get_vert_glyph(n, chr)
731 local fn = font_vert_table[n]
732 return fn and fn[chr] or chr
734 luatexbase.add_to_callback('luatexja.define_font',
735 function (res, name, size, id)
736 prepare_vert_data(id, res)
738 'prepare_vert_data', 1)
740 local function a (n, dat) font_vert_table[n] = dat end
741 luatexja.rmlgbm.vert_addfunc = a
745 -- PACKED の hbox から文字を取り出す
746 -- luatexja.jfmglue.check_box などで使用
748 local function glyph_from_packed(h)
750 return (getid(b)==id_kern)
751 and node_next(node_next(node_next(node_next(b)))) or b
753 luatexja.direction.glyph_from_packed = glyph_from_packed
756 -- adjust and insertion
757 local id_adjust = node.id('adjust')
758 function luatexja.direction.check_adjust_direction()
759 local list_dir = tex_getcount('ltj@adjdir@count')
760 local a = tex.nest[tex.nest.ptr].tail
761 local ad = to_direct(a)
762 if a and getid(ad)==id_adjust then
763 local adj_dir = get_box_dir(ad)
764 if list_dir~=adj_dir then
767 'Direction Incompatible',
768 "\\vadjust's argument and outer vlist must have same direction.")