mirror of
https://git.code.sf.net/p/zint/code
synced 2026-07-31 18:39:52 +00:00
CLI: make --mirror available in standard non-batch mode via
new routines `mirror_start()`, `mirror_outfile()` & limit substitutions on Unix to backslash (Windows remains the same); restrict "borderwidth", "textgap", "vwhitesp", "whitesp" < 100 CODEONE: fix `ceilf()` -> `C1_MULT_CEIL()` in FAST_MODE encodation (improves/changes some encodation) composite: preserve `gs1_verify()` warning using `warn_level` hack; fix wrong name `zint_dbar_omnstk_set_height()` -> `zint_dbar_stk_set_height()`; use new `zint_micropdf_variant()` & `zint_micropdf_expand()` routines (see below) MICROPDF417: move variant determination into new shareable routine `zint_micropdf_variant()` & expansion into `zint_micropdf_expand()` qzint: add helper methods `setbordertypevalue()`, `encodedinputmode()`, `encodedoutputoptions()`, `ecivaluetoeciindex()` and `eciindextoecivalue()` dbar: for performance pre-calculate `combins()` as array coverage: add `malloc()`-type failure testing to AZTEC, CONTENT_SEGS, MEMORY_FILE, raster, Reed-Solomon & vector; numerous changes to remove unused code and test more branches common: add `isxdigit()` general: various code fiddlings manual: add char names to sequence and batch format char tables; mention long options can be shortened (& use "--compliantheight" -> "--compliant"); expand mirror explanation & document substitutions in footnote; workaround xecjk putting space after double quote when quoting cjk chars & rejig input mode examples; workaround html alignment bug in table gs1-enabled symbologies by adding extra rh dashes to header cols; add "figure nn: " to txt image tags via sed: various other small fixes and rephrasings
This commit is contained in:
+122
-73
@@ -125,25 +125,6 @@ namespace Zint {
|
||||
return color;
|
||||
}
|
||||
|
||||
/* Helper to convert ECI combo index to ECI value */
|
||||
static int ECIIndexToECI(const int ECIIndex) {
|
||||
int ret;
|
||||
if (ECIIndex >= 1 && ECIIndex <= 11) {
|
||||
ret = ECIIndex + 2;
|
||||
} else if (ECIIndex >= 12 && ECIIndex <= 15) {
|
||||
ret = ECIIndex + 3;
|
||||
} else if (ECIIndex >= 16 && ECIIndex <= 31) {
|
||||
ret = ECIIndex + 4;
|
||||
} else if (ECIIndex == 32) {
|
||||
ret = 170; /* ISO 646 Invariant */
|
||||
} else if (ECIIndex == 33) {
|
||||
ret = 899; /* 8-bit binary data */
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Helper to calculate max right and bottom of elements for fudging `render()` */
|
||||
static void getMaxRectsRightBottom(struct zint_vector *vector, int &maxRight, int &maxBottom) {
|
||||
struct zint_vector_rect *rect;
|
||||
@@ -184,7 +165,8 @@ namespace Zint {
|
||||
|
||||
/* Segment constructors */
|
||||
QZintSeg::QZintSeg() : m_eci(0) {}
|
||||
QZintSeg::QZintSeg(const QString& text, const int ECIIndex) : m_text(text), m_eci(ECIIndexToECI(ECIIndex)) {}
|
||||
QZintSeg::QZintSeg(const QString& text, const int ECIIndex)
|
||||
: m_text(text), m_eci(QZint::ECIIndexToECIValue(ECIIndex)) {}
|
||||
|
||||
QZint::QZint()
|
||||
: m_zintSymbol(nullptr), m_symbol(BARCODE_CODE128), m_input_mode(UNICODE_MODE),
|
||||
@@ -224,6 +206,7 @@ namespace Zint {
|
||||
ZBarcode_Delete(m_zintSymbol);
|
||||
}
|
||||
|
||||
/* private: Reset the symbol structure for encoding using member fields */
|
||||
bool QZint::resetSymbol() {
|
||||
m_error = 0;
|
||||
m_lastError.clear();
|
||||
@@ -302,6 +285,7 @@ namespace Zint {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* private: `ZBarcode_Encode_and_Buffer_Vector()` or `ZBarcode_Encode_Segs_and_Buffer_Vector()` */
|
||||
void QZint::encode() {
|
||||
if (resetSymbol()) {
|
||||
if (m_segs.empty()) {
|
||||
@@ -344,6 +328,49 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
/* private: Helper to convert `m_segs` to `struct zint_seg[]` */
|
||||
int QZint::convertSegs(struct zint_seg segs[], std::vector<QByteArray>& bstrs) {
|
||||
bstrs.reserve(m_segs.size());
|
||||
int i;
|
||||
for (i = 0; i < (int) m_segs.size() && i < maxSegs && !m_segs[i].m_text.isEmpty(); i++) {
|
||||
segs[i].eci = m_segs[i].m_eci;
|
||||
bstrs.push_back(m_segs[i].m_text.toUtf8());
|
||||
segs[i].source = (unsigned char *) bstrs.back().data();
|
||||
segs[i].length = (int) bstrs.back().length();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* private: static: Convert `zint_vector_rect->colour` to Qt color */
|
||||
Qt::GlobalColor QZint::colourToQtColor(int colour) {
|
||||
switch (colour) {
|
||||
case 1: // Cyan
|
||||
return Qt::cyan;
|
||||
break;
|
||||
case 2: // Blue
|
||||
return Qt::blue;
|
||||
break;
|
||||
case 3: // Magenta
|
||||
return Qt::magenta;
|
||||
break;
|
||||
case 4: // Red
|
||||
return Qt::red;
|
||||
break;
|
||||
case 5: // Yellow
|
||||
return Qt::yellow;
|
||||
break;
|
||||
case 6: // Green
|
||||
return Qt::green;
|
||||
break;
|
||||
case 8: // White
|
||||
return Qt::white;
|
||||
break;
|
||||
default:
|
||||
return Qt::black;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Symbology to use (see BARCODE_XXX) */
|
||||
int QZint::symbol() const {
|
||||
return m_symbol;
|
||||
@@ -577,6 +604,13 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setBorderTypeValue(int borderType) { // Sets literal value
|
||||
if (borderType != BARCODE_BIND && borderType != BARCODE_BOX && borderType != BARCODE_BIND_TOP) {
|
||||
borderType = 0;
|
||||
}
|
||||
m_borderType = borderType;
|
||||
}
|
||||
|
||||
/* Size of border in X-dimensions */
|
||||
int QZint::borderWidth() const {
|
||||
return m_borderWidth;
|
||||
@@ -721,7 +755,7 @@ namespace Zint {
|
||||
}
|
||||
|
||||
void QZint::setECI(int ECIIndex) { // Sets from comboBox index
|
||||
m_eci = ECIIndexToECI(ECIIndex);
|
||||
m_eci = ECIIndexToECIValue(ECIIndex);
|
||||
}
|
||||
|
||||
void QZint::setECIValue(int eci) { // Sets literal value
|
||||
@@ -849,6 +883,14 @@ namespace Zint {
|
||||
return m_encodedOption3;
|
||||
}
|
||||
|
||||
int QZint::encodedInputMode() const { // Read-only, `input_mode`
|
||||
return m_input_mode;
|
||||
}
|
||||
|
||||
int QZint::encodedOutputOptions() const { // Read-only, `output_options`
|
||||
return m_zintSymbol->output_options;
|
||||
}
|
||||
|
||||
/* Legacy property getters/setters */
|
||||
void QZint::setWidth(int width) { setOption2(width); }
|
||||
int QZint::width() const { return m_option_2; }
|
||||
@@ -941,7 +983,7 @@ namespace Zint {
|
||||
break;
|
||||
default:
|
||||
return (symbology >= BARCODE_EANX_CC && symbology <= BARCODE_DBAR_EXPSTK_CC)
|
||||
|| symbology == BARCODE_EAN8_CC || symbology == BARCODE_EAN13_CC;
|
||||
|| symbology == BARCODE_EAN8_CC || symbology == BARCODE_EAN13_CC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -961,6 +1003,7 @@ namespace Zint {
|
||||
return m_lastError.length();
|
||||
}
|
||||
|
||||
/* Encode and print barcode to file `filename`. Only sets `getError()` on error, not on warning */
|
||||
bool QZint::save_to_file(const QString& filename) {
|
||||
if (resetSymbol()) {
|
||||
cpy_bytearray_left(m_zintSymbol->outfile, filename.toUtf8(), ARRAY_SIZE(m_zintSymbol->outfile) - 1);
|
||||
@@ -985,6 +1028,8 @@ namespace Zint {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Encode and print barcode to memory file `filename` (only the extension is used, to determine output format).
|
||||
Only sets `getError()` on error, not on warning */
|
||||
bool QZint::save_to_memfile(const QString& filename, QByteArray& data) {
|
||||
if (resetSymbol()) {
|
||||
m_zintSymbol->output_options |= BARCODE_MEMORY_FILE;
|
||||
@@ -1012,49 +1057,6 @@ namespace Zint {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Convert `zint_vector_rect->colour` to Qt color */
|
||||
Qt::GlobalColor QZint::colourToQtColor(int colour) {
|
||||
switch (colour) {
|
||||
case 1: // Cyan
|
||||
return Qt::cyan;
|
||||
break;
|
||||
case 2: // Blue
|
||||
return Qt::blue;
|
||||
break;
|
||||
case 3: // Magenta
|
||||
return Qt::magenta;
|
||||
break;
|
||||
case 4: // Red
|
||||
return Qt::red;
|
||||
break;
|
||||
case 5: // Yellow
|
||||
return Qt::yellow;
|
||||
break;
|
||||
case 6: // Green
|
||||
return Qt::green;
|
||||
break;
|
||||
case 8: // White
|
||||
return Qt::white;
|
||||
break;
|
||||
default:
|
||||
return Qt::black;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper to convert `m_segs` to `struct zint_seg[]` */
|
||||
int QZint::convertSegs(struct zint_seg segs[], std::vector<QByteArray>& bstrs) {
|
||||
bstrs.reserve(m_segs.size());
|
||||
int i;
|
||||
for (i = 0; i < (int) m_segs.size() && i < maxSegs && !m_segs[i].m_text.isEmpty(); i++) {
|
||||
segs[i].eci = m_segs[i].m_eci;
|
||||
bstrs.push_back(m_segs[i].m_text.toUtf8());
|
||||
segs[i].source = (unsigned char *) bstrs.back().data();
|
||||
segs[i].length = (int) bstrs.back().length();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Encode and display barcode in `paintRect` using `painter`.
|
||||
Note: legacy argument `mode` is not used */
|
||||
void QZint::render(QPainter& painter, const QRectF& paintRect, AspectRatioMode /*mode*/) {
|
||||
@@ -1276,7 +1278,45 @@ namespace Zint {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Return the BARCODE_XXX name of `symbology` */
|
||||
/* static: Convert literal ECI to ECI combobox index */
|
||||
int QZint::ECIValueToECIIndex(const int eci) {
|
||||
int ret;
|
||||
if (eci >= 3 && eci <= 13) {
|
||||
ret = eci - 2;
|
||||
} else if (eci >= 15 && eci <= 18) {
|
||||
ret = eci - 3;
|
||||
} else if (eci >= 20 && eci <= 35) {
|
||||
ret = eci - 4;
|
||||
} else if (eci == 170) {
|
||||
ret = 32;
|
||||
} else if (eci == 899) {
|
||||
ret = 33;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* static: Convert ECI combo index to literal ECI */
|
||||
int QZint::ECIIndexToECIValue(const int ECIIndex) {
|
||||
int ret;
|
||||
if (ECIIndex >= 1 && ECIIndex <= 11) {
|
||||
ret = ECIIndex + 2;
|
||||
} else if (ECIIndex >= 12 && ECIIndex <= 15) {
|
||||
ret = ECIIndex + 3;
|
||||
} else if (ECIIndex >= 16 && ECIIndex <= 31) {
|
||||
ret = ECIIndex + 4;
|
||||
} else if (ECIIndex == 32) {
|
||||
ret = 170; /* ISO 646 Invariant */
|
||||
} else if (ECIIndex == 33) {
|
||||
ret = 899; /* 8-bit binary data */
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* static: Return the BARCODE_XXX name of `symbology` */
|
||||
QString QZint::barcodeName(const int symbology) {
|
||||
char buf[32];
|
||||
if (ZBarcode_BarcodeName(symbology, buf) == 0) {
|
||||
@@ -1285,17 +1325,17 @@ namespace Zint {
|
||||
return QSEmpty;
|
||||
}
|
||||
|
||||
/* Whether Zint library "libzint" built with PNG support or not */
|
||||
/* static: Whether Zint library "libzint" built with PNG support or not */
|
||||
bool QZint::noPng() {
|
||||
return ZBarcode_NoPng() == 1;
|
||||
}
|
||||
|
||||
/* Whether Zint library "libzint" built with PNG support or not */
|
||||
/* static: Whether Zint library "libzint" built with PNG support or not */
|
||||
bool QZint::haveGS1SyntaxEngine() {
|
||||
return ZBarcode_HaveGS1SyntaxEngine() == 1;
|
||||
}
|
||||
|
||||
/* Version of Zint library "libzint" linked to */
|
||||
/* static: Version of Zint library "libzint" linked to */
|
||||
int QZint::getVersion() {
|
||||
return ZBarcode_Version();
|
||||
}
|
||||
@@ -1545,7 +1585,7 @@ namespace Zint {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/* `getAsCLI()` helpers */
|
||||
/* private: static: `getAsCLI()` helpers */
|
||||
void QZint::arg_str(QString& cmd, const char *const opt, const QString& val) {
|
||||
if (!val.isEmpty()) {
|
||||
QByteArray bstr = val.toUtf8();
|
||||
@@ -1553,18 +1593,21 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
void QZint::arg_bool(QString& cmd, const char *const opt, const bool val) {
|
||||
if (val) {
|
||||
cmd += QString::asprintf(" %s", opt);
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
void QZint::arg_data(QString& cmd, const char *const opt, const QString& val, const bool win) {
|
||||
if (!val.isEmpty()) {
|
||||
QString text(val);
|
||||
@@ -1572,12 +1615,14 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
void QZint::arg_seg(QString& cmd, const int seg_no, const QZintSeg& val, const bool win) {
|
||||
QString text(val.m_text);
|
||||
QString opt = QString::asprintf("--seg%d=%d,", seg_no, val.m_eci);
|
||||
arg_data_esc(cmd, opt.toUtf8(), text, win);
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
void QZint::arg_data_esc(QString& cmd, const char *const opt, QString& text, const bool win) {
|
||||
const char delim = win ? '"' : '\'';
|
||||
if (win) {
|
||||
@@ -1594,12 +1639,14 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
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) {
|
||||
@@ -1613,6 +1660,7 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
/* private: static: */
|
||||
void QZint::arg_scalexdimdp(QString& cmd, const char *const opt, const float scale, const float dpmm,
|
||||
const int symbol, const QZintXdimDpVars *xdimdpVars) {
|
||||
if (dpmm) {
|
||||
@@ -1635,7 +1683,7 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper to return "GIF"/"SVG"(/"EMF") if `msg` false, "raster"/"vector"(/"EMF") otherwise
|
||||
/* static: Helper to return "GIF"/"SVG"(/"EMF") if `msg` false, "raster"/"vector"(/"EMF") otherwise
|
||||
(EMF only if `symbol` is MaxiCode) */
|
||||
const char *QZintXdimDpVars::getFileType(int symbol, const struct QZintXdimDpVars *vars, bool msg) {
|
||||
static const char *filetypes[3] = { "GIF", "SVG", "EMF" };
|
||||
@@ -1643,8 +1691,9 @@ namespace Zint {
|
||||
|
||||
if (!vars) return "";
|
||||
|
||||
const int idx = std::max(std::min(symbol == BARCODE_MAXICODE ? vars->filetype_maxicode
|
||||
: vars->filetype, 2), 0);
|
||||
const int filetype = symbol == BARCODE_MAXICODE ? vars->filetype_maxicode : vars->filetype;
|
||||
const int max = symbol == BARCODE_MAXICODE ? 2 : 1;
|
||||
const int idx = std::max(std::min(filetype, max), 0);
|
||||
return msg ? msg_types[idx] : filetypes[idx];
|
||||
}
|
||||
} /* namespace Zint */
|
||||
|
||||
Reference in New Issue
Block a user