mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Issue 797 user patch for code c support
git-svn-id: https://zxing.googlecode.com/svn/trunk@1739 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
cad4d1d42e
commit
c24fefe747
|
@ -45,23 +45,62 @@ public final class Code128Writer extends UPCEANWriter {
|
|||
throw new IllegalArgumentException(
|
||||
"Requested contents should be less than 80 digits long, but got " + length);
|
||||
}
|
||||
|
||||
int codeWidth = 11 + 11 + 13; //start plus check plus stop character
|
||||
//get total code width for this barcode
|
||||
|
||||
//Determine which code we should use (C or B)
|
||||
boolean useCodeC = true;
|
||||
for (int i = 0; i < length; i++) {
|
||||
int[] patterns = Code128Reader.CODE_PATTERNS[contents.charAt(i) - ' '];
|
||||
for (int j = 0; j < patterns.length; j++) {
|
||||
codeWidth += patterns[j];
|
||||
char c = contents.charAt(i);
|
||||
if (c < '0' || c > '9') {
|
||||
useCodeC = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
byte[] result = new byte[codeWidth];
|
||||
int pos = appendPattern(result, 0, Code128Reader.CODE_PATTERNS[104], 1);
|
||||
int check = 104;
|
||||
//append next character to bytematrix
|
||||
for(int i = 0; i < length; i++) {
|
||||
check += (contents.charAt(i) - ' ') * (i + 1);
|
||||
pos += appendPattern(result, pos, Code128Reader.CODE_PATTERNS[contents.charAt(i) - ' '],1);
|
||||
|
||||
int codeWidth = 11 + 11 + 13; //start plus check plus stop character
|
||||
byte[] result;
|
||||
int pos;
|
||||
int check;
|
||||
|
||||
if (useCodeC) {
|
||||
//Optionnaly add "0" to have pairs
|
||||
if (length % 2 != 0) {
|
||||
contents = '0' + contents;
|
||||
length++;
|
||||
}
|
||||
//get total code width for this barcode
|
||||
for (int i = 0; i < length; i += 2){
|
||||
int[] patterns = Code128Reader.CODE_PATTERNS[Integer.parseInt(contents.substring(i, i + 2))];
|
||||
for (int j = 0; j < patterns.length; j++) {
|
||||
codeWidth += patterns[j];
|
||||
}
|
||||
}
|
||||
result = new byte[codeWidth];
|
||||
pos = appendPattern(result, 0, Code128Reader.CODE_PATTERNS[105], 1);
|
||||
check = 105;
|
||||
//append next character to bytematrix
|
||||
for (int i = 0; i < length; i += 2) {
|
||||
int pair = Integer.parseInt(contents.substring(i, i + 2));
|
||||
check += pair * (i / 2 + 1);
|
||||
pos += appendPattern(result, pos, Code128Reader.CODE_PATTERNS[pair],1);
|
||||
}
|
||||
} else {
|
||||
//get total code width for this barcode
|
||||
for (int i = 0; i < length; i++) {
|
||||
int[] patterns = Code128Reader.CODE_PATTERNS[contents.charAt(i) - ' '];
|
||||
for (int j = 0; j < patterns.length; j++) {
|
||||
codeWidth += patterns[j];
|
||||
}
|
||||
}
|
||||
result = new byte[codeWidth];
|
||||
pos = appendPattern(result, 0, Code128Reader.CODE_PATTERNS[104], 1);
|
||||
check = 104;
|
||||
//append next character to bytematrix
|
||||
for (int i = 0; i < length; i++) {
|
||||
check += (contents.charAt(i) - ' ') * (i + 1);
|
||||
pos += appendPattern(result, pos, Code128Reader.CODE_PATTERNS[contents.charAt(i) - ' '],1);
|
||||
}
|
||||
}
|
||||
|
||||
//compute checksum and append it along with end character and quiet space
|
||||
check %= 103;
|
||||
pos += appendPattern(result,pos,Code128Reader.CODE_PATTERNS[check],1);
|
||||
|
@ -70,4 +109,4 @@ public final class Code128Writer extends UPCEANWriter {
|
|||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue