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

@ -31,6 +31,7 @@
#include "testcommon.h"
#include "../output.h"
#include <locale.h>
#ifdef _WIN32
#include <windows.h>
#include <direct.h>
@ -202,13 +203,14 @@ static void test_colour_get_cmyk(const testCtx *const p_ctx) {
testFinish();
}
INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hide_text,
INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset,
float *left, float *right, float *top, float *bottom);
static void test_quiet_zones(const testCtx *const p_ctx) {
int i, ret;
struct zint_symbol symbol = {0};
int hide_text = 0;
int comp_xoffset = 0;
float left, right, top, bottom;
testStart("test_quiet_zones");
@ -219,7 +221,7 @@ static void test_quiet_zones(const testCtx *const p_ctx) {
symbol.symbology = i;
symbol.output_options = BARCODE_QUIET_ZONES;
ret = out_quiet_zones_test(&symbol, hide_text, &left, &right, &top, &bottom);
ret = out_quiet_zones_test(&symbol, hide_text, comp_xoffset, &left, &right, &top, &bottom);
if (i != BARCODE_FLAT && i != BARCODE_BC412) { /* Only two which aren't marked as done */
assert_nonzero(ret, "i:%d %s not done\n", i, testUtilBarcodeName(i));
}
@ -325,6 +327,77 @@ static void test_fopen(const testCtx *const p_ctx) {
testFinish();
}
static void test_out_putsf(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
const char *prefix;
int dp;
float arg;
const char *locale;
const char *expected;
};
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = {
/* 0*/ { "", 2, 1234.123, "", "1234.12" },
/* 1*/ { "", 3, 1234.123, "", "1234.123" },
/* 2*/ { "prefix ", 4, 1234.123, "", "prefix 1234.123" },
/* 3*/ { "", 2, -1234.126, "", "-1234.13" },
/* 4*/ { "", 2, 1234.1, "", "1234.1" },
/* 5*/ { "", 3, 1234.1, "", "1234.1" },
/* 6*/ { "", 4, 1234.1, "", "1234.1" },
/* 7*/ { "", 2, 1234.0, "", "1234" },
/* 8*/ { "", 2, -1234.0, "", "-1234" },
/* 9*/ { "", 3, 1234.1234, "de_DE.UTF-8", "1234.123" },
/* 10*/ { "", 4, -1234.1234, "de_DE.UTF-8", "-1234.1234" },
/* 11*/ { "prefix ", 4, -1234.1234, "de_DE.UTF-8", "prefix -1234.1234" },
};
int data_size = ARRAY_SIZE(data);
int i;
FILE *fp;
char buf[512];
testStart("test_out_putsf");
#ifdef _WIN32
(void)i; (void)fp; (void)buf;
testSkip("Test not implemented on Windows");
#else
for (i = 0; i < data_size; i++) {
const char *locale = NULL;
if (testContinue(p_ctx, i)) continue;
buf[0] = '\0';
fp = fmemopen(buf, sizeof(buf), "w");
assert_nonnull(fp, "%d: fmemopen fail (%d, %s)\n", i, errno, strerror(errno));
if (data[i].locale && data[i].locale[0]) {
locale = setlocale(LC_ALL, data[i].locale);
if (!locale) { /* May not be available - warn unless quiet mode */
if (!(debug & ZINT_DEBUG_TEST_LESS_NOISY)) {
printf("%d: Warning: locale \"%s\" not available\n", i, data[i].locale);
}
}
}
out_putsf(data[i].prefix, data[i].dp, data[i].arg, fp);
assert_zero(fclose(fp), "%d: fclose fail (%d, %s)\n", i, errno, strerror(errno));
if (locale) {
assert_nonnull(setlocale(LC_ALL, locale), "%d: setlocale(%s) restore fail (%d, %s)\n",
i, locale, errno, strerror(errno));
}
assert_zero(strcmp(buf, data[i].expected), "%d: strcmp(%s, %s) != 0\n", i, buf, data[i].expected);
}
testFinish();
#endif /* _WIN32 */
}
int main(int argc, char *argv[]) {
@ -334,6 +407,7 @@ int main(int argc, char *argv[]) {
{ "test_colour_get_cmyk", test_colour_get_cmyk },
{ "test_quiet_zones", test_quiet_zones },
{ "test_fopen", test_fopen },
{ "test_out_putsf", test_out_putsf },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));