% !TeX program = LuaTeX
% Copyright (C) 2019-2022 Roberto Giacomelli

\newbox\mybox
\nopagenumbers

Test 1: the same Code 39 symbol drawing multiple time on the same canvas

\directlua{
local barracuda = require "barracuda"
local c39 = assert(
    barracuda:barcode()
        :new_encoder("code39")
)
local symbol = assert(c39:from_string("ABCDEF12QJ31+"))

local ok, err = c39:set_param("text_vpos", "top")
assert(ok, err)

local canvas = barracuda:new_canvas()
symbol:draw(canvas)

local ok, err = symbol:set_param("text_hpos", "center")
assert(ok, err)
symbol:draw(canvas, tex.sp "4.5cm")

local ok, err = symbol:set_param("text_hpos", "right")
assert(ok, err)
symbol:draw(canvas, tex.sp "9.0cm")

local ok, err = c39:set_param("text_vpos", "bottom")
assert(ok, err)

local ok, err = symbol:set_param("text_hpos", "left")
symbol:draw(canvas, 0, tex.sp "-2.0cm")

local ok, err = symbol:set_param("text_hpos", "center")
assert(ok, err)
symbol:draw(canvas, tex.sp "4.5cm", tex.sp "-2.0cm")

local ok, err = symbol:set_param("text_hpos", "right")
assert(ok, err)
symbol:draw(canvas, tex.sp "9.0cm", tex.sp "-2.0cm")

local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}
\bigskip
\leavevmode\box\mybox
\bye


