Add text_length (length of text) to zint_symbol, and new

`BARCODE_PLAIN_HRT` option for `output_options` - for use
  primarily by ZXing-C++ but may be generally useful;
  centralize setting of HRT using new common `hrt_cpy_nochk()` etc.
  routines to ensure `text_length` always set
PLESSEY: add show default check characters option
CODE32: ignore `option_2` (check digit options)
PZN: ignore `option_2` (check digit options) except when indicates
  PZN7 only
DPD: exclude DEL from ident tag also
out_maybe_mkdir: fix `utf8_to_wide()` return (Windows only)
general: replace use of `strcpy()` etc. (except for test suite)
  with `memcpy()`, `hrt_()` etc. in lib & `cpy_str()` etc. in CLI
  & `cpy_bytearray_left()` in backend_qt
clang-tidy: update README reflecting above
backend_tcl: use sizeof(primary) to check length; tabs -> spaces
general: various code fiddling
docs: pandoc 3.6.2 -> 3.6.3
This commit is contained in:
gitlost 2025-02-15 20:32:55 +00:00
parent ddedd00d2d
commit fef8b083b4
82 changed files with 2873 additions and 1671 deletions

View file

@ -1,7 +1,7 @@
/***************************************************************************
* Copyright (C) 2008 by BogDan Vatra *
* bogdan@licentia.eu *
* Copyright (C) 2010-2024 Robin Stuart *
* Copyright (C) 2010-2025 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 *
@ -35,6 +35,8 @@
#include "../backend/fonts/normal_ttf.h" /* Arimo */
#include "../backend/fonts/upcean_ttf.h" /* OCR-B subset (digits, "<", ">") */
#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
// Shorthand
#define QSL QStringLiteral
#define QSEmpty QLatin1String("")
@ -75,6 +77,12 @@ namespace Zint {
return upceanFontID;
}
/* Helper to copy byte array up to max `max` into `buf` which must be NUL filled & at least `max` size */
static void cpy_bytearray_left(char *buf, const QByteArray &ba, const int max) {
QByteArray left = ba.left(max);
memcpy(buf, left, left.size());
}
/* Helper to convert QColor to RGB(A) hex string */
static QString qcolor_to_str(const QColor &color) {
if (color.alpha() == 0xFF) {
@ -253,9 +261,9 @@ namespace Zint {
if (m_embed_vector_font) {
m_zintSymbol->output_options |= EMBED_VECTOR_FONT;
}
strcpy(m_zintSymbol->fgcolour, m_fgStr.toLatin1().left(15));
strcpy(m_zintSymbol->bgcolour, m_bgStr.toLatin1().left(15));
strcpy(m_zintSymbol->primary, m_primaryMessage.toLatin1().left(127));
cpy_bytearray_left(m_zintSymbol->fgcolour, m_fgStr.toLatin1(), ARRAY_SIZE(m_zintSymbol->fgcolour) - 1);
cpy_bytearray_left(m_zintSymbol->bgcolour, m_bgStr.toLatin1(), ARRAY_SIZE(m_zintSymbol->fgcolour) - 1);
cpy_bytearray_left(m_zintSymbol->primary, m_primaryMessage.toLatin1(), ARRAY_SIZE(m_zintSymbol->primary) - 1);
m_zintSymbol->option_1 = m_option_1;
m_zintSymbol->option_2 = m_option_2;
m_zintSymbol->option_3 = m_option_3;
@ -466,15 +474,8 @@ namespace Zint {
m_structapp.index = index;
memset(m_structapp.id, 0, sizeof(m_structapp.id));
if (!id.isEmpty()) {
QByteArray idArr = id.toLatin1();
#if defined(__GNUC__) && __GNUC__ >= 8 && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif
strncpy(m_structapp.id, idArr, sizeof(m_structapp.id));
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
/* Note may not have NUL terminator */
cpy_bytearray_left(m_structapp.id, id.toLatin1(), ARRAY_SIZE(m_structapp.id));
}
} else {
clearStructApp();
@ -906,7 +907,7 @@ namespace Zint {
bool QZint::save_to_file(const QString& filename) {
if (resetSymbol()) {
strcpy(m_zintSymbol->outfile, filename.toUtf8().left(255));
cpy_bytearray_left(m_zintSymbol->outfile, filename.toUtf8(), ARRAY_SIZE(m_zintSymbol->outfile) - 1);
if (m_segs.empty()) {
QByteArray bstr = m_text.toUtf8();
m_error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char *) bstr.data(), bstr.length(),