Documentation
¶
Overview ¶
Package barcodes encodes a value into the stripe geometry a printout carries.
See doc/printout.md#barcode. A renderer does not need to implement encoding of its own.
Index ¶
Constants ¶
const ( MinHeightRatio = 0.15 MinHeightPt = 18 // 0.25 in )
MinHeightRatio is a one-dimensional symbol's minimum bar height as a fraction of its length, and MinHeightPt the floor under that. Together they are the usual recommendation: fifteen per cent of the symbol length, or a quarter of an inch, whichever is greater.
const ( // MinSymbolContrast is the reflectance difference between paper // and ink that a symbol needs. ISO/IEC 15416 grades this parameter, // and forty per cent is its grade C, the usual floor for retail. MinSymbolContrast = 0.40 // MaxInkFraction is the most of the paper's own reflectance that the // ink may reflect, which is the standard's minimum-reflectance rule. MaxInkFraction = 0.5 )
Scan contrast thresholds, as fractions of full reflectance.
A barcode is read in red light -- around 660 nm for a laser scanner and for most linear imagers, and 670 nm is where ISO/IEC 15416 measures the contrast it grades. So what decides whether a symbol scans is how little red it reflects, not how dark a colour looks. Blue, green, brown and purple bars absorb red and read as bars; red, orange and yellow ones reflect it and are very nearly invisible. The same fact in reverse makes yellow, orange and pink perfectly good backgrounds, and blue or green ones unusable.
const QuietModules = 10
QuietModules is the quiet zone added to each end of a one-dimensional symbol, in modules. Ten is the usual minimum for the symbologies here.
Variables ¶
This section is empty.
Functions ¶
func CheckContrast ¶
CheckContrast reports whether bars of one colour on paper of another can be read, judging both by the red light a scanner uses. Only the red component of each colour is consulted, for the reason above.
The judgement is deliberately coarse. It works from the colours a template names and cannot know what the ink, the substrate, or the printer will do to them, so it catches the combinations that cannot work in principle -- yellow bars, a navy background -- and nothing subtler. A symbol going into production still wants verifying off a printed label.
Types ¶
type Metrics ¶
type Metrics struct {
// Length is the extent along the coding direction, in points.
Length float64
// Cross is the extent across it, in points.
Cross float64
// Module is the narrow-element width in points, after any grow adjustment.
Module float64
}
Metrics is a symbol placed at a module width.
type Symbol ¶
type Symbol struct {
// Type is the symbology, as the template spells it.
Type string
// Value is the encoded string, recorded for renderers printing
// bar codes directly -- such as barcode printer drivers.
Value string
// TwoD reports whether the symbol is a matrix rather than a bar pattern.
TwoD bool
// Stripes for a one-dimensional symbol: alternating space and bar widths,
// starting with a space, which is the leading quiet zone.
Stripes []int
// Rows for a two-dimensional symbol: per row, alternating light and dark
// run lengths, starting with light. A row that opens dark -- which only
// a symbology with no quiet zone can do -- opens with a zero-length
// light run.
Rows [][]int
// Modules is the symbol's extent along the coding direction,
// in modules, quiet zones included.
Modules int
// CrossModules is the extent across the coding direction, in modules.
// It is meaningful only for a two-dimensional symbol.
CrossModules int
}
Symbol is an encoded barcode, in modules.