You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
981 B

  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. checksum int
  13. }
  14. func (c *base1DCode) Content() string {
  15. return c.content
  16. }
  17. func (c *base1DCode) Metadata() barcode.Metadata {
  18. return barcode.Metadata{c.kind, 1}
  19. }
  20. func (c *base1DCode) ColorModel() color.Model {
  21. return color.Gray16Model
  22. }
  23. func (c *base1DCode) Bounds() image.Rectangle {
  24. return image.Rect(0, 0, c.Len(), 1)
  25. }
  26. func (c *base1DCode) At(x, y int) color.Color {
  27. if c.GetBit(x) {
  28. return color.Black
  29. }
  30. return color.White
  31. }
  32. func (c *base1DCode) CheckSum() int {
  33. return c.checksum
  34. }
  35. // New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
  36. func New1DCode(codeKind, content string, bars *BitList, checksum int) barcode.Barcode {
  37. return &base1DCode{bars, codeKind, content, checksum}
  38. }