- ITF14/DPLEIT/DPIDENT: ignore option_2 (check digit options)

- GUI: scalewindow: fix cropping resolution on initial setup
  (`spnResolution` max 1000 -> 254000) and bound X-dim to <= 10 in
  `set_maxima()`
- GUI: mainwindow: bound X-dim as above and clamp `m_xdimdpVars`
  members on initial load from INI
- GUI: undo `QString::mid()` -> `QString::midRef()` from clazy
  & explicitly include "QObject" in "qzint.h" (not Qt6 compatible)
This commit is contained in:
gitlost 2024-01-25 00:10:34 +00:00
parent 7c1bdba8ae
commit 7b41dfbee2
10 changed files with 58 additions and 43 deletions

View File

@ -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)

View File

@ -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++) {

View File

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2020-2023 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020-2024 Robin Stuart <rstuart114@gmail.com>
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"
},
};

View File

@ -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;

View File

@ -24,6 +24,7 @@
#ifndef QZINT_H
#define QZINT_H
#include <QObject>
#include <QColor>
#include <QPainter>
#include "zint.h"

View File

@ -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 {

View File

@ -140,7 +140,7 @@
<string/>
</property>
<property name="maximum">
<number>1000</number>
<number>25400</number>
</property>
<property name="minimum">
<number>1</number>

View File

@ -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;

View File

@ -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 {