Compare commits
No commits in common. "master" and "v1.0.1" have entirely different histories.
@ -27,8 +27,8 @@ import (
|
|||||||
"image/png"
|
"image/png"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/qr"
|
"github.com/boombuler/barcode/qr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -48,6 +48,6 @@ func main() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Documentation ##
|
## Documentation ##
|
||||||
See [GoDoc](https://godoc.org/git.bbr-dev.info/brajkovic/barcode)
|
See [GoDoc](https://godoc.org/github.com/boombuler/barcode)
|
||||||
|
|
||||||
To create a barcode use the Encode function from one of the subpackages.
|
To create a barcode use the Encode function from one of the subpackages.
|
||||||
|
@ -5,19 +5,18 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type aztecCode struct {
|
type aztecCode struct {
|
||||||
*utils.BitList
|
*utils.BitList
|
||||||
size int
|
size int
|
||||||
content []byte
|
content []byte
|
||||||
color barcode.ColorScheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAztecCode(size int, color barcode.ColorScheme) *aztecCode {
|
func newAztecCode(size int) *aztecCode {
|
||||||
return &aztecCode{utils.NewBitList(size * size), size, nil, barcode.ColorScheme16}
|
return &aztecCode{utils.NewBitList(size * size), size, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) Content() string {
|
func (c *aztecCode) Content() string {
|
||||||
@ -29,11 +28,7 @@ func (c *aztecCode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) ColorModel() color.Model {
|
func (c *aztecCode) ColorModel() color.Model {
|
||||||
return c.color.Model
|
return color.Gray16Model
|
||||||
}
|
|
||||||
|
|
||||||
func (c *aztecCode) ColorScheme() barcode.ColorScheme {
|
|
||||||
return c.color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) Bounds() image.Rectangle {
|
func (c *aztecCode) Bounds() image.Rectangle {
|
||||||
@ -42,9 +37,9 @@ func (c *aztecCode) Bounds() image.Rectangle {
|
|||||||
|
|
||||||
func (c *aztecCode) At(x, y int) color.Color {
|
func (c *aztecCode) At(x, y int) color.Color {
|
||||||
if c.GetBit(x*c.size + y) {
|
if c.GetBit(x*c.size + y) {
|
||||||
return c.color.Foreground
|
return color.Black
|
||||||
}
|
}
|
||||||
return c.color.Background
|
return color.White
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) set(x, y int) {
|
func (c *aztecCode) set(x, y int) {
|
||||||
|
@ -4,8 +4,8 @@ package aztec
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -124,11 +124,6 @@ func drawBullsEye(matrix *aztecCode, center, size int) {
|
|||||||
|
|
||||||
// Encode returns an aztec barcode with the given content
|
// Encode returns an aztec barcode with the given content
|
||||||
func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Barcode, error) {
|
func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Barcode, error) {
|
||||||
return EncodeWithColor(data, minECCPercent, userSpecifiedLayers, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode returns an aztec barcode with the given content and color scheme
|
|
||||||
func EncodeWithColor(data []byte, minECCPercent int, userSpecifiedLayers int, color barcode.ColorScheme) (barcode.Barcode, error) {
|
|
||||||
bits := highlevelEncode(data)
|
bits := highlevelEncode(data)
|
||||||
eccBits := ((bits.Len() * minECCPercent) / 100) + 11
|
eccBits := ((bits.Len() * minECCPercent) / 100) + 11
|
||||||
totalSizeBits := bits.Len() + eccBits
|
totalSizeBits := bits.Len() + eccBits
|
||||||
@ -220,7 +215,7 @@ func EncodeWithColor(data []byte, minECCPercent int, userSpecifiedLayers int, co
|
|||||||
alignmentMap[origCenter+i] = center + newOffset + 1
|
alignmentMap[origCenter+i] = center + newOffset + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
code := newAztecCode(matrixSize, color)
|
code := newAztecCode(matrixSize)
|
||||||
code.content = data
|
code.content = data
|
||||||
|
|
||||||
// draw data bits
|
// draw data bits
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_StuffBits(t *testing.T) {
|
func Test_StuffBits(t *testing.T) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package aztec
|
package aztec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bitsToWords(stuffedBits *utils.BitList, wordSize int, wordCount int) []int {
|
func bitsToWords(stuffedBits *utils.BitList, wordSize int, wordCount int) []int {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package aztec
|
package aztec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func highlevelEncode(data []byte) *utils.BitList {
|
func highlevelEncode(data []byte) *utils.BitList {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bitStr(bl *utils.BitList) string {
|
func bitStr(bl *utils.BitList) string {
|
||||||
|
@ -3,7 +3,7 @@ package aztec
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodingMode byte
|
type encodingMode byte
|
||||||
|
@ -3,7 +3,7 @@ package aztec
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type token interface {
|
type token interface {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package barcode
|
package barcode
|
||||||
|
|
||||||
import (
|
import "image"
|
||||||
"image"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeAztec = "Aztec"
|
TypeAztec = "Aztec"
|
||||||
@ -42,7 +40,3 @@ type BarcodeIntCS interface {
|
|||||||
Barcode
|
Barcode
|
||||||
CheckSum() int
|
CheckSum() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type BarcodeColor interface {
|
|
||||||
ColorScheme() ColorScheme
|
|
||||||
}
|
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var encodingTable = map[rune][]bool{
|
var encodingTable = map[rune][]bool{
|
||||||
@ -32,8 +32,8 @@ var encodingTable = map[rune][]bool{
|
|||||||
'D': []bool{true, false, true, false, false, true, true, false, false, true},
|
'D': []bool{true, false, true, false, false, true, true, false, false, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode creates a codabar barcode for the given content and color scheme
|
// Encode creates a codabar barcode for the given content
|
||||||
func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
|
func Encode(content string) (barcode.Barcode, error) {
|
||||||
checkValid, _ := regexp.Compile(`[ABCD][0123456789\-\$\:/\.\+]*[ABCD]$`)
|
checkValid, _ := regexp.Compile(`[ABCD][0123456789\-\$\:/\.\+]*[ABCD]$`)
|
||||||
if content == "!" || checkValid.ReplaceAllString(content, "!") != "!" {
|
if content == "!" || checkValid.ReplaceAllString(content, "!") != "!" {
|
||||||
return nil, fmt.Errorf("can not encode \"%s\"", content)
|
return nil, fmt.Errorf("can not encode \"%s\"", content)
|
||||||
@ -45,10 +45,5 @@ func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode
|
|||||||
}
|
}
|
||||||
resBits.AddBit(encodingTable[r]...)
|
resBits.AddBit(encodingTable[r]...)
|
||||||
}
|
}
|
||||||
return utils.New1DCodeWithColor(barcode.TypeCodabar, content, resBits, color), nil
|
return utils.New1DCode(barcode.TypeCodabar, content, resBits), nil
|
||||||
}
|
|
||||||
|
|
||||||
// Encode creates a codabar barcode for the given content
|
|
||||||
func Encode(content string) (barcode.Barcode, error) {
|
|
||||||
return EncodeWithColor(content, barcode.ColorScheme16)
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func strToRunes(str string) []rune {
|
func strToRunes(str string) []rune {
|
||||||
@ -155,8 +155,8 @@ func getCodeIndexList(content []rune) *utils.BitList {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode creates a Code 128 barcode for the given content and color scheme
|
// Encode creates a Code 128 barcode for the given content
|
||||||
func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.BarcodeIntCS, error) {
|
func Encode(content string) (barcode.BarcodeIntCS, error) {
|
||||||
contentRunes := strToRunes(content)
|
contentRunes := strToRunes(content)
|
||||||
if len(contentRunes) <= 0 || len(contentRunes) > 80 {
|
if len(contentRunes) <= 0 || len(contentRunes) > 80 {
|
||||||
return nil, fmt.Errorf("content length should be between 1 and 80 runes but got %d", len(contentRunes))
|
return nil, fmt.Errorf("content length should be between 1 and 80 runes but got %d", len(contentRunes))
|
||||||
@ -180,19 +180,10 @@ func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode
|
|||||||
sum = sum % 103
|
sum = sum % 103
|
||||||
result.AddBit(encodingTable[sum]...)
|
result.AddBit(encodingTable[sum]...)
|
||||||
result.AddBit(encodingTable[stopSymbol]...)
|
result.AddBit(encodingTable[stopSymbol]...)
|
||||||
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeCode128, content, result, sum, color), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeCode128, content, result, sum), nil
|
||||||
}
|
|
||||||
|
|
||||||
// Encode creates a Code 128 barcode for the given content
|
|
||||||
func Encode(content string) (barcode.BarcodeIntCS, error) {
|
|
||||||
return EncodeWithColor(content, barcode.ColorScheme16)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncodeWithoutChecksum(content string) (barcode.Barcode, error) {
|
func EncodeWithoutChecksum(content string) (barcode.Barcode, error) {
|
||||||
return EncodeWithoutChecksumWithColor(content, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
|
||||||
func EncodeWithoutChecksumWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
|
|
||||||
contentRunes := strToRunes(content)
|
contentRunes := strToRunes(content)
|
||||||
if len(contentRunes) <= 0 || len(contentRunes) > 80 {
|
if len(contentRunes) <= 0 || len(contentRunes) > 80 {
|
||||||
return nil, fmt.Errorf("content length should be between 1 and 80 runes but got %d", len(contentRunes))
|
return nil, fmt.Errorf("content length should be between 1 and 80 runes but got %d", len(contentRunes))
|
||||||
@ -208,5 +199,5 @@ func EncodeWithoutChecksumWithColor(content string, color barcode.ColorScheme) (
|
|||||||
result.AddBit(encodingTable[idx]...)
|
result.AddBit(encodingTable[idx]...)
|
||||||
}
|
}
|
||||||
result.AddBit(encodingTable[stopSymbol]...)
|
result.AddBit(encodingTable[stopSymbol]...)
|
||||||
return utils.New1DCodeWithColor(barcode.TypeCode128, content, result, color), nil
|
return utils.New1DCode(barcode.TypeCode128, content, result), nil
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodeInfo struct {
|
type encodeInfo struct {
|
||||||
@ -111,9 +111,9 @@ func prepare(content string) (string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode returns a code39 barcode for the given content and color scheme
|
// Encode returns a code39 barcode for the given content
|
||||||
// if includeChecksum is set to true, a checksum character is calculated and added to the content
|
// if includeChecksum is set to true, a checksum character is calculated and added to the content
|
||||||
func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme) (barcode.BarcodeIntCS, error) {
|
func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.BarcodeIntCS, error) {
|
||||||
if fullASCIIMode {
|
if fullASCIIMode {
|
||||||
var err error
|
var err error
|
||||||
content, err = prepare(content)
|
content, err = prepare(content)
|
||||||
@ -148,11 +148,5 @@ func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, c
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
checkSum = 0
|
checkSum = 0
|
||||||
}
|
}
|
||||||
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeCode39, content, result, int(checkSum), color), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeCode39, content, result, int(checkSum)), nil
|
||||||
}
|
|
||||||
|
|
||||||
// Encode returns a code39 barcode for the given content
|
|
||||||
// if includeChecksum is set to true, a checksum character is calculated and added to the content
|
|
||||||
func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.BarcodeIntCS, error) {
|
|
||||||
return EncodeWithColor(content, includeChecksum, fullASCIIMode, barcode.ColorScheme16)
|
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodeInfo struct {
|
type encodeInfo struct {
|
||||||
@ -74,9 +74,9 @@ func prepare(content string) (string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode returns a code93 barcode for the given content and color scheme
|
// Encode returns a code93 barcode for the given content
|
||||||
// if includeChecksum is set to true, two checksum characters are calculated and added to the content
|
// if includeChecksum is set to true, two checksum characters are calculated and added to the content
|
||||||
func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme) (barcode.Barcode, error) {
|
func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.Barcode, error) {
|
||||||
if fullASCIIMode {
|
if fullASCIIMode {
|
||||||
var err error
|
var err error
|
||||||
content, err = prepare(content)
|
content, err = prepare(content)
|
||||||
@ -88,9 +88,7 @@ func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := content + string(getChecksum(content, 20))
|
data := content + string(getChecksum(content, 20))
|
||||||
if includeChecksum {
|
|
||||||
data += string(getChecksum(data, 15))
|
data += string(getChecksum(data, 15))
|
||||||
}
|
|
||||||
|
|
||||||
data = "*" + data + "*"
|
data = "*" + data + "*"
|
||||||
result := new(utils.BitList)
|
result := new(utils.BitList)
|
||||||
@ -104,13 +102,7 @@ func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, c
|
|||||||
}
|
}
|
||||||
result.AddBit(true)
|
result.AddBit(true)
|
||||||
|
|
||||||
return utils.New1DCodeWithColor(barcode.TypeCode93, content, result, color), nil
|
return utils.New1DCode(barcode.TypeCode93, content, result), nil
|
||||||
}
|
|
||||||
|
|
||||||
// Encode returns a code93 barcode for the given content
|
|
||||||
// if includeChecksum is set to true, two checksum characters are calculated and added to the content
|
|
||||||
func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.Barcode, error) {
|
|
||||||
return EncodeWithColor(content, includeChecksum, fullASCIIMode, barcode.ColorScheme16)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getChecksum(content string, maxWeight int) rune {
|
func getChecksum(content string, maxWeight int) rune {
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package barcode
|
|
||||||
|
|
||||||
import "image/color"
|
|
||||||
|
|
||||||
// ColorScheme defines a structure for color schemes used in barcode rendering.
|
|
||||||
// It includes the color model, background color, and foreground color.
|
|
||||||
type ColorScheme struct {
|
|
||||||
Model color.Model // Color model to be used (e.g., grayscale, RGB, RGBA)
|
|
||||||
Background color.Color // Color of the background
|
|
||||||
Foreground color.Color // Color of the foreground (e.g., bars in a barcode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ColorScheme8 represents a color scheme with 8-bit grayscale colors.
|
|
||||||
var ColorScheme8 = ColorScheme{
|
|
||||||
Model: color.GrayModel,
|
|
||||||
Background: color.Gray{Y: 255},
|
|
||||||
Foreground: color.Gray{Y: 0},
|
|
||||||
}
|
|
||||||
|
|
||||||
// ColorScheme16 represents a color scheme with 16-bit grayscale colors.
|
|
||||||
var ColorScheme16 = ColorScheme{
|
|
||||||
Model: color.Gray16Model,
|
|
||||||
Background: color.White,
|
|
||||||
Foreground: color.Black,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ColorScheme24 represents a color scheme with 24-bit RGB colors.
|
|
||||||
var ColorScheme24 = ColorScheme{
|
|
||||||
Model: color.RGBAModel,
|
|
||||||
Background: color.RGBA{255, 255, 255, 255},
|
|
||||||
Foreground: color.RGBA{0, 0, 0, 255},
|
|
||||||
}
|
|
||||||
|
|
||||||
// ColorScheme32 represents a color scheme with 32-bit RGBA colors, which is similar to ColorScheme24 but typically includes alpha for transparency.
|
|
||||||
var ColorScheme32 = ColorScheme{
|
|
||||||
Model: color.RGBAModel,
|
|
||||||
Background: color.RGBA{255, 255, 255, 255},
|
|
||||||
Foreground: color.RGBA{0, 0, 0, 255},
|
|
||||||
}
|
|
@ -1,10 +1,8 @@
|
|||||||
package datamatrix
|
package datamatrix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/boombuler/barcode/utils"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type setValFunc func(byte)
|
type setValFunc func(byte)
|
||||||
@ -13,15 +11,13 @@ type codeLayout struct {
|
|||||||
matrix *utils.BitList
|
matrix *utils.BitList
|
||||||
occupy *utils.BitList
|
occupy *utils.BitList
|
||||||
size *dmCodeSize
|
size *dmCodeSize
|
||||||
color barcode.ColorScheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCodeLayout(size *dmCodeSize, color barcode.ColorScheme) *codeLayout {
|
func newCodeLayout(size *dmCodeSize) *codeLayout {
|
||||||
result := new(codeLayout)
|
result := new(codeLayout)
|
||||||
result.matrix = utils.NewBitList(size.MatrixColumns() * size.MatrixRows())
|
result.matrix = utils.NewBitList(size.MatrixColumns() * size.MatrixRows())
|
||||||
result.occupy = utils.NewBitList(size.MatrixColumns() * size.MatrixRows())
|
result.occupy = utils.NewBitList(size.MatrixColumns() * size.MatrixRows())
|
||||||
result.size = size
|
result.size = size
|
||||||
result.color = color
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +159,7 @@ func (l *codeLayout) SetValues(data []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *codeLayout) Merge() *datamatrixCode {
|
func (l *codeLayout) Merge() *datamatrixCode {
|
||||||
result := newDataMatrixCodeWithColor(l.size, l.color)
|
result := newDataMatrixCode(l.size)
|
||||||
|
|
||||||
//dotted horizontal lines
|
//dotted horizontal lines
|
||||||
for r := 0; r < l.size.Rows; r += (l.size.RegionRows() + 2) {
|
for r := 0; r < l.size.Rows; r += (l.size.RegionRows() + 2) {
|
||||||
|
@ -10,19 +10,19 @@ type dmCodeSize struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) RegionRows() int {
|
func (s *dmCodeSize) RegionRows() int {
|
||||||
return (s.Rows - (s.RegionCountVertical * 2)) / s.RegionCountVertical
|
return (s.Rows - (s.RegionCountHorizontal * 2)) / s.RegionCountHorizontal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) RegionColumns() int {
|
func (s *dmCodeSize) RegionColumns() int {
|
||||||
return (s.Columns - (s.RegionCountHorizontal * 2)) / s.RegionCountHorizontal
|
return (s.Columns - (s.RegionCountVertical * 2)) / s.RegionCountVertical
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) MatrixRows() int {
|
func (s *dmCodeSize) MatrixRows() int {
|
||||||
return s.RegionRows() * s.RegionCountVertical
|
return s.RegionRows() * s.RegionCountHorizontal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) MatrixColumns() int {
|
func (s *dmCodeSize) MatrixColumns() int {
|
||||||
return s.RegionColumns() * s.RegionCountHorizontal
|
return s.RegionColumns() * s.RegionCountVertical
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) DataCodewords() int {
|
func (s *dmCodeSize) DataCodewords() int {
|
||||||
|
@ -4,23 +4,18 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type datamatrixCode struct {
|
type datamatrixCode struct {
|
||||||
*utils.BitList
|
*utils.BitList
|
||||||
*dmCodeSize
|
*dmCodeSize
|
||||||
content string
|
content string
|
||||||
color barcode.ColorScheme
|
|
||||||
}
|
|
||||||
|
|
||||||
func newDataMatrixCodeWithColor(size *dmCodeSize, color barcode.ColorScheme) *datamatrixCode {
|
|
||||||
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", color}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDataMatrixCode(size *dmCodeSize) *datamatrixCode {
|
func newDataMatrixCode(size *dmCodeSize) *datamatrixCode {
|
||||||
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", barcode.ColorScheme16}
|
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) Content() string {
|
func (c *datamatrixCode) Content() string {
|
||||||
@ -32,11 +27,7 @@ func (c *datamatrixCode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) ColorModel() color.Model {
|
func (c *datamatrixCode) ColorModel() color.Model {
|
||||||
return c.color.Model
|
return color.Gray16Model
|
||||||
}
|
|
||||||
|
|
||||||
func (c *datamatrixCode) ColorScheme() barcode.ColorScheme {
|
|
||||||
return c.color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) Bounds() image.Rectangle {
|
func (c *datamatrixCode) Bounds() image.Rectangle {
|
||||||
@ -45,9 +36,9 @@ func (c *datamatrixCode) Bounds() image.Rectangle {
|
|||||||
|
|
||||||
func (c *datamatrixCode) At(x, y int) color.Color {
|
func (c *datamatrixCode) At(x, y int) color.Color {
|
||||||
if c.get(x, y) {
|
if c.get(x, y) {
|
||||||
return c.color.Foreground
|
return color.Black
|
||||||
}
|
}
|
||||||
return c.color.Background
|
return color.White
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) get(x, y int) bool {
|
func (c *datamatrixCode) get(x, y int) bool {
|
||||||
|
@ -4,11 +4,11 @@ package datamatrix
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Encode returns a Datamatrix barcode for the given content and color scheme
|
// Encode returns a Datamatrix barcode for the given content
|
||||||
func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
|
func Encode(content string) (barcode.Barcode, error) {
|
||||||
data := encodeText(content)
|
data := encodeText(content)
|
||||||
|
|
||||||
var size *dmCodeSize
|
var size *dmCodeSize
|
||||||
@ -23,7 +23,7 @@ func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode
|
|||||||
}
|
}
|
||||||
data = addPadding(data, size.DataCodewords())
|
data = addPadding(data, size.DataCodewords())
|
||||||
data = ec.calcECC(data, size)
|
data = ec.calcECC(data, size)
|
||||||
code := render(data, size, color)
|
code := render(data, size)
|
||||||
if code != nil {
|
if code != nil {
|
||||||
code.content = content
|
code.content = content
|
||||||
return code, nil
|
return code, nil
|
||||||
@ -31,13 +31,8 @@ func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode
|
|||||||
return nil, errors.New("unable to render barcode")
|
return nil, errors.New("unable to render barcode")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode returns a Datamatrix barcode for the given content
|
func render(data []byte, size *dmCodeSize) *datamatrixCode {
|
||||||
func Encode(content string) (barcode.Barcode, error) {
|
cl := newCodeLayout(size)
|
||||||
return EncodeWithColor(content, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
|
||||||
func render(data []byte, size *dmCodeSize, color barcode.ColorScheme) *datamatrixCode {
|
|
||||||
cl := newCodeLayout(size, color)
|
|
||||||
|
|
||||||
cl.SetValues(data)
|
cl.SetValues(data)
|
||||||
|
|
||||||
@ -74,12 +69,7 @@ func addPadding(data []byte, toCount int) []byte {
|
|||||||
}
|
}
|
||||||
for len(data) < toCount {
|
for len(data) < toCount {
|
||||||
R := ((149 * (len(data) + 1)) % 253) + 1
|
R := ((149 * (len(data) + 1)) % 253) + 1
|
||||||
tmp := 129 + R
|
data = append(data, byte((129+R)%254))
|
||||||
if tmp > 254 {
|
|
||||||
tmp = tmp - 254
|
|
||||||
}
|
|
||||||
|
|
||||||
data = append(data, byte(tmp))
|
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package datamatrix
|
package datamatrix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorCorrection struct {
|
type errorCorrection struct {
|
||||||
|
@ -4,8 +4,8 @@ package ean
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodedNumber struct {
|
type encodedNumber struct {
|
||||||
@ -157,8 +157,8 @@ func encodeEAN13(code string) *utils.BitList {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode returns a EAN 8 or EAN 13 barcode for the given code and color scheme
|
// Encode returns a EAN 8 or EAN 13 barcode for the given code
|
||||||
func EncodeWithColor(code string, color barcode.ColorScheme) (barcode.BarcodeIntCS, error) {
|
func Encode(code string) (barcode.BarcodeIntCS, error) {
|
||||||
var checkSum int
|
var checkSum int
|
||||||
if len(code) == 7 || len(code) == 12 {
|
if len(code) == 7 || len(code) == 12 {
|
||||||
code += string(calcCheckNum(code))
|
code += string(calcCheckNum(code))
|
||||||
@ -175,18 +175,13 @@ func EncodeWithColor(code string, color barcode.ColorScheme) (barcode.BarcodeInt
|
|||||||
if len(code) == 8 {
|
if len(code) == 8 {
|
||||||
result := encodeEAN8(code)
|
result := encodeEAN8(code)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeEAN8, code, result, checkSum, color), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeEAN8, code, result, checkSum), nil
|
||||||
}
|
}
|
||||||
} else if len(code) == 13 {
|
} else if len(code) == 13 {
|
||||||
result := encodeEAN13(code)
|
result := encodeEAN13(code)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeEAN13, code, result, checkSum, color), nil
|
return utils.New1DCodeIntCheckSum(barcode.TypeEAN13, code, result, checkSum), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.New("invalid ean code data")
|
return nil, errors.New("invalid ean code data")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode returns a EAN 8 or EAN 13 barcode for the given code
|
|
||||||
func Encode(code string) (barcode.BarcodeIntCS, error) {
|
|
||||||
return EncodeWithColor(code, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
2
go.mod
2
go.mod
@ -1 +1 @@
|
|||||||
module git.bbr-dev.info/brajkovic/barcode
|
module github.com/boombuler/barcode
|
||||||
|
@ -3,8 +3,8 @@ package pdf417
|
|||||||
import "math"
|
import "math"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
minCols = 9
|
minCols = 2
|
||||||
maxCols = 9
|
maxCols = 30
|
||||||
maxRows = 30
|
maxRows = 30
|
||||||
minRows = 2
|
minRows = 2
|
||||||
moduleHeight = 2
|
moduleHeight = 2
|
||||||
|
@ -4,18 +4,18 @@ package pdf417
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
padding_codeword = 900
|
padding_codeword = 900
|
||||||
)
|
)
|
||||||
|
|
||||||
// Encodes the given data and color scheme as PDF417 barcode.
|
// Encodes the given data as PDF417 barcode.
|
||||||
// securityLevel should be between 0 and 8. The higher the number, the more
|
// securityLevel should be between 0 and 8. The higher the number, the more
|
||||||
// additional error-correction codes are added.
|
// additional error-correction codes are added.
|
||||||
func EncodeWithColor(data string, securityLevel byte, color barcode.ColorScheme) (barcode.Barcode, error) {
|
func Encode(data string, securityLevel byte) (barcode.Barcode, error) {
|
||||||
if securityLevel >= 9 {
|
if securityLevel >= 9 {
|
||||||
return nil, fmt.Errorf("Invalid security level %d", securityLevel)
|
return nil, fmt.Errorf("Invalid security level %d", securityLevel)
|
||||||
}
|
}
|
||||||
@ -34,7 +34,6 @@ func EncodeWithColor(data string, securityLevel byte, color barcode.ColorScheme)
|
|||||||
|
|
||||||
barcode := new(pdfBarcode)
|
barcode := new(pdfBarcode)
|
||||||
barcode.data = data
|
barcode.data = data
|
||||||
barcode.color = color
|
|
||||||
|
|
||||||
codeWords, err := encodeData(dataWords, columns, sl)
|
codeWords, err := encodeData(dataWords, columns, sl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,13 +70,6 @@ func EncodeWithColor(data string, securityLevel byte, color barcode.ColorScheme)
|
|||||||
return barcode, nil
|
return barcode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encodes the given data as PDF417 barcode.
|
|
||||||
// securityLevel should be between 0 and 8. The higher the number, the more
|
|
||||||
// additional error-correction codes are added.
|
|
||||||
func Encode(data string, securityLevel byte) (barcode.Barcode, error) {
|
|
||||||
return EncodeWithColor(data, securityLevel, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeData(dataWords []int, columns int, sl securitylevel) ([]int, error) {
|
func encodeData(dataWords []int, columns int, sl securitylevel) ([]int, error) {
|
||||||
dataCount := len(dataWords)
|
dataCount := len(dataWords)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodingMode byte
|
type encodingMode byte
|
||||||
|
@ -4,15 +4,14 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pdfBarcode struct {
|
type pdfBarcode struct {
|
||||||
data string
|
data string
|
||||||
width int
|
width int
|
||||||
code *utils.BitList
|
code *utils.BitList
|
||||||
color barcode.ColorScheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) Metadata() barcode.Metadata {
|
func (c *pdfBarcode) Metadata() barcode.Metadata {
|
||||||
@ -24,11 +23,7 @@ func (c *pdfBarcode) Content() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) ColorModel() color.Model {
|
func (c *pdfBarcode) ColorModel() color.Model {
|
||||||
return c.color.Model
|
return color.Gray16Model
|
||||||
}
|
|
||||||
|
|
||||||
func (c *pdfBarcode) ColorScheme() barcode.ColorScheme {
|
|
||||||
return c.color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) Bounds() image.Rectangle {
|
func (c *pdfBarcode) Bounds() image.Rectangle {
|
||||||
@ -39,7 +34,7 @@ func (c *pdfBarcode) Bounds() image.Rectangle {
|
|||||||
|
|
||||||
func (c *pdfBarcode) At(x, y int) color.Color {
|
func (c *pdfBarcode) At(x, y int) color.Color {
|
||||||
if c.code.GetBit((y/moduleHeight)*c.width + x) {
|
if c.code.GetBit((y/moduleHeight)*c.width + x) {
|
||||||
return c.color.Foreground
|
return color.Black
|
||||||
}
|
}
|
||||||
return c.color.Background
|
return color.White
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const charSet string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
const charSet string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
||||||
|
@ -3,7 +3,7 @@ package qr
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func encodeAuto(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
func encodeAuto(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
||||||
|
@ -4,8 +4,8 @@ package qr
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodeFn func(content string, eccLevel ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error)
|
type encodeFn func(content string, eccLevel ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error)
|
||||||
@ -54,8 +54,8 @@ func (e Encoding) String() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode returns a QR barcode with the given content and color scheme, error correction level and uses the given encoding
|
// Encode returns a QR barcode with the given content, error correction level and uses the given encoding
|
||||||
func EncodeWithColor(content string, level ErrorCorrectionLevel, mode Encoding, color barcode.ColorScheme) (barcode.Barcode, error) {
|
func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error) {
|
||||||
bits, vi, err := mode.getEncoder()(content, level)
|
bits, vi, err := mode.getEncoder()(content, level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -63,23 +63,19 @@ func EncodeWithColor(content string, level ErrorCorrectionLevel, mode Encoding,
|
|||||||
|
|
||||||
blocks := splitToBlocks(bits.IterateBytes(), vi)
|
blocks := splitToBlocks(bits.IterateBytes(), vi)
|
||||||
data := blocks.interleave(vi)
|
data := blocks.interleave(vi)
|
||||||
result := render(data, vi, color)
|
result := render(data, vi)
|
||||||
result.content = content
|
result.content = content
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error) {
|
func render(data []byte, vi *versionInfo) *qrcode {
|
||||||
return EncodeWithColor(content, level, mode, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
|
||||||
func render(data []byte, vi *versionInfo, color barcode.ColorScheme) *qrcode {
|
|
||||||
dim := vi.modulWidth()
|
dim := vi.modulWidth()
|
||||||
results := make([]*qrcode, 8)
|
results := make([]*qrcode, 8)
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
results[i] = newBarCodeWithColor(dim, color)
|
results[i] = newBarcode(dim)
|
||||||
}
|
}
|
||||||
|
|
||||||
occupied := newBarCodeWithColor(dim, color)
|
occupied := newBarcode(dim)
|
||||||
|
|
||||||
setAll := func(x int, y int, val bool) {
|
setAll := func(x int, y int, val bool) {
|
||||||
occupied.Set(x, y, true)
|
occupied.Set(x, y, true)
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type test struct {
|
type test struct {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package qr
|
package qr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorCorrection struct {
|
type errorCorrection struct {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func encodeNumeric(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
func encodeNumeric(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
||||||
|
22
qr/qrcode.go
22
qr/qrcode.go
@ -5,15 +5,14 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type qrcode struct {
|
type qrcode struct {
|
||||||
dimension int
|
dimension int
|
||||||
data *utils.BitList
|
data *utils.BitList
|
||||||
content string
|
content string
|
||||||
color barcode.ColorScheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) Content() string {
|
func (qr *qrcode) Content() string {
|
||||||
@ -25,11 +24,7 @@ func (qr *qrcode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) ColorModel() color.Model {
|
func (qr *qrcode) ColorModel() color.Model {
|
||||||
return qr.color.Model
|
return color.Gray16Model
|
||||||
}
|
|
||||||
|
|
||||||
func (c *qrcode) ColorScheme() barcode.ColorScheme {
|
|
||||||
return c.color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) Bounds() image.Rectangle {
|
func (qr *qrcode) Bounds() image.Rectangle {
|
||||||
@ -38,9 +33,9 @@ func (qr *qrcode) Bounds() image.Rectangle {
|
|||||||
|
|
||||||
func (qr *qrcode) At(x, y int) color.Color {
|
func (qr *qrcode) At(x, y int) color.Color {
|
||||||
if qr.Get(x, y) {
|
if qr.Get(x, y) {
|
||||||
return qr.color.Foreground
|
return color.Black
|
||||||
}
|
}
|
||||||
return qr.color.Background
|
return color.White
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) Get(x, y int) bool {
|
func (qr *qrcode) Get(x, y int) bool {
|
||||||
@ -163,14 +158,9 @@ func (qr *qrcode) calcPenaltyRule4() uint {
|
|||||||
return uint(math.Min(floor, ceil) * 10)
|
return uint(math.Min(floor, ceil) * 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBarCodeWithColor(dim int, color barcode.ColorScheme) *qrcode {
|
func newBarcode(dim int) *qrcode {
|
||||||
res := new(qrcode)
|
res := new(qrcode)
|
||||||
res.dimension = dim
|
res.dimension = dim
|
||||||
res.data = utils.NewBitList(dim * dim)
|
res.data = utils.NewBitList(dim * dim)
|
||||||
res.color = color
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBarcode(dim int) *qrcode {
|
|
||||||
return newBarCodeWithColor(dim, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,7 @@ package qr
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func encodeUnicode(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
func encodeUnicode(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
||||||
|
@ -49,22 +49,11 @@ func (bc *intCSscaledBC) CheckSum() int {
|
|||||||
|
|
||||||
// Scale returns a resized barcode with the given width and height.
|
// Scale returns a resized barcode with the given width and height.
|
||||||
func Scale(bc Barcode, width, height int) (Barcode, error) {
|
func Scale(bc Barcode, width, height int) (Barcode, error) {
|
||||||
var fill color.Color
|
|
||||||
if v, ok := bc.(BarcodeColor); ok {
|
|
||||||
fill = v.ColorScheme().Background
|
|
||||||
} else {
|
|
||||||
fill = color.White
|
|
||||||
}
|
|
||||||
return ScaleWithFill(bc, width, height, fill)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scale returns a resized barcode with the given width, height and fill color.
|
|
||||||
func ScaleWithFill(bc Barcode, width, height int, fill color.Color) (Barcode, error) {
|
|
||||||
switch bc.Metadata().Dimensions {
|
switch bc.Metadata().Dimensions {
|
||||||
case 1:
|
case 1:
|
||||||
return scale1DCode(bc, width, height, fill)
|
return scale1DCode(bc, width, height)
|
||||||
case 2:
|
case 2:
|
||||||
return scale2DCode(bc, width, height, fill)
|
return scale2DCode(bc, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("unsupported barcode format")
|
return nil, errors.New("unsupported barcode format")
|
||||||
@ -83,7 +72,7 @@ func newScaledBC(wrapped Barcode, wrapperFunc wrapFunc, rect image.Rectangle) Ba
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func scale2DCode(bc Barcode, width, height int, fill color.Color) (Barcode, error) {
|
func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
|
||||||
orgBounds := bc.Bounds()
|
orgBounds := bc.Bounds()
|
||||||
orgWidth := orgBounds.Max.X - orgBounds.Min.X
|
orgWidth := orgBounds.Max.X - orgBounds.Min.X
|
||||||
orgHeight := orgBounds.Max.Y - orgBounds.Min.Y
|
orgHeight := orgBounds.Max.Y - orgBounds.Min.Y
|
||||||
@ -98,12 +87,12 @@ func scale2DCode(bc Barcode, width, height int, fill color.Color) (Barcode, erro
|
|||||||
|
|
||||||
wrap := func(x, y int) color.Color {
|
wrap := func(x, y int) color.Color {
|
||||||
if x < offsetX || y < offsetY {
|
if x < offsetX || y < offsetY {
|
||||||
return fill
|
return color.White
|
||||||
}
|
}
|
||||||
x = (x - offsetX) / factor
|
x = (x - offsetX) / factor
|
||||||
y = (y - offsetY) / factor
|
y = (y - offsetY) / factor
|
||||||
if x >= orgWidth || y >= orgHeight {
|
if x >= orgWidth || y >= orgHeight {
|
||||||
return fill
|
return color.White
|
||||||
}
|
}
|
||||||
return bc.At(x, y)
|
return bc.At(x, y)
|
||||||
}
|
}
|
||||||
@ -115,7 +104,7 @@ func scale2DCode(bc Barcode, width, height int, fill color.Color) (Barcode, erro
|
|||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func scale1DCode(bc Barcode, width, height int, fill color.Color) (Barcode, error) {
|
func scale1DCode(bc Barcode, width, height int) (Barcode, error) {
|
||||||
orgBounds := bc.Bounds()
|
orgBounds := bc.Bounds()
|
||||||
orgWidth := orgBounds.Max.X - orgBounds.Min.X
|
orgWidth := orgBounds.Max.X - orgBounds.Min.X
|
||||||
factor := int(float64(width) / float64(orgWidth))
|
factor := int(float64(width) / float64(orgWidth))
|
||||||
@ -127,12 +116,12 @@ func scale1DCode(bc Barcode, width, height int, fill color.Color) (Barcode, erro
|
|||||||
|
|
||||||
wrap := func(x, y int) color.Color {
|
wrap := func(x, y int) color.Color {
|
||||||
if x < offsetX {
|
if x < offsetX {
|
||||||
return fill
|
return color.White
|
||||||
}
|
}
|
||||||
x = (x - offsetX) / factor
|
x = (x - offsetX) / factor
|
||||||
|
|
||||||
if x >= orgWidth {
|
if x >= orgWidth {
|
||||||
return fill
|
return color.White
|
||||||
}
|
}
|
||||||
return bc.At(x, 0)
|
return bc.At(x, 0)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"git.bbr-dev.info/brajkovic/barcode/utils"
|
"github.com/boombuler/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const patternWidth = 5
|
const patternWidth = 5
|
||||||
@ -78,8 +78,8 @@ func AddCheckSum(content string) (string, error) {
|
|||||||
return content + string(utils.IntToRune(sum%10)), nil
|
return content + string(utils.IntToRune(sum%10)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode creates a codabar barcode for the given content and color scheme
|
// Encode creates a codabar barcode for the given content
|
||||||
func EncodeWithColor(content string, interleaved bool, color barcode.ColorScheme) (barcode.Barcode, error) {
|
func Encode(content string, interleaved bool) (barcode.Barcode, error) {
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return nil, errors.New("content is empty")
|
return nil, errors.New("content is empty")
|
||||||
}
|
}
|
||||||
@ -131,13 +131,8 @@ func EncodeWithColor(content string, interleaved bool, color barcode.ColorScheme
|
|||||||
resBits.AddBit(mode.end...)
|
resBits.AddBit(mode.end...)
|
||||||
|
|
||||||
if interleaved {
|
if interleaved {
|
||||||
return utils.New1DCodeWithColor(barcode.Type2of5Interleaved, content, resBits, color), nil
|
return utils.New1DCode(barcode.Type2of5Interleaved, content, resBits), nil
|
||||||
} else {
|
} else {
|
||||||
return utils.New1DCodeWithColor(barcode.Type2of5, content, resBits, color), nil
|
return utils.New1DCode(barcode.Type2of5, content, resBits), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode creates a codabar barcode for the given content
|
|
||||||
func Encode(content string, interleaved bool) (barcode.Barcode, error) {
|
|
||||||
return EncodeWithColor(content, interleaved, barcode.ColorScheme16)
|
|
||||||
}
|
|
||||||
|
@ -5,14 +5,13 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"git.bbr-dev.info/brajkovic/barcode"
|
"github.com/boombuler/barcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type base1DCode struct {
|
type base1DCode struct {
|
||||||
*BitList
|
*BitList
|
||||||
kind string
|
kind string
|
||||||
content string
|
content string
|
||||||
color barcode.ColorScheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type base1DCodeIntCS struct {
|
type base1DCodeIntCS struct {
|
||||||
@ -29,11 +28,7 @@ func (c *base1DCode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *base1DCode) ColorModel() color.Model {
|
func (c *base1DCode) ColorModel() color.Model {
|
||||||
return c.color.Model
|
return color.Gray16Model
|
||||||
}
|
|
||||||
|
|
||||||
func (c *base1DCode) ColorScheme() barcode.ColorScheme {
|
|
||||||
return c.color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *base1DCode) Bounds() image.Rectangle {
|
func (c *base1DCode) Bounds() image.Rectangle {
|
||||||
@ -42,9 +37,9 @@ func (c *base1DCode) Bounds() image.Rectangle {
|
|||||||
|
|
||||||
func (c *base1DCode) At(x, y int) color.Color {
|
func (c *base1DCode) At(x, y int) color.Color {
|
||||||
if c.GetBit(x) {
|
if c.GetBit(x) {
|
||||||
return c.color.Foreground
|
return color.Black
|
||||||
}
|
}
|
||||||
return c.color.Background
|
return color.White
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *base1DCodeIntCS) CheckSum() int {
|
func (c *base1DCodeIntCS) CheckSum() int {
|
||||||
@ -53,20 +48,10 @@ func (c *base1DCodeIntCS) CheckSum() int {
|
|||||||
|
|
||||||
// New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList
|
// New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList
|
||||||
func New1DCodeIntCheckSum(codeKind, content string, bars *BitList, checksum int) barcode.BarcodeIntCS {
|
func New1DCodeIntCheckSum(codeKind, content string, bars *BitList, checksum int) barcode.BarcodeIntCS {
|
||||||
return &base1DCodeIntCS{base1DCode{bars, codeKind, content, barcode.ColorScheme16}, checksum}
|
return &base1DCodeIntCS{base1DCode{bars, codeKind, content}, checksum}
|
||||||
}
|
|
||||||
|
|
||||||
// New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList
|
|
||||||
func New1DCodeIntCheckSumWithColor(codeKind, content string, bars *BitList, checksum int, color barcode.ColorScheme) barcode.BarcodeIntCS {
|
|
||||||
return &base1DCodeIntCS{base1DCode{bars, codeKind, content, color}, checksum}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
|
// New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
|
||||||
func New1DCode(codeKind, content string, bars *BitList) barcode.Barcode {
|
func New1DCode(codeKind, content string, bars *BitList) barcode.Barcode {
|
||||||
return &base1DCode{bars, codeKind, content, barcode.ColorScheme16}
|
return &base1DCode{bars, codeKind, content}
|
||||||
}
|
|
||||||
|
|
||||||
// New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
|
|
||||||
func New1DCodeWithColor(codeKind, content string, bars *BitList, color barcode.ColorScheme) barcode.Barcode {
|
|
||||||
return &base1DCode{bars, codeKind, content, color}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user