Debian Codegraph @

texmf-dist/doc/luatex/barracuda/test/test-i2of5/001-i2of5-test.tex

raw
1 % !TeX program = LuaTeX
2 % Copyright (C) 2019-2022 Roberto Giacomelli
3
4 \newbox\mybox
5 \nopagenumbers
6
7 \directlua{
8 barracuda = require "barracuda"
9 local barcode = barracuda:barcode()
10 barcode:set_param("debug_bbox", "symb")
11 }
12
13 Interleaved 2 of 5 encoder test.
14
15 Test 1: one simple barcode with default parameters:
16
17 \directlua{
18 local barcode = barracuda:barcode()
19 local enc, err = barcode:new_encoder("i2of5"); assert(not err, err)
20 local symbo, err = enc:from_uint(54654681); assert(not err, err)
21 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
22 local drv = barracuda:get_driver()
23 drv:ga_to_hbox(canvas, "mybox")
24 }%
25 input code 54654681: \vrule A\vrule\box\mybox \vrule A\vrule
26
27 \bigskip
28 Test 2: one simple barcode with default parameter:
29
30 \directlua{
31 local barcode = barracuda:barcode()
32 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
33 local symbo, err = enc:from_uint(1234567895); assert(not err, err)
34 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
35 local drv = barracuda:get_driver()
36 drv:ga_to_hbox(canvas, "mybox")
37 }%
38 input code 1234567895: \vrule A\vrule\box\mybox \vrule A\vrule
39
40 % check digit tests
41
42 \directlua{% verify check digits, the last one
43 local code = {
44 7352621,
45 9624764,
46 7592881,
47 5344147,
48 742238,
49 199766,
50 4544739,
51 2774794,
52 8509895,
53 8285157,
54 5387564,
55 5534371,
56 2155678,
57 4529545,
58 4689164,
59 1674910,
60 5317837,
61 4117698,
62 }
63 local barcode = barracuda:barcode()
64 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
65 for _, n in ipairs(code) do
66 local smbl, err = enc:from_uint(n, {check_digit_policy="verify"})
67 assert(not err, err)
68 end
69 }
70
71 \directlua{% check digits evaluation
72 local code = {
73 ["735262"] = 1,
74 ["962476"] = 4,
75 ["759288"] = 1,
76 ["534414"] = 7,
77 ["74223"] = 8,
78 ["19976"] = 6,
79 ["454473"] = 9,
80 ["277479"] = 4,
81 ["850989"] = 5,
82 ["828515"] = 7,
83 ["538756"] = 4,
84 ["553437"] = 1,
85 ["215567"] = 8,
86 ["452954"] = 5,
87 ["468916"] = 4,
88 ["167491"] = 0,
89 ["531783"] = 7,
90 ["411769"] = 8,
91 }
92 local barcode = barracuda:barcode()
93 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
94 for sc, ck in pairs(code) do
95 local n = tonumber(sc)
96 local c, err = enc:get_checkdigit(n)
97 assert(not err, err)
98 assert(c == ck, "Wrong check digit "..c.." vs "..ck .." for "..sc)
99 end
100 }
101
102 \bigskip
103 Test 3: one simple barcode with check digit automatically added:
104
105 \directlua{
106 local barcode = barracuda:barcode()
107 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
108 local symbo, err = enc:from_uint(454473, {check_digit_policy="add"})
109 assert(not err, err)
110 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
111 local drv = barracuda:get_driver()
112 drv:ga_to_hbox(canvas, "mybox")
113 }%
114 input code 454473: \vrule A\vrule\box\mybox \vrule A\vrule
115
116 \bigskip
117 Test 4: a second simple barcode with check digit automatically added:
118
119 \directlua{
120 local barcode = barracuda:barcode()
121 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
122 local symbo, err = enc:from_uint(74223, {check_digit_policy="add"})
123 assert(not err, err)
124 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
125 local drv = barracuda:get_driver()
126 drv:ga_to_hbox(canvas, "mybox")
127 }%
128 input code 74223: \vrule A\vrule\box\mybox \vrule A\vrule
129
130 \bigskip
131 Test 5: a symbol with native check digits:
132
133 \directlua{
134 local barcode = barracuda:barcode()
135 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
136 local symbo, err = enc:from_uint(121891259, {check_digit_policy="verify"})
137 assert(not err, err)
138 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
139 local drv = barracuda:get_driver()
140 drv:ga_to_hbox(canvas, "mybox")
141 }%
142 input code 121891259: \vrule A\vrule\box\mybox \vrule A\vrule
143
144 \bigskip
145 Test 6: bearer bars please:
146
147 \directlua{
148 local barcode = barracuda:barcode()
149 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
150 local symbo, err = enc:from_string("747867239", {bearer_bars_enabled = true})
151 assert(not err, err)
152 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
153 local drv = barracuda:get_driver()
154 drv:ga_to_hbox(canvas, "mybox")
155 }%
156 input string "747867239": \vrule A\vrule\box\mybox \vrule A\vrule
157
158 \bigskip
159 Test 7: bearer bars all around the symbol:
160
161 \directlua{
162 local barcode = barracuda:barcode()
163 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
164 local symbo, err = enc:from_uint(986790868, {bearer_bars_enabled = true, bearer_bars_layout="frame"})
165 assert(not err, err)
166 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
167 local drv = barracuda:get_driver()
168 drv:ga_to_hbox(canvas, "mybox")
169 }%
170 input code 986790868: \vrule A\vrule\box\mybox \vrule A\vrule
171
172 \bigskip
173 Test 8: bearer bars all around the symbol (with string costructor):
174
175 \directlua{
176 local barcode = barracuda:barcode()
177 local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
178 local symbo, err = enc:from_string("986790868", {bearer_bars_enabled = true, bearer_bars_layout="frame"})
179 assert(not err, err)
180 local canvas = barracuda:new_canvas(); symbo:draw(canvas)
181 local drv = barracuda:get_driver()
182 drv:ga_to_hbox(canvas, "mybox")
183 }%
184 input string "986790868": \vrule A\vrule\box\mybox \vrule A\vrule
185
186 That's all folks!
187
188 \bye
189
190