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
- func Kind(name string) string
- func Kinds() []string
- type Mark
- type Options
- type Symbol
- func (s *Symbol) At(x, y int) bool
- func (s *Symbol) BarHeight(w, h float32) float32
- func (s *Symbol) Bars() (x0, x1 int)
- func (s *Symbol) Fill(o *bdf.Object, x, y, w, h float32)
- func (s *Symbol) HasText() bool
- func (s *Symbol) Mark(x, y, w, h float32) string
- func (s *Symbol) Object(w, h float32) *bdf.Object
- func (s *Symbol) Path(x, y, w, h float32) *bdf.Path
- func (s *Symbol) Rects() [][4]int
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 Mark ¶ added in v0.2.0
type Mark struct {
// Kind is the symbology, and Text what the symbol says (with the
// check digit Encode adds).
Kind string `json:"kind"`
Text string `json:"text"`
// Level is the level of error correction of a QR code.
Level string `json:"level,omitempty"`
// Quiet is Options.Quiet: 0 the quiet zone of the symbology, -1
// none, else its modules.
Quiet int `json:"quiet,omitempty"`
// NoText is set when the drawing has no digits under the bars.
NoText bool `json:"noText,omitempty"`
// Box is the box the symbol and its quiet zone are drawn in (x, y,
// width, height), in the units of the drawing after the mark: the box
// of Symbol.Path.
Box [4]float32 `json:"box"`
}
Mark is what a BARCODE mark of a drawing says (bdf.MarkBarcode, docs/spec.md §7.8): the symbol that the drawing after it draws, and the box it is drawn in. A printer of labels prints such a symbol with its own barcode commands, and a raster of few dots an inch draws its modules on whole dots; anything else draws the drawing as it is.
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) BarHeight ¶ added in v0.2.0
BarHeight returns the height of the bars of the symbol drawn in a box w × h by Path: h less the room of the digits.
func (*Symbol) Bars ¶ added in v0.2.0
Bars returns the columns of the symbol's first and last dark modules (x1 is past the last): the symbol without its quiet zone.
func (*Symbol) Fill ¶ added in v0.2.0
Fill draws the symbol in the box at (x, y) of the size w × h on an object, in its fill colour, after the BARCODE mark that says what it is.
func (*Symbol) Mark ¶ added in v0.2.0
Mark returns the payload of the BARCODE mark of the symbol drawn in the box at (x, y) of the size w × h, as Path draws it.
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.