diff options
Diffstat (limited to 'vendor/github.com/boombuler')
-rw-r--r-- | vendor/github.com/boombuler/barcode/.gitignore | 1 | ||||
-rw-r--r-- | vendor/github.com/boombuler/barcode/README.md | 49 | ||||
-rw-r--r-- | vendor/github.com/boombuler/barcode/barcode.go | 21 | ||||
-rw-r--r-- | vendor/github.com/boombuler/barcode/go.mod | 1 | ||||
-rw-r--r-- | vendor/github.com/boombuler/barcode/qr/qrcode.go | 6 | ||||
-rw-r--r-- | vendor/github.com/boombuler/barcode/scaledbarcode.go | 37 | ||||
-rw-r--r-- | vendor/github.com/boombuler/barcode/utils/base1dcode.go | 19 |
7 files changed, 108 insertions, 26 deletions
diff --git a/vendor/github.com/boombuler/barcode/.gitignore b/vendor/github.com/boombuler/barcode/.gitignore new file mode 100644 index 0000000000..1d74e21965 --- /dev/null +++ b/vendor/github.com/boombuler/barcode/.gitignore @@ -0,0 +1 @@ +.vscode/ diff --git a/vendor/github.com/boombuler/barcode/README.md b/vendor/github.com/boombuler/barcode/README.md index 85c34d6390..2a988db399 100644 --- a/vendor/github.com/boombuler/barcode/README.md +++ b/vendor/github.com/boombuler/barcode/README.md @@ -1,18 +1,53 @@ -##Introduction## +[![Join the chat at https://gitter.im/golang-barcode/Lobby](https://badges.gitter.im/golang-barcode/Lobby.svg)](https://gitter.im/golang-barcode/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +## Introduction ## + This is a package for GO which can be used to create different types of barcodes. -##Supported Barcode Types## +## Supported Barcode Types ## +* 2 of 5 * Aztec Code * Codabar * Code 128 * Code 39 -* EAN 8 -* EAN 13 +* Code 93 * Datamatrix -* QR Codes -* 2 of 5 +* EAN 13 +* EAN 8 +* PDF 417 +* QR Code + +## Example ## + +This is a simple example on how to create a QR-Code and write it to a png-file +```go +package main + +import ( + "image/png" + "os" + + "github.com/boombuler/barcode" + "github.com/boombuler/barcode/qr" +) + +func main() { + // Create the barcode + qrCode, _ := qr.Encode("Hello World", qr.M, qr.Auto) + + // Scale the barcode to 200x200 pixels + qrCode, _ = barcode.Scale(qrCode, 200, 200) + + // create the output file + file, _ := os.Create("qrcode.png") + defer file.Close() + + // encode the barcode as png + png.Encode(file, qrCode) +} +``` -##Documentation## +## Documentation ## See [GoDoc](https://godoc.org/github.com/boombuler/barcode) To create a barcode use the Encode function from one of the subpackages. diff --git a/vendor/github.com/boombuler/barcode/barcode.go b/vendor/github.com/boombuler/barcode/barcode.go index 7e147f22f4..25f4a693db 100644 --- a/vendor/github.com/boombuler/barcode/barcode.go +++ b/vendor/github.com/boombuler/barcode/barcode.go @@ -2,6 +2,21 @@ package barcode import "image" +const ( + TypeAztec = "Aztec" + TypeCodabar = "Codabar" + TypeCode128 = "Code 128" + TypeCode39 = "Code 39" + TypeCode93 = "Code 93" + TypeDataMatrix = "DataMatrix" + TypeEAN8 = "EAN 8" + TypeEAN13 = "EAN 13" + TypePDF = "PDF417" + TypeQR = "QR Code" + Type2of5 = "2 of 5" + Type2of5Interleaved = "2 of 5 (interleaved)" +) + // Contains some meta information about a barcode type Metadata struct { // the name of the barcode kind @@ -17,5 +32,11 @@ type Barcode interface { Metadata() Metadata // the data that was encoded in this barcode Content() string +} + +// Additional interface that some barcodes might implement to provide +// the value of its checksum. +type BarcodeIntCS interface { + Barcode CheckSum() int } diff --git a/vendor/github.com/boombuler/barcode/go.mod b/vendor/github.com/boombuler/barcode/go.mod new file mode 100644 index 0000000000..ed53593b92 --- /dev/null +++ b/vendor/github.com/boombuler/barcode/go.mod @@ -0,0 +1 @@ +module github.com/boombuler/barcode diff --git a/vendor/github.com/boombuler/barcode/qr/qrcode.go b/vendor/github.com/boombuler/barcode/qr/qrcode.go index ab123ce8fc..13607604bb 100644 --- a/vendor/github.com/boombuler/barcode/qr/qrcode.go +++ b/vendor/github.com/boombuler/barcode/qr/qrcode.go @@ -20,7 +20,7 @@ func (qr *qrcode) Content() string { } func (qr *qrcode) Metadata() barcode.Metadata { - return barcode.Metadata{"QR Code", 2} + return barcode.Metadata{barcode.TypeQR, 2} } func (qr *qrcode) ColorModel() color.Model { @@ -46,10 +46,6 @@ func (qr *qrcode) Set(x, y int, val bool) { qr.data.SetBit(x*qr.dimension+y, val) } -func (qr *qrcode) CheckSum() int { - return 0 -} - func (qr *qrcode) calcPenalty() uint { return qr.calcPenaltyRule1() + qr.calcPenaltyRule2() + qr.calcPenaltyRule3() + qr.calcPenaltyRule4() } diff --git a/vendor/github.com/boombuler/barcode/scaledbarcode.go b/vendor/github.com/boombuler/barcode/scaledbarcode.go index c59c9fe7b7..152b180174 100644 --- a/vendor/github.com/boombuler/barcode/scaledbarcode.go +++ b/vendor/github.com/boombuler/barcode/scaledbarcode.go @@ -16,6 +16,10 @@ type scaledBarcode struct { rect image.Rectangle } +type intCSscaledBC struct { + scaledBarcode +} + func (bc *scaledBarcode) Content() string { return bc.wrapped.Content() } @@ -36,8 +40,11 @@ func (bc *scaledBarcode) At(x, y int) color.Color { return bc.wrapperFunc(x, y) } -func (bc *scaledBarcode) CheckSum() int { - return bc.wrapped.CheckSum() +func (bc *intCSscaledBC) CheckSum() int { + if cs, ok := bc.wrapped.(BarcodeIntCS); ok { + return cs.CheckSum() + } + return 0 } // Scale returns a resized barcode with the given width and height. @@ -52,6 +59,19 @@ func Scale(bc Barcode, width, height int) (Barcode, error) { return nil, errors.New("unsupported barcode format") } +func newScaledBC(wrapped Barcode, wrapperFunc wrapFunc, rect image.Rectangle) Barcode { + result := &scaledBarcode{ + wrapped: wrapped, + wrapperFunc: wrapperFunc, + rect: rect, + } + + if _, ok := wrapped.(BarcodeIntCS); ok { + return &intCSscaledBC{*result} + } + return result +} + func scale2DCode(bc Barcode, width, height int) (Barcode, error) { orgBounds := bc.Bounds() orgWidth := orgBounds.Max.X - orgBounds.Min.X @@ -59,7 +79,7 @@ func scale2DCode(bc Barcode, width, height int) (Barcode, error) { factor := int(math.Min(float64(width)/float64(orgWidth), float64(height)/float64(orgHeight))) if factor <= 0 { - return nil, fmt.Errorf("can not scale barcode to an image smaller then %dx%d", orgWidth, orgHeight) + return nil, fmt.Errorf("can not scale barcode to an image smaller than %dx%d", orgWidth, orgHeight) } offsetX := (width - (orgWidth * factor)) / 2 @@ -77,11 +97,11 @@ func scale2DCode(bc Barcode, width, height int) (Barcode, error) { return bc.At(x, y) } - return &scaledBarcode{ + return newScaledBC( bc, wrap, image.Rect(0, 0, width, height), - }, nil + ), nil } func scale1DCode(bc Barcode, width, height int) (Barcode, error) { @@ -90,7 +110,7 @@ func scale1DCode(bc Barcode, width, height int) (Barcode, error) { factor := int(float64(width) / float64(orgWidth)) if factor <= 0 { - return nil, fmt.Errorf("can not scale barcode to an image smaller then %dx1", orgWidth) + return nil, fmt.Errorf("can not scale barcode to an image smaller than %dx1", orgWidth) } offsetX := (width - (orgWidth * factor)) / 2 @@ -106,10 +126,9 @@ func scale1DCode(bc Barcode, width, height int) (Barcode, error) { return bc.At(x, 0) } - return &scaledBarcode{ + return newScaledBC( bc, wrap, image.Rect(0, 0, width, height), - }, nil - + ), nil } diff --git a/vendor/github.com/boombuler/barcode/utils/base1dcode.go b/vendor/github.com/boombuler/barcode/utils/base1dcode.go index 22a2e30205..a335c0c741 100644 --- a/vendor/github.com/boombuler/barcode/utils/base1dcode.go +++ b/vendor/github.com/boombuler/barcode/utils/base1dcode.go @@ -10,8 +10,12 @@ import ( type base1DCode struct { *BitList - kind string - content string + kind string + content string +} + +type base1DCodeIntCS struct { + base1DCode checksum int } @@ -38,11 +42,16 @@ func (c *base1DCode) At(x, y int) color.Color { return color.White } -func (c *base1DCode) CheckSum() int { +func (c *base1DCodeIntCS) CheckSum() int { return c.checksum } +// New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList +func New1DCodeIntCheckSum(codeKind, content string, bars *BitList, checksum int) barcode.BarcodeIntCS { + return &base1DCodeIntCS{base1DCode{bars, codeKind, content}, checksum} +} + // New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList -func New1DCode(codeKind, content string, bars *BitList, checksum int) barcode.Barcode { - return &base1DCode{bars, codeKind, content, checksum} +func New1DCode(codeKind, content string, bars *BitList) barcode.Barcode { + return &base1DCode{bars, codeKind, content} } |