azteccode.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package aztec
  2. import (
  3. "bytes"
  4. "image"
  5. "image/color"
  6. "github.com/boombuler/barcode"
  7. "github.com/boombuler/barcode/utils"
  8. )
  9. type aztecCode struct {
  10. *utils.BitList
  11. size int
  12. content []byte
  13. }
  14. func newAztecCode(size int) *aztecCode {
  15. return &aztecCode{utils.NewBitList(size * size), size, nil}
  16. }
  17. func (c *aztecCode) Content() string {
  18. return string(c.content)
  19. }
  20. func (c *aztecCode) Metadata() barcode.Metadata {
  21. return barcode.Metadata{barcode.TypeAztec, 2}
  22. }
  23. func (c *aztecCode) ColorModel() color.Model {
  24. return color.Gray16Model
  25. }
  26. func (c *aztecCode) Bounds() image.Rectangle {
  27. return image.Rect(0, 0, c.size, c.size)
  28. }
  29. func (c *aztecCode) At(x, y int) color.Color {
  30. if c.GetBit(x*c.size + y) {
  31. return color.Black
  32. }
  33. return color.White
  34. }
  35. func (c *aztecCode) set(x, y int) {
  36. c.SetBit(x*c.size+y, true)
  37. }
  38. func (c *aztecCode) string() string {
  39. buf := new(bytes.Buffer)
  40. for y := 0; y < c.size; y++ {
  41. for x := 0; x < c.size; x++ {
  42. if c.GetBit(x*c.size + y) {
  43. buf.WriteString("X ")
  44. } else {
  45. buf.WriteString(" ")
  46. }
  47. }
  48. buf.WriteRune('\n')
  49. }
  50. return buf.String()
  51. }