diff options
Diffstat (limited to 'macros/luatex/generic/barracuda/example/001-i2of5-test.tex')
-rw-r--r-- | macros/luatex/generic/barracuda/example/001-i2of5-test.tex | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/macros/luatex/generic/barracuda/example/001-i2of5-test.tex b/macros/luatex/generic/barracuda/example/001-i2of5-test.tex new file mode 100644 index 0000000000..43c652d66a --- /dev/null +++ b/macros/luatex/generic/barracuda/example/001-i2of5-test.tex @@ -0,0 +1,187 @@ +% !TeX program = LuaTeX +% Copyright (C) 2019 Roberto Giacomelli + +\newbox\mybox +\nopagenumbers + +\directlua{barracuda = require "barracuda"} + +Interleaved 2 of 5 encoder test. + +Test 1: one simple barcode with default parameters: + +\directlua{ +local barcode = barracuda:get_barcode_class() + +local enc, err = barcode:new_encoder("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(54654681); assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +\bigskip +Test 2: one simple barcode with default parameter: + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(1234567895); assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +% check digit tests + +\directlua{% verify check digits, the last one +local code = { + 7352621, + 9624764, + 7592881, + 5344147, + 742238, + 199766, + 4544739, + 2774794, + 8509895, + 8285157, + 5387564, + 5534371, + 2155678, + 4529545, + 4689164, + 1674910, + 5317837, + 4117698, +} +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +for _, n in ipairs(code) do + local smbl, err = enc:from_uint(n, {check_digit_policy="verify"}) + assert(not err, err) +end +} + +\directlua{% check digits evaluation +local code = { + ["735262"] = 1, + ["962476"] = 4, + ["759288"] = 1, + ["534414"] = 7, + ["74223"] = 8, + ["19976"] = 6, + ["454473"] = 9, + ["277479"] = 4, + ["850989"] = 5, + ["828515"] = 7, + ["538756"] = 4, + ["553437"] = 1, + ["215567"] = 8, + ["452954"] = 5, + ["468916"] = 4, + ["167491"] = 0, + ["531783"] = 7, + ["411769"] = 8, +} +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +for sc, ck in pairs(code) do + local n = tonumber(sc) + local c, err = enc:get_checkdigit(n) + assert(not err, err) + assert(c == ck, "Wrong check digit "..c.." vs "..ck .." for "..sc) +end +} + +\bigskip +Test 3: one simple barcode with check digit automatically added: + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(454473, {check_digit_policy="add"}) +assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +\bigskip +Test 4: a second simple barcode with check digit automatically added: + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(74223, {check_digit_policy="add"}) +assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +\bigskip +Test 5: a symbol with native check digits: + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(121891259, {check_digit_policy="verify"}) +assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +\bigskip +Test 6: bearer bars please: + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(747867239, {bearer_bars_enabled = true}) +assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +\bigskip +Test 7: bearer bars all around the symbol: + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_uint(986790868, {bearer_bars_enabled = true, bearer_bars_layout="frame"}) +assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +\bigskip +Test 8: bearer bars all around the symbol (with string costructor): + +\directlua{ +local barcode = barracuda:get_barcode_class() +local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err) +local symbo, err = enc:from_string("986790868", {bearer_bars_enabled = true, bearer_bars_layout="frame"}) +assert(not err, err) +local canvas = barracuda:new_canvas(); symbo:append_ga(canvas) +local drv = barracuda:get_driver() +drv:ga_to_hbox(canvas, "mybox") +} +\vrule A\vrule\box\mybox \vrule A\vrule + +That's all folks! + +\bye + + |