Debian Codegraph @

texmf-dist/doc/luatex/barracuda/test/test-code39/002-code39-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 }
10
11 Test 1: Code 39 symbol with default parameters:
12
13 \directlua{
14 local c39, err = barracuda:barcode()
15 :new_encoder("code39")
16 assert(not err, err)
17
18 local symbol, err = c39:from_string("ABC12QJ31")
19 assert(not err, err)
20
21 local canvas = barracuda:new_canvas()
22 symbol:draw(canvas)
23 local drv = barracuda:get_driver()
24 drv:ga_to_hbox(canvas, "mybox")
25 }\leavevmode\box\mybox
26
27 Test 2: get the reference of the previous encoder and typeset two
28 Code 39 symbols on the same canvas, one above to the other:
29
30 \directlua{
31 local c39, err = barracuda:barcode()
32 :enc_by_name("code39")
33 assert(c39, err)
34
35 local s1, err = c39:from_string("ZKPQJ31"); assert(s1, err)
36 local s2, err = c39:from_string("RTFG746", {text_vpos="top"}); assert(s2, err)
37
38 local canvas = barracuda:new_canvas()
39 s1:draw(canvas)
40
41 local h2 = s2:get_param("height")
42 s2:draw(canvas, 0.0, h2 + tex.sp "5pt")
43 local drv = barracuda:get_driver()
44 drv:ga_to_hbox(canvas, "mybox")
45 }\leavevmode\box\mybox
46
47 Test 3: with the same encoder print a symbol, change globally the height,
48 and reprint the same symbol again on the same canvas:
49
50 \directlua{
51 local c39, err = barracuda:barcode()
52 :enc_by_name("code39")
53 assert(c39, err)
54
55 local s1, err = c39:from_string("ZKPQJ31"); assert(s1, err)
56
57 local canvas = barracuda:new_canvas()
58 s1:draw(canvas)
59
60 local h = s1:get_param("height")
61 c39:set_param("height", 2*h)
62 c39:set_param {text_vpos = "top"}
63
64 s1:draw(canvas, 0.0, h + tex.sp "5pt")
65
66 local drv = barracuda:get_driver()
67 drv:ga_to_hbox(canvas, "mybox")
68 }\leavevmode\box\mybox
69
70 Test 4: do the same in test 3 but change locally parameters as
71 height and text properties:
72
73 \directlua{
74 local c39, err = barracuda:barcode()
75 :enc_by_name("code39")
76 assert(c39, err)
77
78 local s1, err = c39:from_string("0123456789"); assert(s1, err)
79
80 local canvas = barracuda:new_canvas()
81 s1:draw(canvas)
82 local h, err = s1:get_param("height"); assert(h, err)
83 local ok, err = s1:set_param{
84 height = h/2,
85 text_enabled = true,
86 text_vpos = "bottom",
87 text_hpos = "spaced",
88 text_star = true,
89 ay = 1,
90 }; assert(ok, err)
91 s1:draw(canvas, 0.0, - tex.sp "5pt")
92
93 local drv = barracuda:get_driver()
94 drv:ga_to_hbox(canvas, "mybox")
95 }\leavevmode\box\mybox
96
97 Test 5: create a new encoder with a large module value.
98
99 It's also activeted the debug\_bbox\_on option.
100
101 \bigskip
102 \directlua{
103 local barcode = barracuda:barcode()
104
105 local c39, err = barcode:new_encoder("code39:e2", {module = tex.sp "0.5mm", debug_bbox_on = true})
106 assert(c39, err)
107
108 local s1, err = c39:from_string("02040608"); assert(s1, err)
109
110 local canvas = barracuda:new_canvas()
111 s1:draw(canvas)
112
113 local drv = barracuda:get_driver()
114 drv:ga_to_hbox(canvas, "mybox")
115 }\leavevmode\box\mybox
116
117 \bye