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