Bugfix: EDIFACT unlatch character not needed for all symbols

Ref: ISO 16022 para 5.2.8.2
Bug reported by Daniel Yang
This commit is contained in:
Robin Stuart 2016-07-22 16:42:39 +01:00
parent 8f7cc8d8b1
commit c35378acc5

View File

@ -527,7 +527,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
int sp, tp, i, gs1;
int current_mode, next_mode;
int inputlen = *length_p;
int debug = 0;
int debug = 1;
#ifndef _MSC_VER
char binary[2 * inputlen];
#else
@ -970,7 +970,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
}
static int dm200encode_remainder(unsigned char target[], int target_length, const unsigned char source[], const int inputlen, const int last_mode, const int process_buffer[], const int process_p, const int symbols_left) {
int debug = 0;
int debug = 1;
switch (last_mode) {
case DM_C40:
@ -1047,7 +1047,7 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons
break;
case DM_EDIFACT:
if (symbols_left == process_p) // Unlatch not required!
if (symbols_left <= 2) // Unlatch not required!
{
if (process_p == 1) {
target[target_length] = source[inputlen - 1] + 1;
@ -1060,9 +1060,28 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons
target[target_length] = source[inputlen - 1] + 1;
target_length++;
}
} else {
// Append edifact unlatch value (31) and encode as triple.
if (process_p == 3) // Append edifact unlatch value (31) and encode as triple.
{
if (process_p == 1) {
target[target_length] = (unsigned char) ((process_buffer[0] << 2) + ((31 & 0x30) >> 4));
target_length++;
target[target_length] = (unsigned char) ((31 & 0x0f) << 4) ;
target_length++;
target[target_length] = (unsigned char) 0;
target_length++;
}
if (process_p == 2) {
target[target_length] = (unsigned char) ((process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4));
target_length++;
target[target_length] = (unsigned char) (((process_buffer[1] & 0x0f) << 4) + ((31 & 0x3c) >> 2));
target_length++;
target[target_length] = (unsigned char) (((31 & 0x03) << 6));
target_length++;
}
if (process_p == 3) {
target[target_length] = (unsigned char) ((process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4));
target_length++;
target[target_length] = (unsigned char) (((process_buffer[1] & 0x0f) << 4) + ((process_buffer[2] & 0x3c) >> 2));
@ -1070,38 +1089,7 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons
target[target_length] = (unsigned char) (((process_buffer[2] & 0x03) << 6) + 31);
target_length++;
}
}
if (symbols_left > process_p) // Unlatch and encode remaining data in ascii.
{
// Edifact unlatch.
if (symbols_left < 3) {
target[target_length] = 31;
target_length++;
} else
target[target_length] = (31 << 2);
target_length++;
if (process_p == 1) {
target[target_length] = source[inputlen - 1] + 1;
target_length++;
}
if (process_p == 2) {
target[target_length] = source[inputlen - 2] + 1;
target_length++;
target[target_length] = source[inputlen - 1] + 1;
target_length++;
}
if (process_p == 3) {
target[target_length] = source[inputlen - 3] + 1;
target_length++;
target[target_length] = source[inputlen - 2] + 1;
target_length++;
target[target_length] = source[inputlen - 1] + 1;
target_length++;
}
}
break;
}
@ -1222,7 +1210,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], const in
}
ecc200(binary, bytes, datablock, rsblock, skew);
// Print Codewords
#ifdef DEBUG
//#ifdef DEBUG
{
int CWCount;
if (skew)
@ -1234,7 +1222,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], const in
printf(" %3i", binary[posCur]);
puts("\n");
}
#endif
//#endif
{ // placement
int x, y, NC, NR, *places;
NC = W - 2 * (W / FW);