ExBarcode.Code128 (ex_barcode v0.1.0)

Copy Markdown View Source

Code 128 barcode encoder.

Encodes a string into a list of bar widths suitable for rendering. Supports Code 128B (full ASCII) with automatic Code C optimization for runs of digit pairs.

Reference

Code 128 uses three character sets (A, B, C). This implementation primarily uses Code B (covers ASCII 32–127) with automatic switching to Code C for efficient encoding of digit pairs.

Summary

Functions

Encode a string into Code 128 bar pattern.

Same as encode/1 but raises on error.

Calculate the total width in modules (unit bar widths) for a given text.

Functions

encode(text)

@spec encode(String.t()) :: {:ok, [integer()]} | {:error, atom()}

Encode a string into Code 128 bar pattern.

Returns {:ok, bars} where bars is a flat list of integers representing alternating bar and space widths (starting with a bar).

Returns {:error, reason} if the input contains unsupported characters.

encode!(text)

Same as encode/1 but raises on error.

total_modules(text)

Calculate the total width in modules (unit bar widths) for a given text.