mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Issue #300 : simplify X12 encodation at end of input stream to fix unlatch issue. HT micjahn
This commit is contained in:
parent
4c4b782ad9
commit
4b02337709
|
@ -72,16 +72,11 @@ final class X12Encoder extends C40Encoder {
|
|||
context.updateSymbolInfo();
|
||||
int available = context.getSymbolInfo().getDataCapacity() - context.getCodewordCount();
|
||||
int count = buffer.length();
|
||||
if (count == 2) {
|
||||
context.pos -= count;
|
||||
if (context.getRemainingCharacters() != 1 || available != 1) {
|
||||
context.writeCodeword(HighLevelEncoder.X12_UNLATCH);
|
||||
context.pos -= 2;
|
||||
context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
|
||||
} else if (count == 1) {
|
||||
context.pos--;
|
||||
if (available > 1) {
|
||||
context.writeCodeword(HighLevelEncoder.X12_UNLATCH);
|
||||
}
|
||||
//NOP - No unlatch necessary
|
||||
}
|
||||
if (count > 0) {
|
||||
context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,11 @@
|
|||
|
||||
package com.google.zxing.datamatrix.encoder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import junit.framework.ComparisonFailure;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -316,6 +319,12 @@ public final class HighLevelEncodeTestCase extends Assert {
|
|||
assertEquals("240 13 33 88 181 64 78 124 59 105 105 105", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testX12Unlatch() {
|
||||
String visualized = encodeHighLevel("*DTCP01");
|
||||
assertEquals("238 9 10 104 141 254 50 129", visualized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug3048549() {
|
||||
//There was an IllegalArgumentException for an illegal character here because
|
||||
|
@ -334,14 +343,13 @@ public final class HighLevelEncodeTestCase extends Assert {
|
|||
assertEquals("236 185 185 29 196 196 129 56", visualized);
|
||||
}
|
||||
|
||||
// Not passing?
|
||||
/*
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDataURL() {
|
||||
|
||||
byte[] data = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
|
||||
0x7E, 0x7F, (byte) 0x80, (byte) 0x81, (byte) 0x82};
|
||||
String expected = encodeHighLevel(new String(data, StandardCharsets.ISO-8859-1)));
|
||||
String expected = encodeHighLevel(new String(data, StandardCharsets.ISO_8859_1));
|
||||
String visualized = encodeHighLevel("url(data:text/plain;charset=iso-8859-1,"
|
||||
+ "%00%01%02%03%04%05%06%07%08%09%0A%7E%7F%80%81%82)");
|
||||
assertEquals(expected, visualized);
|
||||
|
@ -350,7 +358,6 @@ public final class HighLevelEncodeTestCase extends Assert {
|
|||
visualized = encodeHighLevel("url(data:;base64,flRlc3R+)");
|
||||
assertEquals("127 85 102 116 117 127 129 56", visualized);
|
||||
}
|
||||
*/
|
||||
|
||||
private static String encodeHighLevel(String msg) {
|
||||
CharSequence encoded = HighLevelEncoder.encodeHighLevel(msg);
|
||||
|
|
Loading…
Reference in a new issue