From 739a64a6ff25a0e21c92271e6c5e66d01eb54295 Mon Sep 17 00:00:00 2001 From: gitlost Date: Tue, 23 Nov 2021 19:12:48 +0000 Subject: [PATCH] GUI: add CLI equivalent dialog (#163); use spinboxes in Sequence dialog and restrict sequence to max 10,000, add button icons; make Export dialog sizable and show every 100 results, add button icon; fix saving CHANNEL option, fix Export painting main window (Windows), fix guard descent not-resetting qzint: add getAsCLI(), warnLevel(), extra isStackable()/isComposite() etc Add ZBarcode_BarcodeName() manual: doc above, some fixes, tweaks --- ChangeLog | 2 + backend/code16k.c | 2 +- backend/common.h | 4 + backend/library.c | 178 ++++++++++- backend/tests/testcommon.c | 163 +--------- backend/tests/testcommon.h | 4 - backend/zint.h | 4 + backend_qt/qzint.cpp | 344 +++++++++++++++++--- backend_qt/qzint.h | 64 ++-- backend_qt/tests/test_qzint.cpp | 475 +++++++++++++++++++++++++++- docs/manual.txt | 465 +++++++++++++++------------ frontend_qt/CMakeLists.txt | 15 +- frontend_qt/barcodeitem.h | 1 + frontend_qt/cliwindow.cpp | 103 ++++++ frontend_qt/cliwindow.h | 46 +++ frontend_qt/datawindow.cpp | 44 +-- frontend_qt/datawindow.h | 22 +- frontend_qt/exportwindow.cpp | 220 +++++++------ frontend_qt/exportwindow.h | 22 +- frontend_qt/extCLI.ui | 162 ++++++++++ frontend_qt/extData.ui | 12 +- frontend_qt/extExport.ui | 462 ++++++++++++--------------- frontend_qt/extSequence.ui | 181 ++++++----- frontend_qt/frontend_qt.pro | 7 +- frontend_qt/frontend_qt_zintdll.pro | 5 +- frontend_qt/frontend_vc8.pro | 9 +- frontend_qt/mainwindow.cpp | 290 +++++++---------- frontend_qt/mainwindow.h | 8 +- frontend_qt/res/check.svg | 1 + frontend_qt/res/delete.svg | 1 + frontend_qt/res/zint_black.ico | Bin 0 -> 14134 bytes frontend_qt/resources.qrc | 3 + frontend_qt/sequencewindow.cpp | 118 +++---- frontend_qt/sequencewindow.h | 26 +- 34 files changed, 2264 insertions(+), 1199 deletions(-) create mode 100644 frontend_qt/cliwindow.cpp create mode 100644 frontend_qt/cliwindow.h create mode 100644 frontend_qt/extCLI.ui create mode 100644 frontend_qt/res/check.svg create mode 100644 frontend_qt/res/delete.svg create mode 100644 frontend_qt/res/zint_black.ico diff --git a/ChangeLog b/ChangeLog index 1bb6bb7b..899ff09e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,8 @@ Changes - Add HEIGHTPERROW_MODE input mode flag - DBAR_EXPSTK: add max rows option - CODE16K/CODE49: add min rows option +- GUI: add CLI equivalent dialog (#163) +- Add ZBarcode_BarcodeName() Bugs ---- diff --git a/backend/code16k.c b/backend/code16k.c index 34721ad7..14c15420 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -175,7 +175,7 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len /* Calculate how tall the symbol will be */ glyph_count = glyph_count + 2.0f; - i = (int)glyph_count; + i = (int) glyph_count; rows = (i / 5); if (i % 5 > 0) { rows++; diff --git a/backend/common.h b/backend/common.h index 84af5798..84ac4a42 100644 --- a/backend/common.h +++ b/backend/common.h @@ -42,6 +42,10 @@ #define TRUE 1 #endif +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) +#endif + /* `is_sane()` flags */ #define IS_SPC_F 0x0001 /* Space */ #define IS_HSH_F 0x0002 /* Hash sign # */ diff --git a/backend/library.c b/backend/library.c index ee82b10c..747eb8db 100644 --- a/backend/library.c +++ b/backend/library.c @@ -30,12 +30,13 @@ */ /* vim: set ts=4 sw=4 et : */ -#include +#include #include #include #ifdef _MSC_VER #include #endif +#include #include "common.h" #include "eci.h" #include "gs1.h" @@ -1308,6 +1309,181 @@ int ZBarcode_ValidID(int symbol_id) { return barcode_funcs[symbol_id] != NULL; } +/* Copy BARCODE_XXX name of `symbol_id` into `name` buffer, NUL-terminated. + Returns 0 if valid, non-zero (1 or -1) if not valid */ +int ZBarcode_BarcodeName(int symbol_id, char name[32]) { + struct item { + const char *name; + int define; + int val; + }; + static const struct item data[] = { + { "", -1, 0 }, + { "BARCODE_CODE11", BARCODE_CODE11, 1 }, + { "BARCODE_C25STANDARD", BARCODE_C25STANDARD, 2 }, + { "BARCODE_C25INTER", BARCODE_C25INTER, 3 }, + { "BARCODE_C25IATA", BARCODE_C25IATA, 4 }, + { "", -1, 5 }, + { "BARCODE_C25LOGIC", BARCODE_C25LOGIC, 6 }, + { "BARCODE_C25IND", BARCODE_C25IND, 7 }, + { "BARCODE_CODE39", BARCODE_CODE39, 8 }, + { "BARCODE_EXCODE39", BARCODE_EXCODE39, 9 }, + { "", -1, 10 }, + { "", -1, 11 }, + { "", -1, 12 }, + { "BARCODE_EANX", BARCODE_EANX, 13 }, + { "BARCODE_EANX_CHK", BARCODE_EANX_CHK, 14 }, + { "", -1, 15 }, + { "BARCODE_GS1_128", BARCODE_GS1_128, 16 }, + { "", -1, 17 }, + { "BARCODE_CODABAR", BARCODE_CODABAR, 18 }, + { "", -1, 19 }, + { "BARCODE_CODE128", BARCODE_CODE128, 20 }, + { "BARCODE_DPLEIT", BARCODE_DPLEIT, 21 }, + { "BARCODE_DPIDENT", BARCODE_DPIDENT, 22 }, + { "BARCODE_CODE16K", BARCODE_CODE16K, 23 }, + { "BARCODE_CODE49", BARCODE_CODE49, 24 }, + { "BARCODE_CODE93", BARCODE_CODE93, 25 }, + { "", -1, 26 }, + { "", -1, 27 }, + { "BARCODE_FLAT", BARCODE_FLAT, 28 }, + { "BARCODE_DBAR_OMN", BARCODE_DBAR_OMN, 29 }, + { "BARCODE_DBAR_LTD", BARCODE_DBAR_LTD, 30 }, + { "BARCODE_DBAR_EXP", BARCODE_DBAR_EXP, 31 }, + { "BARCODE_TELEPEN", BARCODE_TELEPEN, 32 }, + { "", -1, 33 }, + { "BARCODE_UPCA", BARCODE_UPCA, 34 }, + { "BARCODE_UPCA_CHK", BARCODE_UPCA_CHK, 35 }, + { "", -1, 36 }, + { "BARCODE_UPCE", BARCODE_UPCE, 37 }, + { "BARCODE_UPCE_CHK", BARCODE_UPCE_CHK, 38 }, + { "", -1, 39 }, + { "BARCODE_POSTNET", BARCODE_POSTNET, 40 }, + { "", -1, 41 }, + { "", -1, 42 }, + { "", -1, 43 }, + { "", -1, 44 }, + { "", -1, 45 }, + { "", -1, 46 }, + { "BARCODE_MSI_PLESSEY", BARCODE_MSI_PLESSEY, 47 }, + { "", -1, 48 }, + { "BARCODE_FIM", BARCODE_FIM, 49 }, + { "BARCODE_LOGMARS", BARCODE_LOGMARS, 50 }, + { "BARCODE_PHARMA", BARCODE_PHARMA, 51 }, + { "BARCODE_PZN", BARCODE_PZN, 52 }, + { "BARCODE_PHARMA_TWO", BARCODE_PHARMA_TWO, 53 }, + { "", -1, 54 }, + { "BARCODE_PDF417", BARCODE_PDF417, 55 }, + { "BARCODE_PDF417COMP", BARCODE_PDF417COMP, 56 }, + { "BARCODE_MAXICODE", BARCODE_MAXICODE, 57 }, + { "BARCODE_QRCODE", BARCODE_QRCODE, 58 }, + { "", -1, 59 }, + { "BARCODE_CODE128B", BARCODE_CODE128B, 60 }, + { "", -1, 61 }, + { "", -1, 62 }, + { "BARCODE_AUSPOST", BARCODE_AUSPOST, 63 }, + { "", -1, 64 }, + { "", -1, 65 }, + { "BARCODE_AUSREPLY", BARCODE_AUSREPLY, 66 }, + { "BARCODE_AUSROUTE", BARCODE_AUSROUTE, 67 }, + { "BARCODE_AUSREDIRECT", BARCODE_AUSREDIRECT, 68 }, + { "BARCODE_ISBNX", BARCODE_ISBNX, 69 }, + { "BARCODE_RM4SCC", BARCODE_RM4SCC, 70 }, + { "BARCODE_DATAMATRIX", BARCODE_DATAMATRIX, 71 }, + { "BARCODE_EAN14", BARCODE_EAN14, 72 }, + { "BARCODE_VIN", BARCODE_VIN, 73 }, + { "BARCODE_CODABLOCKF", BARCODE_CODABLOCKF, 74 }, + { "BARCODE_NVE18", BARCODE_NVE18, 75 }, + { "BARCODE_JAPANPOST", BARCODE_JAPANPOST, 76 }, + { "BARCODE_KOREAPOST", BARCODE_KOREAPOST, 77 }, + { "", -1, 78 }, + { "BARCODE_DBAR_STK", BARCODE_DBAR_STK, 79 }, + { "BARCODE_DBAR_OMNSTK", BARCODE_DBAR_OMNSTK, 80 }, + { "BARCODE_DBAR_EXPSTK", BARCODE_DBAR_EXPSTK, 81 }, + { "BARCODE_PLANET", BARCODE_PLANET, 82 }, + { "", -1, 83 }, + { "BARCODE_MICROPDF417", BARCODE_MICROPDF417, 84 }, + { "BARCODE_USPS_IMAIL", BARCODE_USPS_IMAIL, 85 }, + { "BARCODE_PLESSEY", BARCODE_PLESSEY, 86 }, + { "BARCODE_TELEPEN_NUM", BARCODE_TELEPEN_NUM, 87 }, + { "", -1, 88 }, + { "BARCODE_ITF14", BARCODE_ITF14, 89 }, + { "BARCODE_KIX", BARCODE_KIX, 90 }, + { "", -1, 91 }, + { "BARCODE_AZTEC", BARCODE_AZTEC, 92 }, + { "BARCODE_DAFT", BARCODE_DAFT, 93 }, + { "", -1, 94 }, + { "", -1, 95 }, + { "BARCODE_DPD", BARCODE_DPD, 96 }, + { "BARCODE_MICROQR", BARCODE_MICROQR, 97 }, + { "BARCODE_HIBC_128", BARCODE_HIBC_128, 98 }, + { "BARCODE_HIBC_39", BARCODE_HIBC_39, 99 }, + { "", -1, 100 }, + { "", -1, 101 }, + { "BARCODE_HIBC_DM", BARCODE_HIBC_DM, 102 }, + { "", -1, 103 }, + { "BARCODE_HIBC_QR", BARCODE_HIBC_QR, 104 }, + { "", -1, 105 }, + { "BARCODE_HIBC_PDF", BARCODE_HIBC_PDF, 106 }, + { "", -1, 107 }, + { "BARCODE_HIBC_MICPDF", BARCODE_HIBC_MICPDF, 108 }, + { "", -1, 109 }, + { "BARCODE_HIBC_BLOCKF", BARCODE_HIBC_BLOCKF, 110 }, + { "", -1, 111 }, + { "BARCODE_HIBC_AZTEC", BARCODE_HIBC_AZTEC, 112 }, + { "", -1, 113 }, + { "", -1, 114 }, + { "BARCODE_DOTCODE", BARCODE_DOTCODE, 115 }, + { "BARCODE_HANXIN", BARCODE_HANXIN, 116 }, + { "", -1, 117 }, + { "", -1, 118 }, + { "", -1, 119 }, + { "", -1, 120 }, + { "BARCODE_MAILMARK", BARCODE_MAILMARK, 121 }, + { "", -1, 122 }, + { "", -1, 123 }, + { "", -1, 124 }, + { "", -1, 125 }, + { "", -1, 126 }, + { "", -1, 127 }, + { "BARCODE_AZRUNE", BARCODE_AZRUNE, 128 }, + { "BARCODE_CODE32", BARCODE_CODE32, 129 }, + { "BARCODE_EANX_CC", BARCODE_EANX_CC, 130 }, + { "BARCODE_GS1_128_CC", BARCODE_GS1_128_CC, 131 }, + { "BARCODE_DBAR_OMN_CC", BARCODE_DBAR_OMN_CC, 132 }, + { "BARCODE_DBAR_LTD_CC", BARCODE_DBAR_LTD_CC, 133 }, + { "BARCODE_DBAR_EXP_CC", BARCODE_DBAR_EXP_CC, 134 }, + { "BARCODE_UPCA_CC", BARCODE_UPCA_CC, 135 }, + { "BARCODE_UPCE_CC", BARCODE_UPCE_CC, 136 }, + { "BARCODE_DBAR_STK_CC", BARCODE_DBAR_STK_CC, 137 }, + { "BARCODE_DBAR_OMNSTK_CC", BARCODE_DBAR_OMNSTK_CC, 138 }, + { "BARCODE_DBAR_EXPSTK_CC", BARCODE_DBAR_EXPSTK_CC, 139 }, + { "BARCODE_CHANNEL", BARCODE_CHANNEL, 140 }, + { "BARCODE_CODEONE", BARCODE_CODEONE, 141 }, + { "BARCODE_GRIDMATRIX", BARCODE_GRIDMATRIX, 142 }, + { "BARCODE_UPNQR", BARCODE_UPNQR, 143 }, + { "BARCODE_ULTRA", BARCODE_ULTRA, 144 }, + { "BARCODE_RMQR", BARCODE_RMQR, 145 }, + }; + + name[0] = '\0'; + + if (!ZBarcode_ValidID(symbol_id)) { + return 1; + } + assert(symbol_id >= 0 && symbol_id < ARRAY_SIZE(data) && data[symbol_id].name[0]); + + /* Self-check, shouldn't happen */ + if (data[symbol_id].val != symbol_id || (data[symbol_id].define != -1 && data[symbol_id].define != symbol_id)) { + assert(0); /* Not reached */ + return -1; + } + + strcpy(name, data[symbol_id].name); + + return 0; +} + /* Return the capability flags for symbology `symbol_id` that match `cap_flag` */ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { unsigned int result = 0; diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index 35a88ebd..56f02518 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -330,170 +330,13 @@ int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, /* Pretty name for symbology */ const char *testUtilBarcodeName(int symbology) { - struct item { - const char *name; - int define; - int val; - }; - static const struct item data[] = { - { "", -1, 0 }, - { "BARCODE_CODE11", BARCODE_CODE11, 1 }, - { "BARCODE_C25STANDARD", BARCODE_C25STANDARD, 2 }, - { "BARCODE_C25INTER", BARCODE_C25INTER, 3 }, - { "BARCODE_C25IATA", BARCODE_C25IATA, 4 }, - { "", -1, 5 }, - { "BARCODE_C25LOGIC", BARCODE_C25LOGIC, 6 }, - { "BARCODE_C25IND", BARCODE_C25IND, 7 }, - { "BARCODE_CODE39", BARCODE_CODE39, 8 }, - { "BARCODE_EXCODE39", BARCODE_EXCODE39, 9 }, - { "", -1, 10 }, - { "", -1, 11 }, - { "", -1, 12 }, - { "BARCODE_EANX", BARCODE_EANX, 13 }, - { "BARCODE_EANX_CHK", BARCODE_EANX_CHK, 14 }, - { "", -1, 15 }, - { "BARCODE_GS1_128", BARCODE_GS1_128, 16 }, - { "", -1, 17 }, - { "BARCODE_CODABAR", BARCODE_CODABAR, 18 }, - { "", -1, 19 }, - { "BARCODE_CODE128", BARCODE_CODE128, 20 }, - { "BARCODE_DPLEIT", BARCODE_DPLEIT, 21 }, - { "BARCODE_DPIDENT", BARCODE_DPIDENT, 22 }, - { "BARCODE_CODE16K", BARCODE_CODE16K, 23 }, - { "BARCODE_CODE49", BARCODE_CODE49, 24 }, - { "BARCODE_CODE93", BARCODE_CODE93, 25 }, - { "", -1, 26 }, - { "", -1, 27 }, - { "BARCODE_FLAT", BARCODE_FLAT, 28 }, - { "BARCODE_DBAR_OMN", BARCODE_DBAR_OMN, 29 }, - { "BARCODE_DBAR_LTD", BARCODE_DBAR_LTD, 30 }, - { "BARCODE_DBAR_EXP", BARCODE_DBAR_EXP, 31 }, - { "BARCODE_TELEPEN", BARCODE_TELEPEN, 32 }, - { "", -1, 33 }, - { "BARCODE_UPCA", BARCODE_UPCA, 34 }, - { "BARCODE_UPCA_CHK", BARCODE_UPCA_CHK, 35 }, - { "", -1, 36 }, - { "BARCODE_UPCE", BARCODE_UPCE, 37 }, - { "BARCODE_UPCE_CHK", BARCODE_UPCE_CHK, 38 }, - { "", -1, 39 }, - { "BARCODE_POSTNET", BARCODE_POSTNET, 40 }, - { "", -1, 41 }, - { "", -1, 42 }, - { "", -1, 43 }, - { "", -1, 44 }, - { "", -1, 45 }, - { "", -1, 46 }, - { "BARCODE_MSI_PLESSEY", BARCODE_MSI_PLESSEY, 47 }, - { "", -1, 48 }, - { "BARCODE_FIM", BARCODE_FIM, 49 }, - { "BARCODE_LOGMARS", BARCODE_LOGMARS, 50 }, - { "BARCODE_PHARMA", BARCODE_PHARMA, 51 }, - { "BARCODE_PZN", BARCODE_PZN, 52 }, - { "BARCODE_PHARMA_TWO", BARCODE_PHARMA_TWO, 53 }, - { "", -1, 54 }, - { "BARCODE_PDF417", BARCODE_PDF417, 55 }, - { "BARCODE_PDF417COMP", BARCODE_PDF417COMP, 56 }, - { "BARCODE_MAXICODE", BARCODE_MAXICODE, 57 }, - { "BARCODE_QRCODE", BARCODE_QRCODE, 58 }, - { "", -1, 59 }, - { "BARCODE_CODE128B", BARCODE_CODE128B, 60 }, - { "", -1, 61 }, - { "", -1, 62 }, - { "BARCODE_AUSPOST", BARCODE_AUSPOST, 63 }, - { "", -1, 64 }, - { "", -1, 65 }, - { "BARCODE_AUSREPLY", BARCODE_AUSREPLY, 66 }, - { "BARCODE_AUSROUTE", BARCODE_AUSROUTE, 67 }, - { "BARCODE_AUSREDIRECT", BARCODE_AUSREDIRECT, 68 }, - { "BARCODE_ISBNX", BARCODE_ISBNX, 69 }, - { "BARCODE_RM4SCC", BARCODE_RM4SCC, 70 }, - { "BARCODE_DATAMATRIX", BARCODE_DATAMATRIX, 71 }, - { "BARCODE_EAN14", BARCODE_EAN14, 72 }, - { "BARCODE_VIN", BARCODE_VIN, 73 }, - { "BARCODE_CODABLOCKF", BARCODE_CODABLOCKF, 74 }, - { "BARCODE_NVE18", BARCODE_NVE18, 75 }, - { "BARCODE_JAPANPOST", BARCODE_JAPANPOST, 76 }, - { "BARCODE_KOREAPOST", BARCODE_KOREAPOST, 77 }, - { "", -1, 78 }, - { "BARCODE_DBAR_STK", BARCODE_DBAR_STK, 79 }, - { "BARCODE_DBAR_OMNSTK", BARCODE_DBAR_OMNSTK, 80 }, - { "BARCODE_DBAR_EXPSTK", BARCODE_DBAR_EXPSTK, 81 }, - { "BARCODE_PLANET", BARCODE_PLANET, 82 }, - { "", -1, 83 }, - { "BARCODE_MICROPDF417", BARCODE_MICROPDF417, 84 }, - { "BARCODE_USPS_IMAIL", BARCODE_USPS_IMAIL, 85 }, - { "BARCODE_PLESSEY", BARCODE_PLESSEY, 86 }, - { "BARCODE_TELEPEN_NUM", BARCODE_TELEPEN_NUM, 87 }, - { "", -1, 88 }, - { "BARCODE_ITF14", BARCODE_ITF14, 89 }, - { "BARCODE_KIX", BARCODE_KIX, 90 }, - { "", -1, 91 }, - { "BARCODE_AZTEC", BARCODE_AZTEC, 92 }, - { "BARCODE_DAFT", BARCODE_DAFT, 93 }, - { "", -1, 94 }, - { "", -1, 95 }, - { "BARCODE_DPD", BARCODE_DPD, 96 }, - { "BARCODE_MICROQR", BARCODE_MICROQR, 97 }, - { "BARCODE_HIBC_128", BARCODE_HIBC_128, 98 }, - { "BARCODE_HIBC_39", BARCODE_HIBC_39, 99 }, - { "", -1, 100 }, - { "", -1, 101 }, - { "BARCODE_HIBC_DM", BARCODE_HIBC_DM, 102 }, - { "", -1, 103 }, - { "BARCODE_HIBC_QR", BARCODE_HIBC_QR, 104 }, - { "", -1, 105 }, - { "BARCODE_HIBC_PDF", BARCODE_HIBC_PDF, 106 }, - { "", -1, 107 }, - { "BARCODE_HIBC_MICPDF", BARCODE_HIBC_MICPDF, 108 }, - { "", -1, 109 }, - { "BARCODE_HIBC_BLOCKF", BARCODE_HIBC_BLOCKF, 110 }, - { "", -1, 111 }, - { "BARCODE_HIBC_AZTEC", BARCODE_HIBC_AZTEC, 112 }, - { "", -1, 113 }, - { "", -1, 114 }, - { "BARCODE_DOTCODE", BARCODE_DOTCODE, 115 }, - { "BARCODE_HANXIN", BARCODE_HANXIN, 116 }, - { "", -1, 117 }, - { "", -1, 118 }, - { "", -1, 119 }, - { "", -1, 120 }, - { "BARCODE_MAILMARK", BARCODE_MAILMARK, 121 }, - { "", -1, 122 }, - { "", -1, 123 }, - { "", -1, 124 }, - { "", -1, 125 }, - { "", -1, 126 }, - { "", -1, 127 }, - { "BARCODE_AZRUNE", BARCODE_AZRUNE, 128 }, - { "BARCODE_CODE32", BARCODE_CODE32, 129 }, - { "BARCODE_EANX_CC", BARCODE_EANX_CC, 130 }, - { "BARCODE_GS1_128_CC", BARCODE_GS1_128_CC, 131 }, - { "BARCODE_DBAR_OMN_CC", BARCODE_DBAR_OMN_CC, 132 }, - { "BARCODE_DBAR_LTD_CC", BARCODE_DBAR_LTD_CC, 133 }, - { "BARCODE_DBAR_EXP_CC", BARCODE_DBAR_EXP_CC, 134 }, - { "BARCODE_UPCA_CC", BARCODE_UPCA_CC, 135 }, - { "BARCODE_UPCE_CC", BARCODE_UPCE_CC, 136 }, - { "BARCODE_DBAR_STK_CC", BARCODE_DBAR_STK_CC, 137 }, - { "BARCODE_DBAR_OMNSTK_CC", BARCODE_DBAR_OMNSTK_CC, 138 }, - { "BARCODE_DBAR_EXPSTK_CC", BARCODE_DBAR_EXPSTK_CC, 139 }, - { "BARCODE_CHANNEL", BARCODE_CHANNEL, 140 }, - { "BARCODE_CODEONE", BARCODE_CODEONE, 141 }, - { "BARCODE_GRIDMATRIX", BARCODE_GRIDMATRIX, 142 }, - { "BARCODE_UPNQR", BARCODE_UPNQR, 143 }, - { "BARCODE_ULTRA", BARCODE_ULTRA, 144 }, - { "BARCODE_RMQR", BARCODE_RMQR, 145 }, - }; - static const int data_size = ARRAY_SIZE(data); + static char name[32]; - if (symbology < 0 || symbology >= data_size) { - return ""; - } - // Self-check - if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { + if (ZBarcode_BarcodeName(symbology, name) == -1) { fprintf(stderr, "testUtilBarcodeName: data table out of sync (%d)\n", symbology); abort(); } - return data[symbology].name; + return name; } /* Pretty name for error/warning */ diff --git a/backend/tests/testcommon.h b/backend/tests/testcommon.h index fa2cab4c..8c8e0564 100644 --- a/backend/tests/testcommon.h +++ b/backend/tests/testcommon.h @@ -70,10 +70,6 @@ extern "C" { #endif -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) -#endif - extern int assertionFailed; extern int assertionNum; extern const char *assertionFilename; diff --git a/backend/zint.h b/backend/zint.h index d7b62107..da8f9d3c 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -404,6 +404,10 @@ extern "C" { /* Is `symbol_id` a recognized symbology? */ ZINT_EXTERN int ZBarcode_ValidID(int symbol_id); + /* Copy BARCODE_XXX name of `symbol_id` into `name` buffer, NUL-terminated. + Returns 0 if valid, non-zero (1 or -1) if not valid */ + ZINT_EXTERN int ZBarcode_BarcodeName(int symbol_id, char name[32]); + /* Return the capability flags for symbology `symbol_id` that match `cap_flag` */ ZINT_EXTERN unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag); diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index bd29b8f1..d2506787 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -31,49 +31,39 @@ /* Qt 5.7 did not require it. */ #include +// Shorthand +#define QSL QStringLiteral + namespace Zint { static const char *fontStyle = "Helvetica"; static const char *fontStyleError = "Helvetica"; static const int fontSizeError = 14; /* Point size */ - QZint::QZint() { - m_zintSymbol = NULL; - m_symbol = BARCODE_CODE128; - m_height = 0.0f; - m_borderType = 0; - m_borderWidth = 0; - m_fontSetting = 0; - m_option_1 = -1; - m_option_2 = 0; - m_option_3 = 0; - m_fgColor = Qt::black; - m_bgColor = Qt::white; - m_cmyk = false; - m_error = 0; - m_input_mode = UNICODE_MODE; - m_scale = 1.0f; - m_show_hrt = 1; - m_eci = 0; - m_dotty = false; - m_dot_size = 4.0f / 5.0f; - m_guardDescent = 5.0f; + QZint::QZint() + : m_zintSymbol(NULL), m_symbol(BARCODE_CODE128), m_input_mode(UNICODE_MODE), + m_height(0.0f), + m_option_1(-1), m_option_2(0), m_option_3(0), + m_scale(1.0f), + m_dotty(false), m_dot_size(4.0f / 5.0f), + m_guardDescent(5.0f), + m_fgColor(Qt::black), m_bgColor(Qt::white), m_cmyk(false), + m_borderType(0), m_borderWidth(0), + m_whitespace(0), m_vwhitespace(0), + m_fontSetting(0), + m_show_hrt(true), + m_gssep(false), + m_quiet_zones(false), m_no_quiet_zones(false), + m_compliant_height(false), + m_rotate_angle(0), + m_eci(0), + m_gs1parens(false), m_gs1nocheck(false), + m_reader_init(false), + m_warn_level(WARN_DEFAULT), m_debug(false), + m_encodedWidth(0), m_encodedRows(0), + m_error(0), + target_size_horiz(0), target_size_vert(0) // Legacy + { memset(&m_structapp, 0, sizeof(m_structapp)); - m_whitespace = 0; - m_vwhitespace = 0; - m_gs1parens = false; - m_gs1nocheck = false; - m_gssep = false; - m_quiet_zones = false; - m_no_quiet_zones = false; - m_compliant_height = false; - m_reader_init = false; - m_rotate_angle = 0; - m_debug = false; - m_encodedWidth = 0; - m_encodedRows = 0; - - target_size_horiz = 0; /* Legacy */ - target_size_vert = 0; /* Legacy */ } QZint::~QZint() { @@ -127,16 +117,19 @@ namespace Zint { if (m_reader_init) { m_zintSymbol->output_options |= READER_INIT; } + if (m_warn_level) { + m_zintSymbol->warn_level = m_warn_level; + } if (m_debug) { m_zintSymbol->debug |= ZINT_DEBUG_PRINT; } strcpy(m_zintSymbol->fgcolour, m_fgColor.name().toLatin1().right(6)); - if (m_fgColor.alpha() != 0xff) { + if (m_fgColor.alpha() != 0xFF) { strcat(m_zintSymbol->fgcolour, m_fgColor.name(QColor::HexArgb).toLatin1().mid(1,2)); } strcpy(m_zintSymbol->bgcolour, m_bgColor.name().toLatin1().right(6)); - if (m_bgColor.alpha() != 0xff) { + if (m_bgColor.alpha() != 0xFF) { strcat(m_zintSymbol->bgcolour, m_bgColor.name(QColor::HexArgb).toLatin1().mid(1,2)); } if (m_cmyk) { @@ -507,6 +500,14 @@ namespace Zint { m_reader_init = readerInit; } + int QZint::warnLevel() const { + return m_warn_level; + } + + void QZint::setWarnLevel(int warnLevel) { + m_warn_level = warnLevel; + } + bool QZint::debug() const { return m_debug; } @@ -541,10 +542,18 @@ namespace Zint { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_HRT); } + bool QZint::isStackable(int symbology) const { + return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_STACKABLE); + } + bool QZint::isExtendable(int symbology) const { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_EXTENDABLE); } + bool QZint::isComposite(int symbology) const { + return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_COMPOSITE); + } + bool QZint::supportsECI(int symbology) const { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_ECI); } @@ -553,6 +562,10 @@ namespace Zint { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_GS1); } + bool QZint::isDotty(int symbology) const { + return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_DOTTY); + } + bool QZint::hasDefaultQuietZones(int symbology) const { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_QUIET_ZONES); } @@ -561,14 +574,22 @@ namespace Zint { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_FIXED_RATIO); } - bool QZint::isDotty(int symbology) const { - return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_DOTTY); - } - bool QZint::supportsReaderInit(int symbology) const { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_READER_INIT); } + bool QZint::supportsFullMultibyte(int symbology) const { + return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_FULL_MULTIBYTE); + } + + bool QZint::hasMask(int symbology) const { + return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_MASK); + } + + bool QZint::supportsStructApp(int symbology) const { + return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_STRUCTAPP); + } + bool QZint::hasCompliantHeight(int symbology) const { return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_COMPLIANT_HEIGHT); } @@ -589,7 +610,7 @@ namespace Zint { return ZBarcode_Version(); } - bool QZint::save_to_file(QString filename) { + bool QZint::save_to_file(const QString &filename) { resetSymbol(); strcpy(m_zintSymbol->outfile, filename.toLatin1().left(255)); QByteArray bstr = m_text.toUtf8(); @@ -796,4 +817,239 @@ namespace Zint { painter.restore(); } + + /* Translate settings into Command Line equivalent. Set `win` to use Windows escaping of data. + If `autoHeight` set then `--height=` option will not be emitted. + If HEIGHTPERROW_MODE set and non-zero `heightPerRow` given then use that for height instead of internal + height */ + QString QZint::getAsCLI(const bool win, const bool longOptOnly, const bool barcodeNames, + const bool autoHeight, const float heightPerRow, const QString &outfile) const { + QString cmd(win ? QSL("zint.exe") : QSL("zint")); + + char name_buf[32]; + if (barcodeNames && ZBarcode_BarcodeName(m_symbol, name_buf) == 0) { + QString name(name_buf + 8); // Strip "BARCODE_" prefix + arg_str(cmd, longOptOnly ? "--barcode=" : "-b ", name); + } else { + arg_int(cmd, longOptOnly ? "--barcode=" : "-b ", m_symbol); + } + + if (isExtendable()) { + arg_int(cmd, "--addongap=", option2()); + } + + if (bgColor() != Qt::white && bgColor() != QColor(0xFF, 0xFF, 0xFF, 0)) { + arg_color(cmd, "--bg=", bgColor()); + } + + arg_bool(cmd, "--binary", (inputMode() & 0x07) == DATA_MODE); + arg_bool(cmd, "--bind", (borderType() & BARCODE_BIND) && !(borderType() & BARCODE_BOX)); + arg_bool(cmd, "--bold", fontSetting() & BOLD_TEXT); + arg_int(cmd, "--border=", borderWidth()); + arg_bool(cmd, "--box", borderType() & BARCODE_BOX); + arg_bool(cmd, "--cmyk", cmyk()); + + if (m_symbol == BARCODE_DBAR_EXPSTK || m_symbol == BARCODE_DBAR_EXPSTK_CC + || m_symbol == BARCODE_PDF417 || m_symbol == BARCODE_PDF417COMP || m_symbol == BARCODE_HIBC_PDF + || m_symbol == BARCODE_MICROPDF417 || m_symbol == BARCODE_HIBC_MICPDF + || m_symbol == BARCODE_DOTCODE || m_symbol == BARCODE_CODABLOCKF || m_symbol == BARCODE_HIBC_BLOCKF) { + arg_int(cmd, "--cols=", option2()); + } + + arg_bool(cmd, "--compliantheight", hasCompliantHeight() && compliantHeight()); + arg_data(cmd, longOptOnly ? "--data=" : "-d ", text(), win); + + if (m_symbol == BARCODE_DATAMATRIX || m_symbol == BARCODE_HIBC_DM) { + arg_bool(cmd, "--dmre", option3() == DM_DMRE); + } + + if ((m_symbol == BARCODE_DOTCODE || (isDotty() && dotty())) && dotSize() != 0.8f) { + arg_float(cmd, "--dotsize=", dotSize()); + } + if (m_symbol != BARCODE_DOTCODE && isDotty() && dotty()) { + arg_bool(cmd, "--dotty", dotty()); + } + + if (supportsECI()) { + arg_int(cmd, "--eci=", eci()); + } + + arg_bool(cmd, "--esc", inputMode() & ESCAPE_MODE); + + if (fgColor() != Qt::black) { + arg_color(cmd, "--fg=", fgColor()); + } + + arg_bool(cmd, "--fullmultibyte", supportsFullMultibyte() && (option3() & 0xFF) == ZINT_FULL_MULTIBYTE); + + if (supportsGS1()) { + arg_bool(cmd, "--gs1", (inputMode() & 0x07) == GS1_MODE); + arg_bool(cmd, "--gs1parens", gs1Parens()); + arg_bool(cmd, "--gs1nocheck", gs1NoCheck()); + arg_bool(cmd, "--gssep", gsSep()); + } + + if (isExtendable() && guardDescent() != 5.0f) { + arg_float(cmd, "--guarddescent=", guardDescent(), true /*allowZero*/); + } + + if (!autoHeight && !isFixedRatio()) { + if (inputMode() & HEIGHTPERROW_MODE) { + arg_float(cmd, "--height=", heightPerRow ? heightPerRow : height()); + arg_bool(cmd, "--heightperrow", true); + } else { + arg_float(cmd, "--height=", height()); + } + } + + arg_bool(cmd, "--init", supportsReaderInit() && readerInit()); + + if (hasMask()) { + arg_int(cmd, "--mask=", (option3() >> 8) - 1, true /*allowZero*/); + } + + if (m_symbol == BARCODE_MAXICODE || isComposite()) { + arg_int(cmd, "--mode=", option1()); + } + + arg_bool(cmd, "--nobackground", bgColor() == QColor(0xFF, 0xFF, 0xFF, 0)); + arg_bool(cmd, "--noquietzones", hasDefaultQuietZones() && noQuietZones()); + arg_bool(cmd, "--notext", hasHRT() && !showText()); + arg_data(cmd, longOptOnly ? "--output=" : "-o ", outfile, win); + + if (m_symbol == BARCODE_MAXICODE || isComposite()) { + arg_data(cmd, "--primary=", primaryMessage(), win); + } + + arg_bool(cmd, "--quietzones", !hasDefaultQuietZones() && quietZones()); + arg_int(cmd, "--rotate=", rotateAngle()); + + if (m_symbol == BARCODE_CODE16K || m_symbol == BARCODE_CODABLOCKF || m_symbol == BARCODE_HIBC_BLOCKF + || m_symbol == BARCODE_CODE49) { + arg_int(cmd, "--rows=", option1()); + } else if (m_symbol == BARCODE_DBAR_EXPSTK || m_symbol == BARCODE_DBAR_EXPSTK_CC + || m_symbol == BARCODE_PDF417 || m_symbol == BARCODE_PDF417COMP || m_symbol == BARCODE_HIBC_PDF) { + arg_int(cmd, "--rows=", option3()); + } + + if (scale() != 1.0f) { + arg_float(cmd, "--scale=", scale()); + } + + if (m_symbol == BARCODE_MAXICODE) { + arg_int(cmd, "--scmvv=", option2() - 1, true /*allowZero*/); + } + + if (m_symbol == BARCODE_PDF417 || m_symbol == BARCODE_PDF417COMP || m_symbol == BARCODE_HIBC_PDF + || m_symbol == BARCODE_AZTEC || m_symbol == BARCODE_HIBC_AZTEC + || m_symbol == BARCODE_QRCODE || m_symbol == BARCODE_HIBC_QR || m_symbol == BARCODE_MICROQR + || m_symbol == BARCODE_RMQR || m_symbol == BARCODE_GRIDMATRIX || m_symbol == BARCODE_HANXIN + || m_symbol == BARCODE_ULTRA) { + arg_int(cmd, "--secure=", option1()); + } + + if (m_symbol == BARCODE_CODE16K || m_symbol == BARCODE_CODABLOCKF || m_symbol == BARCODE_HIBC_BLOCKF + || m_symbol == BARCODE_CODE49) { + arg_int(cmd, "--separator=", option3()); + } + + arg_bool(cmd, "--small", fontSetting() & SMALL_TEXT); + + if (m_symbol == BARCODE_DATAMATRIX || m_symbol == BARCODE_HIBC_DM) { + arg_bool(cmd, "--square", option3() == DM_SQUARE); + } + + if (supportsStructApp()) { + arg_structapp(cmd, "--structapp=", structAppCount(), structAppIndex(), structAppID(), win); + } + + arg_bool(cmd, "--verbose", debug()); + + if (m_symbol == BARCODE_AZTEC || m_symbol == BARCODE_HIBC_AZTEC + || m_symbol == BARCODE_MSI_PLESSEY || m_symbol == BARCODE_CODE11 + || m_symbol == BARCODE_C25STANDARD || m_symbol == BARCODE_C25INTER || m_symbol == BARCODE_C25IATA + || m_symbol == BARCODE_C25LOGIC || m_symbol == BARCODE_C25IND + || m_symbol == BARCODE_CODE39 || m_symbol == BARCODE_HIBC_39 || m_symbol == BARCODE_EXCODE39 + || m_symbol == BARCODE_LOGMARS || m_symbol == BARCODE_CODABAR + || m_symbol == BARCODE_DATAMATRIX || m_symbol == BARCODE_HIBC_DM + || m_symbol == BARCODE_QRCODE || m_symbol == BARCODE_HIBC_QR || m_symbol == BARCODE_MICROQR + || m_symbol == BARCODE_RMQR || m_symbol == BARCODE_GRIDMATRIX || m_symbol == BARCODE_HANXIN + || m_symbol == BARCODE_CHANNEL || m_symbol == BARCODE_CODEONE || m_symbol == BARCODE_CODE93 + || m_symbol == BARCODE_ULTRA || m_symbol == BARCODE_VIN) { + arg_int(cmd, "--vers=", option2()); + } else if (m_symbol == BARCODE_DAFT && option2() != 250) { + arg_int(cmd, "--vers=", option2()); + } + + arg_int(cmd, "--vwhitesp=", vWhitespace()); + arg_int(cmd, longOptOnly ? "--whitesp=" : "-w ", whitespace()); + arg_bool(cmd, "--werror", warnLevel() == WARN_FAIL_ALL); + + return cmd; + } + + /* `getAsCLI()` helpers */ + void QZint::arg_str(QString &cmd, const char *const opt, const QString &val) { + if (!val.isEmpty()) { + QByteArray bstr = val.toUtf8(); + cmd += QString::asprintf(" %s%.*s", opt, bstr.length(), bstr.data()); + } + } + + void QZint::arg_int(QString &cmd, const char *const opt, const int val, const bool allowZero) { + if (val > 0 || (val == 0 && allowZero)) { + cmd += QString::asprintf(" %s%d", opt, val); + } + } + + void QZint::arg_bool(QString &cmd, const char *const opt, const bool val) { + if (val) { + cmd += QString::asprintf(" %s", opt); + } + } + + void QZint::arg_color(QString &cmd, const char *const opt, const QColor val) { + if (val.alpha() != 0xFF) { + cmd += QString::asprintf(" %s%02X%02X%02X%02X", opt, val.red(), val.green(), val.blue(), val.alpha()); + } else { + cmd += QString::asprintf(" %s%02X%02X%02X", opt, val.red(), val.green(), val.blue()); + } + } + + void QZint::arg_data(QString &cmd, const char *const opt, const QString &val, const bool win) { + if (!val.isEmpty()) { + QString text(val); + const char delim = win ? '"' : '\''; + if (win) { + // Difficult (impossible?) to fully escape strings on Windows, e.g. "blah%PATH%" will substitute + // env var PATH, so just doing basic escaping here + text.replace("\\\\", "\\\\\\\\"); // Double-up backslashed backslash `\\` -> `\\\\` + text.replace("\"", "\\\""); // Backslash quote `"` -> `\"` + QByteArray bstr = text.toUtf8(); + cmd += QString::asprintf(" %s%c%.*s%c", opt, delim, bstr.length(), bstr.data(), delim); + } else { + text.replace("'", "'\\''"); // Single quote `'` -> `'\''` + QByteArray bstr = text.toUtf8(); + cmd += QString::asprintf(" %s%c%.*s%c", opt, delim, bstr.length(), bstr.data(), delim); + } + } + } + + void QZint::arg_float(QString &cmd, const char *const opt, const float val, const bool allowZero) { + if (val > 0 || (val == 0 && allowZero)) { + cmd += QString::asprintf(" %s%g", opt, val); + } + } + + void QZint::arg_structapp(QString &cmd, const char *const opt, const int count, const int index, + const QString &id, const bool win) { + if (count >= 2 && index >= 1) { + if (id.isEmpty()) { + cmd += QString::asprintf(" %s%d,%d", opt, index, count); + } else { + QByteArray bstr = id.toUtf8(); + arg_data(cmd, opt, QString::asprintf("%d,%d,%.*s", index, count, bstr.length(), bstr.data()), win); + } + } + } } /* namespace Zint */ diff --git a/backend_qt/qzint.h b/backend_qt/qzint.h index 6bfbd4bb..ce7832e6 100644 --- a/backend_qt/qzint.h +++ b/backend_qt/qzint.h @@ -136,6 +136,9 @@ public: bool readerInit() const; void setReaderInit(bool readerInit); + int warnLevel() const; + void setWarnLevel(int warnLevel); + bool debug() const; void setDebug(bool debug); @@ -155,13 +158,18 @@ public: /* Test capabilities - ZBarcode_Cap() */ bool hasHRT(int symbology = 0) const; + bool isStackable(int symbology = 0) const; bool isExtendable(int symbology = 0) const; + bool isComposite(int symbology = 0) const; bool supportsECI(int symbology = 0) const; bool supportsGS1(int symbology = 0) const; + bool isDotty(int symbology = 0) const; bool hasDefaultQuietZones(int symbology = 0) const; bool isFixedRatio(int symbology = 0) const; - bool isDotty(int symbology = 0) const; bool supportsReaderInit(int symbology = 0) const; + bool supportsFullMultibyte(int symbology = 0) const; + bool hasMask(int symbology = 0) const; + bool supportsStructApp(int symbology = 0) const; bool hasCompliantHeight(int symbology = 0) const; int getError() const; @@ -169,13 +177,20 @@ public: const QString& lastError() const; bool hasErrors() const; - bool save_to_file(QString filename); + bool save_to_file(const QString &filename); /* Note: legacy argument `mode` is not used */ void render(QPainter& painter, const QRectF& paintRect, AspectRatioMode mode = IgnoreAspectRatio); int getVersion() const; + /* Translate settings into Command Line equivalent. Set `win` to use Windows escaping of data. + If `autoHeight` set then `--height=` option will not be emitted. + If HEIGHTPERROW_MODE set and non-zero `heightPerRow` given then use that for height instead of internal + height */ + QString getAsCLI(const bool win, const bool longOptOnly = false, const bool barcodeNames = false, + const bool autoHeight = false, const float heightPerRow = 0.0f, const QString &outfile = "") const; + signals: void encoded(); void errored(); @@ -185,44 +200,55 @@ private: void encode(); static Qt::GlobalColor colourToQtColor(int colour); + /* `getAsCLI()` helpers */ + static void arg_str(QString &cmd, const char *const opt, const QString &val); + static void arg_int(QString &cmd, const char *const opt, const int val, const bool allowZero = false); + static void arg_bool(QString &cmd, const char *const opt, const bool val); + static void arg_color(QString &cmd, const char *const opt, const QColor val); + static void arg_data(QString &cmd, const char *const opt, const QString &val, const bool win); + static void arg_float(QString &cmd, const char *const opt, const float val, const bool allowZero = false); + static void arg_structapp(QString &cmd, const char *const opt, const int count, const int index, + const QString &id, const bool win); + private: + zint_symbol *m_zintSymbol; int m_symbol; + int m_input_mode; QString m_text; QString m_primaryMessage; float m_height; - int m_borderType; - int m_borderWidth; - int m_fontSetting; int m_option_1; int m_option_2; int m_option_3; - int m_input_mode; - QColor m_fgColor; - QColor m_bgColor; - bool m_cmyk; - QString m_lastError; - int m_error; - int m_whitespace; - int m_vwhitespace; - zint_symbol * m_zintSymbol; float m_scale; - bool m_show_hrt; - int m_eci; - int m_rotate_angle; bool m_dotty; float m_dot_size; float m_guardDescent; struct zint_structapp m_structapp; - bool m_gs1parens; - bool m_gs1nocheck; + QColor m_fgColor; + QColor m_bgColor; + bool m_cmyk; + int m_borderType; + int m_borderWidth; + int m_whitespace; + int m_vwhitespace; + int m_fontSetting; + bool m_show_hrt; bool m_gssep; bool m_quiet_zones; bool m_no_quiet_zones; bool m_compliant_height; + int m_rotate_angle; + int m_eci; + bool m_gs1parens; + bool m_gs1nocheck; bool m_reader_init; + int m_warn_level; bool m_debug; int m_encodedWidth; int m_encodedRows; + QString m_lastError; + int m_error; int target_size_horiz; /* Legacy */ int target_size_vert; /* Legacy */ diff --git a/backend_qt/tests/test_qzint.cpp b/backend_qt/tests/test_qzint.cpp index fef0552e..34990fca 100644 --- a/backend_qt/tests/test_qzint.cpp +++ b/backend_qt/tests/test_qzint.cpp @@ -220,6 +220,10 @@ private slots: bc.setReaderInit(readerInit); QCOMPARE(bc.readerInit(), readerInit); + int warnLevel = WARN_FAIL_ALL; + bc.setWarnLevel(warnLevel); + QCOMPARE(bc.warnLevel(), warnLevel); + bool debug = true; bc.setDebug(debug); QCOMPARE(bc.debug(), debug); @@ -286,10 +290,19 @@ private slots: QTest::addColumn("symbology"); QTest::addColumn("cap_flag"); - QTest::newRow("BARCODE_CODE11") << BARCODE_CODE11 << (ZINT_CAP_HRT); - QTest::newRow("BARCODE_CODE128") << BARCODE_CODE128 << (ZINT_CAP_HRT | ZINT_CAP_READER_INIT); - QTest::newRow("BARCODE_EANX") << BARCODE_EANX << (ZINT_CAP_HRT | ZINT_CAP_EXTENDABLE | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT); - QTest::newRow("BARCODE_QRCODE") << BARCODE_QRCODE << (ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO); + QTest::newRow("BARCODE_CODE11") << BARCODE_CODE11 + << (ZINT_CAP_HRT | ZINT_CAP_STACKABLE); + QTest::newRow("BARCODE_CODE128") << BARCODE_CODE128 + << (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_READER_INIT); + QTest::newRow("BARCODE_EANX") << BARCODE_EANX + << (ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_QUIET_ZONES + | ZINT_CAP_COMPLIANT_HEIGHT); + QTest::newRow("BARCODE_EANX_CC") << BARCODE_EANX_CC + << (ZINT_CAP_HRT | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES + | ZINT_CAP_COMPLIANT_HEIGHT); + QTest::newRow("BARCODE_QRCODE") << BARCODE_QRCODE + << (ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE + | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP); } void capTest() @@ -301,13 +314,18 @@ private slots: bc.setSymbol(symbology); QCOMPARE(bc.hasHRT(), (cap_flag & ZINT_CAP_HRT) != 0); + QCOMPARE(bc.isStackable(), (cap_flag & ZINT_CAP_STACKABLE) != 0); QCOMPARE(bc.isExtendable(), (cap_flag & ZINT_CAP_EXTENDABLE) != 0); + QCOMPARE(bc.isComposite(), (cap_flag & ZINT_CAP_COMPOSITE) != 0); QCOMPARE(bc.supportsECI(), (cap_flag & ZINT_CAP_ECI) != 0); QCOMPARE(bc.supportsGS1(), (cap_flag & ZINT_CAP_GS1) != 0); + QCOMPARE(bc.isDotty(), (cap_flag & ZINT_CAP_DOTTY) != 0); QCOMPARE(bc.hasDefaultQuietZones(), (cap_flag & ZINT_CAP_QUIET_ZONES) != 0); QCOMPARE(bc.isFixedRatio(), (cap_flag & ZINT_CAP_FIXED_RATIO) != 0); - QCOMPARE(bc.isDotty(), (cap_flag & ZINT_CAP_DOTTY) != 0); QCOMPARE(bc.supportsReaderInit(), (cap_flag & ZINT_CAP_READER_INIT) != 0); + QCOMPARE(bc.supportsFullMultibyte(), (cap_flag & ZINT_CAP_FULL_MULTIBYTE) != 0); + QCOMPARE(bc.hasMask(), (cap_flag & ZINT_CAP_MASK) != 0); + QCOMPARE(bc.supportsStructApp(), (cap_flag & ZINT_CAP_STRUCTAPP) != 0); QCOMPARE(bc.hasCompliantHeight(), (cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) != 0); } @@ -409,6 +427,453 @@ private slots: QCOMPARE(ret, 0); } } + + void getAsCLITest_data() + { + QTest::addColumn("autoHeight"); + QTest::addColumn("heightPerRow"); + QTest::addColumn("outfile"); + + QTest::addColumn("symbology"); + QTest::addColumn("inputMode"); + QTest::addColumn("text"); + QTest::addColumn("primary"); + QTest::addColumn("height"); + QTest::addColumn("option1"); + QTest::addColumn("option2"); + QTest::addColumn("option3"); + QTest::addColumn("scale"); + QTest::addColumn("dotty"); + QTest::addColumn("dotSize"); + QTest::addColumn("guardDescent"); + QTest::addColumn("structAppCount"); + QTest::addColumn("structAppIndex"); + QTest::addColumn("structAppID"); + QTest::addColumn("fgColor"); + QTest::addColumn("bgColor"); + QTest::addColumn("cmyk"); + QTest::addColumn("borderTypeIndex"); + QTest::addColumn("borderWidth"); + QTest::addColumn("whitespace"); + QTest::addColumn("vWhitespace"); + QTest::addColumn("fontSetting"); + QTest::addColumn("showText"); + QTest::addColumn("gsSep"); + QTest::addColumn("quietZones"); + QTest::addColumn("noQuietZones"); + QTest::addColumn("compliantHeight"); + QTest::addColumn("rotateAngle"); + QTest::addColumn("eci"); + QTest::addColumn("gs1Parens"); + QTest::addColumn("gs1NoCheck"); + QTest::addColumn("readerInit"); + QTest::addColumn("warnLevel"); + QTest::addColumn("debug"); + + QTest::addColumn("expected_cmd"); + QTest::addColumn("expected_win"); + QTest::addColumn("expected_longOptOnly"); + QTest::addColumn("expected_barcodeNames"); + + QTest::newRow("BARCODE_AUSPOST") << true << 0.0f << "" + << BARCODE_AUSPOST << DATA_MODE // symbology-inputMode + << "12345678" << "" // text-primary + << 30.0f << -1 << 0 << 0 << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 63 --binary --compliantheight -d '12345678'" + << "zint.exe -b 63 --binary --compliantheight -d \"12345678\"" + << "zint --barcode=63 --binary --compliantheight --data='12345678'" + << "zint -b AUSPOST --binary --compliantheight -d '12345678'"; + + QTest::newRow("BARCODE_AZTEC") << false << 0.0f << "" + << BARCODE_AZTEC << UNICODE_MODE // symbology-inputMode + << "12345678Ж0%var%" << "" // text-primary + << 0.0f << 1 << 0 << 0 << 4.0f << true << 0.9f // height-dotSize + << 5.0f << 2 << 1 << "as\"dfa'sdf" << QColor(Qt::blue) << QColor(Qt::white) // guardDescent-bgColor + << true << 0 << 0 << 2 << 3 << 0 // cmyk-fontSetting + << true << false << false << false << false << 0 // showText-rotateAngle + << 7 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 92 --cmyk -d '12345678Ж0%var%' --dotsize=0.9 --dotty --eci=7 --fg=0000FF --scale=4" + " --secure=1 --structapp='1,2,as\"dfa'\\''sdf' --vwhitesp=3 -w 2" + << "zint.exe -b 92 --cmyk -d \"12345678Ж0%var%\" --dotsize=0.9 --dotty --eci=7 --fg=0000FF --scale=4" + " --secure=1 --structapp=\"1,2,as\\\"dfa'sdf\" --vwhitesp=3 -w 2" + << "" << ""; + + QTest::newRow("BARCODE_C25INTER") << true << 0.0f << "" + << BARCODE_C25INTER << UNICODE_MODE // symbology-inputMode + << "12345" << "" // text-primary + << 0.0f << -1 << 2 << 0 << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << SMALL_TEXT // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 3 --compliantheight -d '12345' --small --vers=2" + << "zint.exe -b 3 --compliantheight -d \"12345\" --small --vers=2" + << "" << ""; + + QTest::newRow("BARCODE_CHANNEL") << false << 0.0f << "" + << BARCODE_CHANNEL << UNICODE_MODE // symbology-inputMode + << "453678" << "" // text-primary + << 19.7f << -1 << 7 << 0 << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(255, 255, 255, 0) // guardDescent-bgColor + << false << 1 << 2 << 0 << 0 << BOLD_TEXT // cmyk-fontSetting + << true << false << true << false << false << 90 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << true // eci-debug + << "zint -b 140 --bind --bold --border=2 -d '453678' --height=19.7 --nobackground --quietzones" + " --rotate=90 --verbose --vers=7" + << "zint.exe -b 140 --bind --bold --border=2 -d \"453678\" --height=19.7 --nobackground --quietzones" + " --rotate=90 --verbose --vers=7" + << "" << ""; + + QTest::newRow("BARCODE_GS1_128_CC") << false << 0.0f << "" + << BARCODE_GS1_128_CC << UNICODE_MODE // symbology-inputMode + << "[01]12345678901231[15]121212" << "[11]901222[99]ABCDE" // text-primary + << 71.142f << 3 << 0 << 0 << 3.5f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << false << false << true << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 131 --compliantheight -d '[11]901222[99]ABCDE' --height=71.142 --mode=3 --notext" + " --primary='[01]12345678901231[15]121212' --quietzones --scale=3.5" + << "zint.exe -b 131 --compliantheight -d \"[11]901222[99]ABCDE\" --height=71.142 --mode=3 --notext" + " --primary=\"[01]12345678901231[15]121212\" --quietzones --scale=3.5" + << "" << ""; + + QTest::newRow("BARCODE_CODE16K") << false << 11.7f << "" + << BARCODE_CODE16K << (UNICODE_MODE | HEIGHTPERROW_MODE) // symbology-inputMode + << "12345678901234567890123456789012" << "" // text-primary + << 0.0f << 4 << 0 << 2 << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 1 << 1 << 0 << 0 << SMALL_TEXT // cmyk-fontSetting + << true << false << false << true << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 23 --bind --border=1 --compliantheight -d '12345678901234567890123456789012'" + " --height=11.7 --heightperrow --noquietzones --rows=4 --separator=2 --small" + << "zint.exe -b 23 --bind --border=1 --compliantheight -d \"12345678901234567890123456789012\"" + " --height=11.7 --heightperrow --noquietzones --rows=4 --separator=2 --small" + << "" << ""; + + QTest::newRow("BARCODE_CODABLOCKF") << true << 0.0f << "" + << BARCODE_CODABLOCKF << (DATA_MODE | ESCAPE_MODE) // symbology-inputMode + << "T\\n\\xA0t\\\"" << "" // text-primary + << 0.0f << 2 << 5 << 3 << 3.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 2 << 4 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << true << WARN_DEFAULT << false // eci-debug + << "zint -b 74 --binary --border=4 --box --cols=5 --compliantheight -d 'T\\n\\xA0t\\\"' --esc --init" + " --rows=2 --scale=3 --separator=3" + << "zint.exe -b 74 --binary --border=4 --box --cols=5 --compliantheight -d \"T\\n\\xA0t\\\\\"\" --esc --init" + " --rows=2 --scale=3 --separator=3" + << "" << ""; + + QTest::newRow("BARCODE_DAFT") << false << 0.0f << "" + << BARCODE_DAFT << UNICODE_MODE // symbology-inputMode + << "daft" << "" // text-primary + << 9.2f << -1 << 251 << 0 << 1.0f << false << 0.7f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(0x30, 0x31, 0x32, 0x33) << QColor(0xBF, 0xBE, 0xBD, 0xBC) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 93 --bg=BFBEBDBC -d 'daft' --fg=30313233 --height=9.2 --vers=251" + << "zint.exe -b 93 --bg=BFBEBDBC -d \"daft\" --fg=30313233 --height=9.2 --vers=251" + << "" << ""; + + QTest::newRow("BARCODE_DATAMATRIX") << true << 0.0f << "" + << BARCODE_DATAMATRIX << GS1_MODE // symbology-inputMode + << "[20]12" << "" // text-primary + << 0.0f << -1 << 0 << DM_SQUARE << 1.0f << false << 0.7f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << true << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 71 -d '[20]12' --gs1 --gssep --square" + << "zint.exe -b 71 -d \"[20]12\" --gs1 --gssep --square" + << "" << ""; + + QTest::newRow("BARCODE_DBAR_EXPSTK_CC") << false << 40.8f << "" + << BARCODE_DBAR_EXPSTK_CC << (DATA_MODE | HEIGHTPERROW_MODE) // symbology-inputMode + << "[91]ABCDEFGHIJKL" << "[11]901222[99]ABCDE" // text-primary + << 0.0f << -1 << 0 << 2 << 1.0f << true << 0.9f // height-dotSize + << 3.0f << 2 << 1 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 139 --binary --compliantheight -d '[11]901222[99]ABCDE' --height=40.8 --heightperrow" + " --primary='[91]ABCDEFGHIJKL' --rows=2" + << "zint.exe -b 139 --binary --compliantheight -d \"[11]901222[99]ABCDE\" --height=40.8 --heightperrow" + " --primary=\"[91]ABCDEFGHIJKL\" --rows=2" + << "" << ""; + + QTest::newRow("BARCODE_DOTCODE") << false << 1.0f << "" + << BARCODE_DOTCODE << GS1_MODE // symbology-inputMode + << "[20]01" << "" // text-primary + << 30.0f << -1 << 8 << ((0 + 1) << 8) << 1.0f << false << 0.7f // height-dotSize + << 0.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 115 --cols=8 -d '[20]01' --dotsize=0.7 --gs1 --mask=0" + << "zint.exe -b 115 --cols=8 -d \"[20]01\" --dotsize=0.7 --gs1 --mask=0" + << "" << ""; + + QTest::newRow("BARCODE_EANX") << true << 0.0f << "" + << BARCODE_EANX << UNICODE_MODE // symbology-inputMode + << "123456789012+12" << "" // text-primary + << 0.0f << -1 << 8 << 0 << 1.0f << true << 0.8f // height-dotSize + << 0.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 13 --addongap=8 --compliantheight -d '123456789012+12' --guarddescent=0" + << "zint.exe -b 13 --addongap=8 --compliantheight -d \"123456789012+12\" --guarddescent=0" + << "" << ""; + + QTest::newRow("BARCODE_GRIDMATRIX") << false << 0.0f << "" + << BARCODE_GRIDMATRIX << UNICODE_MODE // symbology-inputMode + << "Your Data Here!" << "" // text-primary + << 0.0f << 1 << 5 << 0 << 0.5f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << true << false << true << 270 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 142 -d 'Your Data Here!' --quietzones --rotate=270 --scale=0.5 --secure=1 --vers=5" + << "zint.exe -b 142 -d \"Your Data Here!\" --quietzones --rotate=270 --scale=0.5 --secure=1 --vers=5" + << "" << ""; + + QTest::newRow("BARCODE_HANXIN") << false << 0.0f << "" + << BARCODE_HANXIN << (UNICODE_MODE | ESCAPE_MODE) // symbology-inputMode + << "éβÿ啊\\e\"'" << "" // text-primary + << 30.0f << 2 << 5 << ((0 + 1) << 8) << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 29 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 116 -d 'éβÿ啊\\e\"'\\''' --eci=29 --esc --mask=0 --secure=2 --vers=5" + << "zint.exe -b 116 -d \"éβÿ啊\\e\\\"'\" --eci=29 --esc --mask=0 --secure=2 --vers=5" + << "" << ""; + + QTest::newRow("BARCODE_HIBC_DM") << false << 10.0f << "" + << BARCODE_HIBC_DM << UNICODE_MODE // symbology-inputMode + << "1234" << "" // text-primary + << 0.0f << -1 << 8 << DM_DMRE << 1.0f << false << 0.7f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << true << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 102 -d '1234' --dmre --vers=8" + << "zint.exe -b 102 -d \"1234\" --dmre --vers=8" + << "" << ""; + + QTest::newRow("BARCODE_HIBC_PDF") << false << 0.0f << "" + << BARCODE_HIBC_PDF << (DATA_MODE | HEIGHTPERROW_MODE) // symbology-inputMode + << "TEXT" << "" // text-primary + << 3.5f << 3 << 4 << 10 << 10.0f << false << 0.8f // height-dotSize + << 5.0f << 2 << 1 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << true << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 106 --binary --cols=4 -d 'TEXT' --height=3.5 --heightperrow --quietzones" + " --rows=10 --scale=10 --secure=3 --structapp=1,2" + << "zint.exe -b 106 --binary --cols=4 -d \"TEXT\" --height=3.5 --heightperrow --quietzones" + " --rows=10 --scale=10 --secure=3 --structapp=1,2" + << "" << ""; + + QTest::newRow("BARCODE_MAXICODE") << true << 0.0f << "" + << BARCODE_MAXICODE << (UNICODE_MODE | ESCAPE_MODE) // symbology-inputMode + << "152382802840001" + << "1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G1 MAIN ST\\GTOWN\\GNY\\R\\E" // text-primary + << 0.0f << -1 << (96 + 1) << 0 << 2.5f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << true << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 57 -d '1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G1 MAIN ST\\GTOWN\\GNY\\R\\E'" + " --esc --primary='152382802840001' --quietzones --scale=2.5 --scmvv=96" + << "zint.exe -b 57 -d \"1Z00004951\\GUPSN\\G06X610\\G159\\G1234567\\G1/1\\G\\GY\\G1 MAIN ST\\GTOWN\\GNY\\R\\E\"" + " --esc --primary=\"152382802840001\" --quietzones --scale=2.5 --scmvv=96" + << "" << ""; + + QTest::newRow("BARCODE_MICROQR") << false << 0.0f << "" + << BARCODE_MICROQR << UNICODE_MODE // symbology-inputMode + << "1234" << "" // text-primary + << 30.0f << 2 << 3 << (ZINT_FULL_MULTIBYTE | (3 + 1) << 8) << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 97 -d '1234' --fullmultibyte --mask=3 --secure=2 --vers=3" + << "zint.exe -b 97 -d \"1234\" --fullmultibyte --mask=3 --secure=2 --vers=3" + << "" << ""; + + QTest::newRow("BARCODE_QRCODE") << true << 0.0f << "" + << BARCODE_QRCODE << GS1_MODE // symbology-inputMode + << "(01)12" << "" // text-primary + << 0.0f << 1 << 5 << (ZINT_FULL_MULTIBYTE | (0 + 1) << 8) << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << true << false << true << 0 // showText-rotateAngle + << 0 << true << true << false << WARN_DEFAULT << false // eci-debug + << "zint -b 58 -d '(01)12' --fullmultibyte --gs1 --gs1parens --gs1nocheck --mask=0 --quietzones" + " --secure=1 --vers=5" + << "zint.exe -b 58 -d \"(01)12\" --fullmultibyte --gs1 --gs1parens --gs1nocheck --mask=0 --quietzones" + " --secure=1 --vers=5" + << "" << ""; + + QTest::newRow("BARCODE_RMQR") << true << 0.0f << "" + << BARCODE_RMQR << UNICODE_MODE // symbology-inputMode + << "テ" << "" // text-primary + << 30.0f << -1 << 8 << 0 << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 180 // showText-rotateAngle + << 20 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 145 -d 'テ' --eci=20 --rotate=180 --vers=8" + << "zint.exe -b 145 -d \"テ\" --eci=20 --rotate=180 --vers=8" + << "" << ""; + + QTest::newRow("BARCODE_UPCE_CC") << true << 0.0f << "out.svg" + << BARCODE_UPCE_CC << UNICODE_MODE // symbology-inputMode + << "12345670+1234" << "[11]901222[99]ABCDE" // text-primary + << 0.0f << -1 << 0 << 0 << 1.0f << false << 0.8f // height-dotSize + << 6.5f << 0 << 0 << "" << QColor(0xEF, 0x29, 0x29) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << (BOLD_TEXT | SMALL_TEXT) // cmyk-fontSetting + << true << false << false << true << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_FAIL_ALL << false // eci-debug + << "zint -b 136 --bold --compliantheight -d '[11]901222[99]ABCDE' --fg=EF2929 --guarddescent=6.5" + " --noquietzones -o 'out.svg' --primary='12345670+1234' --small --werror" + << "zint.exe -b 136 --bold --compliantheight -d \"[11]901222[99]ABCDE\" --fg=EF2929 --guarddescent=6.5" + " --noquietzones -o \"out.svg\" --primary=\"12345670+1234\" --small --werror" + << "zint --barcode=136 --bold --compliantheight --data='[11]901222[99]ABCDE' --fg=EF2929" + " --guarddescent=6.5 --noquietzones --output='out.svg' --primary='12345670+1234' --small --werror" + << "zint -b UPCE_CC --bold --compliantheight -d '[11]901222[99]ABCDE' --fg=EF2929 --guarddescent=6.5" + " --noquietzones -o 'out.svg' --primary='12345670+1234' --small --werror"; + + QTest::newRow("BARCODE_VIN") << false << 2.0f << "" + << BARCODE_VIN << UNICODE_MODE // symbology-inputMode + << "12345678701234567" << "" // text-primary + << 20.0f << -1 << 1 << 0 << 1.0f << false << 0.8f // height-dotSize + << 5.0f << 0 << 0 << "" << QColor(Qt::black) << QColor(Qt::white) // guardDescent-bgColor + << false << 0 << 0 << 0 << 0 << 0 // cmyk-fontSetting + << true << false << false << false << true << 0 // showText-rotateAngle + << 0 << false << false << false << WARN_DEFAULT << false // eci-debug + << "zint -b 73 -d '12345678701234567' --height=20 --vers=1" + << "zint.exe -b 73 -d \"12345678701234567\" --height=20 --vers=1" + << "" << ""; + } + + void getAsCLITest() + { + Zint::QZint bc; + + QString cmd; + + QFETCH(bool, autoHeight); + QFETCH(float, heightPerRow); + QFETCH(QString, outfile); + + QFETCH(int, symbology); + QFETCH(int, inputMode); + QFETCH(QString, text); + QFETCH(QString, primary); + QFETCH(float, height); + QFETCH(int, option1); + QFETCH(int, option2); + QFETCH(int, option3); + QFETCH(float, scale); + QFETCH(bool, dotty); + QFETCH(float, dotSize); + QFETCH(float, guardDescent); + QFETCH(int, structAppCount); + QFETCH(int, structAppIndex); + QFETCH(QString, structAppID); + QFETCH(QColor, fgColor); + QFETCH(QColor, bgColor); + QFETCH(bool, cmyk); + QFETCH(int, borderTypeIndex); + QFETCH(int, borderWidth); + QFETCH(int, whitespace); + QFETCH(int, vWhitespace); + QFETCH(int, fontSetting); + QFETCH(bool, showText); + QFETCH(bool, gsSep); + QFETCH(bool, quietZones); + QFETCH(bool, noQuietZones); + QFETCH(bool, compliantHeight); + QFETCH(int, rotateAngle); + QFETCH(int, eci); + QFETCH(bool, gs1Parens); + QFETCH(bool, gs1NoCheck); + QFETCH(bool, readerInit); + QFETCH(int, warnLevel); + QFETCH(bool, debug); + + QFETCH(QString, expected_cmd); + QFETCH(QString, expected_win); + QFETCH(QString, expected_longOptOnly); + QFETCH(QString, expected_barcodeNames); + + bc.setSymbol(symbology); + bc.setInputMode(inputMode); + if (primary.isEmpty()) { + bc.setText(text); + } else { + bc.setText(primary); + bc.setPrimaryMessage(text); + } + bc.setHeight(height); + bc.setOption1(option1); + bc.setOption2(option2); + bc.setOption3(option3); + bc.setScale(scale); + bc.setDotty(dotty); + bc.setDotSize(dotSize); + bc.setGuardDescent(guardDescent); + bc.setStructApp(structAppCount, structAppIndex, structAppID); + bc.setFgColor(fgColor); + bc.setBgColor(bgColor); + bc.setCMYK(cmyk); + bc.setBorderType(borderTypeIndex); + bc.setBorderWidth(borderWidth); + bc.setWhitespace(whitespace); + bc.setVWhitespace(vWhitespace); + bc.setFontSettingValue(fontSetting); + bc.setShowText(showText); + bc.setGSSep(gsSep); + bc.setQuietZones(quietZones); + bc.setNoQuietZones(noQuietZones); + bc.setCompliantHeight(compliantHeight); + bc.setRotateAngleValue(rotateAngle); + bc.setECIValue(eci); + bc.setGS1Parens(gs1Parens); + bc.setGS1NoCheck(gs1NoCheck); + bc.setReaderInit(readerInit); + bc.setWarnLevel(warnLevel); + bc.setDebug(debug); + + cmd = bc.getAsCLI(false /*win*/, false /*longOptOnly*/, false /*barcodeNames*/, + autoHeight, heightPerRow, outfile); + QCOMPARE(cmd, expected_cmd); + + cmd = bc.getAsCLI(true /*win*/, false /*longOptOnly*/, false /*barcodeNames*/, + autoHeight, heightPerRow, outfile); + QCOMPARE(cmd, expected_win); + + if (!expected_longOptOnly.isEmpty()) { + cmd = bc.getAsCLI(false /*win*/, true /*longOptOnly*/, false /*barcodeNames*/, + autoHeight, heightPerRow, outfile); + QCOMPARE(cmd, expected_longOptOnly); + } + + if (!expected_barcodeNames.isEmpty()) { + cmd = bc.getAsCLI(false /*win*/, false /*longOptOnly*/, true /*barcodeNames*/, + autoHeight, heightPerRow, outfile); + QCOMPARE(cmd, expected_barcodeNames); + } + } }; QTEST_MAIN(TestQZint) diff --git a/docs/manual.txt b/docs/manual.txt index bf286f19..3b7f9f4c 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -19,7 +19,7 @@ barcode image. The library which forms the main component of the Zint project is currently 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 +of which it is possible to translate that data from either UTF-8 (Unicode) 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), Tagged Image File Format (TIF), Enhanced Metafile @@ -112,7 +112,7 @@ sudo make install The CLI command line program can be accessed by typing -zint {options} +zint [options] The GUI can be accessed by typing @@ -145,20 +145,21 @@ To build Zint on Windows from source, see "win32/README". 2.3 Apple macOS --------------- -Zint can be installed using Homebrew. To install homebrew input the following -line into the MacOS terminal +Zint can be installed using Homebrew. To install Homebrew input the following +line into the macOS terminal /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -Once homebrew is installed use the following command to install Zint. +Once Homebrew is installed use the following command to install Zint. brew install zint -2.4 zint tcl backend +2.4 Zint Tcl Backend -------------------- -The tcl backend may be built using the provided TEA build on Linux, Windows, -Mac-OS and Android. For Windows, an MS-VC6 makefile is also available. +The Tcl backend in the backend_tcl sub-directory may be built using the +provided TEA (Tcl Extension Architecture) build on Linux, Windows, macOS and +Android. For Windows, an MSVC6 makefile is also available. 3. Using Zint Barcode Studio @@ -195,10 +196,25 @@ single quote, and then continuing: zint -d 'Text containing a single quote '\'' in the middle' -4.1 Inputting data +Some examples use backslash (\) to continue commands onto the next line. For +Windows, use caret (^) instead. + +Certain options that take values have short names as well as long ones, namely +-b (--barcode), -d (--data), -i (--input), -o (--output) and -w (--whitesp). For +these a space should be used to separate the short name from its value, to avoid +ambiguity. For long names a space or an equals sign may be used. For instance: + +zint -d "This Text" +zint --data="This Text" +zint --data "This Text" + +The examples use a space separator for short option names, and an equals sign +for long option names. + +4.1 Inputting Data ------------------ -The data to encode can be entered at the command line using the -d option, for -example +The data to encode can be entered at the command line using the -d or --data +option, for example zint -d "This Text" @@ -207,13 +223,13 @@ Code 128, and output to the default file out.png in the current directory. Alternatively, if libpng was not present when Zint was built, the default output file will be out.gif. -The data input to the Zint CLI is assumed to be encoded in Unicode (UTF-8) +The data input to the Zint CLI is assumed to be encoded in UTF-8 (Unicode) format (Zint will correctly handle UTF-8 data on Windows). If you are encoding characters beyond the 7-bit ASCII set using a scheme other than UTF-8 then you will need to set the appropriate input options as shown in section 4.10 below. -Non-printing characters can be entered on the command line using the backslash -(\) as an escape character in combination with the --esc switch. Permissible +Non-printing characters can be entered on the command line using backslash (\) +as an escape character in combination with the --esc switch. Permissible sequences are shown in the table below. ------------------------------------------------------------------------------ @@ -240,11 +256,11 @@ Escape Sequence | ASCII Equivalent | Name | Interpretation | | | hexadecimal ------------------------------------------------------------------------------ -Input data can be read directly from file using the -i switch as shown below. -The input file is assumed to be Unicode (UTF-8) formatted unless an alternative -mode is selected. This command replaces the use of the -d switch. +Input data can be read directly from file using the -i or --input switch as +shown below. The input file is assumed to be UTF-8 (Unicode) formatted unless an +alternative mode is selected. This command replaces the use of the -d switch. -zint -i ./somefile.txt +zint -i somefile.txt Note that except when batch processing (section 4.11 below), the file should not end with a newline (LF on Unix, CR+LF on Windows) unless you want the newline to @@ -252,18 +268,18 @@ be encoded in the symbol. 4.2 Directing Output -------------------- -Output can be directed to a file other than the default using the -o switch. -For example: +Output can be directed to a file other than the default using the -o or --output +switch. For example: zint -o here.png -d "This Text" -This draws a Code 128 barcode in the file here.png. If an encapsulated -PostScript file is needed simply append the file name with .eps, and so on for +This draws a Code 128 barcode in the file here.png. If an Encapsulated +PostScript file is needed simply append the filename with .eps, and so on for the other supported file types: zint -o there.eps -d "This Text" -4.3 Selecting barcode type +4.3 Selecting Barcode Type -------------------------- Selecting which type of barcode you wish to produce (i.e. which symbology to use) can be done at the command line using the -b or --barcode= switch followed @@ -385,7 +401,7 @@ Value | insensitive) | 145 | RMQR | Rectangular Micro QR Code (rMQR) -------------------------------------------------------------------------------- -4.4 Adjusting height +4.4 Adjusting Height -------------------- The height of a symbol (except those with a fixed width-to-height ratio) can be adjusted using the --height switch. For example: @@ -416,7 +432,7 @@ zint -b PDF417 -d "This Text" --height=4 --heightperrow will produce a barcode of height 32X, with each of the 8 rows 4X high. -4.5 Adjusting whitespace +4.5 Adjusting Whitespace ------------------------ The amount of horizontal whitespace to the left and right of the generated barcode can be altered using the -w or --whitesp switch. For example: @@ -429,13 +445,13 @@ both to the left and to the right of the barcode. The amount of vertical whitespace above and below the barcode can be altered using the --vwhitesp switch. For example for 3 times the X-dimension: -zint --vwhitesp 3 -d "This Text" +zint --vwhitesp=3 -d "This Text" Note that the whitespace at the bottom appears below the text, if any. Horizontal and vertical whitespace can of course be used together: -zint -b DATAMATRIX --whitesp 1 --vwhitesp 1 -d "This Text" +zint -b DATAMATRIX --whitesp=1 --vwhitesp=1 -d "This Text" A --quietzones option is also available which adds quiet zones compliant with the symbology's specification. This is in addition to any whitespace specified @@ -445,7 +461,7 @@ Note that Codablock-F, Code 16K, Code 49, ITF-14, EAN-13, EAN-8, EAN-5, EAN-2, ISBN, UPC-A and UPC-E have compliant quiet zones added by default. This can be disabled with the option --noquietzones. -4.6 Adding boundary bars and boxes +4.6 Adding Boundary Bars and Boxes ---------------------------------- Zint allows the symbol to be bound with 'boundary bars' (also known as 'bearer bars') using the option --bind. These bars help to prevent misreading of the @@ -466,18 +482,18 @@ Codablock-F, Code 16K and Code 49 always have boundary bars, and default to particular horizontal whitespace values. Special considerations apply to ITF-14 - see the specific section 6.1.2.6 for that symbology. -4.7 Using colour +4.7 Using Colour ---------------- The default colours of a symbol are a black symbol on a white background. Zint -allows you to change this. The -r switch allows the default colours to be -inverted so that a white symbol is shown on a black background. For example the -command +allows you to change this. The -r or --reverse switch allows the default colours +to be inverted so that a white symbol is shown on a black background (known as +reflectance reversal). For example the command zint -r -d "This" gives an inverted Code 128 symbol. This is not practical for most symbologies -but white-on-black is allowed by the Data Matrix and Aztec Code symbology -specifications. +but white-on-black is allowed by the Aztec Code, Data Matrix, Han Xin Code, Grid +Matrix and QR Code symbology specifications. For more specific needs the foreground (ink) and background (paper) colours can be specified using the --fg= and --bg= options followed by a number in RRGGBB @@ -514,7 +530,7 @@ followed by the angle of rotation as shown below. --rotate=180 --rotate=270 -4.9 Adjusting image size +4.9 Adjusting Image Size ------------------------ The scale of the image can be altered using the --scale= option followed by a multiple of the default X-dimension. The scale is multiplied by 2 before being @@ -534,7 +550,7 @@ The minimum scale for vector output is 0.1, giving a minimum X-dimension of 0.2. The maximum scale for both raster and vector is 100. -4.9.1 Scaling example +4.9.1 Scaling Example --------------------- The GS1 General Specifications Section 5.2.6.6 "Symbol dimensions at nominal size" gives an example of an EAN-13 barcode using the X-dimension of 0.33mm. @@ -542,7 +558,7 @@ To print that example as a PNG at 12 dots per mm (dpmm), the equivalent of 300 dots per inch (dpi = dpmm * 25.4), specify a scale of 2, since 0.33 * 12 = 3.96 pixels, or 4 pixels rounding to the nearest pixel: -zint -b EANX -d "501234567890" --height 69 --scale 2 +zint -b EANX -d "501234567890" --compliantheight --scale=2 This will result in output of 38.27mm x 26.08mm (WxH) at 300 dpi. The following table shows the scale to use (in 0.5 increments) depending on the dpmm desired, @@ -561,7 +577,7 @@ dpmm | dpi | scale 189 | 4800 | 31 ------------------- -4.9.2 MaxiCode raster scaling +4.9.2 MaxiCode Raster Scaling ----------------------------- For MaxiCode symbols, which use hexagons, the scale for raster output is multiplied by 10 before being applied. The minimum scale is 0.2, so the minimum @@ -588,35 +604,37 @@ Note that the 0.5 increment recommended for normal raster output does not apply. Scales below 0.5 are not recommended and may produce symbols that are not within the minimum/maximum size ranges. -4.10 Input modes +4.10 Input Modes ---------------- -By default all input data is assumed to be encoded in Unicode (UTF-8) format. -Many barcode symbologies encode data using Latin-1 (ISO/IEC 8859-1) character -encoding, so input is converted from UTF-8 to Latin-1 before being put in the -symbol. In addition QR Code, Micro QR Code, Rectangular Micro QR Code, Han Xin -Code and Grid Matrix can encode Japanese or Chinese characters which are also -converted from UTF-8. If Zint encounters characters which can not be encoded -using the default character encoding then it will take advantage of the ECI -(Extended Channel Interpretations) mechanism to encode the data if the symbology -supports it. Be aware that not all barcode readers support ECI mode, so this can -sometimes lead to unreadable barcodes. If you are using characters beyond those -supported by Latin-1 then you should check that the resulting barcode can be -understood by your target barcode reader. Zint will generate a warning message -when an ECI code that has not been explicitly requested has been inserted into a -symbol. +By default all CLI input data is assumed to be encoded in UTF-8 (Unicode) +format. Many barcode symbologies encode data using Latin-1 (ISO/IEC 8859-1) +character encoding, so input is converted from UTF-8 to Latin-1 before being put +in the symbol. In addition QR Code, Micro QR Code, Rectangular Micro QR Code, +Han Xin Code and Grid Matrix can encode Japanese (Kanji) or Chinese (Hanzi) +characters which are also converted from UTF-8. + +If Zint encounters characters which can not be encoded using the default +character encoding then it will take advantage of the ECI (Extended Channel +Interpretations) mechanism to encode the data if the symbology supports it. Be +aware that not all barcode readers support ECI mode, so this can sometimes lead +to unreadable barcodes. If you are using characters beyond those supported by +Latin-1 then you should check that the resulting barcode can be understood by +your target barcode reader. Zint will generate a warning message when an ECI +code that has not been explicitly requested has been inserted into a symbol. GS1 data can be encoded in a number of symbologies. Application Identifiers -should be enclosed in [square brackets] followed by the data to be encoded (see -6.1.11.3). To encode GS1 data use the --gs1 option. GS1 mode is assumed (and -doesn't need to be set) for GS1-128, EAN-14, DataBar and Composite symbologies -but is also available for Aztec Code, Code 16K, Code 49, Code One, Data Matrix, -DotCode, QR Code and Ultracode. +(AIs) should be enclosed in [square brackets] followed by the data to be encoded +(see 6.1.11.3). To encode GS1 data use the --gs1 option. GS1 mode is assumed +(and doesn't need to be set) for GS1-128, EAN-14, DataBar and Composite +symbologies but is also available for Aztec Code, Code 16K, Code 49, Code One, +Data Matrix, DotCode, QR Code and Ultracode. -HIBC data may also be encoded in the symbologies Code 39, Code 128, Codablock-F, -Data Matrix, QR Code, PDF417, MicroPDF417 and Aztec Code. Within this mode, the -leading '+' and the check character are automatically added, conforming to HIBC -Labeler Identification Code (HIBC LIC). For HIBC Provider Applications Standard -(HIBC PAS), preface the data with a slash "/". +Health Industry Barcode (HIBC) data may also be encoded in the symbologies Code +39, Code 128, Codablock-F, Data Matrix, QR Code, PDF417, MicroPDF417 and Aztec +Code. Within this mode, the leading '+' and the check character are +automatically added, conforming to HIBC Labeler Identification Code (HIBC LIC). +For HIBC Provider Applications Standard (HIBC PAS), preface the data with a +slash "/". The --binary option encodes the input data as given. Automatic code page translation to an ECI page is disabled, and no validation of the data's encoding @@ -648,7 +666,7 @@ Latin alphabet No. 1". The row marked with an asterisk (*) translates GB 2312 codepoints, except when using Han Xin Code, which translates GB 18030 codepoints, a superset of GB 2312. -Note: the "--eci 3" specification should only be used for special purposes. +Note: the "--eci=3" specification should only be used for special purposes. Using this parameter, the ECI information is explicitly added to the code symbol. Nevertheless, for ECI Code 3, this is not required, as this is the default encoding, which is also active without any ECI information. @@ -691,33 +709,33 @@ the ISO/IEC 8859-15 codepoint hex A4. It is encoded in UTF-8 as the hex sequence: E2 82 AC. Those 3 bytes are contained in the file "utf8euro.txt". This command will generate the corresponding code: -zint -b 71 --square --scale 10 --eci 17 -i utf8euro.txt +zint -b 71 --square --scale=10 --eci=17 -i utf8euro.txt This is equivalent to the commands (using the --esc switch): -zint -b 71 --square --scale 10 --eci 17 --esc -d "\xE2\x82\xAC" +zint -b 71 --square --scale=10 --eci=17 --esc -d "\xE2\x82\xAC" -zint -b 71 --square --scale 10 --eci 17 --esc -d "\u20AC" +zint -b 71 --square --scale=10 --eci=17 --esc -d "\u20AC" and to the command: -zint -b 71 --square --scale 10 --eci 17 -d "€" +zint -b 71 --square --scale=10 --eci=17 -d "€" Ex2: The Chinese character with Unicode codepoint U+5E38 can be encoded in Big5 encoding. The Big5 representation of this character is the two hex bytes: B1 60 (contained in the file big5char.txt). The generation command for Data Matrix is: -zint -b 71 --square --scale 10 --eci 28 --binary -i big5char.txt +zint -b 71 --square --scale=10 --eci=28 --binary -i big5char.txt This is equivalent to the command (using the --esc switch): -zint -b 71 --square --scale 10 --eci 28 --binary --esc -d "\xB1\x60" +zint -b 71 --square --scale=10 --eci=28 --binary --esc -d "\xB1\x60" and to the commands (no --binary switch so conversion occurs): -zint -b 71 --square --scale 10 --eci 28 --esc -d "\u5E38" +zint -b 71 --square --scale=10 --eci=28 --esc -d "\u5E38" -zint -b 71 --square --scale 10 --eci 28 -d "常" +zint -b 71 --square --scale=10 --eci=28 -d "常" Ex3: Some decoders (in particular mobile app ones) for QR Code assume UTF-8 encoding by default and do not support ECI. In this case supply UTF-8 data and @@ -726,7 +744,7 @@ conversion: zint -b 58 --binary -d "UTF-8 data" -4.11 Batch processing +4.11 Batch Processing --------------------- Data can be batch processed by reading from a text file and producing a separate barcode image for each line of text in that file. To do this use the @@ -762,7 +780,7 @@ Input | Filenames Generated -o t@es~t~.png | t*es0t1.png, t*es0t2.png, t*es0t3.png -------------------------------------------------------------- -4.12 Direct output +4.12 Direct Output ------------------ The finished image files can be output directly to stdout for use as part of a pipe by using the --direct option. By default --direct will output data as a PNG @@ -794,29 +812,28 @@ CAUTION: Outputting binary files to the command shell without catching that data in a pipe can have unpredictable results. Use with care! ============================================================================= -4.13 Automatic filenames +4.13 Automatic Filenames ------------------------ The --mirror option instructs Zint to use the data to be encoded as an indicator of the filename to be used. This is particularly useful if you are processing batch data. For example the input data "1234567" will result in a file named 1234567.png. -There are restrictions, however, on what characters can be stored in a file -name, so the file name may vary from the data if the data includes non- -printable characters, for example, and may be shortened if the data input is -long. +There are restrictions, however, on what characters can be stored in a filename, +so the filename may vary from the data if the data includes non-printable +characters, for example, and may be shortened if the data input is long. To set the output file format use the --filetype= option as detailed in section 4.12. -4.14 Working with dots +4.14 Working with Dots ---------------------- Matrix codes can be rendered as a series of dots or circles rather than the normal squares by using the --dotty option. This option is only available for matrix symbologies, and is automatically selected for DotCode. The size of -the dots can be adjusted using the --dotsize= option followed by the radius -of the dot, where that radius is given as a multiple of the X-dimension. The -minimum dot size is 0.01, the maximum is 20. +the dots can be adjusted using the --dotsize= option followed by the diameter +of the dot, where that diameter is given as a multiple of the X-dimension. The +minimum dot size is 0.01, the maximum is 20. The default size is 0.8. The default and minimum scale for raster output in dotty mode is 1. @@ -839,7 +856,7 @@ for all symbols belonging to the same sequence. The index is 1-based and goes from 1 to count. Count must be 2 or more. See the individual symbologies for further details. -4.16 Help options +4.16 Help Options ----------------- There are three help options which give information about how to use the command line. The -h or --help option will display a list of all of the valid @@ -850,7 +867,7 @@ ID numbers and names. The -e or --ecinos option gives a list of the ECI codes. -4.17 Other output options +4.17 Other Output Options ------------------------- For linear barcodes the text present in the output image can be removed by using the --notext option. @@ -863,7 +880,7 @@ Zint can output a representation of the symbol data as a set of hexadecimal values if asked to output to a text file (*.txt) or if given the option --filetype=txt. This can be used for test and diagnostic purposes. -The --cmyk option is specific to output in encapsulated PostScript and TIF, and +The --cmyk option is specific to output in Encapsulated PostScript and TIF, and converts the RGB colours used to the CMYK colour space. Setting custom colours at the command line will still need to be done in RRGGBB format. @@ -966,7 +983,8 @@ int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, In these definitions "length" can be used to set the length of the input string. This allows the encoding of NUL (ASCII 0) characters in those symbologies which allow this. A value of 0 will disable this usage and Zint -will encode data up to the first NUL character in the input string. +will encode data up to the first NUL character in the input string, which must +be present. The "rotate_angle" value can be used to rotate the image when outputting. Valid values are 0, 90, 180 and 270. @@ -1221,10 +1239,10 @@ strcpy(my_symbol->bgcolour, "55555500"); 5.6 Handling Errors ------------------- -If errors occur during encoding an integer value is passed back to the calling -application. In addition the errtxt value is used to give a message detailing -the nature of the error. The errors generated by Zint are given in the table -below: +If errors occur during encoding a non-zero integer value is passed back to the +calling application. In addition the errtxt value is used to give a message +detailing the nature of the error. The errors generated by Zint are given in the +table below: -------------------------------------------------------------------------------- Return Value | Meaning @@ -1433,7 +1451,7 @@ names in Zint before version 2.9.0. For example, symbology 29 used the name "BARCODE_RSS14". These names are now deprecated but are still recognised by Zint and will continue to be supported in future versions. -5.9 Adjusting other output options +5.9 Adjusting Other Output Options ---------------------------------- The output_options variable can be used to adjust various aspects of the output file. To select more than one option from the table below simply OR them @@ -1453,7 +1471,7 @@ READER_INIT | Add a reader initialisation symbol to the data before | encoding. SMALL_TEXT | Use a smaller font for the Human Readable Text. BOLD_TEXT | Embolden the Human Readable Text. -CMYK_COLOUR | Select the CMYK colour space option for encapsulated +CMYK_COLOUR | Select the CMYK colour space option for Encapsulated | PostScript and TIF files. BARCODE_DOTTY_MODE | Plot a matrix symbol using dots rather than squares. GS1_GS_SEPARATOR | Use GS instead of FNC1 as GS1 separator (Data Matrix) @@ -1462,6 +1480,8 @@ OUT_BUFFER_INTERMEDIATE | Return the bitmap buffer as ASCII values instead of BARCODE_QUIET_ZONES | Add compliant quiet zones (additional to any | specified whitespace). [3] BARCODE_NO_QUIET_ZONES | Disable quiet zones, notably those with defaults. [3] +COMPLIANT_HEIGHT | Warn if height not compliant and use standard height + | (if any) as default. -------------------------------------------------------------------------------- [2] This flag is always set for Codablock-F, Code 16K and Code 49. Special @@ -1497,7 +1517,8 @@ HEIGHTPERROW_MODE | Interpret the height variable as per-row rather than as The default mode is DATA_MODE. DATA_MODE, UNICODE_MODE and GS1_MODE are mutually exclusive, whereas ESCAPE_MODE, -GS1PARENS_MODE and GS1NOCHECK_MODE are optional. So, for example, you can set +GS1PARENS_MODE, GS1NOCHECK_MODE and HEIGHTPERROW_MODE are optional. So, for +example, you can set my_symbol->input_mode = UNICODE_MODE | ESCAPE_MODE; @@ -1539,6 +1560,21 @@ if (ZBarcode_ValidID(BARCODE_PDF417) != 0) { printf("PDF417 not available\n"); } +Another function that may be useful is: + +int ZBarcode_BarcodeName(int symbol_id, char name[32]); + +which copies the name of a symbology into the supplied "name" buffer, which +should be 32 characters in length. The name is NUL-terminated, and zero is +returned on success. For instance: + +char name[32]; +if (ZBarcode_BarcodeName(BARCODE_PDF417, name) == 0) { + printf("%s\n", name); +} + +will print "BARCODE_PDF417". + 5.12 Checking Symbology Capabilities ------------------------------------ It can be useful for frontend programs to know the capabilities of a symbology. @@ -1549,27 +1585,28 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag); by OR-ing the flags below in the "cap_flag" argument and checking the return to see which are set. -------------------------------------------------------------------------------- -Value | Meaning -------------------------------------------------------------------------------- -ZINT_CAP_HRT | Can the symbology print Human Readable Text? -ZINT_CAP_STACKABLE | Is the symbology stackable? -ZINT_CAP_EXTENDABLE | Is the symbology extendable with add-on data? - | (i.e. is it UPC/EAN?) -ZINT_CAP_COMPOSITE | Does the symbology support composite data? - | (see 6.3 below) -ZINT_CAP_ECI | Does the symbology support Extended Channel - | Interpretations? -ZINT_CAP_GS1 | Does the symbology support GS1 data? -ZINT_CAP_DOTTY | Can the symbology be outputted as dots? -ZINT_CAP_QUIET_ZONES | Does the symbology have default quiet zones? -ZINT_CAP_FIXED_RATIO | Does the symbology have a fixed width-to-height - | (aspect) ratio? -ZINT_CAP_READER_INIT | Does the symbology support Reader Initialisation? -ZINT_CAP_FULL_MULTIBYTE | Is the ZINT_FULL_MULTIBYTE option applicable? -ZINT_CAP_MASK | Is mask selection applicable? -ZINT_CAP_STRUCTAPP | Does the symbology support Structured Append? -------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +Value | Meaning +--------------------------------------------------------------------------------- +ZINT_CAP_HRT | Can the symbology print Human Readable Text? +ZINT_CAP_STACKABLE | Is the symbology stackable? +ZINT_CAP_EXTENDABLE | Is the symbology extendable with add-on data? + | (i.e. is it UPC/EAN?) +ZINT_CAP_COMPOSITE | Does the symbology support composite data? + | (see 6.3 below) +ZINT_CAP_ECI | Does the symbology support Extended Channel + | Interpretations? +ZINT_CAP_GS1 | Does the symbology support GS1 data? +ZINT_CAP_DOTTY | Can the symbology be outputted as dots? +ZINT_CAP_QUIET_ZONES | Does the symbology have default quiet zones? +ZINT_CAP_FIXED_RATIO | Does the symbology have a fixed width-to-height + | (aspect) ratio? +ZINT_CAP_READER_INIT | Does the symbology support Reader Initialisation? +ZINT_CAP_FULL_MULTIBYTE | Is the ZINT_FULL_MULTIBYTE option applicable? +ZINT_CAP_MASK | Is mask selection applicable? +ZINT_CAP_STRUCTAPP | Does the symbology support Structured Append? +ZINT_CAP_COMPLIANT_HEIGHT | Does the symbology have a compliant height defined? +-------------------------------------------------------------------------------- For example: @@ -1605,10 +1642,11 @@ They consist of a number of bars and a number of spaces of differing widths. 6.1.1 Code 11 ------------- Developed by Intermec in 1977, Code 11 is similar to Code 2 of 5 Matrix and is -primarily used in telecommunications. The symbol can encode any length string -consisting of the digits 0-9 and the dash character (-). Two modulo-11 check -digits are added by default. To add just one check digit, set option_2 = 1 or ---vers=1. To add no check digits, set option_2 = 2 or --vers=2. +primarily used in telecommunications. The symbol can encode data consisting of +the digits 0-9 and the dash character (\-) up to a maximum of 121 characters. +Two modulo-11 check digits are added by default. To add just one check digit, +set option_2 = 1 or --vers=1. To add no check digits, set option_2 = 2 or +--vers=2. 6.1.2 Code 2 of 5 ----------------- @@ -1620,40 +1658,41 @@ before using these standards. 6.1.2.1 Standard Code 2 of 5 ---------------------------- Also known as Code 2 of 5 Matrix this is a self-checking code used in industrial -applications and photo development. Standard Code 2 of 5 will encode any length -numeric input (digits 0-9). No check digit is added by default. To add a check -digit, set option_2 = 1 or --vers=1. To add a check digit but not show it in -the Human Readable Text, set option_2 = 2 or --vers=2. +applications and photo development. Standard Code 2 of 5 will encode numeric +input (digits 0-9) up to a maximum of 80 digits. No check digit is added by +default. To add a check digit, set option_2 = 1 or --vers=1. To add a check +digit but not show it in the Human Readable Text, set option_2 = 2 or --vers=2. 6.1.2.2 IATA Code 2 of 5 ------------------------ Used for baggage handling in the air-transport industry by the International -Air Transport Agency, this self-checking code will encode any length numeric -input (digits 0-9). No check digit is added by default. To add a check digit, -set option_2 = 1 or --vers=1. To add a check digit but not show it in the Human -Readable Text, set option_2 = 2 or --vers=2. +Air Transport Agency, this self-checking code will encode numeric input (digits +0-9) up to a maximum of 45 digits. No check digit is added by default. To add a +check digit, set option_2 = 1 or --vers=1. To add a check digit but not show it +in the Human Readable Text, set option_2 = 2 or --vers=2. 6.1.2.3 Industrial Code 2 of 5 ------------------------------ -Industrial Code 2 of 5 can encode any length numeric input (digits 0-9). No -check digit is added by default. To add a check digit, set option_2 = 1 or ---vers=1. To add a check digit but not show it in the Human Readable Text, set -option_2 = 2 or --vers=2. +Industrial Code 2 of 5 can encode numeric input (digits 0-9) up to a maximum of +45 digits. No check digit is added by default. To add a check digit, set +option_2 = 1 or --vers=1. To add a check digit but not show it in the Human +Readable Text, set option_2 = 2 or --vers=2. 6.1.2.4 Interleaved Code 2 of 5 (ISO 16390) ------------------------------------------- This self-checking symbology encodes pairs of numbers, and so can only encode an even number of digits (0-9). If an odd number of digits is entered a leading -zero is added by Zint. No check digit is added by default. To add a check digit, -set option_2 = 1 or --vers=1. To add a check digit but not show it in the Human -Readable Text, set option_2 = 2 or --vers=2. +zero is added by Zint. A maximum of 45 pairs (90 digits) can be encoded. No +check digit is added by default. To add a check digit, set option_2 = 1 or +--vers=1. To add a check digit but not show it in the Human Readable Text, set +option_2 = 2 or --vers=2. 6.1.2.5 Code 2 of 5 Data Logic ------------------------------ -Data Logic does not include a check digit by default and can encode any length -numeric input (digits 0-9). To add a check digit, set option_2 = 1 or --vers=1. -To add a check digit but not show it in the Human Readable Text, set option_2 = -2 or --vers=2. +Data Logic does not include a check digit by default and can encode numeric +input (digits 0-9) up to a maximum of 80 digits. To add a check digit, set +option_2 = 1 or --vers=1. To add a check digit but not show it in the Human +Readable Text, set option_2 = 2 or --vers=2. 6.1.2.6 ITF-14 -------------- @@ -1665,8 +1704,8 @@ If no border option is specified Zint defaults to adding a bounding box with a border width of 5. This behaviour can be overridden by using the --bind option (or adding BARCODE_BIND to symbol->output_options). Similarly the border width can be overridden using --border= (or by setting symbol->border_width). If a -symbol with no border is explicitly required this can be achieved by setting -the border type to box or bind and setting the border width to 0. +symbol with no border is required this can be achieved by explicitly setting +the border type to bind (or box) and setting the border width to 0. 6.1.2.7 Deutsche Post Leitcode ------------------------------ @@ -1743,7 +1782,7 @@ The EAN system is used in retail across Europe and includes standards for EAN-2 and EAN-5 add-on codes, EAN-8 and EAN-13 which encode 2, 5, 7 or 12 digit numbers respectively. Zint will decide which symbology to use depending on the length of the input data. In addition EAN-2 and EAN-5 add-on symbols can be -added using the + symbol as with UPC symbols. For example: +added using the + character as with UPC symbols. For example: zint --barcode=EANX -d 54321 @@ -1778,7 +1817,7 @@ EAN-13 symbols (also known as Bookland EAN-13) can also be produced from 9-digit SBN, 10-digit ISBN or 13-digit ISBN-13 data. The relevant check digit needs to be present in the input data and will be verified before the symbol is generated. In addition EAN-2 and EAN-5 add-on symbols can be added using the + -symbol as with UPC symbols, and the gap set with --addongap= (option_2) to +character as with UPC symbols, and the gap set with --addongap= (option_2) to between 7 (default) and 12. The height that the guard bars descend can be adjusted by setting --guarddescent= (variable guard_descent in the symbol structure) to a value between 0 and 20 (default 5). @@ -1791,10 +1830,10 @@ Ltd. in the UK. The symbol can encode any length data consisting of digits 6.1.6 MSI Plessey ----------------- -Based on Plessey and developed by MSE Data Corporation, MSI Plessey is -available with a range of check digit options available by setting option_2 or -by using the --vers= switch. Any length numeric (digits 0-9) input can be -encoded. The table below shows the options available: +Based on Plessey and developed by MSE Data Corporation, MSI Plessey has a range +of check digit options that are selectable by setting option_2 or by using the +--vers= switch. Numeric (digits 0-9) input can be encoded, up to a maximum of 65 +digits. The table below shows the options available: ------------------------------------------- Value of option_2 | Check Digits @@ -1815,26 +1854,28 @@ option_2 value. ------------- 6.1.7.1 Telepen Alpha --------------------- -Telepen Alpha was developed by SB Electronic Systems Limited and can encode any -length of ASCII text input. Telepen includes a modulo-127 check digit. +Telepen Alpha was developed by SB Electronic Systems Limited and can encode +ASCII text input, up to a maximum of 30 characters. Telepen includes a +modulo-127 check digit. 6.1.7.2 Telepen Numeric ----------------------- Telepen Numeric allows compression of numeric data into a Telepen symbol. Data can consist of pairs of numbers or pairs consisting of a numerical digit followed an X character. For example: 466333 and 466X33 are valid codes whereas -46X333 is not (the digit pair "X3" is not valid). Telepen Numeric includes a -modulo-127 check digit which is added by Zint. +46X333 is not (the digit pair "X3" is not valid). Up to 60 digits can be +encoded. Telepen Numeric includes a modulo-127 check digit which is added by +Zint. 6.1.8 Code 39 ------------- 6.1.8.1 Standard Code 39 (ISO 16388) ------------------------------------ -Standard Code 39 was developed in 1974 by Intermec. Input data can be of any -length and can include the characters 0-9, A-Z, dash (-), full stop (.), space, -asterisk (*), dollar ($), slash (/), plus (+) and percent (%). The standard -does not require a check digit but a modulo-43 check digit can be added if -required by setting option_2 = 1 or using --vers=1. +Standard Code 39 was developed in 1974 by Intermec. Input data can be up to 85 +characters in length and can include the characters 0-9, A-Z, dash (-), full +stop (.), space, asterisk (*), dollar ($), slash (/), plus (+) and percent (%). +The standard does not require a check digit but a modulo-43 check digit can be +added if required by setting option_2 = 1 or using --vers=1. 6.1.8.2 Extended Code 39 ------------------------ @@ -1888,7 +1929,7 @@ An Import character prefix 'I' can be added by setting option_2 = 1 or using Also known as NW-7, Monarch, ABC Codabar, USD-4, Ames Code and Code 27, this symbology was developed in 1972 by Monarch Marketing Systems for retail purposes. The American Blood Commission adopted Codabar in 1977 as the standard -symbology for blood identification. Codabar can encode any length string +symbology for blood identification. Codabar can encode up to 60 characters starting and ending with the letters A-D and containing between these letters the numbers 0-9, dash (-), dollar ($), colon (:), slash (/), full stop (.) or plus (+). No check characater is generated by default, but a modulo-16 one can @@ -1915,9 +1956,9 @@ Latin-1 character set is shown in Appendix A. 6.1.11.2 Code 128 Subset B -------------------------- -It is sometimes advantageous to stop Code 128 from using subset mode C which -compresses numerical data. The BARCODE_CODE128B option (symbology 60) suppresses -mode C in favour of mode B. +It is sometimes advantageous to stop Code 128 from beginning in subset mode C +which compresses numerical data. The BARCODE_CODE128B option (symbology 60) +suppresses beginning in mode C in favour of mode B. 6.1.11.3 GS1-128 ---------------- @@ -1989,8 +2030,8 @@ of 33 or greater. Previously known as RSS Limited this standard encodes a 13 digit item code and can be used in the same way as DataBar above. DataBar Limited, however, is limited to data starting with digits 0 and 1 (i.e. numbers in the range 0 to -1999999999999). As with DataBar Omnidirectional a check digit and application -identifier of (01) are added by Zint, and a 14 digit code may be given in which +1999999999999). As with DataBar Omnidirectional a check digit and Application +Identifier of (01) are added by Zint, and a 14 digit code may be given in which case the check digit will be verified. 6.1.12.3 DataBar Expanded @@ -2058,6 +2099,9 @@ error = ZBarcode_Encode(my_symbol, "That", 0); error = ZBarcode_Print(my_symbol); +Note that the Human Readable Text will be that of the last data, so it's best to +use the option --notext (API show_hrt = 0). + The stacked barcode rows can be separated by row separator bars by specifying --bind (output_options |= BARCODE_BIND). The height of the row separator bars in multiples of the X-dimension (minimum and default 1, maximum 4) can be set by @@ -2116,28 +2160,30 @@ If an ID is not given, no ID is encoded. 6.2.5 Compact PDF417 -------------------- -Previously known as Truncated PDF417. Options are the same as for PDF417 above. +Previously known as Truncated PDF417, Compact PDF417 omits some per-row +overhead to produce a narrower but less robust symbol. Options are the same as +for PDF417 above. 6.2.6 MicroPDF417 (ISO 24728) ----------------------------- A variation of the PDF417 standard, MicroPDF417 is intended for applications where symbol size needs to be kept to a minimum. 34 predefined symbol sizes are -available with 1 - 4 columns and 4 - 44 rows. The maximum size MicroPDF417 -symbol can hold 250 alphanumeric characters or 366 digits. The amount of error -correction used is dependent on symbol size. The number of columns used can be -determined using the --cols switch or option_2 as with PDF417. This symbology -uses Latin-1 character encoding by default but also supports the ECI encoding -mechanism. A separate symbology ID can be used to encode Health Industry -Barcode (HIBC) data which adds a leading '+' character and a modulo-49 check -digit to the encoded data. MicroPDF417 supports Structured Append the same as -PDF417, for which see details. +available with 1 - 4 columns and 4 - 44 rows. The maximum size a MicroPDF417 +symbol can hold is 250 alphanumeric characters or 366 digits. The amount of +error correction used is dependent on symbol size. The number of columns used +can be determined using the --cols switch or option_2 as with PDF417. This +symbology uses Latin-1 character encoding by default but also supports the ECI +encoding mechanism. A separate symbology ID can be used to encode Health +Industry Barcode (HIBC) data which adds a leading '+' character and a modulo-49 +check digit to the encoded data. MicroPDF417 supports Structured Append the same +as PDF417, for which see details. 6.2.7 GS1 DataBar Stacked (ISO 24724) ------------------------------------- A stacked variation of the GS1 DataBar Truncated symbol requiring the same input -(see section 6.1.12.1). The height of this symbol is fixed. The data is encoded -in two rows of bars with a central finder pattern. This symbol can be generated -with a two-dimensional component to make a composite symbol. +(see section 6.1.12.1). The data is encoded in two rows of bars with a central +finder pattern. This symbol can be generated with a two-dimensional component to +make a composite symbol. 6.2.8 GS1 DataBar Stacked Omnidirectional (ISO 24724) ----------------------------------------------------- @@ -2233,8 +2279,8 @@ option_1 variable as shown above. 6.3.1 CC-A ---------- -This system uses a variation of MicroPDF417 which optimised to fit into a small -space. The size of the 2D component and the amount of error correction is +This system uses a variation of MicroPDF417 which is optimised to fit into a +small space. The size of the 2D component and the amount of error correction is determined by the amount of data to be encoded and the type of linear component which is being used. CC-A can encode up to 56 numeric digits or an alphanumeric string of shorter length. To select CC-A use --mode=1. @@ -2291,8 +2337,8 @@ by Australia Post for printing Delivery Point ID (DPID) and customer information on mail items. Valid data characters are 0-9, A-Z, a-z, space and hash (#). A Format Control Code (FCC) is added by Zint and should not be included in the input data. Reed-Solomon error correction data is generated by -Zint. Encoding behaviour is determined by the length of the input data -according to the formula shown in the following table: +Zint. Encoding behaviour is determined by the length of the input data according +to the formula shown in the following table: ----------------------------------------------------------------- Input | Required Input Format | Symbol | FCC | Encoding @@ -2449,9 +2495,8 @@ Input | Symbol Size DMRE symbol sizes may be activated in automatic size mode using the option --dmre or by the API option_3 = DM_DMRE -GS1 data may be encoded using FNC1 (preferred) or GS as separator. -Use the option --gssep to change to GS or use the API output_options |= -GS1_GS_SEPARATOR +GS1 data may be encoded using FNC1 (preferred) or GS as separator. Use the +option --gssep to change to GS or use the API output_options |= GS1_GS_SEPARATOR Data Matrix supports Structured Append of up to 16 symbols and a numeric ID (file identifications), which can be set by using the --structapp option (see @@ -2530,7 +2575,7 @@ The maximum capacity of a (version 40) QR Code symbol is 7089 numeric digits, used to encode GS1 data. QR Code symbols can by default encode characters in the Latin-1 set and Kanji characters which are members of the Shift JIS encoding scheme. In addition QR Code supports using other character sets using -the ECI mechanism. Input should usually be entered as Unicode (UTF-8) with +the ECI mechanism. Input should usually be entered as UTF-8 (Unicode) with conversion to Shift JIS being carried out by Zint. A separate symbology ID can be used to encode Health Industry Barcode (HIBC) data which adds a leading '+' character and a modulo-49 check digit to the encoded data. @@ -2586,12 +2631,11 @@ ZINT_FULL_MULTIBYTE | (N + 1) << 8. A rectangular version of QR Code, it is still under development, so it is recommended it should not yet be used for a production environment. Like QR Code, rMQR supports encoding of GS1 data, and Latin-1 characters in the ISO/IEC -8859-1 set and Kanji characters in the Shift JIS encoding scheme. It does not -support other ISO/IEC 8859 character sets or encodings. As with other -symbologies data should be entered as UTF-8 with the conversion to Latin-1 or -Shift JIS being handled by Zint. The amount of ECC codewords can be adjusted -using the --secure= option (API option_1), however only ECC levels M and H are -valid for this type of symbol. +8859-1 set and Kanji characters in the Shift JIS encoding scheme, and other +encodings using the ECI mechanism. As with other symbologies data should be +entered as UTF-8 with conversion being handled by Zint. The amount of ECC +codewords can be adjusted using the --secure= option (API option_1), however +only ECC levels M and H are valid for this type of symbol. ------------------------------------------------------------------------- Input | ECC Level | Error Correction Capacity | Recovery Capacity @@ -2663,7 +2707,7 @@ API set symbol->input_mode = DATA MODE; The following example creates a symbol from data saved as an ISO/IEC 8859-2 file: -zint -o upnqr.png -b 143 --border=5 --scale=3 --binary -i ./upn.txt +zint -o upnqr.png -b 143 --border=5 --scale=3 --binary -i upn.txt 6.6.6 MaxiCode (ISO 16023) -------------------------- @@ -2741,7 +2785,8 @@ using the --structapp option (see section 4.15) or the API structapp variable. It does not support specifying an ID. MaxiCode uses a different scaling than other symbols for raster output, see -4.9.2. +4.9.2, and also for EMF vector output, when the scale is multiplied by 20 +instead of 2. 6.6.7 Aztec Code (ISO 24778) ---------------------------- @@ -2833,8 +2878,8 @@ cannot contain spaces. If an ID is not given, no ID is encoded. 6.6.8 Aztec Runes ----------------- A truncated version of compact Aztec Code for encoding whole integers between 0 -and 255. Includes Reed-Solomon error correction. As defined in ISO/IEC 24778 -Annex A. It does not support Structured Append. +and 255, as defined in ISO/IEC 24778 Annex A. Includes Reed-Solomon error +correction. It does not support Structured Append. 6.6.9 Code One -------------- @@ -2870,13 +2915,15 @@ It does not support specifying an ID. Structured Append is not supported with GS1 data nor for Version S symbols. 6.6.10 Grid Matrix ------------------ +------------------ By default Grid Matrix supports encoding in Latin-1 and Chinese characters within the GB 2312 standard set to be encoded in a chequerboard pattern. Input -should be entered as Unicode (UTF-8) with conversion to GB 2312 being carried -out automatically by Zint. The symbology also supports the ECI mechanism. The -size of the symbol and the error correction capacity can be specified. If you -specify both of these values then Zint will make a 'best-fit' attempt to +should be entered as UTF-8 (Unicode) with conversion to GB 2312 being carried +out automatically by Zint. The symbology also supports the ECI mechanism. +Support for GS1 data has not yet been implemented. + +The size of the symbol and the error correction capacity can be specified. If +you specify both of these values then Zint will make a 'best-fit' attempt to satisfy both conditions. The symbol size can be specified using the --vers= option or by setting option_2, and the error correction capacity can be specified by using the --secure= option or by setting option_1 according to @@ -2919,7 +2966,7 @@ Grid Matrix supports Structured Append of up to 16 symbols and a numeric ID 4.15) or the API structapp variable. The ID ranges from 0 (default) to 255. 6.6.11 DotCode -------------- +-------------- DotCode uses a grid of dots in a rectangular formation to encode characters up to a maximum of approximately 450 characters (or 900 numeric digits). The symbology supports ECI encoding and GS1 data encoding. By default Zint will @@ -2945,8 +2992,9 @@ It does not support specifying an ID. Also known as Chinese Sensible Code, Han Xin is a symbology which is still under development, so it is recommended it should not yet be used for a production environment. The symbology is capable of encoding characters in the GB 18030 -character set (up to 4-byte characters) and is also able to support the ECI -mechanism. Support for the encoding of GS1 data has not yet been implemented. +character set (which includes all Unicode characters) and is also able to +support the ECI mechanism. Support for the encoding of GS1 data has not yet been +implemented. The size of the symbol can be specified using the --vers= option or setting option_2 to a value between 1 and 84 according to the following table. @@ -3100,8 +3148,8 @@ not given, no ID is encoded. 6.7 Other Barcode-Like Markings ------------------------------- -6.7.1. Facing Identification Mark (FIM) ---------------------------------------- +6.7.1 Facing Identification Mark (FIM) +-------------------------------------- Used by the United States Postal Service (USPS), the FIM symbology is used to assist automated mail processing. There are only 4 valid symbols which can be generated using the characters A-D as shown in the table below. @@ -3120,8 +3168,8 @@ D | Used for Information Based Indicia (IBI) postage. ------------------- Used for the recognition of page sequences in print-shops, the Flattermarken is not a true barcode symbol and requires precise knowledge of the position of the -mark on the page. The Flattermarken system can encode any length numeric data -and does not include a check digit. +mark on the page. The Flattermarken system can encode numeric data up to a +maximum of 90 digits and does not include a check digit. 6.7.3 DAFT Code --------------- @@ -3140,9 +3188,10 @@ default value is 250 (25%). ----------- Zint, libzint and Zint Barcode Studio are Copyright © 2021 Robin Stuart. All historical versions are distributed under the GNU General Public License -version 3 or later. Version 2.5 is released under a dual license: the encoding -library is released under the BSD license whereas the GUI, Zint Barcode Studio, -is released under the GNU General Public License version 3 or later. +version 3 or later. Version 2.5 (and later) is released under a dual license: +the encoding library is released under the BSD license whereas the GUI, Zint +Barcode Studio, is released under the GNU General Public License version 3 or +later. Telepen is a trademark of SB Electronic Systems Ltd. @@ -3299,7 +3348,7 @@ A.2 Latin Alphabet No 1 (ISO/IEC 8859-1) ---------------------------------------- A common extension to the ASCII standard, Latin-1 is used to expand the range of Code 128, PDF417 and other symbols. Input strings to the CLI should be in -Unicode (UTF-8) format, unless the --binary switch is given. +UTF-8 (Unicode) format, unless the --binary switch is given. ------------------------------------------------------ Hex | 8 | 9 | A | B | C | D | E | F diff --git a/frontend_qt/CMakeLists.txt b/frontend_qt/CMakeLists.txt index 45b8160b..23603605 100644 --- a/frontend_qt/CMakeLists.txt +++ b/frontend_qt/CMakeLists.txt @@ -6,14 +6,15 @@ project(zint-qt) set(CMAKE_AUTORCC ON) -set(${PROJECT_NAME}_SRCS barcodeitem.cpp main.cpp mainwindow.cpp datawindow.cpp sequencewindow.cpp exportwindow.cpp) +set(${PROJECT_NAME}_SRCS barcodeitem.cpp main.cpp mainwindow.cpp + cliwindow.cpp datawindow.cpp sequencewindow.cpp exportwindow.cpp) 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_wrap_cpp(zint-qt_SRCS mainwindow.h cliwindow.h datawindow.h sequencewindow.h exportwindow.h) + qt6_wrap_ui(zint-qt_SRCS mainWindow.ui extCLI.ui extData.ui extSequence.ui extExport.ui) 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_wrap_cpp(zint-qt_SRCS mainwindow.h cliwindow.h datawindow.h sequencewindow.h exportwindow.h) + qt5_wrap_ui(zint-qt_SRCS mainWindow.ui extCLI.ui extData.ui extSequence.ui extExport.ui) endif() # grpAztec.ui grpC39.ui grpCodablockF.ui grpDotCode.ui grpMaxicode.ui grpQR.ui grpVIN.ui @@ -30,7 +31,9 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/backend" "${CMAKE_SOURCE_DIR}/backend_qt") -target_link_libraries(${PROJECT_NAME} zint QZint Qt${QT_VERSION_MAJOR}::UiTools Qt${QT_VERSION_MAJOR}::Xml Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Core) +target_link_libraries(${PROJECT_NAME} zint QZint + Qt${QT_VERSION_MAJOR}::UiTools Qt${QT_VERSION_MAJOR}::Xml Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Core) install(TARGETS ${PROJECT_NAME} DESTINATION "${BIN_INSTALL_DIR}" RUNTIME) diff --git a/frontend_qt/barcodeitem.h b/frontend_qt/barcodeitem.h index d3f9e5aa..939e8bff 100644 --- a/frontend_qt/barcodeitem.h +++ b/frontend_qt/barcodeitem.h @@ -31,6 +31,7 @@ class BarcodeItem : public QGraphicsItem public: BarcodeItem(); ~BarcodeItem(); + void setSize(int width, int height); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); diff --git a/frontend_qt/cliwindow.cpp b/frontend_qt/cliwindow.cpp new file mode 100644 index 00000000..40658c81 --- /dev/null +++ b/frontend_qt/cliwindow.cpp @@ -0,0 +1,103 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2021 Robin Stuart + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* vim: set ts=4 sw=4 et : */ + +//#include +#include +#include +#include + +#include "cliwindow.h" +#include "barcodeitem.h" +#include "mainwindow.h" + +// Shorthand +#define QSL QStringLiteral + +static const int tempMessageTimeout = 2000; + +CLIWindow::CLIWindow(BarcodeItem *bc, const bool autoHeight, const double heightPerRow) + : m_bc(bc), m_autoHeight(autoHeight), m_heightPerRow(heightPerRow) +{ + setupUi(this); + QSettings settings; +#if QT_VERSION < 0x60000 + settings.setIniCodec("UTF-8"); +#endif + + QByteArray geometry = settings.value(QSL("studio/cli/window_geometry")).toByteArray(); + restoreGeometry(geometry); + +#if _WIN32 + const int index = settings.value(QSL("studio/cli/rad_unix_win"), 1).toInt(); +#else + const int index = settings.value(QSL("studio/cli/rad_unix_win"), 0).toInt(); +#endif + if (index == 1) { + radCLIWin->setChecked(true); + } else { + radCLIUnix->setChecked(true); + } + chkCLILongOpts->setChecked(settings.value(QSL("studio/cli/chk_long_opts"), 0).toInt() ? true : false); + chkCLIBarcodeName->setChecked(settings.value(QSL("studio/cli/chk_barcode_name"), 0).toInt() ? true : false); + + QIcon copyIcon(QIcon::fromTheme(QSL("edit-copy"), QIcon(QSL(":res/copy.svg")))); + QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg")))); + btnCLICopy->setIcon(copyIcon); + btnCLIClose->setIcon(closeIcon); + + connect(btnCLIClose, SIGNAL( clicked( bool )), SLOT(close())); + connect(btnCLICopy, SIGNAL( clicked( bool )), SLOT(copy_to_clipboard())); + connect(radCLIUnix, SIGNAL(toggled( bool )), SLOT(generate_cli())); + connect(radCLIWin, SIGNAL(toggled( bool )), SLOT(generate_cli())); + connect(chkCLILongOpts, SIGNAL(toggled( bool )), SLOT(generate_cli())); + connect(chkCLIBarcodeName, SIGNAL(toggled( bool )), SLOT(generate_cli())); + + generate_cli(); +} + +CLIWindow::~CLIWindow() +{ + QSettings settings; +#if QT_VERSION < 0x60000 + settings.setIniCodec("UTF-8"); +#endif + settings.setValue(QSL("studio/cli/window_geometry"), saveGeometry()); + settings.setValue(QSL("studio/cli/rad_unix_win"), radCLIWin->isChecked() ? 1 : 0); + settings.setValue(QSL("studio/cli/chk_long_opts"), chkCLILongOpts->isChecked() ? 1 : 0); + settings.setValue(QSL("studio/cli/chk_barcode_name"), chkCLIBarcodeName->isChecked() ? 1 : 0); +} + +void CLIWindow::copy_to_clipboard() +{ + QClipboard *clipboard = QGuiApplication::clipboard(); + QMimeData *mdata = new QMimeData; + mdata->setData("text/plain", txtCLICmd->toPlainText().toUtf8()); + clipboard->setMimeData(mdata, QClipboard::Clipboard); + statusBarCLI->showMessage(tr("Copied to clipboard"), tempMessageTimeout); +} + +void CLIWindow::generate_cli() +{ + QString cmd = m_bc->bc.getAsCLI(radCLIWin->isChecked(), chkCLILongOpts->isChecked(), + chkCLIBarcodeName->isChecked(), m_autoHeight, m_heightPerRow); + + txtCLICmd->setPlainText(cmd); + statusBarCLI->clearMessage(); +} diff --git a/frontend_qt/cliwindow.h b/frontend_qt/cliwindow.h new file mode 100644 index 00000000..da688a97 --- /dev/null +++ b/frontend_qt/cliwindow.h @@ -0,0 +1,46 @@ +/* + Zint Barcode Generator - the open source barcode generator + Copyright (C) 2021 Robin Stuart + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* vim: set ts=4 sw=4 et : */ + +#ifndef CLIWINDOW_H +#define CLIWINDOW_H + +#include "ui_extCLI.h" + +class BarcodeItem; + +class CLIWindow : public QDialog, private Ui::CLIDialog +{ + Q_OBJECT + +public: + CLIWindow(BarcodeItem *bc, const bool autoHeight, const double heightPerRow); + virtual ~CLIWindow(); + +private slots: + void copy_to_clipboard(); + void generate_cli(); + +protected: + BarcodeItem *m_bc; + bool m_autoHeight; + double m_heightPerRow; +}; + +#endif diff --git a/frontend_qt/datawindow.cpp b/frontend_qt/datawindow.cpp index 316c4e65..a6908d53 100644 --- a/frontend_qt/datawindow.cpp +++ b/frontend_qt/datawindow.cpp @@ -27,35 +27,43 @@ #include "datawindow.h" -DataWindow::DataWindow() +// Shorthand +#define QSL QStringLiteral + +DataWindow::DataWindow(const QString &input) : Valid(false) { setupUi(this); + QSettings settings; +#if QT_VERSION < 0x60000 + settings.setIniCodec("UTF-8"); +#endif - connect(btnCancel, SIGNAL( clicked( bool )), SLOT(quit_now())); - connect(btnReset, SIGNAL( clicked( bool )), SLOT(clear_data())); - connect(btnOK, SIGNAL( clicked( bool )), SLOT(okay())); -} + QByteArray geometry = settings.value(QSL("studio/data/window_geometry")).toByteArray(); + restoreGeometry(geometry); + + QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg")))); + QIcon clearIcon(QIcon::fromTheme(QSL("edit-clear"), QIcon(QSL(":res/delete.svg")))); + QIcon okIcon(QIcon(QSL(":res/check.svg"))); + btnCancel->setIcon(closeIcon); + btnDataClear->setIcon(clearIcon); + btnOK->setIcon(okIcon); -DataWindow::DataWindow(const QString &input) -{ - setupUi(this); txtDataInput->setPlainText(input); txtDataInput->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); - connect(btnCancel, SIGNAL( clicked( bool )), SLOT(quit_now())); - connect(btnReset, SIGNAL( clicked( bool )), SLOT(clear_data())); + connect(btnCancel, SIGNAL( clicked( bool )), SLOT(close())); + connect(btnDataClear, SIGNAL( clicked( bool )), SLOT(clear_data())); connect(btnOK, SIGNAL( clicked( bool )), SLOT(okay())); connect(btnFromFile, SIGNAL( clicked( bool )), SLOT(from_file())); } DataWindow::~DataWindow() { -} - -void DataWindow::quit_now() -{ - Valid = 0; - close(); + QSettings settings; +#if QT_VERSION < 0x60000 + settings.setIniCodec("UTF-8"); +#endif + settings.setValue(QSL("studio/data/window_geometry"), saveGeometry()); } void DataWindow::clear_data() @@ -65,7 +73,7 @@ void DataWindow::clear_data() void DataWindow::okay() { - Valid = 1; + Valid = true; DataOutput = txtDataInput->toPlainText(); close(); } @@ -93,7 +101,7 @@ void DataWindow::from_file() } file.setFileName(filename); - if(!file.open(QIODevice::ReadOnly)) { + if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file.")); return; } diff --git a/frontend_qt/datawindow.h b/frontend_qt/datawindow.h index 6834d834..369e927e 100644 --- a/frontend_qt/datawindow.h +++ b/frontend_qt/datawindow.h @@ -1,6 +1,6 @@ /* Zint Barcode Generator - the open source barcode generator - Copyright (C) 2009-2017 Robin Stuart + Copyright (C) 2009-2021 Robin Stuart This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* vim: set ts=4 sw=4 et : */ #ifndef DATAWINDOW_H #define DATAWINDOW_H @@ -24,20 +25,19 @@ class DataWindow : public QDialog, private Ui::DataDialog { - Q_OBJECT + Q_OBJECT public: - DataWindow(); - explicit DataWindow(const QString &input); - ~DataWindow(); - int Valid; - QString DataOutput; + DataWindow(const QString &input); + ~DataWindow(); + + bool Valid; + QString DataOutput; private slots: - void quit_now(); - void clear_data(); - void okay(); - void from_file(); + void clear_data(); + void okay(); + void from_file(); }; #endif diff --git a/frontend_qt/exportwindow.cpp b/frontend_qt/exportwindow.cpp index 3c33d20d..c9a5bf40 100644 --- a/frontend_qt/exportwindow.cpp +++ b/frontend_qt/exportwindow.cpp @@ -23,24 +23,34 @@ #include #include #include +#include #include "exportwindow.h" -ExportWindow::ExportWindow() +// Shorthand +#define QSL QStringLiteral + +ExportWindow::ExportWindow(BarcodeItem *bc, const QString& output_data) : m_bc(bc), m_output_data(output_data) { + setupUi(this); QSettings settings; #if QT_VERSION < 0x60000 settings.setIniCodec("UTF-8"); #endif - setupUi(this); - linDestPath->setText(settings.value("studio/export/destination", + QByteArray geometry = settings.value(QSL("studio/export/window_geometry")).toByteArray(); + restoreGeometry(geometry); + + linDestPath->setText(settings.value(QSL("studio/export/destination"), QDir::toNativeSeparators(QDir::homePath())).toString()); - linPrefix->setText(settings.value("studio/export/file_prefix", "bcs_").toString()); - cmbFileName->setCurrentIndex(settings.value("studio/export/name_format", 0).toInt()); - cmbFileFormat->setCurrentIndex(settings.value("studio/export/filetype", 0).toInt()); + linPrefix->setText(settings.value(QSL("studio/export/file_prefix"), QSL("bcs_")).toString()); + cmbFileName->setCurrentIndex(settings.value(QSL("studio/export/name_format"), 0).toInt()); + cmbFileFormat->setCurrentIndex(settings.value(QSL("studio/export/filetype"), 0).toInt()); - connect(btnCancel, SIGNAL( clicked( bool )), SLOT(quit_now())); + QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg")))); + btnCancel->setIcon(closeIcon); + + connect(btnCancel, SIGNAL( clicked( bool )), SLOT(close())); connect(btnOK, SIGNAL( clicked( bool )), SLOT(process())); connect(btnDestPath, SIGNAL( clicked( bool )), SLOT(get_directory())); } @@ -51,16 +61,12 @@ ExportWindow::~ExportWindow() #if QT_VERSION < 0x60000 settings.setIniCodec("UTF-8"); #endif + settings.setValue(QSL("studio/export/window_geometry"), saveGeometry()); - settings.setValue("studio/export/destination", linDestPath->text()); - settings.setValue("studio/export/file_prefix", linPrefix->text()); - settings.setValue("studio/export/name_format", cmbFileName->currentIndex()); - settings.setValue("studio/export/filetype", cmbFileFormat->currentIndex()); -} - -void ExportWindow::quit_now() -{ - close(); + settings.setValue(QSL("studio/export/destination"), linDestPath->text()); + settings.setValue(QSL("studio/export/file_prefix"), linPrefix->text()); + settings.setValue(QSL("studio/export/name_format"), cmbFileName->currentIndex()); + settings.setValue(QSL("studio/export/filetype"), cmbFileFormat->currentIndex()); } void ExportWindow::get_directory() @@ -73,116 +79,148 @@ void ExportWindow::get_directory() QFileDialog fdialog; fdialog.setFileMode(QFileDialog::Directory); - fdialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString()); + fdialog.setDirectory(settings.value(QSL("studio/default_dir"), + QDir::toNativeSeparators(QDir::homePath())).toString()); - if(fdialog.exec()) { + if (fdialog.exec()) { directory = fdialog.selectedFiles().at(0); } else { return; } linDestPath->setText(QDir::toNativeSeparators(directory)); - settings.setValue("studio/default_dir", directory); + settings.setValue(QSL("studio/default_dir"), directory); } void ExportWindow::process() { - QString fileName; - QString dataString; + const QRegularExpression urlRE(QSL("[\\/:*?\"<>|%]")); + + txtFeedback->setPlainText(tr("Processing...")); + txtFeedback->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); + + QStringList dataList = m_output_data.split('\n'); + int lines = dataList.size(); + if (lines && dataList[lines - 1].isEmpty()) { + lines--; + } + + QString biggest; + bool needUrlEscape = false; + + const int fileNameIdx = cmbFileName->currentIndex(); + if (fileNameIdx == 1) { + biggest = QString::number(lines + 1); + } else { + needUrlEscape = m_output_data.contains(urlRE); + } + QString suffix; - QString Feedback; - int lines, i, j, inputpos; - - lines = output_data.count(QChar('\n'), Qt::CaseInsensitive); - inputpos = 0; - - switch(cmbFileFormat->currentIndex()) { + switch (cmbFileFormat->currentIndex()) { #ifdef NO_PNG - case 0: suffix = ".eps"; break; - case 1: suffix = ".gif"; break; - case 2: suffix = ".svg"; break; - case 3: suffix = ".bmp"; break; - case 4: suffix = ".pcx"; break; - case 5: suffix = ".emf"; break; - case 6: suffix = ".tif"; break; + case 0: suffix = QSL(".eps"); break; + case 1: suffix = QSL(".gif"); break; + case 2: suffix = QSL(".svg"); break; + case 3: suffix = QSL(".bmp"); break; + case 4: suffix = QSL(".pcx"); break; + case 5: suffix = QSL(".emf"); break; + case 6: suffix = QSL(".tif"); break; #else - case 0: suffix = ".png"; break; - case 1: suffix = ".eps"; break; - case 2: suffix = ".gif"; break; - case 3: suffix = ".svg"; break; - case 4: suffix = ".bmp"; break; - case 5: suffix = ".pcx"; break; - case 6: suffix = ".emf"; break; - case 7: suffix = ".tif"; break; + case 0: suffix = QSL(".png"); break; + case 1: suffix = QSL(".eps"); break; + case 2: suffix = QSL(".gif"); break; + case 3: suffix = QSL(".svg"); break; + case 4: suffix = QSL(".bmp"); break; + case 5: suffix = QSL(".pcx"); break; + case 6: suffix = QSL(".emf"); break; + case 7: suffix = QSL(".tif"); break; #endif } - txtFeedback->clear(); - Feedback = ""; - for(i = 0; i < lines; i++) { - int datalen = 0; - for(j = inputpos; ((j < output_data.length()) && (output_data[j] != '\n') ); j++) { - datalen++; - } - dataString = output_data.mid(inputpos, datalen); - switch(cmbFileName->currentIndex()) { - case 0: { /* Same as Data (URL Escaped) */ + QString filePathPrefix = linDestPath->text() % QDir::separator() % linPrefix->text(); + + QStringList Feedback; + int successCount = 0, errorCount = 0; + for (int i = 0; i < lines; i++) { + const QString &dataString = dataList[i]; + QString fileName; + switch (fileNameIdx) { + case 0: /* Same as Data (URL Escaped) */ + if (needUrlEscape) { QString url_escaped; - int m; - QChar name_qchar; - for(m = 0; m < dataString.length(); m++) { - name_qchar = dataString[m]; + for (int m = 0; m < dataString.length(); m++) { + QChar name_qchar = dataString[m]; char name_char = name_qchar.toLatin1(); - switch(name_char) { - case '\\': url_escaped += "%5C"; break; - case '/': url_escaped += "%2F"; break; - case ':': url_escaped += "%3A"; break; - case '*': url_escaped += "%2A"; break; - case '?': url_escaped += "%3F"; break; - case '"': url_escaped += "%22"; break; - case '<': url_escaped += "%3C"; break; - case '>': url_escaped += "%3E"; break; - case '|': url_escaped += "%7C"; break; - case '%': url_escaped += "%25"; break; + switch (name_char) { + case '\\': url_escaped += QSL("%5C"); break; + case '/': url_escaped += QSL("%2F"); break; + case ':': url_escaped += QSL("%3A"); break; + case '*': url_escaped += QSL("%2A"); break; + case '?': url_escaped += QSL("%3F"); break; + case '"': url_escaped += QSL("%22"); break; + case '<': url_escaped += QSL("%3C"); break; + case '>': url_escaped += QSL("%3E"); break; + case '|': url_escaped += QSL("%7C"); break; + case '%': url_escaped += QSL("%25"); break; default: url_escaped += name_qchar; break; } } - fileName = linDestPath->text() + QDir::separator() + linPrefix->text() + url_escaped + suffix; + fileName = filePathPrefix % url_escaped % suffix; + } else { + fileName = filePathPrefix % dataString % suffix; } break; case 1: { /* Formatted Serial Number */ - QString biggest, this_val, outnumber; - int number_size, val_size, m; + QString this_val, pad; - biggest = QString::number(lines + 1); - number_size = biggest.length(); this_val = QString::number(i + 1); - val_size = this_val.length(); - for(m = 0; m < (number_size - val_size); m++) { - outnumber += QChar('0'); - } + pad.fill('0', biggest.length() - this_val.length()); - outnumber += this_val; - - fileName = linDestPath->text() + QDir::separator() + linPrefix->text() + outnumber + suffix; + fileName = filePathPrefix % pad % this_val % suffix; } break; } - barcode->bc.setText(dataString.toLatin1().data()); - barcode->bc.save_to_file(fileName.toLatin1().data()); - Feedback += "Line "; - Feedback += QString::number(i + 1); - Feedback += ": "; - if (barcode->bc.hasErrors()) { - Feedback += barcode->bc.error_message(); - Feedback += "\n"; + m_bc->bc.setText(dataString); + m_bc->bc.save_to_file(fileName); + if (m_bc->bc.hasErrors()) { + /*: %1 is line number, %2 is error message */ + Feedback << tr("Line %1: %2").arg(i + 1).arg(m_bc->bc.error_message()); + errorCount++; } else { - Feedback += "Success\n"; + /*: %1 is line number */ + Feedback << tr("Line %1: Success").arg(i + 1); + successCount++; + } + if (i && (i % 100 == 0)) { + txtFeedback->appendPlainText(Feedback.join('\n')); + txtFeedback->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); + Feedback.clear(); } - txtFeedback->document()->setPlainText(Feedback); - inputpos += datalen + 1; } + + QString summary; + if (errorCount && successCount) { + /*: %1 is total no. of items processed, %2 is no. of failures, %3 is no. of successes */ + summary = tr("Total %1, %2 failed, %3 succeeded.").arg(errorCount + successCount).arg(errorCount) + .arg(successCount); + } else if (errorCount) { + /*: %1 is no. of failures */ + summary = tr("All %1 failed.").arg(errorCount); + } else if (successCount) { + /*: %1 is no. of successes */ + summary = tr("All %1 succeeded.").arg(successCount); + } else { + summary = tr("No items."); + } + if (Feedback.size()) { + txtFeedback->appendPlainText(Feedback.join('\n') + '\n' + summary + '\n'); + } else { + txtFeedback->appendPlainText(summary + '\n'); + } + txtFeedback->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); } diff --git a/frontend_qt/exportwindow.h b/frontend_qt/exportwindow.h index c6ac7c84..7c1b3757 100644 --- a/frontend_qt/exportwindow.h +++ b/frontend_qt/exportwindow.h @@ -1,6 +1,6 @@ /* Zint Barcode Generator - the open source barcode generator - Copyright (C) 2009-2017 Robin Stuart + Copyright (C) 2009-2021 Robin Stuart This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* vim: set ts=4 sw=4 et : */ #ifndef EXPORTWINDOW_H #define EXPORTWINDOW_H @@ -25,18 +26,19 @@ class ExportWindow : public QDialog, private Ui::ExportDialog { - Q_OBJECT + Q_OBJECT public: - ExportWindow(); - ~ExportWindow(); - BarcodeItem *barcode; - QString output_data; + ExportWindow(BarcodeItem *bc, const QString& output_data); + ~ExportWindow(); private slots: - void quit_now(); - void process(); - void get_directory(); + void process(); + void get_directory(); + +protected: + BarcodeItem *m_bc; + QString m_output_data; }; -#endif \ No newline at end of file +#endif diff --git a/frontend_qt/extCLI.ui b/frontend_qt/extCLI.ui new file mode 100644 index 00000000..aa01c7e6 --- /dev/null +++ b/frontend_qt/extCLI.ui @@ -0,0 +1,162 @@ + + + CLIDialog + + + + 0 + 0 + 429 + 333 + + + + CLI Equivalent + + + + :res/zint-qt.ico:res/zint-qt.ico + + + true + + + + + + Command Line &Equivalent + + + Current GUI settings as CLI equivalent + + + txtCLICmd + + + + + + + + 0 + 0 + + + + true + + + + + + + Escape Method + + + How to escape data + + + + QLayout::SetMinimumSize + + + + + &Unix + + + Escape for Unix shell + + + true + + + + + + + &Windows + + + Escape for Windows command prompt + + + + + + + + + + + + &Long Options Only + + + Only use long option names, not short ones + + + false + + + + + + + &Barcode Name + + + Use name of barcode, not number + + + false + + + + + + + + + QLayout::SetDefaultConstraint + + + + + false + + + + 40 + 20 + + + + + + + + Copy to clipboard + + + C&opy + + + + + + + &Close + + + Close window + + + + + + + + + + diff --git a/frontend_qt/extData.ui b/frontend_qt/extData.ui index 3f104bc8..8d180432 100644 --- a/frontend_qt/extData.ui +++ b/frontend_qt/extData.ui @@ -27,8 +27,8 @@ &Data - Input data. Newlines (Line Feeds (0xA0)) -will be converted to spaces + Input data. Line Feeds (0xA0) will +be converted to spaces txtDataInput @@ -70,14 +70,14 @@ will be converted to spaces <tr><td>Record Separator (0x1E)</td><td>&nbsp;\R</td></tr> <tr><td>Backslash (0x5C)</td><td>&nbsp;\\</td></tr> </table> -Note that newlines (Line Feeds (0x0A)) are <br/>not included +Note that Line Feed (0x0A) is not included - + - &Reset + C&lear Clear data window @@ -100,7 +100,7 @@ Note that newlines (Line Feeds (0x0A)) are <br/>not included - &OK + &OK Close window and update input data diff --git a/frontend_qt/extExport.ui b/frontend_qt/extExport.ui index 6bccdc6e..f1f8e1c5 100644 --- a/frontend_qt/extExport.ui +++ b/frontend_qt/extExport.ui @@ -10,24 +10,6 @@ 505 - - - 0 - 0 - - - - - 450 - 505 - - - - - 450 - 505 - - Export Barcodes @@ -35,258 +17,214 @@ :res/zint-qt.ico:res/zint-qt.ico - - - - 140 - 10 - 261 - 22 - - - - Destination folder - - - - - - 140 - 40 - 301 - 22 - - - - The first part of the filenames - - - bcs_ - - - - - - 140 - 70 - 301 - 22 - - - - Set the naming convention used by the files - + - - Same as Data - + + + + + &Destination Path: + + + Destination folder + + + linDestPath + + + + + + + + 140 + 10 + 261 + 22 + + + + Destination folder + + + + + + + Find a destination for your files + + + &... + + + + + + + File Name &Prefix: + + + The first part of the filenames + + + linPrefix + + + + + + + The first part of the filenames + + + bcs_ + + + + + + + File &Name: + + + Set the naming convention used by the files + + + cmbFileName + + + + + + + Set the naming convention used by the files + + + + Same as Data + + + + + Serial Number + + + + + + + + File &Format: + + + The type of file which you want to create + + + cmbFileFormat + + + + + + + The type of file which you want to create + + + + Portable Network Graphic (*.png) + + + + + Encapsulated Post Script (*.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) + + + + + - - Serial Number - - - - - - - 140 - 100 - 301 - 22 - - - - The type of file which you want to create - - - - Portable Network Graphic (*.png) - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Export + + + Create files + + + + + + + &Close + + + Close window + + + + - - Encapsulated Post Script (*.eps) - + + + Export Results: + + - - Graphics Interchange Format (*.gif) - + + + true + + - - - Scalable Vector Graphic (*.svg) - - - - - Windows Bitmap (*.bmp) - - - - - ZSoft PC Painter Image (*.pcx) - - - - - Extended Metafile (*.emf) - - - - - Tagged Image File Format (*.tif) - - - - - - - 410 - 10 - 30 - 25 - - - - Find a destination for your files - - - &... - - - - - - 10 - 10 - 121 - 16 - - - - &Destination Path: - - - Destination folder - - - linDestPath - - - - - - 10 - 40 - 111 - 16 - - - - File Name &Prefix: - - - The first part of the filenames - - - linPrefix - - - - - - 10 - 70 - 111 - 16 - - - - File &Name: - - - Set the naming convention used by the files - - - cmbFileName - - - - - - 10 - 100 - 111 - 16 - - - - File &Format: - - - The type of file which you want to create - - - cmbFileFormat - - - - - - 360 - 130 - 80 - 26 - - - - &Close - - - Close window - - - - - - 270 - 130 - 80 - 26 - - - - &Export - - - Create files - - - - - - 10 - 180 - 430 - 315 - - - - - - - 10 - 160 - 101 - 17 - - - - Export Results: - - + diff --git a/frontend_qt/extSequence.ui b/frontend_qt/extSequence.ui index dd90edc0..36593930 100644 --- a/frontend_qt/extSequence.ui +++ b/frontend_qt/extSequence.ui @@ -14,17 +14,17 @@ Sequence Export - + :res/zint-qt.ico:res/zint-qt.ico true - + - + - + 0 @@ -34,155 +34,158 @@ Create Sequence - + - + - + - + + + Start sequence at this value + &Start Value: - linStartVal - - - Start sequence at this value + spnSeqStartVal - + + + End sequence at this value + End &Value: - linEndVal - - - End sequence at this value + spnSeqEndVal - + + + Go from start to end in steps of this amount + Increment &By: - linIncVal - - - Go from start to end in steps of this amount + spnSeqIncVal - + + + Format sequence using special characters<table cellspacing="3"> +<tr><td>#</td><td>Number or space</td></tr> +<tr><td>$</td><td>Number or '0'</td></tr> +<tr><td>*</td><td>Number or '*'</td></tr> +<tr><td>Other</td><td>Insert literally</td></tr> +</table> + &Format: - linFormat - - - Format sequence using special characters<table cellspacing="3"> -<tr><td>#</td><td>Number or space</td></tr> -<tr><td>$</td><td>Number or '0'</td></tr> -<tr><td>*</td><td>Number or '*'</td></tr> -<tr><td>Other</td><td>Insert literally</td></tr> -</table> + linSeqFormat - - - Sequence: - + Create a data sequence + + Sequence: + - - - Sequence File: - + Get a data sequence from a file + + Sequence File: + - - - Generate Bar Codes: - + false Save the symbols to files + + Generate Bar Codes: + - + - - - 1 + + + Start sequence at this value true - - Start sequence at this value + + 999999999 - - - 10 - + End sequence at this value + + 999999999 + - - - 1 - + Go from start to end in steps of this amount + + 1 + + + 999999999 + - - - $$$$$$ - + Format sequence using special characters<table cellspacing="3"> <tr><td>#</td><td>Number or space</td></tr> -<tr><td>$</td><td>Number or '0'</td></tr> -<tr><td>*</td><td>Number or '*'</td></tr> +<tr><td>$</td><td>Number or '0'</td></tr> +<tr><td>*</td><td>Number or '*'</td></tr> <tr><td>Other</td><td>Insert literally</td></tr> </table> + + $$$$$$ + - + Create a data sequence @@ -192,7 +195,7 @@ - + Get a data sequence from a file @@ -202,7 +205,7 @@ - + false @@ -222,33 +225,29 @@ - + 0 0 - - Sequence &Data - The data to be encoded, one line per symbol + + Sequence &Data + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - + - - - - - The data to be encoded, one line per symbol - - - - + + + The data to be encoded, one line per symbol + + @@ -256,9 +255,9 @@ - + - + Qt::Horizontal @@ -271,23 +270,23 @@ - - - &Reset - + Clear the sequence data + + C&lear + - - - &Close - + Close window + + &Close + diff --git a/frontend_qt/frontend_qt.pro b/frontend_qt/frontend_qt.pro index 24b9a174..0c85ea41 100644 --- a/frontend_qt/frontend_qt.pro +++ b/frontend_qt/frontend_qt.pro @@ -15,12 +15,14 @@ QT += uitools # Input HEADERS += barcodeitem.h \ + cliwindow.h \ datawindow.h \ exportwindow.h \ mainwindow.h \ sequencewindow.h -FORMS += extData.ui \ +FORMS += extCLI.ui \ + extData.ui \ extExport.ui \ extSequence.ui \ grpAztec.ui \ @@ -55,12 +57,13 @@ FORMS += extData.ui \ mainWindow.ui SOURCES += barcodeitem.cpp \ + cliwindow.cpp \ datawindow.cpp \ exportwindow.cpp \ main.cpp \ mainwindow.cpp \ sequencewindow.cpp - + TRANSLATIONS = frontend_de.ts RESOURCES += resources.qrc diff --git a/frontend_qt/frontend_qt_zintdll.pro b/frontend_qt/frontend_qt_zintdll.pro index 1c68dcb0..655f8dad 100644 --- a/frontend_qt/frontend_qt_zintdll.pro +++ b/frontend_qt/frontend_qt_zintdll.pro @@ -5,12 +5,14 @@ QT += widgets # Input HEADERS += barcodeitem.h \ + cliwindow.h \ datawindow.h \ exportwindow.h \ mainwindow.h \ sequencewindow.h -FORMS += extData.ui \ +FORMS += extCLI.ui \ + extData.ui \ extExport.ui \ extSequence.ui \ grpAztec.ui \ @@ -45,6 +47,7 @@ FORMS += extData.ui \ mainWindow.ui SOURCES += barcodeitem.cpp \ + cliwindow.cpp \ datawindow.cpp \ exportwindow.cpp \ main.cpp \ diff --git a/frontend_qt/frontend_vc8.pro b/frontend_qt/frontend_vc8.pro index 8eeab07a..4317d197 100644 --- a/frontend_qt/frontend_vc8.pro +++ b/frontend_qt/frontend_vc8.pro @@ -6,20 +6,23 @@ CONFIG += warn_on \ uitools FORMS = mainWindow.ui \ - extSequence.ui \ + extCLI.ui \ + extSequence.ui \ extExport.ui \ extData.ui HEADERS = mainwindow.h \ barcodeitem.h \ + cliwindow.h \ datawindow.h \ exportwindow.h \ sequencewindow.h \ qzint.h -SOURCES = main.cpp \ +SOURCES = main.cpp \ mainwindow.cpp \ barcodeitem.cpp \ + cliwindow.cpp \ datawindow.cpp \ exportwindow.cpp \ sequencewindow.cpp @@ -30,5 +33,5 @@ RESOURCES = resources.qrc INCLUDEPATH += ../backend RC_FILE = ./res/qtZint.rc - + LIBS = QtZint2.lib diff --git a/frontend_qt/mainwindow.cpp b/frontend_qt/mainwindow.cpp index 5ffef2a4..4b5f82ac 100644 --- a/frontend_qt/mainwindow.cpp +++ b/frontend_qt/mainwindow.cpp @@ -34,14 +34,14 @@ #include #include "mainwindow.h" +#include "cliwindow.h" #include "datawindow.h" #include "sequencewindow.h" -#include // Shorthand #define QSL QStringLiteral -static const int statusBarTimeout = 0; // Don't timeout +static const int tempMessageTimeout = 2000; static const QKeySequence quitKeySeq(Qt::CTRL | Qt::Key_Q); // Use on Windows also (i.e. not using QKeySequence::Quit) @@ -430,11 +430,11 @@ bool MainWindow::save() QString dirname = pathname.mid(0, lastSeparator); if (dirname.isEmpty()) { /*: %1 is path saved to */ - statusBar->showMessage(tr("Saved as \"%1\"").arg(pathname), statusBarTimeout); + statusBar->showMessage(tr("Saved as \"%1\"").arg(pathname), 0 /*No timeout*/); } else { QString filename = pathname.right(pathname.length() - (lastSeparator + 1)); /*: %1 is base filename saved to, %2 is directory saved in */ - statusBar->showMessage(tr("Saved as \"%1\" in \"%2\"").arg(filename).arg(dirname), statusBarTimeout); + statusBar->showMessage(tr("Saved as \"%1\" in \"%2\"").arg(filename).arg(dirname), 0 /*No timeout*/); } settings.setValue(QSL("studio/default_dir"), dirname); @@ -476,21 +476,35 @@ void MainWindow::help() QDesktopServices::openUrl(QSL("https://zint.org.uk/manual")); // TODO: manual.md } -int MainWindow::open_data_dialog() +void MainWindow::open_data_dialog() { - int retval; DataWindow dlg(txtData->text()); - retval = dlg.exec(); - if (dlg.Valid == 1) + (void) dlg.exec(); + if (dlg.Valid) { + const bool updated = txtData->text() != dlg.DataOutput; txtData->setText(dlg.DataOutput); - return retval; + if (updated) { + statusBar->showMessage(tr("Updated data"), tempMessageTimeout); + } + } } -int MainWindow::open_sequence_dialog() +void MainWindow::open_sequence_dialog() { - SequenceWindow dlg; - dlg.barcode = &m_bc; - return dlg.exec(); + SequenceWindow dlg(&m_bc); + (void) dlg.exec(); +#ifdef _WIN32 + // Windows causes BarcodeItem to paint on closing dialog so need to re-paint with our (non-Export) values + update_preview(); +#endif +} + +void MainWindow::open_cli_dialog() +{ + CLIWindow dlg(&m_bc, chkAutoHeight->isEnabled() && chkAutoHeight->isChecked(), + m_spnHeightPerRow && m_spnHeightPerRow->isEnabled() ? m_spnHeightPerRow->value() : 0.0); + + (void) dlg.exec(); } void MainWindow::on_fgcolor_clicked() @@ -527,7 +541,7 @@ void MainWindow::autoheight_ui_set() if (enabled && m_spnHeightPerRow->value()) { lblHeight->setEnabled(!enabled); heightb->setEnabled(!enabled); - statusBar->showMessage(tr("Using \"Row Height\""), statusBarTimeout); + statusBar->showMessage(tr("Using \"Row Height\""), 0 /*No timeout*/); } else { statusBar->clearMessage(); } @@ -650,6 +664,9 @@ void MainWindow::structapp_ui_set() void MainWindow::on_encoded() { + if (QApplication::activeModalWidget() != nullptr) { // Protect against encode in popup dialog + return; + } this->setMinimumHeight(m_bc.bc.getError() ? 455 : 435); enableActions(true); errtxtBar_set(false /*isError*/); @@ -663,6 +680,9 @@ void MainWindow::on_encoded() void MainWindow::on_errored() { + if (QApplication::activeModalWidget() != nullptr) { // Protect against error in popup dialog (Sequence Export) + return; + } this->setMinimumHeight(455); enableActions(false); errtxtBar_set(true /*isError*/); @@ -795,7 +815,7 @@ void MainWindow::copy_to_clipboard_errtxt() QMimeData *mdata = new QMimeData; mdata->setText(m_bc.bc.lastError()); clipboard->setMimeData(mdata, QClipboard::Clipboard); - statusBar->showMessage(tr("Copied message to clipboard"), statusBarTimeout); + statusBar->showMessage(tr("Copied message to clipboard"), 0 /*No timeout*/); } } @@ -879,6 +899,8 @@ void MainWindow::view_context_menu(const QPoint &pos) menu.addAction(m_copySVGAct); menu.addAction(m_copyTIFAct); menu.addSeparator(); + menu.addAction(m_CLIAct); + menu.addSeparator(); menu.addAction(m_saveAsAct); menu.exec(get_context_menu_pos(pos, view)); @@ -1698,6 +1720,7 @@ void MainWindow::update_preview() m_bc.bc.setGSSep(false); m_bc.bc.setNoQuietZones(false); m_bc.bc.setDotSize(0.4f / 0.5f); + m_bc.bc.setGuardDescent(5.0f); m_bc.bc.clearStructApp(); switch (symbology) { @@ -2253,6 +2276,7 @@ void MainWindow::createActions() // MIT license - see site and "frontend_qt/res/LICENSE_feathericons" QIcon menuIcon(QSL(":res/menu.svg")); QIcon copyIcon(QIcon::fromTheme(QSL("edit-copy"), QIcon(QSL(":res/copy.svg")))); + QIcon cliIcon(QSL(":res/zint_black.ico")); QIcon saveIcon(QIcon::fromTheme(QSL("document-save"), QIcon(QSL(":res/download.svg")))); QIcon aboutIcon(QSL(":res/zint-qt.ico")); QIcon helpIcon(QIcon::fromTheme(QSL("help-contents"), QIcon(QSL(":res/help-circle.svg")))); @@ -2302,6 +2326,10 @@ void MainWindow::createActions() m_copyTIFAct->setStatusTip(tr("Copy to clipboard as TIF")); connect(m_copyTIFAct, SIGNAL(triggered()), this, SLOT(copy_to_clipboard_tif())); + m_CLIAct = new QAction(cliIcon, tr("C&LI equivalent..."), this); + m_CLIAct->setStatusTip(tr("Generate CLI equivalent")); + connect(m_CLIAct, SIGNAL(triggered()), this, SLOT(open_cli_dialog())); + m_saveAsAct = new QAction(saveIcon, tr("&Save As..."), this); m_saveAsAct->setStatusTip(tr("Output image to file")); m_saveAsAct->setShortcut(QKeySequence::Save); @@ -2346,6 +2374,8 @@ void MainWindow::createMenu() m_menu->addAction(m_copyTIFAct); m_menu->addSeparator(); + m_menu->addAction(m_CLIAct); + m_menu->addSeparator(); m_menu->addAction(m_saveAsAct); m_menu->addSeparator(); m_menu->addAction(m_helpAct); @@ -2374,6 +2404,7 @@ void MainWindow::enableActions(bool enabled) #endif m_copySVGAct->setEnabled(enabled); m_copyTIFAct->setEnabled(enabled); + m_CLIAct->setEnabled(enabled); m_saveAsAct->setEnabled(enabled); m_saveAsShortcut->setEnabled(enabled); @@ -2397,13 +2428,13 @@ void MainWindow::copy_to_clipboard(const QString &filename, const QString& name, file.close(); clipboard->setMimeData(mdata, QClipboard::Clipboard); /*: %1 is format (BMP/EMF etc) */ - statusBar->showMessage(tr("Copied to clipboard as %1").arg(name), statusBarTimeout); + statusBar->showMessage(tr("Copied to clipboard as %1").arg(name), 0 /*No timeout*/); } } else { mdata->setImageData(QImage(filename)); clipboard->setMimeData(mdata, QClipboard::Clipboard); /*: %1 is format (BMP/EMF etc) */ - statusBar->showMessage(tr("Copied to clipboard as %1").arg(name), statusBarTimeout); + statusBar->showMessage(tr("Copied to clipboard as %1").arg(name), 0 /*No timeout*/); } QFile::remove(filename); @@ -2456,172 +2487,59 @@ QWidget *MainWindow::get_widget(const QString &name) } /* Return settings subsection name for a symbol */ -const QString &MainWindow::get_setting_name(int symbology) +QString MainWindow::get_setting_name(int symbology) { - struct item { - const QString name; - int define; - int val; - }; - static const struct item ndata[] = { - { QSL(""), -1, 0 }, - { QSL("code11"), BARCODE_CODE11, 1 }, - { QSL("c25standard"), BARCODE_C25STANDARD, 2 }, - { QSL("c25inter"), BARCODE_C25INTER, 3 }, - { QSL("c25iata"), BARCODE_C25IATA, 4 }, - { QSL(""), -1, 5 }, - { QSL("c25logic"), BARCODE_C25LOGIC, 6 }, - { QSL("c25ind"), BARCODE_C25IND, 7 }, - { QSL("code39"), BARCODE_CODE39, 8 }, - { QSL("excode39"), BARCODE_EXCODE39, 9 }, - { QSL(""), -1, 10 }, - { QSL(""), -1, 11 }, - { QSL(""), -1, 12 }, - { QSL("eanx"), BARCODE_EANX, 13 }, - { QSL("eanx"), BARCODE_EANX_CHK, 14 }, - { QSL(""), -1, 15 }, - { QSL("code128"), BARCODE_GS1_128, 16 }, - { QSL(""), -1, 17 }, - { QSL("codabar"), BARCODE_CODABAR, 18 }, - { QSL(""), -1, 19 }, - { QSL("code128"), BARCODE_CODE128, 20 }, - { QSL("dpleit"), BARCODE_DPLEIT, 21 }, - { QSL("dpident"), BARCODE_DPIDENT, 22 }, - { QSL("code16k"), BARCODE_CODE16K, 23 }, - { QSL("code49"), BARCODE_CODE49, 24 }, - { QSL("code93"), BARCODE_CODE93, 25 }, - { QSL(""), -1, 26 }, - { QSL(""), -1, 27 }, - { QSL("flat"), BARCODE_FLAT, 28 }, - { QSL("dbar_omn"), BARCODE_DBAR_OMN, 29 }, - { QSL("dbar_ltd"), BARCODE_DBAR_LTD, 30 }, - { QSL("dbar_exp"), BARCODE_DBAR_EXP, 31 }, - { QSL("telepen"), BARCODE_TELEPEN, 32 }, - { QSL(""), -1, 33 }, - { QSL("upca"), BARCODE_UPCA, 34 }, - { QSL("upca"), BARCODE_UPCA_CHK, 35 }, - { QSL(""), -1, 36 }, - { QSL("upce"), BARCODE_UPCE, 37 }, - { QSL("upce"), BARCODE_UPCE_CHK, 38 }, - { QSL(""), -1, 39 }, - { QSL("postnet"), BARCODE_POSTNET, 40 }, - { QSL(""), -1, 41 }, - { QSL(""), -1, 42 }, - { QSL(""), -1, 43 }, - { QSL(""), -1, 44 }, - { QSL(""), -1, 45 }, - { QSL(""), -1, 46 }, - { QSL("msi_plessey"), BARCODE_MSI_PLESSEY, 47 }, - { QSL(""), -1, 48 }, - { QSL("fim"), BARCODE_FIM, 49 }, - { QSL("logmars"), BARCODE_LOGMARS, 50 }, - { QSL("pharma"), BARCODE_PHARMA, 51 }, - { QSL("pzn"), BARCODE_PZN, 52 }, - { QSL("pharma_two"), BARCODE_PHARMA_TWO, 53 }, - { QSL(""), -1, 54 }, - { QSL("pdf417"), BARCODE_PDF417, 55 }, - { QSL("pdf417"), BARCODE_PDF417COMP, 56 }, - { QSL("maxicode"), BARCODE_MAXICODE, 57 }, - { QSL("qrcode"), BARCODE_QRCODE, 58 }, - { QSL(""), -1, 59 }, - { QSL("code128"), BARCODE_CODE128B, 60 }, - { QSL(""), -1, 61 }, - { QSL(""), -1, 62 }, - { QSL("auspost"), BARCODE_AUSPOST, 63 }, - { QSL(""), -1, 64 }, - { QSL(""), -1, 65 }, - { QSL("ausreply"), BARCODE_AUSREPLY, 66 }, - { QSL("ausroute"), BARCODE_AUSROUTE, 67 }, - { QSL("ausredirect"), BARCODE_AUSREDIRECT, 68 }, - { QSL("isbnx"), BARCODE_ISBNX, 69 }, - { QSL("rm4scc"), BARCODE_RM4SCC, 70 }, - { QSL("datamatrix"), BARCODE_DATAMATRIX, 71 }, - { QSL("ean14"), BARCODE_EAN14, 72 }, - { QSL("vin"), BARCODE_VIN, 73 }, - { QSL("codablockf"), BARCODE_CODABLOCKF, 74 }, - { QSL("nve18"), BARCODE_NVE18, 75 }, - { QSL("japanpost"), BARCODE_JAPANPOST, 76 }, - { QSL("koreapost"), BARCODE_KOREAPOST, 77 }, - { QSL(""), -1, 78 }, - { QSL("dbar_stk"), BARCODE_DBAR_STK, 79 }, - { QSL("dbar_omnstk"), BARCODE_DBAR_OMNSTK, 80 }, - { QSL("dbar_expstk"), BARCODE_DBAR_EXPSTK, 81 }, - { QSL("planet"), BARCODE_PLANET, 82 }, - { QSL(""), -1, 83 }, - { QSL("micropdf417"), BARCODE_MICROPDF417, 84 }, - { QSL("usps_imail"), BARCODE_USPS_IMAIL, 85 }, - { QSL("plessey"), BARCODE_PLESSEY, 86 }, - { QSL("telepen_num"), BARCODE_TELEPEN_NUM, 87 }, - { QSL(""), -1, 88 }, - { QSL("itf14"), BARCODE_ITF14, 89 }, - { QSL("kix"), BARCODE_KIX, 90 }, - { QSL(""), -1, 91 }, - { QSL("aztec"), BARCODE_AZTEC, 92 }, - { QSL("daft"), BARCODE_DAFT, 93 }, - { QSL(""), -1, 94 }, - { QSL(""), -1, 95 }, - { QSL("dpd"), BARCODE_DPD, 96 }, - { QSL("microqr"), BARCODE_MICROQR, 97 }, - { QSL("code128"), BARCODE_HIBC_128, 98 }, - { QSL("code39"), BARCODE_HIBC_39, 99 }, - { QSL(""), -1, 100 }, - { QSL(""), -1, 101 }, - { QSL("datamatrix"), BARCODE_HIBC_DM, 102 }, - { QSL(""), -1, 103 }, - { QSL("qrcode"), BARCODE_HIBC_QR, 104 }, - { QSL(""), -1, 105 }, - { QSL("pdf417"), BARCODE_HIBC_PDF, 106 }, - { QSL(""), -1, 107 }, - { QSL("micropdf417"), BARCODE_HIBC_MICPDF, 108 }, - { QSL(""), -1, 109 }, - { QSL("codablockf"), BARCODE_HIBC_BLOCKF, 110 }, - { QSL(""), -1, 111 }, - { QSL("aztec"), BARCODE_HIBC_AZTEC, 112 }, - { QSL(""), -1, 113 }, - { QSL(""), -1, 114 }, - { QSL("dotcode"), BARCODE_DOTCODE, 115 }, - { QSL("hanxin"), BARCODE_HANXIN, 116 }, - { QSL(""), -1, 117 }, - { QSL(""), -1, 118 }, - { QSL(""), -1, 119 }, - { QSL(""), -1, 120 }, - { QSL("mailmark"), BARCODE_MAILMARK, 121 }, - { QSL(""), -1, 122 }, - { QSL(""), -1, 123 }, - { QSL(""), -1, 124 }, - { QSL(""), -1, 125 }, - { QSL(""), -1, 126 }, - { QSL(""), -1, 127 }, - { QSL("azrune"), BARCODE_AZRUNE, 128 }, - { QSL("code32"), BARCODE_CODE32, 129 }, - { QSL("eanx"), BARCODE_EANX_CC, 130 }, - { QSL("code128"), BARCODE_GS1_128_CC, 131 }, - { QSL("dbar_omn"), BARCODE_DBAR_OMN_CC, 132 }, - { QSL("dbar_ltd"), BARCODE_DBAR_LTD_CC, 133 }, - { QSL("dbar_exp"), BARCODE_DBAR_EXP_CC, 134 }, - { QSL("upca"), BARCODE_UPCA_CC, 135 }, - { QSL("upce"), BARCODE_UPCE_CC, 136 }, - { QSL("dbar_stk"), BARCODE_DBAR_STK_CC, 137 }, - { QSL("dbar_omnstk"), BARCODE_DBAR_OMNSTK_CC, 138 }, - { QSL("dbar_expstk"), BARCODE_DBAR_EXPSTK_CC, 139 }, - { QSL("channel"), BARCODE_CHANNEL, 140 }, - { QSL("codeone"), BARCODE_CODEONE, 141 }, - { QSL("gridmatrix"), BARCODE_GRIDMATRIX, 142 }, - { QSL("upnqr"), BARCODE_UPNQR, 143 }, - { QSL("ultra"), BARCODE_ULTRA, 144 }, - { QSL("rmqr"), BARCODE_RMQR, 145 }, - }; - static const int data_size = sizeof(ndata) / sizeof(struct item); - - if (symbology < 0 || symbology >= data_size) { - return ndata[0].name; // "" + char name_buf[32]; + switch (symbology) { + case BARCODE_CODE128B: + case BARCODE_GS1_128: + case BARCODE_GS1_128_CC: + case BARCODE_HIBC_128: + symbology = BARCODE_CODE128; + break; + case BARCODE_PDF417COMP: + case BARCODE_HIBC_PDF: + symbology = BARCODE_PDF417; + break; + case BARCODE_HIBC_MICPDF: + symbology = BARCODE_MICROPDF417; + break; + case BARCODE_HIBC_AZTEC: + symbology = BARCODE_AZTEC; + break; + case BARCODE_HIBC_39: + symbology = BARCODE_CODE39; + break; + case BARCODE_HIBC_BLOCKF: + symbology = BARCODE_CODABLOCKF; + break; + case BARCODE_HIBC_DM: + symbology = BARCODE_DATAMATRIX; + break; + case BARCODE_HIBC_QR: + symbology = BARCODE_QRCODE; + break; + case BARCODE_DBAR_EXPSTK_CC: + symbology = BARCODE_DBAR_EXPSTK; + break; + case BARCODE_UPCA_CHK: + case BARCODE_UPCA_CC: + symbology = BARCODE_UPCA; + break; + case BARCODE_EANX_CHK: + case BARCODE_EANX_CC: + symbology = BARCODE_EANX; + break; + case BARCODE_UPCE_CHK: + case BARCODE_UPCE_CC: + symbology = BARCODE_UPCE; + break; } - if (ndata[symbology].val != symbology || - (ndata[symbology].define != -1 && ndata[symbology].define != symbology)) { // Self-check - fprintf(stderr, "MainWindow::get_setting_name: ndata table out of sync (%d)\n", symbology); - return ndata[0].name; // "" + if (ZBarcode_BarcodeName(symbology, name_buf) != 0) { + return QSL(""); } - return ndata[symbology].name; + QString name(name_buf + 8); // Strip "BARCODE_" prefix + return name.toLower(); } /* Helper to return index of selected radio button in group, checking for NULL */ @@ -2752,7 +2670,7 @@ void MainWindow::set_spn_from_setting(QSettings &settings, const QString &settin /* Save settings for an individual symbol */ void MainWindow::save_sub_settings(QSettings &settings, int symbology) { - const QString &name = get_setting_name(symbology); + QString name = get_setting_name(symbology); if (!name.isEmpty()) { settings.setValue(QSL("studio/bc/%1/data").arg(name), txtData->text()); if (!grpComposite->isHidden()) { @@ -3020,6 +2938,10 @@ void MainWindow::save_sub_settings(QSettings &settings, int symbology) settings.setValue(QSL("studio/bc/maxicode/structapp_index"), get_cmb_index(QSL("cmbMaxiStructAppIndex"))); break; + case BARCODE_CHANNEL: + settings.setValue(QSL("studio/bc/channel/channel"), get_cmb_index(QSL("cmbChannel"))); + break; + case BARCODE_CODEONE: settings.setValue(QSL("studio/bc/codeone/size"), get_cmb_index(QSL("cmbC1Size"))); settings.setValue(QSL("studio/bc/codeone/encoding_mode"), get_rad_grp_index( @@ -3105,7 +3027,7 @@ void MainWindow::save_sub_settings(QSettings &settings, int symbology) /* Load settings for an individual symbol */ void MainWindow::load_sub_settings(QSettings &settings, int symbology) { - const QString &name = get_setting_name(symbology); + QString name = get_setting_name(symbology); if (!name.isEmpty()) { const QString &tdata = settings.value(QSL("studio/bc/%1/data").arg(name), QSL("")).toString(); if (!tdata.isEmpty()) { @@ -3391,6 +3313,10 @@ void MainWindow::load_sub_settings(QSettings &settings, int symbology) set_cmb_from_setting(settings, QSL("studio/bc/maxicode/structapp_index"), QSL("cmbMaxiStructAppIndex")); break; + case BARCODE_CHANNEL: + set_cmb_from_setting(settings, QSL("studio/bc/channel/channel"), QSL("cmbChannel")); + break; + case BARCODE_CODEONE: set_cmb_from_setting(settings, QSL("studio/bc/codeone/size"), QSL("cmbC1Size")); set_rad_from_setting(settings, QSL("studio/bc/codeone/encoding_mode"), diff --git a/frontend_qt/mainwindow.h b/frontend_qt/mainwindow.h index b5923f05..9742bc8b 100644 --- a/frontend_qt/mainwindow.h +++ b/frontend_qt/mainwindow.h @@ -69,8 +69,9 @@ public slots: void menu(); void reset_colours(); - int open_data_dialog(); - int open_sequence_dialog(); + void open_data_dialog(); + void open_sequence_dialog(); + void open_cli_dialog(); void copy_to_clipboard_bmp(); void copy_to_clipboard_emf(); @@ -118,7 +119,7 @@ protected: QWidget *get_widget(const QString &name); - const QString &get_setting_name(int symbology); + static QString get_setting_name(int symbology); int get_rad_grp_index(const QStringList &names); void set_rad_from_setting(QSettings &settings, const QString &setting, const QStringList &names, @@ -161,6 +162,7 @@ private: QAction *m_copyPNGAct; QAction *m_copySVGAct; QAction *m_copyTIFAct; + QAction *m_CLIAct; QAction *m_saveAsAct; QAction *m_aboutAct; QAction *m_helpAct; diff --git a/frontend_qt/res/check.svg b/frontend_qt/res/check.svg new file mode 100644 index 00000000..1c209899 --- /dev/null +++ b/frontend_qt/res/check.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend_qt/res/delete.svg b/frontend_qt/res/delete.svg new file mode 100644 index 00000000..8c6074b9 --- /dev/null +++ b/frontend_qt/res/delete.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend_qt/res/zint_black.ico b/frontend_qt/res/zint_black.ico new file mode 100644 index 0000000000000000000000000000000000000000..9f0ae7a2aa7714d8932816dd9be017426d324582 GIT binary patch literal 14134 zcmeI2ONbm*6o&6iOVS`t+KmhtodyxyIiO^l2!h~FUARnKiTEJ8@qwg|GDuctBcdz8 zl`D<95QNKdMF_E~Q<7ercc0eyn z7jrYGV=@2Y`ggGgQr6#}a%w{x_q?Mnzx%b-UQyyQ4ci(!(ALCR-b)qpU)I<&Vw)N+ zRLoCZ&=6m*!#aLj{4pc1A^IGg4`b)Wr^R?ohkwJf>e&*@u7URxc!Nm(cwJ)C=kvHf zEqQ+x&xi-bBCM(NH!+SYvWb01jOTVg`p)7YcwgM2;dAji918G~`sy?g#(BnhW1E_T zxG%Q<&=?wu>M&G4>j0lPCbl(HIsZ>M2ysl__G>Zo-20c>d?DhKkK-7;E0)!tH3^Dh z<394Uj*37X{95GKB>qj;Up%kdzbnsEB&)!U8som89$a(iKm&E4k894FjL(OA^|I*m z6}9Iz-WGUPO~fh}r``wl6<$eEUTXdhq`F;MlZ=UvI z{#ga)S@U?VMg3nohUGZE>eMr{>huQ}!uF;#g!qqisxe6-?7O&*&Jw@L&iVH-&Ic{PqDojP*$d zx*sjE=v^02i2Gn)MJoRl#){q$Pwyk%DXorEGIZ7U70tz~#a`&2Zw;uq!(=S#Ki?Wq zbBD=T)PKG;pym#fv8exiYe3B%CgcB7f4-0R;avI5;4m3YG`%nXCp+d?^E*sN6aD!2 z2@{EFqW`%*iI z@+Qv!))FwWEHC|BH`eMz)XqdLK9EP#YhYQ{Pu2Q5snf*$08Fg%jmP+{r4F~r0sVe| z#_?sgWl76^ODc-{C5s`pXuPcNp)9Vdd8}bh%aS$Gk1sH>Ol!WMn)2?sRjk7+a>&P* z9b1;{GqtJf=aVdk*s{Du{j81mve>F-S%VuQ=Uk`B~~k@$_syZ^WtgW9r|xF7hPAM$MF{or+%xeH?b zx_XLu@+hSl>#w;#S{`cQ{r%C6CT)x_NSCw`CTNh0TJt_4Ci_ I%lw@0U(6_H4gdfE literal 0 HcmV?d00001 diff --git a/frontend_qt/resources.qrc b/frontend_qt/resources.qrc index 3a77a2d3..2eacd923 100644 --- a/frontend_qt/resources.qrc +++ b/frontend_qt/resources.qrc @@ -32,7 +32,10 @@ grpUPCEAN.ui grpVIN.ui res/zint-qt.ico + res/zint_black.ico + res/check.svg res/copy.svg + res/delete.svg res/download.svg res/help-circle.svg res/menu.svg diff --git a/frontend_qt/sequencewindow.cpp b/frontend_qt/sequencewindow.cpp index b0f6af65..f5dac8d3 100644 --- a/frontend_qt/sequencewindow.cpp +++ b/frontend_qt/sequencewindow.cpp @@ -28,29 +28,36 @@ #include "sequencewindow.h" #include "exportwindow.h" -SequenceWindow::SequenceWindow() +// Shorthand +#define QSL QStringLiteral + +SequenceWindow::SequenceWindow(BarcodeItem *bc) : m_bc(bc) { setupUi(this); QSettings settings; #if QT_VERSION < 0x60000 settings.setIniCodec("UTF-8"); #endif - QValidator *intvalid = new QIntValidator(this); - linStartVal->setText(settings.value("studio/sequence/start_value", "1").toString()); - linEndVal->setText(settings.value("studio/sequence/end_value", "10").toString()); - linIncVal->setText(settings.value("studio/sequence/increment", "1").toString()); - linFormat->setText(settings.value("studio/sequence/format", "$$$$$$").toString()); + QByteArray geometry = settings.value(QSL("studio/sequence/window_geometry")).toByteArray(); + restoreGeometry(geometry); - linStartVal->setValidator(intvalid); - linEndVal->setValidator(intvalid); - linIncVal->setValidator(intvalid); - connect(btnClose, SIGNAL( clicked( bool )), SLOT(quit_now())); - connect(btnReset, SIGNAL( clicked( bool )), SLOT(reset_preview())); - connect(btnCreate, SIGNAL( clicked( bool )), SLOT(create_sequence())); - connect(txtPreview, SIGNAL( textChanged()), SLOT(check_generate())); - connect(btnImport, SIGNAL( clicked( bool )), SLOT(import())); - connect(btnExport, SIGNAL( clicked( bool )), SLOT(generate_sequence())); + spnSeqStartVal->setValue(settings.value(QSL("studio/sequence/start_value"), 1).toInt()); + spnSeqEndVal->setValue(settings.value(QSL("studio/sequence/end_value"), 10).toInt()); + spnSeqIncVal->setValue(settings.value(QSL("studio/sequence/increment"), 1).toInt()); + linSeqFormat->setText(settings.value(QSL("studio/sequence/format"), QSL("$$$$$$")).toString()); + + QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg")))); + QIcon clearIcon(QIcon::fromTheme(QSL("edit-clear"), QIcon(QSL(":res/delete.svg")))); + btnSeqClose->setIcon(closeIcon); + btnSeqClear->setIcon(clearIcon); + + connect(btnSeqClose, SIGNAL( clicked( bool )), SLOT(close())); + connect(btnSeqClear, SIGNAL( clicked( bool )), SLOT(clear_preview())); + connect(btnSeqCreate, SIGNAL( clicked( bool )), SLOT(create_sequence())); + connect(txtSeqPreview, SIGNAL( textChanged()), SLOT(check_generate())); + connect(btnSeqImport, SIGNAL( clicked( bool )), SLOT(import())); + connect(btnSeqExport, SIGNAL( clicked( bool )), SLOT(generate_sequence())); } SequenceWindow::~SequenceWindow() @@ -59,40 +66,36 @@ SequenceWindow::~SequenceWindow() #if QT_VERSION < 0x60000 settings.setIniCodec("UTF-8"); #endif + settings.setValue(QSL("studio/sequence/window_geometry"), saveGeometry()); - settings.setValue("studio/sequence/start_value", linStartVal->text()); - settings.setValue("studio/sequence/end_value", linEndVal->text()); - settings.setValue("studio/sequence/increment", linIncVal->text()); - settings.setValue("studio/sequence/format", linFormat->text()); + settings.setValue(QSL("studio/sequence/start_value"), spnSeqStartVal->value()); + settings.setValue(QSL("studio/sequence/end_value"), spnSeqEndVal->value()); + settings.setValue(QSL("studio/sequence/increment"), spnSeqIncVal->value()); + settings.setValue(QSL("studio/sequence/format"), linSeqFormat->text()); } -void SequenceWindow::quit_now() +void SequenceWindow::clear_preview() { - close(); + txtSeqPreview->clear(); } -void SequenceWindow::reset_preview() -{ - txtPreview->clear(); -} - -QString SequenceWindow::apply_format(QString raw_number) +QString SequenceWindow::apply_format(const QString& raw_number) { QString adjusted, reversed; QString format; int format_len, input_len, i, inpos; QChar format_qchar; - format = linFormat->text(); + format = linSeqFormat->text(); input_len = raw_number.length(); format_len = format.length(); inpos = input_len; - for(i = format_len; i > 0; i--) { + for (i = format_len; i > 0; i--) { format_qchar = format[i - 1]; char format_char = format_qchar.toLatin1(); - switch(format_char) { + switch (format_char) { case '#': if (inpos > 0) { adjusted += raw_number[inpos - 1]; @@ -132,42 +135,41 @@ QString SequenceWindow::apply_format(QString raw_number) void SequenceWindow::create_sequence() { - QString startval, endval, incval, part, outputtext; + QStringList outputtext; int start, stop, step, i; - bool ok; - startval = linStartVal->text(); - endval = linEndVal->text(); - incval = linIncVal->text(); - start = startval.toInt(&ok, 10); - stop = endval.toInt(&ok, 10); - step = incval.toInt(&ok, 10); + start = spnSeqStartVal->value(); + stop = spnSeqEndVal->value(); + step = spnSeqIncVal->value(); - if((stop <= start) || (step <= 0)) { - QMessageBox::critical(this, tr("Sequence Error"), tr("One or more of the input values is incorrect.")); + if (stop < start) { + QMessageBox::critical(this, tr("Sequence Error"), + tr("End Value must be greater than or equal to Start Value.")); + return; + } + if ((stop - start) / step > 10000) { + QMessageBox::critical(this, tr("Sequence Error"), tr("The maximum sequence allowed is 10,000 items.")); return; } - for(i = start; i <= stop; i += step) { - part = apply_format(QString::number(i, 10)); - part += '\n'; - outputtext += part; + for (i = start; i <= stop; i += step) { + outputtext << apply_format(QString::number(i, 10)); } - txtPreview->setPlainText(outputtext); + txtSeqPreview->setPlainText(outputtext.join('\n')); } void SequenceWindow::check_generate() { QString preview_copy; - preview_copy = txtPreview->toPlainText(); - if(preview_copy.isEmpty()) { - btnExport->setEnabled(false); - lblExport->setEnabled(false); + preview_copy = txtSeqPreview->toPlainText(); + if (preview_copy.isEmpty()) { + btnSeqExport->setEnabled(false); + lblSeqExport->setEnabled(false); } else { - btnExport->setEnabled(true); - lblExport->setEnabled(true); + btnSeqExport->setEnabled(true); + lblSeqExport->setEnabled(true); } } @@ -182,8 +184,8 @@ void SequenceWindow::import() QFile file; QByteArray outstream; - import_dialog.setWindowTitle("Import File"); - import_dialog.setDirectory(settings.value("studio/default_dir", + import_dialog.setWindowTitle(tr("Import File")); + import_dialog.setDirectory(settings.value(QSL("studio/default_dir"), QDir::toNativeSeparators(QDir::homePath())).toString()); if (import_dialog.exec()) { @@ -193,23 +195,21 @@ void SequenceWindow::import() } file.setFileName(filename); - if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file.")); return; } outstream = file.readAll(); - txtPreview->setPlainText(QString(outstream)); + txtSeqPreview->setPlainText(QString(outstream)); file.close(); - settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator()))); + settings.setValue(QSL("studio/default_dir"), filename.mid(0, filename.lastIndexOf(QDir::separator()))); } void SequenceWindow::generate_sequence() { - ExportWindow dlg; - dlg.barcode = barcode; - dlg.output_data = txtPreview->toPlainText(); + ExportWindow dlg(m_bc, txtSeqPreview->toPlainText()); dlg.exec(); } diff --git a/frontend_qt/sequencewindow.h b/frontend_qt/sequencewindow.h index 153bd447..4d28ddc1 100644 --- a/frontend_qt/sequencewindow.h +++ b/frontend_qt/sequencewindow.h @@ -1,6 +1,6 @@ /* Zint Barcode Generator - the open source barcode generator - Copyright (C) 2009-2017 Robin Stuart + Copyright (C) 2009-2021 Robin Stuart This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* vim: set ts=4 sw=4 et : */ #ifndef SEQUENCEWINDOW_H #define SEQUENCEWINDOW_H @@ -25,23 +26,24 @@ class SequenceWindow : public QDialog, private Ui::SequenceDialog { - Q_OBJECT + Q_OBJECT public: - SequenceWindow(); - ~SequenceWindow(); - BarcodeItem *barcode; + SequenceWindow(BarcodeItem *bc); + ~SequenceWindow(); private: - QString apply_format(QString raw_number); + QString apply_format(const QString &raw_number); private slots: - void quit_now(); - void reset_preview(); - void create_sequence(); - void check_generate(); - void import(); - void generate_sequence(); + void clear_preview(); + void create_sequence(); + void check_generate(); + void import(); + void generate_sequence(); + +protected: + BarcodeItem *m_bc; }; #endif