mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-09 13:41:59 -04:00
zint.h: increase symbol->text
size 160 -> 200;
rename `ZINT_CAP_EXTENDABLE` -> `ZINT_CAP_EANUPC` (`ZINT_CAP_EXTENDABLE` marked as legacy) CODE128: increase no. symbol chars max 60 -> 99 EAN-2/EAN-5: fix `BARCODE_BIND_TOP/BIND/BOX` output GS1_128: warn if data > 48 (GS1 General Specifications max) common: `is_extendable()` -> `is_ucpean()` raster: add `ZFONT_HALIGN_CENTRE/LEFT/RIGHT` flags and process in `draw_string()` (for drawing EAN/UPC outside digits), and for `ZFONT_HALIGN_CENTRE` round when calculating centre (shifts some texts 1 pixel left) raster/vector: use offsets into `symbol->text` for EAN/UPC instead of `out_upcean_split_text()` (removed) BMP/EMF/GIF/PCX/PNG/PS/SVG/TIF: use new `out_colour_get_rgb()` routine (replaces `colour_to_XXX()`) general: simplify/fix some `error_number` handling/returning frontend: truncate overlong `--primary` instead of ignoring; negative floating pt option (for `--textgap`) man page: list size detail for matrix symbols (`--vers`) manual: further fiddling with scaling text; some typos
This commit is contained in:
parent
ca964f9098
commit
323b34502b
113 changed files with 2016 additions and 1550 deletions
|
@ -274,11 +274,25 @@ static int validate_int(const char source[], int len, int *p_val) {
|
|||
|
||||
/* Verifies that a string is a simplified form of floating point, max 7 significant decimal digits with
|
||||
optional decimal point. On success returns val in arg. On failure sets `errbuf` */
|
||||
static int validate_float(const char source[], float *p_val, char errbuf[64]) {
|
||||
static int validate_float(const char source[], const int allow_neg, float *p_val, char errbuf[64]) {
|
||||
static const float fract_muls[7] = { 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f };
|
||||
int val = 0;
|
||||
int neg = 0;
|
||||
const char *dot = strchr(source, '.');
|
||||
int int_len = dot ? (int) (dot - source) : (int) strlen(source);
|
||||
int int_len;
|
||||
|
||||
if (*source == '+' || *source == '-') {
|
||||
if (*source == '-') {
|
||||
if (!allow_neg) {
|
||||
strcpy(errbuf, "negative value not permitted");
|
||||
return 0;
|
||||
}
|
||||
neg = 1;
|
||||
}
|
||||
source++;
|
||||
}
|
||||
|
||||
int_len = dot ? (int) (dot - source) : (int) strlen(source);
|
||||
if (int_len > 9) {
|
||||
strcpy(errbuf, "integer part must be 7 digits maximum"); /* Say 7 not 9 to "manage expections" */
|
||||
return 0;
|
||||
|
@ -324,6 +338,9 @@ static int validate_float(const char source[], float *p_val, char errbuf[64]) {
|
|||
} else {
|
||||
*p_val = (float) val;
|
||||
}
|
||||
if (neg) {
|
||||
*p_val = -*p_val;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -749,7 +766,7 @@ static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_
|
|||
fprintf(stderr, "Error 177: scalexdimdp X-dim units must occur at end\n");
|
||||
return 0;
|
||||
}
|
||||
if (!validate_float(x_buf, p_x_dim_mm, errbuf)) {
|
||||
if (!validate_float(x_buf, 0 /*allow_neg*/, p_x_dim_mm, errbuf)) {
|
||||
fprintf(stderr, "Error 178: scalexdimdp X-dim invalid floating point (%s)\n", errbuf);
|
||||
return 0;
|
||||
}
|
||||
|
@ -762,7 +779,7 @@ static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_
|
|||
fprintf(stderr, "Error 179: scalexdimdp resolution units must occur at end\n");
|
||||
return 0;
|
||||
}
|
||||
if (!validate_float(r_buf, p_dpmm, errbuf)) {
|
||||
if (!validate_float(r_buf, 0 /*allow_neg*/, p_dpmm, errbuf)) {
|
||||
fprintf(stderr, "Error 180: scalexdimdp resolution invalid floating point (%s)\n", errbuf);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1615,7 +1632,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
break;
|
||||
case OPT_DOTSIZE:
|
||||
if (!validate_float(optarg, &float_opt, errbuf)) {
|
||||
if (!validate_float(optarg, 0 /*allow_neg*/, &float_opt, errbuf)) {
|
||||
fprintf(stderr, "Error 181: Invalid dot radius floating point (%s)\n", errbuf);
|
||||
return do_exit(ZINT_ERROR_INVALID_OPTION);
|
||||
}
|
||||
|
@ -1692,7 +1709,7 @@ int main(int argc, char **argv) {
|
|||
my_symbol->output_options |= GS1_GS_SEPARATOR;
|
||||
break;
|
||||
case OPT_GUARDDESCENT:
|
||||
if (!validate_float(optarg, &float_opt, errbuf)) {
|
||||
if (!validate_float(optarg, 0 /*allow_neg*/, &float_opt, errbuf)) {
|
||||
fprintf(stderr, "Error 182: Invalid guard bar descent floating point (%s)\n", errbuf);
|
||||
return do_exit(ZINT_ERROR_INVALID_OPTION);
|
||||
}
|
||||
|
@ -1709,7 +1726,7 @@ int main(int argc, char **argv) {
|
|||
my_symbol->output_options |= EANUPC_GUARD_WHITESPACE;
|
||||
break;
|
||||
case OPT_HEIGHT:
|
||||
if (!validate_float(optarg, &float_opt, errbuf)) {
|
||||
if (!validate_float(optarg, 0 /*allow_neg*/, &float_opt, errbuf)) {
|
||||
fprintf(stderr, "Error 183: Invalid symbol height floating point (%s)\n", errbuf);
|
||||
return do_exit(ZINT_ERROR_INVALID_OPTION);
|
||||
}
|
||||
|
@ -1772,7 +1789,9 @@ int main(int argc, char **argv) {
|
|||
if (strlen(optarg) <= 127) {
|
||||
strcpy(my_symbol->primary, optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Warning 115: Primary data string too long (127 character maximum), ignoring\n");
|
||||
strncpy(my_symbol->primary, optarg, 127);
|
||||
fprintf(stderr,
|
||||
"Warning 115: Primary data string too long (127 character maximum), truncating\n");
|
||||
fflush(stderr);
|
||||
warn_number = ZINT_WARN_INVALID_OPTION;
|
||||
}
|
||||
|
@ -1817,7 +1836,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
break;
|
||||
case OPT_SCALE:
|
||||
if (!validate_float(optarg, &float_opt, errbuf)) {
|
||||
if (!validate_float(optarg, 0 /*allow_neg*/, &float_opt, errbuf)) {
|
||||
fprintf(stderr, "Error 184: Invalid scale floating point (%s)\n", errbuf);
|
||||
return do_exit(ZINT_ERROR_INVALID_OPTION);
|
||||
}
|
||||
|
@ -1835,11 +1854,11 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
if (x_dim_mm > 10.0f || dpmm > 1000.0f) {
|
||||
if (x_dim_mm > 10.0f) {
|
||||
fprintf(stderr,
|
||||
"Warning 185: scalexdimdp X-dim (%g) out of range (> 10), ignoring\n", x_dim_mm);
|
||||
fprintf(stderr, "Warning 185: scalexdimdp X-dim (%g) out of range (> 10), ignoring\n",
|
||||
x_dim_mm);
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Warning 186: scalexdimdp resolution (%g) out of range (> 1000), ignoring\n", dpmm);
|
||||
fprintf(stderr, "Warning 186: scalexdimdp resolution (%g) out of range (> 1000), ignoring\n",
|
||||
dpmm);
|
||||
}
|
||||
fflush(stderr);
|
||||
warn_number = ZINT_WARN_INVALID_OPTION;
|
||||
|
@ -1928,14 +1947,15 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
break;
|
||||
case OPT_TEXTGAP:
|
||||
if (!validate_float(optarg, &float_opt, errbuf)) {
|
||||
if (!validate_float(optarg, 1 /*allow_neg*/, &float_opt, errbuf)) {
|
||||
fprintf(stderr, "Error 194: Invalid text gap floating point (%s)\n", errbuf);
|
||||
return do_exit(ZINT_ERROR_INVALID_OPTION);
|
||||
}
|
||||
if (float_opt >= 0.0f && float_opt <= 10.0f) {
|
||||
if (float_opt >= -5.0f && float_opt <= 10.0f) {
|
||||
my_symbol->text_gap = float_opt;
|
||||
} else {
|
||||
fprintf(stderr, "Warning 195: Text gap '%g' out of range (0 to 10), ignoring\n", float_opt);
|
||||
fprintf(stderr, "Warning 195: Text gap '%g' out of range (-5 to 10), ignoring\n",
|
||||
float_opt);
|
||||
fflush(stderr);
|
||||
warn_number = ZINT_WARN_INVALID_OPTION;
|
||||
}
|
||||
|
|
|
@ -808,8 +808,8 @@ static void test_checks(const testCtx *const p_ctx) {
|
|||
/* 2*/ { 13, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Add-on gap out of range (7 to 12), ignoring" },
|
||||
/* 3*/ { -1, -2, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 107: Invalid border width value (digits only)" },
|
||||
/* 4*/ { -1, 1001, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 108: Border width out of range (0 to 1000), ignoring" },
|
||||
/* 5*/ { -1, -1, -1, -1, -0.5, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 194: Invalid text gap floating point (integer part must be digits only)" },
|
||||
/* 6*/ { -1, -1, -1, -1, 10.01, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 195: Text gap '10.01' out of range (0 to 10), ignoring" },
|
||||
/* 5*/ { -1, -1, -1, -1, -5.1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 195: Text gap '-5.1' out of range (-5 to 10), ignoring" },
|
||||
/* 6*/ { -1, -1, -1, -1, 10.01, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 195: Text gap '10.01' out of range (-5 to 10), ignoring" },
|
||||
/* 7*/ { -1, -1, -1, 12345678, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 181: Invalid dot radius floating point (integer part must be 7 digits maximum)" },
|
||||
/* 8*/ { -1, -1, -1, 0.009, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 106: Invalid dot radius value (less than 0.01), ignoring" },
|
||||
/* 9*/ { -1, -1, -2, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 131: Invalid columns value (digits only)" },
|
||||
|
@ -817,10 +817,10 @@ static void test_checks(const testCtx *const p_ctx) {
|
|||
/* 11*/ { -1, -1, -1, -1, -1, -2, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 138: Invalid ECI value (digits only)" },
|
||||
/* 12*/ { -1, -1, -1, -1, -1, 1000000, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 118: ECI code out of range (0 to 999999), ignoring" },
|
||||
/* 13*/ { -1, -1, -1, -1, -1, -1, "jpg", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 142: File type 'jpg' not supported, ignoring" },
|
||||
/* 14*/ { -1, -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 183: Invalid symbol height floating point (integer part must be digits only)" },
|
||||
/* 14*/ { -1, -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 183: Invalid symbol height floating point (negative value not permitted)" },
|
||||
/* 15*/ { -1, -1, -1, -1, -1, -1, NULL, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height '0' out of range (0.5 to 2000), ignoring" },
|
||||
/* 16*/ { -1, -1, -1, -1, -1, -1, NULL, 2001, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height '2001' out of range (0.5 to 2000), ignoring" },
|
||||
/* 17*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 182: Invalid guard bar descent floating point (integer part must be digits only)" },
|
||||
/* 17*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 182: Invalid guard bar descent floating point (negative value not permitted)" },
|
||||
/* 18*/ { -1, -1, -1, -1, -1, -1, NULL, -1, 50.1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 135: Guard bar descent '50.1' out of range (0 to 50), ignoring" },
|
||||
/* 19*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 148: Invalid mask value (digits only)" },
|
||||
/* 20*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 147: Mask value out of range (0 to 7), ignoring" },
|
||||
|
@ -829,7 +829,7 @@ static void test_checks(const testCtx *const p_ctx) {
|
|||
/* 23*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 137: Invalid rotation parameter (0, 90, 180 or 270 only), ignoring" },
|
||||
/* 24*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, "Error 132: Invalid rows value (digits only)" },
|
||||
/* 25*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, 91, -1, -1, -1, -1, -1, -1, -1, "Warning 112: Number of rows out of range (1 to 90), ignoring" },
|
||||
/* 26*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Error 184: Invalid scale floating point (integer part must be digits only)" },
|
||||
/* 26*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Error 184: Invalid scale floating point (negative value not permitted)" },
|
||||
/* 27*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, 0.49, -1, -1, -1, -1, -1, -1, "Warning 146: Scaling less than 0.5 will be set to 0.5 for 'gif' output" },
|
||||
/* 28*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, "Error 149: Invalid Structured Carrier Message version value (digits only)" },
|
||||
/* 29*/ { -1, -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, 100, -1, -1, -1, -1, -1, "Warning 150: Structured Carrier Message version out of range (0 to 99), ignoring" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue