C25STANDARD/C25INTER/C25IATA/C25LOGIC/C25IND: add check digit option (#216)

This commit is contained in:
gitlost 2021-05-17 20:04:00 +01:00
parent 29d761c795
commit f3a94f0c0c
10 changed files with 392 additions and 227 deletions

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -34,162 +34,121 @@
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h>
#define inline _inline #define inline _inline
#endif #endif
static const char *C25MatrixTable[10] = { static const char *C25MatrixTable[10] = {
"113311", "311131", "131131", "331111", "113131", "313111", "113311", "311131", "131131", "331111", "113131",
"133111", "111331", "311311", "131311" "313111", "133111", "111331", "311311", "131311"
}; };
static const char *C25MatrixStartStop[2] = { "411111", "41111" };
static const char *C25IndustTable[10] = { static const char *C25IndustTable[10] = {
"1111313111", "3111111131", "1131111131", "3131111111", "1111311131", "1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111" "3111311111", "1131311111", "1111113131", "3111113111", "1131113111"
}; };
static const char *C25IndustStartStop[2] = { "313111", "31113" };
static const char *C25IataLogicStartStop[2] = { "1111", "311" };
static const char *C25InterTable[10] = { static const char *C25InterTable[10] = {
"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133", "11331", "31113", "13113", "33111", "11313",
"31131", "13131" "31311", "13311", "11133", "31131", "13131"
}; };
static inline char check_digit(unsigned int count) { static inline char check_digit(const unsigned int count) {
return itoc((10 - (count % 10)) % 10); return itoc((10 - (count % 10)) % 10);
} }
/* Calculate the check digit - the same method used for EAN-13 (GS1 General Specifications 7.9.1) */
static unsigned int gs1_checksum(const unsigned char source[], const int length) {
int i;
unsigned int count = 0;
int factor = length & 1 ? 3 : 1;
for (i = 0; i < length; i++) {
count += factor * ctoi(source[i]);
factor = factor == 1 ? 3 : 1;
}
return count;
}
/* Common to Standard (Matrix), Industrial, IATA, and Data Logic */
static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max,
const char *table[10], const char *start_stop[2], const int error_base) {
int i, error_number;
char dest[512]; /* Largest destination 6 + (80 + 1) * 6 + 5 + 1 = 498 */
unsigned char temp[80 + 1 + 1]; /* Largest maximum 80 */
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
if (length > max) {
sprintf(symbol->errtxt, "%d: Input too long (maximum %d)", error_base, max);
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
sprintf(symbol->errtxt, "%d: Invalid characters in data", error_base + 1);
return error_number;
}
ustrcpy(temp, source);
if (have_checkdigit) {
/* Add standard GS1 check digit */
temp[length] = check_digit(gs1_checksum(source, length));
temp[++length] = '\0';
}
/* start character */
strcpy(dest, start_stop[0]);
for (i = 0; i < length; i++) {
lookup(NEON, table, temp[i], dest);
}
/* Stop character */
strcat(dest, start_stop[1]);
expand(symbol, dest);
ustrcpy(symbol->text, temp);
if (symbol->option_2 == 2) {
/* Remove check digit from HRT */
symbol->text[length - 1] = '\0';
}
return error_number;
}
/* Code 2 of 5 Standard (Code 2 of 5 Matrix) */ /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
INTERNAL int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 80, C25MatrixTable, C25MatrixStartStop, 301);
int i, error_number;
char dest[512]; /* 6 + 80 * 6 + 5 + 1 = 492 */
if (length > 80) {
strcpy(symbol->errtxt, "301: Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "302: Invalid characters in data");
return error_number;
}
/* start character */
strcpy(dest, "411111");
for (i = 0; i < length; i++) {
lookup(NEON, C25MatrixTable, source[i], dest);
}
/* Stop character */
strcat(dest, "41111");
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
/* Code 2 of 5 Industrial */ /* Code 2 of 5 Industrial */
INTERNAL int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 45, C25IndustTable, C25IndustStartStop, 303);
int i, error_number;
char dest[512]; /* 6 + 45 * 10 + 5 + 1 = 462 */
if (length > 45) {
strcpy(symbol->errtxt, "303: Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "304: Invalid character in data");
return error_number;
}
/* start character */
strcpy(dest, "313111");
for (i = 0; i < length; i++) {
lookup(NEON, C25IndustTable, source[i], dest);
}
/* Stop character */
strcat(dest, "31113");
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
/* Code 2 of 5 IATA */ /* Code 2 of 5 IATA */
INTERNAL int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; return c25_common(symbol, source, length, 45, C25IndustTable, C25IataLogicStartStop, 305);
char dest[512]; /* 4 + 45 * 10 + 3 + 1 = 458 */
if (length > 45) {
strcpy(symbol->errtxt, "305: Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "306: Invalid characters in data");
return error_number;
}
/* start */
strcpy(dest, "1111");
for (i = 0; i < length; i++) {
lookup(NEON, C25IndustTable, source[i], dest);
}
/* stop */
strcat(dest, "311");
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
/* Code 2 of 5 Data Logic */ /* Code 2 of 5 Data Logic */
INTERNAL int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 80, C25MatrixTable, C25IataLogicStartStop, 307);
int i, error_number;
char dest[512]; /* 4 + 80 * 6 + 3 + 1 = 488 */
if (length > 80) {
strcpy(symbol->errtxt, "307: Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "308: Invalid characters in data");
return error_number;
}
/* start character */
strcpy(dest, "1111");
for (i = 0; i < length; i++) {
lookup(NEON, C25MatrixTable, source[i], dest);
}
/* Stop character */
strcat(dest, "311");
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
/* Code 2 of 5 Interleaved */ /* Code 2 of 5 Interleaved */
INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, error_number; int i, j, error_number;
char bars[7], spaces[7], mixed[14], dest[512]; /* 4 + 90 * 5 + 3 + 1 = 458 */ char bars[7], spaces[7], mixed[14], dest[512]; /* 4 + (90 + 2) * 5 + 3 + 1 = 468 */
#ifndef _MSC_VER unsigned char temp[90 + 2 + 1];
unsigned char temp[length + 2]; int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
#else
unsigned char* temp = (unsigned char *) _alloca((length + 2) * sizeof (unsigned char));
#endif
if (length > 90) { if (length > 90) {
strcpy(symbol->errtxt, "309: Input too long"); strcpy(symbol->errtxt, "309: Input too long");
@ -203,13 +162,20 @@ INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char s
temp[0] = '\0'; temp[0] = '\0';
/* Input must be an even number of characters for Interlaced 2 of 5 to work: /* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered then add a leading zero */ if an odd number of characters has been entered and no check digit or an even number and have check digit
if (length & 1) { then add a leading zero */
if (((length & 1) && !have_checkdigit) || (!(length & 1) && have_checkdigit)) {
ustrcpy(temp, "0"); ustrcpy(temp, "0");
length++; length++;
} }
ustrncat(temp, source, length); ustrncat(temp, source, length);
if (have_checkdigit) {
/* Add standard GS1 check digit */
temp[length] = check_digit(gs1_checksum(temp, length));
temp[++length] = '\0';
}
/* start character */ /* start character */
strcpy(dest, "1111"); strcpy(dest, "1111");
@ -236,17 +202,20 @@ INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char s
strcat(dest, "311"); strcat(dest, "311");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, temp); ustrcpy(symbol->text, temp);
if (symbol->option_2 == 2) {
/* Remove check digit from HRT */
symbol->text[length - 1] = '\0';
}
return error_number; return error_number;
} }
/* Interleaved 2-of-5 (ITF) */ /* Interleaved 2-of-5 (ITF) */
INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned char localstr[16] = {0};
char localstr[16];
count = 0;
if (length > 13) { if (length > 13) {
strcpy(symbol->errtxt, "311: Input too long"); strcpy(symbol->errtxt, "311: Input too long");
@ -267,14 +236,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
ustrcpy(localstr + zeroes, source); ustrcpy(localstr + zeroes, source);
/* Calculate the check digit - the same method used for EAN-13 */ /* Calculate the check digit - the same method used for EAN-13 */
for (i = 12; i >= 0; i--) { localstr[13] = check_digit(gs1_checksum(localstr, 13));
count += ctoi(localstr[i]);
if (!(i & 1)) {
count += 2 * ctoi(localstr[i]);
}
}
localstr[13] = check_digit(count);
localstr[14] = '\0'; localstr[14] = '\0';
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 14); error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 14);
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
@ -295,7 +257,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
unsigned int count; unsigned int count;
char localstr[16]; unsigned char localstr[16] = {0};
int zeroes; int zeroes;
count = 0; count = 0;
@ -323,7 +285,7 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng
} }
localstr[13] = check_digit(count); localstr[13] = check_digit(count);
localstr[14] = '\0'; localstr[14] = '\0';
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 14); error_number = interleaved_two_of_five(symbol, localstr, 14);
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
return error_number; return error_number;
} }
@ -332,7 +294,7 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng
INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) { INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned int count;
char localstr[16]; unsigned char localstr[16] = {0};
count = 0; count = 0;
if (length > 11) { if (length > 11) {
@ -359,7 +321,7 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len
} }
localstr[11] = check_digit(count); localstr[11] = check_digit(count);
localstr[12] = '\0'; localstr[12] = '\0';
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, 12); error_number = interleaved_two_of_five(symbol, localstr, 12);
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
return error_number; return error_number;
} }

