base1dcode.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Package utils contain some utilities which are needed to create barcodes
  2. package utils
  3. import (
  4. "image"
  5. "image/color"
  6. "github.com/boombuler/barcode"
  7. )
  8. type base1DCode struct {
  9. *BitList
  10. kind string
  11. content string
  12. }
  13. type base1DCodeIntCS struct {
  14. base1DCode
  15. checksum int
  16. }
  17. func (c *base1DCode) Content() string {
  18. return c.content
  19. }
  20. func (c *base1DCode) Metadata() barcode.Metadata {
  21. return barcode.Metadata{c.kind, 1}
  22. }
  23. func (c *base1DCode) ColorModel() color.Model {
  24. return color.Gray16Model
  25. }
  26. func (c *base1DCode) Bounds() image.Rectangle {
  27. return image.Rect(0, 0, c.Len(), 1)
  28. }
  29. func (c *base1DCode) At(x, y int) color.Color {
  30. if c.GetBit(x) {
  31. return color.Black
  32. }
  33. return color.White
  34. }
  35. func (c *base1DCodeIntCS) CheckSum() int {
  36. return c.checksum
  37. }
  38. // New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList
  39. func New1DCodeIntCheckSum(codeKind, content string, bars *BitList, checksum int) barcode.BarcodeIntCS {
  40. return &base1DCodeIntCS{base1DCode{bars, codeKind, content}, checksum}
  41. }
  42. // New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
  43. func New1DCode(codeKind, content string, bars *BitList) barcode.Barcode {
  44. return &base1DCode{bars, codeKind, content}
  45. }