1
0
mirror of https://git.code.sf.net/p/zint/code synced 2025-12-22 04:17:05 +00:00

ERROR_* renamed to ZERROR_*

errno renamed to err_no
Merged form master
This commit is contained in:
tgotic
2011-01-17 19:44:27 +01:00
parent 03fbe2c2d5
commit 411d4d71e5

View File

@@ -20,7 +20,7 @@
*/
#include <stdio.h>
#ifdef _MSC_VER
#ifdef WIN32
#include <fcntl.h>
#include <io.h>
#endif
@@ -34,8 +34,8 @@
#ifndef NO_PNG
#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
#include "maxipng.h" /* Maxicode shapes */
#endif /* NO_PNG */
#include "maxipng.h" /* Maxicode shapes */
#include "font.h" /* Font for human readable text */
@@ -84,7 +84,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
graphic = &wpng_info;
unsigned long rowbytes;
unsigned char *image_data;
int i, row, column, errno;
int i, row, column, err_no;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
switch(rotate_angle) {
@@ -106,21 +106,21 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
if(strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
if(strlen(symbol->bgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed background colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
if (errno == ERROR_INVALID_DATA) {
err_no = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
if (err_no == ZERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
if (errno == ERROR_INVALID_DATA) {
err_no = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
if (err_no == ZERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed background colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
@@ -132,17 +132,17 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
/* Open output file in binary mode */
if((symbol->output_options & BARCODE_STDOUT) != 0) {
#ifdef _MSC_VER
#ifdef WIN32
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "Can't open output file");
return ERROR_FILE_ACCESS;
return ZERROR_FILE_ACCESS;
}
#endif
graphic->outfile = stdout;
} else {
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "Can't open output file");
return ERROR_FILE_ACCESS;
return ZERROR_FILE_ACCESS;
}
}
@@ -150,21 +150,21 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL);
if (!png_ptr) {
strcpy(symbol->errtxt, "Out of memory");
return ERROR_MEMORY;
return ZERROR_MEMORY;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
strcpy(symbol->errtxt, "Out of memory");
return ERROR_MEMORY;
return ZERROR_MEMORY;
}
/* catch jumping here */
if (setjmp(graphic->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
strcpy(symbol->errtxt, "libpng error occurred");
return ERROR_MEMORY;
return ZERROR_MEMORY;
}
/* open output file with libpng */
@@ -305,7 +305,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle)
{
unsigned long rowbytes;
int i, row, column, errno;
int i, row, column, err_no;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
switch(rotate_angle) {
@@ -333,21 +333,21 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
if(strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
if(strlen(symbol->bgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed background colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
if (errno == ERROR_INVALID_DATA) {
err_no = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
if (err_no == ZERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->fgcolour));
if (errno == ERROR_INVALID_DATA) {
err_no = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->fgcolour));
if (err_no == ZERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed background colour target");
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
}
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
@@ -463,7 +463,7 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
/* Apply scale options by creating another pixel buffer */
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
printf("Insufficient memory for pixel buffer");
return ERROR_ENCODING_PROBLEM;
return ZERROR_ENCODING_PROBLEM;
} else {
for(i = 0; i < (scale_width * scale_height); i++) {
*(scaled_pixelbuf + i) = '0';
@@ -480,7 +480,7 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
#ifndef NO_PNG
error_number = png_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle);
#else
return ERROR_INVALID_OPTION;
return ZERROR_INVALID_OPTION;
#endif
} else {
error_number = bmp_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle);
@@ -557,7 +557,7 @@ void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn)
}
}
void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int image_width, int image_height)
void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int smalltext, int image_width, int image_height)
{
/* Put a letter into a position */
int skip, i, j, glyph_no, alphabet;
@@ -565,6 +565,8 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int
skip = 0;
alphabet = 0;
image_height = 0; /* to silence compiler warning */
if(letter < 33) { skip = 1; }
if((letter > 127) && (letter < 161)) { skip = 1; }
@@ -576,6 +578,21 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int
glyph_no = letter - 33;
}
if(smalltext) {
for(i = 0; i <= 8; i++) {
for(j = 0; j < 5; j++) {
if(alphabet == 0) {
if(small_font[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
}
} else {
if(small_font_extended[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
}
}
}
}
} else {
for(i = 0; i <= 13; i++) {
for(j = 0; j < 7; j++) {
if(alphabet == 0) {
@@ -591,8 +608,9 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int
}
}
}
}
void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int image_width, int image_height)
void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int smalltext, int image_width, int image_height)
{
/* Plot a string into the pixel buffer */
int i, string_length, string_left_hand;
@@ -601,7 +619,7 @@ void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int im
string_left_hand = xposn - ((7 * string_length) / 2);
for(i = 0; i < string_length; i++) {
draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, image_width, image_height);
draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height);
}
}
@@ -621,7 +639,7 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
if (!(pixelbuf = (char *) malloc(image_width * image_height))) {
printf("Insifficient memory for pixel buffer");
return ERROR_ENCODING_PROBLEM;
return ZERROR_ENCODING_PROBLEM;
} else {
for(i = 0; i < (image_width * image_height); i++) {
*(pixelbuf + i) = '0';
@@ -635,13 +653,13 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
for(column = 0; column < symbol->width; column++) {
xposn = column * 10;
if(module_is_set(symbol, row, column)) {
if((row % 2) == 0) {
/* Even (full) row */
draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset));
} else {
if(row & 1) {
/* Odd (reduced) row */
xposn += 5;
draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset));
} else {
/* Even (full) row */
draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset));
}
}
}
@@ -702,7 +720,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
float addon_text_posn, preset_height, large_bar_height;
int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height;
char *pixelbuf;
int addon_latch = 0;
int addon_latch = 0, smalltext = 0;
int this_row, block_width, plot_height, plot_yposn, textpos;
float row_height, row_posn;
int error_number;
@@ -726,6 +744,9 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
comp_offset = 0;
addon_text_posn = 0.0;
row_height = 0;
if(symbol->output_options & SMALL_TEXT) {
smalltext = 1;
}
if (symbol->height == 0) {
symbol->height = 50;
@@ -810,7 +831,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
if (!(pixelbuf = (char *) malloc(image_width * image_height))) {
printf("Insufficient memory for pixel buffer");
return ERROR_ENCODING_PROBLEM;
return ZERROR_ENCODING_PROBLEM;
} else {
for(i = 0; i < (image_width * image_height); i++) {
*(pixelbuf + i) = '0';
@@ -891,22 +912,22 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[4] = '\0';
textpos = 2 * (17 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 4; i++) {
textpart[i] = symbol->text[i + 4];
}
textpart[4] = '\0';
textpos = 2 * (50 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1;
switch(strlen(addon)) {
case 2:
textpos = 2 * (xoffset + 86);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
case 5:
textpos = 2 * (xoffset + 100);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
}
@@ -924,28 +945,28 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[0] = symbol->text[0];
textpart[1] = '\0';
textpos = 2 * (-7 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 6; i++) {
textpart[i] = symbol->text[i + 1];
}
textpart[6] = '\0';
textpos = 2 * (24 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 6; i++) {
textpart[i] = symbol->text[i + 7];
}
textpart[6] = '\0';
textpos = 2 * (71 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1;
switch(strlen(addon)) {
case 2:
textpos = 2 * (xoffset + 114);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
case 5:
textpos = 2 * (xoffset + 128);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
}
break;
@@ -995,32 +1016,32 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[0] = symbol->text[0];
textpart[1] = '\0';
textpos = 2 * (-5 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 5; i++) {
textpart[i] = symbol->text[i + 1];
}
textpart[5] = '\0';
textpos = 2 * (27 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 5; i++) {
textpart[i] = symbol->text[i + 6];
}
textpart[6] = '\0';
textpos = 2 * (68 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textpart[0] = symbol->text[11];
textpart[1] = '\0';
textpos = 2 * (100 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1;
switch(strlen(addon)) {
case 2:
textpos = 2 * (xoffset + 116);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
case 5:
textpos = 2 * (xoffset + 130);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
}
@@ -1037,26 +1058,26 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[0] = symbol->text[0];
textpart[1] = '\0';
textpos = 2 * (-5 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 6; i++) {
textpart[i] = symbol->text[i + 1];
}
textpart[6] = '\0';
textpos = 2 * (24 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textpart[0] = symbol->text[7];
textpart[1] = '\0';
textpos = 2 * (55 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1;
switch(strlen(addon)) {
case 2:
textpos = 2 * (xoffset + 70);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
case 5:
textpos = 2 * (xoffset + 84);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break;
}
@@ -1088,7 +1109,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
/* Put the human readable text at the bottom */
if((textdone == 0) && (ustrlen(local_text) != 0)) {
textpos = (image_width / 2);
draw_string(pixelbuf, (char*)local_text, textpos, default_text_posn, image_width, image_height);
draw_string(pixelbuf, (char*)local_text, textpos, default_text_posn, smalltext, image_width, image_height);
}
error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);