Skip to content

Commit

Permalink
Add support for Code B FNC characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejkjr committed Feb 17, 2014
1 parent 09eaf4e commit c064fe2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/main/java/com/google/zxing/oned/Code128Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,27 @@ public boolean[] encode(String contents) {
if (newCodeSet == codeSet) {
// Encode the current character
if (codeSet == CODE_CODE_B) {
patternIndex = contents.charAt(position) - ' ';
position += 1;
switch (contents.charAt(position)) {
case ESCAPE_FNC_1:
patternIndex = CODE_FNC_1;
position++;
break;
case ESCAPE_FNC_2:
patternIndex = CODE_FNC_2;
position++;
break;
case ESCAPE_FNC_3:
patternIndex = CODE_FNC_3;
position++;
break;
case ESCAPE_FNC_4:
patternIndex = CODE_FNC_4_B; // FIXME if this ever outputs Code A
position++;
break;
default:
patternIndex = contents.charAt(position) - ' ';
position++;
}
} else { // CODE_CODE_C
switch (contents.charAt(position)) {
case ESCAPE_FNC_1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.google.zxing.oned;

import org.junit.Test;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.Writer;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;

import static org.junit.Assert.*;

public class Code128WriterTestCase {
private static final String FNC3 = "10111100010";
private static final String START_CODE_B = "11010010000";
public static final String QUIET_SPACE = "00000";
public static final String STOP = "1100011101011";

@Test
public void testEncodeWithFunc3() throws WriterException {
String toEncode = "\u00f3" + "123";
// "1" "2" "3" check digit 51
String expected = QUIET_SPACE + START_CODE_B + FNC3 + "10011100110" + "11001110010" + "11001011100" + "11101000110" + STOP + QUIET_SPACE;

Writer writer = new Code128Writer();
BitMatrix result = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);

StringBuilder actual = new StringBuilder(result.getWidth());
for (int i = 0; i < result.getWidth(); i++) {
actual.append(result.get(i, 0) ? '1' : '0');
}
assertEquals(expected, actual.toString());
}
}

0 comments on commit c064fe2

Please sign in to comment.