Ultra: Add colour rectangle output to EPS

This commit is contained in:
Robin Stuart 2020-01-06 18:00:43 +00:00
parent d370f3c0c7
commit 6181885e2e

View File

@ -37,6 +37,70 @@
#include <math.h> #include <math.h>
#include "common.h" #include "common.h"
void colour_to_pscolor(int option, int colour, char* output) {
strcpy(output, "");
if ((option & CMYK_COLOUR) == 0) {
// Use RGB colour space
switch(colour) {
case 0: // White
strcat(output, "1.00 1.00 1.00");
break;
case 1: // Cyan
strcat(output, "0.00 1.00 1.00");
break;
case 2: // Blue
strcat(output, "0.00 0.00 1.00");
break;
case 3: // Magenta
strcat(output, "1.00 0.00 1.00");
break;
case 4: // Red
strcat(output, "1.00 0.00 0.00");
break;
case 5: // Yellow
strcat(output, "1.00 1.00 0.00");
break;
case 6: // Green
strcat(output, "0.00 1.00 0.00");
break;
default: // Black
strcat(output, "0.00 0.00 0.00");
break;
}
strcat(output, " setrgbcolor");
} else {
// Use CMYK colour space
switch(colour) {
case 0: // White
strcat(output, "0.00 0.00 0.00 0.00");
break;
case 1: // Cyan
strcat(output, "1.00 0.00 0.00 0.00");
break;
case 2: // Blue
strcat(output, "1.00 1.00 0.00 0.00");
break;
case 3: // Magenta
strcat(output, "0.00 1.00 0.00 0.00");
break;
case 4: // Red
strcat(output, "0.00 1.00 1.00 0.00");
break;
case 5: // Yellow
strcat(output, "0.00 0.00 1.00 0.00");
break;
case 6: // Green
strcat(output, "1.00 0.00 1.00 0.00");
break;
default: // Black
strcat(output, "0.00 0.00 0.00 1.00");
break;
}
strcat(output, " setcmykcolor");
}
}
int ps_plot(struct zint_symbol *symbol) { int ps_plot(struct zint_symbol *symbol) {
FILE *feps; FILE *feps;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
@ -46,6 +110,8 @@ int ps_plot(struct zint_symbol *symbol) {
int error_number = 0; int error_number = 0;
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy; float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
float radius; float radius;
int colour_index, colour_rect_counter;
char ps_color[30];
struct zint_vector_rect *rect; struct zint_vector_rect *rect;
struct zint_vector_hexagon *hex; struct zint_vector_hexagon *hex;
@ -152,17 +218,40 @@ int ps_plot(struct zint_symbol *symbol) {
fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", symbol->vector->height, symbol->vector->width); fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", symbol->vector->height, symbol->vector->width);
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
if ((symbol->output_options & CMYK_COLOUR) == 0) { if (symbol->symbology != BARCODE_ULTRA) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); if ((symbol->output_options & CMYK_COLOUR) == 0) {
} else { fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink); } else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink);
}
} }
// Rectangles // Rectangles
rect = symbol->vector->rectangles; if (symbol->symbology == BARCODE_ULTRA) {
while (rect) { for (colour_index = 0; colour_index <= 7; colour_index++) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width); colour_rect_counter = 0;
rect = rect->next; rect = symbol->vector->rectangles;
while (rect) {
if (rect->colour == colour_index) {
if (colour_rect_counter == 0) {
//Set new colour
colour_to_pscolor(symbol->output_options, colour_index, ps_color);
fprintf(feps, "%s\n", ps_color);
}
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");
}
rect = rect->next;
}
}
} else {
rect = symbol->vector->rectangles;
while (rect) {
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;
}
} }
// Hexagons // Hexagons
@ -225,7 +314,7 @@ int ps_plot(struct zint_symbol *symbol) {
string = string->next; string = string->next;
} }
fprintf(feps, "\nshowpage\n"); //fprintf(feps, "\nshowpage\n");
if (symbol->output_options & BARCODE_STDOUT) { if (symbol->output_options & BARCODE_STDOUT) {
fflush(feps); fflush(feps);