/
datamatrixcode.go
53 lines (42 loc) · 1.02 KB
/
datamatrixcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package datamatrix
import (
"github.com/henrylee2cn/faygo/ext/barcode"
"github.com/henrylee2cn/faygo/ext/barcode/utils"
"image"
"image/color"
)
type datamatrixCode struct {
*utils.BitList
*dmCodeSize
content string
}
func newDataMatrixCode(size *dmCodeSize) *datamatrixCode {
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, ""}
}
func (c *datamatrixCode) Content() string {
return c.content
}
func (c *datamatrixCode) Metadata() barcode.Metadata {
return barcode.Metadata{"DataMatrix", 2}
}
func (c *datamatrixCode) ColorModel() color.Model {
return color.Gray16Model
}
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 color.Black
}
return color.White
}
func (c *datamatrixCode) CheckSum() int {
return 0
}
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)
}