EAN/UPC: add quiet zone indicators option (API output_options

`EANUPC_GUARD_WHITESPACE`, CLI `--guardwhitespace`) (ticket #287)
EAN-2/EAN-5: HRT now at top instead of at bottom for standalones,
  following BWIPP
CLI: batch mode: don't close input if stdin
EAN/UPC: fix excess 1X to right of add-ons
Composites: fix excess whitespace; fix quiet zone calcs to allow
  for linear shifting
CLI: use own (Wine) version of `CommandLineToArgvW()` to avoid
  loading "shell32.dll"
Move "font.h" -> "raster_font.h"
EPS/SVG: use new `out_putsf()` func to output floats, avoiding
  trailing zeroes & locale dependency
EPS: simplify "TR" formula
SVG: change font from "Helvetica, sans serif" to "OCR-B, monospace";
  use single "<path>" instead of multiple "<rect>"s to draw boxes
  (reduces file size)
Add `EMBED_VECTOR_FONT` to `output_options` (CLI `--embedfont`) to
  enable embedding of font in vector output - currently only for
  SVG output of EAN/UPC
GUI: use "OCR-B" font for EAN/UPC and "Arimo" for all others (was
  "Helvetica" for both); paint background of screen preview light
  grey so as contrasts with whitespace and quiet zones
EMF: prefix funcs with `emf_`; simplify string `halign` handling
large: rename `large_int` -> `large_uint`
CODE128/common: move `c128_hrt_cpy_iso8859_1()` to
  `hrt_cpy_iso8859_1()` and add `ZINT_WARN_HRT_TRUNCATED` warning
  (for future use)
Various symbologies: replace `printf()` with `fputs()`
  (symbol->debug)
QRCODE: better assert(), removing a NOLINT (2 left)
CLI: add some more barcode synonyms for DBAR
common: various fiddlings
CMake: don't include png.c unless ZINT_USE_PNG (avoids clang
  warning)
This commit is contained in:
gitlost 2023-06-12 01:25:55 +01:00
parent 6d015d6a8f
commit 607e4ed33a
395 changed files with 11528 additions and 23016 deletions

View file

