Refactor to use ColorScheme instead of 'depth' approach

This commit is contained in:
zhaori96 committed 2024-07-31 16:11:52 -03:00
1 parent e966fa7106
commit 30509e0dd7
16 files changed
+83 -81

No files matched your search

+3 -3
View File
@@ -33,7 +33,7 @@ var encodingTable = map[rune][]bool{
}
// Encode creates a codabar barcode for the given content
func EncodeWithDepth(content string, depth int) (barcode.Barcode, error) {
func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
checkValid, _ := regexp.Compile(`[ABCD][0123456789\-\$\:/\.\+]*[ABCD]$`)
if content == "!" || checkValid.ReplaceAllString(content, "!") != "!" {
return nil, fmt.Errorf("can not encode \"%s\"", content)
@@ -45,10 +45,10 @@ func EncodeWithDepth(content string, depth int) (barcode.Barcode, error) {
}
resBits.AddBit(encodingTable[r]...)
}
return utils.New1DCodeWithDepth(barcode.TypeCodabar, content, resBits, depth), nil
return utils.New1DCodeWithColor(barcode.TypeCodabar, content, resBits, color), nil
}
// Encode creates a codabar barcode for the given content
func Encode(content string) (barcode.Barcode, error) {
return EncodeWithDepth(content, 16)
return EncodeWithColor(content, barcode.ColorScheme16)
}