Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
914f64a08d | ||
|
c575a3c357 | ||
|
ca3e24f327 | ||
|
d79eb8727b | ||
|
d5743d95af | ||
|
49d4ce8a5b | ||
|
a8e67c5d16 | ||
|
b1129f9d8b | ||
|
1c8224977e | ||
|
2c9211e1ea | ||
|
30509e0dd7 | ||
|
e966fa7106 | ||
|
87ab0677e3 | ||
|
f3630e1cd4 | ||
|
e8e52a74a7 | ||
|
83789dfea1 | ||
|
d6f8bd41de | ||
|
65580ac6e3 | ||
|
abf40d274d | ||
|
608a8ad611 | ||
|
196dd6e4c1 | ||
|
6c824513ba | ||
|
7bcb6b0526 | ||
|
34fff276c7 | ||
|
3d4b26039d | ||
|
3c06908149 | ||
|
8a3bb0c01c | ||
|
5a7395f627 | ||
|
33202215fe | ||
|
79be24267e | ||
|
58ed45cf65 |
@ -27,8 +27,8 @@ import (
|
|||||||
"image/png"
|
"image/png"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/qr"
|
"git.bbr-dev.info/brajkovic/barcode/qr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -48,6 +48,6 @@ func main() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Documentation ##
|
## Documentation ##
|
||||||
See [GoDoc](https://godoc.org/github.com/boombuler/barcode)
|
See [GoDoc](https://godoc.org/git.bbr-dev.info/brajkovic/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,18 +5,19 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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) *aztecCode {
|
func newAztecCode(size int, color barcode.ColorScheme) *aztecCode {
|
||||||
return &aztecCode{utils.NewBitList(size * size), size, nil}
|
return &aztecCode{utils.NewBitList(size * size), size, nil, barcode.ColorScheme16}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) Content() string {
|
func (c *aztecCode) Content() string {
|
||||||
@ -28,7 +29,11 @@ func (c *aztecCode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) ColorModel() color.Model {
|
func (c *aztecCode) ColorModel() color.Model {
|
||||||
return color.Gray16Model
|
return c.color.Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *aztecCode) ColorScheme() barcode.ColorScheme {
|
||||||
|
return c.color
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) Bounds() image.Rectangle {
|
func (c *aztecCode) Bounds() image.Rectangle {
|
||||||
@ -37,9 +42,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 color.Black
|
return c.color.Foreground
|
||||||
}
|
}
|
||||||
return color.White
|
return c.color.Background
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aztecCode) set(x, y int) {
|
func (c *aztecCode) set(x, y int) {
|
||||||
|
@ -4,8 +4,8 @@ package aztec
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -124,6 +124,11 @@ 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
|
||||||
@ -215,7 +220,7 @@ func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Ba
|
|||||||
alignmentMap[origCenter+i] = center + newOffset + 1
|
alignmentMap[origCenter+i] = center + newOffset + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
code := newAztecCode(matrixSize)
|
code := newAztecCode(matrixSize, color)
|
||||||
code.content = data
|
code.content = data
|
||||||
|
|
||||||
// draw data bits
|
// draw data bits
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_StuffBits(t *testing.T) {
|
func Test_StuffBits(t *testing.T) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package aztec
|
package aztec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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 (
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func highlevelEncode(data []byte) *utils.BitList {
|
func highlevelEncode(data []byte) *utils.BitList {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bitStr(bl *utils.BitList) string {
|
func bitStr(bl *utils.BitList) string {
|
||||||
|
@ -3,7 +3,7 @@ package aztec
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodingMode byte
|
type encodingMode byte
|
||||||
|
@ -3,7 +3,7 @@ package aztec
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type token interface {
|
type token interface {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package barcode
|
package barcode
|
||||||
|
|
||||||
import "image"
|
import (
|
||||||
|
"image"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeAztec = "Aztec"
|
TypeAztec = "Aztec"
|
||||||
@ -40,3 +42,7 @@ type BarcodeIntCS interface {
|
|||||||
Barcode
|
Barcode
|
||||||
CheckSum() int
|
CheckSum() int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BarcodeColor interface {
|
||||||
|
ColorScheme() ColorScheme
|
||||||
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var encodingTable = map[rune][]bool{
|
var encodingTable = map[rune][]bool{
|
||||||
@ -25,15 +25,15 @@ var encodingTable = map[rune][]bool{
|
|||||||
':': []bool{true, true, false, true, false, true, true, false, true, true},
|
':': []bool{true, true, false, true, false, true, true, false, true, true},
|
||||||
'/': []bool{true, true, false, true, true, false, true, false, true, true},
|
'/': []bool{true, true, false, true, true, false, true, false, true, true},
|
||||||
'.': []bool{true, true, false, true, true, false, true, true, false, true},
|
'.': []bool{true, true, false, true, true, false, true, true, false, true},
|
||||||
'+': []bool{true, false, true, true, false, false, true, true, false, false, true, true},
|
'+': []bool{true, false, true, true, false, true, true, false, true, true},
|
||||||
'A': []bool{true, false, true, true, false, false, true, false, false, true},
|
'A': []bool{true, false, true, true, false, false, true, false, false, true},
|
||||||
'B': []bool{true, false, true, false, false, true, false, false, true, true},
|
'B': []bool{true, false, false, true, false, false, true, false, true, true},
|
||||||
'C': []bool{true, false, false, true, false, false, true, false, true, true},
|
'C': []bool{true, false, true, false, false, true, false, false, true, true},
|
||||||
'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
|
// Encode creates a codabar barcode for the given content and color scheme
|
||||||
func Encode(content string) (barcode.Barcode, error) {
|
func EncodeWithColor(content string, color barcode.ColorScheme) (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,5 +45,10 @@ func Encode(content string) (barcode.Barcode, error) {
|
|||||||
}
|
}
|
||||||
resBits.AddBit(encodingTable[r]...)
|
resBits.AddBit(encodingTable[r]...)
|
||||||
}
|
}
|
||||||
return utils.New1DCode(barcode.TypeCodabar, content, resBits), nil
|
return utils.New1DCodeWithColor(barcode.TypeCodabar, content, resBits, color), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode creates a codabar barcode for the given content
|
||||||
|
func Encode(content string) (barcode.Barcode, error) {
|
||||||
|
return EncodeWithColor(content, barcode.ColorScheme16)
|
||||||
}
|
}
|
||||||
|
@ -28,5 +28,5 @@ func Test_Encode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testEncode("A40156B", "10110010010101101001010101001101010110010110101001010010101101010010011")
|
testEncode("A40156B", "10110010010101101001010101001101010110010110101001010010101101001001011")
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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
|
// Encode creates a Code 128 barcode for the given content and color scheme
|
||||||
func Encode(content string) (barcode.BarcodeIntCS, error) {
|
func EncodeWithColor(content string, color barcode.ColorScheme) (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,10 +180,19 @@ func Encode(content string) (barcode.BarcodeIntCS, error) {
|
|||||||
sum = sum % 103
|
sum = sum % 103
|
||||||
result.AddBit(encodingTable[sum]...)
|
result.AddBit(encodingTable[sum]...)
|
||||||
result.AddBit(encodingTable[stopSymbol]...)
|
result.AddBit(encodingTable[stopSymbol]...)
|
||||||
return utils.New1DCodeIntCheckSum(barcode.TypeCode128, content, result, sum), nil
|
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeCode128, content, result, sum, color), 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))
|
||||||
@ -199,5 +208,5 @@ func EncodeWithoutChecksum(content string) (barcode.Barcode, error) {
|
|||||||
result.AddBit(encodingTable[idx]...)
|
result.AddBit(encodingTable[idx]...)
|
||||||
}
|
}
|
||||||
result.AddBit(encodingTable[stopSymbol]...)
|
result.AddBit(encodingTable[stopSymbol]...)
|
||||||
return utils.New1DCode(barcode.TypeCode128, content, result), nil
|
return utils.New1DCodeWithColor(barcode.TypeCode128, content, result, color), nil
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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
|
// Encode returns a code39 barcode for the given content and color scheme
|
||||||
// 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 Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.BarcodeIntCS, error) {
|
func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme) (barcode.BarcodeIntCS, error) {
|
||||||
if fullASCIIMode {
|
if fullASCIIMode {
|
||||||
var err error
|
var err error
|
||||||
content, err = prepare(content)
|
content, err = prepare(content)
|
||||||
@ -148,5 +148,11 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
checkSum = 0
|
checkSum = 0
|
||||||
}
|
}
|
||||||
return utils.New1DCodeIntCheckSum(barcode.TypeCode39, content, result, int(checkSum)), nil
|
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeCode39, content, result, int(checkSum), color), 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"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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
|
// Encode returns a code93 barcode for the given content and color scheme
|
||||||
// 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 Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.Barcode, error) {
|
func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme) (barcode.Barcode, error) {
|
||||||
if fullASCIIMode {
|
if fullASCIIMode {
|
||||||
var err error
|
var err error
|
||||||
content, err = prepare(content)
|
content, err = prepare(content)
|
||||||
@ -88,7 +88,9 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := content + string(getChecksum(content, 20))
|
data := content + string(getChecksum(content, 20))
|
||||||
data += string(getChecksum(data, 15))
|
if includeChecksum {
|
||||||
|
data += string(getChecksum(data, 15))
|
||||||
|
}
|
||||||
|
|
||||||
data = "*" + data + "*"
|
data = "*" + data + "*"
|
||||||
result := new(utils.BitList)
|
result := new(utils.BitList)
|
||||||
@ -102,7 +104,13 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B
|
|||||||
}
|
}
|
||||||
result.AddBit(true)
|
result.AddBit(true)
|
||||||
|
|
||||||
return utils.New1DCode(barcode.TypeCode93, content, result), nil
|
return utils.New1DCodeWithColor(barcode.TypeCode93, content, result, color), 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 {
|
||||||
|
39
color_scheme.go
Normal file
39
color_scheme.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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,8 +1,10 @@
|
|||||||
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)
|
||||||
@ -11,13 +13,15 @@ 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) *codeLayout {
|
func newCodeLayout(size *dmCodeSize, color barcode.ColorScheme) *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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +163,7 @@ func (l *codeLayout) SetValues(data []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *codeLayout) Merge() *datamatrixCode {
|
func (l *codeLayout) Merge() *datamatrixCode {
|
||||||
result := newDataMatrixCode(l.size)
|
result := newDataMatrixCodeWithColor(l.size, l.color)
|
||||||
|
|
||||||
//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.RegionCountHorizontal * 2)) / s.RegionCountHorizontal
|
return (s.Rows - (s.RegionCountVertical * 2)) / s.RegionCountVertical
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) RegionColumns() int {
|
func (s *dmCodeSize) RegionColumns() int {
|
||||||
return (s.Columns - (s.RegionCountVertical * 2)) / s.RegionCountVertical
|
return (s.Columns - (s.RegionCountHorizontal * 2)) / s.RegionCountHorizontal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) MatrixRows() int {
|
func (s *dmCodeSize) MatrixRows() int {
|
||||||
return s.RegionRows() * s.RegionCountHorizontal
|
return s.RegionRows() * s.RegionCountVertical
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) MatrixColumns() int {
|
func (s *dmCodeSize) MatrixColumns() int {
|
||||||
return s.RegionColumns() * s.RegionCountVertical
|
return s.RegionColumns() * s.RegionCountHorizontal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dmCodeSize) DataCodewords() int {
|
func (s *dmCodeSize) DataCodewords() int {
|
||||||
|
@ -4,18 +4,23 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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, ""}
|
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", barcode.ColorScheme16}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) Content() string {
|
func (c *datamatrixCode) Content() string {
|
||||||
@ -27,7 +32,11 @@ func (c *datamatrixCode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) ColorModel() color.Model {
|
func (c *datamatrixCode) ColorModel() color.Model {
|
||||||
return color.Gray16Model
|
return c.color.Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *datamatrixCode) ColorScheme() barcode.ColorScheme {
|
||||||
|
return c.color
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *datamatrixCode) Bounds() image.Rectangle {
|
func (c *datamatrixCode) Bounds() image.Rectangle {
|
||||||
@ -36,9 +45,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 color.Black
|
return c.color.Foreground
|
||||||
}
|
}
|
||||||
return color.White
|
return c.color.Background
|
||||||
}
|
}
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Encode returns a Datamatrix barcode for the given content
|
// Encode returns a Datamatrix barcode for the given content and color scheme
|
||||||
func Encode(content string) (barcode.Barcode, error) {
|
func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
|
||||||
data := encodeText(content)
|
data := encodeText(content)
|
||||||
|
|
||||||
var size *dmCodeSize
|
var size *dmCodeSize
|
||||||
@ -23,7 +23,7 @@ func Encode(content string) (barcode.Barcode, error) {
|
|||||||
}
|
}
|
||||||
data = addPadding(data, size.DataCodewords())
|
data = addPadding(data, size.DataCodewords())
|
||||||
data = ec.calcECC(data, size)
|
data = ec.calcECC(data, size)
|
||||||
code := render(data, size)
|
code := render(data, size, color)
|
||||||
if code != nil {
|
if code != nil {
|
||||||
code.content = content
|
code.content = content
|
||||||
return code, nil
|
return code, nil
|
||||||
@ -31,8 +31,13 @@ func Encode(content string) (barcode.Barcode, error) {
|
|||||||
return nil, errors.New("unable to render barcode")
|
return nil, errors.New("unable to render barcode")
|
||||||
}
|
}
|
||||||
|
|
||||||
func render(data []byte, size *dmCodeSize) *datamatrixCode {
|
// Encode returns a Datamatrix barcode for the given content
|
||||||
cl := newCodeLayout(size)
|
func Encode(content string) (barcode.Barcode, error) {
|
||||||
|
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)
|
||||||
|
|
||||||
@ -69,7 +74,12 @@ 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
|
||||||
data = append(data, byte((129+R)%254))
|
tmp := 129 + R
|
||||||
|
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 (
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorCorrection struct {
|
type errorCorrection struct {
|
||||||
|
@ -4,8 +4,8 @@ package ean
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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
|
// Encode returns a EAN 8 or EAN 13 barcode for the given code and color scheme
|
||||||
func Encode(code string) (barcode.BarcodeIntCS, error) {
|
func EncodeWithColor(code string, color barcode.ColorScheme) (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,13 +175,18 @@ func Encode(code string) (barcode.BarcodeIntCS, error) {
|
|||||||
if len(code) == 8 {
|
if len(code) == 8 {
|
||||||
result := encodeEAN8(code)
|
result := encodeEAN8(code)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
return utils.New1DCodeIntCheckSum(barcode.TypeEAN8, code, result, checkSum), nil
|
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeEAN8, code, result, checkSum, color), 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.New1DCodeIntCheckSum(barcode.TypeEAN13, code, result, checkSum), nil
|
return utils.New1DCodeIntCheckSumWithColor(barcode.TypeEAN13, code, result, checkSum, color), 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)
|
||||||
|
}
|
||||||
|
@ -3,8 +3,8 @@ package pdf417
|
|||||||
import "math"
|
import "math"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
minCols = 2
|
minCols = 9
|
||||||
maxCols = 30
|
maxCols = 9
|
||||||
maxRows = 30
|
maxRows = 30
|
||||||
minRows = 2
|
minRows = 2
|
||||||
moduleHeight = 2
|
moduleHeight = 2
|
||||||
|
@ -4,18 +4,18 @@ package pdf417
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
padding_codeword = 900
|
padding_codeword = 900
|
||||||
)
|
)
|
||||||
|
|
||||||
// Encodes the given data as PDF417 barcode.
|
// Encodes the given data and color scheme 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 Encode(data string, securityLevel byte) (barcode.Barcode, error) {
|
func EncodeWithColor(data string, securityLevel byte, color barcode.ColorScheme) (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,6 +34,7 @@ func Encode(data string, securityLevel byte) (barcode.Barcode, error) {
|
|||||||
|
|
||||||
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 {
|
||||||
@ -70,6 +71,13 @@ func Encode(data string, securityLevel byte) (barcode.Barcode, error) {
|
|||||||
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"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encodingMode byte
|
type encodingMode byte
|
||||||
|
@ -4,14 +4,15 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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 {
|
||||||
@ -23,7 +24,11 @@ func (c *pdfBarcode) Content() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) ColorModel() color.Model {
|
func (c *pdfBarcode) ColorModel() color.Model {
|
||||||
return color.Gray16Model
|
return c.color.Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *pdfBarcode) ColorScheme() barcode.ColorScheme {
|
||||||
|
return c.color
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pdfBarcode) Bounds() image.Rectangle {
|
func (c *pdfBarcode) Bounds() image.Rectangle {
|
||||||
@ -34,7 +39,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 color.Black
|
return c.color.Foreground
|
||||||
}
|
}
|
||||||
return color.White
|
return c.color.Background
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const charSet string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
const charSet string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
||||||
|
@ -3,7 +3,7 @@ package qr
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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, error correction level and uses the given encoding
|
// Encode returns a QR barcode with the given content and color scheme, error correction level and uses the given encoding
|
||||||
func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error) {
|
func EncodeWithColor(content string, level ErrorCorrectionLevel, mode Encoding, color barcode.ColorScheme) (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,19 +63,23 @@ func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.
|
|||||||
|
|
||||||
blocks := splitToBlocks(bits.IterateBytes(), vi)
|
blocks := splitToBlocks(bits.IterateBytes(), vi)
|
||||||
data := blocks.interleave(vi)
|
data := blocks.interleave(vi)
|
||||||
result := render(data, vi)
|
result := render(data, vi, color)
|
||||||
result.content = content
|
result.content = content
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func render(data []byte, vi *versionInfo) *qrcode {
|
func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error) {
|
||||||
|
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] = newBarcode(dim)
|
results[i] = newBarCodeWithColor(dim, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
occupied := newBarcode(dim)
|
occupied := newBarCodeWithColor(dim, color)
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type test struct {
|
type test struct {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package qr
|
package qr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorCorrection struct {
|
type errorCorrection struct {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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,14 +5,15 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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 {
|
||||||
@ -24,7 +25,11 @@ func (qr *qrcode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) ColorModel() color.Model {
|
func (qr *qrcode) ColorModel() color.Model {
|
||||||
return color.Gray16Model
|
return qr.color.Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *qrcode) ColorScheme() barcode.ColorScheme {
|
||||||
|
return c.color
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) Bounds() image.Rectangle {
|
func (qr *qrcode) Bounds() image.Rectangle {
|
||||||
@ -33,9 +38,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 color.Black
|
return qr.color.Foreground
|
||||||
}
|
}
|
||||||
return color.White
|
return qr.color.Background
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *qrcode) Get(x, y int) bool {
|
func (qr *qrcode) Get(x, y int) bool {
|
||||||
@ -158,9 +163,14 @@ func (qr *qrcode) calcPenaltyRule4() uint {
|
|||||||
return uint(math.Min(floor, ceil) * 10)
|
return uint(math.Min(floor, ceil) * 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBarcode(dim int) *qrcode {
|
func newBarCodeWithColor(dim int, color barcode.ColorScheme) *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"
|
||||||
|
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func encodeUnicode(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
func encodeUnicode(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
|
||||||
|
@ -49,11 +49,22 @@ 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)
|
return scale1DCode(bc, width, height, fill)
|
||||||
case 2:
|
case 2:
|
||||||
return scale2DCode(bc, width, height)
|
return scale2DCode(bc, width, height, fill)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("unsupported barcode format")
|
return nil, errors.New("unsupported barcode format")
|
||||||
@ -72,7 +83,7 @@ func newScaledBC(wrapped Barcode, wrapperFunc wrapFunc, rect image.Rectangle) Ba
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
|
func scale2DCode(bc Barcode, width, height int, fill color.Color) (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
|
||||||
@ -87,12 +98,12 @@ func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
|
|||||||
|
|
||||||
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 color.White
|
return fill
|
||||||
}
|
}
|
||||||
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 color.White
|
return fill
|
||||||
}
|
}
|
||||||
return bc.At(x, y)
|
return bc.At(x, y)
|
||||||
}
|
}
|
||||||
@ -104,7 +115,7 @@ func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
|
|||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func scale1DCode(bc Barcode, width, height int) (Barcode, error) {
|
func scale1DCode(bc Barcode, width, height int, fill color.Color) (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))
|
||||||
@ -116,12 +127,12 @@ func scale1DCode(bc Barcode, width, height int) (Barcode, error) {
|
|||||||
|
|
||||||
wrap := func(x, y int) color.Color {
|
wrap := func(x, y int) color.Color {
|
||||||
if x < offsetX {
|
if x < offsetX {
|
||||||
return color.White
|
return fill
|
||||||
}
|
}
|
||||||
x = (x - offsetX) / factor
|
x = (x - offsetX) / factor
|
||||||
|
|
||||||
if x >= orgWidth {
|
if x >= orgWidth {
|
||||||
return color.White
|
return fill
|
||||||
}
|
}
|
||||||
return bc.At(x, 0)
|
return bc.At(x, 0)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/barcode"
|
||||||
"github.com/boombuler/barcode/utils"
|
"git.bbr-dev.info/brajkovic/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
|
// Encode creates a codabar barcode for the given content and color scheme
|
||||||
func Encode(content string, interleaved bool) (barcode.Barcode, error) {
|
func EncodeWithColor(content string, interleaved bool, color barcode.ColorScheme) (barcode.Barcode, error) {
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return nil, errors.New("content is empty")
|
return nil, errors.New("content is empty")
|
||||||
}
|
}
|
||||||
@ -131,8 +131,13 @@ func Encode(content string, interleaved bool) (barcode.Barcode, error) {
|
|||||||
resBits.AddBit(mode.end...)
|
resBits.AddBit(mode.end...)
|
||||||
|
|
||||||
if interleaved {
|
if interleaved {
|
||||||
return utils.New1DCode(barcode.Type2of5Interleaved, content, resBits), nil
|
return utils.New1DCodeWithColor(barcode.Type2of5Interleaved, content, resBits, color), nil
|
||||||
} else {
|
} else {
|
||||||
return utils.New1DCode(barcode.Type2of5, content, resBits), nil
|
return utils.New1DCodeWithColor(barcode.Type2of5, content, resBits, color), 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,13 +5,14 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/boombuler/barcode"
|
"git.bbr-dev.info/brajkovic/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 {
|
||||||
@ -28,7 +29,11 @@ func (c *base1DCode) Metadata() barcode.Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *base1DCode) ColorModel() color.Model {
|
func (c *base1DCode) ColorModel() color.Model {
|
||||||
return color.Gray16Model
|
return c.color.Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *base1DCode) ColorScheme() barcode.ColorScheme {
|
||||||
|
return c.color
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *base1DCode) Bounds() image.Rectangle {
|
func (c *base1DCode) Bounds() image.Rectangle {
|
||||||
@ -37,21 +42,31 @@ 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 color.Black
|
return c.color.Foreground
|
||||||
}
|
}
|
||||||
return color.White
|
return c.color.Background
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *base1DCodeIntCS) CheckSum() int {
|
func (c *base1DCodeIntCS) CheckSum() int {
|
||||||
return c.checksum
|
return c.checksum
|
||||||
}
|
}
|
||||||
|
|
||||||
// New1DCode 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}, checksum}
|
return &base1DCodeIntCS{base1DCode{bars, codeKind, content, barcode.ColorScheme16}, 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}
|
return &base1DCode{bars, codeKind, content, barcode.ColorScheme16}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import "testing"
|
|||||||
|
|
||||||
func Test_RuneToIntIntToRune(t *testing.T) {
|
func Test_RuneToIntIntToRune(t *testing.T) {
|
||||||
if IntToRune(0) != '0' {
|
if IntToRune(0) != '0' {
|
||||||
t.Errorf("failed IntToRune(0) returned %d", string(IntToRune(0)))
|
t.Errorf("failed IntToRune(0) returned %d", IntToRune(0))
|
||||||
}
|
}
|
||||||
if IntToRune(9) != '9' {
|
if IntToRune(9) != '9' {
|
||||||
t.Errorf("failed IntToRune(9) returned %d", IntToRune(9))
|
t.Errorf("failed IntToRune(9) returned %d", IntToRune(9))
|
||||||
@ -13,12 +13,12 @@ func Test_RuneToIntIntToRune(t *testing.T) {
|
|||||||
t.Errorf("failed IntToRune(10) returned %d", IntToRune(10))
|
t.Errorf("failed IntToRune(10) returned %d", IntToRune(10))
|
||||||
}
|
}
|
||||||
if RuneToInt('0') != 0 {
|
if RuneToInt('0') != 0 {
|
||||||
t.Error("failed RuneToInt('0') returned %d", RuneToInt(0))
|
t.Errorf("failed RuneToInt('0') returned %d", RuneToInt(0))
|
||||||
}
|
}
|
||||||
if RuneToInt('9') != 9 {
|
if RuneToInt('9') != 9 {
|
||||||
t.Error("failed RuneToInt('9') returned %d", RuneToInt(9))
|
t.Errorf("failed RuneToInt('9') returned %d", RuneToInt(9))
|
||||||
}
|
}
|
||||||
if RuneToInt('F') != -1 {
|
if RuneToInt('F') != -1 {
|
||||||
t.Error("failed RuneToInt('F') returned %d", RuneToInt('F'))
|
t.Errorf("failed RuneToInt('F') returned %d", RuneToInt('F'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user