diff --git a/ChangeLog b/ChangeLog index cffc45b6..3efb7bf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,8 @@ Bugs <= 200 - BMP/EMF/PCX/TIF: fix endianness on big-endian machines (note TIF now always written as little-endian - simplifies testing) +- ITF14/DPLEIT/DPIDENT: ignore `option_2` (check digit options) +- GUI: scalewindow: fix cropping of initial resolution and bound X-dim <= 10 Version 2.13.0 (2023-12-18) diff --git a/backend/2of5.c b/backend/2of5.c index 7026c63e..7879dd94 100644 --- a/backend/2of5.c +++ b/backend/2of5.c @@ -70,7 +70,7 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[], char dest[818]; /* Largest destination 4 + (80 + 1) * 10 + 3 + 1 = 818 */ char *d = dest; unsigned char temp[113 + 1 + 1]; /* Largest maximum 113 + optional check digit */ - int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2; + const int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2; if (length > max) { /* errtxt 301: 303: 305: 307: */ @@ -147,12 +147,12 @@ INTERNAL int c25logic(struct zint_symbol *symbol, unsigned char source[], int le /* Common to Interleaved, ITF-14, DP Leitcode, DP Identcode */ static int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length, - const int dont_set_height) { + const int checkdigit_option, const int dont_set_height) { int i, j, error_number = 0; char dest[638]; /* 4 + (125 + 1) * 5 + 3 + 1 = 638 */ char *d = dest; unsigned char temp[125 + 1 + 1]; - int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2; + const int have_checkdigit = checkdigit_option == 1 || checkdigit_option == 2; if (length > 125) { /* 4 + (125 + 1) * 9 + 5 = 1143 */ strcpy(symbol->errtxt, "309: Input too long (125 character maximum)"); @@ -202,7 +202,7 @@ static int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], expand(symbol, dest, d - dest); ustrcpy(symbol->text, temp); - if (symbol->option_2 == 2) { + if (checkdigit_option == 2) { /* Remove check digit from HRT */ symbol->text[length - 1] = '\0'; } @@ -231,7 +231,7 @@ static int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], /* Code 2 of 5 Interleaved ISO/IEC 16390:2007 */ INTERNAL int c25inter(struct zint_symbol *symbol, unsigned char source[], int length) { - return c25_inter_common(symbol, source, length, 0 /*dont_set_height*/); + return c25_inter_common(symbol, source, length, symbol->option_2 /*checkdigit_option*/, 0 /*dont_set_height*/); } /* Interleaved 2-of-5 (ITF-14) */ @@ -259,7 +259,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt /* Calculate the check digit - the same method used for EAN-13 */ localstr[13] = gs1_check_digit(localstr, 13); localstr[14] = '\0'; - error_number = c25_inter_common(symbol, localstr, 14, 1 /*dont_set_height*/); + error_number = c25_inter_common(symbol, localstr, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); ustrcpy(symbol->text, localstr); if (error_number < ZINT_ERROR) { @@ -320,7 +320,7 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng } localstr[13] = c25_check_digit(count); localstr[14] = '\0'; - error_number = c25_inter_common(symbol, localstr, 14, 1 /*dont_set_height*/); + error_number = c25_inter_common(symbol, localstr, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); /* HRT formatting as per DIALOGPOST SCHWER brochure but TEC-IT differs as do examples at https://www.philaseiten.de/cgi-bin/index.pl?ST=8615&CP=0&F=1#M147 */ @@ -368,7 +368,7 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len } localstr[11] = c25_check_digit(count); localstr[12] = '\0'; - error_number = c25_inter_common(symbol, localstr, 12, 1 /*dont_set_height*/); + error_number = c25_inter_common(symbol, localstr, 12, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); /* HRT formatting as per DIALOGPOST SCHWER brochure but TEC-IT differs as do other examples (see above) */ for (i = 0, j = 0; i <= 12; i++) { diff --git a/backend/tests/test_2of5.c b/backend/tests/test_2of5.c index 14775554..1c9e882f 100644 --- a/backend/tests/test_2of5.c +++ b/backend/tests/test_2of5.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020-2023 Robin Stuart + Copyright (C) 2020-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -282,31 +282,40 @@ static void test_encode(const testCtx *const p_ctx) { /* 15*/ { BARCODE_DPLEIT, -1, "0000087654321", 0, 1, 135, "Deutsche Post Leitcode; verified manually against tec-it", "101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101" }, - /* 16*/ { BARCODE_DPLEIT, -1, "2045703000360", 0, 1, 135, "Deutsche Post DIALOGPOST SCHWER brochure 3.1 example", + /* 16*/ { BARCODE_DPLEIT, 1, "0000087654321", 0, 1, 135, "Check digit option ignored", + "101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101" + }, + /* 17*/ { BARCODE_DPLEIT, -1, "2045703000360", 0, 1, 135, "Deutsche Post DIALOGPOST SCHWER brochure 3.1 example", "101010111010001000111010001011100010111010101000111000111011101110100010001010101110001110001011101110001000101010001011100011101011101" }, - /* 17*/ { BARCODE_DPLEIT, -1, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example", + /* 18*/ { BARCODE_DPLEIT, -1, "5082300702800", 0, 1, 135, "Deutsche Post Leitcode https://de.wikipedia.org/wiki/Leitcode example", "101011101011100010001011101000101110100011101110100010001010101110111000100010100011101110100011101010001110001010001011100011101011101" }, - /* 18*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it (HRT differently formatted)", + /* 19*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Deutsche Post Identcode; verified manually against tec-it (HRT differently formatted)", "101010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101" }, - /* 19*/ { BARCODE_DPIDENT, -1, "80420000001", 0, 1, 117, "Deutsche Post DIALOGPOST SCHWER brochure 3.1 example", + /* 20*/ { BARCODE_DPIDENT, -1, "00087654321", 0, 1, 117, "Check digit option ignored", + "101010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000100010111011101" + }, + /* 21*/ { BARCODE_DPIDENT, -1, "80420000001", 0, 1, 117, "Deutsche Post DIALOGPOST SCHWER brochure 3.1 example", "101011101010001110001010100011101011100010101110001110001010101110001110001010101110001110001011101010001000111011101" }, - /* 20*/ { BARCODE_DPIDENT, -1, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example", + /* 22*/ { BARCODE_DPIDENT, -1, "39601313414", 0, 1, 117, "Deutsche Post Identcode https://de.wikipedia.org/wiki/Leitcode example", "101011101110001010001010111011100010001011100010001010111011100010001010111010001011101011100010101110001000111011101" }, - /* 21*/ { BARCODE_ITF14, -1, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it", + /* 23*/ { BARCODE_ITF14, -1, "0000087654321", 0, 1, 135, "ITF-14; verified manually against tec-it", "101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101" }, - /* 22*/ { BARCODE_ITF14, -1, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2", + /* 24*/ { BARCODE_ITF14, 1, "0000087654321", 0, 1, 135, "Check digit option ignored", + "101010101110001110001010101110001110001010001011101110001010100010001110111011101011100010100011101110001010100011101000101011100011101" + }, + /* 25*/ { BARCODE_ITF14, -1, "0950110153000", 0, 1, 135, "GS1 General Specifications Figure 5.1-2", "101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001010001000111011101011101" }, - /* 23*/ { BARCODE_ITF14, -1, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1", + /* 26*/ { BARCODE_ITF14, -1, "1540014128876", 0, 1, 135, "GS1 General Specifications Figure 5.3.2.4-1", "101011100010100010111010101110001000111010001011101110100010001011101011100010001110101000111011101010111000100010001110001110101011101" }, - /* 24*/ { BARCODE_ITF14, -1, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1", + /* 27*/ { BARCODE_ITF14, -1, "0950110153001", 0, 1, 135, "GS1 General Specifications Figure 5.3.6-1", "101010100011101110001011101011100010001011100010101011100010001011101110100011100010001110101010101110001110001011101010001000111011101" }, }; diff --git a/backend/tests/tools/bwipp_dump.ps.tar.xz b/backend/tests/tools/bwipp_dump.ps.tar.xz index 512bd5e9..c5b0a300 100644 Binary files a/backend/tests/tools/bwipp_dump.ps.tar.xz and b/backend/tests/tools/bwipp_dump.ps.tar.xz differ diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 4e961bf8..1752306b 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -91,19 +91,19 @@ namespace Zint { int comma1 = text.indexOf(','); int comma2 = text.indexOf(',', comma1 + 1); int comma3 = text.indexOf(',', comma2 + 1); - int black = 100 - text.midRef(comma3 + 1).toInt(); - int val = 100 - text.midRef(0, comma1).toInt(); + int black = 100 - text.mid(comma3 + 1).toInt(); + int val = 100 - text.mid(0, comma1).toInt(); r = (int) roundf((0xFF * val * black) / 10000.0f); - val = 100 - text.midRef(comma1 + 1, comma2 - comma1 - 1).toInt(); + val = 100 - text.mid(comma1 + 1, comma2 - comma1 - 1).toInt(); g = (int) roundf((0xFF * val * black) / 10000.0f); - val = 100 - text.midRef(comma2 + 1, comma3 - comma2 - 1).toInt(); + val = 100 - text.mid(comma2 + 1, comma3 - comma2 - 1).toInt(); b = (int) roundf((0xFF * val * black) / 10000.0f); a = 0xFF; } else { - r = text.midRef(0, 2).toInt(nullptr, 16); - g = text.midRef(2, 2).toInt(nullptr, 16); - b = text.midRef(4, 2).toInt(nullptr, 16); - a = text.length() == 8 ? text.midRef(6, 2).toInt(nullptr, 16) : 0xFF; + r = text.mid(0, 2).toInt(nullptr, 16); + g = text.mid(2, 2).toInt(nullptr, 16); + b = text.mid(4, 2).toInt(nullptr, 16); + a = text.length() == 8 ? text.mid(6, 2).toInt(nullptr, 16) : 0xFF; } color.setRgb(r, g, b, a); return color; diff --git a/backend_qt/qzint.h b/backend_qt/qzint.h index aeadea44..20e4f0d8 100644 --- a/backend_qt/qzint.h +++ b/backend_qt/qzint.h @@ -24,6 +24,7 @@ #ifndef QZINT_H #define QZINT_H +#include #include #include #include "zint.h" diff --git a/frontend_qt/datawindow.cpp b/frontend_qt/datawindow.cpp index 624f6efc..bb6056ca 100644 --- a/frontend_qt/datawindow.cpp +++ b/frontend_qt/datawindow.cpp @@ -67,7 +67,7 @@ DataWindow::DataWindow(const QString &input, bool isEscaped, int seg_no) : Valid lastPosn = match.capturedEnd(0); } } - out += input.midRef(lastPosn); + out += input.mid(lastPosn); txtDataInput->setPlainText(out); statusBarData->showMessage(tr("Converted LFs"), tempMessageTimeout); } else { diff --git a/frontend_qt/extScale.ui b/frontend_qt/extScale.ui index 83a56898..d073b4b0 100644 --- a/frontend_qt/extScale.ui +++ b/frontend_qt/extScale.ui @@ -140,7 +140,7 @@ - 1000 + 25400 1 diff --git a/frontend_qt/mainwindow.cpp b/frontend_qt/mainwindow.cpp index b6aa4773..fde08e0a 100644 --- a/frontend_qt/mainwindow.cpp +++ b/frontend_qt/mainwindow.cpp @@ -89,19 +89,19 @@ static QColor str_to_qcolor(const QString &str) int comma1 = str.indexOf(','); int comma2 = str.indexOf(',', comma1 + 1); int comma3 = str.indexOf(',', comma2 + 1); - int black = 100 - str.midRef(comma3 + 1).toInt(); - int val = 100 - str.midRef(0, comma1).toInt(); + int black = 100 - str.mid(comma3 + 1).toInt(); + int val = 100 - str.mid(0, comma1).toInt(); r = (int) roundf((0xFF * val * black) / 10000.0f); - val = 100 - str.midRef(comma1 + 1, comma2 - comma1 - 1).toInt(); + val = 100 - str.mid(comma1 + 1, comma2 - comma1 - 1).toInt(); g = (int) roundf((0xFF * val * black) / 10000.0f); - val = 100 - str.midRef(comma2 + 1, comma3 - comma2 - 1).toInt(); + val = 100 - str.mid(comma2 + 1, comma3 - comma2 - 1).toInt(); b = (int) roundf((0xFF * val * black) / 10000.0f); a = 0xFF; } else { - r = str.midRef(0, 2).toInt(nullptr, 16); - g = str.midRef(2, 2).toInt(nullptr, 16); - b = str.midRef(4, 2).toInt(nullptr, 16); - a = str.length() == 8 ? str.midRef(6, 2).toInt(nullptr, 16) : 0xFF; + r = str.mid(0, 2).toInt(nullptr, 16); + g = str.mid(2, 2).toInt(nullptr, 16); + b = str.mid(4, 2).toInt(nullptr, 16); + a = str.length() == 8 ? str.mid(6, 2).toInt(nullptr, 16) : 0xFF; } color.setRgb(r, g, b, a); return color; @@ -546,12 +546,15 @@ void MainWindow::load_settings(QSettings &settings) chkDotty->setChecked(settings.value(QSL("studio/appearance/chk_dotty"), 0).toInt() ? true : false); spnDotSize->setValue(settings.value(QSL("studio/appearance/dot_size"), 4.0 / 5.0).toFloat()); // These are "system-wide" - m_xdimdpVars.resolution_units = settings.value(QSL("studio/xdimdpvars/resolution_units"), 0).toInt(); + m_xdimdpVars.resolution_units = std::max(std::min(settings.value(QSL("studio/xdimdpvars/resolution_units"), + 0).toInt(), 1), 0); const int defaultResolution = m_xdimdpVars.resolution_units == 1 ? 300 : 12; // 300dpi or 12dpmm - m_xdimdpVars.resolution = settings.value(QSL("studio/xdimdpvars/resolution"), defaultResolution).toInt(); + const int maxRes = m_xdimdpVars.resolution_units == 1 ? 25400 : 1000; + m_xdimdpVars.resolution = std::max(std::min(settings.value(QSL("studio/xdimdpvars/resolution"), + defaultResolution).toInt(), maxRes), 1); m_xdimdpVars.filetype = std::max(std::min(settings.value(QSL("studio/xdimdpvars/filetype"), 0).toInt(), 1), 0); - m_xdimdpVars.filetype_maxicode - = std::max(std::min(settings.value(QSL("studio/xdimdpvars/filetype_maxicode"), 0).toInt(), 2), 0); + m_xdimdpVars.filetype_maxicode = std::max(std::min(settings.value(QSL("studio/xdimdpvars/filetype_maxicode"), + 0).toInt(), 2), 0); } QString MainWindow::get_zint_version(void) @@ -1424,7 +1427,7 @@ void MainWindow::size_msg_ui_set() struct Zint::QZintXdimDpVars *vars = m_scaleWindow ? &m_scaleWindow->m_vars : &m_xdimdpVars; if (vars->x_dim == 0.0) { vars->x_dim_units = 0; - vars->x_dim = m_bc.bc.getXdimDpFromScale(scale, get_dpmm(vars), getFileType(vars)); + vars->x_dim = std::min(m_bc.bc.getXdimDpFromScale(scale, get_dpmm(vars), getFileType(vars)), 10.0f); } else { // Scale trumps stored X-dimension double x_dim_mm = vars->x_dim_units == 1 ? vars->x_dim * 25.4 : vars->x_dim; diff --git a/frontend_qt/scalewindow.cpp b/frontend_qt/scalewindow.cpp index 171fbcf5..4b7b22cf 100644 --- a/frontend_qt/scalewindow.cpp +++ b/frontend_qt/scalewindow.cpp @@ -150,7 +150,7 @@ void ScaleWindow::size_msg_ui_set() void ScaleWindow::unset_scale() { - m_vars.x_dim = m_bc->bc.getXdimDpFromScale(m_originalScale, get_dpmm(), getFileType()); + m_vars.x_dim = std::min(m_bc->bc.getXdimDpFromScale(m_originalScale, get_dpmm(), getFileType()), 10.0f); m_vars.set = 0; if (cmbXdimUnits->currentIndex() == 1) { // Inches @@ -252,7 +252,7 @@ const char *ScaleWindow::getFileType() const void ScaleWindow::set_maxima() { - float maxXdim = m_bc->bc.getXdimDpFromScale(200.0f, get_dpmm(), getFileType()); + float maxXdim = std::min(m_bc->bc.getXdimDpFromScale(200.0f, get_dpmm(), getFileType()), 10.0f); if (cmbXdimUnits->currentIndex() == 1) { // Inches spnXdim->setMaximum(maxXdim / 25.4); } else {