Permalink
Browse files

Optimize code width calculation in Code39Writer (#1103)

Every code39 character has 9 bars containing 3 wide bars, and separated by a white bar.
(9-3)*1 + 3*2 + 1 = 13
  • Loading branch information...
makiuchi-d authored and srowen committed Nov 4, 2018
1 parent 58feb44 commit b31e090239cf20793ba222d1bf3e61d9f4fb7a44
Showing with 1 addition and 8 deletions.
  1. +1 −8 core/src/main/java/com/google/zxing/oned/Code39Writer.java
@@ -64,14 +64,7 @@ public BitMatrix encode(String contents,
}
int[] widths = new int[9];
int codeWidth = 24 + 1 + length;
for (int i = 0; i < length; i++) {
int indexInString = Code39Reader.ALPHABET_STRING.indexOf(contents.charAt(i));
toIntArray(Code39Reader.CHARACTER_ENCODINGS[indexInString], widths);
for (int width : widths) {
codeWidth += width;
}
}
int codeWidth = 24 + 1 + (13 * length);
boolean[] result = new boolean[codeWidth];
toIntArray(Code39Reader.ASTERISK_ENCODING, widths);
int pos = appendPattern(result, 0, widths, true);

0 comments on commit b31e090

Please sign in to comment.