Compare commits

...

3 Commits

Author SHA1 Message Date
Fred Boniface 5e1cf45c58 Fix codabar generation 2023-09-04 12:18:11 +01:00
Fred Boniface 0b2effd135 Implement EAN and improve Code39 error handling 2023-09-04 12:11:45 +01:00
Fred Boniface 54fa0d34ad Add Code39 2023-09-04 12:05:16 +01:00
6 changed files with 60 additions and 22 deletions

View File

@ -8,7 +8,7 @@ import (
)
func generateCodabar(parameters Parameters) (barcode.Barcode, error) {
codabarItem, err := codabar.Encode(parameters.Content)
codabarItem, err := codabar.Encode("A" + parameters.Content + "B")
if err != nil {
fmt.Println("Error creating Barcode", err)
}

19
generation/code39.go Normal file
View File

@ -0,0 +1,19 @@
package generation
import (
"fmt"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/code39"
)
func generateCode39(parameters Parameters) (barcode.Barcode, error) {
var strippedBarcode barcode.Barcode
GeneratedBarcode, err := code39.Encode(parameters.Content, true, true)
if err != nil {
fmt.Println("Error creating Barcode", err)
} else {
strippedBarcode = GeneratedBarcode.(barcode.Barcode)
}
return strippedBarcode, err
}

20
generation/ean.go Normal file
View File

@ -0,0 +1,20 @@
package generation
import (
"fmt"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/ean"
)
func generateEAN(parameters Parameters) (barcode.Barcode, error) {
var strippedBarcode barcode.Barcode
GeneratedBarcode, err := ean.Encode(parameters.Content)
if err != nil {
fmt.Println("Error creating Barcode", err)
} else {
strippedBarcode = GeneratedBarcode.(barcode.Barcode)
}
return strippedBarcode, err
}

View File

@ -29,6 +29,10 @@ func Generate(parameters Parameters) (barcode.Barcode, error) {
barcode_content, err = generate2of5Interleaved(parameters)
case TwoOfFive:
barcode_content, err = generate2of5(parameters)
case Code39:
barcode_content, err = generateCode39(parameters)
case EAN:
barcode_content, err = generateEAN(parameters)
default:
fmt.Println("Unsupported barcode type: ", parameters.Format)
}

View File

@ -12,6 +12,8 @@ const (
PDF417 BarcodeType = "pdf417"
TwoOfFive BarcodeType = "2of5"
TwoOfFiveInterleaved BarcodeType = "2of5interleaved"
Code39 BarcodeType = "code39"
EAN BarcodeType = "ean"
)
type ECCLevel int

View File

@ -41,13 +41,13 @@ var FormatRules = map[string]rule{
divisible: 1,
},
/* "code39": {
"code39": {
minLength: 1,
maxLength: 80,
charset: *CODE39,
charset: *ASCII,
divisible: 1,
},
*/
"code93": {
minLength: 1,
maxLength: 80,
@ -68,21 +68,14 @@ var FormatRules = map[string]rule{
charset: *ANY,
divisible: 1,
},
/*
"ean8": {
minLength: 7,
maxLength: 7,
charset: *NUMERAL,
divisible: 1,
},
"ean13": {
minLength: 12,
"ean": {
minLength: 7,
maxLength: 12,
charset: *NUMERAL,
divisible: 1,
},
*/
"pdf417": {
minLength: 1,
maxLength: 1100,