Debian Codegraph @

texmf-dist/doc/luatex/barracuda/test/test-ga-pdfliteral/001-ga-pdfliteral-test.tex

raw
1 % !TeX program = LuaTeX
2 % test for ga-canvas pdfliteral driver
3 %
4 % Copyright (C) 2019-2022 Roberto Giacomelli
5 % see LICENSE.txt file
6
7 ---ga--- is a binary format as an istruction set similar to
8 a sort of assembler language that describes simple graphic
9 objects like lines and rectangles.
10 This file contains tests aiming to check the pdfliteral
11 driver capability to render such ga streams---usually a Lua
12 array.
13
14 The pdfliteral driver directly inserts PDF vector graphic
15 primitives within the output and should be intented as the
16 "native" driver of barracuda package.
17
18 The complete reference of the ---ga--- format is available
19 throgh out the content of the "ga-grammar.tex" file.
20
21 Please note that all dimensions are in scaled point, the
22 very small \TeX{} internal unit, in fact we have that
23 65536sp = 1pt.
24
25 Running the source file with luatex. The typesetting engine
26 executes the directlua macro, so vector graphics appear in
27 the PDF output file.
28
29 \newbox\mybox
30 \directlua{
31 brcd = require "barracuda"
32 driver = brcd:get_driver() % global Lua variables
33 pt = tex.sp [[1pt]] % 1pt = 65536sp
34 }
35
36 Let's start drawing an horizontal line 100pt long:
37 \directlua{
38 local ga = {33, 0*pt, 100*pt, 0*pt}
39 driver:ga_to_hbox(ga, [[mybox]])
40 }\box\mybox
41
42 or two different parallel lines 24pt long:
43 \directlua{
44 local ga = {33, 0*pt, 24*pt, 0*pt, 33, 0*pt, 24*pt, 5*pt}
45 driver:ga_to_hbox(ga, [[mybox]])
46 }\box\mybox
47
48 and again two horizontal lines 10pt thick, touching a corner:
49 \directlua{
50 local ga = {
51 1, 10*pt,
52 33, -24*pt, 0*pt, -5*pt,
53 33, 0*pt, 24*pt, 5*pt,
54 }
55 driver:ga_to_hbox(ga, [[mybox]])
56 }\box\mybox
57
58 Several vertical lines with its horizontal limits:
59 \directlua{
60 local ga = {
61 34, -20*pt, 20*pt, 0*pt,
62 34, -15*pt, 15*pt, 5*pt,
63 34, -10*pt, 10*pt, 10*pt,
64 34, -5*pt, 5*pt, 15*pt,
65 34, -.5*pt, .5*pt, 20*pt,
66 34, -5*pt, 5*pt, 25*pt,
67 34, -10*pt, 10*pt, 30*pt,
68 34, -15*pt, 15*pt, 35*pt,
69 34, -20*pt, 20*pt, 40*pt,
70 1, .05*pt,
71 33, 0*pt, 40*pt, -20*pt,
72 33, 0*pt, 40*pt, 20*pt,
73 }
74 driver:ga_to_hbox(ga, [[mybox]])
75 }\box\mybox
76
77 Finally a little rectangle:
78 \directlua{
79 local ga = {
80 1, 5*pt,
81 48, 0*pt, 0*pt, 15*pt, 10*pt,
82 }
83 driver:ga_to_hbox(ga, [[mybox]])
84 }\box\mybox
85
86 \bigskip
87 Test number 1: a vbar 2pt width, 20pt height:
88 \directlua{
89 % vbar: <36> y1 y2 <nbars> x1 w1 x2 w2 ... xn wn
90 local ga = {36, 0, 20*pt, 1, 0.0, 2*pt}
91 driver:ga_to_hbox(ga, [[mybox]])
92 }\box\mybox
93
94 \bigskip
95 Test number 2: ten vbars in a row equally spaced by 10pt:
96 \directlua{
97 local ga = {36, 0, 10*pt, 10,}
98 for i = 0, 9 do
99 ga[i*2 + 5] = 5*pt + i*20*pt
100 ga[i*2 + 6] = 10*pt
101 end
102 driver:ga_to_hbox(ga, [[mybox]])
103 }\vrule\box\mybox\vrule
104
105 \bigskip
106 Test number 3: two series of vbars 10pt and 5pt large:
107 \directlua{
108 local ga = {36, 0, 10*pt, 10,}
109 for i = 0, 9 do
110 ga[i*2 + 5] = 5*pt + i*20*pt
111 ga[i*2 + 6] = 10*pt
112 end
113 ga[25] = 36 % vbar opcode
114 ga[26] = 2.5*pt % y1
115 ga[27] = 7.5*pt % y2
116 ga[28] = 9 % number of bars
117 for i = 0, 8 do
118 ga[i*2 + 29] = 15*pt + i*20*pt
119 ga[i*2 + 30] = 5*pt
120 end
121 driver:ga_to_hbox(ga, [[mybox]])
122 }\vrule\box\mybox\vrule
123
124 \bigskip
125 Test number 4: a bunch of thin vertical bars (25):
126 \directlua{
127 local ga = {}
128 ga[1] = 36 % vbar opcode
129 ga[2] = 5*pt % y1
130 ga[3] = 25*pt % y2
131 ga[4] = 25 % number of bars
132 for i = 0, 24 do
133 ga[i*2 + 5] = 1*pt + i*4*pt
134 ga[i*2 + 6] = 2*pt
135 end
136 driver:ga_to_hbox(ga, [[mybox]])
137 }\vrule A\box\mybox A\vrule
138
139 \bigskip
140 Test number 5: two rows of a bunch of thin bars:
141 \directlua{
142 local ga = {}
143 ga[1] = 36 % vbar opcode
144 ga[2] = 5*pt % y1
145 ga[3] = 25*pt % y2
146 ga[4] = 25 % number of bars
147 for i = 0, 24 do
148 ga[i*2 + 5] = 1*pt + i*4*pt
149 ga[i*2 + 6] = 2*pt
150 end
151 ga[55] = 36 % vbar opcode
152 ga[56] = 25*pt % y1
153 ga[57] = 45*pt % y2
154 ga[58] = 24 % number of bars
155 for i = 0, 23 do
156 ga[i*2 + 59] = 3*pt + i*4*pt
157 ga[i*2 + 60] = 2*pt
158 end
159 driver:ga_to_hbox(ga, [[mybox]])
160 }\vrule\box\mybox\vrule
161
162 \bigskip
163 Test number 6: staircase of Vbars (manually data definition):
164 \directlua{
165 local ga = {
166 36, % vbar opcode
167 0*pt, % y1
168 20*pt, % y2
169 1, % number of bars
170 5*pt, % x
171 10*pt, % w
172 36, % vbar opcode
173 20*pt, % y1
174 40*pt, % y2
175 1, % number of bars
176 15*pt, % x
177 10*pt, % w
178 36, % vbar opcode
179 40*pt, % y1
180 60*pt, % y2
181 1, % number of bars
182 25*pt, % x
183 10*pt, % w
184 }
185 driver:ga_to_hbox(ga, [[mybox]])
186 }\vrule\box\mybox\vrule
187
188 \bigskip
189 Test number 7: vbars with spaced text, in three different rows:
190 \directlua{
191 local ga = {}
192 ga[1] = 36 % vbar opcode
193 ga[2] = 0*pt % y1
194 ga[3] = 20*pt % y2
195 ga[4] = 8 % number of bars
196 for i = 1,8 do
197 ga[3 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
198 ga[4 + i*2] = 5*pt % bar width
199 end
200 ga[21] = 36 % vbar opcode
201 ga[22] = 30*pt % y1
202 ga[23] = 50*pt % y2
203 ga[24] = 8 % number of bars
204 for i = 1,8 do
205 ga[23 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
206 ga[24 + i*2] = 5*pt % bar width
207 end
208 % 131 <x1: FLOAT> <xgap: FLOAT> <ay: DIM> <ypos: DIM> <c: CHARS>
209 ga[41] = 131 % opcode text_xspaced
210 ga[42] = 10*pt % x coordinate of the first glyph axis
211 ga[43] = 10*pt % x gap among glyphs
212 ga[44] = 0.5 % half height
213 ga[45] = 25*pt % y coordinate of glyps
214 ga[46] = 65 % A
215 ga[47] = 66 % B
216 ga[48] = 67 % C
217 ga[49] = 68 % D
218 ga[50] = 69 % E
219 ga[51] = 70 % F
220 ga[52] = 71 % G
221 ga[53] = 72 % H
222 ga[54] = 0
223 driver:ga_to_hbox(ga, [[mybox]])
224 }\vrule\box\mybox\vrule
225
226 \bigskip
227 Test number 8: spaced text (checking the correct vertical alignment):
228 \directlua{
229 local ga = {}
230 ga[1] = 36 % vbar opcode
231 ga[2] = 0*pt % y1
232 ga[3] = 20*pt % y2
233 ga[4] = 8 % number of bars
234 for i = 1,8 do
235 ga[3 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
236 ga[4 + i*2] = 1*pt % bar width
237 end
238 ga[21] = 36 % vbar opcode
239 ga[22] = 40*pt % y1
240 ga[23] = 60*pt % y2
241 ga[24] = 8 % number of bars
242 for i = 1,8 do
243 ga[23 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
244 ga[24 + i*2] = 1*pt % bar width
245 end
246 % 131 <x1: FLOAT> <xgap: FLOAT> <ay: DIM> <ypos: DIM> <c: CHARS>
247 ga[41] = 131 % opcode text_xspaced
248 ga[42] = 10*pt % x coordinate of the first glyph axis
249 ga[43] = 10*pt % x gap among glyphs
250 ga[44] = 0.0 % half height
251 ga[45] = 30*pt % y coordinate of glyps
252 ga[46] = 65 % A
253 ga[47] = 66 % B
254 ga[48] = 67 % C
255 ga[49] = string.byte("Q")
256 ga[50] = 69 % E
257 ga[51] = 70 % F
258 ga[52] = 71 % G
259 ga[53] = 72 % H
260 ga[54] = 0
261 ga[55] = 131 % opcode text_xspaced
262 ga[56] = 10*pt % x coordinate of the first glyph axis
263 ga[57] = 10*pt % x gap among glyphs
264 ga[58] = 1.0 % half height
265 ga[59] = 30*pt % y coordinate of glyps
266 ga[60] = 49 % 1
267 ga[61] = 50 % 2
268 ga[62] = 51 % 3
269 ga[63] = 52 % 4
270 ga[64] = 53 % 5
271 ga[65] = 54 % 6
272 ga[66] = 55 % 7
273 ga[67] = 56 % 8
274 ga[68] = 0
275 driver:ga_to_hbox(ga, [[mybox]])
276 }\vrule\box\mybox\vrule
277
278 \bigskip
279 Test number 9: spaced text, check correct vertical alignment:
280 \directlua{
281 local ga = {}
282 ga[1] = 36 % vbar opcode
283 ga[2] = 0*pt % y1
284 ga[3] = 20*pt % y2
285 ga[4] = 8 % number of bars
286 for i = 1,8 do
287 ga[3 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
288 ga[4 + i*2] = 8*pt % bar width
289 end
290 ga[21] = 36 % vbar opcode
291 ga[22] = 40*pt % y1
292 ga[23] = 60*pt % y2
293 ga[24] = 8 % number of bars
294 for i = 1,8 do
295 ga[23 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
296 ga[24 + i*2] = 8*pt % bar width
297 end
298 % 131 <x1: FLOAT> <xgap: FLOAT> <ay: DIM> <ypos: DIM> <c: CHARS>
299 ga[41] = 131 % opcode text_xspaced
300 ga[42] = 10*pt % x coordinate of the first glyph axis
301 ga[43] = 10*pt % x gap among glyphs
302 ga[44] = 0.0 % half height
303 ga[45] = 20*pt % y coordinate of glyps
304 ga[46] = 65 % A
305 ga[47] = 66 % B
306 ga[48] = 67 % C
307 ga[49] = 68 % D
308 ga[50] = 69 % E
309 ga[51] = 70 % F
310 ga[52] = 71 % G
311 ga[53] = 72 % H
312 ga[54] = 0
313 ga[55] = 131 % opcode text_xspaced
314 ga[56] = 10*pt % x coordinate of the first glyph axis
315 ga[57] = 10*pt % x gap among glyphs
316 ga[58] = 1.0 % half height
317 ga[59] = 40*pt % y coordinate of glyps
318 ga[60] = 49 % 1
319 ga[61] = 50 % 2
320 ga[62] = 51 % 3
321 ga[63] = 52 % 4
322 ga[64] = 53 % 5
323 ga[65] = 54 % 6
324 ga[66] = 55 % 7
325 ga[67] = 56 % 8
326 ga[68] = 0
327 driver:ga_to_hbox(ga, [[mybox]])
328 }\vrule\box\mybox\vrule
329
330 \bigskip
331 Test number 10: two centered texts aligned to the baseline:
332 \directlua{
333 local ga = {}
334 % 130 <ax: FLOAT> <ay: FLOAT> <xpos: DIM> <ypos: DIM> <c: CHARS>
335 ga[ 1] = 130 % opcode text
336 ga[ 2] = 0.5 % ax relative x coordinate
337 ga[ 3] = 1.0 % ay relative y coordinate
338 ga[ 4] = 0.0 % x position
339 ga[ 5] = 0.0 % y position
340 ga[ 6] = 65 % A
341 ga[ 7] = string.byte("Q") % Q depth glyph
342 ga[ 8] = 67 % C
343 ga[ 9] = 0
344 ga[10] = 130 % opcode text
345 ga[11] = 0.5 % ax
346 ga[12] = 0.0 % ay
347 ga[13] = 0.0 % x
348 ga[14] = 0.0 % y
349 ga[15] = 48 % 0
350 ga[16] = 49 % 1
351 ga[17] = 50 % 2
352 ga[18] = 51 % 3
353 ga[19] = 52 % 4
354 ga[20] = 53 % 5
355 ga[21] = 54 % 6
356 ga[22] = 55 % 7
357 ga[23] = 56 % 8
358 ga[24] = 57 % 9
359 ga[25] = 0
360 driver:ga_to_hbox(ga, [[mybox]])
361 }\vrule\box\mybox\vrule
362
363 \bigskip
364 So far, we have manually build data for ga stream. For now on, we are going to
365 use the ga-canvas library.
366
367 \bigskip
368 In fact, all the previous tests are rebuild with the ga-canvas library.
369
370 Test 1: a vbar 2pt width, 20pt height:
371 \directlua{
372 local ga = brcd:new_canvas()
373 local vbar = {0.0, 2*pt}
374 assert(ga:encode_vbar(vbar, 0.0, 0.0, 20*pt)) % x, w
375 driver:ga_to_hbox(ga, [[mybox]])
376 }\box\mybox
377
378 \bigskip
379 Test 2: ten vbars equally spaced by 10pt:
380 \directlua{
381 local ga = brcd:new_canvas()
382 local bars = {}
383 for i = 0, 9 do
384 bars[i*2 + 1] = 5*pt + i*20*pt % x
385 bars[i*2 + 2] = 10*pt % w
386 end
387 assert(ga:encode_vbar(bars, 0.0, 0.0, 10*pt))
388 driver:ga_to_hbox(ga, [[mybox]])
389 }\vrule\box\mybox\vrule
390
391 \bigskip
392 Test 3: two series of vbars 10pt and 5pt large:
393 \directlua{
394 local b1 = {}
395 for i = 0, 9 do
396 b1[i*2 + 1] = i*20*pt
397 b1[i*2 + 2] = 10*pt
398 end
399 local b2 = {}
400 for i = 0, 8 do
401 b2[i*2 + 1] = i*20*pt
402 b2[i*2 + 2] = 5*pt
403 end
404 local ga = brcd:new_canvas()
405 assert(ga:encode_vbar(b1, 0.0, 0.0, 10*pt))
406 assert(ga:encode_vbar(b2, 10.0*pt, 2.5*pt, 7.5*pt))
407 driver:ga_to_hbox(ga, [[mybox]])
408 }\vrule\box\mybox\vrule
409
410 \bigskip
411 Test 4: a bunch of thin bars:
412 \directlua{
413 local b = {}
414 for i = 0, 24 do
415 b[i*2 + 1] = 1*pt + i*4*pt
416 b[i*2 + 2] = 2*pt
417 end
418 local ga = brcd:new_canvas()
419 assert(ga:encode_vbar(b, 0.0, 5*pt, 25*pt))
420 driver:ga_to_hbox(ga, [[mybox]])
421 }\vrule{ }\box\mybox{ }\vrule
422
423 \bigskip
424 Test 5: two levels of a bunch of thin bars:
425 \directlua{
426 local b = {}
427 for i = 0, 24 do
428 b[i*2 + 1] = i*4*pt
429 b[i*2 + 2] = 2*pt
430 end
431 local ga = brcd:new_canvas()
432 assert(ga:encode_vbar(b, 0.0, 5*pt, 25*pt))
433 assert(ga:encode_vbar(b, 2*pt, 25*pt, 45*pt, b))
434 driver:ga_to_hbox(ga, [[mybox]])
435 }\vrule\box\mybox\vrule
436
437 \bigskip
438 Test number 6: staircase of bars (manual insertion of data):
439 \directlua{
440 local b = {0.0, 10*pt}
441 local ga = brcd:new_canvas()
442 assert(ga:encode_vbar(b, 0.0, 0.0, 20*pt))
443 assert(ga:encode_vbar(b, 10*pt, 20*pt, 40*pt))
444 assert(ga:encode_vbar(b, 20*pt, 40*pt, 60*pt))
445 driver:ga_to_hbox(ga, [[mybox]])
446 }\vrule\box\mybox\vrule
447
448 \bigskip
449 Test number 7: vbars with spaced text, all in three rows:
450 \directlua{
451 local vb = {}
452 for i = 0,7 do
453 vb[i*2+1] = i*10*pt
454 vb[i*2+2] = 5*pt
455 end
456 local ga = brcd:new_canvas()
457 assert(ga:encode_vbar(vb, 0.0, 0.0, 20*pt))
458 assert(ga:encode_vbar(vb, 0.0, 30*pt, 50*pt))
459 local txt = {codepoint = {
460 65, % A
461 66, % B
462 67, % C
463 68, % D
464 69, % E
465 70, % F
466 71, % G
467 72, % H
468 }}
469 assert(ga:encode_Text_xspaced(txt, 0.0, 10*pt, 25*pt, 0.5))
470 driver:ga_to_hbox(ga, [[mybox]])
471 }\vrule\box\mybox\vrule
472
473 \bigskip
474 Test 8: spaced text, check correct vertical alignment:
475 \directlua{
476 local b = {}
477 for i = 0,7 do
478 b[i*2+1] = i*10*pt
479 b[i*2+2] = 2*pt
480 end
481 local ga = brcd:new_canvas()
482 assert(ga:encode_vbar(b, 0.0, 0.0, 20*pt))
483 assert(ga:encode_vbar(b, 0.0, 40*pt, 60*pt))
484 local c = { codepoint = {
485 65, % A
486 66, % B
487 67, % C
488 string.byte("Q"),
489 69, % E
490 70, % F
491 71, % G
492 72, % H
493 }}
494 assert(ga:encode_Text_xspaced(c, 0.0, 10*pt, 30*pt, 0.0))
495 local n = { codepoint = {
496 49, % 1
497 50, % 2
498 51, % 3
499 52, % 4
500 53, % 5
501 54, % 6
502 55, % 7
503 56, % 8
504 }}
505 assert(ga:encode_Text_xspaced(n, 0.0, 10*pt, 30*pt, 1.0))
506 driver:ga_to_hbox(ga, [[mybox]])
507 }\vrule\box\mybox\vrule
508
509 \bigskip
510 Test number 9: spaced text, check correct vertical alignment:
511 \directlua{
512 local b = {}
513 for i = 0,7 do
514 b[i*2+1] = i*10*pt
515 b[i*2+2] = 8*pt
516 end
517 local ga = brcd:new_canvas()
518 assert(ga:encode_vbar(b, 0.0, 0.0, 20*pt))
519 assert(ga:encode_vbar(b, 0.0, 40*pt, 60*pt))
520 local c = { codepoint = {
521 65, % A
522 66, % B
523 67, % C
524 string.byte("Q"),
525 69, % E
526 70, % F
527 71, % G
528 72, % H
529 }}
530 assert(ga:encode_Text_xspaced(c, 0.0, 10*pt, 20*pt, 0.0))
531 local n = { codepoint = {
532 49, % 1
533 50, % 2
534 51, % 3
535 52, % 4
536 53, % 5
537 54, % 6
538 55, % 7
539 56, % 8
540 }}
541 assert(ga:encode_Text_xspaced(n, 0.0, 10*pt, 40*pt, 1.0))
542 driver:ga_to_hbox(ga, [[mybox]])
543 }\vrule{ }\box\mybox{ }\vrule
544
545 \bigskip
546 Test number 10: two centered texts and baseline aligned:
547 \directlua{
548 local n = { codepoint = {
549 48, % 0
550 49, % 1
551 50, % 2
552 51, % 3
553 52, % 4
554 53, % 5
555 54, % 6
556 55, % 7
557 56, % 8
558 57, % 9
559 }}
560 local ga = brcd:new_canvas()
561 assert(ga:encode_Text(n, 0, 0, 0.5, 0))
562 local a = { codepoint = {
563 65, % A
564 string.byte("Q"), % Q
565 67, % C
566 }}
567 assert(ga:encode_Text(a, 0, 0, 0.5, 1))
568 driver:ga_to_hbox(ga, [[mybox]])
569 }\vrule\box\mybox\vrule
570
571 \bigskip
572 Test number 11: two centered texts aligned:
573 \directlua{
574 local n = { codepoint = {
575 48, % 0
576 49, % 1
577 50, % 2
578 51, % 3
579 52, % 4
580 53, % 5
581 54, % 6
582 55, % 7
583 56, % 8
584 57, % 9
585 }}
586 local ga = brcd:new_canvas()
587 assert(ga:encode_Text(n, 0, 0, 0.5, 1))
588 local a = { codepoint = {
589 65, % A
590 string.byte("Q"), % Q
591 67, % C
592 }}
593 assert(ga:encode_Text(a, 0, 0, 0.5, 0))
594 driver:ga_to_hbox(ga, [[mybox]])
595 }\vrule\box\mybox\vrule
596
597 \bigskip
598 Test number 12: text\_xwidth opcode:
599
600 \directlua{
601 local n = { codepoint = {
602 48, % 0
603 49, % 1
604 50, % 2
605 51, % 3
606 52, % 4
607 53, % 5
608 54, % 6
609 55, % 7
610 56, % 8
611 57, % 9
612 }}
613 local ga = brcd:new_canvas()
614 assert(ga:encode_Text_xwidth(n, 0, tex.sp "5cm", 0, 0))
615 driver:ga_to_hbox(ga, [[mybox]])
616 }\vrule\box\mybox\vrule
617
618 \vrule\hbox to 5cm{0 \hfill9}\vrule
619
620 \bigskip
621 Test number 13: text\_xwidth with different size:
622 \smallskip
623
624 \directlua{
625 local n = {codepoint = {
626 48, % 0
627 49, % 1
628 50, % 2
629 51, % 3
630 52, % 4
631 53, % 5
632 54, % 6
633 55, % 7
634 56, % 8
635 57, % 9
636 }}
637 local ga = brcd:new_canvas()
638 % (txt, x1, x2, ypos, ay) --> ok, err
639 assert(ga:encode_Text_xwidth(n, tex.sp "0mm", tex.sp "50mm", 0, 0))
640 assert(ga:encode_Text_xwidth(n, tex.sp "5mm", tex.sp "45mm", tex.sp "3mm", 0))
641 assert(ga:encode_Text_xwidth(n, tex.sp "10mm", tex.sp "40mm", tex.sp "6mm", 0))
642 assert(ga:encode_Text_xwidth(n, tex.sp "15mm", tex.sp "35mm", tex.sp "9mm", 0))
643 assert(ga:encode_Text_xwidth(n, tex.sp "20mm", tex.sp "30mm", tex.sp "12mm", 0))
644 assert(ga:encode_Text_xwidth(n, tex.sp "24mm", tex.sp "26mm", tex.sp "15mm", 0))
645 driver:ga_to_hbox(ga, [[mybox]])
646 }\vrule\box\mybox\vrule
647
648 \bigskip
649 Test number 14: place bars and text as text\_xwidth:
650 \smallskip
651
652 \directlua{
653 local b = {}
654 for i = 0, 9 do
655 b[i*2 + 1] = i*12*pt
656 b[i*2 + 2] = 0.4*pt
657 end
658 local n = {codepoint = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,}}
659 local ga = brcd:new_canvas()
660 % (vbar, x0, y1, y2) --> ok, err
661 assert(ga:encode_vbar(b, 0.0, 0*pt, 25*pt))
662 % (txt, x1, x2, ypos, ay) --> ok, err
663 assert(ga:encode_Text_xwidth(n, 0*pt, 108*pt, 25*pt, 0))
664 driver:ga_to_hbox(ga, [[mybox]])
665 }\vrule\box\mybox\vrule
666
667 \smallskip
668 \directlua{
669 local b = {}
670 for i = 0, 8 do
671 b[i*2 + 1] = i*12*pt
672 b[i*2 + 2] = 0.2*pt
673 end
674 local n = { 48, 49, 50, 51, string.byte([[x]]), 53, 54, 55, 56,}
675 n = {codepoint = n}
676 local ga = brcd:new_canvas()
677 % x0, y1, y2, bars
678 assert(ga:encode_vbar(b, 0.0, 0*pt, 25*pt))
679 assert(ga:encode_vbar(b, 0.0, 32*pt, 42*pt))
680 % (txt, x1, x2, ypos, ay) --> ok, err
681 assert(ga:encode_Text_xwidth(n, 0*pt, 96*pt, 25*pt, 0))
682 driver:ga_to_hbox(ga, [[mybox]])
683 }\vrule\box\mybox\vrule
684
685 \bigskip
686 Test number 15: place text\_xwidth when text is only two chars long:
687
688 \directlua{
689 local n = {codepoint = { 48, 56,}} % 0 and 8
690 local ga = brcd:new_canvas()
691 % (txt, x1, x2, ypos, ay) --> ok, err
692 assert(ga:encode_Text_xwidth(n, 0*pt, 32*pt, 25*pt, 0))
693 driver:ga_to_hbox(ga, [[mybox]])
694 }\vrule\box\mybox\vrule
695
696 \bye