Home

Awesome

bar128-love

Barcode rendering library for LÖVE, based on Zanstra's JS implementation (code128.js).

Installation

You can simply download the bar128.lua file from the GitHub repository and include it in your LÖVE project.

Usage

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).

Public Methods

Constructor

Barcode(code: string|number, barHeight: number, barWidth: number, barcodeType: 'A'|'B'|'C'): Barcode

Creates a new Barcode object with the specified parameters:

Drawing

draw(text: 'notext'|'text', x: number, y: number)

Draws the barcode on the screen.

ℹ️ Note that the X/Y position accounts for the initial 'quiet zone' of the barcode.

Getters and Setters

getCode(): string|number

Returns the current barcode value.

setCode(code: string|number, barcodeType: 'A'|'B'|'C')

Changes the barcode's value.

⚠️ Warning: changing the value causes the barcode to be re-parsed internally. Don't use this too often.

getBarWidth(): number

Returns the current bar width.

setBarWidth(width: number)

Changes the base width of bars.

getBarHeight(): number

Returns the current barcode height.

setBarHeight(height: number)

Changes the barcode's height.

getFullWidth(): number

Returns total width of the barcode.

getFullSize(): number, number

Returns total size of the barcode.

⚠️ Warning: the result of getFullWidth gets cached, so the first invocation after setCode or setBarWidth will take slightly longer. getFullSize also uses getFullWidth under the hood.

License

This library is licensed under the MIT License. See the bar128.lua file for details.