CMakeLists.txt: cmake min required 3.13 -> 3.5 using CMAKE_REQUIRED_LIBRARIES; add ZINT_COVERAGE option

bmp/emf/ps.c: allow for foreground colour in ULTRA
bmp/gif/pcx.c: allow for BARCODE_STDOUT (fflush/fclose)
emf.c: hexagon rotation field not used; dont't use float index in font loop; Windows stdout binary mode
png.c: remove unused 8-bit; simplify libpng error handling and fclose outfile on error
ps.c: fix buffer overflow on colour_to_pscolor() CMYK
tif.c: fix BLACKISZERO indexes
CODE39: simplify check digit setting
reedsol.c: rs_uint_init_gf() log/alog tables must be zeroed
ZBarcode_Encode: debug: fix access out-of-bounds on non-NUL-terminated source if length < 10
manual.txt/zint.h: document NUL-terminated strings
tests: cover further cases for output (bmp/emf/etc), eci/gb18030/gb2312/sjis, reedsol, AZTEC, CODE39
This commit is contained in:
gitlost 2021-07-26 15:29:05 +01:00
parent 059abdf6a1
commit 3f33ed3eb9
90 changed files with 3754 additions and 863 deletions

View file

@ -40,8 +40,8 @@
#endif
#include "common.h"
static void colour_to_pscolor(int option, int colour, char* output) {
strcpy(output, "");
static void colour_to_pscolor(int option, int colour, char *output) {
*output = '\0';
if ((option & CMYK_COLOUR) == 0) {
// Use RGB colour space
switch (colour) {
@ -142,8 +142,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
float previous_diameter;
float radius, half_radius, half_sqrt3_radius;
int colour_index, colour_rect_counter;
char ps_color[30];
int colour_index, colour_rect_flag;
char ps_color[33]; /* max "1.00 0.00 0.00 0.00 setcmykcolor" = 32 + 1 */
int draw_background = 1;
struct zint_vector_rect *rect;
struct zint_vector_hexagon *hex;
@ -154,24 +154,29 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
int i, len;
int ps_len = 0;
int iso_latin1 = 0;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
#ifdef _MSC_VER
unsigned char *ps_string;
#endif
if (symbol->vector == NULL) {
strcpy(symbol->errtxt, "646: Vector header NULL");
return ZINT_ERROR_INVALID_DATA;
}
if (strlen(symbol->bgcolour) > 6) {
if ((ctoi(symbol->bgcolour[6]) == 0) && (ctoi(symbol->bgcolour[7]) == 0)) {
draw_background = 0;
}
}
if (symbol->output_options & BARCODE_STDOUT) {
if (output_to_stdout) {
feps = stdout;
} else {
feps = fopen(symbol->outfile, "w");
}
if (feps == NULL) {
sprintf(symbol->errtxt, "645: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
if (!(feps = fopen(symbol->outfile, "w"))) {
sprintf(symbol->errtxt, "645: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
locale = setlocale(LC_ALL, "C");
@ -269,7 +274,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
fprintf(feps, "%%%%Title: Zint Generated Symbol\n");
fprintf(feps, "%%%%Pages: 0\n");
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n",
(int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height));
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
fprintf(feps, "%%%%EndComments\n");
/* Definitions */
@ -283,15 +288,15 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
fprintf(feps, "newpath\n");
/* Now the actual representation */
//Background
// Background
if (draw_background) {
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_paper, magenta_paper, yellow_paper, black_paper);
}
fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", symbol->vector->height, symbol->vector->width);
fprintf(feps, "TE\n");
}
@ -306,17 +311,37 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
// Rectangles
if (symbol->symbology == BARCODE_ULTRA) {
for (colour_index = 0; colour_index <= 8; colour_index++) {
colour_rect_counter = 0;
colour_rect_flag = 0;
rect = symbol->vector->rectangles;
while (rect) {
if (rect->colour == -1) { // Foreground
if (colour_rect_flag == 0) {
// Set foreground colour
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n",
cyan_ink, magenta_ink, yellow_ink, black_ink);
}
colour_rect_flag = 1;
}
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
}
rect = rect->next;
}
for (colour_index = 1; colour_index <= 8; colour_index++) {
colour_rect_flag = 0;
rect = symbol->vector->rectangles;
while (rect) {
if (rect->colour == colour_index) {
if (colour_rect_counter == 0) {
//Set new colour
if (colour_rect_flag == 0) {
// Set new colour
colour_to_pscolor(symbol->output_options, colour_index, ps_color);
fprintf(feps, "%s\n", ps_color);
colour_rect_flag = 1;
}
colour_rect_counter++;
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
@ -456,9 +481,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
} while (string);
}
//fprintf(feps, "\nshowpage\n");
if (symbol->output_options & BARCODE_STDOUT) {
if (output_to_stdout) {
fflush(feps);
} else {
fclose(feps);