下面列出了com.google.zxing.BarcodeFormat# CODABAR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static int symbolToFormat(BarcodeFormat symbol) {
if (BarcodeFormat.AZTEC == symbol) {
return 225;
} else if (BarcodeFormat.CODABAR == symbol) {
return 38;
} else if (BarcodeFormat.CODE_128 == symbol) {
return 128;
} else if (BarcodeFormat.CODE_39 == symbol) {
return 39;
} else if (BarcodeFormat.CODE_93 == symbol) {
return 93;
} else if (BarcodeFormat.DATA_MATRIX == symbol) {
return 200;
} else if (BarcodeFormat.EAN_13 == symbol) {
return 13;
} else if (BarcodeFormat.EAN_8 == symbol) {
return 8;
} else if (BarcodeFormat.ITF == symbol) {
return 25;
} else if (BarcodeFormat.MAXICODE == symbol) {
return 94;
} else if (BarcodeFormat.PDF_417 == symbol) {
return 57;
} else if (BarcodeFormat.QR_CODE == symbol) {
return 64;
} else if (BarcodeFormat.RSS_14 == symbol) {
return 34;
} else if (BarcodeFormat.RSS_EXPANDED == symbol) {
return 35;
} else if (BarcodeFormat.UPC_A == symbol) {
return 12;
} else if (BarcodeFormat.UPC_E == symbol) {
return 9;
} else if (BarcodeFormat.UPC_EAN_EXTENSION == symbol) {
return 15;
}
return -1;
}
private static BarcodeFormat formatToSymbol(int format) {
if (225 == format) {
return BarcodeFormat.AZTEC;
} else if (38 == format) {
return BarcodeFormat.CODABAR;
} else if (128 == format) {
return BarcodeFormat.CODE_128;
} else if (39 == format) {
return BarcodeFormat.CODE_39;
} else if (93 == format) {
return BarcodeFormat.CODE_93;
} else if (200 == format) {
return BarcodeFormat.DATA_MATRIX;
} else if (13 == format) {
return BarcodeFormat.EAN_13;
} else if (8 == format) {
return BarcodeFormat.EAN_8;
} else if (25 == format) {
return BarcodeFormat.ITF;
} else if (94 == format) {
return BarcodeFormat.MAXICODE;
} else if (57 == format) {
return BarcodeFormat.PDF_417;
} else if (64 == format) {
return BarcodeFormat.QR_CODE;
} else if (34 == format) {
return BarcodeFormat.RSS_14;
} else if (35 == format) {
return BarcodeFormat.RSS_EXPANDED;
} else if (12 == format) {
return BarcodeFormat.UPC_A;
} else if (9 == format) {
return BarcodeFormat.UPC_E;
} else if (15 == format) {
return BarcodeFormat.UPC_EAN_EXTENSION;
}
return null;
}
/**
* Method is used to convert parsed id to BarcodeFormat to create an image of the qr code
* @param id as int
* @return format as BarcodeFormat
*/
public BarcodeFormat idToBarcodeFormat(int id){
BarcodeFormat format;
switch(id){
case 1:
format = BarcodeFormat.CODABAR;
break;
case 2:
format= BarcodeFormat.CODE_128;
break;
case 3:
format = BarcodeFormat.CODE_39;
break;
case 4:
format = BarcodeFormat.EAN_13;
break;
case 5:
format = BarcodeFormat.EAN_8;
break;
case 6:
format = BarcodeFormat.ITF;
break;
case 7:
format = BarcodeFormat.PDF_417;
break;
case 8:
format = BarcodeFormat.UPC_A;
break;
case 9:
format = BarcodeFormat.QR_CODE;
break;
case 10:
format = BarcodeFormat.AZTEC;
break;
default:
format = BarcodeFormat.CODABAR;
break;
}
return format;
}
/**
* Method is used to convert parsed String to BarcodeFormat to create an image of the qr code
* @param stringFormat as String
* @return format as BarcodeFormat
*/
public BarcodeFormat StringToBarcodeFormat(String stringFormat){
BarcodeFormat format;
switch(stringFormat){
case "CODBAR":
format = BarcodeFormat.CODABAR;
break;
case "CODE_128":
format= BarcodeFormat.CODE_128;
break;
case "CODE_39":
format = BarcodeFormat.CODE_39;
break;
case "EAN_13":
format = BarcodeFormat.EAN_13;
break;
case "EAN_8":
format = BarcodeFormat.EAN_8;
break;
case "ITF":
format = BarcodeFormat.ITF;
break;
case "PDF_417":
format = BarcodeFormat.PDF_417;
break;
case "UPC_A":
format = BarcodeFormat.UPC_A;
break;
case "QR_CODE":
format = BarcodeFormat.QR_CODE;
break;
case "AZTEC":
format = BarcodeFormat.AZTEC;
break;
default:
format = BarcodeFormat.CODABAR;
break;
}
return format;
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char) charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)},
BarcodeFormat.CODABAR);
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char) charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)},
BarcodeFormat.CODABAR);
}
/**
* Parse barcodes as BarcodeFormat constants.
*
* Supports all iOS codes except [code39mod43, itf14]
*
* Additionally supports [codabar, maxicode, rss14, rssexpanded, upca, upceanextension]
*/
private BarcodeFormat parseBarCodeString(String c) {
if ("aztec".equals(c)) {
return BarcodeFormat.AZTEC;
} else if ("ean13".equals(c)) {
return BarcodeFormat.EAN_13;
} else if ("ean8".equals(c)) {
return BarcodeFormat.EAN_8;
} else if ("qr".equals(c)) {
return BarcodeFormat.QR_CODE;
} else if ("pdf417".equals(c)) {
return BarcodeFormat.PDF_417;
} else if ("upce".equals(c)) {
return BarcodeFormat.UPC_E;
} else if ("datamatrix".equals(c)) {
return BarcodeFormat.DATA_MATRIX;
} else if ("code39".equals(c)) {
return BarcodeFormat.CODE_39;
} else if ("code93".equals(c)) {
return BarcodeFormat.CODE_93;
} else if ("interleaved2of5".equals(c)) {
return BarcodeFormat.ITF;
} else if ("codabar".equals(c)) {
return BarcodeFormat.CODABAR;
} else if ("code128".equals(c)) {
return BarcodeFormat.CODE_128;
} else if ("maxicode".equals(c)) {
return BarcodeFormat.MAXICODE;
} else if ("rss14".equals(c)) {
return BarcodeFormat.RSS_14;
} else if ("rssexpanded".equals(c)) {
return BarcodeFormat.RSS_EXPANDED;
} else if ("upca".equals(c)) {
return BarcodeFormat.UPC_A;
} else if ("upceanextension".equals(c)) {
return BarcodeFormat.UPC_EAN_EXTENSION;
} else {
android.util.Log.v("RCTCamera", "Unsupported code.. [" + c + "]");
return null;
}
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char) charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)},
BarcodeFormat.CODABAR);
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char)charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = (float) runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = (float) runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, (float) rowNumber),
new ResultPoint(right, (float) rowNumber)},
BarcodeFormat.CODABAR);
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char)charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = (float) runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = (float) runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, (float) rowNumber),
new ResultPoint(right, (float) rowNumber)},
BarcodeFormat.CODABAR);
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char)charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = (float) runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = (float) runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, (float) rowNumber),
new ResultPoint(right, (float) rowNumber)},
BarcodeFormat.CODABAR);
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char) charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)},
BarcodeFormat.CODABAR);
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char)charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException.getNotFoundInstance();
}
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = (float) runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = (float) runningCount;
return new Result(
decodeRowResult.toString(),
null,
new ResultPoint[]{
new ResultPoint(left, (float) rowNumber),
new ResultPoint(right, (float) rowNumber)},
BarcodeFormat.CODABAR);
}
public Result decodeRow(int i, BitArray bitarray, Map map)
{
int ai[] = a(bitarray);
ai[1] = 0;
int j = bitarray.getNextSet(ai[1]);
int k = bitarray.getSize();
StringBuilder stringbuilder = new StringBuilder();
int ai1[] = new int[7];
do
{
for (int l = 0; l < ai1.length; l++)
{
ai1[l] = 0;
}
recordPattern(bitarray, j, ai1);
char c1 = a(ai1);
if (c1 == '!')
{
throw NotFoundException.getNotFoundInstance();
}
stringbuilder.append(c1);
int i1 = ai1.length;
int j1 = 0;
int k1 = j;
for (; j1 < i1; j1++)
{
k1 += ai1[j1];
}
int l1 = bitarray.getNextSet(k1);
if (l1 >= k)
{
int i2 = 0;
int j2 = ai1.length;
for (int k2 = 0; k2 < j2; k2++)
{
i2 += ai1[k2];
}
int l2 = l1 - j - i2;
if (l1 != k && l2 / 2 < i2)
{
throw NotFoundException.getNotFoundInstance();
}
if (stringbuilder.length() < 2)
{
throw NotFoundException.getNotFoundInstance();
}
char c2 = stringbuilder.charAt(0);
if (!a(e, c2))
{
throw NotFoundException.getNotFoundInstance();
}
int i3 = 1;
do
{
label0:
{
if (i3 < stringbuilder.length())
{
if (stringbuilder.charAt(i3) != c2 || i3 + 1 == stringbuilder.length())
{
break label0;
}
stringbuilder.delete(i3 + 1, -1 + stringbuilder.length());
}
if (stringbuilder.length() <= 6)
{
throw NotFoundException.getNotFoundInstance();
} else
{
stringbuilder.deleteCharAt(-1 + stringbuilder.length());
stringbuilder.deleteCharAt(0);
float f = (float)(ai[1] + ai[0]) / 2.0F;
float f1 = (float)(j + l1) / 2.0F;
String s = stringbuilder.toString();
ResultPoint aresultpoint[] = new ResultPoint[2];
aresultpoint[0] = new ResultPoint(f, i);
aresultpoint[1] = new ResultPoint(f1, i);
return new Result(s, null, aresultpoint, BarcodeFormat.CODABAR);
}
}
i3++;
} while (true);
}
j = l1;
} while (true);
}
@Override
public InputStream createBarCode(
String serialno, BarcodeTypeConfig barcodeTypeConfig, boolean isPadding)
throws AxelorException {
if (serialno != null && barcodeTypeConfig != null) {
BarcodeFormat barcodeFormat = null;
switch (barcodeTypeConfig.getName()) {
case "AZTEC":
barcodeFormat = BarcodeFormat.AZTEC;
break;
case "CODABAR":
barcodeFormat = BarcodeFormat.CODABAR;
serialno = checkTypeForCodabar(serialno, barcodeFormat);
break;
case "CODE_39":
barcodeFormat = BarcodeFormat.CODE_39;
serialno = checkTypeForCode39(serialno, barcodeFormat);
break;
case "CODE_128":
barcodeFormat = BarcodeFormat.CODE_128;
break;
case "DATA_MATRIX":
barcodeFormat = BarcodeFormat.DATA_MATRIX;
break;
case "EAN_8":
barcodeFormat = BarcodeFormat.EAN_8;
serialno = checkTypeForEan8(serialno, barcodeFormat, isPadding);
break;
case "ITF":
barcodeFormat = BarcodeFormat.ITF;
serialno = checkTypeForItf(serialno, barcodeFormat, isPadding);
break;
case "PDF_417":
barcodeFormat = BarcodeFormat.PDF_417;
serialno = checkTypeForPdf417(serialno, barcodeFormat, isPadding);
break;
case "QR_CODE":
barcodeFormat = BarcodeFormat.QR_CODE;
break;
case "UPC_A":
barcodeFormat = BarcodeFormat.UPC_A;
serialno = checkTypeForUpca(serialno, barcodeFormat, isPadding);
break;
case "EAN_13":
barcodeFormat = BarcodeFormat.EAN_13;
serialno = checkTypeForEan13(serialno, barcodeFormat, isPadding);
break;
default:
throw new AxelorException(
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
I18n.get(IExceptionMessage.BARCODE_GENERATOR_9));
}
return generateBarcode(serialno, barcodeTypeConfig, barcodeFormat);
}
return null;
}
@Override
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) throws NotFoundException {
Arrays.fill(counters, 0);
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.setLength(0);
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException.getNotFoundInstance();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append((char) charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 && arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on
// reading while data is
// available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we
// are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException.getNotFoundInstance();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < decodeRowResult.length(); i++) {
decodeRowResult.setCharAt(i, ALPHABET[decodeRowResult.charAt(i)]);
}
// Ensure a valid start and end character
char startchar = decodeRowResult.charAt(0);
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException.getNotFoundInstance();
}
char endchar = decodeRowResult.charAt(decodeRowResult.length() - 1);
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException.getNotFoundInstance();
}
// remove stop/start characters character and check if a long enough
// string is contained
if (decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1
// character)
throw NotFoundException.getNotFoundInstance();
}
if (hints == null || !hints.containsKey(DecodeHintType.RETURN_CODABAR_START_END)) {
decodeRowResult.deleteCharAt(decodeRowResult.length() - 1);
decodeRowResult.deleteCharAt(0);
}
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = (float) runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = (float) runningCount;
return new Result(decodeRowResult.toString(), null, new ResultPoint[] {
new ResultPoint(left, (float) rowNumber), new ResultPoint(right, (float) rowNumber) },
BarcodeFormat.CODABAR);
}