add support for depth in barcode generations

- Introduced depth parameter to EncodeWithDepth function to allow generating barcodes with specified color depth.
- Updated Encode function to use EncodeWithDepth with a default depth of 16.
This commit is contained in:
zhaori96 committed 2024-07-24 10:29:23 -03:00
1 parent f3630e1cd4
commit 87ab0677e3
15 files changed
+114 -47

No files matched your search

+8 -3
View File
@@ -158,7 +158,7 @@ func encodeEAN13(code string) *utils.BitList {
}
// Encode returns a EAN 8 or EAN 13 barcode for the given code
func Encode(code string) (barcode.BarcodeIntCS, error) {
func EncodeWithDepth(code string, depth int) (barcode.BarcodeIntCS, error) {
var checkSum int
if len(code) == 7 || len(code) == 12 {
code += string(calcCheckNum(code))
@@ -175,13 +175,18 @@ func Encode(code string) (barcode.BarcodeIntCS, error) {
if len(code) == 8 {
result := encodeEAN8(code)
if result != nil {
return utils.New1DCodeIntCheckSum(barcode.TypeEAN8, code, result, checkSum), nil
return utils.New1DCodeIntCheckSumWithDepth(barcode.TypeEAN8, code, result, checkSum, depth), nil
}
} else if len(code) == 13 {
result := encodeEAN13(code)
if result != nil {
return utils.New1DCodeIntCheckSum(barcode.TypeEAN13, code, result, checkSum), nil
return utils.New1DCodeIntCheckSumWithDepth(barcode.TypeEAN13, code, result, checkSum, depth), nil
}
}
return nil, errors.New("invalid ean code data")
}
// Encode returns a EAN 8 or EAN 13 barcode for the given code
func Encode(code string) (barcode.BarcodeIntCS, error) {
return EncodeWithDepth(code, 16)
}