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

Function EncodeWithColor

code39/encoder.go:116–152  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

114// Encode returns a code39 barcode for the given content and color scheme
115// if includeChecksum is set to true, a checksum character is calculated and added to the content
116func EncodeWithColor(content string, includeChecksum bool, fullASCIIMode bool, color barcode.ColorScheme) (barcode.BarcodeIntCS, error) {
117 if fullASCIIMode {
118 var err error
119 content, err = prepare(content)
120 if err != nil {
121 return nil, err
122 }
123 } else if strings.ContainsRune(content, '*') {
124 return nil, errors.New("invalid data! try full ascii mode")
125 }
126
127 data := "*" + content
128 if includeChecksum {
129 data += getChecksum(content)
130 }
131 data += "*"
132
133 result := new(utils.BitList)
134
135 for i, r := range data {
136 if i != 0 {
137 result.AddBit(false)
138 }
139
140 info, ok := encodeTable[r]
141 if !ok {
142 return nil, errors.New("invalid data! try full ascii mode")
143 }
144 result.AddBit(info.data...)
145 }
146
147 checkSum, err := strconv.ParseInt(getChecksum(content), 10, 64)
148 if err != nil {
149 checkSum = 0
150 }
151 return utils.New1DCodeIntCheckSumWithColor(barcode.TypeCode39, content, result, int(checkSum), color), nil
152}
153
154// Encode returns a code39 barcode for the given content
155// if includeChecksum is set to true, a checksum character is calculated and added to the content

Callers 1

EncodeFunction · 0.70

Calls 4

AddBitMethod · 0.80
prepareFunction · 0.70
getChecksumFunction · 0.70

Tested by

no test coverage detected