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

@ -1,7 +1,7 @@
/* large.c - Handles binary manipulation of large numbers */
/*
libzint - the open source barcode library
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008-2023 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -52,7 +52,7 @@
#define MASK32 0xFFFFFFFF
/* Convert decimal string `s` of (at most) length `length` to 64-bit and place in 128-bit `t` */
INTERNAL void large_load_str_u64(large_int *t, const unsigned char *s, const int length) {
INTERNAL void large_load_str_u64(large_uint *t, const unsigned char *s, const int length) {
uint64_t val = 0;
const unsigned char *const se = s + length;
for (; s < se && z_isdigit(*s); s++) {
@ -64,13 +64,13 @@ INTERNAL void large_load_str_u64(large_int *t, const unsigned char *s, const int
}
/* Add 128-bit `s` to 128-bit `t` */
INTERNAL void large_add(large_int *t, const large_int *s) {
INTERNAL void large_add(large_uint *t, const large_uint *s) {
t->lo += s->lo;
t->hi += s->hi + (t->lo < s->lo);
}
/* Add 64-bit `s` to 128-bit `t` */
INTERNAL void large_add_u64(large_int *t, const uint64_t s) {
INTERNAL void large_add_u64(large_uint *t, const uint64_t s) {
t->lo += s;
if (t->lo < s) {
t->hi++;
@ -78,7 +78,7 @@ INTERNAL void large_add_u64(large_int *t, const uint64_t s) {
}
/* Subtract 64-bit `s` from 128-bit `t` */
INTERNAL void large_sub_u64(large_int *t, const uint64_t s) {
INTERNAL void large_sub_u64(large_uint *t, const uint64_t s) {
uint64_t r = t->lo - s;
if (r > t->lo) {
t->hi--;
@ -107,7 +107,7 @@ INTERNAL void large_sub_u64(large_int *t, const uint64_t s) {
* p10
* p11 + k10
*/
INTERNAL void large_mul_u64(large_int *t, const uint64_t s) {
INTERNAL void large_mul_u64(large_uint *t, const uint64_t s) {
uint64_t thi = t->hi;
uint64_t tlo0 = t->lo & MASK32;
uint64_t tlo1 = t->lo >> 32;
@ -149,7 +149,7 @@ INTERNAL int clz_u64_test(uint64_t x) {
/* Divide 128-bit dividend `t` by 64-bit divisor `v`, returning 64-bit remainder
* See Jacob `divmod128by128/64()` and Warren Section 92 (divmu64.c.txt)
* Note digits are 32-bit parts */
INTERNAL uint64_t large_div_u64(large_int *t, uint64_t v) {
INTERNAL uint64_t large_div_u64(large_uint *t, uint64_t v) {
const uint64_t b = 0x100000000; /* Number base (2**32) */
uint64_t qhi = 0; /* High digit of returned quotient */
@ -241,7 +241,7 @@ INTERNAL uint64_t large_div_u64(large_int *t, uint64_t v) {
}
/* Unset a bit (zero-based) */
INTERNAL void large_unset_bit(large_int *t, const int bit) {
INTERNAL void large_unset_bit(large_uint *t, const int bit) {
if (bit < 64) {
t->lo &= ~(((uint64_t) 1) << bit);
} else if (bit < 128) {
@ -249,8 +249,8 @@ INTERNAL void large_unset_bit(large_int *t, const int bit) {
}
}
/* Output large_int into an unsigned int array of size `size`, each element containing `bits` bits */
INTERNAL void large_uint_array(const large_int *t, unsigned int *uint_array, const int size, int bits) {
/* Output large_uint into an unsigned int array of size `size`, each element containing `bits` bits */
INTERNAL void large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits) {
int i, j;
uint64_t mask;
if (bits <= 0) {
@ -281,7 +281,7 @@ INTERNAL void large_uint_array(const large_int *t, unsigned int *uint_array, con
}
/* As `large_uint_array()` above, except output to unsigned char array */
INTERNAL void large_uchar_array(const large_int *t, unsigned char *uchar_array, const int size, int bits) {
INTERNAL void large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits) {
int i;
unsigned int *uint_array = (unsigned int *) z_alloca(sizeof(unsigned int) * (size ? size : 1));
@ -292,8 +292,8 @@ INTERNAL void large_uchar_array(const large_int *t, unsigned char *uchar_array,
}
}
/* Format large_int into buffer, which should be at least 35 chars in size */
INTERNAL char *large_dump(const large_int *t, char *buf) {
/* Format large_uint into buffer, which should be at least 35 chars in size */
INTERNAL char *large_dump(const large_uint *t, char *buf) {
unsigned int tlo1 = (unsigned int) (large_lo(t) >> 32);
unsigned int tlo0 = (unsigned int) (large_lo(t) & MASK32);
unsigned int thi1 = (unsigned int) (large_hi(t) >> 32);
@ -311,8 +311,8 @@ INTERNAL char *large_dump(const large_int *t, char *buf) {
return buf;
}
/* Output formatted large_int to stdout */
INTERNAL void large_print(const large_int *t) {
/* Output formatted large_uint to stdout */
INTERNAL void large_print(const large_uint *t) {
char buf[35]; /* 2 (0x) + 32 (hex) + 1 */
puts(large_dump(t, buf));