Documentation
¶
Overview ¶
Package barcode makes QR codes and barcodes as drawings: the symbols that forms carry for the machines that read them (slips, labels, invoices).
Encode makes a symbol of a text: a QR code (model 2, versions 1 to 40, the four levels of error correction, in the numeric, alphanumeric or byte mode that the text needs), or a linear barcode: JAN/EAN-13, EAN-8, UPC-A, Code 39, Code 128, GS1-128, ITF (interleaved 2 of 5, ITF-14) and NW-7 (Codabar). A symbol is a grid of modules with its quiet zone, and Path draws its dark modules in a box, with human-readable digits for JAN/EAN and UPC-A: as vectors, which stay sharp at any size and in print.
The package writes symbols; it does not read them. It does not check what a text means (that the digits of a JAN code are those of a product), only that the symbology can hold it, and the check digits that a symbology has.
Digit outlines derived from M PLUS 1p Regular 1.062. Copyright 2016 The M+ Project Authors. Licensed under the SIL Open Font License 1.1; see OFL-MPLUS.txt. The outlines use font coordinates (y up), with an advance of 620.
Index ¶
Constants ¶
const ( QR = "qr" EAN13 = "ean13" // JAN (13 digits) EAN8 = "ean8" // JAN (8 digits) UPCA = "upca" Code39 = "code39" Code128 = "code128" GS1128 = "gs1-128" ITF = "itf" ITF14 = "itf14" NW7 = "nw7" // Codabar )
The symbologies.
const MaxText = 8192
MaxText bounds the text of a symbol, in bytes: more than a QR code holds.
const NoQuiet = -1
NoQuiet is the Options.Quiet of a symbol without a quiet zone.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Level is the level of error correction of a QR code: "L" (7% of
// the symbol may be lost), "M" (15%, the default), "Q" (25%) or "H"
// (30%).
Level string
// Quiet is the width of the quiet zone around the symbol in modules:
// the white margin readers need. 0 is that of the symbology (4
// modules around a QR code, 10 at the sides of most barcodes), and
// NoQuiet none: the margin is then for what is around the symbol to
// leave.
Quiet int
// NoText leaves out the human-readable digits of JAN/EAN and UPC-A.
// The digits are drawn by Path and Object by default, including a
// check digit added by Encode. The modules are unchanged either way.
NoText bool
}
Options are the options of a symbol.
type Symbol ¶
type Symbol struct {
// Kind is the symbology.
Kind string
// Text is what the symbol says: the text, with the check digit of
// the symbology when the text came without it.
Text string
// W and H are the size of the grid with its quiet zone, in modules.
// A linear barcode is a module high; Path leaves room for the digits
// of JAN/EAN and UPC-A inside the box where it draws the bars.
W, H int
// Linear is set for a barcode of bars.
Linear bool
// contains filtered or unexported fields
}
Symbol is a symbol: a grid of modules, dark or light.
func (*Symbol) Object ¶
Object returns the symbol as an object of the size w × h: its dark modules and, for JAN/EAN and UPC-A, its digits, in black on nothing. Options.NoText leaves out the digits. The object needs no font.
func (*Symbol) Path ¶
Path returns the symbol (and its quiet zone) in the box at (x, y) of the size w × h. Its dark modules are rectangles. JAN/EAN and UPC-A also have their digits below the bars unless Options.NoText was set; the bars are shortened to leave room inside the box. The digits are outlines, so no font is needed. Fill the path with the nonzero rule.