diff --git a/core/src/main/java/com/google/zxing/datamatrix/encoder/X12Encoder.java b/core/src/main/java/com/google/zxing/datamatrix/encoder/X12Encoder.java index 1f88b3fa7..0184bec49 100644 --- a/core/src/main/java/com/google/zxing/datamatrix/encoder/X12Encoder.java +++ b/core/src/main/java/com/google/zxing/datamatrix/encoder/X12Encoder.java @@ -73,10 +73,11 @@ final class X12Encoder extends C40Encoder { int available = context.getSymbolInfo().getDataCapacity() - context.getCodewordCount(); int count = buffer.length(); context.pos -= count; - if (context.getRemainingCharacters() != 1 || available != 1) { + if (context.getRemainingCharacters() > 1 || available > 1 || + context.getRemainingCharacters() != available) { context.writeCodeword(HighLevelEncoder.X12_UNLATCH); } - if (count > 0) { + if (context.getNewEncoding() < 0) { context.signalEncoderChange(HighLevelEncoder.ASCII_ENCODATION); } } diff --git a/core/src/test/java/com/google/zxing/datamatrix/encoder/HighLevelEncodeTestCase.java b/core/src/test/java/com/google/zxing/datamatrix/encoder/HighLevelEncodeTestCase.java index e4710c13d..15235ff1b 100644 --- a/core/src/test/java/com/google/zxing/datamatrix/encoder/HighLevelEncodeTestCase.java +++ b/core/src/test/java/com/google/zxing/datamatrix/encoder/HighLevelEncodeTestCase.java @@ -325,6 +325,12 @@ public final class HighLevelEncodeTestCase extends Assert { assertEquals("238 9 10 104 141 254 50 129", visualized); } + @Test + public void testX12Unlatch2() { + String visualized = encodeHighLevel("*DTCP0"); + assertEquals("238 9 10 104 141", visualized); + } + @Test public void testBug3048549() { //There was an IllegalArgumentException for an illegal character here because