View File

@ -38,6 +38,7 @@ static void test_large(int index, int debug) {
int ret; int ret;
struct item { struct item {
int symbology; int symbology;
int option_2;
char *pattern; char *pattern;
int length; int length;
int ret; int ret;
@ -46,22 +47,32 @@ static void test_large(int index, int debug) {
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, "1", 80, 0, 1, 817 }, /* 0*/ { BARCODE_C25STANDARD, -1, "1", 80, 0, 1, 817 },
/* 1*/ { BARCODE_C25STANDARD, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 1*/ { BARCODE_C25STANDARD, -1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_C25INTER, "1", 90, 0, 1, 819 }, /* 2*/ { BARCODE_C25STANDARD, 1, "1", 80, 0, 1, 827 },
/* 3*/ { BARCODE_C25INTER, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { BARCODE_C25STANDARD, 1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_C25IATA, "1", 45, 0, 1, 639 }, /* 4*/ { BARCODE_C25INTER, -1, "1", 90, 0, 1, 819 },
/* 5*/ { BARCODE_C25IATA, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 5*/ { BARCODE_C25INTER, -1, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { BARCODE_C25LOGIC, "1", 80, 0, 1, 809 }, /* 6*/ { BARCODE_C25INTER, 1, "1", 90, 0, 1, 837 },
/* 7*/ { BARCODE_C25LOGIC, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 7*/ { BARCODE_C25INTER, 1, "1", 91, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 8*/ { BARCODE_C25IND, "1", 45, 0, 1, 649 }, /* 8*/ { BARCODE_C25IATA, -1, "1", 45, 0, 1, 639 },
/* 9*/ { BARCODE_C25IND, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 9*/ { BARCODE_C25IATA, -1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 10*/ { BARCODE_DPLEIT, "1", 13, 0, 1, 135 }, /* 10*/ { BARCODE_C25IATA, 1, "1", 45, 0, 1, 653 },
/* 11*/ { BARCODE_DPLEIT, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 11*/ { BARCODE_C25IATA, 1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 12*/ { BARCODE_DPIDENT, "1", 11, 0, 1, 117 }, /* 12*/ { BARCODE_C25LOGIC, -1, "1", 80, 0, 1, 809 },
/* 13*/ { BARCODE_DPIDENT, "1", 12, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 13*/ { BARCODE_C25LOGIC, -1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 14*/ { BARCODE_ITF14, "1", 13, 0, 1, 135 }, /* 14*/ { BARCODE_C25LOGIC, 1, "1", 80, 0, 1, 819 },
/* 15*/ { BARCODE_ITF14, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 }, /* 15*/ { BARCODE_C25LOGIC, 1, "1", 81, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 16*/ { BARCODE_C25IND, -1, "1", 45, 0, 1, 649 },
/* 17*/ { BARCODE_C25IND, -1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 18*/ { BARCODE_C25IND, 1, "1", 45, 0, 1, 663 },
/* 19*/ { BARCODE_C25IND, 1, "1", 46, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 20*/ { BARCODE_DPLEIT, -1, "1", 13, 0, 1, 135 },
/* 21*/ { BARCODE_DPLEIT, -1, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 22*/ { BARCODE_DPIDENT, -1, "1", 11, 0, 1, 117 },
/* 23*/ { BARCODE_DPIDENT, -1, "1", 12, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 24*/ { BARCODE_ITF14, -1, "1", 13, 0, 1, 135 },
/* 25*/ { BARCODE_ITF14, -1, "1", 14, ZINT_ERROR_TOO_LONG, -1, -1 },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -77,7 +88,7 @@ static void test_large(int index, int debug) {
testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length); testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf)); assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data_buf, data[i].length, debug); int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data_buf, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
@ -100,22 +111,36 @@ static void test_hrt(int index, int debug) {
int ret; int ret;
struct item { struct item {
int symbology; int symbology;
int option_2;
char *data; char *data;
char *expected; char *expected;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, "123456789", "123456789" }, /* 0*/ { BARCODE_C25STANDARD, -1, "123456789", "123456789" },
/* 1*/ { BARCODE_C25INTER, "123456789", "0123456789" }, // Adds leading zero if odd /* 1*/ { BARCODE_C25STANDARD, 1, "123456789", "1234567895" },
/* 2*/ { BARCODE_C25IATA, "123456789", "123456789" }, /* 2*/ { BARCODE_C25STANDARD, 2, "123456789", "123456789" }, // Suppresses printing of check digit
/* 3*/ { BARCODE_C25LOGIC, "123456789", "123456789" }, /* 3*/ { BARCODE_C25INTER, -1, "123456789", "0123456789" }, // Adds leading zero if odd
/* 4*/ { BARCODE_C25IND, "123456789", "123456789" }, /* 4*/ { BARCODE_C25INTER, 1, "123456789", "1234567895" }, // Unless check digit added when it becomes even
/* 5*/ { BARCODE_DPLEIT, "123456789", "00001234567890" }, // Leading zeroes added to make 13 + appended checksum /* 5*/ { BARCODE_C25INTER, 2, "123456789", "123456789" },
/* 6*/ { BARCODE_DPLEIT, "1234567890123", "12345678901236" }, /* 6*/ { BARCODE_C25INTER, -1, "1234567890", "1234567890" }, // No leading zero if even
/* 7*/ { BARCODE_DPIDENT, "123456789", "001234567890" }, // Leading zeroes added to make 11 + appended checksum /* 7*/ { BARCODE_C25INTER, 1, "1234567890", "012345678905" }, // Unless check digit added when it becomes odd
/* 8*/ { BARCODE_DPIDENT, "12345678901", "123456789016" }, /* 8*/ { BARCODE_C25INTER, 2, "1234567890", "01234567890" },
/* 9*/ { BARCODE_ITF14, "123456789", "00001234567895" }, // Leading zeroes added to make 13 + appended checksum /* 9*/ { BARCODE_C25IATA, -1, "123456789", "123456789" },
/* 10*/ { BARCODE_ITF14, "1234567890123", "12345678901231" }, /* 10*/ { BARCODE_C25IATA, 1, "123456789", "1234567895" },
/* 11*/ { BARCODE_C25IATA, 2, "123456789", "123456789" },
/* 12*/ { BARCODE_C25LOGIC, -1, "123456789", "123456789" },
/* 13*/ { BARCODE_C25LOGIC, 1, "123456789", "1234567895" },
/* 14*/ { BARCODE_C25LOGIC, 2, "123456789", "123456789" },
/* 15*/ { BARCODE_C25IND, -1, "123456789", "123456789" },
/* 16*/ { BARCODE_C25IND, 1, "123456789", "1234567895" },
/* 17*/ { BARCODE_C25IND, 2, "123456789", "123456789" },
/* 18*/ { BARCODE_DPLEIT, -1, "123456789", "00001234567890" }, // Leading zeroes added to make 13 + appended checksum
/* 19*/ { BARCODE_DPLEIT, -1, "1234567890123", "12345678901236" },
/* 20*/ { BARCODE_DPIDENT, -1, "123456789", "001234567890" }, // Leading zeroes added to make 11 + appended checksum
/* 21*/ { BARCODE_DPIDENT, -1, "12345678901", "123456789016" },
/* 22*/ { BARCODE_ITF14, -1, "123456789", "00001234567895" }, // Leading zeroes added to make 13 + appended checksum
/* 23*/ { BARCODE_ITF14, -1, "1234567890123", "12345678901231" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -126,7 +151,7 @@ static void test_hrt(int index, int debug) {
struct zint_symbol *symbol = ZBarcode_Create(); struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt); assert_zero(ret, "i:%d ZBarcode_Encode ret %d != 0 %s\n", i, ret, symbol->errtxt);
@ -196,6 +221,7 @@ static void test_encode(int index, int generate, int debug) {
int ret; int ret;
struct item { struct item {
int symbology; int symbology;
int option_2;
char *data; char *data;
int ret; int ret;
@ -206,46 +232,67 @@ static void test_encode(int index, int generate, int debug) {
}; };
// BARCODE_ITF14 examples verified manually against GS1 General Specifications 21.0.1 // BARCODE_ITF14 examples verified manually against GS1 General Specifications 21.0.1
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_C25STANDARD, "87654321", 0, 1, 97, "Standard Code 2 of 5; note zint uses 4X start/end wides while BWIPP uses 3X", /* 0*/ { BARCODE_C25STANDARD, -1, "87654321", 0, 1, 97, "Standard Code 2 of 5; note zint uses 4X start/end wides while BWIPP uses 3X",
"1111010101110100010101000111010001110101110111010101110111011100010101000101110111010111011110101" "1111010101110100010101000111010001110101110111010101110111011100010101000101110111010111011110101"
}, },
/* 1*/ { BARCODE_C25INTER, "87654321", 0, 1, 81, "Interleaved Code 2 of 5; verified manually against tec-it", /* 1*/ { BARCODE_C25STANDARD, 1, "87654321", 0, 1, 107, "With check digit",
"11110101011101000101010001110100011101011101110101011101110111000101010001011101110101110100010111011110101"
},
/* 2*/ { BARCODE_C25INTER, -1, "87654321", 0, 1, 81, "Interleaved Code 2 of 5, even; verified manually against tec-it",
"101011101010111000100010001110111000101010001000111010111010001110101011100011101" "101011101010111000100010001110111000101010001000111010111010001110101011100011101"
}, },
/* 2*/ { BARCODE_C25INTER, "602003", 0, 1, 63, "DX cartridge barcode https://en.wikipedia.org/wiki/Interleaved_2_of_5 example", /* 3*/ { BARCODE_C25INTER, 1, "87654321", 0, 1, 99, "With check digit",
"101010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101"
},
/* 4*/ { BARCODE_C25INTER, -1, "7654321", 0, 1, 81, "Interleaved Code 2 of 5, odd",
"101010101110111000100010001110111000101010001000111010111010001110101011100011101"
},
/* 5*/ { BARCODE_C25INTER, 1, "7654321", 0, 1, 81, "With check digit",
"101010100010001110111011101011100010100011101110001010100011101010001000111011101"
},
/* 6*/ { BARCODE_C25INTER, -1, "602003", 0, 1, 63, "DX cartridge barcode https://en.wikipedia.org/wiki/Interleaved_2_of_5 example",
"101010111011100010001010111010001000111010001000111011101011101" "101010111011100010001010111010001000111010001000111011101011101"
}, },
/* 3*/ { BARCODE_C25IATA, "87654321", 0, 1, 121, "IATA Code 2 of 5; verified manually against tec-it", /* 7*/ { BARCODE_C25IATA, -1, "87654321", 0, 1, 121, "IATA Code 2 of 5; verified manually against tec-it",
"1010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111011101" "1010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111011101"
}, },
/* 4*/ { BARCODE_C25LOGIC, "87654321", 0, 1, 89, "Code 2 of 5 Data Logic; verified manually against tec-it", /* 8*/ { BARCODE_C25IATA, 1, "87654321", 0, 1, 135, "With check digit",
"101011101010111010101010111011101011101110101011101011101010101011101011101110111010101010111010101110111010101011101011101010111011101"
},
/* 9*/ { BARCODE_C25LOGIC, -1, "87654321", 0, 1, 89, "Code 2 of 5 Data Logic; verified manually against tec-it",
"10101110100010101000111010001110101110111010101110111011100010101000101110111010111011101" "10101110100010101000111010001110101110111010101110111011100010101000101110111010111011101"
}, },
/* 5*/ { BARCODE_C25IND, "87654321", 0, 1, 131, "Industrial Code 2 of 5; verified manually against tec-it", /* 10*/ { BARCODE_C25LOGIC, 1, "87654321", 0, 1, 99, "With check digit",
"101011101000101010001110100011101011101110101011101110111000101010001011101110101110100010111011101"
},
/* 11*/ { BARCODE_C25IND, -1, "87654321", 0, 1, 131, "Industrial Code 2 of 5; verified manually against tec-it",
"11101110101110101011101010101011101110101110111010101110101110101010101110101110111011101010101011101010111011101010101110111010111" "11101110101110101011101010101011101110101110111010101110101110101010101110101110111011101010101011101010111011101010101110111010111"
}, },
/* 6*/ { BARCODE_DPLEIT, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it", /* 12*/ { BARCODE_C25IND, 1, "87654321", 0, 1, 145, "With check digit",
"1110111010111010101110101010101110111010111011101010111010111010101010111010111011101110101010101110101011101110101010111010111010101110111010111"
},
/* 13*/ { BARCODE_DPLEIT, -1, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it",
"101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101" "101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101"
}, },
/* 7*/ { BARCODE_DPLEIT, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example", /* 14*/ { BARCODE_DPLEIT, -1, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example",
"101011101011100010001011101000101110100011101110100010001010101110111000100010100011101110100011101010001110001010001011100011101011101" "101011101011100010001011101000101110100011101110100010001010101110111000100010100011101110100011101010001110001010001011100011101011101"
}, },
/* 8*/ { BARCODE_DPIDENT, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it", /* 15*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it",
"101010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101" "101010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101"
}, },
/* 9*/ { BARCODE_DPIDENT, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example", /* 16*/ { BARCODE_DPIDENT, -1, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example",
"101011101110001010001010111011100010001011100010001010111011100010001010111010001011101011100010101110001000111011101" "101011101110001010001010111011100010001011100010001010111011100010001010111010001011101011100010101110001000111011101"
}, },
/* 10*/ { BARCODE_ITF14, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it", /* 17*/ { BARCODE_ITF14, -1, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it",
"101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101" "101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101"
}, },
/* 11*/ { BARCODE_ITF14, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2", /* 18*/ { BARCODE_ITF14, -1, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2",
"101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001010001000111011101011101" "101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001010001000111011101011101"
}, },
/* 12*/ { BARCODE_ITF14, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1", /* 19*/ { BARCODE_ITF14, -1, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1",
"101011100010100010111010101110001000111010001011101110100010001011101011100010001110101000111011101010111000100010001110001110101011101" "101011100010100010111010101110001000111010001011101110100010001011101011100010001110101000111011101010111000100010001110001110101011101"
}, },
/* 13*/ { BARCODE_ITF14, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1", /* 20*/ { BARCODE_ITF14, -1, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1",
"101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001011101010001000111011101" "101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001011101010001000111011101"
}, },
}; };
@ -262,14 +309,14 @@ static void test_encode(int index, int generate, int debug) {
struct zint_symbol *symbol = ZBarcode_Create(); struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); assert_nonnull(symbol, "Symbol not created\n");
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, -1 /*output_options*/, data[i].data, -1, debug); int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) { if (generate) {
printf(" /*%3d*/ { %s, \"%s\", %s, %d, %d, \"%s\",\n", printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), i, testUtilBarcodeName(data[i].symbology), data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesPrint(symbol, " ", "\n"); testUtilModulesPrint(symbol, " ", "\n");
printf(" },\n"); printf(" },\n");
@ -282,8 +329,8 @@ static void test_encode(int index, int generate, int debug) {
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data); assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) {
ret = testUtilBwipp(i, symbol, -1, -1, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf)); ret = testUtilBwipp(i, symbol, -1, data[i].option_2, -1, data[i].data, length, NULL, bwipp_buf, sizeof(bwipp_buf));
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);

View File

@ -1758,12 +1758,12 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
static const struct item data[] = { static const struct item data[] = {
{ "", -1, 0, 0, 0, 0, 0, 0, }, { "", -1, 0, 0, 0, 0, 0, 0, },
{ "code11", BARCODE_CODE11, 1, 0, 1, 0, 0, 0, }, { "code11", BARCODE_CODE11, 1, 0, 1, 0, 0, 0, },
{ "matrix2of5", BARCODE_C25STANDARD, 2, 0, 0, 0, 0, 0, }, { "matrix2of5", BARCODE_C25STANDARD, 2, 0, 1, 0, 0, 0, },
{ "interleaved2of5", BARCODE_C25INTER, 3, 0, 0, 0, 0, 0, }, { "interleaved2of5", BARCODE_C25INTER, 3, 0, 1, 0, 0, 0, },
{ "iata2of5", BARCODE_C25IATA, 4, 0, 0, 0, 0, 0, }, { "iata2of5", BARCODE_C25IATA, 4, 0, 1, 0, 0, 0, },
{ "", -1, 5, 0, 0, 0, 0, 0, }, { "", -1, 5, 0, 0, 0, 0, 0, },
{ "datalogic2of5", BARCODE_C25LOGIC, 6, 0, 0, 0, 0, 0, }, { "datalogic2of5", BARCODE_C25LOGIC, 6, 0, 1, 0, 0, 0, },
{ "industrial2of5", BARCODE_C25IND, 7, 0, 0, 0, 0, 0, }, { "industrial2of5", BARCODE_C25IND, 7, 0, 1, 0, 0, 0, },
{ "code39", BARCODE_CODE39, 8, 0, 1, 0, 0, 0, }, { "code39", BARCODE_CODE39, 8, 0, 1, 0, 0, 0, },
{ "code39ext", BARCODE_EXCODE39, 9, 0, 1, 0, 0, 0, }, { "code39ext", BARCODE_EXCODE39, 9, 0, 1, 0, 0, 0, },
{ "", -1, 10, 0, 0, 0, 0, 0, }, { "", -1, 10, 0, 0, 0, 0, 0, },
@ -2239,7 +2239,13 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
bwipp_opts = bwipp_opts_buf; bwipp_opts = bwipp_opts_buf;
} }
if (symbology == BARCODE_CODE93) { if (symbology == BARCODE_C25STANDARD || symbology == BARCODE_C25INTER || symbology == BARCODE_C25IATA
|| symbology == BARCODE_C25LOGIC || symbology == BARCODE_C25IND) {
if (option_2 == 1 || option_2 == 2) { // Add check digit without or with HRT suppression
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : "");
bwipp_opts = bwipp_opts_buf;
}
} else if (symbology == BARCODE_CODE93) {
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : "");
if (parse) { if (parse) {
bwipp_barcode = "code93ext"; bwipp_barcode = "code93ext";

View File

@ -1434,29 +1434,39 @@ before using these standards.
---------------------------- ----------------------------
Also known as Code 2 of 5 Matrix this is a self-checking code used in industrial Also known as Code 2 of 5 Matrix this is a self-checking code used in industrial
applications and photo development. Standard Code 2 of 5 will encode any length applications and photo development. Standard Code 2 of 5 will encode any length
numeric input (digits 0-9). numeric input (digits 0-9). No check digit is added by default. To add a check
digit, set option_2 = 1 or --vers=1. To add a check digit but not show it in
the human readable text, set option_2 = 2 or --vers=2.
6.1.2.2 IATA Code 2 of 5 6.1.2.2 IATA Code 2 of 5
------------------------ ------------------------
Used for baggage handling in the air-transport industry by the International Used for baggage handling in the air-transport industry by the International
Air Transport Agency, this self-checking code will encode any length numeric Air Transport Agency, this self-checking code will encode any length numeric
input (digits 0-9) and does not include a check digit. input (digits 0-9). No check digit is added by default. To add a check digit,
set option_2 = 1 or --vers=1. To add a check digit but not show it in the human
readable text, set option_2 = 2 or --vers=2.
6.1.2.3 Industrial Code 2 of 5 6.1.2.3 Industrial Code 2 of 5
------------------------------ ------------------------------
Industrial Code 2 of 5 can encode any length numeric input (digits 0-9) and Industrial Code 2 of 5 can encode any length numeric input (digits 0-9). No
does not include a check digit. check digit is added by default. To add a check digit, set option_2 = 1 or
--vers=1. To add a check digit but not show it in the human readable text, set
option_2 = 2 or --vers=2.
6.1.2.4 Interleaved Code 2 of 5 6.1.2.4 Interleaved Code 2 of 5
------------------------------- -------------------------------
This self-checking symbology encodes pairs of numbers, and so can only encode This self-checking symbology encodes pairs of numbers, and so can only encode
an even number of digits (0-9). If an odd number of digits is entered a leading an even number of digits (0-9). If an odd number of digits is entered a leading
zero is added by Zint. No check digit is added. zero is added by Zint. No check digit is added by default. To add a check digit,
set option_2 = 1 or --vers=1. To add a check digit but not show it in the human
readable text, set option_2 = 2 or --vers=2.
6.1.2.5 Code 2 of 5 Data Logic 6.1.2.5 Code 2 of 5 Data Logic
------------------------------ ------------------------------
Data Logic does not include a check digit and can encode any length numeric Data Logic does not include a check digit by default and can encode any length
input (digits 0-9). numeric input (digits 0-9). To add a check digit, set option_2 = 1 or --vers=1.
To add a check digit but not show it in the human readable text, set option_2 =
2 or --vers=2.
6.1.2.6 ITF-14 6.1.2.6 ITF-14
-------------- --------------

View File

@ -16,11 +16,11 @@ else()
qt5_wrap_ui(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui extExport.ui) qt5_wrap_ui(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui extExport.ui)
qt5_add_resources(zint-qt_SRCS resources.qrc) qt5_add_resources(zint-qt_SRCS resources.qrc)
endif() endif()
# grpAztec.ui grpC49.ui grpDBExtend.ui grpLOGMARS.ui grpPDF417.ui grpUPCEAN.ui # grpAztec.ui grpC39.ui grpCodeOne.ui grpHX.ui grpMSICheck.ui grpUPCA.ui
# grpC11.ui grpChannel.ui grpDM.ui grpMaxicode.ui grpQR.ui grpVIN.ui # grpC11.ui grpC49.ui grpDBExtend.ui grpLOGMARS.ui grpPDF417.ui grpUPCEAN.ui
# grpC128.ui grpCodabar.ui grpDotCode.ui grpMicroPDF.ui grpRMQR.ui # grpC128.ui grpChannel.ui grpDM.ui grpMaxicode.ui grpQR.ui grpVIN.ui
# grpC16k.ui grpCodablockF.ui grpGrid.ui grpMQR.ui grpUltra.ui # grpC16k.ui grpCodabar.ui grpDotCode.ui grpMicroPDF.ui grpRMQR.ui
# grpC39.ui grpCodeOne.ui grpHX.ui grpMSICheck.ui grpUPCA.ui # grpC25.ui grpCodablockF.ui grpGrid.ui grpMQR.ui grpUltra.ui
add_executable(zint-qt ${zint-qt_SRCS}) add_executable(zint-qt ${zint-qt_SRCS})
add_dependencies(zint-qt zint) add_dependencies(zint-qt zint)

View File

@ -65,6 +65,7 @@ FORMS += extData.ui \
grpC11.ui \ grpC11.ui \
grpC128.ui \ grpC128.ui \
grpC16k.ui \ grpC16k.ui \
grpC25.ui \
grpC39.ui \ grpC39.ui \
grpC49.ui \ grpC49.ui \
grpChannel.ui \ grpChannel.ui \

View File

@ -18,6 +18,7 @@ FORMS += extData.ui \
grpC11.ui \ grpC11.ui \
grpC128.ui \ grpC128.ui \
grpC16k.ui \ grpC16k.ui \
grpC25.ui \
grpC39.ui \ grpC39.ui \
grpC49.ui \ grpC49.ui \
grpChannel.ui \ grpChannel.ui \

77
frontend_qt/grpC25.ui Normal file
View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>grpC25</class>
<widget class="QWidget" name="grpC25">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>254</width>
<height>131</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>600</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="radC25Stand">
<property name="text">
<string>&amp;No Check Digit</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="toolTip">
<string>No check digit added</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radC25Check">
<property name="text">
<string>&amp;Check Digit</string>
</property>
<property name="toolTip">
<string>Add standard GS1 mod-10 weighted check digit</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radC25CheckHide">
<property name="text">
<string>Check Digit, Not Shown in &amp;Text</string>
</property>
<property name="toolTip">
<string>Add standard GS1 check digit but do not display in Human Readable Text</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -37,7 +37,7 @@
#include <stdio.h> #include <stdio.h>
MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl) MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl)
: QWidget(parent, fl), m_optionWidget(NULL), m_symbology(0) : QWidget(parent, fl), m_optionWidget(nullptr), m_symbology(0)
{ {
m_bc.bc.setDebug(QCoreApplication::arguments().contains("--verbose")); // Undocumented command line debug flag m_bc.bc.setDebug(QCoreApplication::arguments().contains("--verbose")); // Undocumented command line debug flag
@ -713,6 +713,21 @@ void MainWindow::change_options()
connect(m_optionWidget->findChild<QObject*>("radC11NoCheckDigits"), SIGNAL(clicked( bool )), SLOT(update_preview())); connect(m_optionWidget->findChild<QObject*>("radC11NoCheckDigits"), SIGNAL(clicked( bool )), SLOT(update_preview()));
} }
if (symbology == BARCODE_C25STANDARD || symbology == BARCODE_C25INTER || symbology == BARCODE_C25IATA
|| symbology == BARCODE_C25LOGIC || symbology == BARCODE_C25IND)
{
QFile file(":/grpC25.ui");
if (file.open(QIODevice::ReadOnly)) {
m_optionWidget = uiload.load(&file);
file.close();
static const char *names[] = { "Standard (Matrix)", "Interleaved", "IATA", "", "Data Logic", "Industrial" };
tabMain->insertTab(1, m_optionWidget, tr("Cod&e 2 of 5 %1").arg(names[symbology - BARCODE_C25STANDARD]));
connect(m_optionWidget->findChild<QObject*>("radC25Stand"), SIGNAL(clicked( bool )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("radC25Check"), SIGNAL(clicked( bool )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("radC25CheckHide"), SIGNAL(clicked( bool )), SLOT(update_preview()));
}
}
if ((symbology == BARCODE_CODE39) || (symbology == BARCODE_EXCODE39)) if ((symbology == BARCODE_CODE39) || (symbology == BARCODE_EXCODE39))
{ {
QFile file(":/grpC39.ui"); QFile file(":/grpC39.ui");
@ -1334,6 +1349,15 @@ void MainWindow::update_preview()
} }
break; break;
case BARCODE_C25STANDARD:
case BARCODE_C25INTER:
case BARCODE_C25IATA:
case BARCODE_C25LOGIC:
case BARCODE_C25IND:
m_bc.bc.setSymbol(symbology);
m_bc.bc.setOption2(get_button_group_index(QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide"));
break;
case BARCODE_CODE39: case BARCODE_CODE39:
if(m_optionWidget->findChild<QRadioButton*>("radC39HIBC")->isChecked()) if(m_optionWidget->findChild<QRadioButton*>("radC39HIBC")->isChecked())
m_bc.bc.setSymbol(BARCODE_HIBC_39); m_bc.bc.setSymbol(BARCODE_HIBC_39);
@ -1809,11 +1833,13 @@ const char *MainWindow::get_setting_name(int symbology) {
/* Helper to return index of selected radio button in group, checking for NULL */ /* Helper to return index of selected radio button in group, checking for NULL */
int MainWindow::get_button_group_index(const QStringList &children) { int MainWindow::get_button_group_index(const QStringList &children) {
QRadioButton *radioButton; if (m_optionWidget) {
for (int index = 0; index < children.size(); index++) { QRadioButton *radioButton;
radioButton = m_optionWidget->findChild<QRadioButton*>(children[index]); for (int index = 0; index < children.size(); index++) {
if (radioButton && radioButton->isChecked()) { radioButton = m_optionWidget->findChild<QRadioButton*>(children[index]);
return index; if (radioButton && radioButton->isChecked()) {
return index;
}
} }
} }
return 0; return 0;
@ -1821,27 +1847,29 @@ int MainWindow::get_button_group_index(const QStringList &children) {
/* Helper to set radio button in group from index in settings, checking for NULL */ /* Helper to set radio button in group from index in settings, checking for NULL */
void MainWindow::set_radiobutton_from_setting(QSettings &settings, const QString &setting, const QStringList &children, int default_val) { void MainWindow::set_radiobutton_from_setting(QSettings &settings, const QString &setting, const QStringList &children, int default_val) {
int index = settings.value(setting, default_val).toInt(); if (m_optionWidget) {
QRadioButton *radioButton; int index = settings.value(setting, default_val).toInt();
if (index >= 0 && index < children.size()) { QRadioButton *radioButton;
radioButton = m_optionWidget->findChild<QRadioButton*>(children[index]); if (index >= 0 && index < children.size()) {
} else { radioButton = m_optionWidget->findChild<QRadioButton*>(children[index]);
radioButton = m_optionWidget->findChild<QRadioButton*>(children[0]); } else {
} radioButton = m_optionWidget->findChild<QRadioButton*>(children[0]);
if (radioButton) { }
radioButton->setChecked(true); if (radioButton) {
radioButton->setChecked(true);
}
} }
} }
/* Helper to return index of selected item in combobox, checking for NULL */ /* Helper to return index of selected item in combobox, checking for NULL */
int MainWindow::get_combobox_index(const QString &child) { int MainWindow::get_combobox_index(const QString &child) {
QComboBox *comboBox = m_optionWidget->findChild<QComboBox*>(child); QComboBox *comboBox = m_optionWidget ? m_optionWidget->findChild<QComboBox*>(child) : nullptr;
return comboBox ? comboBox->currentIndex() : 0; return comboBox ? comboBox->currentIndex() : 0;
} }
/* Helper to set item in combobox from index in settings, checking for NULL */ /* Helper to set item in combobox from index in settings, checking for NULL */
void MainWindow::set_combobox_from_setting(QSettings &settings, const QString &setting, const QString &child, int default_val) { void MainWindow::set_combobox_from_setting(QSettings &settings, const QString &setting, const QString &child, int default_val) {
QComboBox *comboBox = m_optionWidget->findChild<QComboBox*>(child); QComboBox *comboBox = m_optionWidget ? m_optionWidget->findChild<QComboBox*>(child) : nullptr;
if (comboBox) { if (comboBox) {
comboBox->setCurrentIndex(settings.value(setting, default_val).toInt()); comboBox->setCurrentIndex(settings.value(setting, default_val).toInt());
} }
@ -1849,13 +1877,13 @@ void MainWindow::set_combobox_from_setting(QSettings &settings, const QString &s
/* Helper to return if checkbox checked, checking for NULL */ /* Helper to return if checkbox checked, checking for NULL */
int MainWindow::get_checkbox_val(const QString &child) { int MainWindow::get_checkbox_val(const QString &child) {
QCheckBox *checkBox = m_optionWidget->findChild<QCheckBox*>(child); QCheckBox *checkBox = m_optionWidget ? m_optionWidget->findChild<QCheckBox*>(child) : nullptr;
return checkBox && checkBox->isChecked() ? 1 : 0; return checkBox && checkBox->isChecked() ? 1 : 0;
} }
/* Helper to set checkbox from settings, checking for NULL */ /* Helper to set checkbox from settings, checking for NULL */
void MainWindow::set_checkbox_from_setting(QSettings &settings, const QString &setting, const QString &child, int default_val) { void MainWindow::set_checkbox_from_setting(QSettings &settings, const QString &setting, const QString &child, int default_val) {
QCheckBox *checkBox = m_optionWidget->findChild<QCheckBox*>(child); QCheckBox *checkBox = m_optionWidget ? m_optionWidget->findChild<QCheckBox*>(child) : nullptr;
if (checkBox) { if (checkBox) {
checkBox->setChecked(settings.value(setting, default_val).toInt() ? true : false); checkBox->setChecked(settings.value(setting, default_val).toInt() ? true : false);
} }
@ -1863,13 +1891,13 @@ void MainWindow::set_checkbox_from_setting(QSettings &settings, const QString &s
/* Helper to return text of line edit, checking for NULL */ /* Helper to return text of line edit, checking for NULL */
QString MainWindow::get_lineedit_val(const QString &child) { QString MainWindow::get_lineedit_val(const QString &child) {
QLineEdit *lineEdit = m_optionWidget->findChild<QLineEdit*>(child); QLineEdit *lineEdit = m_optionWidget ? m_optionWidget->findChild<QLineEdit*>(child) : nullptr;
return lineEdit ? lineEdit->text() : ""; return lineEdit ? lineEdit->text() : "";
} }
/* Helper to set line edit from settings, checking for NULL */ /* Helper to set line edit from settings, checking for NULL */
void MainWindow::set_lineedit_from_setting(QSettings &settings, const QString &setting, const QString &child, const char *default_val) { void MainWindow::set_lineedit_from_setting(QSettings &settings, const QString &setting, const QString &child, const char *default_val) {
QLineEdit *lineEdit = m_optionWidget->findChild<QLineEdit*>(child); QLineEdit *lineEdit = m_optionWidget ? m_optionWidget->findChild<QLineEdit*>(child) : nullptr;
if (lineEdit) { if (lineEdit) {
lineEdit->setText(settings.value(setting, default_val).toString()); lineEdit->setText(settings.value(setting, default_val).toString());
} }
@ -1877,13 +1905,13 @@ void MainWindow::set_lineedit_from_setting(QSettings &settings, const QString &s
/* Helper to return value of spin box, checking for NULL */ /* Helper to return value of spin box, checking for NULL */
int MainWindow::get_spinbox_val(const QString &child) { int MainWindow::get_spinbox_val(const QString &child) {
QSpinBox *spinBox = m_optionWidget->findChild<QSpinBox*>(child); QSpinBox *spinBox = m_optionWidget ? m_optionWidget->findChild<QSpinBox*>(child) : nullptr;
return spinBox ? spinBox->value() : 0; return spinBox ? spinBox->value() : 0;
} }
/* Helper to set spin box from settings, checking for NULL */ /* Helper to set spin box from settings, checking for NULL */
void MainWindow::set_spinbox_from_setting(QSettings &settings, const QString &setting, const QString &child, int default_val) { void MainWindow::set_spinbox_from_setting(QSettings &settings, const QString &setting, const QString &child, int default_val) {
QSpinBox *spinBox = m_optionWidget->findChild<QSpinBox*>(child); QSpinBox *spinBox = m_optionWidget ? m_optionWidget->findChild<QSpinBox*>(child) : nullptr;
if (spinBox) { if (spinBox) {
spinBox->setValue(settings.value(setting, default_val).toInt()); spinBox->setValue(settings.value(setting, default_val).toInt());
} }
@ -1982,6 +2010,22 @@ void MainWindow::save_sub_settings(QSettings &settings, int symbology) {
settings.setValue("studio/bc/code11/check_digit", get_button_group_index(QStringList() << "radC11TwoCheckDigits" << "radC11OneCheckDigit" << "radC11NoCheckDigits")); settings.setValue("studio/bc/code11/check_digit", get_button_group_index(QStringList() << "radC11TwoCheckDigits" << "radC11OneCheckDigit" << "radC11NoCheckDigits"));
break; break;
case BARCODE_C25STANDARD:
settings.setValue("studio/bc/c25standard/check_digit", get_button_group_index(QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide"));
break;
case BARCODE_C25INTER:
settings.setValue("studio/bc/c25inter/check_digit", get_button_group_index(QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide"));
break;
case BARCODE_C25IATA:
settings.setValue("studio/bc/c25iata/check_digit", get_button_group_index(QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide"));
break;
case BARCODE_C25LOGIC:
settings.setValue("studio/bc/c25logic/check_digit", get_button_group_index(QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide"));
break;
case BARCODE_C25IND:
settings.setValue("studio/bc/c25ind/check_digit", get_button_group_index(QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide"));
break;
case BARCODE_CODE39: case BARCODE_CODE39:
case BARCODE_HIBC_39: case BARCODE_HIBC_39:
settings.setValue("studio/bc/code39/check_digit", get_button_group_index(QStringList() << "radC39Stand" << "radC39Check" << "radC39HIBC")); settings.setValue("studio/bc/code39/check_digit", get_button_group_index(QStringList() << "radC39Stand" << "radC39Check" << "radC39HIBC"));
@ -2212,6 +2256,22 @@ void MainWindow::load_sub_settings(QSettings &settings, int symbology) {
set_radiobutton_from_setting(settings, "studio/bc/code11/check_digit", QStringList() << "radC11TwoCheckDigits" << "radC11OneCheckDigit" << "radC11NoCheckDigits"); set_radiobutton_from_setting(settings, "studio/bc/code11/check_digit", QStringList() << "radC11TwoCheckDigits" << "radC11OneCheckDigit" << "radC11NoCheckDigits");
break; break;
case BARCODE_C25STANDARD:
set_radiobutton_from_setting(settings, "studio/bc/c25standard/check_digit", QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide");
break;
case BARCODE_C25INTER:
set_radiobutton_from_setting(settings, "studio/bc/c25inter/check_digit", QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide");
break;
case BARCODE_C25IATA:
set_radiobutton_from_setting(settings, "studio/bc/c25iata/check_digit", QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide");
break;
case BARCODE_C25LOGIC:
set_radiobutton_from_setting(settings, "studio/bc/c25logic/check_digit", QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide");
break;
case BARCODE_C25IND:
set_radiobutton_from_setting(settings, "studio/bc/c25ind/check_digit", QStringList() << "radC25Stand" << "radC25Check" << "radC25CheckHide");
break;
case BARCODE_CODE39: case BARCODE_CODE39:
case BARCODE_HIBC_39: case BARCODE_HIBC_39:
set_radiobutton_from_setting(settings, "studio/bc/code39/check_digit", QStringList() << "radC39Stand" << "radC39Check" << "radC39HIBC"); set_radiobutton_from_setting(settings, "studio/bc/code39/check_digit", QStringList() << "radC39Stand" << "radC39Check" << "radC39HIBC");

View File

@ -6,6 +6,7 @@
<file>images/zoomin.png</file> <file>images/zoomin.png</file>
<file>grpAztec.ui</file> <file>grpAztec.ui</file>
<file>grpC11.ui</file> <file>grpC11.ui</file>
<file>grpC25.ui</file>
<file>grpC39.ui</file> <file>grpC39.ui</file>
<file>grpDM.ui</file> <file>grpDM.ui</file>
<file>grpMSICheck.ui</file> <file>grpMSICheck.ui</file>