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(
|
throw new IllegalArgumentException(
|
||||||
"Requested contents should be less than 80 digits long, but got " + length);
|
"Requested contents should be less than 80 digits long, but got " + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int codeWidth = 11 + 11 + 13; //start plus check plus stop character
|
//Determine which code we should use (C or B)
|
||||||
//get total code width for this barcode
|
boolean useCodeC = true;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
int[] patterns = Code128Reader.CODE_PATTERNS[contents.charAt(i) - ' '];
|
char c = contents.charAt(i);
|
||||||
for (int j = 0; j < patterns.length; j++) {
|
if (c < '0' || c > '9') {
|
||||||
codeWidth += patterns[j];
|
useCodeC = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] result = new byte[codeWidth];
|
|
||||||
int pos = appendPattern(result, 0, Code128Reader.CODE_PATTERNS[104], 1);
|
int codeWidth = 11 + 11 + 13; //start plus check plus stop character
|
||||||
int check = 104;
|
byte[] result;
|
||||||
//append next character to bytematrix
|
int pos;
|
||||||
for(int i = 0; i < length; i++) {
|
int check;
|
||||||
check += (contents.charAt(i) - ' ') * (i + 1);
|
|
||||||
pos += appendPattern(result, pos, Code128Reader.CODE_PATTERNS[contents.charAt(i) - ' '],1);
|
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
|
//compute checksum and append it along with end character and quiet space
|
||||||
check %= 103;
|
check %= 103;
|
||||||
pos += appendPattern(result,pos,Code128Reader.CODE_PATTERNS[check],1);
|
pos += appendPattern(result,pos,Code128Reader.CODE_PATTERNS[check],1);
|
||||||
|
@ -70,4 +109,4 @@ public final class Code128Writer extends UPCEANWriter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue