datamatrixcode.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package datamatrix
  2. import (
  3. "image"
  4. "image/color"
  5. "github.com/boombuler/barcode"
  6. "github.com/boombuler/barcode/utils"
  7. )
  8. type datamatrixCode struct {
  9. *utils.BitList
  10. *dmCodeSize
  11. content string
  12. }
  13. func newDataMatrixCode(size *dmCodeSize) *datamatrixCode {
  14. return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, ""}
  15. }
  16. func (c *datamatrixCode) Content() string {
  17. return c.content
  18. }
  19. func (c *datamatrixCode) Metadata() barcode.Metadata {
  20. return barcode.Metadata{barcode.TypeDataMatrix, 2}
  21. }
  22. func (c *datamatrixCode) ColorModel() color.Model {
  23. return color.Gray16Model
  24. }
  25. func (c *datamatrixCode) Bounds() image.Rectangle {
  26. return image.Rect(0, 0, c.Columns, c.Rows)
  27. }
  28. func (c *datamatrixCode) At(x, y int) color.Color {
  29. if c.get(x, y) {
  30. return color.Black
  31. }
  32. return color.White
  33. }
  34. func (c *datamatrixCode) get(x, y int) bool {
  35. return c.GetBit(x*c.Rows + y)
  36. }
  37. func (c *datamatrixCode) set(x, y int, value bool) {
  38. c.SetBit(x*c.Rows+y, value)
  39. }