Allow output to stdout

This commit is contained in:
hooper114 2008-12-21 12:17:14 +00:00
parent db6757ab91
commit ef80d11beb
4 changed files with 33 additions and 13 deletions

View File

@ -110,15 +110,17 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
/* Open output file in binary mode */
if((symbol->output_options & BARCODE_STDOUT) != 0) {
graphic->outfile = stdout;
} else {
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "Can't open output file [B5]");
return ERROR_FILE_ACCESS;
}
/* graphic->outfile = stdout; */
}
/* Set up error handling routine as proc() above */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic,
writepng_error_handler, NULL);
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL);
if (!png_ptr) {
strcpy(symbol->errtxt, "Out of memory [B6]");
return ERROR_MEMORY;
@ -758,7 +760,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle)
xoffset -= comp_offset;
/* Put boundary bars or box around symbol */
if ((symbol->output_options == BARCODE_BOX) || (symbol->output_options == BARCODE_BIND)) {
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
if(symbol->symbology != BARCODE_CODABLOCKF) {
/* boundary bars */
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * scaler, textoffset * scaler, symbol->border_width * scaler, image_width, image_height);
@ -782,7 +784,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle)
}
}
if (symbol->output_options == BARCODE_BOX) {
if((symbol->output_options & BARCODE_BOX) != 0) {
/* side bars */
draw_bar(pixelbuf, 0, symbol->border_width * scaler, textoffset * scaler, (symbol->height + (2 * symbol->border_width)) * scaler, image_width, image_height);
draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler, textoffset * scaler, (symbol->height + (2 * symbol->border_width)) * scaler, image_width, image_height);

View File

@ -66,7 +66,11 @@ int ps_plot(struct zint_symbol *symbol)
comp_offset = 0;
addon_text_posn = 0.0;
if((symbol->output_options & BARCODE_STDOUT) != 0) {
feps = stdout;
} else {
feps = fopen(symbol->outfile, "w");
}
if(feps == NULL) {
strcpy(symbol->errtxt, "Could not open output file [C1]");
return ERROR_FILE_ACCESS;
@ -683,7 +687,7 @@ int ps_plot(struct zint_symbol *symbol)
/* Put boundary bars or box around symbol */
if ((symbol->output_options == BARCODE_BOX) || (symbol->output_options == BARCODE_BIND)) {
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
if(symbol->symbology != BARCODE_CODABLOCKF) {
/* boundary bars */
fprintf(feps, "TE\n");
@ -719,7 +723,7 @@ int ps_plot(struct zint_symbol *symbol)
}
}
if (symbol->output_options == BARCODE_BOX) {
if((symbol->output_options & BARCODE_BOX) != 0) {
/* side bars */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);

View File

@ -129,6 +129,7 @@ struct zint_symbol {
#define BARCODE_NO_ASCII 1
#define BARCODE_BIND 2
#define BARCODE_BOX 4
#define BARCODE_STDOUT 8
#define WARN_INVALID_OPTION 2
#define ERROR_TOO_LONG 5

View File

@ -73,6 +73,9 @@ void usage(void)
" -r, --reverse Reverse colours (white on black).\n"
" --fg=COLOUR Specify a foreground colour.\n"
" --bg=COLOUR Specify a background colour.\n"
" --scale=NUMBER Adjust size of output image.\n"
" --directpng Send PNG output to stdout\n"
" --directeps Send EPS output to stdout\n"
" --rotate=NUMBER Rotate symbol (PNG output only).\n"
" --cols=NUMBER (PDF417) Number of columns.\n"
" --vers=NUMBER (QR Code) Version\n"
@ -180,6 +183,8 @@ int main(int argc, char **argv)
{"types", 0, 0, 't'},
{"bind", 0, 0, 0},
{"box", 0, 0, 0},
{"directeps", 0, 0, 0},
{"directpng", 0, 0, 0},
{"barcode=", 1, 0, 'b'},
{"height=", 1, 0, 0},
{"whitesp=", 1, 0, 'w'},
@ -205,10 +210,18 @@ int main(int argc, char **argv)
switch(c) {
case 0:
if(!strcmp(long_options[option_index].name, "bind")) {
my_symbol->output_options = BARCODE_BIND;
my_symbol->output_options += BARCODE_BIND;
}
if(!strcmp(long_options[option_index].name, "box")) {
my_symbol->output_options = BARCODE_BOX;
my_symbol->output_options += BARCODE_BOX;
}
if(!strcmp(long_options[option_index].name, "directeps")) {
my_symbol->output_options += BARCODE_STDOUT;
strncpy(my_symbol->outfile, "dummy.eps", 10);
}
if(!strcmp(long_options[option_index].name, "directpng")) {
my_symbol->output_options += BARCODE_STDOUT;
strncpy(my_symbol->outfile, "dummy.png", 10);
}
if(!strcmp(long_options[option_index].name, "fg=")) {
strncpy(my_symbol->fgcolour, optarg, 7);