eancode.go 758 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package ean
  2. import (
  3. "github.com/boombuler/barcode"
  4. "image"
  5. "image/color"
  6. )
  7. type eancode struct {
  8. *barcode.BitList
  9. content string
  10. }
  11. func newEANCode(isEAN8 bool) *eancode {
  12. capacity := 95
  13. if isEAN8 {
  14. capacity = 67
  15. }
  16. return &eancode{barcode.NewBitList(capacity), ""}
  17. }
  18. func (c *eancode) Content() string {
  19. return c.content
  20. }
  21. func (c *eancode) Metadata() barcode.Metadata {
  22. if c.Len() == 67 {
  23. return barcode.Metadata{"EAN 8", 1}
  24. }
  25. return barcode.Metadata{"EAN 13", 1}
  26. }
  27. func (c *eancode) ColorModel() color.Model {
  28. return color.Gray16Model
  29. }
  30. func (c *eancode) Bounds() image.Rectangle {
  31. return image.Rect(0, 0, c.Len(), 1)
  32. }
  33. func (c *eancode) At(x, y int) color.Color {
  34. if c.GetBit(x) {
  35. return color.Black
  36. }
  37. return color.White
  38. }