summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/barracuda/test/test-ga-pdfliteral/001-ga-pdfliteral-test.tex
blob: 1a5ed80d0c5e2502faf3ac1fb6d4d6a51c6eca29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
% !TeX program = LuaTeX
% test for ga-canvas pdfliteral driver
%
% Copyright (C) 2019 Roberto Giacomelli
% see LICENSE.txt file

---ga--- is a binary format as an istruction set similar to
a sort of assembler language that describes simple graphic
objects like lines and rectangles.
This file contains tests aiming to check the pdfliteral
driver capability to render such ga streams---usually a Lua
array.

The pdfliteral driver directly inserts PDF vector graphic
primitives within the output and should be intented as the
"native" driver of barracuda package.

The complete reference of the ---ga--- format is available
throgh out the content of the "ga-grammar.tex" file.

Please note that all dimensions are in scaled point, the
very small \TeX{} internal unit, in fact we have that
65536sp = 1pt.

Running the source file with luatex. The typesetting engine
executes the directlua macro, so vector graphics appear in
the PDF output file.

\newbox\mybox
\directlua{
    driver = require [[lib-driver.brcd-driver]] % global Lua variables
    pt = tex.sp [[1pt]] % 1pt = 65536sp
}

Let's start drawing an horizontal line 100pt long:
\directlua{
   local ga = {_data = {33, 0*pt, 100*pt, 0*pt}}
   driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

or two different parallel lines 24pt long:
\directlua{
   local ga = {_data = {33, 0*pt, 24*pt, 0*pt, 33, 0*pt, 24*pt, 5*pt}}
   driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

and again two horizontal lines 10pt thick, touching a corner:
\directlua{
   local ga = {_data = {
       1,   10*pt,
       33, -24*pt,  0*pt, -5*pt,
       33,   0*pt, 24*pt,  5*pt,
   }}
   driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

Several vertical lines with its horizontal limits:
\directlua{
   local ga = { _data = {
       34, -20*pt, 20*pt,  0*pt,
       34, -15*pt, 15*pt,  5*pt,
       34, -10*pt, 10*pt, 10*pt,
       34,  -5*pt,  5*pt, 15*pt,
       34, -.5*pt, .5*pt, 20*pt,
       34,  -5*pt,  5*pt, 25*pt,
       34, -10*pt, 10*pt, 30*pt,
       34, -15*pt, 15*pt, 35*pt,
       34, -20*pt, 20*pt, 40*pt,
        1, .05*pt,
       33,   0*pt, 40*pt, -20*pt,
       33,   0*pt, 40*pt,  20*pt,
   }}
   driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

Finally a little rectangle:
\directlua{
   local ga = {_data = {
       1, 5*pt,
      48, 0*pt, 0*pt, 15*pt, 10*pt,
   }}
   driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

\bigskip
Test number 1: a vbar 2pt width, 20pt height:
\directlua{
    % vbar: <36> y1 y2 <nbars> x1 w1 x2 w2 ... xn wn
    local ga = {_data = {36, 0, 20*pt, 1, 0.0, 2*pt}}
    driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

\bigskip
Test number 2: ten vbars in a row equally spaced by 10pt:
\directlua{
    local ga = {36, 0, 10*pt, 10,}
    for i = 0, 9 do
        ga[i*2 + 5] = 5*pt + i*20*pt
        ga[i*2 + 6] = 10*pt
    end
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 3: two series of vbars 10pt and 5pt large:
\directlua{
    local ga = {36, 0, 10*pt, 10,}
    for i = 0, 9 do
        ga[i*2 + 5] = 5*pt + i*20*pt
        ga[i*2 + 6] = 10*pt
    end
    ga[25] = 36 % vbar opcode
    ga[26] = 2.5*pt % y1
    ga[27] = 7.5*pt % y2
    ga[28] = 9      % number of bars
    for i = 0, 8 do
        ga[i*2 + 29] = 15*pt + i*20*pt
        ga[i*2 + 30] = 5*pt
    end
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 4: a bunch of thin vertical bars (25):
\directlua{
    local ga = {}
    ga[1] = 36    % vbar opcode
    ga[2] = 5*pt  % y1
    ga[3] = 25*pt % y2
    ga[4] = 25    % number of bars
    for i = 0, 24 do
        ga[i*2 + 5] = 1*pt + i*4*pt
        ga[i*2 + 6] = 2*pt
    end
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule A\box\mybox A\vrule

\bigskip
Test number 5: two rows of a bunch of thin bars:
\directlua{
    local ga = {}
    ga[1] = 36    % vbar opcode
    ga[2] = 5*pt  % y1
    ga[3] = 25*pt % y2
    ga[4] = 25    % number of bars
    for i = 0, 24 do
        ga[i*2 + 5] = 1*pt + i*4*pt
        ga[i*2 + 6] = 2*pt
    end
    ga[55] = 36    % vbar opcode
    ga[56] = 25*pt % y1
    ga[57] = 45*pt % y2
    ga[58] = 24    % number of bars
    for i = 0, 23 do
        ga[i*2 + 59] = 3*pt + i*4*pt
        ga[i*2 + 60] = 2*pt
    end
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 6: staircase of Vbars (manually data definition):
\directlua{
    local ga = {
        36, % vbar opcode
      0*pt, % y1
     20*pt, % y2
         1, % number of bars
      5*pt, % x
     10*pt, % w
        36, % vbar opcode
     20*pt, % y1
     40*pt, % y2
         1, % number of bars
     15*pt, % x
     10*pt, % w
        36, % vbar opcode
     40*pt, % y1
     60*pt, % y2
         1, % number of bars
     25*pt, % x
     10*pt, % w
    }
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 7: vbars with spaced text, in three different rows:
\directlua{
    local ga = {}
    ga[1] =    36 % vbar opcode
    ga[2] =  0*pt % y1
    ga[3] = 20*pt % y2
    ga[4] =     8 % number of bars
    for i = 1,8 do
        ga[3 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
        ga[4 + i*2] = 5*pt % bar width
    end
    ga[21] =    36 % vbar opcode
    ga[22] = 30*pt % y1
    ga[23] = 50*pt % y2
    ga[24] =     8 % number of bars
    for i = 1,8 do
        ga[23 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
        ga[24 + i*2] = 5*pt % bar width
    end
    % 131 <x1: FLOAT> <xgap: FLOAT> <ay: DIM> <ypos: DIM> <c: CHARS>
    ga[41] = 131   % opcode text_xspaced
    ga[42] = 10*pt % x coordinate of the first glyph axis
    ga[43] = 10*pt % x gap among glyphs
    ga[44] = 0.5   % half height
    ga[45] = 25*pt % y coordinate of glyps
    ga[46] = 65 % A
    ga[47] = 66 % B
    ga[48] = 67 % C
    ga[49] = 68 % D
    ga[50] = 69 % E
    ga[51] = 70 % F
    ga[52] = 71 % G
    ga[53] = 72 % H
    ga[54] = 0
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 8: spaced text (checking the correct vertical alignment):
\directlua{
    local ga = {}
    ga[1] =    36 % vbar opcode
    ga[2] =  0*pt % y1
    ga[3] = 20*pt % y2
    ga[4] =     8 % number of bars
    for i = 1,8 do
        ga[3 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
        ga[4 + i*2] = 1*pt % bar width
    end
    ga[21] =    36 % vbar opcode
    ga[22] = 40*pt % y1
    ga[23] = 60*pt % y2
    ga[24] =     8 % number of bars
    for i = 1,8 do
        ga[23 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
        ga[24 + i*2] = 1*pt % bar width
    end
    % 131 <x1: FLOAT> <xgap: FLOAT> <ay: DIM> <ypos: DIM> <c: CHARS>
    ga[41] = 131   % opcode text_xspaced
    ga[42] = 10*pt % x coordinate of the first glyph axis
    ga[43] = 10*pt % x gap among glyphs
    ga[44] = 0.0   % half height
    ga[45] = 30*pt % y coordinate of glyps
    ga[46] = 65 % A
    ga[47] = 66 % B
    ga[48] = 67 % C
    ga[49] = string.byte("Q")
    ga[50] = 69 % E
    ga[51] = 70 % F
    ga[52] = 71 % G
    ga[53] = 72 % H
    ga[54] = 0
    ga[55] = 131   % opcode text_xspaced
    ga[56] = 10*pt % x coordinate of the first glyph axis
    ga[57] = 10*pt % x gap among glyphs
    ga[58] = 1.0   % half height
    ga[59] = 30*pt % y coordinate of glyps
    ga[60] = 49 % 1
    ga[61] = 50 % 2
    ga[62] = 51 % 3
    ga[63] = 52 % 4
    ga[64] = 53 % 5
    ga[65] = 54 % 6
    ga[66] = 55 % 7
    ga[67] = 56 % 8
    ga[68] = 0
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 9: spaced text, check correct vertical alignment:
\directlua{
    local ga = {}
    ga[1] =    36 % vbar opcode
    ga[2] =  0*pt % y1
    ga[3] = 20*pt % y2
    ga[4] =     8 % number of bars
    for i = 1,8 do
        ga[3 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
        ga[4 + i*2] = 8*pt % bar width
    end
    ga[21] =    36 % vbar opcode
    ga[22] = 40*pt % y1
    ga[23] = 60*pt % y2
    ga[24] =     8 % number of bars
    for i = 1,8 do
        ga[23 + i*2] = i * 2 * 5*pt % x coordinate of bar axis
        ga[24 + i*2] = 8*pt % bar width
    end
    % 131 <x1: FLOAT> <xgap: FLOAT> <ay: DIM> <ypos: DIM> <c: CHARS>
    ga[41] = 131   % opcode text_xspaced
    ga[42] = 10*pt % x coordinate of the first glyph axis
    ga[43] = 10*pt % x gap among glyphs
    ga[44] = 0.0   % half height
    ga[45] = 20*pt % y coordinate of glyps
    ga[46] = 65 % A
    ga[47] = 66 % B
    ga[48] = 67 % C
    ga[49] = 68 % D
    ga[50] = 69 % E
    ga[51] = 70 % F
    ga[52] = 71 % G
    ga[53] = 72 % H
    ga[54] = 0
    ga[55] = 131   % opcode text_xspaced
    ga[56] = 10*pt % x coordinate of the first glyph axis
    ga[57] = 10*pt % x gap among glyphs
    ga[58] = 1.0   % half height
    ga[59] = 40*pt % y coordinate of glyps
    ga[60] = 49 % 1
    ga[61] = 50 % 2
    ga[62] = 51 % 3
    ga[63] = 52 % 4
    ga[64] = 53 % 5
    ga[65] = 54 % 6
    ga[66] = 55 % 7
    ga[67] = 56 % 8
    ga[68] = 0
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 10: two centered texts aligned to the baseline:
\directlua{
    local ga = {}
    % 130 <ax: FLOAT> <ay: FLOAT> <xpos: DIM> <ypos: DIM> <c: CHARS>
    ga[ 1] = 130 % opcode text
    ga[ 2] = 0.5 % ax relative x coordinate
    ga[ 3] = 1.0 % ay relative y coordinate
    ga[ 4] = 0.0 % x position
    ga[ 5] = 0.0 % y position
    ga[ 6] =  65 % A
    ga[ 7] =  string.byte("Q") % Q depth glyph
    ga[ 8] =  67 % C
    ga[ 9] =   0
    ga[10] = 130 % opcode text
    ga[11] = 0.5 % ax
    ga[12] = 0.0 % ay
    ga[13] = 0.0 % x
    ga[14] = 0.0 % y
    ga[15] =  48 % 0
    ga[16] =  49 % 1
    ga[17] =  50 % 2
    ga[18] =  51 % 3
    ga[19] =  52 % 4
    ga[20] =  53 % 5
    ga[21] =  54 % 6
    ga[22] =  55 % 7
    ga[23] =  56 % 8
    ga[24] =  57 % 9
    ga[25] =   0
    driver:ga_to_hbox({_data = ga}, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
So far, we have manually build data for ga stream. Next we are going to
use the ga-canvas library.

\bigskip
In fact, all the previous tests are rebuild with the ga-canvas library.

Test 1: a vbar 2pt width, 20pt height:
\directlua{
    gacanvas = require "lib-geo.brcd-gacanvas"
    local ga = gacanvas:new()
    local vbar = {_yline = {0.0, 2*pt}}
    local err = ga:encode_Vbar(vbar, 0.0, 0.0, 20*pt) % x, w
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\box\mybox

\bigskip
Test 2: ten vbars equally spaced by 10pt:
\directlua{
    local ga = gacanvas:new()
    local data = {}
    for i = 0, 9 do
        data[i*2 + 1] =  5*pt + i*20*pt % x
        data[i*2 + 2] = 10*pt           % w
    end
    local bars = {_yline = data}
    local err = ga:encode_Vbar(bars, 0.0, 0.0, 10*pt)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test 3: two series of vbars 10pt and 5pt large:
\directlua{
    local b1 = {}
    for i = 0, 9 do
        b1[i*2 + 1] = i*20*pt
        b1[i*2 + 2] = 10*pt
    end
    local b2 = {}
    for i = 0, 8 do
        b2[i*2 + 1] = i*20*pt
        b2[i*2 + 2] = 5*pt
    end
    local ga = gacanvas:new()
    local err = ga:encode_Vbar({_yline=b1}, 0.0, 0.0, 10*pt)
    assert(not err, err)
    err = ga:encode_Vbar({_yline=b2}, 10.0*pt, 2.5*pt, 7.5*pt)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test 4: a bunch of thin bars:
\directlua{
    local b = {}
    for i = 0, 24 do
        b[i*2 + 1] = 1*pt + i*4*pt
        b[i*2 + 2] = 2*pt
    end
    local ga = gacanvas:new()
    local err = ga:encode_Vbar({_yline=b}, 0.0, 5*pt, 25*pt)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule{ }\box\mybox{ }\vrule

\bigskip
Test 5: two levels of a bunch of thin bars:
\directlua{
    local b = {}
    for i = 0, 24 do
        b[i*2 + 1] = i*4*pt
        b[i*2 + 2] = 2*pt
    end
    local b = {_yline=b}
    local ga = gacanvas:new()
    local err = ga:encode_Vbar(b, 0.0, 5*pt, 25*pt)
    assert(not err, err)
    err = ga:encode_Vbar(b, 2*pt, 25*pt, 45*pt, b)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 6: staircase of bars (manual insertion of data):
\directlua{
    local b = {_yline={0.0, 10*pt}}
    local ga = gacanvas:new()
    local err = ga:encode_Vbar(b, 0.0, 0.0, 20*pt)
    assert(not err, err)
    err = ga:encode_Vbar(b, 10*pt, 20*pt, 40*pt)
    assert(not err, err)
    err = ga:encode_Vbar(b, 20*pt, 40*pt, 60*pt)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 7: vbars with spaced text, all in three rows:
\directlua{
    local b = {}
    for i = 0,7 do
        b[i*2+1] = i*10*pt
        b[i*2+2] = 5*pt
    end
    local vb = {_yline=b}
    local ga = gacanvas:new()
    local err = ga:encode_Vbar(vb, 0.0, 0.0, 20*pt)
    assert(not err, err)
    local err = ga:encode_Vbar(vb, 0.0, 30*pt, 50*pt)
    assert(not err, err)
    local txt = {codepoint = {
        65, % A
        66, % B
        67, % C
        68, % D
        69, % E
        70, % F
        71, % G
        72, % H
    }}
    err = ga:encode_Text_xspaced(txt, 0.0, 10*pt, 25*pt, 0.5)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test 8: spaced text, check correct vertical alignment:
\directlua{
    local b = {}
    for i = 0,7 do
        b[i*2+1] = i*10*pt
        b[i*2+2] = 2*pt
    end
    b = {_yline=b}
    local ga = gacanvas:new()
    local err = ga:encode_Vbar(b, 0.0, 0.0, 20*pt)
    assert(not err, err)
    local err = ga:encode_Vbar(b, 0.0, 40*pt, 60*pt)
    assert(not err, err)
    local c = { codepoint = {
        65, % A
        66, % B
        67, % C
        string.byte("Q"),
        69, % E
        70, % F
        71, % G
        72, % H
    }}
    err = ga:encode_Text_xspaced(c, 0.0, 10*pt, 30*pt, 0.0)
    assert(not err, err)
    local n = { codepoint = {
        49, % 1
        50, % 2
        51, % 3
        52, % 4
        53, % 5
        54, % 6
        55, % 7
        56, % 8
    }}
    err = ga:encode_Text_xspaced(n, 0.0, 10*pt, 30*pt, 1.0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 9: spaced text, check correct vertical alignment:
\directlua{
    local b = {}
    for i = 0,7 do
        b[i*2+1] = i*10*pt
        b[i*2+2] = 8*pt
    end
    b = {_yline = b}
    local ga = gacanvas:new()
    local err = ga:encode_Vbar(b, 0.0, 0.0, 20*pt)
    assert(not err, err)
    local err = ga:encode_Vbar(b, 0.0, 40*pt, 60*pt)
    assert(not err, err)
    local c = { codepoint = {
        65, % A
        66, % B
        67, % C
        string.byte("Q"),
        69, % E
        70, % F
        71, % G
        72, % H
    }}
    err = ga:encode_Text_xspaced(c, 0.0, 10*pt, 20*pt, 0.0)
    assert(not err, err)
    local n = { codepoint = {
        49, % 1
        50, % 2
        51, % 3
        52, % 4
        53, % 5
        54, % 6
        55, % 7
        56, % 8
    }}
    err = ga:encode_Text_xspaced(n, 0.0, 10*pt, 40*pt, 1.0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule{ }\box\mybox{ }\vrule

\bigskip
Test number 10: two centered texts and baseline aligned:
\directlua{
    local n = { codepoint = {
        48, % 0
        49, % 1
        50, % 2
        51, % 3
        52, % 4
        53, % 5
        54, % 6
        55, % 7
        56, % 8
        57, % 9
    }}
    local ga = gacanvas:new()
    local err = ga:encode_Text(n, 0, 0, 0.5, 0)
    assert(not err, err)
    local a = { codepoint = {
        65, % A
        string.byte("Q"), % Q
        67, % C
    }}
    err = ga:encode_Text(a, 0, 0, 0.5, 1)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 11: two centered texts aligned:
\directlua{
    local n = { codepoint = {
        48, % 0
        49, % 1
        50, % 2
        51, % 3
        52, % 4
        53, % 5
        54, % 6
        55, % 7
        56, % 8
        57, % 9
    }}
    local ga = gacanvas:new()
    local err = ga:encode_Text(n, 0, 0, 0.5, 1)
    assert(not err, err)
    local a = { codepoint = {
        65, % A
        string.byte("Q"), % Q
        67, % C
    }}
    err = ga:encode_Text(a, 0, 0, 0.5, 0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 12: text\_xwidth opcode:

\directlua{
    local n = { codepoint = {
        48, % 0
        49, % 1
        50, % 2
        51, % 3
        52, % 4
        53, % 5
        54, % 6
        55, % 7
        56, % 8
        57, % 9
    }}
    local ga = gacanvas:new()
    local err = ga:encode_Text_xwidth(n, 0, tex.sp "5cm", 0, 0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\vrule\hbox to 5cm{0 \hfill9}\vrule

\bigskip
Test number 13: text\_xwidth with different size:
\smallskip

\directlua{
    local n = {codepoint = {
        48, % 0
        49, % 1
        50, % 2
        51, % 3
        52, % 4
        53, % 5
        54, % 6
        55, % 7
        56, % 8
        57, % 9
    }}
    local ga = gacanvas:new()
    %                                (txt, x1, x2, ypos, ay) --> err
    local err = ga:encode_Text_xwidth(n, tex.sp "0mm", tex.sp "50mm", 0, 0) 
    assert(not err, err)
    local err = ga:encode_Text_xwidth(n, tex.sp "5mm", tex.sp "45mm", tex.sp "3mm", 0)
    assert(not err, err)
    local err = ga:encode_Text_xwidth(n, tex.sp "10mm", tex.sp "40mm", tex.sp "6mm", 0)
    assert(not err, err)
    local err = ga:encode_Text_xwidth(n, tex.sp "15mm", tex.sp "35mm", tex.sp "9mm", 0)
    assert(not err, err)
    local err = ga:encode_Text_xwidth(n, tex.sp "20mm", tex.sp "30mm", tex.sp "12mm", 0)
    assert(not err, err)
    local err = ga:encode_Text_xwidth(n, tex.sp "24mm", tex.sp "26mm", tex.sp "15mm", 0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 14: place bars and text as text\_xwidth:
\smallskip

\directlua{
    local b = {}
    for i = 0, 9 do
        b[i*2 + 1] = i*12*pt
        b[i*2 + 2] = 0.4*pt
    end
    b = {_yline = b}
    local n = {codepoint = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,}}
    local ga = gacanvas:new()
    %                         (vbar, x0, y1, y2) --> err
    local err = ga:encode_Vbar(b, 0.0,  0*pt, 25*pt)
    local err = ga:encode_Vbar(b, 0.0, 32*pt, 42*pt)
    assert(not err, err)
    %                            (txt, x1, x2, ypos, ay) --> err
    local err = ga:encode_Text_xwidth(n, 0*pt, 108*pt, 25*pt, 0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\smallskip
\directlua{
    local b = {}
    for i = 0, 8 do
        b[i*2 + 1] = i*12*pt
        b[i*2 + 2] = 0.2*pt
    end
    b = {_yline = b}
    local n = { 48, 49, 50, 51, string.byte([[x]]), 53, 54, 55, 56,}
    n = {codepoint = n}
    local ga = gacanvas:new()
    %                    x0,    y1,    y2, bars
    local err = ga:encode_Vbar(b, 0.0,  0*pt, 25*pt)
    local err = ga:encode_Vbar(b, 0.0, 32*pt, 42*pt)
    assert(not err, err)
    %                (txt, x1, x2, ypos, ay) --> err
    local err = ga:encode_Text_xwidth(n, 0*pt, 96*pt, 25*pt, 0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bigskip
Test number 15: place text\_xwidth when text is only two chars long:

\directlua{
    local n = {codepoint = { 48, 56,}} % 0 and 8
    local ga = gacanvas:new()
    %                           (txt, x1, x2, ypos, ay) --> err
    local err = ga:encode_Text_xwidth(n, 0*pt, 32*pt, 25*pt, 0)
    assert(not err, err)
    driver:ga_to_hbox(ga, [[mybox]])
}\vrule\box\mybox\vrule

\bye