diff --git a/CMakeLists.txt b/CMakeLists.txt index f5a11c22..e21834c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,35 +100,61 @@ ENDIF(APPLE) add_subdirectory(backend) add_subdirectory(frontend) -find_package(Qt5Widgets) -find_package(Qt5Gui) -find_package(Qt5UiTools) +if($ENV{CMAKE_PREFIX_PATH} MATCHES "6[.][0-9][.][0-9]") + set(USE_QT6 TRUE) + message(STATUS "Using Qt6") + cmake_policy(SET CMP0012 NEW) # Recognize constants in if() + cmake_policy(SET CMP0072 NEW) # Choose OpenGL over legacy GL + find_package(Qt6Widgets) + find_package(Qt6Gui) + find_package(Qt6UiTools) -if (Qt5Widgets_FOUND) - if (Qt5Gui_FOUND) - if (Qt5UiTools_FOUND) - set( QT_USE_QTGUI TRUE ) - set( QT_USE_QTUITOOLS TRUE ) - set( QT_USE_QTXML TRUE ) - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${Qt5Widgets_INCLUDES} - ${Qt5Gui_INCLUDES} - ${Qt5UiTools_INCLUDES} - ${CMAKE_CURRENT_BINARY_DIR} - ) - add_subdirectory(backend_qt) - add_subdirectory(frontend_qt) - endif(Qt5UiTools_FOUND) - endif(Qt5Gui_FOUND) -endif(Qt5Widgets_FOUND) + if(Qt6Widgets_FOUND AND Qt6Gui_FOUND AND Qt6UiTools_FOUND) + set(QT_USE_QTGUI TRUE) + set(QT_USE_QTUITOOLS TRUE) + set(QT_USE_QTXML TRUE) + include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${Qt6Widgets_INCLUDES} + ${Qt6Gui_INCLUDES} + ${Qt6UiTools_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR} + ) + add_subdirectory(backend_qt) + add_subdirectory(frontend_qt) + else() + message(STATUS "Could NOT find Qt6") + endif() +else() + message(STATUS "Using Qt5") + find_package(Qt5Widgets) + find_package(Qt5Gui) + find_package(Qt5UiTools) -CONFIGURE_FILE( + if(Qt5Widgets_FOUND AND Qt5Gui_FOUND AND Qt5UiTools_FOUND) + set(QT_USE_QTGUI TRUE) + set(QT_USE_QTUITOOLS TRUE) + set(QT_USE_QTXML TRUE) + include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${Qt5Widgets_INCLUDES} + ${Qt5Gui_INCLUDES} + ${Qt5UiTools_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR} + ) + add_subdirectory(backend_qt) + add_subdirectory(frontend_qt) + else() + message(STATUS "Could NOT find Qt5") + endif() +endif() + +configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) -ADD_CUSTOM_TARGET(uninstall +add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") # staniek: don't install diff --git a/backend/aztec.c b/backend/aztec.c index 466c6bfd..941a260d 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -49,14 +49,14 @@ static int count_doubles(const unsigned char source[], const int posn, const siz int i = posn; int cond = 1; - do { + while ((i + 1 < (int) src_len) && cond) { if (((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ')) { c++; } else { cond = 0; } i += 2; - } while ((i < (int) src_len) && cond); + } return c; } @@ -66,14 +66,14 @@ static int count_cr(unsigned char source[], int posn, int length) { int i = posn; int cond = 1; - do { + while ((i < length) && cond) { if (source[i] == 13) { c++; } else { cond = 0; } i++; - } while ((i < length) && cond); + } return c; } @@ -83,14 +83,14 @@ static int count_dotcomma(unsigned char source[], int posn, int length) { int i = posn; int cond = 1; - do { + while ((i < length) && cond) { if ((source[i] == '.') || (source[i] == ',')) { c++; } else { cond = 0; } i++; - } while ((i < length) && cond); + } return c; } @@ -100,14 +100,14 @@ static int count_spaces(unsigned char source[], int posn, int length) { int i = posn; int cond = 1; - do { + while ((i < length) && cond) { if (source[i] == ' ') { c++; } else { cond = 0; } i++; - } while ((i < length) && cond); + } return c; } @@ -168,7 +168,7 @@ static int aztec_text_process(const unsigned char source[], const size_t src_len // Deal first with letter combinations which can be combined to one codeword // Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode current_mode = 'U'; - for (i = 0; i < (int) src_len - 1; i++) { + for (i = 0; i + 1 < (int) src_len; i++) { // Combination (CR LF) should always be in Punct mode if ((source[i] == 13) && (source[i + 1] == 10)) { encode_mode[i] = 'P'; @@ -249,19 +249,19 @@ static int aztec_text_process(const unsigned char source[], const size_t src_len i = 0; j = 0; while (i < (int) src_len) { - if ((source[i] == 13) && (source[i + 1] == 10)) { // CR LF + if ((source[i] == 13) && (i + 1 < (int) src_len) && (source[i + 1] == 10)) { // CR LF reduced_source[j] = 'a'; reduced_encode_mode[j] = encode_mode[i]; i += 2; - } else if (((source[i] == '.') && (source[i + 1] == ' ')) && (encode_mode[i] == 'P')) { + } else if ((source[i] == '.') && (i + 1 < (int) src_len) && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) { reduced_source[j] = 'b'; reduced_encode_mode[j] = encode_mode[i]; i += 2; - } else if (((source[i] == ',') && (source[i + 1] == ' ')) && (encode_mode[i] == 'P')) { + } else if ((source[i] == ',') && (i + 1 < (int) src_len) && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) { reduced_source[j] = 'c'; reduced_encode_mode[j] = encode_mode[i]; i += 2; - } else if ((source[i] == ':') && (source[i + 1] == ' ')) { + } else if ((source[i] == ':') && (i + 1 < (int) src_len) && (source[i + 1] == ' ')) { reduced_source[j] = 'd'; reduced_encode_mode[j] = encode_mode[i]; i += 2; @@ -530,7 +530,7 @@ static int aztec_text_process(const unsigned char source[], const size_t src_len printf("\n"); } - strcpy(binary_string, ""); + *binary_string = '\0'; if (gs1) { bin_append(0, 5, binary_string); // P/S @@ -1128,25 +1128,20 @@ INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], const siz j = 0; count = 0; for (i = 0; i < data_length; i++) { - if ((j + 1) % codeword_size == 0) { // Last bit of codeword /* 7.3.1.2 "whenever the first B-1 bits ... are all “0”s, then a dummy “1” is inserted..." * "Similarly a message codeword that starts with B-1 “1”s has a dummy “0” inserted..." */ - if (count == (codeword_size - 1)) { - // Codeword of B-1 '1's - adjusted_string[j] = '0'; + if (count == 0 || count == (codeword_size - 1)) { + // Codeword of B-1 '0's or B-1 '1's + adjusted_string[j] = count == 0 ? '1' : '0'; j++; + count = binary_string[i] == '1' ? 1 : 0; + } else { + count = 0; } - if (count == 0) { - // Codeword of B-1 '0's - adjusted_string[j] = '1'; - j++; - } - - count = 0; } else if (binary_string[i] == '1') { /* Skip B so only counting B-1 */ count++; } @@ -1235,19 +1230,15 @@ INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], const siz if ((j + 1) % codeword_size == 0) { // Last bit of codeword - if (count == (codeword_size - 1)) { - // Codeword of B-1 '1's - adjusted_string[j] = '0'; + if (count == 0 || count == (codeword_size - 1)) { + // Codeword of B-1 '0's or B-1 '1's + adjusted_string[j] = count == 0 ? '1' : '0'; j++; + count = binary_string[i] == '1' ? 1 : 0; + } else { + count = 0; } - if (count == 0) { - // Codeword of B-1 '0's - adjusted_string[j] = '1'; - j++; - } - - count = 0; } else if (binary_string[i] == '1') { /* Skip B so only counting B-1 */ count++; } @@ -1581,6 +1572,7 @@ INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int int input_value, error_number, i, y, x; char binary_string[28]; unsigned char data_codewords[3], ecc_codewords[6]; + int debug = symbol->debug & ZINT_DEBUG_PRINT; input_value = 0; if (length > 3) { @@ -1609,7 +1601,7 @@ INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int return ZINT_ERROR_INVALID_DATA; } - strcpy(binary_string, ""); + *binary_string = '\0'; bin_append(input_value, 8, binary_string); data_codewords[0] = 0; @@ -1635,8 +1627,6 @@ INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int rs_encode(2, data_codewords, ecc_codewords); rs_free(); - strcpy(binary_string, ""); - for (i = 0; i < 5; i++) { if (ecc_codewords[4 - i] & 0x08) { binary_string[(i * 4) + 8] = '1'; @@ -1668,6 +1658,10 @@ INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int } } + if (debug) { + printf("Binary String: %.28s\n", binary_string); + } + for (y = 8; y < 19; y++) { for (x = 8; x < 19; x++) { if (CompactAztecMap[(y * 27) + x] == 1) { diff --git a/backend/common.c b/backend/common.c index 533bd028..b082eb63 100644 --- a/backend/common.c +++ b/backend/common.c @@ -64,9 +64,10 @@ INTERNAL void bin_append_posn(const int arg, const int length, char *binary, siz start = 0x01 << (length - 1); for (i = 0; i < length; i++) { - binary[posn + i] = '0'; if (arg & (start >> i)) { binary[posn + i] = '1'; + } else { + binary[posn + i] = '0'; } } } @@ -114,18 +115,19 @@ INTERNAL int is_sane(const char test_string[], const unsigned char source[], con /* Replaces huge switch statements for looking up in tables */ INTERNAL void lookup(const char set_string[], const char *table[], const char data, char dest[]) { - size_t i, n = strlen(set_string); + int i, n = (int) strlen(set_string); for (i = 0; i < n; i++) { if (data == set_string[i]) { strcat(dest, table[i]); + break; } } } /* Returns the position of data in set_string */ INTERNAL int posn(const char set_string[], const char data) { - int i, n = (int)strlen(set_string); + int i, n = (int) strlen(set_string); for (i = 0; i < n; i++) { if (data == set_string[i]) { @@ -162,22 +164,23 @@ INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const /* Expands from a width pattern to a bit pattern */ INTERNAL void expand(struct zint_symbol *symbol, const char data[]) { - size_t reader, n = strlen(data); + int reader, n = (int) strlen(data); int writer, i; - char latch; + int latch, num; writer = 0; - latch = '1'; + latch = 1; for (reader = 0; reader < n; reader++) { - for (i = 0; i < ctoi(data[reader]); i++) { - if (latch == '1') { + num = ctoi(data[reader]); + for (i = 0; i < num; i++) { + if (latch) { set_module(symbol, symbol->rows, writer); } writer++; } - latch = (latch == '1' ? '0' : '1'); + latch = !latch; } if (symbol->symbology != BARCODE_PHARMA) { diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 639d6d21..a2c7a6f5 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2009-2017 Robin Stuart + Copyright (C) 2009 - 2020 Robin Stuart developed from and including some functions from: IEC16022 bar code generation @@ -40,8 +40,6 @@ /* vim: set ts=4 sw=4 et : */ #include -#include -#include #include #include #ifdef _MSC_VER @@ -528,7 +526,8 @@ static int look_ahead_test(const unsigned char inputData[], const size_t sourcel /* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate Supports encoding FNC1 in supporting systems */ -static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], unsigned char target[], int *last_mode, size_t *length_p, int process_buffer[], int *process_p, int *binlen_p) { +static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], unsigned char target[], + int *last_mode, int *last_shift, size_t *length_p, int process_buffer[], int *process_p, int *binlen_p) { size_t sp; int tp, i, gs1; @@ -543,7 +542,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], sp = 0; tp = 0; - memset(process_buffer, 0, 8); + memset(process_buffer, 0, 8 * sizeof(int)); *process_p = 0; strcpy(binary, ""); @@ -645,7 +644,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], if (istwodigits(source, inputlen, sp)) { target[tp] = (unsigned char) ((10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130); - if (debug) printf("N%d ", target[tp] - 130); + if (debug) printf("N%02d ", target[tp] - 130); tp++; strcat(binary, " "); sp += 2; @@ -735,17 +734,20 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], shift_set = c40_shift[source[sp] - 128]; value = c40_value[source[sp] - 128]; } else { - shift_set = c40_shift[source[sp]]; - value = c40_value[source[sp]]; - } - - if (gs1 && (source[sp] == '[')) { - if (gs1 == 2) { - shift_set = c40_shift[29]; - value = c40_value[29]; /* GS */ + if (gs1 && (source[sp] == '[')) { + if (gs1 == 2) { + shift_set = c40_shift[29]; + value = c40_value[29]; /* GS */ + } else { + shift_set = 2; + value = 27; /* FNC1 */ + } } else { - shift_set = 2; - value = 27; /* FNC1 */ + shift_set = c40_shift[source[sp]]; + value = c40_value[source[sp]]; + } + if (*process_p % 3 == 2) { + *last_shift = shift_set; } } @@ -803,17 +805,20 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], shift_set = text_shift[source[sp] - 128]; value = text_value[source[sp] - 128]; } else { - shift_set = text_shift[source[sp]]; - value = text_value[source[sp]]; - } - - if (gs1 && (source[sp] == '[')) { - if (gs1 == 2) { - shift_set = text_shift[29]; - value = text_value[29]; /* GS */ + if (gs1 && (source[sp] == '[')) { + if (gs1 == 2) { + shift_set = text_shift[29]; + value = text_value[29]; /* GS */ + } else { + shift_set = 2; + value = 27; /* FNC1 */ + } } else { - shift_set = 2; - value = 27; /* FNC1 */ + shift_set = text_shift[source[sp]]; + value = text_value[source[sp]]; + } + if (*process_p % 3 == 2) { + *last_shift = shift_set; } } @@ -865,20 +870,15 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], int value = 0; if (source[sp] == 13) { value = 0; - } - if (source[sp] == '*') { + } else if (source[sp] == '*') { value = 1; - } - if (source[sp] == '>') { + } else if (source[sp] == '>') { value = 2; - } - if (source[sp] == ' ') { + } else if (source[sp] == ' ') { value = 3; - } - if ((source[sp] >= '0') && (source[sp] <= '9')) { + } else if ((source[sp] >= '0') && (source[sp] <= '9')) { value = (source[sp] - '0') + 4; - } - if ((source[sp] >= 'A') && (source[sp] <= 'Z')) { + } else if ((source[sp] >= 'A') && (source[sp] <= 'Z')) { value = (source[sp] - 'A') + 14; } @@ -977,6 +977,8 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], } /* while */ + if (debug) printf("\n"); + /* Add length and randomising algorithm to b256 */ i = 0; while (i < tp) { @@ -1024,19 +1026,28 @@ 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 size_t inputlen, - const int last_mode, const int process_buffer[], const int process_p, const int symbols_left, int debug) { + const int last_mode, const int last_shift, const int process_buffer[], const int process_p, const int symbols_left, int debug) { switch (last_mode) { case DM_C40: case DM_TEXT: - if (debug) printf(" %s symbols_left %d, process_p %d\n", last_mode == DM_C40 ? "C40" : "TEXT", symbols_left, process_p); + /* NOTE: the use of a 0-padded doublet is only mentioned in ISO/IEC 16022:2006 for case 5.2.5.2 (b) when 2 symbols and + * 2 C40/Text characters are left, but using it here also for other cases. This matches the behaviour of tec-it (but + * not BWIPP) and is used for figures 4.15-1-1 and 4.15-1-1 in GS1 General Specifications. */ + + if (debug) printf("%s last_shift %d, symbols_left %d, process_p %d ", last_mode == DM_C40 ? "C40" : "TEX", last_shift, symbols_left, process_p); if (process_p == 1) // 1 data character left to encode. { + if (last_shift) { + target[target_length - 1] -= last_shift - 1; // Remove shift from second half of previous doublet leaving pad value (0) + } if (symbols_left > 1) { target[target_length] = 254; target_length++; // Unlatch and encode remaining data in ascii. + if (debug) printf("ASC "); } target[target_length] = source[inputlen - 1] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; } else if (process_p == 2) // 2 data characters left to encode. { @@ -1046,55 +1057,62 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons target_length++; target[target_length] = (unsigned char) (intValue % 256); target_length++; + if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], 0); if (symbols_left > 2) { target[target_length] = 254; // Unlatch target_length++; + if (debug) printf("ASC "); } } else { if (symbols_left > 0) { target[target_length] = 254; // Unlatch target_length++; + if (debug) printf("ASC "); } } break; case DM_X12: - if (debug) printf(" X12 symbols_left %d, process_p %d\n", symbols_left, process_p); + if (debug) printf("X12 symbols_left %d, process_p %d ", symbols_left, process_p); if ((symbols_left == process_p) && (process_p == 1)) { // Unlatch not required! target[target_length] = source[inputlen - 1] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; } else if (symbols_left) { target[target_length] = (254); target_length++; // Unlatch. + if (debug) printf("ASC "); if (process_p == 1) { target[target_length] = source[inputlen - 1] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; - } - - if (process_p == 2) { + } else if (process_p == 2) { target[target_length] = source[inputlen - 2] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; target[target_length] = source[inputlen - 1] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; } } break; case DM_EDIFACT: - if (debug) printf(" EDIFACT symbols_left %d, process_p %d\n", symbols_left, process_p); + if (debug) printf("EDI symbols_left %d, process_p %d ", symbols_left, process_p); if (symbols_left <= 2) // Unlatch not required! { if (process_p == 1) { target[target_length] = source[inputlen - 1] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; - } - - if (process_p == 2) { + } else if (process_p == 2) { target[target_length] = source[inputlen - 2] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; target[target_length] = source[inputlen - 1] + 1; + if (debug) printf("A%02X ", target[target_length] - 1); target_length++; } } else { @@ -1102,31 +1120,29 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons if (process_p == 0) { target[target_length] = (unsigned char) (31 << 2); target_length++; - } - - if (process_p == 1) { + if (debug) printf("[31 0 0 0] "); + } else 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++; - } - - if (process_p == 2) { + if (debug) printf("[%d 31 0 0] ", process_buffer[0]); + } else 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) { + if (debug) printf("[%d %d 31 0] ", process_buffer[0], process_buffer[1]); + } else 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)); target_length++; target[target_length] = (unsigned char) (((process_buffer[2] & 0x03) << 6) + 31); target_length++; + if (debug) printf("[%d %d %d 31] ", process_buffer[0], process_buffer[1], process_buffer[2]); } } break; @@ -1134,9 +1150,9 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons if (debug) { int i; - printf("\n\n"); + printf("\nData (%d): ", target_length); for (i = 0; i < target_length; i++) - printf("%03d ", target[i]); + printf("%d ", target[i]); printf("\n"); } @@ -1177,10 +1193,12 @@ static int data_matrix_200(struct zint_symbol *symbol,const unsigned char source int taillength, error_number = 0; int H, W, FH, FW, datablock, bytes, rsblock; int last_mode = DM_ASCII; + int last_shift = 0; int symbols_left; + int debug = symbol->debug & ZINT_DEBUG_PRINT; /* inputlen may be decremented by 2 if macro character is used */ - error_number = dm200encode(symbol, source, binary, &last_mode, &inputlen, process_buffer, &process_p, &binlen); + error_number = dm200encode(symbol, source, binary, &last_mode, &last_shift, &inputlen, process_buffer, &process_p, &binlen); if (error_number != 0) { return error_number; } @@ -1226,7 +1244,7 @@ static int data_matrix_200(struct zint_symbol *symbol,const unsigned char source // Now we know the symbol size we can handle the remaining data in the process buffer. symbols_left = matrixbytes[symbolsize] - binlen; - binlen = dm200encode_remainder(binary, binlen, source, inputlen, last_mode, process_buffer, process_p, symbols_left, symbol->debug & ZINT_DEBUG_PRINT); + binlen = dm200encode_remainder(binary, binlen, source, inputlen, last_mode, last_shift, process_buffer, process_p, symbols_left, debug); if (binlen > matrixbytes[symbolsize]) { strcpy(symbol->errtxt, "523: Data too long to fit in symbol"); @@ -1246,27 +1264,23 @@ static int data_matrix_200(struct zint_symbol *symbol,const unsigned char source if (taillength != 0) { add_tail(binary, binlen, taillength); } + if (debug) { + printf("Pads (%d): ", taillength); + for (i = binlen; i < binlen + taillength; i++) printf("%d ", binary[i]); + printf("\n"); + } // ecc code if (symbolsize == INTSYMBOL144) { skew = 1; } ecc200(binary, bytes, datablock, rsblock, skew); - // Print Codewords -#ifdef DEBUG - { - int CWCount; - int posCur; - if (skew) - CWCount = 1558 + 620; - else - CWCount = bytes + rsblock * (bytes / datablock); - printf("Codewords (%i):", CWCount); - for (posCur = 0; posCur < CWCount; posCur++) - printf(" %3i", binary[posCur]); - puts("\n"); + if (debug) { + printf("ECC (%d): ", rsblock * (bytes / datablock)); + for (i = bytes; i < bytes + rsblock * (bytes / datablock); i++) printf("%d ", binary[i]); + printf("\n"); } -#endif + #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, binary, skew ? 1558 + 620 : bytes + rsblock * (bytes / datablock)); #endif diff --git a/backend/dmatrix.h b/backend/dmatrix.h index ef39825d..54772fa0 100644 --- a/backend/dmatrix.h +++ b/backend/dmatrix.h @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2009-2017 Robin Stuart + Copyright (C) 2009 - 2020 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -40,15 +40,13 @@ #ifndef __DMATRIX_H #define __DMATRIX_H -#define MAXBARCODE 3116 - -#define DM_NULL 0 -#define DM_ASCII 1 -#define DM_C40 2 -#define DM_TEXT 3 -#define DM_X12 4 -#define DM_EDIFACT 5 -#define DM_BASE256 6 +#define DM_NULL 0 +#define DM_ASCII 1 +#define DM_C40 2 +#define DM_TEXT 3 +#define DM_X12 4 +#define DM_EDIFACT 5 +#define DM_BASE256 6 static const char c40_shift[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -93,13 +91,12 @@ static const unsigned short int intsymbol[] = { 44, /* 21:104x104,816*/ 45, /* 22:120x120,1050*/46, /* 23:132x132,1304*/47, /* 24:144x144,1558*/ 2, /* 25: 8x18 , 5*/ 4, /* 26: 8x32 , 10*/ 6, /* 27: 12x26 , 16*/ 10, /* 28: 12x36 , 22*/ 13, /* 29: 16x36 , 32*/ 20, /* 30: 16x48 , 49*/ -/* DMRE */ +/* DMRE */ 8, /* 31: 8x48 , 18*/ 11, /* 32: 8x64 , 24*/ 14, /* 33: 8x80 , 32*/ 16, /* 34: 8x96 , 38*/ 21, /* 35: 8x120, 49*/ 25, /* 36: 8x144, 63*/ 17, /* 37: 12x64 , 43*/ 26, /* 38: 12x88 , 64*/ 24, /* 39: 16x64 , 62*/ 19, /* 40: 20x36 , 44*/ 22, /* 41: 20x44 , 56*/ 30, /* 42: 20x64 , 84*/ 28, /* 43: 22x48 , 72*/ 29, /* 44: 24x48 , 80*/ 33, /* 45: 24x64 ,108*/ 27, /* 46: 26x40 , 70*/ 32, /* 47: 26x48 , 90*/ 35, /* 48: 26x64 ,118*/ - 0 }; // Number of DM Sizes @@ -167,14 +164,14 @@ static const unsigned short int matrixFH[] = { /* 4*/ 8, /* 8x32 */ 16, /* 16x16 */ 12, /* 12x26 */ 18, /* 18x18 */ /* 8*/ 8, /* 8x48 */ 20, /* 20x20 */ 12, /* 12x36 */ 8, /* 8x64 */ /*12*/ 22, /* 22x22 */ 16, /* 16x36 */ 8, /* 8x80 */ 24, /* 24x24 */ - /*16*/ 8, /* 8x96 */ 12, /* 12x64 */ 26, /* 26x26 */ 20, /* 20x36 */ + /*16*/ 8, /* 8x96 */ 12, /* 12x64 */ 26, /* 26x26 */ 20, /* 20x36 */ /*20*/ 16, /* 16x48 */ 8, /* 8x120*/ 20, /* 20x44 */ 16, /* 32x32 */ /*24*/ 16, /* 16x64 */ 8, /* 8x144*/ 12, /* 12x88 */ 26, /* 26x40 */ /*28*/ 22, /* 22x48 */ 24, /* 24x48 */ 20, /* 20x64 */ 18, /* 36x36 */ /*32*/ 26, /* 26x48 */ 24, /* 24x64 */ 20, /* 40x40 */ 26, /* 26x64 */ /*36*/ 22, /* 44x44 */ 24, /* 48x48 */ 26, /* 52x52 */ 16, /* 64x64 */ /*40*/ 18, /* 72x72 */ 20, /* 80x80 */ 22, /* 88x88 */ 24, /* 96x96 */ - /*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/ + /*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/ }; // Vertical submodule size (including subfinder) @@ -184,14 +181,14 @@ static const unsigned short int matrixFW[] = { /* 4*/ 16, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */ /* 8*/ 24, /* 8x48 */ 20, /* 20x20 */ 18, /* 12x36 */ 16, /* 8x64 */ /*12*/ 22, /* 22x22 */ 18, /* 16x36 */ 20, /* 8x80 */ 24, /* 24x24 */ - /*16*/ 24, /* 8x96 */ 16, /* 12x64 */ 26, /* 26x26 */ 18, /* 20x36 */ + /*16*/ 24, /* 8x96 */ 16, /* 12x64 */ 26, /* 26x26 */ 18, /* 20x36 */ /*20*/ 24, /* 16x48 */ 20, /* 8x120*/ 22, /* 20x44 */ 16, /* 32x32 */ /*24*/ 16, /* 16x64 */ 24, /* 8x144*/ 22, /* 12x88 */ 20, /* 26x40 */ /*28*/ 24, /* 22x48 */ 24, /* 24x48 */ 16, /* 20x64 */ 18, /* 36x36 */ /*32*/ 24, /* 26x48 */ 16, /* 24x64 */ 20, /* 40x40 */ 16, /* 26x64 */ /*36*/ 22, /* 44x44 */ 24, /* 48x48 */ 26, /* 52x52 */ 16, /* 64x64 */ /*40*/ 18, /* 72x72 */ 20, /* 80x80 */ 22, /* 88x88 */ 24, /* 96x96 */ - /*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/ + /*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/ }; // Total Data Codewords @@ -201,14 +198,14 @@ static const unsigned short int matrixbytes[] = { /* 4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */ /* 8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */ /*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 32, /* 8x80 */ 36, /* 24x24 */ - /*16*/ 38, /* 8x96 */ 43, /* 12x64 */ 44, /* 26x26 */ 44, /* 20x36 */ + /*16*/ 38, /* 8x96 */ 43, /* 12x64 */ 44, /* 26x26 */ 44, /* 20x36 */ /*20*/ 49, /* 16x48 */ 49, /* 8x120*/ 56, /* 20x44 */ 62, /* 32x32 */ /*24*/ 62, /* 16x64 */ 63, /* 8x144*/ 64, /* 12x88 */ 70, /* 26x40 */ /*28*/ 72, /* 22x48 */ 80, /* 24x48 */ 84, /* 20x64 */ 86, /* 36x36 */ /*32*/ 90, /* 26x48 */ 108, /* 24x64 */ 114, /* 40x40 */ 118, /* 26x64 */ /*36*/ 144, /* 44x44 */ 174, /* 48x48 */ 204, /* 52x52 */ 280, /* 64x64 */ /*40*/ 368, /* 72x72 */ 456, /* 80x80 */ 576, /* 88x88 */ 696, /* 96x96 */ - /*44*/ 816, /*104x104*/1050, /*120x120*/1304, /*132x132*/1558 /*144x144*/ + /*44*/ 816, /*104x104*/1050, /*120x120*/1304, /*132x132*/1558 /*144x144*/ }; // Data Codewords per RS-Block @@ -218,14 +215,14 @@ static const unsigned short int matrixdatablock[] = { /* 4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */ /* 8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */ /*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 32, /* 8x80 */ 36, /* 24x24 */ - /*16*/ 38, /* 8x96 */ 43, /* 12x64 */ 44, /* 26x26 */ 44, /* 20x36 */ + /*16*/ 38, /* 8x96 */ 43, /* 12x64 */ 44, /* 26x26 */ 44, /* 20x36 */ /*20*/ 49, /* 16x48 */ 49, /* 8x120*/ 56, /* 20x44 */ 62, /* 32x32 */ /*24*/ 62, /* 16x64 */ 63, /* 8x144*/ 64, /* 12x88 */ 70, /* 26x40 */ /*28*/ 72, /* 22x48 */ 80, /* 24x48 */ 84, /* 20x64 */ 86, /* 36x36 */ /*32*/ 90, /* 26x48 */ 108, /* 24x64 */ 114, /* 40x40 */ 118, /* 26x64 */ /*36*/ 144, /* 44x44 */ 174, /* 48x48 */ 102, /* 52x52 */ 140, /* 64x64 */ /*40*/ 92, /* 72x72 */ 114, /* 80x80 */ 144, /* 88x88 */ 174, /* 96x96 */ - /*44*/ 136, /*104x104*/ 175, /*120x120*/ 163, /*132x132*/ 156 /* 144x144*/ + /*44*/ 136, /*104x104*/ 175, /*120x120*/ 163, /*132x132*/ 156 /* 144x144*/ }; // ECC Codewords per RS-Block @@ -241,7 +238,7 @@ static const unsigned short int matrixrsblock[] = { /*28*/ 38, /* 22x48 */ 41, /* 24x48 */ 42, /* 20x64 */ 42, /* 36x36 */ /*32*/ 42, /* 26x48 */ 46, /* 24x64 */ 48, /* 40x40 */ 50, /* 26x64 */ /*36*/ 56, /* 44x44 */ 68, /* 48x48 */ 42, /* 52x52 */ 56, /* 64x64 */ - /*40*/ 36, /* 72x72 */ 48, /* 80x80 */ 56, /* 88x88 */ 68, /* 96x96 */ + /*40*/ 36, /* 72x72 */ 48, /* 80x80 */ 56, /* 88x88 */ 68, /* 96x96 */ /*44*/ 56, /*104x104*/ 68, /*120x120*/ 62, /*132x132*/ 62 /*144x144*/ }; diff --git a/backend/emf.c b/backend/emf.c index 1c89d3f7..712fa241 100644 --- a/backend/emf.c +++ b/backend/emf.c @@ -166,7 +166,8 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { int hexagon_count, this_hexagon; int string_count, this_text; int bytecount, recordcount; - float radius; + float previous_diameter; + float radius, half_radius, half_sqrt3_radius; int colours_used = 0; int rectangle_count_bycolour[9]; unsigned char *this_string[6]; @@ -443,10 +444,14 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { } //Circles + previous_diameter = radius = 0.0f; circ = symbol->vector->circles; this_circle = 0; while (circ) { - radius = circ->diameter / 2.0; + if (previous_diameter != circ->diameter) { + previous_diameter = circ->diameter; + radius = (float) (0.5 * previous_diameter); + } circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE circle[this_circle].size = 24; circle[this_circle].box.top = circ->y - radius; @@ -460,6 +465,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { } //Hexagons + previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f; hex = symbol->vector->hexagons; this_hexagon = 0; while (hex) { @@ -467,33 +473,38 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { hexagon[this_hexagon].size = 76; hexagon[this_hexagon].count = 6; - radius = hex->diameter / 2.0; + if (previous_diameter != hex->diameter) { + previous_diameter = hex->diameter; + radius = (float) (0.5 * previous_diameter); + half_radius = (float) (0.25 * previous_diameter); + half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter); + } if ((hex->rotation == 0) || (hex->rotation == 180)) { - ay = hex->y + (1.0 * radius); - by = hex->y + (0.5 * radius); - cy = hex->y - (0.5 * radius); - dy = hex->y - (1.0 * radius); - ey = hex->y - (0.5 * radius); - fy = hex->y + (0.5 * radius); + ay = hex->y + radius; + by = hex->y + half_radius; + cy = hex->y - half_radius; + dy = hex->y - radius; + ey = hex->y - half_radius; + fy = hex->y + half_radius; ax = hex->x; - bx = hex->x + (0.86 * radius); - cx = hex->x + (0.86 * radius); + bx = hex->x + half_sqrt3_radius; + cx = hex->x + half_sqrt3_radius; dx = hex->x; - ex = hex->x - (0.86 * radius); - fx = hex->x - (0.86 * radius); + ex = hex->x - half_sqrt3_radius; + fx = hex->x - half_sqrt3_radius; } else { ay = hex->y; - by = hex->y + (0.86 * radius); - cy = hex->y + (0.86 * radius); + by = hex->y + half_sqrt3_radius; + cy = hex->y + half_sqrt3_radius; dy = hex->y; - ey = hex->y - (0.86 * radius); - fy = hex->y - (0.86 * radius); - ax = hex->x - (1.0 * radius); - bx = hex->x - (0.5 * radius); - cx = hex->x + (0.5 * radius); - dx = hex->x + (1.0 * radius); - ex = hex->x + (0.5 * radius); - fx = hex->x - (0.5 * radius); + ey = hex->y - half_sqrt3_radius; + fy = hex->y - half_sqrt3_radius; + ax = hex->x - radius; + bx = hex->x - half_radius; + cx = hex->x + half_radius; + dx = hex->x + radius; + ex = hex->x + half_radius; + fx = hex->x - half_radius; } hexagon[this_hexagon].a_points_a.x = ax; diff --git a/backend/library.c b/backend/library.c index 62513921..fd0efa4c 100644 --- a/backend/library.c +++ b/backend/library.c @@ -48,12 +48,6 @@ struct zint_symbol *ZBarcode_Create() { memset(symbol, 0, sizeof (*symbol)); symbol->symbology = BARCODE_CODE128; - symbol->height = 0; - symbol->whitespace_width = 0; - symbol->border_width = 0; - symbol->output_options = 0; - symbol->rows = 0; - symbol->width = 0; strcpy(symbol->fgcolour, "000000"); symbol->fgcolor = &symbol->fgcolour[0]; strcpy(symbol->bgcolour, "ffffff"); @@ -61,19 +55,14 @@ struct zint_symbol *ZBarcode_Create() { strcpy(symbol->outfile, "out.png"); symbol->scale = 1.0f; symbol->option_1 = -1; - symbol->option_2 = 0; - symbol->option_3 = 0; symbol->show_hrt = 1; // Show human readable text symbol->fontsize = 8; symbol->input_mode = DATA_MODE; symbol->bitmap = NULL; - symbol->bitmap_width = 0; - symbol->bitmap_height = 0; symbol->alphamap = NULL; symbol->eci = 0; // Default 0 uses ECI 3 symbol->dot_size = 4.0f / 5.0f; symbol->vector = NULL; - symbol->debug = 0; symbol->warn_level = WARN_DEFAULT; return symbol; } @@ -786,9 +775,9 @@ int ZBarcode_ValidID(int symbol_id) { return result; } -static int reduced_charset(struct zint_symbol *symbol, const unsigned char *source, size_t in_length); +static int reduced_charset(struct zint_symbol *symbol, unsigned char *source, size_t in_length); -static int extended_or_reduced_charset(struct zint_symbol *symbol, const unsigned char *source, const int length) { +static int extended_or_reduced_charset(struct zint_symbol *symbol, unsigned char *source, const int length) { int error_number = 0; switch (symbol->symbology) { @@ -812,30 +801,25 @@ static int extended_or_reduced_charset(struct zint_symbol *symbol, const unsigne return error_number; } -static int reduced_charset(struct zint_symbol *symbol, const unsigned char *source, size_t in_length) { +static int reduced_charset(struct zint_symbol *symbol, unsigned char *source, size_t in_length) { /* These are the "norm" standards which only support Latin-1 at most, though a few support ECI */ int error_number = 0; + unsigned char *preprocessed = source; #ifndef _MSC_VER - unsigned char preprocessed[in_length + 1]; + unsigned char preprocessed_buf[in_length + 1]; #else - unsigned char* preprocessed = (unsigned char*) _alloca(in_length + 1); + unsigned char *preprocessed_buf = (unsigned char *) _alloca(in_length + 1); #endif - switch (symbol->input_mode & 0x07) { - case DATA_MODE: - case GS1_MODE: - memcpy(preprocessed, source, in_length); - preprocessed[in_length] = '\0'; - break; - case UNICODE_MODE: - /* Prior check ensures ECI only set for those that support it */ - error_number = utf_to_eci(symbol->eci && symbol->eci <= 899 ? symbol->eci : 3, source, preprocessed, &in_length); - if (error_number != 0) { - strcpy(symbol->errtxt, "204: Invalid characters in input data"); - return error_number; - } - break; + if ((symbol->input_mode & 0x07) == UNICODE_MODE) { + /* Prior check ensures ECI only set for those that support it */ + preprocessed = preprocessed_buf; + error_number = utf_to_eci(symbol->eci && symbol->eci <= 899 ? symbol->eci : 3, source, preprocessed, &in_length); + if (error_number != 0) { + strcpy(symbol->errtxt, "204: Invalid characters in input data"); + return error_number; + } } if ((symbol->height == 0) && is_linear(symbol->symbology)) { @@ -1197,22 +1181,16 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - } - /* symbol->symbologys 1 to 86 are defined by tbarcode */ - if (symbol->symbology == 5) { + } else if (symbol->symbology == 5) { symbol->symbology = BARCODE_C25STANDARD; - } - if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) { + } else if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) { symbol->symbology = BARCODE_EANX; - } - if (symbol->symbology == 15) { + } else if (symbol->symbology == 15) { symbol->symbology = BARCODE_EANX; - } - if (symbol->symbology == 17) { + } else if (symbol->symbology == 17) { symbol->symbology = BARCODE_UPCA; - } - if (symbol->symbology == 19) { + } else if (symbol->symbology == 19) { strcpy(symbol->errtxt, "207: Codabar 18 not supported"); if (symbol->warn_level == WARN_FAIL_ALL) { return WARN_FAIL_ALL; @@ -1220,30 +1198,22 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODABAR; error_number = ZINT_WARN_INVALID_OPTION; } - } - if (symbol->symbology == 26) { + } else if (symbol->symbology == 26) { symbol->symbology = BARCODE_UPCA; - } - if (symbol->symbology == 27) { + } else if (symbol->symbology == 27) { strcpy(symbol->errtxt, "208: UPCD1 not supported"); error_number = ZINT_ERROR_INVALID_OPTION; - } - if (symbol->symbology == 33) { + } else if (symbol->symbology == 33) { symbol->symbology = BARCODE_GS1_128; - } - if (symbol->symbology == 36) { + } else if (symbol->symbology == 36) { symbol->symbology = BARCODE_UPCA; - } - if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) { + } else if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) { symbol->symbology = BARCODE_POSTNET; - } - if (symbol->symbology == 46) { + } else if (symbol->symbology == 46) { symbol->symbology = BARCODE_PLESSEY; - } - if (symbol->symbology == 48) { + } else if (symbol->symbology == 48) { symbol->symbology = BARCODE_NVE18; - } - if (symbol->symbology == 54) { + } else if (symbol->symbology == 54) { strcpy(symbol->errtxt, "210: General Parcel Code not supported"); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; @@ -1251,26 +1221,19 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - } - if ((symbol->symbology == 59) || (symbol->symbology == 61)) { + } else if ((symbol->symbology == 59) || (symbol->symbology == 61)) { symbol->symbology = BARCODE_CODE128; - } - if (symbol->symbology == 62) { + } else if (symbol->symbology == 62) { symbol->symbology = BARCODE_CODE93; - } - if ((symbol->symbology == 64) || (symbol->symbology == 65)) { + } else if ((symbol->symbology == 64) || (symbol->symbology == 65)) { symbol->symbology = BARCODE_AUSPOST; - } - if (symbol->symbology == 78) { + } else if (symbol->symbology == 78) { symbol->symbology = BARCODE_DBAR_OMN; - } - if (symbol->symbology == 83) { + } else if (symbol->symbology == 83) { symbol->symbology = BARCODE_PLANET; - } - if (symbol->symbology == 88) { + } else if (symbol->symbology == 88) { symbol->symbology = BARCODE_GS1_128; - } - if (symbol->symbology == 91) { + } else if (symbol->symbology == 91) { strcpy(symbol->errtxt, "212: Symbology out of range"); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; @@ -1278,8 +1241,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - } - if ((symbol->symbology >= 94) && (symbol->symbology <= 95)) { + } else if ((symbol->symbology >= 94) && (symbol->symbology <= 95)) { strcpy(symbol->errtxt, "213: Symbology out of range"); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; @@ -1287,29 +1249,21 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - } - if (symbol->symbology == 100) { + } else if (symbol->symbology == 100) { symbol->symbology = BARCODE_HIBC_128; - } - if (symbol->symbology == 101) { + } else if (symbol->symbology == 101) { symbol->symbology = BARCODE_HIBC_39; - } - if (symbol->symbology == 103) { + } else if (symbol->symbology == 103) { symbol->symbology = BARCODE_HIBC_DM; - } - if (symbol->symbology == 105) { + } else if (symbol->symbology == 105) { symbol->symbology = BARCODE_HIBC_QR; - } - if (symbol->symbology == 107) { + } else if (symbol->symbology == 107) { symbol->symbology = BARCODE_HIBC_PDF; - } - if (symbol->symbology == 109) { + } else if (symbol->symbology == 109) { symbol->symbology = BARCODE_HIBC_MICPDF; - } - if (symbol->symbology == 111) { + } else if (symbol->symbology == 111) { symbol->symbology = BARCODE_HIBC_BLOCKF; - } - if ((symbol->symbology == 113) || (symbol->symbology == 114)) { + } else if ((symbol->symbology == 113) || (symbol->symbology == 114)) { strcpy(symbol->errtxt, "214: Symbology out of range"); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; @@ -1317,11 +1271,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - } - if (symbol->symbology == 115) { + } else if (symbol->symbology == 115) { symbol->symbology = BARCODE_DOTCODE; - } - if ((symbol->symbology >= 117) && (symbol->symbology <= 127)) { + } else if ((symbol->symbology >= 117) && (symbol->symbology <= 127)) { if (symbol->symbology != 121) { strcpy(symbol->errtxt, "215: Symbology out of range"); if (symbol->warn_level == WARN_FAIL_ALL) { @@ -1331,9 +1283,8 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int error_number = ZINT_WARN_INVALID_OPTION; } } - } /* Everything from 128 up is Zint-specific */ - if (symbol->symbology > 145) { + } else if (symbol->symbology > 145) { strcpy(symbol->errtxt, "216: Symbology out of range"); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; diff --git a/backend/ps.c b/backend/ps.c index 7fe4f2f7..1246f5ae 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -139,7 +139,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { float cyan_paper, magenta_paper, yellow_paper, black_paper; int error_number = 0; float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy; - float radius; + float previous_diameter; + float radius, half_radius, half_sqrt3_radius; int colour_index, colour_rect_counter; char ps_color[30]; int draw_background = 1; @@ -180,58 +181,58 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); - red_ink = fgred / 256.0; - green_ink = fggrn / 256.0; - blue_ink = fgblu / 256.0; - red_paper = bgred / 256.0; - green_paper = bggrn / 256.0; - blue_paper = bgblu / 256.0; + red_ink = (float) (fgred / 256.0); + green_ink = (float) (fggrn / 256.0); + blue_ink = (float) (fgblu / 256.0); + red_paper = (float) (bgred / 256.0); + green_paper = (float) (bggrn / 256.0); + blue_paper = (float) (bgblu / 256.0); /* Convert RGB to CMYK */ if (red_ink > green_ink) { if (blue_ink > red_ink) { - black_ink = 1 - blue_ink; + black_ink = 1.0f - blue_ink; } else { - black_ink = 1 - red_ink; + black_ink = 1.0f - red_ink; } } else { if (blue_ink > red_ink) { - black_ink = 1 - blue_ink; + black_ink = 1.0f - blue_ink; } else { - black_ink = 1 - green_ink; + black_ink = 1.0f - green_ink; } } - if (black_ink < 1.0) { - cyan_ink = (1 - red_ink - black_ink) / (1 - black_ink); - magenta_ink = (1 - green_ink - black_ink) / (1 - black_ink); - yellow_ink = (1 - blue_ink - black_ink) / (1 - black_ink); + if (black_ink < 1.0f) { + cyan_ink = (1.0f - red_ink - black_ink) / (1.0f - black_ink); + magenta_ink = (1.0f - green_ink - black_ink) / (1.0f - black_ink); + yellow_ink = (1.0f - blue_ink - black_ink) / (1.0f - black_ink); } else { - cyan_ink = 0.0; - magenta_ink = 0.0; - yellow_ink = 0.0; + cyan_ink = 0.0f; + magenta_ink = 0.0f; + yellow_ink = 0.0f; } if (red_paper > green_paper) { if (blue_paper > red_paper) { - black_paper = 1 - blue_paper; + black_paper = 1.0f - blue_paper; } else { - black_paper = 1 - red_paper; + black_paper = 1.0f - red_paper; } } else { if (blue_paper > red_paper) { - black_paper = 1 - blue_paper; + black_paper = 1.0f - blue_paper; } else { - black_paper = 1 - green_paper; + black_paper = 1.0f - green_paper; } } - if (black_paper < 1.0) { - cyan_paper = (1 - red_paper - black_paper) / (1 - black_paper); - magenta_paper = (1 - green_paper - black_paper) / (1 - black_paper); - yellow_paper = (1 - blue_paper - black_paper) / (1 - black_paper); + if (black_paper < 1.0f) { + cyan_paper = (1.0f - red_paper - black_paper) / (1.0f - black_paper); + magenta_paper = (1.0f - green_paper - black_paper) / (1.0f - black_paper); + yellow_paper = (1.0f - blue_paper - black_paper) / (1.0f - black_paper); } else { - cyan_paper = 0.0; - magenta_paper = 0.0; - yellow_paper = 0.0; + cyan_paper = 0.0f; + magenta_paper = 0.0f; + yellow_paper = 0.0f; } for (i = 0, len = (int) ustrlen(symbol->text); i < len; i++) { @@ -329,43 +330,54 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { } // Hexagons + previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f; hex = symbol->vector->hexagons; while (hex) { - radius = hex->diameter / 2.0; + if (previous_diameter != hex->diameter) { + previous_diameter = hex->diameter; + radius = (float) (0.5 * previous_diameter); + half_radius = (float) (0.25 * previous_diameter); + half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter); + } if ((hex->rotation == 0) || (hex->rotation == 180)) { - ay = (symbol->vector->height - hex->y) + (1.0 * radius); - by = (symbol->vector->height - hex->y) + (0.5 * radius); - cy = (symbol->vector->height - hex->y) - (0.5 * radius); - dy = (symbol->vector->height - hex->y) - (1.0 * radius); - ey = (symbol->vector->height - hex->y) - (0.5 * radius); - fy = (symbol->vector->height - hex->y) + (0.5 * radius); + ay = (symbol->vector->height - hex->y) + radius; + by = (symbol->vector->height - hex->y) + half_radius; + cy = (symbol->vector->height - hex->y) - half_radius; + dy = (symbol->vector->height - hex->y) - radius; + ey = (symbol->vector->height - hex->y) - half_radius; + fy = (symbol->vector->height - hex->y) + half_radius; ax = hex->x; - bx = hex->x + (0.86 * radius); - cx = hex->x + (0.86 * radius); + bx = hex->x + half_sqrt3_radius; + cx = hex->x + half_sqrt3_radius; dx = hex->x; - ex = hex->x - (0.86 * radius); - fx = hex->x - (0.86 * radius); + ex = hex->x - half_sqrt3_radius; + fx = hex->x - half_sqrt3_radius; } else { ay = (symbol->vector->height - hex->y); - by = (symbol->vector->height - hex->y) + (0.86 * radius); - cy = (symbol->vector->height - hex->y) + (0.86 * radius); + by = (symbol->vector->height - hex->y) + half_sqrt3_radius; + cy = (symbol->vector->height - hex->y) + half_sqrt3_radius; dy = (symbol->vector->height - hex->y); - ey = (symbol->vector->height - hex->y) - (0.86 * radius); - fy = (symbol->vector->height - hex->y) - (0.86 * radius); - ax = hex->x - (1.0 * radius); - bx = hex->x - (0.5 * radius); - cx = hex->x + (0.5 * radius); - dx = hex->x + (1.0 * radius); - ex = hex->x + (0.5 * radius); - fx = hex->x - (0.5 * radius); + ey = (symbol->vector->height - hex->y) - half_sqrt3_radius; + fy = (symbol->vector->height - hex->y) - half_sqrt3_radius; + ax = hex->x - radius; + bx = hex->x - half_radius; + cx = hex->x + half_radius; + dx = hex->x + radius; + ex = hex->x + half_radius; + fx = hex->x - half_radius; } fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH\n", ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy); hex = hex->next; } // Circles + previous_diameter = radius = 0.0f; circle = symbol->vector->circles; while (circle) { + if (previous_diameter != circle->diameter) { + previous_diameter = circle->diameter; + radius = (float) (0.5 * previous_diameter); + } if (circle->colour) { // A 'white' circle if ((symbol->output_options & CMYK_COLOUR) == 0) { @@ -373,7 +385,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { } else { fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_paper, magenta_paper, yellow_paper, black_paper); } - fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), circle->diameter / 2.0); + fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), radius); if (circle->next) { if ((symbol->output_options & CMYK_COLOUR) == 0) { fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); @@ -383,7 +395,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { } } else { // A 'black' circle - fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), circle->diameter / 2.0); + fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), radius); } circle = circle->next; } diff --git a/backend/raster.c b/backend/raster.c index 34a5c889..33de24d9 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -667,28 +667,34 @@ static int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int f int r, i; int scale_width, scale_height; int error_number = 0; - int image_width, image_height; int xoffset, yoffset, roffset, boffset; - int dot_overspill = 0; + float dot_overspill; + float dotoffset; float dotradius_scaled; + int dot_overspill_scaled; + + if (scaler < 2.0f) { + scaler = 2.0f; + } symbol->height = symbol->rows; // This is true because only 2d matrix symbols are processed here output_set_whitespace_offsets(symbol, &xoffset, &yoffset, &roffset, &boffset); - dot_overspill = (int) ceil(symbol->dot_size - 1); /* Allow for exceeding 1X */ - if (dot_overspill < 0) { - dot_overspill = 0; + dot_overspill = symbol->dot_size - 1.0f; /* Allow for exceeding 1X */ + if (dot_overspill < 0.0f) { + dotoffset = -dot_overspill / 2.0f; + dot_overspill_scaled = 0; + } else { + dotoffset = 0.0f; + dot_overspill_scaled = dot_overspill * scaler; + } + if (dot_overspill_scaled == 0) { + dot_overspill_scaled = 1; } - image_width = symbol->width + dot_overspill + xoffset + roffset; - image_height = symbol->height + dot_overspill + yoffset + boffset; - - if (scaler < 2.0f) { - scaler = 2.0f; - } - scale_width = image_width * scaler; - scale_height = image_height * scaler; + scale_width = (symbol->width + xoffset + roffset) * scaler + dot_overspill_scaled; + scale_height = (symbol->height + yoffset + boffset) * scaler + dot_overspill_scaled; /* Apply scale options by creating another pixel buffer */ if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) { @@ -700,11 +706,11 @@ static int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int f /* Plot the body of the symbol to the pixel buffer */ dotradius_scaled = (symbol->dot_size * scaler) / 2.0f; for (r = 0; r < symbol->rows; r++) { - float row_scaled = (r + yoffset) * scaler + dotradius_scaled; + float row_scaled = (r + dotoffset + yoffset) * scaler + dotradius_scaled; for (i = 0; i < symbol->width; i++) { if (module_is_set(symbol, r, i)) { draw_circle(scaled_pixelbuf, scale_width, scale_height, - (i + xoffset) * scaler + dotradius_scaled, + (i + dotoffset + xoffset) * scaler + dotradius_scaled, row_scaled, dotradius_scaled, DEFAULT_INK); @@ -1178,14 +1184,12 @@ INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_ return error; } - if (symbol->output_options & BARCODE_DOTTY_MODE) { + if (symbol->symbology == BARCODE_MAXICODE) { + error = plot_raster_maxicode(symbol, rotate_angle, file_type); + } else if (symbol->output_options & BARCODE_DOTTY_MODE) { error = plot_raster_dotty(symbol, rotate_angle, file_type); } else { - if (symbol->symbology == BARCODE_MAXICODE) { - error = plot_raster_maxicode(symbol, rotate_angle, file_type); - } else { - error = plot_raster_default(symbol, rotate_angle, file_type); - } + error = plot_raster_default(symbol, rotate_angle, file_type); } return error; diff --git a/backend/svg.c b/backend/svg.c index ead5440c..45c3b27f 100644 --- a/backend/svg.c +++ b/backend/svg.c @@ -41,7 +41,7 @@ #include "common.h" -void pick_colour(int colour, char colour_code[]) { +static void pick_colour(int colour, char colour_code[]) { switch(colour) { case 1: // Cyan strcpy(colour_code, "00ffff"); @@ -119,12 +119,14 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { int error_number = 0; const char *locale = NULL; float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy; - float radius; + float previous_diameter; + float radius, half_radius, half_sqrt3_radius; int i; char fgcolour_string[7]; char bgcolour_string[7]; int bg_alpha = 0xff; int fg_alpha = 0xff; + float fg_alpha_opacity = 0.0f, bg_alpha_opacity = 0.0f; const char *font_family = "Helvetica, sans-serif"; int bold; @@ -149,9 +151,15 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { if (strlen(symbol->fgcolour) > 6) { fg_alpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]); + if (fg_alpha != 0xff) { + fg_alpha_opacity = (float) (fg_alpha / 255.0); + } } if (strlen(symbol->bgcolour) > 6) { bg_alpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]); + if (bg_alpha != 0xff) { + bg_alpha_opacity = (float) (bg_alpha / 255.0); + } } html_len = strlen((char *)symbol->text) + 1; @@ -204,7 +212,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { if (bg_alpha != 0) { fprintf(fsvg, " vector->width), (int) ceil(symbol->vector->height), bgcolour_string); if (bg_alpha != 0xff) { - fprintf(fsvg, " opacity=\"%.3f\"", (float) bg_alpha / 255.0); + fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity); } fprintf(fsvg, " />\n"); } @@ -217,63 +225,74 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { fprintf(fsvg, " fill=\"#%s\"", colour_code); } if (fg_alpha != 0xff) { - fprintf(fsvg, " opacity=\"%.3f\"", (float) fg_alpha / 255.0); + fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity); } fprintf(fsvg, " />\n"); rect = rect->next; } + previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f; hex = symbol->vector->hexagons; while (hex) { - radius = hex->diameter / 2.0; + if (previous_diameter != hex->diameter) { + previous_diameter = hex->diameter; + radius = (float) (0.5 * previous_diameter); + half_radius = (float) (0.25 * previous_diameter); + half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter); + } if ((hex->rotation == 0) || (hex->rotation == 180)) { - ay = hex->y + (1.0 * radius); - by = hex->y + (0.5 * radius); - cy = hex->y - (0.5 * radius); - dy = hex->y - (1.0 * radius); - ey = hex->y - (0.5 * radius); - fy = hex->y + (0.5 * radius); + ay = hex->y + radius; + by = hex->y + half_radius; + cy = hex->y - half_radius; + dy = hex->y - radius; + ey = hex->y - half_radius; + fy = hex->y + half_radius; ax = hex->x; - bx = hex->x + (0.86 * radius); - cx = hex->x + (0.86 * radius); + bx = hex->x + half_sqrt3_radius; + cx = hex->x + half_sqrt3_radius; dx = hex->x; - ex = hex->x - (0.86 * radius); - fx = hex->x - (0.86 * radius); + ex = hex->x - half_sqrt3_radius; + fx = hex->x - half_sqrt3_radius; } else { ay = hex->y; - by = hex->y + (0.86 * radius); - cy = hex->y + (0.86 * radius); + by = hex->y + half_sqrt3_radius; + cy = hex->y + half_sqrt3_radius; dy = hex->y; - ey = hex->y - (0.86 * radius); - fy = hex->y - (0.86 * radius); - ax = hex->x - (1.0 * radius); - bx = hex->x - (0.5 * radius); - cx = hex->x + (0.5 * radius); - dx = hex->x + (1.0 * radius); - ex = hex->x + (0.5 * radius); - fx = hex->x - (0.5 * radius); + ey = hex->y - half_sqrt3_radius; + fy = hex->y - half_sqrt3_radius; + ax = hex->x - radius; + bx = hex->x - half_radius; + cx = hex->x + half_radius; + dx = hex->x + radius; + ex = hex->x + half_radius; + fx = hex->x - half_radius; } fprintf(fsvg, " \n"); hex = hex->next; } + previous_diameter = radius = 0.0f; circle = symbol->vector->circles; while (circle) { - fprintf(fsvg, " x, circle->y, circle->diameter / 2.0); + if (previous_diameter != circle->diameter) { + previous_diameter = circle->diameter; + radius = (float) (0.5 * previous_diameter); + } + fprintf(fsvg, " x, circle->y, radius); if (circle->colour) { fprintf(fsvg, " fill=\"#%s\"", bgcolour_string); if (bg_alpha != 0xff) { // This doesn't work how the user is likely to expect - more work needed! - fprintf(fsvg, " opacity=\"%.3f\"", (float) bg_alpha / 255.0); + fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity); } } else { if (fg_alpha != 0xff) { - fprintf(fsvg, " opacity=\"%.3f\"", (float) fg_alpha / 255.0); + fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity); } } fprintf(fsvg, " />\n"); @@ -290,7 +309,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { fprintf(fsvg, " font-weight=\"bold\""); } if (fg_alpha != 0xff) { - fprintf(fsvg, " opacity=\"%.3f\"", (float) fg_alpha / 255.0); + fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity); } if (string->rotation != 0) { fprintf(fsvg, " transform=\"rotate(%d,%.2f,%.2f)\"", string->rotation, string->x, string->y); diff --git a/backend/tests/data/print/bmp/dotcode_aim_fig7.bmp b/backend/tests/data/print/bmp/dotcode_aim_fig7.bmp index 69bb9520..e7f5282d 100644 Binary files a/backend/tests/data/print/bmp/dotcode_aim_fig7.bmp and b/backend/tests/data/print/bmp/dotcode_aim_fig7.bmp differ diff --git a/backend/tests/data/print/emf/dotcode_aim_fig7.emf b/backend/tests/data/print/emf/dotcode_aim_fig7.emf index 741e222b..42b87b01 100644 Binary files a/backend/tests/data/print/emf/dotcode_aim_fig7.emf and b/backend/tests/data/print/emf/dotcode_aim_fig7.emf differ diff --git a/backend/tests/data/print/eps/dotcode_aim_fig7.eps b/backend/tests/data/print/eps/dotcode_aim_fig7.eps index 61730583..43dbc88e 100644 --- a/backend/tests/data/print/eps/dotcode_aim_fig7.eps +++ b/backend/tests/data/print/eps/dotcode_aim_fig7.eps @@ -15,42 +15,42 @@ newpath 100.00 0.00 TB 0.00 130.00 TR TE 0.00 0.00 0.00 setrgbcolor -4.00 96.00 4.00 TD -24.00 96.00 4.00 TD -64.00 96.00 4.00 TD -84.00 96.00 4.00 TD -104.00 96.00 4.00 TD -124.00 96.00 4.00 TD -34.00 86.00 4.00 TD -4.00 76.00 4.00 TD -44.00 76.00 4.00 TD -84.00 76.00 4.00 TD -104.00 76.00 4.00 TD -124.00 76.00 4.00 TD -14.00 66.00 4.00 TD -74.00 66.00 4.00 TD -94.00 66.00 4.00 TD -44.00 56.00 4.00 TD -64.00 56.00 4.00 TD -104.00 56.00 4.00 TD -14.00 46.00 4.00 TD -54.00 46.00 4.00 TD -114.00 46.00 4.00 TD -4.00 36.00 4.00 TD -44.00 36.00 4.00 TD -64.00 36.00 4.00 TD -84.00 36.00 4.00 TD -124.00 36.00 4.00 TD -14.00 26.00 4.00 TD -34.00 26.00 4.00 TD -54.00 26.00 4.00 TD -94.00 26.00 4.00 TD -4.00 16.00 4.00 TD -44.00 16.00 4.00 TD -84.00 16.00 4.00 TD -104.00 16.00 4.00 TD -124.00 16.00 4.00 TD -14.00 6.00 4.00 TD -34.00 6.00 4.00 TD -74.00 6.00 4.00 TD -114.00 6.00 4.00 TD +5.00 95.00 4.00 TD +25.00 95.00 4.00 TD +65.00 95.00 4.00 TD +85.00 95.00 4.00 TD +105.00 95.00 4.00 TD +125.00 95.00 4.00 TD +35.00 85.00 4.00 TD +5.00 75.00 4.00 TD +45.00 75.00 4.00 TD +85.00 75.00 4.00 TD +105.00 75.00 4.00 TD +125.00 75.00 4.00 TD +15.00 65.00 4.00 TD +75.00 65.00 4.00 TD +95.00 65.00 4.00 TD +45.00 55.00 4.00 TD +65.00 55.00 4.00 TD +105.00 55.00 4.00 TD +15.00 45.00 4.00 TD +55.00 45.00 4.00 TD +115.00 45.00 4.00 TD +5.00 35.00 4.00 TD +45.00 35.00 4.00 TD +65.00 35.00 4.00 TD +85.00 35.00 4.00 TD +125.00 35.00 4.00 TD +15.00 25.00 4.00 TD +35.00 25.00 4.00 TD +55.00 25.00 4.00 TD +95.00 25.00 4.00 TD +5.00 15.00 4.00 TD +45.00 15.00 4.00 TD +85.00 15.00 4.00 TD +105.00 15.00 4.00 TD +125.00 15.00 4.00 TD +15.00 5.00 4.00 TD +35.00 5.00 4.00 TD +75.00 5.00 4.00 TD +115.00 5.00 4.00 TD diff --git a/backend/tests/data/print/gif/dotcode_aim_fig7.gif b/backend/tests/data/print/gif/dotcode_aim_fig7.gif index e82f1425..41f53d10 100644 Binary files a/backend/tests/data/print/gif/dotcode_aim_fig7.gif and b/backend/tests/data/print/gif/dotcode_aim_fig7.gif differ diff --git a/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx b/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx index 7b6bf7b8..484311a1 100644 Binary files a/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx and b/backend/tests/data/print/pcx/dotcode_aim_fig7.pcx differ diff --git a/backend/tests/data/print/png/dotcode_aim_fig7.png b/backend/tests/data/print/png/dotcode_aim_fig7.png index 3a38e294..d3053123 100644 Binary files a/backend/tests/data/print/png/dotcode_aim_fig7.png and b/backend/tests/data/print/png/dotcode_aim_fig7.png differ diff --git a/backend/tests/data/print/svg/dotcode_aim_fig7.svg b/backend/tests/data/print/svg/dotcode_aim_fig7.svg index 7966d67c..228f4396 100644 --- a/backend/tests/data/print/svg/dotcode_aim_fig7.svg +++ b/backend/tests/data/print/svg/dotcode_aim_fig7.svg @@ -8,44 +8,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/tests/data/print/tif/dotcode_aim_fig7.tif b/backend/tests/data/print/tif/dotcode_aim_fig7.tif index 74f4dcc2..a668466e 100644 Binary files a/backend/tests/data/print/tif/dotcode_aim_fig7.tif and b/backend/tests/data/print/tif/dotcode_aim_fig7.tif differ diff --git a/backend/tests/test_2of5.c b/backend/tests/test_2of5.c index 8174a101..433bbdec 100644 --- a/backend/tests/test_2of5.c +++ b/backend/tests/test_2of5.c @@ -282,7 +282,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_auspost.c b/backend/tests/test_auspost.c index d2298893..1025322f 100644 --- a/backend/tests/test_auspost.c +++ b/backend/tests/test_auspost.c @@ -282,7 +282,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_aztec.c b/backend/tests/test_aztec.c index 073b7fb1..ab69ef15 100644 --- a/backend/tests/test_aztec.c +++ b/backend/tests/test_aztec.c @@ -31,7 +31,7 @@ #include "testcommon.h" -static void test_encode(int index, int generate, int debug) { +static void test_options(int index, int debug) { testStart(""); @@ -39,6 +39,7 @@ static void test_encode(int index, int generate, int debug) { struct item { int symbology; int input_mode; + int output_options; int option_1; int option_2; char *data; @@ -46,11 +47,67 @@ static void test_encode(int index, int generate, int debug) { int expected_rows; int expected_width; + }; + // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) + struct item data[] = { + /* 0*/ { BARCODE_AZTEC, -1, -1, -1, -1, "1234567890", 0, 15, 15 }, + /* 1*/ { BARCODE_AZTEC, -1, -1, 4, -1, "1234567890", 0, 19, 19 }, + /* 2*/ { BARCODE_AZTEC, -1, -1, 5, -1, "1234567890", ZINT_WARN_INVALID_OPTION, 15, 15 }, + /* 3*/ { BARCODE_AZTEC, -1, -1, -1, 36, "1234567890", 0, 151, 151 }, + /* 4*/ { BARCODE_AZTEC, -1, -1, -1, 37, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1 }, + /* 5*/ { BARCODE_AZTEC, GS1_MODE, READER_INIT, -1, -1, "[91]A", ZINT_ERROR_INVALID_OPTION, -1, -1 }, + }; + int data_size = ARRAY_SIZE(data); + + for (int i = 0; i < data_size; i++) { + + if (index != -1 && i != index) continue; + + struct zint_symbol *symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); + + 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); + + if (ret < ZINT_ERROR) { + assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, symbol->errtxt); + assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, symbol->errtxt); + } + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +static void test_encode(int index, int generate, int debug) { + + testStart(""); + + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + + int ret; + struct item { + int symbology; + int input_mode; + int eci; + int output_options; + int option_1; + int option_2; + char *data; + int length; + int ret; + + int expected_rows; + int expected_width; + int bwipp_cmp; char *comment; char *expected; }; struct item data[] = { - /* 0*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, "123456789012", 0, 15, 15, "ISO/IEC 24778:2008 Figure 1 (left)", + /* 0*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "123456789012", -1, 0, 15, 15, 1, "ISO/IEC 24778:2008 Figure 1 (left)", "000111000011100" "110111001110010" "111100001000100" @@ -67,7 +124,7 @@ static void test_encode(int index, int generate, int debug) { "101011110101010" "100010001000101" }, - /* 1*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, "Aztec Code is a public domain 2D matrix barcode symbology of nominally square symbols built on a square grid with a distinctive square bullseye pattern at their center.", 0, 41, 41, "ISO/IEC 24778:2008 Figure 1 (right) NOTE: Not the same but down to single encoding mode difference (UPPER space rather than LOWER space after 2D)", + /* 1*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "Aztec Code is a public domain 2D matrix barcode symbology of nominally square symbols built on a square grid with a distinctive square bullseye pattern at their center.", -1, 0, 41, 41, 0, "ISO/IEC 24778:2008 Figure 1 (right) NOTE: Not the same but down to single encoding mode difference (UPPER space rather than LOWER space after 2D); BWIPP same encodation as figure", "00001100110010010010111000010100001011000" "01000110010110110001000000100101101000001" "01011100101011001110101100000001100011001" @@ -110,7 +167,7 @@ static void test_encode(int index, int generate, int debug) { "00010010010011001011011010000110001000101" "10001000001010100110100000001001001110000" }, - /* 2*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, "Code 2D!", 0, 15, 15, "ISO/IEC 24778:2008 Figure G.2", + /* 2*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "Code 2D!", -1, 0, 15, 15, 1, "ISO/IEC 24778:2008 Figure G.2", "000110001100000" "000000110000010" "101100001000101" @@ -127,7 +184,7 @@ static void test_encode(int index, int generate, int debug) { "011000011011010" "111001101100000" }, - /* 3*/ { BARCODE_AZTEC, UNICODE_MODE, -1, 1, "Code 2D!", 0, 15, 15, "ISO/IEC 24778:2008 Figure G.2; specify size", + /* 3*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, -1, 1, "Code 2D!", -1, 0, 15, 15, 1, "ISO/IEC 24778:2008 Figure G.2; specify size", "000110001100000" "000000110000010" "101100001000101" @@ -144,7 +201,7 @@ static void test_encode(int index, int generate, int debug) { "011000011011010" "111001101100000" }, - /* 4*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", 0, 53, 53, "**NOT SAME** ISO/IEC 24778:2008 Figure I.1 (left) TODO: investigate", + /* 4*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\015\012", -1, 0, 53, 53, 0, "ISO/IEC 24778:2008 Figure I.1 (left) (note CRLF at end!), same; BWIPP different encodation (doesn't use P/S CRLF)", "00010101011010101010101010110101010101010110101010101" "00101010100101010101010101001010101010101001010101010" "11100101011010101010101010110101010101010110101010110" @@ -156,37 +213,37 @@ static void test_encode(int index, int generate, int debug) { "10101010101010101010101010110101010101010110110101010" "01010101010101010101010101001010101010101001001010101" "10101010101010101010101010101010101010101010101010101" - "10101010100101111100100010001100110110010001010101010" - "01010101011011100000011011111100100111010010101010101" - "10101010100101000000011011011101100100000101010101010" - "01010101011010110110100001100000100100100010101010101" - "10101010100111101100101000001111010001001001010101010" - "01010101011110000110010111110110001101010010101010101" - "10101010100111001001110011011111100001000101010101010" - "01010101011110101000100001101101111001000010101010101" - "10101010100010011011101000000010011011000101010101010" - "01010101011010000001111111111111110100110110101010101" - "10101010100110000001100000000000110000010001010101010" - "01010101011000001000101111111110100001100110101010101" - "10101010100011000011101000000010101100001001010101010" - "01010101011101111101101011111010101000011010101010101" - "10101010100001100111101010001010101010110001010101010" + "10101010100101010100000010000100011110011001010101010" + "01010101011010010011110110111000110101111010101010101" + "10101010100100011100001111011001101011001101010101010" + "01010101011011001111111011100110111001001010101010101" + "10101010100101001000001100001111011001011101010101010" + "01010101011001100000011100110001110001100010101010101" + "10101010100001100100101000011101101100111001010101010" + "01010101011001000110001101100101011101111110101010101" + "10101010100101001101101000000010011100011001010101010" + "01010101011111010101111111111111110111010110101010101" + "10101010100110110101100000000000111000100001010101010" + "01010101011110111010101111111110101101000110101010101" + "10101010100010011000101000000010100100000101010101010" + "01010101011111010010101011111010101011110010101010101" + "10101010100000010001101010001010101011010001010101010" "10101010101010101010101010101010101010101010101010101" - "01010101010001101100101010001010100110010100101010101" - "10101010101101100011101011111010110001100011010101010" - "01010101010010110110101000000010100110110100101010101" - "10101010101111000100101111111110111110000011010101010" - "01010101010110011110100000000000110001100000101010101" - "10101010101011001000111111111111110100001111010101010" - "01010101010011101000001000001111000110001100101010101" - "10101010101001010100110111101001011010101111010101010" - "01010101010010100011010011000101101111011000101010101" - "10101010101111000100000111111101101110111111010101010" - "01010101010110100110110110000011100010000000101010101" - "10101010101101110111010001101100001000011111010101010" - "01010101010110001101001100010100101010110000101010101" - "10101010101000101001111010110101100111100111010101010" - "01010101010010010000111100011100110101100000101010101" + "01010101010101000111101010001010111100101100101010101" + "10101010101111111001101011111010111101000011010101010" + "01010101010110010001101000000010111100111100101010101" + "10101010101011010100101111111110101010010011010101010" + "01010101010000101110100000000000101111001000101010101" + "10101010101001000000111111111111111110110111010101010" + "01010101010101101100010110000110000111110100101010101" + "10101010101101110101011101100001010010100111010101010" + "01010101010000111001101101011011011010111000101010101" + "10101010101001011011011100100001001001001011010101010" + "01010101010001110110101010000110111100000000101010101" + "10101010101000001110110100101011000011001111010101010" + "01010101010001110010110111010101111111101100101010101" + "10101010101100100010010111110110111100001111010101010" + "01010101010000011101010001000010011111011100101010101" "10101010101010101010101010101010101010101010101010101" "10101010010010101010101010010101010101010101010101010" "01010101101101010101010101101010101010101010101010101" @@ -199,7 +256,7 @@ static void test_encode(int index, int generate, int debug) { "01010101010010101010101010010101010101010100101010110" "10101010101101010101010101101010101010101011010101001" }, - /* 5*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", 0, 53, 53, "**NOT SAME** ISO/IEC 24778:2008 Figure I.1 (right) TODO: investigate", + /* 5*/ { BARCODE_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\015\012", -1, 0, 53, 53, 0, "ISO/IEC 24778:2008 Figure I.1 (right) (CRLF at end), same; BWIPP different encodation (doesn't use P/S CRLF)", "00111111111111111111111111111111111111111111111111111" "00000000000000000000000000000000000000000000000000000" "11101111111111111111111111111111111111111111111111101" @@ -211,37 +268,37 @@ static void test_encode(int index, int generate, int debug) { "10101010101111111111111111111111111111111111101010101" "10101010100000000000000000000000000000000000001010101" "10101010101010101010101010101010101010101010101010101" - "10101010100100010001110111001110000101000000101010101" - "10101010101101011100101111110011101011101010101010101" - "10101010100100111100011011000001110011010000101010101" - "10101010101100110110001101111010001010101010101010101" - "10101010100110111110011111000100011001111100101010101" - "10101010101110110100111001111011110011111110101010101" - "10101010100110011110100000010101000011010000101010101" - "10101010101011001010101110101110001010011110101010101" - "10101010100110010101101000000010010101100000101010101" - "10101010101101111111111111111111111010111110101010101" - "10101010100111110111100000000000110001101000101010101" - "10101010101101101100101111111110100000000110101010101" - "10101010100101100001101000000010101110011000101010101" - "10101010101100110101101011111010101001000010101010101" - "10101010100001100111101010001010101100100000101010101" + "10101010100100101111110001000100101100100000101010101" + "10101010101101111101110010111000101000111010101010101" + "10101010100101100101101111010110010110001000101010101" + "10101010101101110110011100100101011101001110101010101" + "10101010100100101010001101001001101000011100101010101" + "10101010101000101001010110111111111000100110101010101" + "10101010100000101001101101000111100001001100101010101" + "10101010101001011101100000110001101011000010101010101" + "10101010100100000111101000000010010100011100101010101" + "10101010101111001011111111111111111011111110101010101" + "10101010100110110111100000000000111101001100101010101" + "10101010101111001010101111111110100000100110101010101" + "10101010100001001000101000000010101010000000101010101" + "10101010101100110010101011111010100101111110101010101" + "10101010100010111111101010001010100001100000101010101" "10101010101010101010101010101010101010101010101010101" - "10101010100000111110101010001010100010011000101010101" - "10101010101011011101101011111010111011110110101010101" - "10101010100100010000101000000010101001010000101010101" - "10101010101011010100101111111110110110000010101010101" - "10101010100011111000100000000000110110101000101010101" - "10101010101101000110111111111111111100100010101010101" - "10101010100100100000001000001111000100010100101010101" - "10101010101000111110011001100110101101100110101010101" - "10101010100101100010110011011100001010110100101010101" - "10101010101101111011000111100110101010011110101010101" - "10101010100001101011111001001000010001001000101010101" - "10101010101010100111010011111110000111100010101010101" - "10101010100000001011111101010011011010000000101010101" - "10101010101100100000011011100010000000101010101010101" - "10101010100001101101001111001100000001000100101010101" + "10101010100111000101101010001010111101001100101010101" + "10101010101001000011101011111010110001011010101010101" + "10101010100111011011101000000010111000000100101010101" + "10101010101011100110101111111110100100011110101010101" + "10101010100001010110100000000000100011100100101010101" + "10101010101110101100111111111111110011110010101010101" + "10101010100100000010010110000110000110001100101010101" + "10101010101110101100110100111110100111001110101010101" + "10101010100100011000111110000001100011101000101010101" + "10101010101010100111001011111011100101111110101010101" + "10101010100011101001111001000100101000111100101010101" + "10101010101101100101110101110101101010110010101010101" + "10101010100101000101110100010000011101011100101010101" + "10101010101000110100111011110110000101000010101010101" + "10101010100101010001100000001011100001110000101010101" "10101010101010101010101010101010101010101010101010101" "10101010000000000000000000000000000000000000101010101" "10101010111111111111111111111111111111111110101010101" @@ -254,7 +311,7 @@ static void test_encode(int index, int generate, int debug) { "00000000000000000000000000000000000000000000000000001" "11111111111111111111111111111111111111111111111111101" }, - /* 6*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, "[01]03453120000011[17]120508[10]ABCD1234[410]9501101020917", 0, 23, 23, "#189 Follow embedded FLG(n) with FLG(0)", + /* 6*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, -1, -1, "[01]03453120000011[17]120508[10]ABCD1234[410]9501101020917", -1, 0, 23, 23, 1, "#189 Follow embedded FLG(n) with FLG(0)", "00100000101111000100100" "00011101100110001010000" "00000111000111101011011" @@ -279,7 +336,7 @@ static void test_encode(int index, int generate, int debug) { "00010001010101010101011" "11101100000000000010110" }, - /* 7*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, "[01]95012345678903[3103]000123", 0, 19, 19, "#189 Follow embedded FLG(n) with FLG(0)", + /* 7*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, -1, -1, "[01]95012345678903[3103]000123", -1, 0, 19, 19, 1, "#189 Follow embedded FLG(n) with FLG(0)", "0000000100001010101" "0001101111011000000" "0111100100010110100" @@ -300,7 +357,7 @@ static void test_encode(int index, int generate, int debug) { "1000110111011000101" "1010100000101101001" }, - /* 8*/ { BARCODE_AZTEC, GS1_MODE, -1, -1, "[01]04610044273252[21]LRFX)k\\R06\\G+/ACMRN123456/V2009121908334\\R\\E", -1, 0, 23, 23, 0, "HIBC/PAS Section 2.2 Patient Id Macro **NOT SAME** different encodation, Zint 1 codeword longer; BWIPP same as figure", + "11010110110000110111011" + "10111111001000110100000" + "11000001011011010011010" + "11001101001101000001100" + "10101000100101011100111" + "11000010111111111010111" + "01101111100111001101011" + "10101011111111111011111" + "11110111000000011110001" + "10000001011111011111110" + "11111001010001010111101" + "00011001010101010001001" + "11000111010001011011111" + "11000111011111010100100" + "11110101000000011010001" + "10100001111111111001000" + "11111000111101100110101" + "01001101000000011001000" + "10100101111001101010001" + "01001111101010100001111" + "01110000011111101011111" + "11110110111110011000100" + "10110000010101011110010" + }, + /* 12*/ { BARCODE_HIBC_AZTEC, UNICODE_MODE, -1, -1, 3, -1, "/EO523201", -1, 0, 19, 19, 1, "HIBC/PAS Section 2.2 Purchase Order, same", + "0011100011001101111" + "0010011001010110110" + "0110100100101000000" + "1001111000110011001" + "0011110100101011001" + "0001111111111110101" + "0001010000000100100" + "0001010111110101000" + "1000010100010100011" + "1001010101010111001" + "0000010100010110100" + "0111010111110111101" + "1000110000000101001" + "1001011111111111010" + "0010000000111001101" + "0110010000010110011" + "1110001000101101001" + "0111011100001111101" + "1010000000101001001" + }, + /* 13*/ { BARCODE_HIBC_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "/KN12345", -1, 0, 19, 19, 1, "HIBC/PAS Section 2.2 Asset Tag, same", + "0011111101100100110" + "0010011100111110101" + "0111110010101101110" + "1000010111011000001" + "0001110100101010001" + "0010111111111110110" + "0001110000000111110" + "0000010111110110011" + "1010010100010100000" + "1011010101010100101" + "0010010100010100100" + "1101110111110110110" + "0011110000000110110" + "0100011111111110100" + "1110000011111000011" + "1100001111010010010" + "1100001101001110001" + "0010000010110001111" + "1001101110111100011" + }, + /* 14*/ { BARCODE_HIBC_AZTEC, UNICODE_MODE, -1, -1, -1, -1, "A123ABCDEFGHI1234567891/$$420020216LOT123456789012345/SXYZ456789012345678/16D20130202", -1, 0, 27, 27, 1, "IDAutomation example, same", + "001010100100100010000010110" + "000110110110001000101000100" + "010010001101110110001000110" + "000110101101000001010111100" + "000101110011011000111100000" + "000100110000110111011011010" + "011100000100000111111000001" + "011101111110011100111011100" + "110001001111110110101101100" + "100100001111111111100110000" + "001000101100000001011001101" + "111011010101111101111010001" + "010010101101000101001101100" + "001000110101010101010011100" + "011011001101000101010011111" + "011111010101111101000100100" + "110000011100000001001111011" + "101110110111111111111001001" + "001110110000000110000001101" + "010010001010001000001011001" + "000100111010110100000100110" + "000010100010001000000111001" + "111100011100100010001100100" + "001110101000001010011010101" + "100001000110111011000010111" + "011010111000111110011011110" + "000010010001000011010000001" + }, + /* 15*/ { BARCODE_AZTEC, DATA_MODE, -1, -1, -1, -1, "\377\000\000\377\300\000\017\377\376\217\300\017", 12, 0, 19, 19, 1, "6 bit words", + "1101000001111000001" + "1101011000011100000" + "1000001010001001001" + "0110011100001000011" + "1001110101001011011" + "0111111111111110100" + "1111010000000110101" + "1110110111110100001" + "1010010100010101001" + "1110010101010111111" + "0001110100010101011" + "0000010111110101101" + "0011010000000110011" + "0011011111111110011" + "0110000011010001001" + "0010101001100111111" + "0001000100011100011" + "1011110000001001011" + "0011111100000000010" + }, + /* 16*/ { BARCODE_AZTEC, DATA_MODE, -1, -1, -1, 3, "\377\377\377\377\377\000\000\000\000\377\377\377\000\000\377\377\377\377\000\000\000\000\000", 23, 0, 23, 23, 1, "8 bit words", + "11111111111111111100000" + "11011101110111011110001" + "11110110111011010101100" + "01111000111100011111100" + "11000101111110011010100" + "11001111001011001100000" + "11000111100110101001011" + "10001111111111111100111" + "11000111000000011111011" + "11010111011111010001101" + "11000011010001011010111" + "10000101010101011000011" + "11001011010001010001011" + "11011011011111011101001" + "11001111000000011010011" + "10001001111111111111011" + "11001100000000000000111" + "11011011001100000010011" + "11000011001011110101011" + "10001000111111011110000" + "11000000001110101011000" + "11011100001000100010010" + "11111110000000000000000" + }, + /* 17*/ { BARCODE_AZTEC, DATA_MODE, -1, -1, -1, 13, "\000\000\000\377\377\000\000\000\000\377\377\377\377\000\377\377\377\377\000\000\377\000\000", 23, 0, 53, 53, 1, "10 bit words", + "00011010011110010011110101110010000000111111010101001" + "00000010100101010010001000010100000010101101001111110" + "11101010001110100001111100110101111010110110110001010" + "11000010110001100001000100010011110110001001110110011" + "11101001111011111001010000100101101011101010101000100" + "01110000100100011010101111011100111000100001000011011" + "11001000001101011010001111100001101111000011010001110" + "00001110000100111010100000000110101111011101001101001" + "00101001111001011001001000110011011001110011110010111" + "00001110100001001111111111001011001010001101001101111" + "10101010101010101010101010101010101010101010101010101" + "00010011000110111100001100011010011010101101000001000" + "01110111011000100011111111111111010100110010010100110" + "00011101100100100001111111000100111100010101101010011" + "00010100011010010011101101101001100101111110110010011" + "00110110000001100111111101001111100011110101011110000" + "00111110111111001011010000100001100001101010001101110" + "01010011000110100110101111000100000010000000000111110" + "00011001011011101101110111100010000100010011111011110" + "00011010000111001001101000000000010100110001000111010" + "00000100001011100111111111111111111000010010001010101" + "11110000100101010111100000000000100000101101001011100" + "11100011101111001100101111111110111111010110000001111" + "11000000010100001101101000000010100100010000101010110" + "11011000001010101011101011111010110100101011100111110" + "11101111100010111000101010001010101011011001010101001" + "10101010101010101010101010101010101010101010101010101" + "11000100000110100000101010001010101100101000011000011" + "10110100011010000110101011111010100100100111000101100" + "11000001010101000101101000000010111010100100000101001" + "10110111011110011110101111111110110011001110000001100" + "00000111100110110001100000000000111000101101111011111" + "00100101001001100110111111111111110110100111011101000" + "00001100110000110010001101011000001100110001110010010" + "00001010111110011011011100110001001110011110100100100" + "00111111000010000111110111010111101010101101000100010" + "00110100101110101000101110100101010110101111001010100" + "00100100000010111111001101001100000011110001111100101" + "01011111101101001110100101101000000111101110110111001" + "00001111000100101010011111001100011101011100010011010" + "00001011111001000011100001100001000001111011010101111" + "00000101010011100101010000010010000010011001111101011" + "10101010101010101010101010101010101010101010101010101" + "00000011000011110011111000001000000110011100110110010" + "01100110111101101010001110101001111111000111011110000" + "00010110000111101110001011011110001100100100000001000" + "00110110011101001010011110111110111101010110001011100" + "00100010010011101001001010000101011011011101011100010" + "01101001101111101010010000110100110011000111011010000" + "11110001000011110111001100010011011001010001110101000" + "11011000101001001101101111100111101001010110111011100" + "11101111010111010000111101011101111011000000001011100" + "11111111111111110000111111111111111111100010000011111" + }, + /* 18*/ { BARCODE_AZTEC, DATA_MODE, -1, -1, -1, 27, "\377\377\377\000\000\377\377\377\377\000\000\000\000\377\000\000\000\000\377\377\000\377\377\377\000\000\000", 27, 0, 113, 113, 1, "12 bit words", + "11111010101001000010110010110110001010111011100001100010111010111011011110010101111001111110001101011111100000011" + "11111001010001010111110100101000101000010110010011001000011010011001111000010101011110010001110101100110011001100" + "11101100111000011000000011000001001001111001111110000001110100001110010010001100100011101110000011010101101011011" + "10110010001100011001110101101111111010100000010000011010011100111110010000000111011110010111110001010010000011001" + "11101111110100000110110011100000101100011010001010011100110001010111001110011001100010101101000101001000110110110" + "11000001000111110000011001001100110001010000000001010111000100101100100000011011001001000111011001101101001111101" + "11011101101011110011011110111101101101001100010010101010100001111111100110011101010100011100110111111101101100000" + "11011110000101110011110000101111100111100101011010100010011000011100010001111000100110100101011011001101011001101" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "11101110000011011000110000100100010110100010110101111111000011111011010101010011000101000110111111111011001101111" + "11010011100011001101011011110000010100011001100100111111111110001010111110000000001111001110000001111011110100101" + "11110101011101110000011001000111000101000011000110111011000110110011100100000111101100000011000100001010011111001" + "10111001111000101000101111110101001000001000001100011100111001011010001110110000101011001001111001100011101001010" + "11101000001010100010000000100110101011010100010000110101010111111011000101110100001101110110010101010101011010000" + "11101110101000010010010111101100100110111000111001011010110110010001111010010011011100001001011101110010110111111" + "11101110001111110110010000110111101100010000111100110111000110111101101001111001101010010100011010001001001110001" + "11111000100110000011010110111010101001001011001101111000110110001011000110100000100100001111000000000100101010001" + "11001110001110100010000001100110100001100010001110001011000100111100111101100000011101000001010110101111010011001" + "10100001101001100010010010110010111001101000010101110110111010000111100110000001110111111000110001000110100100101" + "00111101011000111111010101011111111011000000001110101111011101110111100100011111001100110000110000011001010001100" + "00000011111100000101111110100000010010101000000011011011111110011000100010011000010100011001010101001000101100001" + "00000010011110111000110101001101011101010011011111011111010110100000111000100001110010110001110111110101001100011" + "00100101101010111011111011011011100110011100100111100111101011010011100010100110101011001111111010100111111011111" + "00100001011101110100100001001101011101010111100001000100001000110111111100010011110001010000100001110001000001111" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "01101111010111101011110101110001010000100011000111100011010110111101011101000001001011110111110101100000001010101" + "00011110100001100110001010110011001011011110110110110000101100100110100110001111111011111111010100111000101101111" + "00001100001111101101101000011101111101100100001011000001001000010111101100100011101101110001010010111001001111111" + "01001010110111011110001110101011101100111110100101100000101001111101010011001111110101011110101011100001100010001" + "11111110010100000110111001001010100011010100110101011101001000111010100100010011011111000100001100000000001100100" + "11101010100001010011100010010010100010001000001000110000110110000100011110001101001101111111110011001010101101110" + "11010001000111100010100000111000011111000110011101100001001011010110111001101011111100000000000001010011010111010" + "11001011110110001001101111000111101010011100001011011001101010000000110111111011100011111010100100001110100001001" + "11110111010110000000011100111110101000110110101110001000011011111010001001111000110010110011110110010110001100101" + "11011000101011000111010111110110101000001010001011111000101010110010110011000100100101001100010110100001111111110" + "11001100010000000000101100001110011101100111100110101110000100101010111000100001001000000001011111100100011111011" + "11001000101100010101000010000100110001001101101110100100100111110111011011010111100011101011001001100001110010110" + "10000100001000101100011001011111100110010111111111011011000011011110001100001000101110100100001010010000000001110" + "11001001100000100110010111011101111010111011110011100110110011110110111011011101000001111001100111111100110110010" + "11110100010011101010111101111011100100010001110000100010010100011110001101101100000110100110001010001100000110110" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "11101010011001111101000001000100111100010111100110100011011111100010100100100100101000000000011110011010011111100" + "11011000110000000101010110110011111000111110100100000011100111011010110111101010110000001011111100010110111101101" + "11100100001010010001100001001100000011100000110001000110011110100000001101000000101000000000111111011111001011111" + "10110100101101001001110110110000100011111101000011110010101110001111001010010110100100001001111111101000111111111" + "11110111000000010110101000100110010010110011111011100001001001101110111101001101111001100101111010110110010010110" + "10101010111100101100111010010101101111001101011101100110101000101011110011001001011001011010000111100110110001100" + "00011000010111101000001001100001101110000101000100001100011010111000100100011111001101110010101010100011011000000" + "00000001111010100010111111010011001010011100111010010001110001111100000111000100011011101000011111000011101011111" + "00101011000110101001011000111011011001010100111101110110000000010011101100100011101001110111001101011110000000011" + "00010000101001010000110011111001001110111111011011111111111111110010110110011111010101101110111011111001111001100" + "00000011011110011110000101111111101001000011011010100000000000100100010101010110111110100000000101100011011100101" + "00010111100101101100111111000001100010011011011010101111111110110110100011001010000100111001100001101001100100010" + "00001011011111110001111001100001000111000000010011101000000010100011100100001110000011000100111111010001011011001" + "00110000100100110001100110101011100110111011100001101011111010101111100110111011010000111011011001001110110100001" + "00011001010000110100101000001000011000110011111011101010001010111010101001111011110010000111010001110101011110010" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "01100111001110010110110100001110110000000110011110101010001010110000011001000001000101100010011011100101000111001" + "00101001100010010001111010100101101110111011101000101011111010100001011110110000010010101100110011011010111001101" + "00000100001011011100011101111011101110110010010100101000000010111010010100110110101110110000100010101100001011011" + "00110010111110000001110111010110010101101101000000101111111110111000110111100000001111001011010001000110101010110" + "00100101010110001001011100111010111001110110111111100000000000110010011000111011101110000010100011011001000001001" + "00000000111101111101111110111000101000011111000100111111111111110100010011100110010001101011001100111011110101110" + "01011111001111001111101001100010110011000001010110011110010001000110101001101111110100000000111100001101010010000" + "01110001111101111010111011100110010011101111011111100000100101001111010111111101100111001100101001111000100011011" + "11101100000100010100011100001011011101010101101101001010000101001111100101101100001100110101001010100000010000011" + "11001111110100111000110111111000110001001111110000010111101010000000010011100111010011111000101111100000101111101" + "11111011011110101010100101110100001011110000000000010001011011001111000101010000001100000111100001100110001100101" + "10001111111110011011110011111110001110011000010011101000101000011100111010000101111110001110011110001101100001101" + "00001100001010000010100001011101011100110010110010001000010010011101011001110011011001110001100111101110001001001" + "00100110110000000101000010110101010001001110101110000010110110101111001010011011110111101011101010011000110010000" + "00011111000011010010101000010001110010100110101010010101000010101111100100010010111010110000010011111100011000100" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "00100110010000010110110100011110100001000011011000110110001011000011011101101011101010100101110110101111010010101" + "00001100100010111111111011011000100110101110110010000111100110001100111110001110101100101100001011001101100100100" + "00000100000110001111010000100000100011010000011111111010011011110000111000011110001000010101100001100001010010110" + "01010011111111111100001010101100001010111101001111100010111110010000101010100000011100101001110011011110101011101" + "00100110001010001111011101101111100000000000001101010011010111010100100000010011101011100101111001111101011100101" + "00111011100011001100100011001110001011111010000101101001100110001110111010111110000101111100011110010110101110100" + "00011000001101000110001001000010010101010111011101100101010000000101100000010001111001010101100101100011001000110" + "00101001111001011010110111010101001010101111111011010111100111001100010010010001101010111000100111000110111101110" + "00001000011101110110110101111110100010100100011110000111010100000100010100101111010101110101001111000101001110010" + "01010111110111001101011110101101001110001011010011011111100000100011101010101110111101001111110001100010111001011" + "00000111000100111011101101010100001100100110010110010010011000111000010000011100000110100010000100001011011011010" + "00001101101110011111110010000111100110111100101011011110111111010101111111000000111110011011110000010111101100000" + "00010010001110011111110101110000001100010001111001101111000000101000000001010001100111100001101100010010010111110" + "01110011101110110110110011011101110100001010010110100110110011101011100011001111011110111110101111011101110010001" + "11111010000100110111101100110110111010110011110111110010000010011000011101111101001101100100111000110001011110001" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "11010010010101011110111001111011101100010101010111000000011011011111101100010000000100000011100111000011010101101" + "11001111111111001010101010000001010001011100101100110110100110111010101011101111100100011011100110110101101010011" + "11110011000011100100010001101001000101000010111111010101001110110000010000000001000101010101100111010110011101100" + "11100101100001000110100111011001011000001100010001100110101111110110101111100101010001001100110011010101101001110" + "11111001000100001001110100011001001110010011001100000000011111000110010000010100001011010010100010111111000100001" + "11001100111001110001010011110110011110101010100001111011111010111011011011010010110010101000001111000100111100110" + "10010100001100111111100101101000111001110111010011011110000000110111001101100010110110100001111011001011011000100" + "00111010100010111011001111110001000000101010011111111111100000100101110110101010011101111010110100100001100001100" + "00110001010001110111011100011011110111110110100010000100011011110100000000100000101000000010010100011101010100100" + "00101000100110010001111010000110100101011000011111101110110000100111100011000110000010011011111100100010110011000" + "00000101001010101000010101000110010110110101000100100110011010100101110000110100100111010100111100100100011110111" + "11011100101011111001110111001000101111001001101101010111101101011110110011110110001110011001001000010010110001101" + "11000010011001001000100101001100111011000101100000111110011011110011100101000010101011000000110000100101011010000" + "11000001111010110010111011110100100100101100111101111100111010000011110010011001111110101100101000001000100110010" + "11110111000001001010010000001000101101110101001110110011011011011010010101111110000000000111001111010010011000111" + "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + "11000011011111001011001101010001011100100111010000101011000101111101101101000101110101110110010011100011001101100" + "11001000101111010000101011101000011011001010110010101000100011110101111111000001000110001101100001001110111100101" + "11101110000100001111001001001101100111000010011100011111001010100010101000011110000111000010101001100010010001111" + "10000001111010110010110010001111101001111011011100110001111111001011010010100000001011001111010010101100111010111" + "11110101011110010111100001100001000000010111111010101111000001100011111101110001000001000001100000100110000001011" + "11101101100010110000110110001100111001001101000101110001101010000111011110000001111001011010110100011101110011100" + "11000000001000001011101101101101101001100000101000000000010111000000100101000110010000110010000011000101011111000" + "11100000100000001110111110110000111110011100000010001110101010101111000011001011111001101101010010001011111011101" + }, + /* 19*/ { BARCODE_AZTEC, UNICODE_MODE, -1, READER_INIT, -1, -1, "A", -1, 0, 15, 15, 1, "", + "000011000111101" + "001110010011000" + "011100100000100" + "011111111111110" + "101100000001010" + "110101111101100" + "111101000101010" + "100101010101000" + "100101000101111" + "100101111101101" + "000100000001010" + "100111111111100" + "100011001110001" + "110110000101100" + "010001010010110" + }, + /* 20*/ { BARCODE_AZTEC, DATA_MODE, 3, -1, -1, -1, "\101\300", -1, 0, 15, 15, 1, "AÀ", + "000000101011100" + "000100010100111" + "001100000110110" + "011111111111111" + "001100000001100" + "001101111101000" + "011101000101110" + "000101010101011" + "100101000101010" + "101101111101111" + "101100000001111" + "000111111111111" + "100011000110001" + "110001000111110" + "111001100011011" + }, + /* 21*/ { BARCODE_AZTEC, UNICODE_MODE, 26, -1, -1, -1, "AÀ", -1, 0, 15, 15, 1, "AÀ", + "001111011000101" + "000110100011000" + "001100001000111" + "011111111111111" + "001100000001101" + "000101111101100" + "010101000101101" + "011101010101001" + "001101000101001" + "100101111101001" + "010100000001011" + "000111111111111" + "000001100010010" + "001100010010010" + "011110110011000" + }, + /* 22*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "0", -1, 0, 11, 11, 1, "ISO/IEC 24778:2008 Figure A.1 (1st)", "11101010101" "11111111111" "01000000010" @@ -381,7 +822,7 @@ static void test_encode(int index, int generate, int debug) { "01111111111" "00101010100" }, - /* 11*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, "25", 0, 11, 11, "ISO/IEC 24778:2008 Figure A.1 (2nd)", + /* 23*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "25", -1, 0, 11, 11, 1, "ISO/IEC 24778:2008 Figure A.1 (2nd)", "11101100101" "11111111111" "01000000011" @@ -394,7 +835,7 @@ static void test_encode(int index, int generate, int debug) { "01111111111" "00100100000" }, - /* 12*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, "125", 0, 11, 11, "ISO/IEC 24778:2008 Figure A.1 (3rd)", + /* 24*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "125", -1, 0, 11, 11, 1, "ISO/IEC 24778:2008 Figure A.1 (3rd)", "11110101101" "11111111111" "11000000011" @@ -407,8 +848,8 @@ static void test_encode(int index, int generate, int debug) { "01111111111" "00111101000" }, - /* 13*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, "255", 0, 11, 11, "ISO/IEC 24778:2008 Figure A.1 (4th)", - "11110101001" + /* 25*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "255", -1, 0, 11, 11, 1, "ISO/IEC 24778:2008 Figure A.1 (4th)", + "11010101001" "11111111111" "01000000011" "11011111011" @@ -420,10 +861,181 @@ static void test_encode(int index, int generate, int debug) { "01111111111" "00110011100" }, + /* 26*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "1", -1, 0, 11, 11, 1, "", + "11101010101" + "11111111111" + "11000000011" + "11011111010" + "01010001010" + "11010101010" + "01010001011" + "01011111011" + "01000000011" + "01111111111" + "00100110100" + }, + /* 27*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "15", -1, 0, 11, 11, 1, "", + "11101001001" + "11111111111" + "11000000011" + "01011111011" + "11010001010" + "01010101010" + "11010001011" + "11011111010" + "11000000010" + "01111111111" + "00001111100" + }, + /* 28*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "16", -1, 0, 11, 11, 1, "", + "11101110101" + "11111111111" + "11000000010" + "01011111010" + "01010001011" + "01010101011" + "01010001011" + "11011111010" + "11000000011" + "01111111111" + "00111100100" + }, + /* 29*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "63", -1, 0, 11, 11, 1, "", + "11100101001" + "11111111111" + "11000000011" + "11011111011" + "01010001011" + "11010101010" + "11010001011" + "11011111010" + "01000000011" + "01111111111" + "00101010000" + }, + /* 30*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "64", -1, 0, 11, 11, 1, "", + "11111010101" + "11111111111" + "01000000010" + "01011111011" + "01010001010" + "01010101011" + "11010001011" + "01011111011" + "01000000011" + "01111111111" + "00111011100" + }, + /* 31*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "65", -1, 0, 11, 11, 1, "", + "11111010101" + "11111111111" + "11000000011" + "01011111010" + "01010001010" + "01010101010" + "11010001010" + "11011111011" + "01000000010" + "01111111111" + "00110111100" + }, + /* 32*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "126", -1, 0, 11, 11, 1, "", + "11110101001" + "11111111111" + "01000000010" + "01011111010" + "01010001011" + "01010101011" + "01010001011" + "11011111010" + "01000000011" + "01111111111" + "00110111000" + }, + /* 33*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "127", -1, 0, 11, 11, 1, "", + "11110101001" + "11111111111" + "11000000011" + "01011111011" + "01010001011" + "01010101010" + "01010001010" + "01011111010" + "01000000010" + "01111111111" + "00111011000" + }, + /* 34*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "128", -1, 0, 11, 11, 1, "", + "11001010101" + "11111111111" + "11000000010" + "01011111011" + "11010001010" + "11010101010" + "01010001010" + "01011111010" + "11000000010" + "01111111111" + "00100010000" + }, + /* 35*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "191", -1, 0, 11, 11, 1, "", + "11000101001" + "11111111111" + "01000000011" + "01011111011" + "11010001011" + "11010101011" + "11010001011" + "01011111011" + "11000000011" + "01111111111" + "00100010100" + }, + /* 36*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "192", -1, 0, 11, 11, 1, "", + "11011010101" + "11111111111" + "11000000010" + "11011111011" + "11010001010" + "01010101010" + "11010001011" + "11011111010" + "11000000011" + "01111111111" + "00110011000" + }, + /* 37*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "225", -1, 0, 11, 11, 1, "", + "11010010101" + "11111111111" + "11000000011" + "11011111011" + "01010001010" + "01010101011" + "11010001011" + "01011111011" + "11000000010" + "01111111111" + "00001100100" + }, + /* 38*/ { BARCODE_AZRUNE, UNICODE_MODE, -1, -1, -1, -1, "254", -1, 0, 11, 11, 1, "", + "11010101001" + "11111111111" + "11000000010" + "11011111010" + "11010001011" + "01010101010" + "01010001011" + "01011111011" + "11000000011" + "01111111111" + "00111111100" + }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); char escaped[1024]; + char bwipp_buf[16384]; + char bwipp_msg[1024]; for (int i = 0; i < data_size; i++) { @@ -432,25 +1044,16 @@ static void test_encode(int index, int generate, int debug) { struct zint_symbol *symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - symbol->symbology = data[i].symbology; - symbol->input_mode = data[i].input_mode; - if (data[i].option_1 != -1) { - symbol->option_1 = data[i].option_1; - } - if (data[i].option_2 != -1) { - symbol->option_2 = data[i].option_2; - } - symbol->debug |= debug; - - int length = strlen(data[i].data); + int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, data[i].length, debug); 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); if (generate) { - printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n", - i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, - testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); + printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, \"%s\", %d, %s, %d, %d, %d, \"%s\",\n", + i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOutputOptionsName(data[i].output_options), + data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), data[i].length, + testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); testUtilModulesDump(symbol, " ", "\n"); printf(" },\n"); } else { @@ -458,10 +1061,21 @@ static void test_encode(int index, int generate, int debug) { assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data); assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data); - if (ret == 0) { - int 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); + int 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); + + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) { + if (!data[i].bwipp_cmp) { + if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); + } else { + ret = testUtilBwipp(i, symbol, data[i].option_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); + + ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); + assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", + i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected); + } } } } @@ -890,7 +1504,7 @@ static void test_fuzz(int index, int debug) { "\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240\240", 2080, -1, 1, ZINT_ERROR_TOO_LONG }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); for (int i = 0; i < data_size; i++) { @@ -899,18 +1513,7 @@ static void test_fuzz(int index, int debug) { struct zint_symbol *symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - symbol->symbology = data[i].symbology; - int length = data[i].length; - if (length == -1) { - length = strlen(data[i].data); - } - if (data[i].input_mode != -1) { - symbol->input_mode = data[i].input_mode; - } - if (data[i].option_1 != -1) { - symbol->option_1 = data[i].option_1; - } - symbol->debug |= debug; + int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug); 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); @@ -924,6 +1527,7 @@ static void test_fuzz(int index, int debug) { int main(int argc, char *argv[]) { testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ + { "test_options", test_options, 1, 0, 1 }, { "test_encode", test_encode, 1, 1, 1 }, { "test_fuzz", test_fuzz, 1, 0, 1 }, }; diff --git a/backend/tests/test_channel.c b/backend/tests/test_channel.c index e1c9ae36..6ce7dc3b 100644 --- a/backend/tests/test_channel.c +++ b/backend/tests/test_channel.c @@ -380,7 +380,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { 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); diff --git a/backend/tests/test_codablock.c b/backend/tests/test_codablock.c index 1b55342c..00427cb5 100644 --- a/backend/tests/test_codablock.c +++ b/backend/tests/test_codablock.c @@ -444,7 +444,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) { if (!data[i].bwipp_cmp) { if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); } else { diff --git a/backend/tests/test_code.c b/backend/tests/test_code.c index d493ad89..e97c9adc 100644 --- a/backend/tests/test_code.c +++ b/backend/tests/test_code.c @@ -368,7 +368,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { 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); diff --git a/backend/tests/test_code1.c b/backend/tests/test_code1.c index df1d9b04..cd1e025a 100644 --- a/backend/tests/test_code1.c +++ b/backend/tests/test_code1.c @@ -234,7 +234,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { 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); diff --git a/backend/tests/test_code128.c b/backend/tests/test_code128.c index 75d6ecef..75c59088 100644 --- a/backend/tests/test_code128.c +++ b/backend/tests/test_code128.c @@ -665,7 +665,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { if (!data[i].bwipp_cmp) { if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); } else { diff --git a/backend/tests/test_code16k.c b/backend/tests/test_code16k.c index d04153d2..5ef7dd59 100644 --- a/backend/tests/test_code16k.c +++ b/backend/tests/test_code16k.c @@ -278,7 +278,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_code49.c b/backend/tests/test_code49.c index 628f6104..0eba355e 100644 --- a/backend/tests/test_code49.c +++ b/backend/tests/test_code49.c @@ -212,7 +212,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_composite.c b/backend/tests/test_composite.c index 83985fbe..0a715364 100644 --- a/backend/tests/test_composite.c +++ b/backend/tests/test_composite.c @@ -1265,7 +1265,7 @@ static void test_examples(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); @@ -1431,7 +1431,7 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); @@ -1561,7 +1561,7 @@ static void test_ean128_cc_shift(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) { if (!data[i].bwipp_cmp) { if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); } else { @@ -2112,7 +2112,7 @@ static void test_encodation_0(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); @@ -2251,7 +2251,7 @@ static void test_encodation_10(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); @@ -2633,7 +2633,7 @@ static void test_encodation_11(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, data[i].option_1, -1, -1, data[i].composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); @@ -2786,7 +2786,7 @@ static void test_addongap(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) { ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); diff --git a/backend/tests/test_dmatrix.c b/backend/tests/test_dmatrix.c index a0d87a2e..d26ac384 100644 --- a/backend/tests/test_dmatrix.c +++ b/backend/tests/test_dmatrix.c @@ -92,19 +92,19 @@ static void test_buffer(int index, int debug) { int ret; struct item { - char *data; int eci; int input_mode; int output_options; + char *data; int ret; char *comment; }; // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) struct item data[] = { - /* 0*/ { "1", 16383, UNICODE_MODE, READER_INIT, 0, "" }, - /* 1*/ { "000106j 05 Galeria A Nação0000000000", 3, UNICODE_MODE, 0, 0, "From Okapi, consecutive use of upper shift; ticket #176" }, + /* 0*/ { 16383, UNICODE_MODE, READER_INIT, "1", 0, "" }, + /* 1*/ { 3, UNICODE_MODE, 0, "000106j 05 Galeria A Nação0000000000", 0, "From Okapi, consecutive use of upper shift; #176" }, }; - int data_size = sizeof(data) / sizeof(struct item); + int data_size = ARRAY_SIZE(data); for (int i = 0; i < data_size; i++) { @@ -113,13 +113,7 @@ static void test_buffer(int index, int debug) { struct zint_symbol *symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - symbol->symbology = BARCODE_DATAMATRIX; - symbol->input_mode = data[i].input_mode; - symbol->eci = data[i].eci; - symbol->output_options = data[i].output_options; - symbol->debug |= debug; - - int length = strlen(data[i].data); + int length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); @@ -130,6 +124,118 @@ static void test_buffer(int index, int debug) { testFinish(); } +static void test_options(int index, int debug) { + + testStart(""); + + int ret; + struct item { + int symbology; + int option_1; + int option_2; + int option_3; + char *data; + int ret; + + int expected_rows; + int expected_width; + }; + // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) + struct item data[] = { + /* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, "1", 0, 10, 10 }, + /* 1*/ { BARCODE_DATAMATRIX, 2, -1, -1, "1", ZINT_ERROR_INVALID_OPTION, -1, -1 }, + /* 2*/ { BARCODE_DATAMATRIX, -1, 1, -1, "1", 0, 10, 10 }, + /* 3*/ { BARCODE_DATAMATRIX, -1, 2, -1, "1", 0, 12, 12 }, + /* 4*/ { BARCODE_DATAMATRIX, -1, 48, -1, "1", 0, 26, 64 }, + /* 5*/ { BARCODE_DATAMATRIX, -1, 49, -1, "1", 0, 10, 10 }, // Ignored + /* 6*/ { BARCODE_DATAMATRIX, -1, -1, -1, "ABCDEFGHIJK", 0, 8, 32 }, + /* 7*/ { BARCODE_DATAMATRIX, -1, -1, DM_SQUARE, "ABCDEFGHIJK", 0, 16, 16 }, + /* 8*/ { BARCODE_DATAMATRIX, -1, -1, -1, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32 }, + /* 9*/ { BARCODE_DATAMATRIX, -1, -1, DM_DMRE, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 20, 44 }, + /* 10*/ { BARCODE_DATAMATRIX, -1, -1, 9999, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTU", 0, 32, 32 }, // Ignored + }; + int data_size = ARRAY_SIZE(data); + + for (int i = 0; i < data_size; i++) { + + if (index != -1 && i != index) continue; + + struct zint_symbol *symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + + 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); + + if (ret < ZINT_ERROR) { + assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, symbol->errtxt); + assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, symbol->errtxt); + } + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +static void test_reader_init(int index, int generate, int debug) { + + testStart(""); + + int ret; + struct item { + int symbology; + int input_mode; + int output_options; + char *data; + int ret; + int expected_rows; + int expected_width; + char *expected; + char *comment; + }; + struct item data[] = { + /* 0*/ { BARCODE_DATAMATRIX, UNICODE_MODE, READER_INIT, "A", 0, 10, 10, "EA 42 81 19 A4 53 21 DF", "TODO: Check this" }, + /* 1*/ { BARCODE_DATAMATRIX, GS1_MODE, READER_INIT, "[91]A", ZINT_ERROR_INVALID_OPTION, 0, 0, "Error 521: Cannot encode in GS1 mode and Reader Initialisation at the same time", "" }, + }; + int data_size = ARRAY_SIZE(data); + + char escaped[1024]; + + for (int i = 0; i < data_size; i++) { + + if (index != -1 && i != index) continue; + + struct zint_symbol *symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt + + int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1 /*option_2*/, -1, data[i].output_options, data[i].data, -1, debug); + + 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); + + if (generate) { + printf(" /*%3d*/ { %s, %s, %s, \"%s\", %s, %d, %d, \"%s\", \"%s\" },\n", + i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), + testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), + testUtilErrorName(data[i].ret), symbol->rows, symbol->width, symbol->errtxt, data[i].comment); + } else { + if (ret < 5) { + assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data); + assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data); + assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); + } + } + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + static void test_input(int index, int generate, int debug) { testStart(""); @@ -138,7 +244,6 @@ static void test_input(int index, int generate, int debug) { struct item { int input_mode; int eci; - int option_1; int option_2; int option_3; char *data; @@ -151,16 +256,78 @@ static void test_input(int index, int generate, int debug) { char *comment; }; struct item data[] = { - /* 0*/ { UNICODE_MODE, 0, -1, -1, -1, "0466010592130100000k*AGUATY80", 0, 0, 18, 18, "(32) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 93 B0 1C 3C 76 FB D4 AB 16 11", "" }, - /* 1*/ { UNICODE_MODE, 0, -1, 5, -1, "0466010592130100000k*AGUATY80", 0, 0, 18, 18, "(32) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 93 B0 1C 3C 76 FB D4 AB 16 11", "" }, - /* 2*/ { UNICODE_MODE, 0, -1, -1, -1, "0466010592130100000k*AGUATY8", 0, 0, 18, 18, "(32) 86 C4 83 87 DE 8F 83 82 82 E6 19 5C 07 B7 82 5F D4 3D 65 B5 97 30 00 FC 2C 4C 30 52", "" }, - /* 3*/ { UNICODE_MODE, 0, -1, -1, -1, "0466010592130100000k*AGUATY80U", 0, 0, 20, 20, "(40) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 FE 56 81 76 4F AB 22 B8 6F 0A", "" }, - /* 4*/ { UNICODE_MODE, 0, -1, 5, -1, "0466010592130100000k*AGUATY80U", ZINT_ERROR_TOO_LONG, -1, 0, 0, "Error 522: Input too long for selected symbol size", "" }, - /* 5*/ { UNICODE_MODE, 0, -1, 6, -1, "0466010592130100000k*AGUATY80U", 0, 0, 20, 20, "(40) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 FE 56 81 76 4F AB 22 B8 6F 0A", "" }, - /* 6*/ { UNICODE_MODE, 0, -1, -1, -1, "0466010592130100000k*AGUATY80UA", 0, 0, 20, 20, "(40) 86 C4 83 87 DE 8F 83 82 82 31 6C E6 07 B7 82 5F D4 3D 1E 5F FE 81 1E 1B B0 FE E7 54", "" }, - /* 7*/ { UNICODE_MODE, 0, -1, -1, -1, "A*0>B1*", 0, 0, 14, 14, "EE 57 AD 0E DE FE 2B 81 F8 05 75 94 1E 5F 24 0C A0 D3", "X12 symbols_left 3, process_p 1" }, - /* 8*/ { UNICODE_MODE, 0, -1, -1, -1, "A*0>B1*2", 0, 0, 14, 14, "EE 57 AD 0E DE FE 2B 33 E7 BB FB 78 F9 F5 4B 11 BB 5A", "X12 symbols_left 3, process_p 2" }, - /* 9*/ { UNICODE_MODE, 0, -1, -1, -1, "A*0>B1*2>", 0, 0, 14, 14, "EE 57 AD 0E DE 07 33 FE 75 99 1B 4D 76 0E 9E 49 E0 37", "X12 symbols_left 1, process_p 0" }, + /* 0*/ { UNICODE_MODE, 0, -1, -1, "0466010592130100000k*AGUATY80", 0, 0, 18, 18, "(32) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 93 B0 1C 3C 76 FB D4 AB 16 11", "#208" }, + /* 1*/ { UNICODE_MODE, 0, 5, -1, "0466010592130100000k*AGUATY80", 0, 0, 18, 18, "(32) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 93 B0 1C 3C 76 FB D4 AB 16 11", "" }, + /* 2*/ { UNICODE_MODE, 0, -1, -1, "0466010592130100000k*AGUATY8", 0, 0, 18, 18, "(32) 86 C4 83 87 DE 8F 83 82 82 E6 19 5C 07 B7 82 5F D4 3D 65 B5 97 30 00 FC 2C 4C 30 52", "" }, + /* 3*/ { UNICODE_MODE, 0, -1, -1, "0466010592130100000k*AGUATY80U", 0, 0, 20, 20, "(40) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 FE 56 81 76 4F AB 22 B8 6F 0A", "" }, + /* 4*/ { UNICODE_MODE, 0, 5, -1, "0466010592130100000k*AGUATY80U", ZINT_ERROR_TOO_LONG, -1, 0, 0, "Error 522: Input too long for selected symbol size", "" }, + /* 5*/ { UNICODE_MODE, 0, 6, -1, "0466010592130100000k*AGUATY80U", 0, 0, 20, 20, "(40) 86 C4 83 87 DE 8F 83 82 82 31 6C EE 08 85 D6 D2 EF 65 FE 56 81 76 4F AB 22 B8 6F 0A", "" }, + /* 6*/ { UNICODE_MODE, 0, -1, -1, "0466010592130100000k*AGUATY80UA", 0, 0, 20, 20, "(40) 86 C4 83 87 DE 8F 83 82 82 31 6C E6 07 B7 82 5F D4 3D 1E 5F FE 81 1E 1B B0 FE E7 54", "" }, + /* 7*/ { UNICODE_MODE, 0, -1, -1, "A*0>B1*", 0, 0, 14, 14, "EE 57 AD 0E DE FE 2B 81 F8 05 75 94 1E 5F 24 0C A0 D3", "X12 symbols_left 3, process_p 1" }, + /* 8*/ { UNICODE_MODE, 0, -1, -1, "A*0>B1*2", 0, 0, 14, 14, "EE 57 AD 0E DE FE 2B 33 E7 BB FB 78 F9 F5 4B 11 BB 5A", "X12 symbols_left 3, process_p 2" }, + /* 9*/ { UNICODE_MODE, 0, -1, -1, "A*0>B1*2>", 0, 0, 14, 14, "EE 57 AD 0E DE 07 33 FE 75 99 1B 4D 76 0E 9E 49 E0 37", "X12 symbols_left 1, process_p 0" }, + /* 10*/ { UNICODE_MODE, 0, -1, -1, "ABCDEF", 0, 0, 12, 12, "E6 59 E9 6D 24 3D 15 EF AA 21 F9 59", "C40 last_shift 0, symbols_left 0, process_p 0" }, + /* 11*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFG", 0, 0, 14, 14, "E6 59 E9 6D 24 FE 48 81 8C 7E 09 5E 10 64 BC 5F 4C 91", "C40 last_shift 0, symbols_left 3, process_p 1" }, + /* 12*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGH", 0, 0, 14, 14, "E6 59 E9 6D 24 80 49 FE DD 85 9E 5B E9 8F 4D F3 02 9C", "C40 last_shift 0, symbols_left 3, process_p 2" }, + /* 13*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHI", 0, 0, 14, 14, "E6 59 E9 6D 24 80 5F FE 01 DE 20 9F AA C2 FF 8F 08 97", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 14*/ { UNICODE_MODE, 0, -1, -1, "ABCDEF\001G", 0, 0, 14, 14, "E6 59 E9 6D 24 00 3D FE 5D 5A F5 0A 8A 4E 1D 63 07 B9", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 15*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFG\001", 0, 0, 14, 14, "E6 59 E9 6D 24 7D 02 FE 14 A3 27 63 01 2F B1 94 FE FA", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 16*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFG\001H", 0, 0, 14, 14, "E6 59 E9 6D 24 7D 02 49 C2 E6 DD 06 89 51 BA 8E 9D 1F", "C40 last_shift 0, symbols_left 1, process_p 1" }, + /* 17*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGH\001", 0, 0, 14, 14, "E6 59 E9 6D 24 80 49 02 4F 4D 86 23 5F 1B F9 8C 67 7E", "C40 last_shift 1, symbols_left 1, process_p 1" }, + /* 18*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGH\001I", 0, 0, 8, 32, "E6 59 E9 6D 24 80 49 09 B1 FE 27 19 F1 CA B7 85 D0 25 0D 5E 24", "C40 last_shift 1, symbols_left 3, process_p 2" }, + /* 19*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHI\001", 0, 0, 8, 32, "E6 59 E9 6D 24 80 5F FE 02 81 47 6C 3E 49 D3 FA 46 47 53 6E E5", "Switches to ASC for last char" }, + /* 20*/ { UNICODE_MODE, 0, -1, -1, "ABCDEF+G", 0, 0, 14, 14, "E6 59 E9 6D 24 07 E5 FE 6B 35 71 7F 3D 57 59 46 F7 B9", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 21*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFG+", 0, 0, 14, 14, "E6 59 E9 6D 24 7D 33 FE 33 F5 97 60 73 48 13 2E E5 74", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 22*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFG+H", 0, 0, 14, 14, "E6 59 E9 6D 24 7D 33 49 E5 B0 6D 05 FB 36 18 34 86 91", "C40 last_shift 0, symbols_left 1, process_p 1" }, + /* 23*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGH+", 0, 0, 14, 14, "E6 59 E9 6D 24 80 49 2C 67 1F 09 CA 1A CD 0D 55 80 21", "C40 last_shift 2, symbols_left 1, process_p 1" }, + /* 24*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGH+I", 0, 0, 8, 32, "E6 59 E9 6D 24 80 4A 41 F1 FE 41 81 CF 13 E2 64 43 2F E1 D1 11", "C40 last_shift 2, symbols_left 3, process_p 2" }, + /* 25*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHI+", 0, 0, 8, 32, "E6 59 E9 6D 24 80 5F FE 2C 81 F8 BC 8D 12 17 7E 22 27 DE 7F E2", "Switches to ASC for last char" }, + /* 26*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFjG", 0, 0, 14, 14, "E6 59 E9 6D 24 0E 25 FE DA 14 D7 15 47 69 9D 4A 54 6D", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 27*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGj", 0, 0, 14, 14, "E6 59 E9 6D 24 7D 5B FE B5 F3 24 0A 99 26 D6 CC A8 40", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 28*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGjH", 0, 0, 14, 14, "E6 59 E9 6D 24 7D 5B 49 63 B6 DE 6F 11 58 DD D6 CB A5", "C40 last_shift 0, symbols_left 1, process_p 1" }, + /* 29*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHj", 0, 0, 14, 14, "E6 59 E9 6D 24 80 49 6B 12 00 5B FD B0 3A D9 DF 26 B6", "C40 last_shift 3, symbols_left 1, process_p 1" }, + /* 30*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHjI", 0, 0, 8, 32, "E6 59 E9 6D 24 80 4B 41 F1 FE FB 10 AC 51 A1 56 8F 20 98 18 1B", "C40 last_shift 3, symbols_left 3, process_p 2" }, + /* 31*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHIj", 0, 0, 8, 32, "E6 59 E9 6D 24 80 5F FE 6B 81 17 79 06 42 7E 96 B2 70 79 F8 3C", "Switches to ASC for last char" }, + /* 32*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHIJÊ", 0, 0, 16, 16, "E6 59 E9 6D 24 80 5F FE 4B EB 4B 81 DD D9 F9 C9 C5 38 F3 4B DB 80 92 A7", "Switches to ASC for last 2 chars" }, + /* 33*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHIJKÊ", 0, 0, 16, 16, "E6 59 E9 6D 24 80 5F 93 82 BF 19 FE E7 50 32 B4 0B CC 8C 07 D2 78 8D F5", "C40 last_shift 0, symbols_left 3, process_p 2" }, + /* 34*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHIJKª", 0, 0, 16, 16, "E6 59 E9 6D 24 80 5F 93 82 BB B2 FE 11 5C 60 32 A6 DE FC 7B 30 F1 03 56", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 35*/ { UNICODE_MODE, 0, -1, -1, "ABCDEFGHIJKê", 0, 0, 16, 16, "E6 59 E9 6D 24 80 5F 93 82 BB DB FE 78 43 69 3C C2 FE F5 2E 1B 4F B6 04", "C40 last_shift 0, symbols_left 1, process_p 0" }, + /* 36*/ { UNICODE_MODE, 0, -1, -1, "abcdef", 0, 0, 12, 12, "EF 59 E9 6D 24 E2 CC D9 B4 55 E2 6A", "TEX last_shift 0, symbols_left 0, process_p 0" }, + /* 37*/ { UNICODE_MODE, 0, -1, -1, "abcdefg", 0, 0, 14, 14, "EF 59 E9 6D 24 FE 68 81 A9 65 CD 3A A2 E9 E0 B7 E1 E5", "TEX last_shift 0, symbols_left 3, process_p 1" }, + /* 38*/ { UNICODE_MODE, 0, -1, -1, "abcdefgh", 0, 0, 14, 14, "EF 59 E9 6D 24 80 49 FE 06 E4 44 D2 32 58 90 31 E9 F8", "TEX last_shift 0, symbols_left 3, process_p 2" }, + /* 39*/ { UNICODE_MODE, 0, -1, -1, "abcdefghi", 0, 0, 14, 14, "EF 59 E9 6D 24 80 5F FE DA BF FA 16 71 15 22 4D E3 F3", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 40*/ { UNICODE_MODE, 0, -1, -1, "abcdef\001g", 0, 0, 14, 14, "EF 59 E9 6D 24 00 3D FE 86 3B 2F 83 51 99 C0 A1 EC DD", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 41*/ { UNICODE_MODE, 0, -1, -1, "abcdefg\001", 0, 0, 14, 14, "EF 59 E9 6D 24 7D 02 FE CF C2 FD EA DA F8 6C 56 15 9E", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 42*/ { UNICODE_MODE, 0, -1, -1, "abcdefg\001h", 0, 0, 14, 14, "EF 59 E9 6D 24 7D 02 69 7A 9B EB A4 5E DE 99 25 01 8C", "TEX last_shift 0, symbols_left 1, process_p 1" }, + /* 43*/ { UNICODE_MODE, 0, -1, -1, "abcdefgh\001", 0, 0, 14, 14, "EF 59 E9 6D 24 80 49 02 94 2C 5C AA 84 CC 24 4E 8C 1A", "TEX last_shift 1, symbols_left 1, process_p 1" }, + /* 44*/ { UNICODE_MODE, 0, -1, -1, "abcdefgh\001i", 0, 0, 8, 32, "EF 59 E9 6D 24 80 49 09 B1 FE 2D DE FF 05 A9 AE 0B 91 4B C5 70", "TEX last_shift 1, symbols_left 3, process_p 2" }, + /* 45*/ { UNICODE_MODE, 0, -1, -1, "abcdefghi\001", 0, 0, 8, 32, "EF 59 E9 6D 24 80 5F FE 02 81 4D AB 30 86 CD D1 9D F3 15 F5 B1", "Switches to ASC for last char" }, + /* 46*/ { UNICODE_MODE, 0, -1, -1, "abcdefJg", 0, 0, 14, 14, "EF 59 E9 6D 24 0E 25 FE 01 75 0D 9C 9C BE 40 88 BF 09", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 47*/ { UNICODE_MODE, 0, -1, -1, "abcdefgJ", 0, 0, 14, 14, "EF 59 E9 6D 24 7D 5B FE 6E 92 FE 83 42 F1 0B 0E 43 24", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 48*/ { UNICODE_MODE, 0, -1, -1, "abcdefgJh", 0, 0, 14, 14, "EF 59 E9 6D 24 7D 5B 69 DB CB E8 CD C6 D7 FE 7D 57 36", "TEX last_shift 0, symbols_left 1, process_p 1" }, + /* 49*/ { UNICODE_MODE, 0, -1, -1, "abcdefghJ", 0, 0, 14, 14, "EF 59 E9 6D 24 80 49 4B AA 7D 6D 5F 67 B5 FA 74 BA 25", "TEX last_shift 3, symbols_left 1, process_p 1" }, + /* 50*/ { UNICODE_MODE, 0, -1, -1, "abcdefghJi", 0, 0, 8, 32, "EF 59 E9 6D 24 80 4B 41 F1 FE F1 D7 A2 9E BF 7D 54 94 DE 83 4F", "TEX last_shift 3, symbols_left 3, process_p 2" }, + /* 51*/ { UNICODE_MODE, 0, -1, -1, "abcdefghiJ", 0, 0, 8, 32, "EF 59 E9 6D 24 80 5F FE 4B 81 B3 A5 20 E3 DC F9 74 40 09 30 46", "Switches to ASC for last char" }, + /* 52*/ { UNICODE_MODE, 0, -1, -1, "abcdefghijkÊ", 0, 0, 16, 16, "EF 59 E9 6D 24 80 5F 93 82 BB DB FE 3E C8 EC 73 58 A7 42 46 10 49 25 99", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 53*/ { UNICODE_MODE, 0, -1, -1, "abcdefghijkª", 0, 0, 16, 16, "EF 59 E9 6D 24 80 5F 93 82 BB B2 FE 57 D7 E5 7D 3C 87 4B 13 3B F7 90 CB", "TEX last_shift 0, symbols_left 1, process_p 0" }, + /* 54*/ { UNICODE_MODE, 0, -1, -1, "abcdefghijkê", 0, 0, 16, 16, "EF 59 E9 6D 24 80 5F 93 82 BF 19 FE A1 DB B7 FB 91 95 3B 6F D9 7E 1E 68", "TEX last_shift 2, symbols_left 3, process_p 2" }, + /* 55*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@E", 0, 0, 14, 14, "F0 00 10 80 0C 40 05 81 45 D9 9B 1F BC 09 CD E4 7F F4", "EDIFACT symbols_left 1, process_p 0" }, + /* 56*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@EF", 0, 0, 14, 14, "F0 00 10 80 0C 40 05 47 AC D8 F1 F0 DE 6C 30 5E 30 D4", "EDIFACT symbols_left 1, process_p 1" }, + /* 57*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@EF@", 0, 0, 8, 32, "F0 00 10 80 0C 40 05 18 07 C0 6C 60 CA 7E 7B F3 38 A1 9D D0 CC", "EDIFACT symbols_left 3, process_p 2" }, + /* 58*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@EF@G", 0, 0, 8, 32, "F0 00 10 80 0C 40 05 18 01 DF 71 FB 95 EA E6 4B 36 E0 23 9B 4C", "EDIFACT symbols_left 3, process_p 3" }, + /* 59*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@EF@GH", 0, 0, 8, 32, "F0 00 10 80 0C 40 05 18 01 C8 77 0F 96 AD 39 FB F3 04 3B BF 99", "EDIFACT symbols_left 0, process_p 0" }, + /* 60*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@EF@GH@", 0, 0, 16, 16, "F0 00 10 80 0C 40 05 18 01 C8 41 81 4A 43 1E F1 26 2E 4B EB B8 6A 2B 64", "EDIFACT symbols_left 2, process_p 1" }, + /* 61*/ { UNICODE_MODE, 0, -1, -1, "@AB@CD@EF@GH@I", 0, 0, 16, 16, "F0 00 10 80 0C 40 05 18 01 C8 41 4A 49 B3 34 91 8C 2A C4 0E 16 2F 45 9B", "EDIFACT symbols_left 2, process_p 2" }, + /* 62*/ { DATA_MODE, 0, -1, -1, "\377\376", 0, 0, 12, 12, "EB 80 EB 7F 81 6F A8 0F 21 6F 5F 88", "FN4 A7F FN4 A7E" }, + /* 63*/ { DATA_MODE, 0, -1, -1, "\377\376\375", 0, 0, 12, 12, "E7 2F C0 55 E9 52 B7 8D 38 76 E8 6E", "BAS BFF BFE BFD" }, + /* 64*/ { DATA_MODE, 3, -1, -1, "\101\102\103\104\300\105\310", 0, 3, 16, 16, "F1 04 E7 5E 2D C4 5B F1 03 1D 36 81 64 0E C0 77 9A 18 52 B2 F9 F0 04 39", "ECI 4 BAS B41 B42 B43 B44 BC0 B45 BC8" }, + /* 65*/ { UNICODE_MODE, 26, -1, -1, "ABCDÀEÈ", 0, 26, 12, 26, "F1 1B E7 60 2D C4 5B F1 06 58 B3 C7 21 81 57 ED 3D C0 12 2E 6C 80 58 CC 2C 05 0D 31 FC 2D", "ECI 27 BAS B41 B42 B43 B44 BC3 B80 B45 BC3 B88" }, + /* 66*/ { UNICODE_MODE, 0, -1, -1, "β", ZINT_WARN_USES_ECI, 9, 12, 12, "Warning F1 0A EB 63 81 41 56 DA C0 3D 2D CC", "ECI 10 FN4 A62" }, + /* 67*/ { UNICODE_MODE, 127, -1, -1, "A", 0, 127, 12, 12, "F1 80 01 42 81 14 A2 86 07 F5 27 30", "ECI 128 A41" }, + /* 68*/ { UNICODE_MODE, 16382, -1, -1, "A", 0, 16382, 12, 12, "F1 BF FE 42 81 29 57 AA A0 92 B2 45", "ECI 16383 A41" }, + /* 69*/ { UNICODE_MODE, 810899, -1, -1, "A", 0, 810899, 12, 12, "F1 CC 51 05 42 BB A5 A7 8A C6 6E 0F", "ECI 810900 A41" }, + /* 70*/ { UNICODE_MODE, 26, -1, -1, "abcdefghi1234FGHIJKLMNabc@@@@@@@@@é", 0, 26, 24, 24, "(60) F1 1B EF 59 E9 6D 24 80 5F FE 8E A4 E6 79 F6 8D 31 A0 6C FE 62 63 64 F0 00 00 00 00", "Mix of modes TEX ASC C40 ASC EDI BAS" }, + /* 71*/ { UNICODE_MODE | ESCAPE_MODE, -1, -1, -1, "[)>\\R05\\GA\\R\\E", 0, 0, 10, 10, "EC 42 81 5D 17 49 F6 B6", "Macro05 A41" }, }; int data_size = ARRAY_SIZE(data); @@ -175,14 +342,14 @@ static void test_input(int index, int generate, int debug) { symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt - int length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); + int length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); if (generate) { - printf(" /*%3d*/ { %s, %d, %d, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\", \"%s\" },\n", - i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_1, data[i].option_2, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), + printf(" /*%3d*/ { %s, %d, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\", \"%s\" },\n", + i, testUtilInputModeName(data[i].input_mode), data[i].eci, data[i].option_2, data[i].option_3, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), ret < 5 ? symbol->eci : -1, symbol->rows, symbol->width, symbol->errtxt, data[i].comment); } else { if (ret < 5) { @@ -203,20 +370,28 @@ static void test_encode(int index, int generate, int debug) { testStart(""); + int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise + int ret; struct item { int symbology; int input_mode; + int eci; + int output_options; + int option_2; + int option_3; char *data; int ret; int expected_rows; int expected_width; + int bwipp_cmp; char *comment; char *expected; }; + // Verified manually against ISO/IEC 16022:2006, GS1 General Specifications 20.0 (GGS), ANSI/HIBC LIC 2.6-2016 (HIBC/LIC) and ANSI/HIBC PAS 1.3-2010 (HIBC/PAS), with noted exceptions struct item data[] = { - /* 0*/ { BARCODE_DATAMATRIX, -1, "1234abcd", 0, 14, 14, "", + /* 0*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, "1234abcd", 0, 14, 14, 1, "", "10101010101010" "11001010001111" "11000101100100" @@ -232,7 +407,7 @@ static void test_encode(int index, int generate, int debug) { "10011111000100" "11111111111111" }, - /* 1*/ { BARCODE_DATAMATRIX, -1, "A1B2C3D4E5F6G7H8I9J0K1L2", 0, 18, 18, "ISO 16022:2006 Figure 1", + /* 1*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, "A1B2C3D4E5F6G7H8I9J0K1L2", 0, 18, 18, 1, "ISO 16022:2006 Figure 1", "101010101010101010" "101000101010001111" "101100000111000010" @@ -252,7 +427,7 @@ static void test_encode(int index, int generate, int debug) { "100011000000100100" "111111111111111111" }, - /* 2*/ { BARCODE_DATAMATRIX, -1, "123456", 0, 10, 10, "ISO 16022:2006 Figure O.2", + /* 2*/ { BARCODE_DATAMATRIX, -1, -1, -1, -1, -1, "123456", 0, 10, 10, 1, "ISO 16022:2006 Figure O.2", "1010101010" "1100101101" "1100000100" @@ -264,7 +439,7 @@ static void test_encode(int index, int generate, int debug) { "1001110100" "1111111111" }, - /* 3*/ { BARCODE_DATAMATRIX, -1, "30Q324343430794\\R06\\G+/ACMRN123456/V2009121908334\\R\\E", 0, 20, 20, 1, "HIBC/PAS Section 2.2 Patient Id Macro, same", + "10101010101010101010" + "10000000001110001111" + "11010101001010011100" + "11000000011100110101" + "11011001101011001100" + "11001100000100010001" + "11110111101011000100" + "11010010001101100001" + "11110010010110011110" + "11010010010000010011" + "10010001100010110000" + "11101100100001000111" + "11101010000011111100" + "11000010000101001011" + "11001110111110010010" + "11000010110100011101" + "11001011001001011100" + "10010110010000010101" + "11100110001010111010" + "11111111111111111111" + }, + /* 21*/ { BARCODE_HIBC_DM, -1, -1, -1, -1, -1, "/EO523201", 0, 14, 14, 1, "HIBC/PAS Section 2.2 Purchase Order, same", + "10101010101010" + "10011001010101" + "11101000011010" + "10001100011101" + "11101100101100" + "10100001101111" + "10010001010110" + "10000001011001" + "11100000010100" + "11011010100101" + "10111110101110" + "11110000101101" + "10010010000100" + "11111111111111" + }, + /* 22*/ { BARCODE_HIBC_DM, -1, -1, -1, -1, DM_SQUARE, "/EU720060FF0/O523201", 0, 18, 18, 1, "HIBC/PAS Section 2.2 2nd Purchase Order, same", + "101010101010101010" + "100110010100100001" + "111011110110010110" + "100000101110011001" + "111001001010000100" + "100000000000011101" + "100101100000101110" + "111000000111111011" + "110110111000101010" + "101001000111000111" + "100011110101010110" + "111111001101010011" + "100000000001101000" + "110100100011011111" + "111000100110101110" + "111010100101000011" + "111000010011001010" + "111111111111111111" + }, + /* 23*/ { BARCODE_HIBC_DM, -1, -1, -1, -1, -1, "/EU720060FF0/O523201/Z34H159/M9842431340", 0, 22, 22, 1, "HIBC/PAS Section 2.2 3rd Purchase Order (left), same", + "1010101010101010101010" + "1001100101001000000011" + "1110111101100001111010" + "1000001011101100111111" + "1110010010010000111100" + "1000000000011100000111" + "1001011010011000001110" + "1110000010001001101001" + "1101100110001010100100" + "1010010011011101000101" + "1000100011010000001110" + "1111010100101000010111" + "1000001001011011101110" + "1111110111111101100011" + "1001010110011010000000" + "1101010100110100010011" + "1001010011000110000000" + "1111001010100101110111" + "1100110010110011010000" + "1100001011100001000111" + "1010110000010001001000" + "1111111111111111111111" + }, + /* 24*/ { BARCODE_DATAMATRIX, DATA_MODE | ESCAPE_MODE, -1, -1, -1, -1, "[)>\\R06\\G+/EU720060FF0/O523201/Z34H159/M9842431340V\\R\\E", 0, 22, 22, 1, "HIBC/PAS Section 2.2 3rd Purchase Order (right), same", + "1010101010101010101010" + "1000000000111010011101" + "1101011100101001011100" + "1100010000000001101001" + "1111110110000111100000" + "1100100000110011001101" + "1001011001000010000110" + "1000100101110111110111" + "1100001001110111111100" + "1011111001001010001101" + "1000011000010100101010" + "1111001101110100101101" + "1110001101101100001100" + "1001010101111010110011" + "1000110111011100101010" + "1111110011011111010101" + "1101000011100111101110" + "1011000010010100110111" + "1001110101111101000000" + "1110101001011011000111" + "1001110110011101101000" + "1111111111111111111111" + }, + /* 25*/ { BARCODE_HIBC_DM, -1, -1, -1, -1, -1, "/E+/KN12345", 0, 16, 16, 1, "HIBC/PAS Section 2.2 Asset Tag **NOT SAME** check digit 'A' in figure is for '/KN12345', but actual data is as given here, when check digit is 'J'", + "1010101010101010" + "1001101010001111" + "1110001000101100" + "1000110100101101" + "1101000000110010" + "1000101001000001" + "1110000111001100" + "1010001101111101" + "1111101010101000" + "1101100101010001" + "1100001011010010" + "1100001111001001" + "1100010100000110" + "1010001101001101" + "1001000000000010" + "1111111111111111" + }, + /* 26*/ { BARCODE_HIBC_DM, -1, -1, -1, -1, -1, "/LAH123/NC903", 0, 16, 16, 1, "HIBC/PAS Section 2.2 Surgical Instrument, same", + "1010101010101010" + "1001010001010001" + "1110010100000100" + "1000001100000011" + "1110001100101000" + "1000111111100001" + "1011001110000100" + "1100110000001101" + "1000001110010000" + "1011001110111111" + "1001011010011010" + "1111000110111011" + "1010010101000100" + "1011001110110101" + "1100000101010010" + "1111111111111111" + }, + /* 27*/ { BARCODE_DATAMATRIX, DATA_MODE, 3, -1, -1, -1, "\101\300", 0, 12, 12, 1, "AÀ", + "101010101010" + "100010101111" + "100001011110" + "110000010001" + "101100110000" + "110010100111" + "101011011100" + "110100111101" + "101100110100" + "101011100101" + "100011011010" + "111111111111" + }, + /* 28*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 26, -1, -1, -1, "AÀ", 0, 14, 14, 1, "AÀ", + "10101010101010" + "10001010100001" + "10110101100100" + "10110001000101" + "10111000100010" + "11101011110011" + "10011100001100" + "10001100101111" + "10110110111110" + "10000111010001" + "10000001111000" + "11110100110001" + "11000110001100" + "11111111111111" + }, + /* 29*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, -1, -1, -1, "abcdefgh+", 0, 14, 14, 0, "TEX last_shift 2, symbols_left 1, process_p 1; BWIPP different encodation (does not use 0 padded Text)", + "10101010101010" + "10100110111011" + "10110010100010" + "10011000100101" + "11101000000000" + "11000110110111" + "11000010110100" + "10101011010111" + "10111110000100" + "11011001001111" + "11110111100000" + "11001011110101" + "10010111010100" + "11111111111111" + }, }; int data_size = ARRAY_SIZE(data); + char escaped[1024]; + char bwipp_buf[8192]; + char bwipp_msg[1024]; + for (int i = 0; i < data_size; i++) { if (index != -1 && i != index) continue; @@ -446,15 +1029,16 @@ static void test_encode(int index, int generate, int debug) { struct zint_symbol *symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, data[i].option_2, data[i].option_3, data[i].output_options, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d\n", i, ret, data[i].ret); if (generate) { - printf(" /*%3d*/ { %s, %s, \"%s\", %s, %d, %d, \"%s\",\n", - i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), - data[i].data, testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment); + printf(" /*%3d*/ { %s, %s, %d, %s, %d, %s, \"%s\", %s, %d, %d, %d, \"%s\",\n", + i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilOutputOptionsName(data[i].output_options), + data[i].option_2, testUtilOption3Name(data[i].option_3), testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), + testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); testUtilModulesDump(symbol, " ", "\n"); printf(" },\n"); } else { @@ -462,10 +1046,21 @@ static void test_encode(int index, int generate, int debug) { assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data); assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data); - if (ret == 0) { - int 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); + int 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); + + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, debug)) { + if (!data[i].bwipp_cmp) { + if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); + } else { + ret = testUtilBwipp(i, symbol, -1, data[i].option_2, data[i].option_3, 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); + + ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected); + assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n", + i, testUtilBarcodeName(symbol->symbology), ret, bwipp_msg, bwipp_buf, data[i].expected); + } } } } @@ -481,6 +1076,8 @@ int main(int argc, char *argv[]) { testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ { "test_large", test_large, 1, 0, 1 }, { "test_buffer", test_buffer, 1, 0, 1 }, + { "test_options", test_options, 1, 0, 1 }, + { "test_reader_init", test_reader_init, 1, 1, 1 }, { "test_input", test_input, 1, 1, 1 }, { "test_encode", test_encode, 1, 1, 1 }, }; diff --git a/backend/tests/test_gs1.c b/backend/tests/test_gs1.c index 8db0009f..d9ff1824 100644 --- a/backend/tests/test_gs1.c +++ b/backend/tests/test_gs1.c @@ -213,7 +213,7 @@ static void test_gs1_reduce(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -1, text, length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); diff --git a/backend/tests/test_imail.c b/backend/tests/test_imail.c index aaf3ec8f..fb501e25 100644 --- a/backend/tests/test_imail.c +++ b/backend/tests/test_imail.c @@ -267,7 +267,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_medical.c b/backend/tests/test_medical.c index 76e81785..36cdc056 100644 --- a/backend/tests/test_medical.c +++ b/backend/tests/test_medical.c @@ -283,7 +283,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { 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); diff --git a/backend/tests/test_pdf417.c b/backend/tests/test_pdf417.c index d94fd103..af2a1b5e 100644 --- a/backend/tests/test_pdf417.c +++ b/backend/tests/test_pdf417.c @@ -186,7 +186,7 @@ static void test_input(int index, int generate, int debug) { char *comment; }; // é U+00E9 (\351, 233), UTF-8 C3A9 - // β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page), in Shift JIS 0x83C0, UTF-8 CEB2 + // β U+03B2 in ISO 8859-7 Greek (but not other ISO 8859 or Win page) (\342, 226), UTF-8 CEB2 struct item data[] = { /* 0*/ { BARCODE_PDF417, UNICODE_MODE, -1, "é", 0, 0, 6, 103, "(12) 4 913 233 900 398 878 279 350 217 295 231 77", "" }, /* 1*/ { BARCODE_PDF417, UNICODE_MODE, 3, "é", 0, 3, 7, 103, "(14) 6 927 3 913 233 900 162 81 551 529 607 384 164 108", "" }, @@ -261,6 +261,7 @@ static void test_encode(int index, int generate, int debug) { int ret; struct item { int symbology; + int eci; int input_mode; int option_1; int option_2; @@ -274,7 +275,7 @@ static void test_encode(int index, int generate, int debug) { char *expected; }; struct item data[] = { - /* 0*/ { BARCODE_PDF417, UNICODE_MODE, 1, 2, "PDF417 Symbology Standard", 0, 10, 103, 0, "ISO 15438:2015 Figure 1, same, BWIPP uses different encodation, same codeword count", + /* 0*/ { BARCODE_PDF417, -1, UNICODE_MODE, 1, 2, "PDF417 Symbology Standard", 0, 10, 103, 0, "ISO 15438:2015 Figure 1, same, BWIPP uses different encodation, same codeword count", "1111111101010100011101010011100000111010110011110001110111011001100011110101011110000111111101000101001" "1111111101010100011111010100110000110100001110001001111010001010000011111010100110000111111101000101001" "1111111101010100011101010111111000101100110111100001110111111000101011010100111110000111111101000101001" @@ -286,14 +287,14 @@ static void test_encode(int index, int generate, int debug) { "1111111101010100011010011011111100110000101001111101101111100010001010100110011111000111111101000101001" "1111111101010100010100011000001100100010111101111001100011100011001011010001100011100111111101000101001" }, - /* 1*/ { BARCODE_PDF417, UNICODE_MODE, 1, 2, "PDF417", 0, 5, 103, 1, "ISO 15438:2015 Annex Q example for generating ECC", + /* 1*/ { BARCODE_PDF417, -1, UNICODE_MODE, 1, 2, "PDF417", 0, 5, 103, 1, "ISO 15438:2015 Annex Q example for generating ECC", "1111111101010100011110101011110000110101000110000001110111011001100011110101011110000111111101000101001" "1111111101010100011111101010011100110100001110001001111010001010000011111101010111000111111101000101001" "1111111101010100011101010111111000101100110011110001100011111001001011101010011111100111111101000101001" "1111111101010100010101111001111000101011101110000001100001101000100010101111001111000111111101000101001" "1111111101010100011101011100011000100001101011111101111110110001011011101011100110000111111101000101001" }, - /* 2*/ { BARCODE_PDF417, UNICODE_MODE, 0, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", 0, 17, 86, 1, "Text Compaction Alpha", + /* 2*/ { BARCODE_PDF417, -1, UNICODE_MODE, 0, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", 0, 17, 86, 1, "Text Compaction Alpha", "11111111010101000111110101001111101101011001110000011101010111000000111111101000101001" "11111111010101000111111010101110001111110101011100011110101000100000111111101000101001" "11111111010101000110101011111000001010011001111100011101010111111000111111101000101001" @@ -312,7 +313,7 @@ static void test_encode(int index, int generate, int debug) { "11111111010101000110010110111000001100011000100001011100101000111000111111101000101001" "11111111010101000101000111100100001110000101100010010100011110000100111111101000101001" }, - /* 3*/ { BARCODE_PDF417, UNICODE_MODE, 1, 1, "abcdefghijklmnopqrstuvwxyz ", 0, 19, 86, 1, "Text Compaction Lower", + /* 3*/ { BARCODE_PDF417, -1, UNICODE_MODE, 1, 1, "abcdefghijklmnopqrstuvwxyz ", 0, 19, 86, 1, "Text Compaction Lower", "11111111010101000110101000110000001101011001110000011101010111000000111111101000101001" "11111111010101000111110101001100001100000101110010011111010100011000111111101000101001" "11111111010101000110101011111000001111101011110110011010100111110000111111101000101001" @@ -333,14 +334,14 @@ static void test_encode(int index, int generate, int debug) { "11111111010101000111111001011101101010000001001111010010111001111110111111101000101001" "11111111010101000111011010000110001000100111001110011110110100111000111111101000101001" }, - /* 4*/ { BARCODE_PDF417, UNICODE_MODE, 1, 4, "0123456&\015\011,:#-.$/+%*=^ 789", 0, 5, 137, 1, "Text Compaction Mixed", + /* 4*/ { BARCODE_PDF417, -1, UNICODE_MODE, 1, 4, "0123456&\015\011,:#-.$/+%*=^ 789", 0, 5, 137, 1, "Text Compaction Mixed", "11111111010101000111101010111100001110101100111100010000110111001100110101111001111101010001110111000011101010011100000111111101000101001" "11111111010101000111111010100111001010001111000001011101101111001100110110011110010001110010000011010011111101010111000111111101000101001" "11111111010101000110101001111100001100111010000111011011110010110000100000101011110001101111101010000011101010011111100111111101000101001" "11111111010101000101011110011110001000010000100001010010011000011000110010000100110001000011000110010010101111101111100111111101000101001" "11111111010101000111010111000110001001111001001111010000101111101100100011110010111101001111110110111011101011100110000111111101000101001" }, - /* 5*/ { BARCODE_PDF417, UNICODE_MODE, 3, 2, ";<>@[\\]_'~!\015\011,:\012-.$/\"|*()?{", 0, 16, 103, 1, "Text Compaction Punctuation", + /* 5*/ { BARCODE_PDF417, -1, UNICODE_MODE, 3, 2, ";<>@[\\]_'~!\015\011,:\012-.$/\"|*()?{", 0, 16, 103, 1, "Text Compaction Punctuation", "1111111101010100011111010100111110111010110011110001000111011100100011110101011110000111111101000101001" "1111111101010100011111010100001100111111010101110001101011111101111011110101000100000111111101000101001" "1111111101010100011101010111111000101000001000111101011011001111000011010100001111100111111101000101001" @@ -358,26 +359,26 @@ static void test_encode(int index, int generate, int debug) { "1111111101010100011101000011111010111111010001101001011000010011100010010101111000000111111101000101001" "1111111101010100011001011011100000110011001100001101100100101100000011110010100011110111111101000101001" }, - /* 6*/ { BARCODE_PDF417, UNICODE_MODE, 2, 3, "12345678901234", 0, 5, 120, 1, "Numeric Compaction", + /* 6*/ { BARCODE_PDF417, -1, UNICODE_MODE, 2, 3, "12345678901234", 0, 5, 120, 1, "Numeric Compaction", "111111110101010001111010101111000011101010001110000100111101111010001001011100001110011111010101111100111111101000101001" "111111110101010001111110101000111011010000001110010111111011010011001111010100000010011111101010111000111111101000101001" "111111110101010001010100111100000010111000110011100101110011000011101110001111110101011101010001111110111111101000101001" "111111110101010001010111100111100010001100001100010100001100011101101110101100111100011010111100111110111111101000101001" "111111110101010001110101110000110011000000101110010110001001110000101011001000111111011101011100110000111111101000101001" }, - /* 7*/ { BARCODE_PDF417, UNICODE_MODE, 1, 4, "\177\177\177\177\177\177\177\177\177\177\177", 0, 4, 137, 1, "Byte Compaction", + /* 7*/ { BARCODE_PDF417, -1, UNICODE_MODE, 1, 4, "\177\177\177\177\177\177\177\177\177\177\177", 0, 4, 137, 1, "Byte Compaction", "11111111010101000111101010111100001101011011100000010000010000100010111001001100111101000010100001000011101010011100000111111101000101001" "11111111010101000111110101001100001110010000111011010100111110000110111101001100001101111101000100011011111101010111000111111101000101001" "11111111010101000110101001111100001010000001011110010100000010111100101000000101111001010000001011110011010100111110000111111101000101001" "11111111010101000101011110011110001010001000001000011011000010100000111000110001001101100111000110010010101111101111100111111101000101001" }, - /* 8*/ { BARCODE_PDF417, UNICODE_MODE, 1, 4, "\177\177\177\177\177\177\177\177\177\177\177\177", 0, 4, 137, 1, "Byte Compaction, mod 6 == 0 (924 emitted)", + /* 8*/ { BARCODE_PDF417, -1, UNICODE_MODE, 1, 4, "\177\177\177\177\177\177\177\177\177\177\177\177", 0, 4, 137, 1, "Byte Compaction, mod 6 == 0 (924 emitted)", "11111111010101000111101010111100001101011011100000011000111000110100111001001100111101000010100001000011101010011100000111111101000101001" "11111111010101000111110101001100001110010000111011010100111110000110111101001100001101111001010010000011111101010111000111111101000101001" "11111111010101000110101001111100001001110000100110010011000100001110101000011001111101101000101111100011010100111110000111111101000101001" "11111111010101000101011110011110001101000100011000010011000111001100110001100001000101110100010111000010101111101111100111111101000101001" }, - /* 9*/ { BARCODE_PDF417, UNICODE_MODE, -1, 5, "ABCDEF1234567890123\177\177\177\177VWXYZ", 0, 6, 154, 1, "Text, Numeric, Byte, Text", + /* 9*/ { BARCODE_PDF417, -1, UNICODE_MODE, -1, 5, "ABCDEF1234567890123\177\177\177\177VWXYZ", 0, 6, 154, 1, "Text, Numeric, Byte, Text", "1111111101010100011110101011110000110101110111100001111010101111000010100111001110000110100000101100001001111011110100011110101001111000111111101000101001" "1111111101010100011110101000010000111101011001100001010011110000100011111100011101010110000010111000101111001011011000011111101010111000111111101000101001" "1111111101010100011101010011111100110011111101100101010000001011110010100000010111100101000000101111001010000001011110010101000011110000111111101000101001" @@ -385,7 +386,7 @@ static void test_encode(int index, int generate, int debug) { "1111111101010100011010111000001000101111110101100001011111101011000011001011111001110111100100100100001011111101011000011101011100110000111111101000101001" "1111111101010100011111010111100110110111110110011001101001011111000010101110011111100100100001000111101011000000101110011110101111101100111111101000101001" }, - /* 10*/ { BARCODE_PDF417COMP, UNICODE_MODE, 1, 2, "PDF417 APK", 0, 6, 69, 0, "ISO 15438:2015 Figure G.1, same, BWIPP uses different encodation, same codeword count", + /* 10*/ { BARCODE_PDF417COMP, -1, UNICODE_MODE, 1, 2, "PDF417 APK", 0, 6, 69, 0, "ISO 15438:2015 Figure G.1, same, BWIPP uses different encodation, same codeword count", "111111110101010001111010101111000011010100001100000111011101100110001" "111111110101010001111010100010000011010000111000100111101000101000001" "111111110101010001110101011111100010110011011110000100111110011000101" @@ -393,7 +394,7 @@ static void test_encode(int index, int generate, int debug) { "111111110101010001111010111000111011011000001111010110010011101000001" "111111110101010001111010111101000011110100111101000110010010011111001" }, - /* 11*/ { BARCODE_PDF417COMP, UNICODE_MODE, 4, 4, "ABCDEFG", 0, 10, 103, 1, "", + /* 11*/ { BARCODE_PDF417COMP, -1, UNICODE_MODE, 4, 4, "ABCDEFG", 0, 10, 103, 1, "", "1111111101010100011101010011100000110101000011000001111010101111000010100111001110000110100000101100001" "1111111101010100011110101000000100110100000011100101011111101011000010111111010110000101111110101100001" "1111111101010100011010100111110000101111001100011001000001111010100010011111001100100111001011111001001" @@ -405,7 +406,7 @@ static void test_encode(int index, int generate, int debug) { "1111111101010100010100110011111000100110000110111101100111000010111010010001011110000110011111010001001" "1111111101010100010100011000001100110001101010000001100011000110011011001001101110000111110111110101001" }, - /* 12*/ { BARCODE_HIBC_PDF, UNICODE_MODE, -1, 3, "H123ABC01234567890D", 0, 8, 120, 0, "BWIPP uses different encodation, same codeword count but zint half-pad shorter", + /* 12*/ { BARCODE_HIBC_PDF, -1, UNICODE_MODE, -1, 3, "H123ABC01234567890D", 0, 8, 120, 0, "BWIPP uses different encodation, same codeword count but zint half-pad shorter", "111111110101010001111101010111110011101011001111000100000100010010001110001110100010011111010101111100111111101000101001" "111111110101010001111110101000111011110000010001010110101111110111101111100011101101011110101001000000111111101000101001" "111111110101010001010100111100000011111010111101100100001111000101001100101000011111011101010001111110111111101000101001" @@ -415,7 +416,7 @@ static void test_encode(int index, int generate, int debug) { "111111110101010001110100111011111010100110001100000110100011100111101111010010111100011101001110111110111111101000101001" "111111110101010001111101001011000011100001001100100111010000011001001111011000110100010101111110111000111111101000101001" }, - /* 13*/ { BARCODE_HIBC_PDF, UNICODE_MODE, 1, 3, "A123BJC5D6E71", 0, 6, 120, 1, "BWIPP example", + /* 13*/ { BARCODE_HIBC_PDF, -1, UNICODE_MODE, 1, 3, "A123BJC5D6E71", 0, 6, 120, 1, "BWIPP example", "111111110101010001111010101111000011110101101111100100000100010010001000011011100110011111010101111100111111101000101001" "111111110101010001111010100010000011110000010001010110101111110111101111000001000101011111101010111000111111101000101001" "111111110101010001010100111100000010110001100011110101111110111101101000111100011011010101000111100000111111101000101001" @@ -423,7 +424,7 @@ static void test_encode(int index, int generate, int debug) { "111111110101010001111010111000111011010111110011100110100000011100101111110101000111011101011100110000111111101000101001" "111111110101010001111101011110110010011100110011100100011110110011001011001011100000011110101111000100111111101000101001" }, - /* 14*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 1, "ABCDEFGHIJKLMNOPQRSTUV", 0, 20, 38, 1, "ISO 24728:2006 Figure 1 1st 1x20, same", + /* 14*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 1, "ABCDEFGHIJKLMNOPQRSTUV", 0, 20, 38, 1, "ISO 24728:2006 Figure 1 1st 1x20, same", "11110101001000011000110010011110101001" "11100101001111110101011100011100101001" "11101101001010011001111100011101101001" @@ -445,7 +446,7 @@ static void test_encode(int index, int generate, int debug) { "11011101001111011111011010011011101001" "11011001001100010001110100011011001001" }, - /* 15*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 2, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD", 0, 20, 55, 1, "ISO 24728:2006 Figure 1 2nd 2x20, same", + /* 15*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 2, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD", 0, 20, 55, 1, "ISO 24728:2006 Figure 1 2nd 2x20, same", "1111010100100001100011001001111010101111000011110101001" "1110010100110101111110111101111101000100110011100101001" "1110110100101101100111100001011001110011111011101101001" @@ -467,7 +468,7 @@ static void test_encode(int index, int generate, int debug) { "1101110100111010110011110001000001001101100011011101001" "1101100100111100110110100001001001111001000011011001001" }, - /* 16*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 3, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN", 0, 20, 82, 1, "ISO 24728:2006 Figure 1 3rd 3x20", + /* 16*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 3, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN", 0, 20, 82, 1, "ISO 24728:2006 Figure 1 3rd 3x20", "1100100010100001100011001001011110010111101010111100001010011100111000011100101101" "1110100010111110100010011001011110110101000011111001101001011110010000011000101101" "1110110010111100010111101001001110110110111011001111001001100001000111011000101001" @@ -489,7 +490,7 @@ static void test_encode(int index, int generate, int debug) { "1111010100101111011110100001011001000111110011010111101011110111110110011010000101" "1110010100110010001111011001011001100111000010111011001110001011100110011011000101" }, - /* 17*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 4, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZAB", 0, 20, 99, 1, "ISO 24728:2006 Figure 1 4th 4x20, same", + /* 17*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 4, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZAB", 0, 20, 99, 1, "ISO 24728:2006 Figure 1 4th 4x20, same", "110010001010000110001100100111101010111100001011110010101001110011100001101000001011000011100101101" "111010001010100001111100110100101111001000001011110110111011011110011001101100111100100011000101101" "111011001010011000010001110110011101000011101001110110110111100101100001000001010111100011000101001" @@ -511,7 +512,7 @@ static void test_encode(int index, int generate, int debug) { "111101010011100011101010000110001011101111001011001000111110111101011001100101110111100011010000101" "111001010010001000001111010111100010100001001011001100100111101101111101001110100111110011011000101" }, - /* 18*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 1, "123456789012345", 0, 14, 38, 1, "Number Compaction", + /* 18*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 1, "123456789012345", 0, 14, 38, 1, "Number Compaction", "11101110101011111101001100011101110101" "11100110101110101011111100011100110101" "11110110101000001011001100011110110101" @@ -527,7 +528,7 @@ static void test_encode(int index, int generate, int debug) { "11100101001101011110000110011100101001" "11101101001101000111111001011101101001" }, - /* 19*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 2, "\177\177\177", 0, 8, 55, 1, "Byte Compaction", + /* 19*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 2, "\177\177\177", 0, 8, 55, 1, "Byte Compaction", "1100100010100000100001000101010000010010000011001000101" "1110100010111110100010001101111101000100011011101000101" "1110110010110001111100100101100011111001001011101100101" @@ -537,7 +538,7 @@ static void test_encode(int index, int generate, int debug) { "1100111010111001111001100101000001001101100011001110101" "1110111010111000101111011101110001000011010011101110101" }, - /* 20*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 2, "\177\177\177\177\177\177", 0, 8, 55, 1, "Byte Compaction, mod 6 == 0 (924 emitted)", + /* 20*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 2, "\177\177\177\177\177\177", 0, 8, 55, 1, "Byte Compaction, mod 6 == 0 (924 emitted)", "1100100010110001110001101001110010011001111011001000101" "1110100010100010001111010001110010000111011011101000101" "1110110010101000011001111101101000101111100011101100101" @@ -547,7 +548,7 @@ static void test_encode(int index, int generate, int debug) { "1100111010100100010000100001110111101100001011001110101" "1110111010111110011010100001101100001111010011101110101" }, - /* 21*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 3, "ABCDEFG\177\177\177", 0, 8, 82, 1, "Text & Byte Compaction", + /* 21*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 3, "ABCDEFG\177\177\177", 0, 8, 82, 1, "Text & Byte Compaction", "1100111010100001100011001001000010110111101010111100001010011100111000011001110101" "1110111010111110100010011001000010010110100000011100101101111110101110011101110101" "1110011010101000000101111001000011010101000000101111001010000001011110011100110101" @@ -557,7 +558,7 @@ static void test_encode(int index, int generate, int debug) { "1100001010111110111010111001001100010110011100011000101101100001100110011000010101" "1100011010110100011100001001001110010110110000111101001100011011110010011000110101" }, - /* 22*/ { BARCODE_MICROPDF417, UNICODE_MODE, -1, 4, "\177\177\177abcdefgh1234567890123", 0, 8, 99, 1, "Byte & Text & Numeric Compaction", + /* 22*/ { BARCODE_MICROPDF417, -1, UNICODE_MODE, -1, 4, "\177\177\177abcdefgh1234567890123", 0, 8, 99, 1, "Byte & Text & Numeric Compaction", "110011101010000010000100010101000001001000001000010110101000001001000001010000010010000011001110101" "111011101010111111010110000110000010111001001000010010111101011100111001110100111001100011101110101" "111001101011111001011110110101100110011110001000011010100001111000101001111110101100010011100110101" @@ -567,7 +568,7 @@ static void test_encode(int index, int generate, int debug) { "110000101011000011010000100100000101101100001001100010101110111110111001111001110010110011000010101" "110001101011101110111100010100100011110100001001110010100000101111000101111001010010000011000110101" }, - /* 23*/ { BARCODE_HIBC_MICPDF, UNICODE_MODE, -1, 4, "H123ABC01234567890D", 0, 8, 99, 0, "BWIPP uses different encodation, same codeword count but zint full-pad shorter", + /* 23*/ { BARCODE_HIBC_MICPDF, -1, UNICODE_MODE, -1, 4, "H123ABC01234567890D", 0, 8, 99, 0, "BWIPP uses different encodation, same codeword count but zint full-pad shorter", "110011101010000110001100100100000100010010001000010110111000111010001001000001001100011011001110101" "111011101011010111111011110111110001110110101000010010111101011100111001011111101001100011101110101" "111001101011001010000111110100011110101000001000011010100111110001101001011011000111100011100110101" @@ -577,7 +578,7 @@ static void test_encode(int index, int generate, int debug) { "110000101010110110001000000111000101100111101001100010110111101110000101100010101100000011000010101" "110001101011110110000011010111100100001101101001110010101101011111100001111001000110011011000110101" }, - /* 24*/ { BARCODE_HIBC_MICPDF, UNICODE_MODE, -1, 1, "/EAH783", 0, 17, 38, 1, "HIBC Provider Applications Standard (PAS) example", + /* 24*/ { BARCODE_HIBC_MICPDF, -1, UNICODE_MODE, -1, 1, "/EAH783", 0, 17, 38, 1, "HIBC Provider Applications Standard (PAS) example", "11001101001100011111001001011001101001" "11011101001000001000100100011011101001" "11011001001000100011110100011011001001" @@ -596,6 +597,31 @@ static void test_encode(int index, int generate, int debug) { "11010000101101100100001111011010000101" "11011000101110111000100010011011000101" }, + /* 25*/ { BARCODE_PDF417, 9, DATA_MODE, -1, -1, "\342", 0, 7, 103, 1, "β", + "1111111101010100011111010101111100110101000110000001100011100011001011110101011110000111111101000101001" + "1111111101010100011111010100011000111110101000011001011111100100011011110101001000000111111101000101001" + "1111111101010100011101010111111000110110010011110001100011111001001011010100011111000111111101000101001" + "1111111101010100011010111100111110100110011100110001010001100001100010101111001111000111111101000101001" + "1111111101010100011010111000010000110110001111000101111110010010111011110101110011100111111101000101001" + "1111111101010100011110101111010000100011110001000101000110010111000011110101111000010111111101000101001" + "1111111101010100011101001110111110101110001110001001010001101100000011010011101111000111111101000101001" + }, + /* 26*/ { BARCODE_MICROPDF417, 9, DATA_MODE, -1, 1, "\342\343", 0, 14, 38, 1, "βγ", + "11101110101001111110010110011101110101" + "11100110101101010000111110011100110101" + "11110110101000001000010001011110110101" + "11110010101111001011001100011110010101" + "11100010101110110010011111011100010101" + "11000010101000011000110010011000010101" + "11000110101011111101011000011000110101" + "11000100101001111000101000011000100101" + "11100100101000100000101000011100100101" + "11110100101101110010111111011110100101" + "11110101101101100101111000011110101101" + "11110101001101011100111100011110101001" + "11100101001011100101111100011100101001" + "11101101001101001001111100011101101001" + }, }; int data_size = sizeof(data) / sizeof(struct item); @@ -610,24 +636,14 @@ static void test_encode(int index, int generate, int debug) { struct zint_symbol *symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - symbol->symbology = data[i].symbology; - symbol->input_mode = data[i].input_mode; - if (data[i].option_1 != -1) { - symbol->option_1 = data[i].option_1; - } - if (data[i].option_2 != -1) { - symbol->option_2 = data[i].option_2; - } - symbol->debug |= debug; - - int length = strlen(data[i].data); + int length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].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); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); if (generate) { - printf(" /*%3d*/ { %s, %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", - i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, + printf(" /*%3d*/ { %s, %d, %s, %d, %d, \"%s\", %s, %d, %d, %d, \"%s\",\n", + i, testUtilBarcodeName(data[i].symbology), data[i].eci, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)), testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); testUtilModulesDump(symbol, " ", "\n"); @@ -641,7 +657,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) { if (!data[i].bwipp_cmp) { if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment); } else { diff --git a/backend/tests/test_postal.c b/backend/tests/test_postal.c index 6638ba6d..e766cf33 100644 --- a/backend/tests/test_postal.c +++ b/backend/tests/test_postal.c @@ -406,7 +406,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_raster.c b/backend/tests/test_raster.c index 3cc32e1a..57c232de 100644 --- a/backend/tests/test_raster.c +++ b/backend/tests/test_raster.c @@ -219,7 +219,7 @@ static void test_buffer(int index, int generate, int debug) { /* 95*/ { BARCODE_HIBC_MICPDF, "1234567890", "", 28, 14, 38, 76, 56 }, /* 96*/ { BARCODE_HIBC_BLOCKF, "1234567890", "", 30, 3, 101, 242, 64 }, /* 97*/ { BARCODE_HIBC_AZTEC, "1234567890AB", "", 19, 19, 19, 38, 38 }, - /* 98*/ { BARCODE_DOTCODE, "ABC", "", 11, 11, 16, 32, 22 }, + /* 98*/ { BARCODE_DOTCODE, "ABC", "", 11, 11, 16, 33, 23 }, /* 99*/ { BARCODE_HANXIN, "1234567890AB", "", 23, 23, 23, 46, 46 }, /*100*/ { BARCODE_MAILMARK, "01000000000000000AA00AA0A", "", 10, 3, 155, 310, 20 }, /*101*/ { BARCODE_AZRUNE, "255", "", 11, 11, 11, 22, 22 }, @@ -660,35 +660,41 @@ static void test_output_options(int index, int debug) { /* 27*/ { BARCODE_QRCODE, 5, 6, BARCODE_BIND, 0, "A123", 0, 21, 21, 21, 62, 66, 1, 0, 0 }, /* 28*/ { BARCODE_QRCODE, 5, 6, BARCODE_BIND, 0, "A123", 0, 21, 21, 21, 62, 66, 0, 12, 0 }, /* 29*/ { BARCODE_QRCODE, 5, 6, BARCODE_BOX, 0, "A123", 0, 21, 21, 21, 86, 66, 1, 12, 0 }, - /* 30*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 42, 42, 1, 0, 0 }, - /* 31*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 42, 42, 0, 1, 1 }, - /* 32*/ { BARCODE_QRCODE, -1, 4, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 42, 42, 1, 0, 0 }, - /* 33*/ { BARCODE_QRCODE, -1, 4, BARCODE_BIND | BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 42, 58, -1, -1, -1 }, // TODO: fix (bind/box in dotty mode) - /* 34*/ { BARCODE_QRCODE, 1, 4, BARCODE_BOX | BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 62, 58, -1, -1, -1 }, // TODO: fix (bind/box in dotty mode) - /* 35*/ { BARCODE_QRCODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 21, 21, 21, 42, 42, 0, 2, 2 }, - /* 36*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE | OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 21, 21, 21, 42, 42, 1, 0, 0 }, - /* 37*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE | OUT_BUFFER_INTERMEDIATE, 180, "A123", 0, 21, 21, 21, 42, 42, 0, 40, 1 }, - /* 38*/ { BARCODE_MAXICODE, -1, -1, -1, 0, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, - /* 39*/ { BARCODE_MAXICODE, -1, -1, -1, 270, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, - /* 40*/ { BARCODE_MAXICODE, -1, 5, -1, 0, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, - /* 41*/ { BARCODE_MAXICODE, -1, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 300, 320, 1, 0, 0 }, - /* 42*/ { BARCODE_MAXICODE, -1, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 300, 320, 0, 10, 0 }, - /* 43*/ { BARCODE_MAXICODE, -1, 5, BARCODE_BOX, 0, "A123", 0, 165, 33, 30, 320, 320, 1, 10, 0 }, - /* 44*/ { BARCODE_MAXICODE, -1, -1, -1, 0, "A123", 0, 165, 33, 30, 300, 300, 1, 0, 14 }, - /* 45*/ { BARCODE_MAXICODE, 6, -1, -1, 0, "A123", 0, 165, 33, 30, 324, 300, 0, 0, 14 }, - /* 46*/ { BARCODE_MAXICODE, 6, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 324, 320, 1, 10, 25 }, - /* 47*/ { BARCODE_MAXICODE, 6, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 324, 320, 0, 10, 9 }, - /* 48*/ { BARCODE_MAXICODE, 6, 5, BARCODE_BOX, 0, "A123", 0, 165, 33, 30, 344, 320, 1, 10, 9 }, - /* 49*/ { BARCODE_MAXICODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", ZINT_ERROR_INVALID_OPTION, -1, -1, -1, -1, -1, -1, -1, -1 }, - /* 50*/ { BARCODE_MAXICODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, - /* 51*/ { BARCODE_MAXICODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 165, 33, 30, 300, 300, 1, 0, 14 }, - /* 52*/ { BARCODE_MAXICODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 270, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, - /* 53*/ { BARCODE_ITF14, -1, -1, -1, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, - /* 54*/ { BARCODE_ITF14, -1, -1, -1, 90, "123", 0, 50, 1, 135, 136, 330, 1, 0, 110 }, - /* 55*/ { BARCODE_ITF14, -1, 0, -1, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, - /* 56*/ { BARCODE_ITF14, -1, 0, BARCODE_BOX, 0, "123", 0, 50, 1, 135, 310, 116, 0, 100, 0 }, - /* 57*/ { BARCODE_ITF14, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, - /* 58*/ { BARCODE_ITF14, -1, -1, OUT_BUFFER_INTERMEDIATE, 90, "123", 0, 50, 1, 135, 136, 330, 1, 0, 110 }, + /* 30*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 43, 1, 1, 1 }, + /* 31*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 43, 0, 2, 2 }, + /* 32*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 43, 1, 41, 1 }, + /* 33*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 43, 0, 40, 2 }, + /* 34*/ { BARCODE_QRCODE, -1, 4, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 43, 1, 1, 1 }, + /* 35*/ { BARCODE_QRCODE, -1, 4, BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 43, 0, 2, 2 }, + /* 36*/ { BARCODE_QRCODE, -1, 4, BARCODE_BIND | BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 43, 59, -1, -1, -1 }, // TODO: fix (bind/box in dotty mode) + /* 37*/ { BARCODE_QRCODE, 1, 4, BARCODE_BOX | BARCODE_DOTTY_MODE, 0, "A123", 0, 21, 21, 21, 63, 59, -1, -1, -1 }, // TODO: fix (bind/box in dotty mode) + /* 38*/ { BARCODE_QRCODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 21, 21, 21, 42, 42, 1, 1, 1 }, + /* 39*/ { BARCODE_QRCODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 21, 21, 21, 42, 42, 0, 2, 2 }, + /* 40*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE | OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 21, 21, 21, 43, 43, 1, 1, 1 }, + /* 41*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE | OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 21, 21, 21, 43, 43, 0, 2, 2 }, + /* 42*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE | OUT_BUFFER_INTERMEDIATE, 180, "A123", 0, 21, 21, 21, 43, 43, 1, 41, 1 }, + /* 43*/ { BARCODE_QRCODE, -1, -1, BARCODE_DOTTY_MODE | OUT_BUFFER_INTERMEDIATE, 180, "A123", 0, 21, 21, 21, 43, 43, 0, 40, 2 }, + /* 44*/ { BARCODE_MAXICODE, -1, -1, -1, 0, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, + /* 45*/ { BARCODE_MAXICODE, -1, -1, -1, 270, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, + /* 46*/ { BARCODE_MAXICODE, -1, 5, -1, 0, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, + /* 47*/ { BARCODE_MAXICODE, -1, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 300, 320, 1, 0, 0 }, + /* 48*/ { BARCODE_MAXICODE, -1, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 300, 320, 0, 10, 0 }, + /* 49*/ { BARCODE_MAXICODE, -1, 5, BARCODE_BOX, 0, "A123", 0, 165, 33, 30, 320, 320, 1, 10, 0 }, + /* 50*/ { BARCODE_MAXICODE, -1, -1, -1, 0, "A123", 0, 165, 33, 30, 300, 300, 1, 0, 14 }, + /* 51*/ { BARCODE_MAXICODE, 6, -1, -1, 0, "A123", 0, 165, 33, 30, 324, 300, 0, 0, 14 }, + /* 52*/ { BARCODE_MAXICODE, 6, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 324, 320, 1, 10, 25 }, + /* 53*/ { BARCODE_MAXICODE, 6, 5, BARCODE_BIND, 0, "A123", 0, 165, 33, 30, 324, 320, 0, 10, 9 }, + /* 54*/ { BARCODE_MAXICODE, 6, 5, BARCODE_BOX, 0, "A123", 0, 165, 33, 30, 344, 320, 1, 10, 9 }, + /* 55*/ { BARCODE_MAXICODE, -1, -1, BARCODE_DOTTY_MODE, 0, "A123", ZINT_ERROR_INVALID_OPTION, -1, -1, -1, -1, -1, -1, -1, -1 }, + /* 56*/ { BARCODE_MAXICODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, + /* 57*/ { BARCODE_MAXICODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "A123", 0, 165, 33, 30, 300, 300, 1, 0, 14 }, + /* 58*/ { BARCODE_MAXICODE, -1, -1, OUT_BUFFER_INTERMEDIATE, 270, "A123", 0, 165, 33, 30, 300, 300, 0, 0, 0 }, + /* 59*/ { BARCODE_ITF14, -1, -1, -1, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, + /* 60*/ { BARCODE_ITF14, -1, -1, -1, 90, "123", 0, 50, 1, 135, 136, 330, 1, 0, 110 }, + /* 61*/ { BARCODE_ITF14, -1, 0, -1, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, + /* 62*/ { BARCODE_ITF14, -1, 0, BARCODE_BOX, 0, "123", 0, 50, 1, 135, 310, 116, 0, 100, 0 }, + /* 63*/ { BARCODE_ITF14, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, + /* 64*/ { BARCODE_ITF14, -1, -1, OUT_BUFFER_INTERMEDIATE, 90, "123", 0, 50, 1, 135, 136, 330, 1, 0, 110 }, }; int data_size = ARRAY_SIZE(data); diff --git a/backend/tests/test_rss.c b/backend/tests/test_rss.c index 6999cf49..08f91903 100644 --- a/backend/tests/test_rss.c +++ b/backend/tests/test_rss.c @@ -164,7 +164,7 @@ static void test_binary_div_modulo_divisor(int index, int generate, int debug) { ret = ZBarcode_Buffer_Vector(symbol, 0); assert_zero(ret, "i:%d ZBarcode_Buffer_Vector ret %d != 0\n", i, ret); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -1, text, length, symbol->primary, bwipp_buf, sizeof(bwipp_buf)); assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret); @@ -663,7 +663,7 @@ static void test_examples(int index, int generate, int debug) { ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row); assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { 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); diff --git a/backend/tests/test_telepen.c b/backend/tests/test_telepen.c index 148040fb..d31fd9e0 100644 --- a/backend/tests/test_telepen.c +++ b/backend/tests/test_telepen.c @@ -258,7 +258,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, -1, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, -1, -1, debug)) { ret = testUtilBwipp(i, symbol, -1, -1, -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); diff --git a/backend/tests/test_upcean.c b/backend/tests/test_upcean.c index fe848226..89ca2d0b 100644 --- a/backend/tests/test_upcean.c +++ b/backend/tests/test_upcean.c @@ -696,7 +696,7 @@ static void test_encode(int index, int generate, int debug) { 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); - if (do_bwipp && testUtilCanBwipp(symbol->symbology, -1, data[i].option_2, -1, debug)) { + if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { 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); diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index 32165ca6..1db41a86 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -1427,7 +1427,7 @@ int testUtilVerifyLibreOffice(char *filename, int debug) { char cmd[512 + 128]; char svg[512]; char *slash, *dot; - char buf[32768]; + char buf[16384]; char *b = buf, *be = buf + sizeof(buf) - 1; FILE *fp; int len; @@ -1536,7 +1536,7 @@ int testUtilVerifyVnu(char *filename, int debug) { return system(buf); } -static const char *testUtilBwippName(int symbology, int option_1, int option_2, int option_3, int *linear_row_height, int *gs1_cvt) { +static const char *testUtilBwippName(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug, int *linear_row_height, int *gs1_cvt) { struct item { const char *name; int define; @@ -1619,7 +1619,7 @@ static const char *testUtilBwippName(int symbology, int option_1, int option_2, { "", BARCODE_AUSREDIRECT, 68, 0, 0, 0, 0, 0, }, { "isbn", BARCODE_ISBNX, 69, 0, 1, 0, 0, 1 /*gs1_cvt*/, }, { "royalmail", BARCODE_RM4SCC, 70, 0, 0, 0, 0, 0, }, - { "datamatrix", BARCODE_DATAMATRIX, 71, 0, 0, 0, 0, 0, }, + { "datamatrix", BARCODE_DATAMATRIX, 71, 0, 1, 1, 0, 0, }, { "ean14", BARCODE_EAN14, 72, 0, 0, 0, 0, 1 /*gs1_cvt*/, }, { "code39", BARCODE_VIN, 73, 0, 0, 0, 0, 0, }, { "codablockf", BARCODE_CODABLOCKF, 74, 1, 1, 0, 10 /*linear_row_height*/, 0, }, @@ -1640,7 +1640,7 @@ static const char *testUtilBwippName(int symbology, int option_1, int option_2, { "itf14", BARCODE_ITF14, 89, 0, 0, 0, 0, 0, }, { "kix", BARCODE_KIX, 90, 0, 0, 0, 0, 0, }, { "", -1, 91, 0, 0, 0, 0, 0, }, - { "azteccode", BARCODE_AZTEC, 92, 0, 0, 0, 0, 0, }, + { "azteccode", BARCODE_AZTEC, 92, 0, 1, 0, 0, 0, }, { "daft", BARCODE_DAFT, 93, 0, 0, 0, 0, 0, }, { "", -1, 94, 0, 0, 0, 0, 0, }, { "", -1, 95, 0, 0, 0, 0, 0, }, @@ -1650,7 +1650,7 @@ static const char *testUtilBwippName(int symbology, int option_1, int option_2, { "hibccode39", BARCODE_HIBC_39, 99, 0, 0, 0, 0, 0, }, { "", -1, 100, 0, 0, 0, 0, 0, }, { "", -1, 101, 0, 0, 0, 0, 0, }, - { "hibcdatamatrix", BARCODE_HIBC_DM, 102, 0, 0, 0, 0, 0, }, + { "hibcdatamatrix", BARCODE_HIBC_DM, 102, 0, 1, 1, 0, 0, }, { "", -1, 103, 0, 0, 0, 0, 0, }, { "hibcqrcode", BARCODE_HIBC_QR, 104, 0, 0, 0, 0, 0, }, { "", -1, 105, 0, 0, 0, 0, 0, }, @@ -1660,7 +1660,7 @@ static const char *testUtilBwippName(int symbology, int option_1, int option_2, { "", -1, 109, 0, 0, 0, 0, 0, }, { "hibccodablockf", BARCODE_HIBC_BLOCKF, 110, 1, 1, 0, 10 /*linear_row_height*/, 0, }, { "", -1, 111, 0, 0, 0, 0, 0, }, - { "hibcazteccode", BARCODE_HIBC_AZTEC, 112, 0, 0, 0, 0, 0, }, + { "hibcazteccode", BARCODE_HIBC_AZTEC, 112, 1, 0, 1, 0, 0, }, { "", -1, 113, 0, 0, 0, 0, 0, }, { "", -1, 114, 0, 0, 0, 0, 0, }, { "dotcode", BARCODE_DOTCODE, 115, 0, 0, 0, 0, 0, }, @@ -1697,27 +1697,43 @@ static const char *testUtilBwippName(int symbology, int option_1, int option_2, }; static const int data_size = ARRAY_SIZE(data); + int symbology = symbol->symbology; + int gs1 = (symbol->input_mode & 0x07) == GS1_MODE; + if (symbology < 0 || symbology >= data_size) { - return NULL; + fprintf(stderr, "testUtilBwippName: unknown symbology (%d)\n", symbology); + abort(); } if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { // Self-check fprintf(stderr, "testUtilBwippName: data table out of sync (%d)\n", symbology); abort(); } if (data[symbology].name[0] == '\0') { + if (debug & ZINT_DEBUG_TEST_PRINT) { + printf("i:%d %s no BWIPP mapping\n", index, testUtilBarcodeName(symbology)); + } return NULL; } if ((option_1 != -1 && !data[symbology].can_option_1) || (option_2 != -1 && !data[symbology].can_option_2) || (option_3 != -1 && !data[symbology].can_option_3)) { + if (debug & ZINT_DEBUG_TEST_PRINT) { + printf("i:%d %s not BWIPP compatible, options not supported, option_1 %d, option_2 %d, option_3 %d\n", index, testUtilBarcodeName(symbology), option_1, option_2, option_3); + } return NULL; } if (symbology == BARCODE_CODE11) { if (option_2 != 1 && option_2 != 2) { /* 2 check digits (Zint default) not supported */ + if (debug & ZINT_DEBUG_TEST_PRINT) { + printf("i:%d %s not BWIPP compatible, 2 check digits not supported, option_1 %d, option_2 %d\n", index, testUtilBarcodeName(symbology), option_1, option_2); + } return NULL; } } else if (symbology == BARCODE_CODABLOCKF || symbology == BARCODE_HIBC_BLOCKF) { if (option_1 == 1) { /* Single row i.e. CODE128 not supported */ + if (debug & ZINT_DEBUG_TEST_PRINT) { + printf("i:%d %s not BWIPP compatible, single row not supported, option_1 %d\n", index, testUtilBarcodeName(symbology), option_1); + } return NULL; } } @@ -1728,19 +1744,31 @@ static const char *testUtilBwippName(int symbology, int option_1, int option_2, if (gs1_cvt) { *gs1_cvt = data[symbology].gs1_cvt; } + if (gs1) { + if (symbology == BARCODE_DATAMATRIX) { + if (symbol->output_options & GS1_GS_SEPARATOR) { /* Not supported */ + if (debug & ZINT_DEBUG_TEST_PRINT) { + printf("i:%d %s not BWIPP compatible, GS1_GS_SEPARATOR not supported\n", index, testUtilBarcodeName(symbology)); + } + return NULL; + } + if (gs1_cvt) { + *gs1_cvt = 1; + } + return "gs1datamatrix"; + } else if (symbology == BARCODE_AZTEC) { + if (debug & ZINT_DEBUG_TEST_PRINT) { + printf("i:%d %s not BWIPP compatible, GS1_MODE not supported\n", index, testUtilBarcodeName(symbology)); + } + return NULL; + } + } return data[symbology].name; } -int testUtilCanBwipp(int symbology, int option_1, int option_2, int option_3, int debug) { - if (testUtilBwippName(symbology, option_1, option_2, option_3, NULL, NULL) != NULL) { - return 1; - } - if (debug & ZINT_DEBUG_TEST_PRINT) { - printf("testUtilCanBwipp: not supported %s, option_1 %d, option_2 %d, option_3 %d\n", testUtilBarcodeName(symbology), option_1, option_2, option_3); - } - - return 0; +int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug) { + return testUtilBwippName(index, symbol, option_1, option_2, option_3, debug, NULL, NULL) != NULL; } static void testUtilBwippCvtGS1Data(char *bwipp_data, int upcean, int *addon_posn) { @@ -1763,21 +1791,59 @@ static void testUtilBwippCvtGS1Data(char *bwipp_data, int upcean, int *addon_pos } } -static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const char *data, int length, int *parse) { +static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const char *data, int length, int zint_escape_mode, int eci, int *parse, int *parsefnc) { char *b = bwipp_data; char *be = b + bwipp_data_size; unsigned char *d = (unsigned char *) data; unsigned char *de = (unsigned char *) data + length; - *parse = 0; + *parse = *parsefnc = 0; + + if (eci) { + sprintf(bwipp_data, "^ECI%06d", eci); + *parsefnc = 1; + b = bwipp_data + 10; + } while (b < be && d < de) { /* Have to escape double quote otherwise Ghostscript gives "Unterminated quote in @-file" for some reason */ /* Escape single quote also to avoid having to do proper shell escaping TODO: proper shell escaping */ if (*d < 0x20 || *d >= 0x7F || *d == '^' || *d == '"' || *d == '\'') { + if (b + 4 >= be) { + fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n"); + return NULL; + } sprintf(b, "^%03u", *d++); b += 4; *parse = 1; + } else if (zint_escape_mode && *d == '\\' && d + 1 < de) { + int val; + switch (*++d) { + case '0': val = 0x00; /* Null */ break; + case 'E': val = 0x04; /* End of Transmission */ break; + case 'a': val = 0x07; /* Bell */ break; + case 'b': val = 0x08; /* Backspace */ break; + case 't': val = 0x09; /* Horizontal tab */ break; + case 'n': val = 0x0a; /* Line feed */ break; + case 'v': val = 0x0b; /* Vertical tab */ break; + case 'f': val = 0x0c; /* Form feed */ break; + case 'r': val = 0x0d; /* Carriage return */ break; + case 'e': val = 0x1b; /* Escape */ break; + case 'G': val = 0x1d; /* Group Separator */ break; + case 'R': val = 0x1e; /* Record Separator */ break; + //case 'x': val = 0; /* TODO: implement */ break; + case '\\': val = '\\'; break; + //case 'u': val = 0; /* TODO: implement */ break; + default: fprintf(stderr, "testUtilBwippEscape: unknown escape %c\n", *d); return NULL; break; + } + if (b + 4 >= be) { + fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n"); + return NULL; + } + sprintf(b, "^%03d", val); + b += 4; + d++; + *parse = 1; } else { *b++ = *d++; } @@ -1838,7 +1904,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int char *b = buffer; char *be = buffer + buffer_size; int r, h; - int parse; + int parse, parsefnc; int upcean = is_extendable(symbology); int upca = symbology == BARCODE_UPCA || symbology == BARCODE_UPCA_CHK || symbology == BARCODE_UPCA_CC; @@ -1846,7 +1912,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int bwipp_data[0] = bwipp_opts_buf[0] = '\0'; - bwipp_barcode = testUtilBwippName(symbology, option_1, option_2, option_3, &linear_row_height, &gs1_cvt); + bwipp_barcode = testUtilBwippName(index, symbol, option_1, option_2, option_3, 0, &linear_row_height, &gs1_cvt); if (!bwipp_barcode) { fprintf(stderr, "i:%d testUtilBwipp: no mapping for %s, option_1 %d, option_2 %d, option_3 %d\n", index, testUtilBarcodeName(symbology), option_1, option_2, option_3); return -1; @@ -1924,11 +1990,18 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } } } else { - testUtilBwippEscape(bwipp_data, sizeof(bwipp_data), data, data_len, &parse); + int eci = symbol->eci >= 3 && ZBarcode_Cap(symbology, ZINT_CAP_ECI) ? symbol->eci : 0; + if (testUtilBwippEscape(bwipp_data, sizeof(bwipp_data), data, data_len, symbol->input_mode & ESCAPE_MODE, eci, &parse, &parsefnc) == NULL) { + return -1; + } if (parse) { sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparse", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } + if (parsefnc) { + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparsefnc", strlen(bwipp_opts_buf) ? " " : ""); + bwipp_opts = bwipp_opts_buf; + } if (symbology == BARCODE_CODE93) { sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); @@ -2010,12 +2083,69 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int for (r = 0; r < symbol->rows; r++) bwipp_row_height[r] = 8; /* Change from 10 */ sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%ssepheight=0", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; + } else if (symbology == BARCODE_AZTEC || symbology == BARCODE_HIBC_AZTEC) { + int compact = 0; + if (option_1 >= 1 && option_1 <= 4) { + int eclevel; + if (option_1 == 1) { + eclevel = 10; + } else if (option_1 == 2) { + eclevel = 23; + } else if (option_1 == 3) { + eclevel = 36; + } else { + eclevel = 50; + } + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%seclevel=%d", strlen(bwipp_opts_buf) ? " " : "", eclevel); + bwipp_opts = bwipp_opts_buf; + } + if (option_2 >= 1) { + int layers; + if (option_2 <= 4) { + compact = 1; + layers = option_2; + } else { + layers = option_2 - 4; + } + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%slayers=%d", strlen(bwipp_opts_buf) ? " " : "", layers); + bwipp_opts = bwipp_opts_buf; + } + if (symbol->output_options & READER_INIT) { + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sreaderinit", strlen(bwipp_opts_buf) ? " " : ""); + bwipp_opts = bwipp_opts_buf; + } + if (symbology == BARCODE_HIBC_AZTEC) { + compact = 1; + } + if (compact) { + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sformat=compact", strlen(bwipp_opts_buf) ? " " : ""); + bwipp_opts = bwipp_opts_buf; + } + } + } + + if (symbology == BARCODE_DATAMATRIX || symbology == BARCODE_HIBC_DM) { + #include "../dmatrix.h" + (void)matrixrsblock; (void)matrixdatablock; (void)matrixbytes; (void)matrixFW; (void)matrixFH; + (void)isDMRE; (void)text_value; (void)text_shift; (void)c40_value; (void)c40_shift; + + if (option_2 >= 1 && option_2 <= (int) sizeof(intsymbol)) { + int idx = intsymbol[option_2 - 1]; + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%srows=%d columns=%d", strlen(bwipp_opts_buf) ? " " : "", matrixH[idx], matrixW[idx]); + bwipp_opts = bwipp_opts_buf; + } + if (option_3 != DM_SQUARE && symbol->width != symbol->height) { + sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sformat=rectangle", strlen(bwipp_opts_buf) ? " " : ""); + bwipp_opts = bwipp_opts_buf; + } + if (option_3 != -1) { + bwipp_opts = bwipp_opts_buf; } } } if ((option_1 != -1 || option_2 != -1 || option_3 != -1) && !bwipp_opts) { - fprintf(stderr, "i:%d testUtilBwipp: no mapping option_1 %d, option_2 %d, option_3 %d for symbology %s\n", index, option_1, option_2, option_3, testUtilBarcodeName(symbology)); + fprintf(stderr, "i:%d testUtilBwipp: no BWIPP options set option_1 %d, option_2 %d, option_3 %d for symbology %s\n", index, option_1, option_2, option_3, testUtilBarcodeName(symbology)); return -1; } diff --git a/backend/tests/testcommon.h b/backend/tests/testcommon.h index 4d4de826..7b04b3dc 100644 --- a/backend/tests/testcommon.h +++ b/backend/tests/testcommon.h @@ -112,7 +112,7 @@ int testUtilHaveGhostscript(); int testUtilVerifyGhostscript(char *filename, int debug); int testUtilHaveVnu(); int testUtilVerifyVnu(char *filename, int debug); -int testUtilCanBwipp(int symbology, int option_1, int option_2, int option_3, int debug); +int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug); int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size); int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected); int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf, const char *expected); diff --git a/backend/tests/tools/bwipp_dump-barcode.ps.diff b/backend/tests/tools/bwipp_dump-barcode.ps.diff index cfa936d0..89b3bdfc 100644 --- a/backend/tests/tools/bwipp_dump-barcode.ps.diff +++ b/backend/tests/tools/bwipp_dump-barcode.ps.diff @@ -1,5 +1,5 @@ ---- ../../../../postscriptbarcode/build/monolithic/barcode.ps 2020-10-02 20:03:59.411955883 +0100 -+++ ../tools/bwipp_dump.ps 2020-10-03 01:47:30.454223200 +0100 +--- ../../../../postscriptbarcode/build/monolithic/barcode.ps 2020-10-26 01:13:25.080992540 +0000 ++++ ../tools/bwipp_dump.ps 2020-10-26 11:19:21.268222231 +0000 @@ -29,6 +29,8 @@ % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS % IN THE SOFTWARE. @@ -9,7 +9,7 @@ % --BEGIN TEMPLATE-- % --BEGIN RESOURCE preamble-- -@@ -25404,34 +25406,80 @@ +@@ -24466,34 +24468,80 @@ pop } ifelse @@ -109,7 +109,7 @@ end -@@ -25490,7 +25538,7 @@ +@@ -24552,7 +24600,7 @@ pop } ifelse @@ -118,7 +118,7 @@ % Get the result of encoding with ean8 and gs1-cc options (lintype) (ean8) put -@@ -25498,29 +25546,75 @@ +@@ -24560,29 +24608,75 @@ options (dontdraw) true put % Plot the linear part @@ -214,7 +214,7 @@ end -@@ -25579,34 +25673,80 @@ +@@ -24641,34 +24735,80 @@ pop } ifelse @@ -314,7 +314,7 @@ end -@@ -25680,34 +25820,80 @@ +@@ -24742,34 +24882,80 @@ /opt options >> def @@ -414,7 +414,7 @@ end -@@ -25766,7 +25952,7 @@ +@@ -24828,7 +25014,7 @@ pop } ifelse @@ -423,7 +423,7 @@ options (lintype) (databaromni) put options (linkage) true put -@@ -25777,7 +25963,7 @@ +@@ -24839,7 +25025,7 @@ linear options //databaromni exec dup (sbs) get /linsbs exch def dup (bhs) get 0 get 72 mul /linheight exch def @@ -432,7 +432,7 @@ % Plot the separator /sepfinder { -@@ -25808,20 +25994,66 @@ +@@ -24870,20 +25056,66 @@ sep 0 [0 0 0] putinterval sep sep length 4 sub [0 0 0 0] putinterval 18 sepfinder 64 sepfinder @@ -511,7 +511,7 @@ end -@@ -25879,7 +26111,7 @@ +@@ -24941,7 +25173,7 @@ pop } ifelse @@ -520,7 +520,7 @@ options (lintype) (databarstacked) put options (linkage) true put -@@ -25890,7 +26122,7 @@ +@@ -24952,7 +25184,7 @@ linear options //databarstacked exec dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def dup (pixy) get /linheight exch def @@ -529,7 +529,7 @@ % Plot the separator /sepfinder { -@@ -25918,20 +26150,52 @@ +@@ -24980,20 +25212,52 @@ sep 0 [ 0 0 0 0 ] putinterval sep sep length 4 sub [ 0 0 0 0 ] putinterval 18 sepfinder @@ -594,7 +594,7 @@ end -@@ -25989,7 +26253,7 @@ +@@ -25051,7 +25315,7 @@ pop } ifelse @@ -603,7 +603,7 @@ options (lintype) (databarstackedomni) put options (linkage) true put -@@ -26000,7 +26264,7 @@ +@@ -25062,7 +25326,7 @@ linear options //databarstackedomni exec dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def dup (pixy) get /linheight exch def @@ -612,7 +612,7 @@ % Plot the separator /sepfinder { -@@ -26028,20 +26292,52 @@ +@@ -25090,20 +25354,52 @@ sep 0 [ 0 0 0 0 ] putinterval sep sep length 4 sub [ 0 0 0 0 ] putinterval 18 sepfinder @@ -677,7 +677,7 @@ end -@@ -26214,7 +26510,7 @@ +@@ -25276,7 +25572,7 @@ pop } ifelse @@ -686,7 +686,7 @@ options (lintype) (databarlimited) put options (linkage) true put -@@ -26225,7 +26521,7 @@ +@@ -25287,7 +25583,7 @@ linear options //databarlimited exec dup (sbs) get /linsbs exch def dup (bhs) get 0 get 72 mul /linheight exch def @@ -695,7 +695,7 @@ % Plot the separator mark -@@ -26233,22 +26529,68 @@ +@@ -25295,22 +25591,68 @@ counttomark 1 sub array astore /sep exch def pop pop sep 0 [0 0 0] putinterval sep sep length 9 sub [0 0 0 0 0 0 0 0 0] putinterval % 4 + 5 right guard spaces @@ -778,7 +778,7 @@ end -@@ -26307,7 +26649,7 @@ +@@ -25369,7 +25711,7 @@ pop } ifelse @@ -787,7 +787,7 @@ options (lintype) (databarexpanded) put options (linkage) true put -@@ -26318,7 +26660,7 @@ +@@ -25380,7 +25722,7 @@ linear options //databarexpanded exec dup (sbs) get /linsbs exch def dup (bhs) get 0 get 72 mul /linheight exch def @@ -796,7 +796,7 @@ % Plot the separator /sepfinder { -@@ -26347,20 +26689,60 @@ +@@ -25409,20 +25751,60 @@ 18 98 bot length 13 sub {} for 69 98 bot length 13 sub {} for ] {sepfinder} forall @@ -869,7 +869,7 @@ end -@@ -26418,7 +26800,7 @@ +@@ -25480,7 +25862,7 @@ pop } ifelse @@ -878,7 +878,7 @@ options (lintype) (databarexpandedstacked) put options (linkage) true put -@@ -26429,7 +26811,7 @@ +@@ -25491,7 +25873,7 @@ linear options //databarexpandedstacked exec dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def dup (pixy) get /linheight exch def @@ -887,14 +887,7 @@ % Plot the separator /sepfinder { -@@ -26449,27 +26831,55 @@ - } for - } bind def - /sep [ bot {1 exch sub} forall ] def -- sep 0 [ 0 0 0 ] putinterval -+ sep 0 [ 0 0 0 0 ] putinterval - sep sep length 4 sub [ 0 0 0 0 ] putinterval - [ % Finder pattern module positions +@@ -25517,21 +25899,49 @@ 19 98 bot length 13 sub {} for 70 98 bot length 13 sub {} for ] {sepfinder} forall @@ -957,7 +950,7 @@ end -@@ -26528,7 +26938,7 @@ +@@ -25590,7 +26000,7 @@ pop } ifelse @@ -966,7 +959,7 @@ options (inkspread) (0) put options (dontdraw) true put -@@ -26555,35 +26965,87 @@ +@@ -25617,35 +26027,87 @@ linear << options {} forall >> //gs1-128 exec dup (sbs) get /linsbs exch def dup (bhs) get 0 get 72 mul /linheight exch def @@ -1068,7 +1061,7 @@ end -@@ -27881,3 +28343,176 @@ +@@ -26919,3 +27381,176 @@ % --END ENCODER hibcazteccode-- % --END TEMPLATE-- diff --git a/backend/tests/tools/bwipp_dump.ps.tar.xz b/backend/tests/tools/bwipp_dump.ps.tar.xz index 38fc9caa..02dbc179 100644 Binary files a/backend/tests/tools/bwipp_dump.ps.tar.xz and b/backend/tests/tools/bwipp_dump.ps.tar.xz differ diff --git a/backend/tests/tools/run_bwipp_tests.sh b/backend/tests/tools/run_bwipp_tests.sh index fd24c224..04c34b69 100755 --- a/backend/tests/tools/run_bwipp_tests.sh +++ b/backend/tests/tools/run_bwipp_tests.sh @@ -15,6 +15,7 @@ function run_bwipp_test() { run_bwipp_test "test_2of5" "encode" run_bwipp_test "test_auspost" "encode" +run_bwipp_test "test_aztec" "encode" run_bwipp_test "test_channel" "encode" run_bwipp_test "test_codablock" "encode" run_bwipp_test "test_code" "encode" @@ -23,6 +24,7 @@ run_bwipp_test "test_code128" "encode" run_bwipp_test "test_code16k" "encode" run_bwipp_test "test_code49" "encode" run_bwipp_test "test_composite" +run_bwipp_test "test_dmatrix" "encode" run_bwipp_test "test_gs1" "gs1_reduce" run_bwipp_test "test_imail" "encode" run_bwipp_test "test_medical" "encode" diff --git a/backend/upcean.c b/backend/upcean.c index 99044fc0..54478134 100644 --- a/backend/upcean.c +++ b/backend/upcean.c @@ -101,14 +101,14 @@ static char upc_check(char source[]) { /* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */ static void upca_draw(char source[], char dest[]) { - unsigned int i, half_way; + unsigned int i, half_way, length = strlen(source); - half_way = strlen(source) / 2; + half_way = length / 2; /* start character */ strcat(dest, "111"); - for (i = 0; i <= strlen(source); i++) { + for (i = 0; i < length; i++) { if (i == half_way) { /* middle character - separates manufacturer no. from product no. */ /* also inverts right hand characters */ @@ -157,7 +157,7 @@ static int upca(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* UPC E is a zero-compressed version of UPC A */ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) { - unsigned int i, num_system; + unsigned int i, num_system, length; char emode, equivalent[12], check_digit, parity[8], temp[9]; char hrt[9]; int error_number = 0; @@ -285,7 +285,8 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* start character */ strcat(dest, "111"); - for (i = 0; i <= ustrlen(source); i++) { + length = ustrlen(source); + for (i = 0; i < length; i++) { switch (parity[i]) { case 'A': lookup(NEON, EANsetA, source[i], dest); break; @@ -321,7 +322,7 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* EAN-2 and EAN-5 add-on codes */ static void add_on(unsigned char source[], char dest[], int addon_gap) { char parity[6]; - unsigned int i, code_type; + unsigned int i, code_type, length; /* If an add-on then append with space */ if (addon_gap != 0) { @@ -363,7 +364,8 @@ static void add_on(unsigned char source[], char dest[], int addon_gap) { strcpy(parity, EAN5Parity[parity_bit]); } - for (i = 0; i < ustrlen(source); i++) { + length = ustrlen(source); + for (i = 0; i < length; i++) { switch (parity[i]) { case 'A': lookup(NEON, EANsetA, source[i], dest); break; @@ -441,7 +443,7 @@ static int ean13(struct zint_symbol *symbol, unsigned char source[], char dest[] /* start character */ strcat(dest, "111"); length = strlen(gtin); - for (i = 1; i <= length; i++) { + for (i = 1; i < length; i++) { if (i == half_way) { /* middle character - separates manufacturer no. from product no. */ /* also inverses right hand characters */ diff --git a/backend/vector.c b/backend/vector.c index a027e045..4e9be76e 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -79,7 +79,7 @@ static struct zint_vector_hexagon *vector_plot_create_hexagon(float x, float y, hexagon->next = NULL; hexagon->x = x; hexagon->y = y; - hexagon->diameter = (diameter * 5.0f) / 4.0f; // Ugly kludge for legacy support + hexagon->diameter = diameter; hexagon->rotation = 0; return hexagon; @@ -407,7 +407,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ float dot_overspill = 0.0f; float dotoffset = 0.0f; - int rect_count, last_row_start; + int rect_count, last_row_start = 0; int this_row; struct zint_vector *vector; @@ -469,14 +469,16 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if ((symbol->symbology != BARCODE_MAXICODE) && (symbol->output_options & BARCODE_DOTTY_MODE)) { dot_overspill = symbol->dot_size - 1.0f; /* Allow for exceeding 1X */ if (dot_overspill < 0.0f) { + dotoffset = -dot_overspill / 2.0f; dot_overspill = 0.0f; } else { - dotoffset = 0.1f; /* Fudge for anti-aliasing */ + dot_overspill += 0.1f; /* Fudge for anti-aliasing */ + dotoffset = 0.05f; } } - vector->width = symbol->width + dotoffset * 2.0f + dot_overspill + (xoffset + roffset); - vector->height = symbol->height + textoffset + dotoffset * 2.0f + dot_overspill + (yoffset + boffset); + vector->width = symbol->width + dot_overspill + (xoffset + roffset); + vector->height = symbol->height + textoffset + dot_overspill + (yoffset + boffset); if (symbol->border_width > 0 && ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND))) { default_text_posn = symbol->height + text_height + text_gap + symbol->border_width + symbol->border_width; @@ -484,11 +486,52 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ default_text_posn = symbol->height + text_height + text_gap; } - rect_count = 0; - last_row_start = 0; + // Plot Maxicode symbols + if (symbol->symbology == BARCODE_MAXICODE) { + struct zint_vector_circle *circle; + float hex_diameter = (float) (symbol->dot_size * 5.0 / 4.0); // Ugly kludge for legacy support + vector->width = 37.0f + (xoffset + roffset); + vector->height = 36.0f + (yoffset + boffset); + // Bullseye + circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 10.85f, 0); + vector_plot_add_circle(symbol, circle, &last_circle); + circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 8.97f, 1); + vector_plot_add_circle(symbol, circle, &last_circle); + circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 7.10f, 0); + vector_plot_add_circle(symbol, circle, &last_circle); + circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 5.22f, 1); + vector_plot_add_circle(symbol, circle, &last_circle); + circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 3.31f, 0); + vector_plot_add_circle(symbol, circle, &last_circle); + circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 1.43f, 1); + vector_plot_add_circle(symbol, circle, &last_circle); + + /* Hexagons */ + for (r = 0; r < symbol->rows; r++) { + for (i = 0; i < symbol->width; i++) { + if (module_is_set(symbol, r, i)) { + //struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 0.88) + ((r & 1) ? 1.76 : 1.32)), ((r * 0.76) + 0.76), hex_diameter); + struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 1.23f) + 0.615f + ((r & 1) ? 0.615f : 0.0f)) + xoffset, + ((r * 1.067f) + 0.715f) + yoffset, hex_diameter); + vector_plot_add_hexagon(symbol, hexagon, &last_hexagon); + } + } + } + // Dotty mode + } else if (symbol->output_options & BARCODE_DOTTY_MODE) { + float dotradius = symbol->dot_size / 2.0f; + for (r = 0; r < symbol->rows; r++) { + for (i = 0; i < symbol->width; i++) { + if (module_is_set(symbol, r, i)) { + struct zint_vector_circle *circle = vector_plot_create_circle(i + dotradius + dotoffset + xoffset, r + dotradius + dotoffset + yoffset, symbol->dot_size, 0); + vector_plot_add_circle(symbol, circle, &last_circle); + } + } + } // Plot rectangles - most symbols created here - if ((symbol->symbology != BARCODE_MAXICODE) && ((symbol->output_options & BARCODE_DOTTY_MODE) == 0)) { + } else { + rect_count = 0; row_posn = yoffset; for (r = 0; r < symbol->rows; r++) { this_row = r; @@ -537,52 +580,6 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ } } - // Plot Maxicode symbols - if (symbol->symbology == BARCODE_MAXICODE) { - struct zint_vector_circle *circle; - vector->width = 37.0f + (xoffset + roffset); - vector->height = 36.0f + (yoffset + boffset); - - // Bullseye - circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 10.85f, 0); - vector_plot_add_circle(symbol, circle, &last_circle); - circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 8.97f, 1); - vector_plot_add_circle(symbol, circle, &last_circle); - circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 7.10f, 0); - vector_plot_add_circle(symbol, circle, &last_circle); - circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 5.22f, 1); - vector_plot_add_circle(symbol, circle, &last_circle); - circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 3.31f, 0); - vector_plot_add_circle(symbol, circle, &last_circle); - circle = vector_plot_create_circle(17.88f + xoffset, 17.8f + yoffset, 1.43f, 1); - vector_plot_add_circle(symbol, circle, &last_circle); - - /* Hexagons */ - for (r = 0; r < symbol->rows; r++) { - for (i = 0; i < symbol->width; i++) { - if (module_is_set(symbol, r, i)) { - //struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 0.88) + ((r & 1) ? 1.76 : 1.32)), ((r * 0.76) + 0.76), symbol->dot_size); - struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 1.23f) + 0.615f + ((r & 1) ? 0.615f : 0.0f)) + xoffset, - ((r * 1.067f) + 0.715f) + yoffset, symbol->dot_size); - vector_plot_add_hexagon(symbol, hexagon, &last_hexagon); - } - } - } - } - - // Dotty mode - if ((symbol->symbology != BARCODE_MAXICODE) && (symbol->output_options & BARCODE_DOTTY_MODE)) { - float dotradius = symbol->dot_size / 2.0f; - for (r = 0; r < symbol->rows; r++) { - for (i = 0; i < symbol->width; i++) { - if (module_is_set(symbol, r, i)) { - struct zint_vector_circle *circle = vector_plot_create_circle(i + dotradius + dotoffset + xoffset, r + dotradius + dotoffset + yoffset, symbol->dot_size, 0); - vector_plot_add_circle(symbol, circle, &last_circle); - } - } - } - } - if (upceanflag) { /* Guard bar extension */ if (upceanflag == 6) { /* UPC-E */ diff --git a/backend_qt/CMakeLists.txt b/backend_qt/CMakeLists.txt index 8be5bc0e..03d9566f 100644 --- a/backend_qt/CMakeLists.txt +++ b/backend_qt/CMakeLists.txt @@ -1,22 +1,32 @@ # (c) 2008 by BogDan Vatra < bogdan@licentia.eu > +# vim: set ts=4 sw=4 et : project(QZint) include_directories(BEFORE "${CMAKE_SOURCE_DIR}/backend" ) set(QZint_SRCS qzint.cpp) -QT5_WRAP_CPP(QZint_SRCS qzint.h) + +if(USE_QT6) + qt6_wrap_cpp(QZint_SRCS qzint.h) +else() + qt5_wrap_cpp(QZint_SRCS qzint.h) +endif() add_library(QZint SHARED ${QZint_SRCS}) -set_target_properties(QZint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}" +set_target_properties(QZint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}" VERSION ${ZINT_VERSION}) add_dependencies(QZint zint) link_directories( "${CMAKE_BINARY_DIR}/backend" ) -target_link_libraries(QZint zint Qt5::Widgets Qt5::Gui ) +if(USE_QT6) + target_link_libraries(QZint zint Qt6::Widgets Qt6::Gui) +else() + target_link_libraries(QZint zint Qt5::Widgets Qt5::Gui) +endif() install(TARGETS QZint ${INSTALL_TARGETS_DEFAULT_ARGS} ) install(FILES qzint.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel) diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 2de11d45..f5a4d959 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -411,7 +411,6 @@ namespace Zint { struct zint_vector_hexagon *hex; struct zint_vector_circle *circle; struct zint_vector_string *string; - qreal radius; (void)mode; /* Not currently used */ @@ -454,9 +453,6 @@ namespace Zint { xtr += (qreal) (paintRect.width() - gwidth * scale) / 2.0; ytr += (qreal) (paintRect.height() - gheight * scale) / 2.0; - painter.setBackground(QBrush(m_bgColor)); - painter.fillRect(paintRect, QBrush(m_bgColor)); - if (m_rotate_angle) { painter.translate(paintRect.width() / 2.0, paintRect.height() / 2.0); // Need to rotate around centre painter.rotate(m_rotate_angle); @@ -466,6 +462,9 @@ namespace Zint { painter.translate(xtr, ytr); painter.scale(scale, scale); + QBrush bgBrush(m_bgColor); + painter.fillRect(QRectF(0, 0, gwidth, gheight), bgBrush); + //Red square for diagnostics //painter.fillRect(QRect(0, 0, m_zintSymbol->vector->width, m_zintSymbol->vector->height), QBrush(QColor(255,0,0,255))); @@ -488,19 +487,25 @@ namespace Zint { hex = m_zintSymbol->vector->hexagons; if (hex) { painter.setRenderHint(QPainter::Antialiasing); - QBrush brush(m_fgColor); + QBrush fgBrush(m_fgColor); + qreal previous_diameter = 0.0, radius = 0.0, half_radius = 0.0, half_sqrt3_radius = 0.0; while (hex) { - radius = hex->diameter / 2.0; + if (previous_diameter != hex->diameter) { + previous_diameter = hex->diameter; + radius = 0.5 * previous_diameter; + half_radius = 0.25 * previous_diameter; + half_sqrt3_radius = 0.43301270189221932338 * previous_diameter; + } QPainterPath pt; - pt.moveTo(hex->x, hex->y + (1.0 * radius)); - pt.lineTo(hex->x + (0.86 * radius), hex->y + (0.5 * radius)); - pt.lineTo(hex->x + (0.86 * radius), hex->y - (0.5 * radius)); - pt.lineTo(hex->x, hex->y - (1.0 * radius)); - pt.lineTo(hex->x - (0.86 * radius), hex->y - (0.5 * radius)); - pt.lineTo(hex->x - (0.86 * radius), hex->y + (0.5 * radius)); - pt.lineTo(hex->x, hex->y + (1.0 * radius)); - painter.fillPath(pt, brush); + pt.moveTo(hex->x, hex->y + radius); + pt.lineTo(hex->x + half_sqrt3_radius, hex->y + half_radius); + pt.lineTo(hex->x + half_sqrt3_radius, hex->y - half_radius); + pt.lineTo(hex->x, hex->y - radius); + pt.lineTo(hex->x - half_sqrt3_radius, hex->y - half_radius); + pt.lineTo(hex->x - half_sqrt3_radius, hex->y + half_radius); + pt.lineTo(hex->x, hex->y + radius); + painter.fillPath(pt, fgBrush); hex = hex->next; } @@ -511,19 +516,25 @@ namespace Zint { if (circle) { painter.setRenderHint(QPainter::Antialiasing); QPen p; + QBrush fgBrush(m_fgColor); + qreal previous_diameter = 0.0, radius = 0.0; while (circle) { + if (previous_diameter != circle->diameter) { + previous_diameter = circle->diameter; + radius = 0.5 * previous_diameter; + } if (circle->colour) { // Set means use background colour p.setColor(m_bgColor); p.setWidth(0); painter.setPen(p); - painter.setBrush(QBrush(m_bgColor)); + painter.setBrush(bgBrush); } else { p.setColor(m_fgColor); p.setWidth(0); painter.setPen(p); - painter.setBrush(QBrush(m_fgColor)); + painter.setBrush(fgBrush); } - painter.drawEllipse(QPointF(circle->x, circle->y), (double) circle->diameter / 2.0, (double) circle->diameter / 2.0); + painter.drawEllipse(QPointF(circle->x, circle->y), radius, radius); circle = circle->next; } } diff --git a/docs/manual.txt b/docs/manual.txt index 07b5f209..13494e7c 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -22,11 +22,11 @@ able to encode data in over 50 barcode symbologies (types of barcode), for each of which it is possible to translate that data from either Unicode (UTF-8) or a raw 8-bit data stream. The image can be rendered as either a Portable Network Graphic (PNG) image, Windows Bitmap (BMP), Graphics Interchange Format (GIF), -ZSoft Paintbrush image (PCX), as Encapsulated Post Script (EPS) or as a -Scalable Vector Graphic (SVG). Many options are available for setting the -characteristics of the output image including the size and colour of the image, -the amount of error correction used in the symbol and, in the case of raster -images, the orientation of the image. +ZSoft Paintbrush image (PCX), Tagged Image File Format (TIF), Enhanced Metafile +Format (EMF), as Encapsulated Post Script (EPS), or as a Scalable Vector Graphic +(SVG). Many options are available for setting the characteristics of the output +image including the size and colour of the image, the amount of error correction +used in the symbol and the orientation of the image. 1.1 Terms of Reference ---------------------- @@ -388,8 +388,8 @@ zint --box --border=10 -d "This" gives a box with a width 10 times the X-dimension of the symbol. -These options are ignored for Code 16k and Codablock-F. Special considerations -apply to ITF-14 - see the specific section for that symbology. +These options are ignored for Code 16k, Code 49 and Codablock-F. Special +considerations apply to ITF-14 - see the specific section for that symbology. 4.7 Using colour ---------------- @@ -433,8 +433,7 @@ PNG, GIF, SVG, EMF and EPS files. 4.8 Rotating the Symbol ----------------------- The symbol can be rotated through four orientations using the --rotate= option -followed by the angle of rotation as shown below. This option does not (yet) -apply to EMF file output. +followed by the angle of rotation as shown below. --rotate=0 (default) --rotate=90 @@ -627,6 +626,7 @@ supported output file formats are shown in the following table: Abbreviation | File format -------------------------------------------------------------- BMP | Windows Bitmap +EMF | Enhanced Metafile Format EPS | Encapsulated PostScript GIF | Graphics Interchange Format PCX | ZSoft Paintbrush image @@ -790,8 +790,8 @@ string. This allows the encoding of NUL (ASCII 0) characters in those symbologies which allow this. A value of 0 will disable this function and Zint will encode data up to the first NUL character in the input string. -The "rotate_angle" value can be used to rotate the image when outputting as a -raster image. Valid values are 0, 90, 180 and 270. +The "rotate_angle" value can be used to rotate the image when outputting. Valid +values are 0, 90, 180 and 270. The ZBarcode_Encode_File() and ZBarcode_Encode_File_and_Print() functions can be used to encode data read directly from a text file where the filename is @@ -816,10 +816,10 @@ saving the image to file it is placed in an unsigned character array. The "bitmap" pointer is set to the first memory location in the array and the values "barcode_width" and "barcode_height" indicate the size of the resulting image in pixels. Rotation and colour options can be used at the same time as using -the buffer functions in the same way as when saving to a raster image. The -pixel data can be extracted from the array by the method shown in the example -below where render_pixel() is assumed to be a function for drawing a pixel on -the screen implemented by the external application: +the buffer functions in the same way as when saving to a file. The pixel data +can be extracted from the array by the method shown in the example below where +render_pixel() is assumed to be a function for drawing a pixel on the screen +implemented by the external application: int row, col, i = 0; int red, blue, green; @@ -2377,7 +2377,7 @@ Input | Symbol Size 24 | 101 x 101 25 | 105 x 105 26 | 109 x 109 -28 | 113 x 113 +27 | 113 x 113 28 | 117 x 117 29 | 121 x 121 30 | 125 x 125 diff --git a/frontend_qt/CMakeLists.txt b/frontend_qt/CMakeLists.txt index a18c13fa..0b8781f4 100644 --- a/frontend_qt/CMakeLists.txt +++ b/frontend_qt/CMakeLists.txt @@ -1,26 +1,36 @@ # (c) 2008 by BogDan Vatra < bogdan@licentia.eu > +# vim: set ts=4 sw=4 et : project(zint-qt) include_directories(BEFORE "${CMAKE_SOURCE_DIR}/backend" "${CMAKE_SOURCE_DIR}/backend_qt") set(zint-qt_SRCS barcodeitem.cpp main.cpp mainwindow.cpp datawindow.cpp sequencewindow.cpp exportwindow.cpp) -QT5_WRAP_CPP(zint-qt_SRCS mainwindow.h datawindow.h sequencewindow.h exportwindow.h) -QT5_WRAP_UI(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui extExport.ui) +if(USE_QT6) + qt6_wrap_cpp(zint-qt_SRCS mainwindow.h datawindow.h sequencewindow.h exportwindow.h) + qt6_wrap_ui(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui extExport.ui) + qt6_add_resources(zint-qt_SRCS resources.qrc) +else() + qt5_wrap_cpp(zint-qt_SRCS mainwindow.h datawindow.h sequencewindow.h exportwindow.h) + qt5_wrap_ui(zint-qt_SRCS mainWindow.ui extData.ui extSequence.ui extExport.ui) + qt5_add_resources(zint-qt_SRCS resources.qrc) +endif() # grpAztec.ui grpC49.ui grpDBExtend.ui grpLOGMARS.ui grpPDF417.ui grpUPCEAN.ui # grpC11.ui grpChannel.ui grpDM.ui grpMaxicode.ui grpQR.ui grpVIN.ui # grpC128.ui grpCodabar.ui grpDotCode.ui grpMicroPDF.ui grpRMQR.ui # grpC16k.ui grpCodablockF.ui grpGrid.ui grpMQR.ui grpUltra.ui # grpC39.ui grpCodeOne.ui grpHX.ui grpMSICheck.ui grpUPCA.ui -QT5_ADD_RESOURCES(zint-qt_SRCS resources.qrc) - add_executable(zint-qt ${zint-qt_SRCS}) add_dependencies(zint-qt QZint zint) link_directories( "${CMAKE_BINARY_DIR}/backend" "${CMAKE_BINARY_DIR}/backend_qt" ) -target_link_libraries(zint-qt zint QZint Qt5::UiTools ${QT_QTXML_LIBRARY} Qt5::Gui Qt5::Core ) +if(USE_QT6) + target_link_libraries(zint-qt zint QZint Qt6::UiTools ${QT_QTXML_LIBRARY} Qt6::Gui Qt6::Core) +else() + target_link_libraries(zint-qt zint QZint Qt5::UiTools ${QT_QTXML_LIBRARY} Qt5::Gui Qt5::Core) +endif() install(TARGETS zint-qt DESTINATION "${BIN_INSTALL_DIR}" RUNTIME) diff --git a/frontend_qt/frontend_qt_zintdll.pro b/frontend_qt/frontend_qt_zintdll.pro index b79178ba..a39e6ecd 100644 --- a/frontend_qt/frontend_qt_zintdll.pro +++ b/frontend_qt/frontend_qt_zintdll.pro @@ -36,6 +36,8 @@ FORMS += extData.ui \ grpPDF417.ui \ grpQR.ui \ grpRMQR.ui \ + grpUPCA.ui \ + grpUPCEAN.ui \ grpVIN.ui \ mainWindow.ui diff --git a/frontend_qt/mainWindow.ui b/frontend_qt/mainWindow.ui index 22d5f767..df86fd24 100644 --- a/frontend_qt/mainWindow.ui +++ b/frontend_qt/mainWindow.ui @@ -22,7 +22,7 @@ 420 - 500 + 460 diff --git a/frontend_qt/mainwindow.cpp b/frontend_qt/mainwindow.cpp index b428a027..4133facd 100644 --- a/frontend_qt/mainwindow.cpp +++ b/frontend_qt/mainwindow.cpp @@ -286,10 +286,10 @@ bool MainWindow::save() #ifdef NO_PNG suffix = settings.value("studio/default_suffix", "gif").toString(); - save_dialog.setNameFilter(tr("Encapsulated PostScript (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Extended Metafile (*.emf);;Tagged Image File Format (*.tif)")); + save_dialog.setNameFilter(tr("Encapsulated PostScript (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Enhanced Metafile (*.emf);;Tagged Image File Format (*.tif)")); #else suffix = settings.value("studio/default_suffix", "png").toString(); - save_dialog.setNameFilter(tr("Portable Network Graphic (*.png);;Encapsulated PostScript (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Extended Metafile (*.emf);;Tagged Image File Format (*.tif)")); + save_dialog.setNameFilter(tr("Portable Network Graphic (*.png);;Encapsulated PostScript (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Enhanced Metafile (*.emf);;Tagged Image File Format (*.tif)")); #endif if (QString::compare(suffix, "png", Qt::CaseInsensitive) == 0) @@ -305,7 +305,7 @@ bool MainWindow::save() if (QString::compare(suffix, "pcx", Qt::CaseInsensitive) == 0) save_dialog.selectNameFilter("ZSoft PC Painter Image (*.pcx)"); if (QString::compare(suffix, "emf", Qt::CaseInsensitive) == 0) - save_dialog.selectNameFilter("Extended Metafile (*.emf)"); + save_dialog.selectNameFilter("Enhanced Metafile (*.emf)"); if (QString::compare(suffix, "tif", Qt::CaseInsensitive) == 0) save_dialog.selectNameFilter("Tagged Image File Format (*.tif)");