barcode/datamatrix/datamatrixcode.go

56 lines
1.3 KiB
Go
Raw Normal View History

2013-12-12 19:36:57 +00:00
package datamatrix
import (
"image"
"image/color"
2017-06-17 21:42:17 +00:00
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/utils"
2013-12-12 19:36:57 +00:00
)
type datamatrixCode struct {
*utils.BitList
2013-12-12 19:36:57 +00:00
*dmCodeSize
content string
color barcode.ColorScheme
}
func newDataMatrixCodeWithColor(size *dmCodeSize, color barcode.ColorScheme) *datamatrixCode {
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", color}
2013-12-12 19:36:57 +00:00
}
func newDataMatrixCode(size *dmCodeSize) *datamatrixCode {
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", barcode.ColorScheme16}
2013-12-12 19:36:57 +00:00
}
func (c *datamatrixCode) Content() string {
return c.content
}
func (c *datamatrixCode) Metadata() barcode.Metadata {
2017-06-17 21:42:17 +00:00
return barcode.Metadata{barcode.TypeDataMatrix, 2}
2013-12-12 19:36:57 +00:00
}
func (c *datamatrixCode) ColorModel() color.Model {
return c.color.Model
2013-12-12 19:36:57 +00:00
}
func (c *datamatrixCode) Bounds() image.Rectangle {
return image.Rect(0, 0, c.Columns, c.Rows)
}
func (c *datamatrixCode) At(x, y int) color.Color {
if c.get(x, y) {
return c.color.Foreground
2013-12-12 19:36:57 +00:00
}
return c.color.Background
2013-12-12 19:36:57 +00:00
}
func (c *datamatrixCode) get(x, y int) bool {
return c.GetBit(x*c.Rows + y)
}
func (c *datamatrixCode) set(x, y int, value bool) {
c.SetBit(x*c.Rows+y, value)
}