mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Various minor bugfixes
This commit is contained in:
parent
f3e8505fd4
commit
93d65a910c
@ -53,6 +53,7 @@ struct zint_symbol *ZBarcode_Create()
|
||||
symbol->option_1 = -1;
|
||||
symbol->option_2 = 0;
|
||||
symbol->option_3 = 928; // PDF_MAX
|
||||
symbol->show_hrt = 1; // Show human readable text
|
||||
symbol->input_mode = DATA_MODE;
|
||||
strcpy(symbol->primary, "");
|
||||
for(i = 0; i < 178; i++) {
|
||||
@ -82,6 +83,7 @@ void ZBarcode_Clear(struct zint_symbol *symbol)
|
||||
symbol->errtxt[0] = '\0';
|
||||
if (symbol->bitmap != NULL)
|
||||
free(symbol->bitmap);
|
||||
symbol->bitmap = NULL;
|
||||
symbol->bitmap_width = 0;
|
||||
symbol->bitmap_height = 0;
|
||||
}
|
||||
|
@ -714,7 +714,11 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
||||
unsigned char* local_text = (unsigned char*)_alloca(ustrlen(symbol->text) + 1);
|
||||
#endif
|
||||
|
||||
if(symbol->show_hrt != 0) {
|
||||
to_latin1(symbol->text, local_text);
|
||||
} else {
|
||||
local_text[0] = '\0';
|
||||
}
|
||||
|
||||
textdone = 0;
|
||||
main_width = symbol->width;
|
||||
|
10
backend/ps.c
10
backend/ps.c
@ -44,6 +44,7 @@ int ps_plot(struct zint_symbol *symbol)
|
||||
float addon_text_posn;
|
||||
float scaler = symbol->scale;
|
||||
float default_text_posn;
|
||||
int plot_text = 1;
|
||||
|
||||
row_height=0;
|
||||
textdone = 0;
|
||||
@ -167,7 +168,10 @@ int ps_plot(struct zint_symbol *symbol)
|
||||
}
|
||||
addon[r] = '\0';
|
||||
|
||||
if(ustrlen(symbol->text) != 0) {
|
||||
if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
|
||||
plot_text = 0;
|
||||
}
|
||||
if(plot_text) {
|
||||
textoffset = 9;
|
||||
} else {
|
||||
textoffset = 0;
|
||||
@ -327,6 +331,7 @@ int ps_plot(struct zint_symbol *symbol)
|
||||
|
||||
xoffset += comp_offset;
|
||||
|
||||
if (plot_text) {
|
||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
|
||||
(symbol->symbology == BARCODE_ISBNX)) {
|
||||
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
||||
@ -693,6 +698,7 @@ int ps_plot(struct zint_symbol *symbol)
|
||||
}
|
||||
|
||||
}
|
||||
} /* if (plot_text) */
|
||||
|
||||
xoffset -= comp_offset;
|
||||
|
||||
@ -743,7 +749,7 @@ int ps_plot(struct zint_symbol *symbol)
|
||||
}
|
||||
|
||||
/* Put the human readable text at the bottom */
|
||||
if((textdone == 0) && (ustrlen(symbol->text) != 0)) {
|
||||
if(plot_text && (textdone == 0)) {
|
||||
fprintf(feps, "TE\n");
|
||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||
fprintf(feps, "matrix currentmatrix\n");
|
||||
|
@ -1077,7 +1077,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
char* general_field_type = (char*)_alloca(strlen(source));
|
||||
#endif
|
||||
int remainder, d1, d2, value;
|
||||
char padstring[14];
|
||||
char padstring[40];
|
||||
|
||||
read_posn=0;
|
||||
value=0;
|
||||
@ -1643,19 +1643,34 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
}
|
||||
|
||||
latch = general_rules(general_field, general_field_type);
|
||||
if(debug) printf("General field type: %s\n", general_field_type);
|
||||
|
||||
last_mode = NUMERIC;
|
||||
|
||||
/* Set initial mode if not NUMERIC */
|
||||
if(general_field_type[0] == ALPHA) {
|
||||
concat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
last_mode = ALPHA;
|
||||
}
|
||||
if(general_field_type[0] == ISOIEC) {
|
||||
concat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
concat(binary_string, "00100"); /* ISO/IEC 646 latch */
|
||||
last_mode = ISOIEC;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
if(debug) printf("Processing character %d ", i);
|
||||
switch(general_field_type[i]) {
|
||||
case NUMERIC:
|
||||
if(debug) printf("as NUMERIC\n");
|
||||
if(i != 0) {
|
||||
if((general_field_type[i - 1] != NUMERIC) && (general_field[i - 1] != '[')) {
|
||||
if(debug) printf("as NUMERIC:");
|
||||
|
||||
if(last_mode != NUMERIC) {
|
||||
concat(binary_string, "000"); /* Numeric latch */
|
||||
}
|
||||
if(debug) printf("<NUMERIC LATCH>\n");
|
||||
}
|
||||
|
||||
if(debug) printf(" %c%c > ", general_field[i], general_field[i + 1]);
|
||||
if(general_field[i] != '[') {
|
||||
d1 = ctoi(general_field[i]);
|
||||
} else {
|
||||
@ -1674,24 +1689,27 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
for(j = 0; j < 7; j++) {
|
||||
if((value & mask) == 0x00) {
|
||||
concat(binary_string, "0");
|
||||
if(debug) printf("0");
|
||||
} else {
|
||||
concat(binary_string, "1");
|
||||
if(debug) printf("1");
|
||||
}
|
||||
mask = mask >> 1;
|
||||
}
|
||||
|
||||
i += 2;
|
||||
if(debug) printf("\n");
|
||||
last_mode = NUMERIC;
|
||||
break;
|
||||
|
||||
case ALPHA:
|
||||
if(debug) printf("as ALPHA\n");
|
||||
if(i != 0) {
|
||||
if((general_field_type[i - 1] == NUMERIC) || (general_field[i - 1] == '[')) {
|
||||
if(last_mode == NUMERIC) {
|
||||
concat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
}
|
||||
if(general_field_type[i - 1] == ISOIEC) {
|
||||
concat(binary_string, "00100"); /* ISO/IEC 646 latch */
|
||||
if(last_mode == ISOIEC) {
|
||||
concat(binary_string, "00100"); /* Alphanumeric latch */
|
||||
}
|
||||
}
|
||||
|
||||
@ -1725,7 +1743,8 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
}
|
||||
}
|
||||
|
||||
if(general_field[i] == '[') concat(binary_string, "01111"); /* FNC1/Numeric latch */
|
||||
last_mode = ALPHA;
|
||||
if(general_field[i] == '[') { concat(binary_string, "01111"); last_mode = NUMERIC; } /* FNC1/Numeric latch */
|
||||
if(general_field[i] == '*') concat(binary_string, "111010"); /* asterisk */
|
||||
if(general_field[i] == ',') concat(binary_string, "111011"); /* comma */
|
||||
if(general_field[i] == '-') concat(binary_string, "111100"); /* minus or hyphen */
|
||||
@ -1733,17 +1752,16 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
if(general_field[i] == '/') concat(binary_string, "111110"); /* slash or solidus */
|
||||
|
||||
i++;
|
||||
last_mode = ALPHA;
|
||||
break;
|
||||
|
||||
case ISOIEC:
|
||||
if(debug) printf("as ISOIEC\n");
|
||||
if(i != 0) {
|
||||
if((general_field_type[i - 1] == NUMERIC) || (general_field[i - 1] == '[')) {
|
||||
if(last_mode == NUMERIC) {
|
||||
concat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
concat(binary_string, "00100"); /* ISO/IEC 646 latch */
|
||||
}
|
||||
if(general_field_type[i - 1] == ALPHA) {
|
||||
if(last_mode == ALPHA) {
|
||||
concat(binary_string, "00100"); /* ISO/IEC 646 latch */
|
||||
}
|
||||
}
|
||||
@ -1793,7 +1811,8 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
}
|
||||
}
|
||||
|
||||
if(general_field[i] == '[') concat(binary_string, "01111"); /* FNC1/Numeric latch */
|
||||
last_mode = ISOIEC;
|
||||
if(general_field[i] == '[') { concat(binary_string, "01111"); last_mode = NUMERIC; } /* FNC1/Numeric latch */
|
||||
if(general_field[i] == '!') concat(binary_string, "11101000"); /* exclamation mark */
|
||||
if(general_field[i] == 34) concat(binary_string, "11101001"); /* quotation mark */
|
||||
if(general_field[i] == 37) concat(binary_string, "11101010"); /* percent sign */
|
||||
@ -1817,20 +1836,21 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
if(general_field[i] == ' ') concat(binary_string, "11111100"); /* space */
|
||||
|
||||
i++;
|
||||
last_mode = ISOIEC;
|
||||
break;
|
||||
}
|
||||
} while (i + latch < strlen(general_field));
|
||||
if(debug) printf("Resultant binary = %s\n", binary_string);
|
||||
if(debug) printf("\tLength: %d\n", strlen(binary_string));
|
||||
if(debug) printf("\tLength: %d\n", (int)strlen(binary_string));
|
||||
|
||||
remainder = strlen(binary_string) % 12;
|
||||
remainder = 12 - (strlen(binary_string) % 12);
|
||||
if(remainder == 12) { remainder = 0; }
|
||||
if(strlen(binary_string) < 36) { remainder = 36 - strlen(binary_string); }
|
||||
|
||||
if(latch == 1) {
|
||||
/* There is still one more numeric digit to encode */
|
||||
if(debug) printf("Adding extra (odd) numeric digit\n");
|
||||
|
||||
if(last_mode == NUMERIC) {
|
||||
if((remainder >= 4) && (remainder <= 6)) {
|
||||
value = ctoi(general_field[i]);
|
||||
value++;
|
||||
@ -1860,11 +1880,25 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
mask = mask >> 1;
|
||||
}
|
||||
}
|
||||
remainder = strlen(binary_string) % 12;
|
||||
} else {
|
||||
value = general_field[i] - 43;
|
||||
|
||||
mask = 0x10;
|
||||
for(j = 0; j < 5; j++) {
|
||||
if((value & mask) == 0x00) {
|
||||
concat(binary_string, "0");
|
||||
} else {
|
||||
concat(binary_string, "1");
|
||||
}
|
||||
mask = mask >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
remainder = 12 - (strlen(binary_string) % 12);
|
||||
if(remainder == 12) { remainder = 0; }
|
||||
if(strlen(binary_string) < 36) { remainder = 36 - strlen(binary_string); }
|
||||
last_mode = NUMERIC;
|
||||
if(debug) printf("Resultant binary = %s\n", binary_string);
|
||||
if(debug) printf("\tLength: %d\n", strlen(binary_string));
|
||||
if(debug) printf("\tLength: %d\n", (int)strlen(binary_string));
|
||||
}
|
||||
|
||||
if(strlen(binary_string) > 252) {
|
||||
@ -1872,18 +1906,18 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* Now add padding to binary string */
|
||||
if(strlen(general_field) != 0) {
|
||||
if (last_mode == NUMERIC) {
|
||||
strcpy(padstring, "000000100001");
|
||||
/* Now add padding to binary string (7.2.5.5.4) */
|
||||
i = remainder;
|
||||
if((strlen(general_field) != 0) && (last_mode == NUMERIC)) {
|
||||
strcpy(padstring, "0000");
|
||||
i -= 4;
|
||||
} else {
|
||||
strcpy(padstring, "001000010000");
|
||||
strcpy(padstring, "");
|
||||
}
|
||||
} else {
|
||||
strcpy(padstring, "001000010000");
|
||||
for(;i > 0;i -= 5) {
|
||||
concat(padstring, "00100");
|
||||
}
|
||||
remainder = 12 - remainder;
|
||||
if(remainder == 12) { remainder = 0; }
|
||||
|
||||
padstring[remainder] = '\0';
|
||||
concat(binary_string, padstring);
|
||||
|
||||
@ -1904,7 +1938,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
if(d2 == 0) { binary_string[7] = '0'; } else { binary_string[7] = '1'; }
|
||||
}
|
||||
if(debug) printf("Resultant binary = %s\n", binary_string);
|
||||
if(debug) printf("\tLength: %d\n", strlen(binary_string));
|
||||
if(debug) printf("\tLength: %d\n", (int)strlen(binary_string));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ int svg_plot(struct zint_symbol *symbol)
|
||||
float addon_text_posn;
|
||||
float scaler = symbol->scale;
|
||||
float default_text_posn;
|
||||
int plot_text = 1;
|
||||
|
||||
row_height=0;
|
||||
textdone = 0;
|
||||
@ -163,7 +164,10 @@ int svg_plot(struct zint_symbol *symbol)
|
||||
}
|
||||
addon[r] = '\0';
|
||||
|
||||
if(ustrlen(symbol->text) != 0) {
|
||||
if((symbol->show_hrt == 0) || (ustrlen(symbol->text) != 0)) {
|
||||
plot_text = 0;
|
||||
}
|
||||
if(plot_text) {
|
||||
textoffset = 9;
|
||||
} else {
|
||||
textoffset = 0;
|
||||
@ -310,6 +314,7 @@ int svg_plot(struct zint_symbol *symbol)
|
||||
xoffset += comp_offset;
|
||||
row_posn = (row_posn + large_bar_height) * scaler;
|
||||
|
||||
if(plot_text) {
|
||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
|
||||
(symbol->symbology == BARCODE_ISBNX)) {
|
||||
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
||||
@ -556,6 +561,7 @@ int svg_plot(struct zint_symbol *symbol)
|
||||
}
|
||||
|
||||
}
|
||||
} /* if (plot_text) */
|
||||
|
||||
xoffset -= comp_offset;
|
||||
|
||||
@ -596,7 +602,7 @@ int svg_plot(struct zint_symbol *symbol)
|
||||
}
|
||||
|
||||
/* Put the human readable text at the bottom */
|
||||
if((textdone == 0) && (ustrlen(symbol->text) != 0)) {
|
||||
if(plot_text && (textdone == 0)) {
|
||||
textpos = symbol->width / 2.0;
|
||||
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", (textpos + xoffset) * scaler, default_text_posn);
|
||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
||||
|
@ -388,6 +388,7 @@ char isbn13_check(unsigned char source[]) /* For ISBN(13) only */
|
||||
char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
|
||||
{
|
||||
unsigned int i, weight, sum, check, h;
|
||||
char check_char;
|
||||
|
||||
sum = 0;
|
||||
weight = 1;
|
||||
@ -400,7 +401,9 @@ char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
|
||||
}
|
||||
|
||||
check = sum % 11;
|
||||
return itoc(check);
|
||||
check_char = itoc(check);
|
||||
if(check == 10) { check_char = 'X'; }
|
||||
return check_char;
|
||||
}
|
||||
|
||||
int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char dest[]) /* Make an EAN-13 barcode from an SBN or ISBN */
|
||||
|
@ -38,6 +38,7 @@ struct zint_symbol {
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
int show_hrt;
|
||||
int input_mode;
|
||||
unsigned char text[128];
|
||||
int rows;
|
||||
|
@ -65,6 +65,11 @@ void QZint::encode()
|
||||
m_zintSymbol->option_1=m_securityLevel;
|
||||
m_zintSymbol->input_mode = m_input_mode;
|
||||
m_zintSymbol->option_2=m_width;
|
||||
if(m_hidetext) {
|
||||
m_zintSymbol->show_hrt = 0;
|
||||
} else {
|
||||
m_zintSymbol->show_hrt = 1;
|
||||
}
|
||||
if(m_symbol == BARCODE_PDF417) {
|
||||
m_zintSymbol->option_3=m_pdf417CodeWords;
|
||||
} else {
|
||||
@ -76,9 +81,6 @@ void QZint::encode()
|
||||
int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data(), bstr.length());
|
||||
if (error > WARN_INVALID_OPTION)
|
||||
m_lastError=m_zintSymbol->errtxt;
|
||||
if(m_hidetext) {
|
||||
m_zintSymbol->text[0] = (unsigned char) '\0';
|
||||
}
|
||||
|
||||
if (m_zintSymbol->symbology == BARCODE_MAXICODE)
|
||||
m_zintSymbol->height = 33;
|
||||
@ -259,6 +261,11 @@ bool QZint::save_to_file(QString filename)
|
||||
m_zintSymbol->option_1=m_securityLevel;
|
||||
m_zintSymbol->input_mode = m_input_mode;
|
||||
m_zintSymbol->option_2=m_width;
|
||||
if(m_hidetext) {
|
||||
m_zintSymbol->show_hrt = 0;
|
||||
} else {
|
||||
m_zintSymbol->show_hrt = 1;
|
||||
}
|
||||
if(m_symbol == BARCODE_PDF417) {
|
||||
m_zintSymbol->option_3=m_pdf417CodeWords;
|
||||
} else {
|
||||
@ -277,9 +284,6 @@ bool QZint::save_to_file(QString filename)
|
||||
int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data(), bstr.length());
|
||||
if (error > WARN_INVALID_OPTION)
|
||||
m_lastError=m_zintSymbol->errtxt;
|
||||
if(m_hidetext) {
|
||||
m_zintSymbol->text[0] = (unsigned char) '\0';
|
||||
}
|
||||
error = ZBarcode_Print(m_zintSymbol, 0);
|
||||
if (error > WARN_INVALID_OPTION)
|
||||
m_lastError=m_zintSymbol->errtxt;
|
||||
@ -573,6 +577,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
|
||||
|
||||
textdone = false;
|
||||
|
||||
if(m_hidetext == false) {
|
||||
painter.setFont(fontSmall);
|
||||
if(((m_zintSymbol->symbology == BARCODE_EANX) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) ||
|
||||
(m_zintSymbol->symbology == BARCODE_ISBNX)) {
|
||||
@ -689,8 +694,9 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
|
||||
painter.setFont(fontSmall);
|
||||
textdone = true;
|
||||
}
|
||||
} /* if (m_hidetext == false) */
|
||||
|
||||
if((caption.isEmpty() == false) && (textdone == false)) {
|
||||
if((m_hidetext == false) && (textdone == false)) {
|
||||
/* Add text to any other symbol */
|
||||
painter.drawText(0, m_zintSymbol->height + yoffset, m_zintSymbol->width, 7, Qt::AlignCenter, caption);
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ void usage(void)
|
||||
" --gs1 Treat input as GS1 data\n"
|
||||
" --binary Treat input as Binary data\n"
|
||||
" --notext Remove human readable text\n"
|
||||
" --square Force Data Matrix symbols to be square\n"
|
||||
, ZINT_VERSION);
|
||||
}
|
||||
|
||||
@ -120,14 +121,12 @@ int main(int argc, char **argv)
|
||||
int error_number;
|
||||
int rotate_angle;
|
||||
int generated;
|
||||
int suppress_human_readable;
|
||||
|
||||
error_number = 0;
|
||||
rotate_angle = 0;
|
||||
generated = 0;
|
||||
my_symbol = ZBarcode_Create();
|
||||
my_symbol->input_mode = UNICODE_MODE;
|
||||
suppress_human_readable = 0;
|
||||
|
||||
if(argc == 1) {
|
||||
usage();
|
||||
@ -166,6 +165,7 @@ int main(int argc, char **argv)
|
||||
{"sjis", 0, 0, 0},
|
||||
{"binary", 0, 0, 0},
|
||||
{"notext", 0, 0, 0},
|
||||
{"square", 0, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
c = getopt_long(argc, argv, "htb:w:d:o:i:rcmp", long_options, &option_index);
|
||||
@ -210,7 +210,10 @@ int main(int argc, char **argv)
|
||||
strncpy(my_symbol->bgcolour, optarg, 7);
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "notext")) {
|
||||
suppress_human_readable = 1;
|
||||
my_symbol->show_hrt = 0;
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "square")) {
|
||||
my_symbol->option_3 = DM_SQUARE;
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "scale")) {
|
||||
my_symbol->scale = (float)(atof(optarg));
|
||||
@ -331,9 +334,6 @@ int main(int argc, char **argv)
|
||||
case 'd': /* we have some data! */
|
||||
error_number = ZBarcode_Encode(my_symbol, (unsigned char*)optarg, strlen(optarg));
|
||||
if(error_number == 0) {
|
||||
if(suppress_human_readable) {
|
||||
my_symbol->text[0] = (unsigned char)'\0';
|
||||
}
|
||||
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
||||
}
|
||||
generated = 1;
|
||||
@ -347,9 +347,6 @@ int main(int argc, char **argv)
|
||||
case 'i': /* Take data from file */
|
||||
error_number = ZBarcode_Encode_File(my_symbol, optarg);
|
||||
if(error_number == 0) {
|
||||
if(suppress_human_readable) {
|
||||
my_symbol->text[0] = (unsigned char)'\0';
|
||||
}
|
||||
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
||||
}
|
||||
generated = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user