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)
| 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 |
| 116 | func 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 |
no test coverage detected