Refactor to use ColorScheme instead of 'depth' approach
This commit is contained in:
1 parent
e966fa7106
commit
30509e0dd7
16 files changed
+83
-81
No files matched your search
+3
-3
@@ -15,7 +15,7 @@ const (
|
||||
// Encodes the given data as PDF417 barcode.
|
||||
// securityLevel should be between 0 and 8. The higher the number, the more
|
||||
// additional error-correction codes are added.
|
||||
func EncodeWithDepth(data string, securityLevel byte, depth int) (barcode.Barcode, error) {
|
||||
func EncodeWithColor(data string, securityLevel byte, color barcode.ColorScheme) (barcode.Barcode, error) {
|
||||
if securityLevel >= 9 {
|
||||
return nil, fmt.Errorf("Invalid security level %d", securityLevel)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func EncodeWithDepth(data string, securityLevel byte, depth int) (barcode.Barcod
|
||||
|
||||
barcode := new(pdfBarcode)
|
||||
barcode.data = data
|
||||
barcode.depth = depth
|
||||
barcode.color = color
|
||||
|
||||
codeWords, err := encodeData(dataWords, columns, sl)
|
||||
if err != nil {
|
||||
@@ -75,7 +75,7 @@ func EncodeWithDepth(data string, securityLevel byte, depth int) (barcode.Barcod
|
||||
// securityLevel should be between 0 and 8. The higher the number, the more
|
||||
// additional error-correction codes are added.
|
||||
func Encode(data string, securityLevel byte) (barcode.Barcode, error) {
|
||||
return EncodeWithDepth(data, securityLevel, 16)
|
||||
return EncodeWithColor(data, securityLevel, barcode.ColorScheme16)
|
||||
}
|
||||
|
||||
func encodeData(dataWords []int, columns int, sl securitylevel) ([]int, error) {
|
||||
|
||||
+4
-4
@@ -12,7 +12,7 @@ type pdfBarcode struct {
|
||||
data string
|
||||
width int
|
||||
code *utils.BitList
|
||||
depth int
|
||||
color barcode.ColorScheme
|
||||
}
|
||||
|
||||
func (c *pdfBarcode) Metadata() barcode.Metadata {
|
||||
@@ -24,7 +24,7 @@ func (c *pdfBarcode) Content() string {
|
||||
}
|
||||
|
||||
func (c *pdfBarcode) ColorModel() color.Model {
|
||||
return utils.ColorModel(c.depth)
|
||||
return c.color.Model
|
||||
}
|
||||
|
||||
func (c *pdfBarcode) Bounds() image.Rectangle {
|
||||
@@ -35,7 +35,7 @@ func (c *pdfBarcode) Bounds() image.Rectangle {
|
||||
|
||||
func (c *pdfBarcode) At(x, y int) color.Color {
|
||||
if c.code.GetBit((y/moduleHeight)*c.width + x) {
|
||||
return utils.BlackColor(c.depth)
|
||||
return c.color.Foreground
|
||||
}
|
||||
return utils.WhiteColor(c.depth)
|
||||
return c.color.Background
|
||||
}
|
||||
Reference in new issue
Block a user