- zint_symbol->fgcolour & bgcolour buffer lengths extended 10

-> 16 to allow for "C,M,Y,K" comma-separated decimal percentage
  strings
- API/CLI/GUI: allow foreground/background colours to be specified
  as comma-separated decimal "C,M,Y,K" strings where "C", "M" etc.
  are percentages (0-100) (ticket #281, 3rd point)
- output.c: new funcs `out_colour_get_rgb()` & `out_colour_get_cmyk()`
  and use in bmp/emf/gif etc.
- PCX: add alpha support
- GUI: fix fg/gbcolor icon background not being reset on zap
- GUI: Rearrange some Appearance tab inputs (Border Type <-> Width,
  Show Text <-> Font, Text/Font <-> Printing Scale/Size) to flow
  more naturally (hopefully)
- GUI: save button "Save As..." -> "Save..." and add icon
- CLI: add --bgcolor/colour & --fgcolor/colour synonyms
This commit is contained in:
gitlost
2023-01-29 19:51:11 +00:00
parent 48eaa0cc4e
commit ab2abccdb6
55 changed files with 1439 additions and 886 deletions

View File

@ -1,7 +1,7 @@
/* main.c - Command line handling routines for Zint */
/*
libzint - the open source barcode library
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008-2023 Robin Stuart <rstuart114@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -146,7 +146,7 @@ static void usage(int no_png) {
fputs( " -b, --barcode=TYPE Number or name of barcode type. Default is 20 (CODE128)\n"
" --addongap=NUMBER Set add-on gap in multiples of X-dimension for EAN/UPC\n"
" --batch Treat each line of input file as a separate data set\n"
" --bg=COLOUR Specify a background colour (in hex RGB/RGBA)\n"
" --bg=COLOUR Specify a background colour (as RGB(A) or \"C,M,Y,K\")\n"
" --binary Treat input as raw binary data\n", stdout);
fputs( " --bind Add boundary bars\n"
" --bindtop Add top boundary bar only\n"
@ -167,7 +167,7 @@ static void usage(int no_png) {
" --esc Process escape sequences in input data\n"
" --extraesc Process symbology-specific escape sequences (Code 128)\n"
" --fast Use faster encodation or other shortcuts if available\n"
" --fg=COLOUR Specify a foreground colour (in hex RGB/RGBA)\n", stdout);
" --fg=COLOUR Specify a foreground colour (as RGB(A) or \"C,M,Y,K\")\n", stdout);
printf(" --filetype=TYPE Set output file type BMP/EMF/EPS/GIF/PCX%s/SVG/TIF/TXT\n", no_png_type);
fputs( " --fullmultibyte Use multibyte for binary/Latin (QR/Han Xin/Grid Matrix)\n"
" --gs1 Treat input as GS1 compatible data\n"
@ -863,7 +863,7 @@ static int batch_process(struct zint_symbol *symbol, const char *filename, const
if (mirror_start_o > 221) { /* Insist on leaving at least ~30 chars for filename */
fprintf(stderr, "Warning 188: directory for mirrored batch output too long (> 220), ignored\n");
fflush(stderr);
warn_number = ZINT_WARN_INVALID_OPTION; /* TODO: maybe new warning e.g. ZINT_WARN_INVALID_INPUT? */
warn_number = ZINT_WARN_INVALID_OPTION; /* TODO: maybe new warning ZINT_WARN_INVALID_INPUT? */
mirror_start_o = 0;
} else {
memcpy(output_file, symbol->outfile, mirror_start_o);
@ -1201,6 +1201,8 @@ int main(int argc, char **argv) {
{"batch", 0, NULL, OPT_BATCH},
{"binary", 0, NULL, OPT_BINARY},
{"bg", 1, 0, OPT_BG},
{"bgcolor", 1, 0, OPT_BG}, /* Synonym */
{"bgcolour", 1, 0, OPT_BG}, /* Synonym */
{"bind", 0, NULL, OPT_BIND},
{"bindtop", 0, NULL, OPT_BIND_TOP},
{"bold", 0, NULL, OPT_BOLD},
@ -1221,6 +1223,8 @@ int main(int argc, char **argv) {
{"extraesc", 0, NULL, OPT_EXTRAESC},
{"fast", 0, NULL, OPT_FAST},
{"fg", 1, 0, OPT_FG},
{"fgcolor", 1, 0, OPT_FG}, /* Synonym */
{"fgcolour", 1, 0, OPT_FG}, /* Synonym */
{"filetype", 1, NULL, OPT_FILETYPE},
{"fontsize", 1, NULL, OPT_FONTSIZE},
{"fullmultibyte", 0, NULL, OPT_FULLMULTIBYTE},
@ -1300,7 +1304,7 @@ int main(int argc, char **argv) {
}
break;
case OPT_BG:
strncpy(my_symbol->bgcolour, optarg, 9);
strncpy(my_symbol->bgcolour, optarg, 15); /* Allow for "CCC,MMM,YYY,KKK" */
break;
case OPT_BINARY:
my_symbol->input_mode = (my_symbol->input_mode & ~0x07) | DATA_MODE;
@ -1401,7 +1405,7 @@ int main(int argc, char **argv) {
my_symbol->input_mode |= FAST_MODE;
break;
case OPT_FG:
strncpy(my_symbol->fgcolour, optarg, 9);
strncpy(my_symbol->fgcolour, optarg, 15); /* Allow for "CCC,MMM,YYY,KKK" */
break;
case OPT_FILETYPE:
/* Select the type of output file */

View File

@ -1150,62 +1150,67 @@ static void test_other_opts(const testCtx *const p_ctx) {
/* 0*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900", "", 0 },
/* 1*/ { BARCODE_CODE128, "1", -1, " -bg=", "EF9900", "", 0 },
/* 2*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900AA", "", 0 },
/* 3*/ { BARCODE_CODE128, "1", -1, " --bg=", "GF9900", "Error 654: Malformed background colour 'GF9900' (hexadecimal only)", 0 },
/* 4*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000", "", 0 },
/* 5*/ { BARCODE_CODE128, "1", -1, " --fg=", "00000000", "", 0 },
/* 6*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000F", "Error 651: Malformed foreground colour (6 or 8 characters only)", 0 },
/* 7*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000FG", "Error 653: Malformed foreground colour '000000FG' (hexadecimal only)", 0 },
/* 8*/ { BARCODE_CODE128, "1", -1, " --compliantheight", "", "", 0 },
/* 9*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "10", "", 0 },
/* 10*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "101", "Warning 126: Font size out of range (0 to 100), ignoring", 0 },
/* 11*/ { BARCODE_CODE128, "1", -1, " --nobackground", "", "", 0 },
/* 12*/ { BARCODE_CODE128, "1", -1, " --noquietzones", "", "", 0 },
/* 13*/ { BARCODE_CODE128, "1", -1, " --notext", "", "", 0 },
/* 14*/ { BARCODE_CODE128, "1", -1, " --quietzones", "", "", 0 },
/* 15*/ { BARCODE_CODE128, "1", -1, " --reverse", "", "", 0 },
/* 16*/ { BARCODE_CODE128, "1", -1, " --werror", NULL, "", 0 },
/* 17*/ { 19, "1", -1, " --werror", NULL, "Error 207: Codabar 18 not supported", 0 },
/* 18*/ { BARCODE_GS1_128, "[01]12345678901231", -1, "", NULL, "", 0 },
/* 19*/ { BARCODE_GS1_128, "0112345678901231", -1, "", NULL, "Error 252: Data does not start with an AI", 0 },
/* 20*/ { BARCODE_GS1_128, "0112345678901231", -1, " --gs1nocheck", NULL, "Error 252: Data does not start with an AI", 0 },
/* 21*/ { BARCODE_GS1_128, "[00]376104250021234569", -1, "", NULL, "", 0 },
/* 22*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, "", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'", 0 },
/* 23*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --gs1nocheck", NULL, "", 0 },
/* 24*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --werror", NULL, "Error 261: AI (00) position 18: Bad checksum '8', expected '9'", 0 },
/* 25*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "1", "Error 155: Invalid Structured Append argument, expect \"index,count[,ID]\"", 0 },
/* 26*/ { BARCODE_AZTEC, "1", -1, " --structapp=", ",", "Error 156: Structured Append index too short", 0 },
/* 27*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "1234567890,", "Error 156: Structured Append index too long", 0 },
/* 28*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,", "Error 159: Structured Append count too short", 0 },
/* 29*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,1234567890", "Error 159: Structured Append count too long", 0 },
/* 30*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,", "Error 158: Structured Append ID too short", 0 },
/* 31*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,1234567890,", "Error 157: Structured Append count too long", 0 },
/* 32*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,123456789012345678901234567890123", "Error 158: Structured Append ID too long", 0 },
/* 33*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,12345678901234567890123456789012", "Error 701: Structured Append count out of range (2-26)", 0 },
/* 34*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,26,12345678901234567890123456789012", "", 0 },
/* 35*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "A,26,12345678901234567890123456789012", "Error 160: Invalid Structured Append index (digits only)", 0 },
/* 36*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,A,12345678901234567890123456789012", "Error 161: Invalid Structured Append count (digits only)", 0 },
/* 37*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,1,12345678901234567890123456789012", "Error 162: Invalid Structured Append count, must be >= 2", 0 },
/* 38*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "0,2,12345678901234567890123456789012", "Error 163: Structured Append index out of range (1-2)", 0 },
/* 39*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "3,2,12345678901234567890123456789012", "Error 163: Structured Append index out of range (1-2)", 0 },
/* 40*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "2,3,12345678901234567890123456789012", "", 0 },
/* 41*/ { BARCODE_PDF417, "1", -1, " --heightperrow", "", "", 0 },
/* 42*/ { -1, NULL, -1, " -v", NULL, "Zint version ", 1 },
/* 43*/ { -1, NULL, -1, " --version", NULL, "Zint version ", 1 },
/* 44*/ { -1, NULL, -1, " -h", NULL, "Encode input data in a barcode ", 1 },
/* 45*/ { -1, NULL, -1, " -e", NULL, "3: ISO/IEC 8859-1 ", 1 },
/* 46*/ { -1, NULL, -1, " -t", NULL, "1 CODE11 ", 1 },
/* 47*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12345678", "Error 178: scalexdimdp X-dim invalid floating point (integer part must be 7 digits maximum)", 0 },
/* 48*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1234567890123", "Error 176: scalexdimdp X-dim too long", 0 },
/* 49*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "123456.12", "Error 178: scalexdimdp X-dim invalid floating point (7 significant digits maximum)", 0 },
/* 50*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", ",12.34", "Error 174: scalexdimdp X-dim too short", 0 },
/* 51*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12.34,", "Error 175: scalexdimdp resolution too short", 0 },
/* 52*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12mm1", "Error 177: scalexdimdp X-dim units must occur at end", 0 },
/* 53*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1inc", "Error 177: scalexdimdp X-dim units must occur at end", 0 },
/* 54*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1234x", "Error 178: scalexdimdp X-dim invalid floating point (integer part must be digits only)", 0 },
/* 55*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12.34in,123x", "Error 180: scalexdimdp resolution invalid floating point (integer part must be digits only)", 0 },
/* 56*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12,123.45678", "Error 180: scalexdimdp resolution invalid floating point (7 significant digits maximum)", 0 },
/* 57*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "10.1,1000", "Warning 185: scalexdimdp X-dim (10.1) out of range (> 10), ignoring", 0 },
/* 58*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "10,1000.1", "Warning 186: scalexdimdp resolution (1000.1) out of range (> 1000), ignoring", 0 },
/* 3*/ { BARCODE_CODE128, "1", -1, " --bg=", "GF9900", "Error 691: Malformed background RGB colour 'GF9900' (hexadecimal only)", 0 },
/* 4*/ { BARCODE_CODE128, "1", -1, " --bgcolor=", "EF9900", "", 0 },
/* 5*/ { BARCODE_CODE128, "1", -1, " --bgcolour=", "EF9900", "", 0 },
/* 6*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000", "", 0 },
/* 7*/ { BARCODE_CODE128, "1", -1, " --fg=", "00000000", "", 0 },
/* 8*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000F", "Error 690: Malformed foreground RGB colour (6 or 8 characters only)", 0 },
/* 9*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000FG", "Error 691: Malformed foreground RGB colour '000000FG' (hexadecimal only)", 0 },
/* 10*/ { BARCODE_CODE128, "1", -1, " --fg=", "0,0,0,100", "", 0 },
/* 11*/ { BARCODE_CODE128, "1", -1, " --fgcolor=", "111111", "", 0 },
/* 12*/ { BARCODE_CODE128, "1", -1, " --fgcolour=", "111111", "", 0 },
/* 13*/ { BARCODE_CODE128, "1", -1, " --compliantheight", "", "", 0 },
/* 14*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "10", "", 0 },
/* 15*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "101", "Warning 126: Font size out of range (0 to 100), ignoring", 0 },
/* 16*/ { BARCODE_CODE128, "1", -1, " --nobackground", "", "", 0 },
/* 17*/ { BARCODE_CODE128, "1", -1, " --noquietzones", "", "", 0 },
/* 18*/ { BARCODE_CODE128, "1", -1, " --notext", "", "", 0 },
/* 19*/ { BARCODE_CODE128, "1", -1, " --quietzones", "", "", 0 },
/* 20*/ { BARCODE_CODE128, "1", -1, " --reverse", "", "", 0 },
/* 21*/ { BARCODE_CODE128, "1", -1, " --werror", NULL, "", 0 },
/* 22*/ { 19, "1", -1, " --werror", NULL, "Error 207: Codabar 18 not supported", 0 },
/* 23*/ { BARCODE_GS1_128, "[01]12345678901231", -1, "", NULL, "", 0 },
/* 24*/ { BARCODE_GS1_128, "0112345678901231", -1, "", NULL, "Error 252: Data does not start with an AI", 0 },
/* 25*/ { BARCODE_GS1_128, "0112345678901231", -1, " --gs1nocheck", NULL, "Error 252: Data does not start with an AI", 0 },
/* 26*/ { BARCODE_GS1_128, "[00]376104250021234569", -1, "", NULL, "", 0 },
/* 27*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, "", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'", 0 },
/* 28*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --gs1nocheck", NULL, "", 0 },
/* 29*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --werror", NULL, "Error 261: AI (00) position 18: Bad checksum '8', expected '9'", 0 },
/* 30*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "1", "Error 155: Invalid Structured Append argument, expect \"index,count[,ID]\"", 0 },
/* 31*/ { BARCODE_AZTEC, "1", -1, " --structapp=", ",", "Error 156: Structured Append index too short", 0 },
/* 32*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "1234567890,", "Error 156: Structured Append index too long", 0 },
/* 33*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,", "Error 159: Structured Append count too short", 0 },
/* 34*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,1234567890", "Error 159: Structured Append count too long", 0 },
/* 35*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,", "Error 158: Structured Append ID too short", 0 },
/* 36*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,1234567890,", "Error 157: Structured Append count too long", 0 },
/* 37*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,123456789012345678901234567890123", "Error 158: Structured Append ID too long", 0 },
/* 38*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "123456789,123456789,12345678901234567890123456789012", "Error 701: Structured Append count out of range (2-26)", 0 },
/* 39*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,26,12345678901234567890123456789012", "", 0 },
/* 40*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "A,26,12345678901234567890123456789012", "Error 160: Invalid Structured Append index (digits only)", 0 },
/* 41*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,A,12345678901234567890123456789012", "Error 161: Invalid Structured Append count (digits only)", 0 },
/* 42*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "26,1,12345678901234567890123456789012", "Error 162: Invalid Structured Append count, must be >= 2", 0 },
/* 43*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "0,2,12345678901234567890123456789012", "Error 163: Structured Append index out of range (1-2)", 0 },
/* 44*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "3,2,12345678901234567890123456789012", "Error 163: Structured Append index out of range (1-2)", 0 },
/* 45*/ { BARCODE_AZTEC, "1", -1, " --structapp=", "2,3,12345678901234567890123456789012", "", 0 },
/* 46*/ { BARCODE_PDF417, "1", -1, " --heightperrow", "", "", 0 },
/* 47*/ { -1, NULL, -1, " -v", NULL, "Zint version ", 1 },
/* 48*/ { -1, NULL, -1, " --version", NULL, "Zint version ", 1 },
/* 49*/ { -1, NULL, -1, " -h", NULL, "Encode input data in a barcode ", 1 },
/* 50*/ { -1, NULL, -1, " -e", NULL, "3: ISO/IEC 8859-1 ", 1 },
/* 51*/ { -1, NULL, -1, " -t", NULL, "1 CODE11 ", 1 },
/* 52*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12345678", "Error 178: scalexdimdp X-dim invalid floating point (integer part must be 7 digits maximum)", 0 },
/* 53*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1234567890123", "Error 176: scalexdimdp X-dim too long", 0 },
/* 54*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "123456.12", "Error 178: scalexdimdp X-dim invalid floating point (7 significant digits maximum)", 0 },
/* 55*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", ",12.34", "Error 174: scalexdimdp X-dim too short", 0 },
/* 56*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12.34,", "Error 175: scalexdimdp resolution too short", 0 },
/* 57*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12mm1", "Error 177: scalexdimdp X-dim units must occur at end", 0 },
/* 58*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1inc", "Error 177: scalexdimdp X-dim units must occur at end", 0 },
/* 59*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "1234x", "Error 178: scalexdimdp X-dim invalid floating point (integer part must be digits only)", 0 },
/* 60*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12.34in,123x", "Error 180: scalexdimdp resolution invalid floating point (integer part must be digits only)", 0 },
/* 61*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "12,123.45678", "Error 180: scalexdimdp resolution invalid floating point (7 significant digits maximum)", 0 },
/* 62*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "10.1,1000", "Warning 185: scalexdimdp X-dim (10.1) out of range (> 10), ignoring", 0 },
/* 63*/ { BARCODE_EANX, "501234567890", -1, " --scalexdimdp=", "10,1000.1", "Warning 186: scalexdimdp resolution (1000.1) out of range (> 1000), ignoring", 0 },
};
int data_size = ARRAY_SIZE(data);
int i;