| 1 | package onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/ |
| 2 | |
| 3 | import ( |
| 4 | "github.com/makiuchi-d/gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/" |
| 5 | ) |
| 6 | |
| 7 | // upce_MIDDLE_END_PATTERN The pattern that marks the middle, and end, of a UPC-E pattern. |
| 8 | // There is no "second half" to a UPC-E barcode. |
| 9 | var upce_MIDDLE_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upce_MIDDLE_END_PATTERN. = []int{1, 1, 1, 1, 1, 1} |
| 10 | |
| 11 | // For an UPC-E barcode, the final digit is represented by the parities used |
| 12 | // to encode the middle six digits, according to the table below. |
| 13 | // |
| 14 | // Parity of next 6 digits |
| 15 | // Digit 0 1 2 3 4 5 |
| 16 | // 0 Even Even Even Odd Odd Odd |
| 17 | // 1 Even Even Odd Even Odd Odd |
| 18 | // 2 Even Even Odd Odd Even Odd |
| 19 | // 3 Even Even Odd Odd Odd Even |
| 20 | // 4 Even Odd Even Even Odd Odd |
| 21 | // 5 Even Odd Odd Even Even Odd |
| 22 | // 6 Even Odd Odd Odd Even Even |
| 23 | // 7 Even Odd Even Odd Even Odd |
| 24 | // 8 Even Odd Even Odd Odd Even |
| 25 | // 9 Even Odd Odd Even Odd Even |
| 26 | // |
| 27 | // The encoding is represented by the following array, which is a bit pattern |
| 28 | // using Odd = 0 and Even = 1. For example, 5 is represented by: |
| 29 | // |
| 30 | // Odd Even Even Odd Odd Even |
| 31 | // in binary: |
| 32 | // 0 1 1 0 0 1 == 0x19 |
| 33 | // |
| 34 | |
| 35 | // upce_NUMSYS_AND_CHECK_DIGIT_PATTERNS See {@link #L_AND_G_PATTERNS}; |
| 36 | // these values similarly represent patterns of |
| 37 | // even-odd parity encodings of digits that imply both the number system (0 or 1) |
| 38 | // used, and the check digit. |
| 39 | // |
| 40 | var upce_NUMSYS_AND_CHECK_DIGIT_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upce_NUMSYS_AND_CHECK_DIGIT_PATTERNS. = [][]int{ |
| 41 | {0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25}, |
| 42 | {0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A}, |
| 43 | } |
| 44 | |
| 45 | type upcEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader# struct { |
| 46 | *upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#upceanReader. |
| 47 | decodeMiddleCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#decodeMiddleCounters. []int |
| 48 | } |
| 49 | |
| 50 | func NewUPCEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/NewUPCEReader().() gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Reader# { |
| 51 | this := &upcEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#{ |
| 52 | decodeMiddleCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#decodeMiddleCounters.: make([]int, 4), |
| 53 | } |
| 54 | this.upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#upceanReader. = newUPCEANReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/newUPCEANReader().(this) |
| 55 | return this |
| 56 | } |
| 57 | |
| 58 | func (this *upcEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#) decodeMiddlescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#decodeMiddle().(row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, startRange []int, result []byte) (int, []byte, error) { |
| 59 | counters := this.decodeMiddleCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#decodeMiddleCounters. |
| 60 | counters[0] = 0 |
| 61 | counters[1] = 0 |
| 62 | counters[2] = 0 |
| 63 | counters[3] = 0 |
| 64 | end := row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().() |
| 65 | rowOffset := startRange[1] |
| 66 | |
| 67 | lgPatternFound := 0 |
| 68 | |
| 69 | result = append(result, '0') // put in determineNumSysAndCheckDigit() |
| 70 | |
| 71 | for x := 0; x < 6 && rowOffset < end; x++ { |
| 72 | bestMatch, e := upceanReader_decodeDigitscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_decodeDigit().(row, counters, rowOffset, UPCEANReader_L_AND_G_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_AND_G_PATTERNS.) |
| 73 | if e != nil { |
| 74 | return 0, result, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.WrapNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/WrapNotFoundException().(e) |
| 75 | } |
| 76 | result = append(result, '0'+byte(bestMatch%10)) |
| 77 | for _, counter := range counters { |
| 78 | rowOffset += counter |
| 79 | } |
| 80 | if bestMatch >= 10 { |
| 81 | lgPatternFound |= 1 << uint(5-x) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | result, e := determineNumSysAndCheckDigitscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/determineNumSysAndCheckDigit().(result, lgPatternFound) |
| 86 | if e != nil { |
| 87 | return 0, result, e |
| 88 | } |
| 89 | |
| 90 | return rowOffset, result, nil |
| 91 | } |
| 92 | |
| 93 | func (this *upcEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#) decodeEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#decodeEnd().(row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, endStart int) ([]int, error) { |
| 94 | return upceanReader_findGuardPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findGuardPattern().(row, endStart, true, upce_MIDDLE_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upce_MIDDLE_END_PATTERN.) |
| 95 | } |
| 96 | |
| 97 | func (this *upcEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#) checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#checkChecksum().(s string) (bool, error) { |
| 98 | return upceanReader_checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_checkChecksum().(convertUPCEtoUPCAscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/convertUPCEtoUPCA().(s)) |
| 99 | } |
| 100 | |
| 101 | func determineNumSysAndCheckDigitscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/determineNumSysAndCheckDigit().(resultString []byte, lgPatternFound int) ([]byte, error) { |
| 102 | for numSys := byte(0); numSys <= 1; numSys++ { |
| 103 | for d := byte(0); d < 10; d++ { |
| 104 | if lgPatternFound == upce_NUMSYS_AND_CHECK_DIGIT_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upce_NUMSYS_AND_CHECK_DIGIT_PATTERNS.[numSys][d] { |
| 105 | resultString[0] = '0' + numSys |
| 106 | resultString = append(resultString, '0'+d) |
| 107 | return resultString, nil |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | return resultString, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().() |
| 112 | } |
| 113 | |
| 114 | func (this *upcEReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#) getBarcodeFormatscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upcEReader#getBarcodeFormat().() gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormatscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat# { |
| 115 | return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormat_UPC_Escip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat_UPC_E. |
| 116 | } |
| 117 | |
| 118 | // convertUPCEtoUPCA Expands a UPC-E value back into its full, equivalent UPC-A code value. |
| 119 | // |
| 120 | // @param upce UPC-E code as string of digits |
| 121 | // @return equivalent UPC-A code as string of digits |
| 122 | // |
| 123 | func convertUPCEtoUPCAscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/convertUPCEtoUPCA().(upce string) string { |
| 124 | upceChars := upce[1:7] |
| 125 | result := make([]byte, 0, 12) |
| 126 | result = append(result, upce[0]) |
| 127 | lastChar := upceChars[5] |
| 128 | switch lastChar { |
| 129 | case '0', '1', '2': |
| 130 | result = append(result, upceChars[0:2]...) |
| 131 | result = append(result, lastChar) |
| 132 | result = append(result, []byte("0000")...) |
| 133 | result = append(result, upceChars[2:5]...) |
| 134 | case '3': |
| 135 | result = append(result, upceChars[0:3]...) |
| 136 | result = append(result, []byte("00000")...) |
| 137 | result = append(result, upceChars[3:5]...) |
| 138 | case '4': |
| 139 | result = append(result, upceChars[0:4]...) |
| 140 | result = append(result, []byte("00000")...) |
| 141 | result = append(result, upceChars[4]) |
| 142 | default: |
| 143 | result = append(result, upceChars[0:5]...) |
| 144 | result = append(result, []byte("0000")...) |
| 145 | result = append(result, lastChar) |
| 146 | } |
| 147 | // Only append check digit in conversion if supplied |
| 148 | if len(upce) >= 8 { |
| 149 | result = append(result, upce[7]) |
| 150 | } |
| 151 | return string(result) |
| 152 | } |