@ -51,6 +51,110 @@ static int is_sane_orig(const char test_string[], const unsigned char source[],
return 0;
}
static void test_to_int(const testCtx *const p_ctx) {
struct item {
char *data;
int length;
int ret;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { "", -1, 0 },
/* 1*/ { "1234", -1, 1234 },
/* 2*/ { "-1234", -1, -1 },
/* 3*/ { "A123A", -1, -1 },
/* 4*/ { " ", -1, -1 },
/* 5*/ { "999999999", -1, 999999999 },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
testStart("test_to_int");
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = to_int((const unsigned char *) data[i].data, length);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
}
testFinish();
}
static void test_to_upper(const testCtx *const p_ctx) {
struct item {
char *data;
int length;
char *expected;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { "", -1, "" },
/* 1*/ { "abcefghijklmnopqrstuvwxyz", -1, "ABCEFGHIJKLMNOPQRSTUVWXYZ" },
/* 2*/ { ".a[b`cA~B\177C;\200", -1, ".A[B`CA~B\177C;\200" },
/* 3*/ { "é", -1, "é" },
};
int data_size = ARRAY_SIZE(data);
int i, length;
unsigned char buf[512];
testStart("test_to_upper");
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
buf[0] = '\0';
memcpy(buf, data[i].data, length);
buf[length] = '\0';
to_upper(buf, length);
assert_zero(strcmp((const char *) buf, data[i].expected), "i:%d strcmp(%s,%s) != 0\n", i, buf, data[i].expected);
}
testFinish();
}
static void test_chr_cnt(const testCtx *const p_ctx) {
struct item {
char *data;
int length;
char c;
int ret;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { "", -1, 'a', 0 },
/* 1*/ { "BDAaED", -1, 'a', 1 },
/* 1*/ { "aBDAaaaEaDa", -1, 'a', 6 },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
testStart("test_chr_cnt");
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = chr_cnt((const unsigned char *) data[i].data, length, data[i].c);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
}
testFinish();
}
static void test_is_sane(const testCtx *const p_ctx) {
struct item {
@ -229,6 +333,42 @@ static void test_is_sane_lookup(const testCtx *const p_ctx) {
testFinish();
}
static void test_cnt_digits(const testCtx *const p_ctx) {
struct item {
char *data;
int length;
int position;
int max;
int ret;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { "", -1, 0, -1, 0 },
/* 1*/ { "asdf1", -1, 0, -1, 0 },
/* 2*/ { "asdf1asdf", -1, 4, -1, 1 },
/* 3*/ { "a12345asdf", -1, 1, -1, 5 },
/* 4*/ { "a12345asdf", -1, 1, 4, 4},
/* 5*/ { "a1234", -1, 1, 5, 4},
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
testStart("test_cnt_digits");
for (i = 0; i < data_size; i++) {
if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = cnt_digits((const unsigned char *) data[i].data, length, data[i].position, data[i].max);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
}
testFinish();
}
static void test_is_valid_utf8(const testCtx *const p_ctx) {
struct item {
@ -320,6 +460,77 @@ static void test_utf8_to_unicode(const testCtx *const p_ctx) {
testFinish();
}
/* Note transferred from "test_code128.c" */
static void test_hrt_cpy_iso8859_1(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
char *data;
int length;
int ret;
char *expected;
char *comment;
};
/*
NBSP U+00A0 (\240, 160), UTF-8 C2A0 (\302\240)
¡ U+00A1 (\241, 161), UTF-8 C2A1 (\302\241)
é U+00E9 (\351, 233), UTF-8 C3A9
*/
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { "", -1, 0, "", "" },
/* 1*/ { "abc", -1, 0, "abc", "" },
/* 2*/ { "\000A\001B\002\036\037C ~\177", 11, 0, " A B C ~ ", "" },
/* 3*/ { "~\177\200\201\237\240", -1, 0, "~ \302\240", "" },
/* 4*/ { "\241\242\243\244\257\260", -1, 0, "¡¢£¤¯°", "" },
/* 5*/ { "\276\277\300\337\377", -1, 0, "¾¿Àßÿ", "" },
/* 6*/ { "\351", -1, 0, "é", "" },
/* 7*/ { "\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241", -1, 0, "¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡", "79 \241" },
/* 8*/ { "a\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241", -1, 0, "a¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡", "a + 79 \241" },
/* 9*/ { "\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241a", -1, 0, "¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a", "79 \241 + a" },
/* 10*/ { "\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241", -1, 1, "¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡", "80 \241 (truncated)" },
/* 11*/ { "a\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241", -1, 1, "a¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡", "a + 80 \241 (truncated)" },
/* 12*/ { "\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241a", -1, 1, "¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡", "80 \241 + a (truncated)" },
/* 13*/ { "\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241\241", -1, 1, "¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡", "81 \241 (truncated)" },
/* 14*/ { "\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351", -1, 0, "ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "79 \351" },
/* 15*/ { "a\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351", -1, 0, "aééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "a + 79 \351" },
/* 16*/ { "\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351a", -1, 0, "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééa", "79 \351 + a" },
/* 17*/ { "\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351", -1, 1, "ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "80 \351 (truncated)" },
/* 18*/ { "a\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351", -1, 1, "aééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "a + 80 \351 (truncated)" },
/* 19*/ { "\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351a", -1, 1, "ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "80 \351 + a (truncated)" },
/* 20*/ { "\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351\351", -1, 1, "ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé", "81 \351 (truncated)" },
/* 21*/ { "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", -1, 1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "160 A (truncated)" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
struct zint_symbol symbol = {0};
testStart("test_hrt_cpy_iso8859_1");
symbol.debug = debug;
for (i = 0; i < data_size; i++) {
int j;
if (testContinue(p_ctx, i)) continue;
length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length;
ret = hrt_cpy_iso8859_1(&symbol, (unsigned char *) data[i].data, length);
if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) {
for (j = 0; j < ret; j++) {
fprintf(stderr, "symbol.text[%d] %2X\n", j, symbol.text[j]);
}
}
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
assert_nonzero(testUtilIsValidUTF8(symbol.text, (int) ustrlen(symbol.text)), "i:%d testUtilIsValidUTF8(%s) != 1\n", i, symbol.text);
assert_zero(strcmp((char *) symbol.text, data[i].expected), "i:%d symbol.text (%s) != expected (%s)\n", i, symbol.text, data[i].expected);
}
testFinish();
}
static void test_set_height(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
@ -420,10 +631,15 @@ static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) {
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
{ "test_chr_cnt", test_chr_cnt },
{ "test_to_int", test_to_int },
{ "test_to_upper", test_to_upper },
{ "test_is_sane", test_is_sane },
{ "test_is_sane_lookup", test_is_sane_lookup },
{ "test_cnt_digits", test_cnt_digits },
{ "test_is_valid_utf8", test_is_valid_utf8 },
{ "test_utf8_to_unicode", test_utf8_to_unicode },
{ "test_hrt_cpy_iso8859_1", test_hrt_cpy_iso8859_1 },
{ "test_set_height", test_set_height },
{ "test_debug_test_codeword_dump_int", test_debug_test_codeword_dump_int },
};