git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/pdf417/pdfcode.go (about)

     1  package pdf417
     2  
     3  import (
     4  	"image"
     5  	"image/color"
     6  
     7  	"git.sr.ht/~pingoo/stdx/barcode"
     8  	"git.sr.ht/~pingoo/stdx/barcode/utils"
     9  )
    10  
    11  type pdfBarcode struct {
    12  	data  string
    13  	width int
    14  	code  *utils.BitList
    15  }
    16  
    17  func (c *pdfBarcode) Metadata() barcode.Metadata {
    18  	return barcode.Metadata{barcode.TypePDF, 2}
    19  }
    20  
    21  func (c *pdfBarcode) Content() string {
    22  	return c.data
    23  }
    24  
    25  func (c *pdfBarcode) ColorModel() color.Model {
    26  	return color.Gray16Model
    27  }
    28  
    29  func (c *pdfBarcode) Bounds() image.Rectangle {
    30  	height := c.code.Len() / c.width
    31  
    32  	return image.Rect(0, 0, c.width, height*moduleHeight)
    33  }
    34  
    35  func (c *pdfBarcode) At(x, y int) color.Color {
    36  	if c.code.GetBit((y/moduleHeight)*c.width + x) {
    37  		return color.Black
    38  	}
    39  	return color.White
    40  }