MCPcopy Create free account
hub / github.com/boombuler/barcode / EncodeWithColor

Function EncodeWithColor

code93/encoder.go:79–108  ·  view source on GitHub ↗

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

(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme)

Source from the content-addressed store, hash-verified

77// Encode returns a code93 barcode for the given content and color scheme
78// if includeChecksum is set to true, two checksum characters are calculated and added to the content
79func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme) (barcode.Barcode, error) {
80 if fullASCIIMode {
81 var err error
82 content, err = prepare(content)
83 if err != nil {
84 return nil, err
85 }
86 } else if strings.ContainsRune(content, '*') {
87 return nil, errors.New("invalid data! content may not contain '*'")
88 }
89
90 data := content + string(getChecksum(content, 20))
91 if includeChecksum {
92 data += string(getChecksum(data, 15))
93 }
94
95 data = "*" + data + "*"
96 result := new(utils.BitList)
97
98 for _, r := range data {
99 info, ok := encodeTable[r]
100 if !ok {
101 return nil, errors.New("invalid data!")
102 }
103 result.AddBits(info.data, 9)
104 }
105 result.AddBit(true)
106
107 return utils.New1DCodeWithColor(barcode.TypeCode93, content, result, color), nil
108}
109
110// Encode returns a code93 barcode for the given content
111// if includeChecksum is set to true, two checksum characters are calculated and added to the content

Callers 1

EncodeFunction · 0.70

Calls 5

New1DCodeWithColorFunction · 0.92
AddBitsMethod · 0.80
AddBitMethod · 0.80
prepareFunction · 0.70
getChecksumFunction · 0.70

Tested by

no test coverage detected