Merge pull request #22 from aaronarduino/add-barcode-const
added constants for barcode types
This commit is contained in:
commit
56ef0af912
|
@ -24,7 +24,7 @@ func (c *aztecCode) Content() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) Metadata() barcode.Metadata {
|
func (c *aztecCode) Metadata() barcode.Metadata {
|
||||||
return barcode.Metadata{"Aztec", 2}
|
return barcode.Metadata{barcode.TypeAztec, 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) ColorModel() color.Model {
|
func (c *aztecCode) ColorModel() color.Model {
|
||||||
|
|
15
barcode.go
15
barcode.go
|
@ -2,6 +2,21 @@ package barcode
|
||||||
|
|
||||||
import "image"
|
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
|
// Contains some meta information about a barcode
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
// the name of the barcode kind
|
// the name of the barcode kind
|
||||||
|
|
|
@ -45,5 +45,5 @@ func Encode(content string) (barcode.Barcode, error) {
|
||||||
}
|
}
|
||||||
resBits.AddBit(encodingTable[r]...)
|
resBits.AddBit(encodingTable[r]...)
|
||||||
}
|
}
|
||||||
return utils.New1DCode("Codabar", content, resBits), nil
|
return utils.New1DCode(barcode.TypeCodabar, content, resBits), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ func Encode(content string) (barcode.BarcodeIntCS, error) {
|
||||||
sum = sum % 103
|
sum = sum % 103
|
||||||
result.AddBit(encodingTable[sum]...)
|
result.AddBit(encodingTable[sum]...)
|
||||||
result.AddBit(encodingTable[stopSymbol]...)
|
result.AddBit(encodingTable[stopSymbol]...)
|
||||||
return utils.New1DCodeIntCheckSum("Code 128", content, result, sum), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeCode128, content, result, sum), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncodeWithoutChecksum(content string) (barcode.Barcode, error) {
|
func EncodeWithoutChecksum(content string) (barcode.Barcode, error) {
|
||||||
|
@ -199,5 +199,5 @@ func EncodeWithoutChecksum(content string) (barcode.Barcode, error) {
|
||||||
result.AddBit(encodingTable[idx]...)
|
result.AddBit(encodingTable[idx]...)
|
||||||
}
|
}
|
||||||
result.AddBit(encodingTable[stopSymbol]...)
|
result.AddBit(encodingTable[stopSymbol]...)
|
||||||
return utils.New1DCode("Code 128", content, result), nil
|
return utils.New1DCode(barcode.TypeCode128, content, result), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,5 +148,5 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B
|
||||||
if err != nil {
|
if err != nil {
|
||||||
checkSum = 0
|
checkSum = 0
|
||||||
}
|
}
|
||||||
return utils.New1DCodeIntCheckSum("Code 39", content, result, int(checkSum)), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeCode39, content, result, int(checkSum)), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B
|
||||||
}
|
}
|
||||||
result.AddBit(true)
|
result.AddBit(true)
|
||||||
|
|
||||||
return utils.New1DCode("Code 93", content, result), nil
|
return utils.New1DCode(barcode.TypeCode93, content, result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getChecksum(content string, maxWeight int) rune {
|
func getChecksum(content string, maxWeight int) rune {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package datamatrix
|
package datamatrix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/boombuler/barcode"
|
|
||||||
"github.com/boombuler/barcode/utils"
|
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
|
"github.com/boombuler/barcode"
|
||||||
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type datamatrixCode struct {
|
type datamatrixCode struct {
|
||||||
|
@ -22,7 +23,7 @@ func (c *datamatrixCode) Content() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) Metadata() barcode.Metadata {
|
func (c *datamatrixCode) Metadata() barcode.Metadata {
|
||||||
return barcode.Metadata{"DataMatrix", 2}
|
return barcode.Metadata{barcode.TypeDataMatrix, 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) ColorModel() color.Model {
|
func (c *datamatrixCode) ColorModel() color.Model {
|
||||||
|
|
|
@ -175,12 +175,12 @@ func Encode(code string) (barcode.BarcodeIntCS, error) {
|
||||||
if len(code) == 8 {
|
if len(code) == 8 {
|
||||||
result := encodeEAN8(code)
|
result := encodeEAN8(code)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
return utils.New1DCodeIntCheckSum("EAN 8", code, result, checkSum), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeEAN8, code, result, checkSum), nil
|
||||||
}
|
}
|
||||||
} else if len(code) == 13 {
|
} else if len(code) == 13 {
|
||||||
result := encodeEAN13(code)
|
result := encodeEAN13(code)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
return utils.New1DCodeIntCheckSum("EAN 13", code, result, checkSum), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeEAN13, code, result, checkSum), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.New("invalid ean code data")
|
return nil, errors.New("invalid ean code data")
|
||||||
|
|
|
@ -15,7 +15,7 @@ type pdfBarcode struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) Metadata() barcode.Metadata {
|
func (c *pdfBarcode) Metadata() barcode.Metadata {
|
||||||
return barcode.Metadata{"PDF417", 2}
|
return barcode.Metadata{barcode.TypePDF, 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) Content() string {
|
func (c *pdfBarcode) Content() string {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (qr *qrcode) Content() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) Metadata() barcode.Metadata {
|
func (qr *qrcode) Metadata() barcode.Metadata {
|
||||||
return barcode.Metadata{"QR Code", 2}
|
return barcode.Metadata{barcode.TypeQR, 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) ColorModel() color.Model {
|
func (qr *qrcode) ColorModel() color.Model {
|
||||||
|
|
|
@ -130,9 +130,9 @@ func Encode(content string, interleaved bool) (barcode.Barcode, error) {
|
||||||
|
|
||||||
resBits.AddBit(mode.end...)
|
resBits.AddBit(mode.end...)
|
||||||
|
|
||||||
kindTxt := ""
|
|
||||||
if interleaved {
|
if interleaved {
|
||||||
kindTxt = " (interleaved)"
|
return utils.New1DCode(barcode.Type2of5Interleaved, content, resBits), nil
|
||||||
|
} else {
|
||||||
|
return utils.New1DCode(barcode.Type2of5, content, resBits), nil
|
||||||
}
|
}
|
||||||
return utils.New1DCode("2 of 5"+kindTxt, content, resBits), nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue