2013-12-11 13:31:11 +00:00
|
|
|
package ean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/boombuler/barcode"
|
2013-12-13 12:53:27 +00:00
|
|
|
"github.com/boombuler/barcode/utils"
|
2013-12-11 13:31:11 +00:00
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
|
|
|
type eancode struct {
|
2013-12-13 12:53:27 +00:00
|
|
|
*utils.BitList
|
2013-12-11 13:31:11 +00:00
|
|
|
content string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newEANCode(isEAN8 bool) *eancode {
|
|
|
|
capacity := 95
|
|
|
|
if isEAN8 {
|
|
|
|
capacity = 67
|
|
|
|
}
|
2013-12-13 12:53:27 +00:00
|
|
|
return &eancode{utils.NewBitList(capacity), ""}
|
2013-12-11 13:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *eancode) Content() string {
|
|
|
|
return c.content
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *eancode) Metadata() barcode.Metadata {
|
|
|
|
if c.Len() == 67 {
|
|
|
|
return barcode.Metadata{"EAN 8", 1}
|
|
|
|
}
|
|
|
|
return barcode.Metadata{"EAN 13", 1}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *eancode) ColorModel() color.Model {
|
|
|
|
return color.Gray16Model
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *eancode) Bounds() image.Rectangle {
|
|
|
|
return image.Rect(0, 0, c.Len(), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *eancode) At(x, y int) color.Color {
|
|
|
|
if c.GetBit(x) {
|
|
|
|
return color.Black
|
|
|
|
}
|
|
|
|
return color.White
|
|
|
|
}
|