base1dcode.go 881 B

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