diff --git a/backend/library.c b/backend/library.c index 57d6e55b..69c7d314 100644 --- a/backend/library.c +++ b/backend/library.c @@ -62,7 +62,7 @@ struct zint_symbol *ZBarcode_Create() { symbol->scale = 1.0; symbol->option_1 = -1; symbol->option_2 = 0; - symbol->option_3 = 928; // PDF_MAX + symbol->option_3 = 0; symbol->show_hrt = 1; // Show human readable text symbol->fontsize = 8; symbol->input_mode = DATA_MODE; diff --git a/backend/tests/CMakeLists.txt b/backend/tests/CMakeLists.txt index 18d6ed8f..a3e054e4 100644 --- a/backend/tests/CMakeLists.txt +++ b/backend/tests/CMakeLists.txt @@ -64,6 +64,7 @@ zint_add_test(imail, test_imail) zint_add_test(library, test_library) zint_add_test(mailmark, test_mailmark) zint_add_test(maxicode, test_maxicode) +zint_add_test(pdf417, test_pdf417) zint_add_test(postal, test_postal) zint_add_test(qr, test_qr) zint_add_test(raster, test_raster) diff --git a/backend/tests/test_hanxin.c b/backend/tests/test_hanxin.c index 70b088a2..191d5fe2 100644 --- a/backend/tests/test_hanxin.c +++ b/backend/tests/test_hanxin.c @@ -31,7 +31,7 @@ #include "testcommon.h" -#define TEST_INPUT_GENERATE_EXPECTED 1 +//#define TEST_INPUT_GENERATE_EXPECTED 1 //#define TEST_ENCODE_GENERATE_EXPECTED 1 static void test_options(void) @@ -141,7 +141,7 @@ static void test_input(void) /* 18*/ { UNICODE_MODE, 0, "123", -1, 0, 0, "11 EF FF 00 00 00 00 00 00", "N3 (ASCII)" }, /* 19*/ { UNICODE_MODE, 0, "12345", -1, 0, 0, "11 EC 2D FF 80 00 00 00 00", "N5 (ASCII)" }, /* 20*/ { UNICODE_MODE, 0, "Aa%$Bb9", -1, 0, 0, "22 A4 FA 18 3E 2E 52 7F 00", "T7 (ASCII)" }, - /* 21*/ { UNICODE_MODE, 0, "Summer Palace Ticket for 6 June 2015 13:00;2015年6月6日夜01時00分PM頤和園のチケット;2015년6월6일13시오후여름궁전티켓.2015年6月6号下午13:00的颐和园门票;", -1, 0, 0, "(189) 27 38 C3 0A 35 F9 CF 99 92 F9 26 A3 E7 3E 76 C9 AE A3 7F CC 08 04 0C CD EE 44 06 C4 09 4E AD", "T20 B64 N4 H(f)1 T1 H(f)1 T1 H(f)1 T2 H(f)9 B35 (GB 18030)" }, + /* 21*/ { UNICODE_MODE, 0, "Summer Palace Ticket for 6 June 2015 13:00;2015年6月6日夜01時00分PM頤和園のチケット;2015년6월6일13시오후여름궁전티켓.2015年6月6号下午13:00的颐和园门票;", -1, 0, 0, "(189) 27 38 C3 0A 35 F9 CF 99 92 F9 26 A3 E7 3E 76 C9 AE A3 7F CC 08 04 0C CD EE 44 06 C4", "T20 B64 N4 H(f)1 T1 H(f)1 T1 H(f)1 T2 H(f)9 B35 (GB 18030)" }, /* 22*/ { UNICODE_MODE, 0, "\000\014\033 #/059:<@AMZ", 15, 0, 0, "2F 80 31 B7 1F AF E0 05 27 EB 2E CB E2 96 8F F0 00", "T15 (ASCII)" }, /* 23*/ { UNICODE_MODE, 0, "Z[\\`alz{~\177", -1, 0, 0, "28 FE CF 4E 3E 92 FF 7E E7 CF 7F 00 00", "T10 (ASCII)" }, }; diff --git a/backend/tests/test_pdf417.c b/backend/tests/test_pdf417.c new file mode 100644 index 00000000..e1cc2f88 --- /dev/null +++ b/backend/tests/test_pdf417.c @@ -0,0 +1,206 @@ +/* + libzint - the open source barcode library + Copyright (C) 2008-2019 Robin Stuart + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the project nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + */ +/* vim: set ts=4 sw=4 et : */ + +#include "testcommon.h" + +//#define TEST_PDF417_ENCODE_GENERATE_EXPECTED 1 + +static void test_pdf417_options(void) +{ + testStart(""); + + int ret; + struct item { + unsigned char* data; + int option_1; + int option_2; + int option_3; + int ret_encode; + int ret_vector; + + int expected_option_1; + int expected_option_2; + int expected_rows; + int expected_width; + int compare_previous; + }; + // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) + struct item data[] = { + /* 0*/ { "12345", -1, -1, -1, 0, 0, 2, 2, 6, 103, -1 }, // ECC auto-set to 2, cols auto-set to 2 + /* 1*/ { "12345", -1, -1, 928, 0, 0, 2, 2, 6, 103, 0 }, // Option 3 ignored + /* 2*/ { "12345", -1, -1, 300, 0, 0, 2, 2, 6, 103, 0 }, // Option 3 ignored + /* 3*/ { "12345", 3, -1, -1, 0, 0, 3, 3, 7, 120, -1 }, // ECC 3, cols auto-set to 3 + /* 4*/ { "12345", 3, 2, -1, 0, 0, 3, 2, 10, 103, -1 }, // ECC 3, cols 2 + /* 5*/ { "12345", 8, 2, -1, ZINT_ERROR_TOO_LONG, -1, 8, 3, 0, 0, -1 }, // ECC 8, cols 2, fails + /* 6*/ { "12345", 7, 2, -1, 0, 0, 7, 3, 87, 120, -1 }, // ECC 7, cols 2 auto-upped to 3 + /* 7*/ { "12345", -1, 10, -1, 0, 0, 2, 10, 3, 239, -1 }, // ECC auto-set to 2, cols 10 + }; + int data_size = sizeof(data) / sizeof(struct item); + + struct zint_symbol previous_symbol; + + for (int i = 0; i < data_size; i++) { + + struct zint_symbol* symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->symbology = BARCODE_PDF417; + 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; + } + if (data[i].option_3 != -1) { + symbol->option_3 = data[i].option_3; + } + int length = strlen(data[i].data); + + ret = ZBarcode_Encode(symbol, data[i].data, length); + assert_equal(ret, data[i].ret_encode, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret_encode, symbol->errtxt); + + assert_equal(symbol->option_1, data[i].expected_option_1, "i:%d symbol->option_1 %d != %d (%d)\n", i, symbol->option_1, data[i].expected_option_1, data[i].option_1); + assert_equal(symbol->option_2, data[i].expected_option_2, "i:%d symbol->option_2 %d != %d (%d)\n", i, symbol->option_2, data[i].expected_option_2, data[i].option_2); + if (data[i].option_3 != -1) { + assert_equal(symbol->option_3, data[i].option_3, "i:%d symbol->option_3 %d != %d\n", i, symbol->option_3, data[i].option_3); // Unchanged + } else { + assert_zero(symbol->option_3, "i:%d symbol->option_3 %d != 0\n", i, symbol->option_3); + } + + assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); + assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); + + if (data[i].compare_previous != -1) { + ret = testUtilSymbolCmp(symbol, &previous_symbol); + assert_equal(!ret, !data[i].compare_previous, "i:%d testUtilSymbolCmp !ret %d != %d\n", i, ret, data[i].compare_previous); + } + memcpy(&previous_symbol, symbol, sizeof(previous_symbol)); + + if (data[i].ret_vector != -1) { + ret = ZBarcode_Buffer_Vector(symbol, 0); + assert_equal(ret, data[i].ret_vector, "i:%d ZBarcode_Buffer_Vector ret %d != %d\n", i, ret, data[i].ret_vector); + } + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +static void test_pdf417_encode(void) +{ + testStart(""); + + int ret; + struct item { + int input_mode; + unsigned char* data; + int option_1; + int option_2; + int ret; + + int expected_rows; + int expected_width; + char* comment; + char* expected; + }; + struct item data[] = { + /* 0*/ { UNICODE_MODE, "PDF417 Symbology Standard", 2, 2, 0, 13, 103, "ISO 15438:2015 Figure 1 **NOT SAME** TODO: investigate", + "1111111101010100011110101001111000101011000110000001000011000110010011110101011110000111111101000101001" + "1111111101010100011111010100011000110110000011110101101000011100010011111101010011100111111101000101001" + "1111111101010100011101010111111000111010000111110101011001101111000011010100011111000111111101000101001" + "1111111101010100011111010111111010100000100010100001000001001000001010101111001111000111111101000101001" + "1111111101010100011010111000010000111001000110010001111001000001010011101011100011000111111101000101001" + "1111111101010100011110101111010000101110001000110001001111000010100011110101111000010111111101000101001" + "1111111101010100011010011100111100110000010010011001011100011101000011010011101111000111111101000101001" + "1111111101010100011110100101000000111111011000101101111010110011000010101111110011100111111101000101001" + "1111111101010100011010011011111100111110100001110101100011111001001010100110001111100111111101000101001" + "1111111101010100010100011101110000110110111100111101101100100100000011010001100011100111111101000101001" + "1111111101010100011010011100010000111000000101101001101101111100110011101001110011000111111101000101001" + "1111111101010100010100010001111000101010000111100001011111100011101010100011011111000111111101000101001" + "1111111101010100010100000101000000110000101011000001001000110000110010100001100000110111111101000101001" + }, + }; + int data_size = sizeof(data) / sizeof(struct item); + + for (int i = 0; i < data_size; i++) { + + struct zint_symbol* symbol = ZBarcode_Create(); + assert_nonnull(symbol, "Symbol not created\n"); + + symbol->symbology = BARCODE_PDF417; + 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; + } + + int length = strlen(data[i].data); + + ret = ZBarcode_Encode(symbol, 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); + + #ifdef TEST_PDF417_ENCODE_GENERATE_EXPECTED + printf(" /*%3d*/ { %s, \"%s\", %d, %d, %s, %d, %d, \"%s\",\n", + i, testUtilInputModeName(data[i].input_mode), data[i].data, data[i].option_1, data[i].option_2, testUtilErrorName(data[i].ret), + symbol->rows, symbol->width, data[i].comment); + testUtilModulesDump(symbol, " ", "\n"); + printf(" },\n"); + #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); + + 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); + } + } + #endif + + ZBarcode_Delete(symbol); + } + + testFinish(); +} + +int main() +{ + test_pdf417_options(); + test_pdf417_encode(); + + testReport(); + + return 0; +} diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 65d386f1..1d3fbd5c 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -31,7 +31,6 @@ namespace Zint { m_border = NO_BORDER; m_borderWidth = 0; m_securityLevel = -1; - m_pdf417CodeWords = 928; m_fgColor = Qt::black; m_bgColor = Qt::white; m_zintSymbol = 0; @@ -72,11 +71,7 @@ namespace Zint { } else { m_zintSymbol->show_hrt = 1; } - if (m_symbol == BARCODE_PDF417) { - m_zintSymbol->option_3 = m_pdf417CodeWords; - } else { - m_zintSymbol->option_3 = m_option_3; - } + m_zintSymbol->option_3 = m_option_3; QByteArray bstr = m_text.toUtf8(); QByteArray pstr = m_primaryMessage.left(99).toLatin1(); strcpy(m_zintSymbol->primary, pstr.data()); @@ -190,14 +185,6 @@ namespace Zint { m_whitespace = whitespace; } - int QZint::pdf417CodeWords() const { - return m_pdf417CodeWords; - } - - void QZint::setPdf417CodeWords(int pdf417CodeWords) { - m_pdf417CodeWords = pdf417CodeWords; - } - int QZint::securityLevel() const { return m_securityLevel; } @@ -249,11 +236,7 @@ namespace Zint { } else { m_zintSymbol->show_hrt = 1; } - if (m_symbol == BARCODE_PDF417) { - m_zintSymbol->option_3 = m_pdf417CodeWords; - } else { - m_zintSymbol->option_3 = m_option_3; - } + m_zintSymbol->option_3 = m_option_3; m_zintSymbol->scale = m_scale; QByteArray bstr = m_text.toUtf8(); QByteArray pstr = m_primaryMessage.left(99).toLatin1(); diff --git a/backend_qt/qzint.h b/backend_qt/qzint.h index ec154f35..3925fcea 100644 --- a/backend_qt/qzint.h +++ b/backend_qt/qzint.h @@ -65,9 +65,6 @@ public: int borderWidth() const; void setBorderWidth(int boderWidth); - int pdf417CodeWords() const; - void setPdf417CodeWords(int pdf417CodeWords); - int securityLevel() const; void setSecurityLevel(int securityLevel); @@ -111,7 +108,6 @@ private: int m_borderWidth; int m_width; int m_securityLevel; - int m_pdf417CodeWords; int m_input_mode; QColor m_fgColor; QColor m_bgColor; diff --git a/docs/manual.txt b/docs/manual.txt index 0fce77f4..f3f5a9bc 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -1528,7 +1528,7 @@ standard maximum symbol size of 925 codewords which (at error correction level 0) allows a maximum data size of 1850 text characters, or 2710 digits. The width of the generated PDF417 symbol can be specified at the command line using the --cols switch followed by a number between 1 and 30, and the amount of -check digit information can be specified by using the --security switch +check digit information can be specified by using the --secure switch followed by a number between 0 and 8 where the number of codewords used for check information is determined by 2^(value + 1). If using the API these values are assigned to option_2 and option_1 respectively. The default level of check diff --git a/frontend_qt/grpPDF417.ui b/frontend_qt/grpPDF417.ui index 7c9d2427..18a5ee74 100644 --- a/frontend_qt/grpPDF417.ui +++ b/frontend_qt/grpPDF417.ui @@ -205,32 +205,6 @@ - - - Ma&ximum Codeword Lengh: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - codewords - - - - - - - 928 - - - 1800 - - - 928 - - - - S&tandard @@ -240,14 +214,14 @@ - + &HIBC PDF417 - + &Truncated diff --git a/frontend_qt/mainwindow.cpp b/frontend_qt/mainwindow.cpp index e206764e..229d6392 100644 --- a/frontend_qt/mainwindow.cpp +++ b/frontend_qt/mainwindow.cpp @@ -419,7 +419,6 @@ void MainWindow::change_options() m_optionWidget=uiload.load(&file); file.close(); tabMain->insertTab(1,m_optionWidget,tr("PDF417")); - connect(m_optionWidget->findChild("codewords"), SIGNAL(valueChanged( int )), SLOT(update_preview())); connect(m_optionWidget->findChild("cmbPDFECC"), SIGNAL(currentIndexChanged( int )), SLOT(update_preview())); connect(m_optionWidget->findChild("cmbPDFCols"), SIGNAL(currentIndexChanged( int )), SLOT(update_preview())); connect(m_optionWidget->findChild("radPDFTruncated"), SIGNAL(clicked( bool )), SLOT(update_preview())); @@ -859,7 +858,6 @@ void MainWindow::update_preview() case BARCODE_PDF417: m_bc.bc.setWidth(m_optionWidget->findChild("cmbPDFCols")->currentIndex()); m_bc.bc.setSecurityLevel(m_optionWidget->findChild("cmbPDFECC")->currentIndex()-1); - m_bc.bc.setPdf417CodeWords(m_optionWidget->findChild("codewords")->value()); if(m_optionWidget->findChild("radPDFStand")->isChecked()) m_bc.bc.setSymbol(BARCODE_PDF417);