Barcode rendering library for LÖVE, based on Zanstra's JS implementation (code128.js).
You can simply download the bar128.lua
file from the GitHub repository and include it in your LÖVE project.
Here's an example of how to use the library in a LÖVE program:
local Barcode = require("bar128")
function love.load()
-- Create a new Barcode object with the code "12345"
barcode = Barcode("12345")
end
function love.draw()
-- Draw the barcode at position (100, 100)
barcode:draw('notext', 100, 100)
end
This example will render a barcode with the code "12345" at position (100, 100).
Barcode(code: string|number, barHeight: number, barWidth: number, barcodeType: 'A'|'B'|'C'): Barcode
Creates a new Barcode object with the specified parameters:
code
: The text to be encoded in the barcode.barHeight
: The height of the barcode image in pixels (default: 20).barWidth
: The width of one bar in pixels (default: 1).barcodeType
: The code 128 character set to use ('A'
,'B'
or'C'
). If not provided, the library will detect the charset automatically.
Draws the barcode on the screen.
text
:Indicates whether the text representation should be drawn underneath the barcode.Coming Soon™.x
: The X coordinate of the top-left corner of the barcode.y
: The Y coordinate of the top-left corner of the barcode.
ℹ️ Note that the X/Y position accounts for the initial 'quiet zone' of the barcode.
Returns the current barcode value.
Changes the barcode's value.
code
: The new barcode value.barcodeType
: (Optional) The code 128 character set to use ('A'
,'B'
or'C'
). If not provided, the library will detect the charset automatically.
⚠️ Warning: changing the value causes the barcode to be re-parsed internally. Don't use this too often.
Returns the current bar width.
Changes the base width of bars.
width
: The new bar width in pixels.
Returns the current barcode height.
Changes the barcode's height.
height
: The new barcode height in pixels.
Returns total width of the barcode.
Returns total size of the barcode.
⚠️ Warning: the result ofgetFullWidth
gets cached, so the first invocation aftersetCode
orsetBarWidth
will take slightly longer.getFullSize
also usesgetFullWidth
under the hood.
This library is licensed under the MIT License. See the bar128.lua file for details.