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:
1 parent
f3630e1cd4
commit
87ab0677e3
15 files changed
+114
-47
No files matched your search
+7
-2
@@ -33,7 +33,7 @@ var encodingTable = map[rune][]bool{
|
||||
}
|
||||
|
||||
// Encode creates a codabar barcode for the given content
|
||||
func Encode(content string) (barcode.Barcode, error) {
|
||||
func EncodeWithDepth(content string, depth int) (barcode.Barcode, error) {
|
||||
checkValid, _ := regexp.Compile(`[ABCD][0123456789\-\$\:/\.\+]*[ABCD]$`)
|
||||
if content == "!" || checkValid.ReplaceAllString(content, "!") != "!" {
|
||||
return nil, fmt.Errorf("can not encode \"%s\"", content)
|
||||
@@ -45,5 +45,10 @@ func Encode(content string) (barcode.Barcode, error) {
|
||||
}
|
||||
resBits.AddBit(encodingTable[r]...)
|
||||
}
|
||||
return utils.New1DCode(barcode.TypeCodabar, content, resBits), nil
|
||||
return utils.New1DCodeWithDepth(barcode.TypeCodabar, content, resBits, depth), nil
|
||||
}
|
||||
|
||||
// Encode creates a codabar barcode for the given content
|
||||
func Encode(content string) (barcode.Barcode, error) {
|
||||
return EncodeWithDepth(content, 16)
|
||||
}
|
||||
Reference in new issue
Block a user