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
|
% !TeX program = LuaTeX
% Copyright (C) 2020 Roberto Giacomelli
\newbox\mybox
\nopagenumbers
\directlua{
barracuda = require "barracuda"
}
Test 1: Code 39 symbol with default parameters:
\directlua{
local c39, err = barracuda:barcode()
:new_encoder("code39")
assert(not err, err)
local symbol, err = c39:from_string("ABC12QJ31")
assert(not err, err)
local canvas = barracuda:new_canvas()
symbol:append_ga(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}\box\mybox
Test 2: get the reference of the previous encoder and typeset two
Code 39 symbols on the same canvas, one above to the other:
\directlua{
local c39, err = barracuda:barcode()
:enc_by_name("code39")
assert(c39, err)
local s1, err = c39:from_string("ZKPQJ31"); assert(s1, err)
local s2, err = c39:from_string("RTFG746", {text_vpos="top"}); assert(s2, err)
local canvas = barracuda:new_canvas()
s1:append_ga(canvas)
local h2 = s2:get_param("height")
s2:append_ga(canvas, 0.0, h2 + tex.sp "5pt")
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}\box\mybox
Test 3: with the same encoder print a symbol, change globally the height,
and reprint the same symbol again on the same canvas:
\directlua{
local c39, err = barracuda:barcode()
:enc_by_name("code39")
assert(c39, err)
local s1, err = c39:from_string("ZKPQJ31"); assert(s1, err)
local canvas = barracuda:new_canvas()
s1:append_ga(canvas)
local h = s1:get_param("height")
c39:set_param("height", 2*h)
c39:set_param {text_vpos = "top"}
s1:append_ga(canvas, 0.0, h + tex.sp "5pt")
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}\box\mybox
Test 4: do the same in test 3 but change locally parameters as
height and text properties:
\directlua{
local c39, err = barracuda:barcode()
:enc_by_name("code39")
assert(c39, err)
local s1, err = c39:from_string("0123456789"); assert(s1, err)
local canvas = barracuda:new_canvas()
s1:append_ga(canvas)
local h, err = s1:get_param("height"); assert(h, err)
local ok, err = s1:set_param{
height = h/2,
text_enabled = true,
text_vpos = "bottom",
text_hpos = "spaced",
text_star = true,
ay = 1,
}; assert(ok, err)
s1:append_ga(canvas, 0.0, - tex.sp "5pt")
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}\box\mybox
Test 5: create a new encoder with a large module value:
\directlua{
local barcode = barracuda:barcode()
local c39, err = barcode:new_encoder("code39:e2", {module = tex.sp "0.5mm"})
assert(c39, err)
local s1, err = c39:from_string("02040608"); assert(s1, err)
local canvas = barracuda:new_canvas()
s1:append_ga(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}\box\mybox
\bye
|