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

+9 -4
View File
@@ -78,8 +78,8 @@ func AddCheckSum(content string) (string, error) {
return content + string(utils.IntToRune(sum%10)), nil
}
// Encode creates a codabar barcode for the given content
func Encode(content string, interleaved bool) (barcode.Barcode, error) {
// Encode creates a codabar barcode for the given content and depth
func EncodeWithDepth(content string, interleaved bool, depth int) (barcode.Barcode, error) {
if content == "" {
return nil, errors.New("content is empty")
}
@@ -131,8 +131,13 @@ func Encode(content string, interleaved bool) (barcode.Barcode, error) {
resBits.AddBit(mode.end...)
if interleaved {
return utils.New1DCode(barcode.Type2of5Interleaved, content, resBits), nil
return utils.New1DCodeWithDepth(barcode.Type2of5Interleaved, content, resBits, depth), nil
} else {
return utils.New1DCode(barcode.Type2of5, content, resBits), nil
return utils.New1DCodeWithDepth(barcode.Type2of5, content, resBits, depth), nil
}
}
// Encode creates a codabar barcode for the given content
func Encode(content string, interleaved bool) (barcode.Barcode, error) {
return EncodeWithDepth(content, interleaved, 16)
}