1
0
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:
gitlost
2026-06-23 23:25:23 +01:00
parent 4a60a0b068
commit a81c9d9258
91 changed files with 6879 additions and 4368 deletions
+97 -34
View File
@@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2019-2025 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2019-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -109,31 +109,45 @@ static void test_large(const testCtx *const p_ctx) {
assert_nonnull(symbol, "Symbol not created\n");
testUtilStrCpyRepeat(data_buf, data[i].pattern, data[i].length);
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n", i, data[i].length, (int) strlen(data_buf));
assert_equal(data[i].length, (int) strlen(data_buf), "i:%d length %d != strlen(data_buf) %d\n",
i, data[i].length, (int) strlen(data_buf));
length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data_buf, data[i].length, debug);
length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1, -1 /*output_options*/,
data_buf, data[i].length, debug);
strcpy(symbol->primary, data[i].primary);
ret = ZBarcode_Encode(symbol, TCU(data_buf), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n", i, ret ? "set" : "empty", symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->errtxt[0] == '\0', ret == 0, "i:%d symbol->errtxt not %s (%s)\n",
i, ret ? "set" : "empty", symbol->errtxt);
if (ret < ZINT_ERROR) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n",
i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
} else {
assert_zero(strcmp(symbol->errtxt, expected_errtxt), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, expected_errtxt);
assert_zero(strcmp(symbol->errtxt, expected_errtxt), "i:%d strcmp(%s, %s) != 0\n",
i, symbol->errtxt, expected_errtxt);
}
if (ret < ZINT_ERROR) {
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
char modules_dump[33 * 33 + 1];
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1, "i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data_buf, length, symbol->primary, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
assert_notequal(testUtilModulesDump(symbol, modules_dump, sizeof(modules_dump)), -1,
"i:%d testUtilModulesDump == -1\n", i);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data_buf, length,
symbol->primary, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i,
testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, modules_dump);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
@@ -1220,14 +1234,17 @@ static void test_encode(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, data[i].input_mode, -1 /*eci*/,
data[i].option_1, data[i].option_2, -1, -1 /*output_options*/,
data[i].data, data[i].length, debug);
if (data[i].structapp.count) {
symbol->structapp = data[i].structapp;
}
strcpy(symbol->primary, data[i].primary);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, \"%s\", %d, \"%s\", %s, %d, %d, %d, %d, \"%s\",\n",
@@ -1242,22 +1259,31 @@ static void test_encode(const testCtx *const p_ctx) {
if (ret < ZINT_ERROR) {
int width, row;
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n",
i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n",
i, symbol->width, data[i].expected_width, data[i].data);
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, ret, width, row, data[i].data);
assert_zero(ret, "i:%d testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n",
i, ret, width, row, data[i].data);
if (do_bwipp && testUtilCanBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, debug)) {
if (!data[i].bwipp_cmp) {
if (debug & ZINT_DEBUG_TEST_PRINT) printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), data[i].comment);
if (debug & ZINT_DEBUG_TEST_PRINT) {
printf("i:%d %s not BWIPP compatible (%s)\n",
i, testUtilBarcodeName(symbol->symbology), data[i].comment);
}
} else {
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length, data[i].primary, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwipp(i, symbol, data[i].option_1, data[i].option_2, -1, data[i].data, length,
data[i].primary, cmp_buf, sizeof(cmp_buf), NULL);
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n",
i, testUtilBarcodeName(symbol->symbology), ret);
ret = testUtilBwippCmp(symbol, cmp_msg, cmp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf, data[i].expected);
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_buf,
data[i].expected);
}
}
if (do_zxingcpp && testUtilCanZXingCPP(i, symbol, data[i].data, length, debug)) {
@@ -1826,15 +1852,20 @@ static void test_encode_segs(const testCtx *const p_ctx) {
for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++);
ret = ZBarcode_Encode_Segs(symbol, data[i].segs, seg_count);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_Segs ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
if (p_ctx->generate) {
char escaped1[4096];
char escaped2[4096];
int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length;
int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length;
int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length;
printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, \"%s\", %s, %d, %d, %d, \"%s\",\n",
int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source)
: data[i].segs[0].length;
int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source)
: data[i].segs[1].length;
int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source)
: data[i].segs[2].length;
printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d },"
"{ TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, \"%s\", %s, %d, %d, %d, \"%s\",\n",
i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2,
data[i].structapp.index, data[i].structapp.count, data[i].structapp.id,
testUtilEscape((const char *) data[i].segs[0].source, length, escaped, sizeof(escaped)),
@@ -1897,7 +1928,8 @@ static void test_encode_segs(const testCtx *const p_ctx) {
ret = testUtilZXingCPPCmpSegs(symbol, cmp_msg, cmp_buf, cmp_len, data[i].segs, seg_count,
data[i].primary, escaped, &ret_len);
assert_zero(ret, "i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
assert_zero(ret,
"i:%d %s testUtilZXingCPPCmpSegs %d != 0 %s\n actual: %.*s\nexpected: %.*s\n",
i, testUtilBarcodeName(symbol->symbology), ret, cmp_msg, cmp_len, cmp_buf,
ret_len, escaped);
}
@@ -1908,6 +1940,32 @@ static void test_encode_segs(const testCtx *const p_ctx) {
ZBarcode_Delete(symbol);
}
if (!p_ctx->generate && p_ctx->index == -1) {
struct zint_seg segs[25] = {0};
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
for (i = 0; i < ARRAY_SIZE(segs); i++) {
segs[i].eci = 899;
segs[i].source = ZUCP("A");
segs[i].length = 1;
}
symbol->symbology = BARCODE_MAXICODE;
symbol->option_1 = 5;
seg_count = ARRAY_SIZE(segs);
ret = ZBarcode_Encode_Segs(symbol, segs, seg_count);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_Segs ret %d != %d (%s)\n",
ret, ZINT_ERROR_TOO_LONG, symbol->errtxt);
seg_count = 19;
ret = ZBarcode_Encode_Segs(symbol, segs, seg_count);
assert_zero(ret, "ZBarcode_Encode_Segs ret %d != 0 (%s)\n", ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
testFinish();
}
@@ -1977,8 +2035,8 @@ static void test_rt(const testCtx *const p_ctx) {
i, symbol->content_segs[0].length, expected_length);
assert_zero(memcmp(symbol->content_segs[0].source, data[i].expected, expected_length),
"i:%d content_segs[0].source memcmp(%s, %s, %d) != 0\n", i,
testUtilEscape((const char *) symbol->content_segs[0].source, symbol->content_segs[0].length,
escaped, sizeof(escaped)),
testUtilEscape((const char *) symbol->content_segs[0].source,
symbol->content_segs[0].length, escaped, sizeof(escaped)),
testUtilEscape(data[i].expected, expected_length, escaped2, sizeof(escaped2)),
expected_length);
assert_equal(symbol->content_segs[0].eci, data[i].expected_content_eci,
@@ -2050,8 +2108,9 @@ static void test_rt_segs(const testCtx *const p_ctx) {
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n",
i, symbol->width, data[i].expected_width);
assert_equal(symbol->content_seg_count, data[i].expected_content_seg_count, "i:%d symbol->content_seg_count %d != %d\n",
i, symbol->content_seg_count, data[i].expected_content_seg_count);
assert_equal(symbol->content_seg_count, data[i].expected_content_seg_count,
"i:%d symbol->content_seg_count %d != %d\n",
i, symbol->content_seg_count, data[i].expected_content_seg_count);
if (symbol->output_options & BARCODE_CONTENT_SEGS) {
assert_nonnull(symbol->content_segs, "i:%d content_segs NULL\n", i);
for (j = 0; j < symbol->content_seg_count; j++) {
@@ -2062,7 +2121,8 @@ static void test_rt_segs(const testCtx *const p_ctx) {
assert_equal(symbol->content_segs[j].length, expected_length,
"i:%d content_segs[%d].length %d != expected_length %d\n",
i, j, symbol->content_segs[j].length, expected_length);
assert_zero(memcmp(symbol->content_segs[j].source, data[i].expected_content_segs[j].source, expected_length),
assert_zero(memcmp(symbol->content_segs[j].source, data[i].expected_content_segs[j].source,
expected_length),
"i:%d content_segs[%d].source memcmp(%s, %s, %d) != 0\n", i, j,
testUtilEscape((const char *) symbol->content_segs[j].source, expected_length, escaped,
sizeof(escaped)),
@@ -2115,10 +2175,13 @@ static void test_fuzz(const testCtx *const p_ctx) {
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, data[i].length, debug);
length = testUtilSetSymbol(symbol, BARCODE_MAXICODE, -1 /*input_mode*/, data[i].eci,
-1 /*option_1*/, -1, -1, -1 /*output_options*/,
data[i].data, data[i].length, debug);
ret = ZBarcode_Encode(symbol, TCU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n",
i, ret, data[i].ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}