1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-01-12 22:46:03 +00:00

latin1_process function changed

This commit is contained in:
tgotic
2011-05-16 20:03:21 +02:00
parent 3407239b80
commit d550f18d90
7 changed files with 68 additions and 80 deletions

View File

@@ -680,8 +680,11 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
local_source[length] = '\0';
break;
case UNICODE_MODE:
err_code = latin1_process(symbol, source, local_source, &length);
if(err_code != 0) { return err_code; }
err_code = latin1_process(source, local_source, &length);
if(err_code != 0) {
strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)");
return err_code;
}
break;
}
@@ -1317,7 +1320,7 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
rs_encode(2, data_codewords, ecc_codewords);
rs_free();
strcpy(binary_string, "");
memset(binary_string, 0, 28);
for(i = 0; i < 5; i++) {
if(ecc_codewords[4 - i] & 0x08) { binary_string[(i * 4) + 8] = '1'; } else { binary_string[(i * 4) + 8] = '0'; }

View File

@@ -283,40 +283,41 @@ float froundup(float input)
return output;
}
int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length)
int latin1_process(unsigned char source[], unsigned char preprocessed[], int *length)
{
int j, i, next;
/* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
j = 0;
i = 0;
do {
next = -1;
if(source[i] < 128) {
preprocessed[j] = source[i];
j++;
next = i + 1;
} else {
if(source[i] == 0xC2) {
preprocessed[j] = source[i + 1];
if (length && *length) {
do {
next = -1;
if(source[i] < 128) {
preprocessed[j] = source[i];
j++;
next = i + 2;
next = i + 1;
} else {
if(source[i] == 0xC2) {
preprocessed[j] = source[i + 1];
j++;
next = i + 2;
}
if(source[i] == 0xC3) {
preprocessed[j] = source[i + 1] + 64;
j++;
next = i + 2;
}
}
if(source[i] == 0xC3) {
preprocessed[j] = source[i + 1] + 64;
j++;
next = i + 2;
if(next == -1) {
return ZERROR_INVALID_DATA;
}
}
if(next == -1) {
strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)");
return ZERROR_INVALID_DATA;
}
i = next;
} while(i < *length);
preprocessed[j] = '\0';
*length = j;
i = next;
} while(i < *length);
preprocessed[j] = '\0';
*length = j;
}
return 0;
}

View File

@@ -61,7 +61,7 @@ extern void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord);
extern int istwodigits(unsigned char source[], int position);
extern float froundup(float input);
extern int parunmodd(unsigned char llyth);
extern int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length);
extern int latin1_process(unsigned char source[], unsigned char preprocessed[], int *length);
extern int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length);
#ifdef __cplusplus
}

View File

@@ -469,8 +469,11 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt
preprocessed[length] = '\0';
break;
case UNICODE_MODE:
error_number = latin1_process(symbol, source, preprocessed, &length);
if(error_number != 0) { return error_number; }
error_number = latin1_process(source, preprocessed, &length);
if(error_number != 0) {
strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)");
return error_number;
}
break;
}

View File

@@ -575,8 +575,11 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
local_source[length] = '\0';
break;
case UNICODE_MODE:
error_number = latin1_process(symbol, source, local_source, &length);
if(error_number != 0) { return error_number; }
error_number = latin1_process(source, local_source, &length);
if(error_number != 0) {
strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)");
return error_number;
}
break;
}
memset(maxi_codeword, 0, sizeof(maxi_codeword));

View File

@@ -680,62 +680,33 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
return error_number;
}
void to_latin1(unsigned char source[], unsigned char preprocessed[])
{
int j, i, input_length;
input_length = ustrlen(source);
j = 0;
i = 0;
do {
if(source[i] < 128) {
preprocessed[j] = source[i];
j++;
i++;
} else {
if(source[i] == 0xC2) {
preprocessed[j] = source[i + 1];
j++;
i += 2;
}
if(source[i] == 0xC3) {
preprocessed[j] = source[i + 1] + 64;
j++;
i += 2;
}
}
} while (i < input_length);
preprocessed[j] = '\0';
return;
}
int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
{
int textdone, main_width, comp_offset, large_bar_count;
char textpart[10], addon[6];
float addon_text_posn, preset_height, large_bar_height;
int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height;
char *pixelbuf;
char *pixelbuf = NULL;
int addon_latch = 0, smalltext = 0;
int this_row, block_width, plot_height, plot_yposn, textpos;
float row_height, row_posn;
int error_number;
int default_text_posn;
int next_yposn;
#ifndef _MSC_VER
unsigned char local_text[ustrlen(symbol->text) + 1];
#else
unsigned char* local_text = (unsigned char*)_alloca(ustrlen(symbol->text) + 1);
#endif
unsigned char* local_text = NULL;
int tlen = ustrlen(symbol->text);
if(symbol->show_hrt != 0) {
to_latin1(symbol->text, local_text);
} else {
local_text[0] = '\0';
if (tlen) {
local_text = (unsigned char*)calloc(tlen + 1, sizeof(char));
if (NULL == local_text) {
strcpy(symbol->errtxt, "Out of memory");
return ZERROR_MEMORY;
}
}
if(symbol->show_hrt != 0 && tlen)
latin1_process(symbol->text, local_text, &tlen);
textdone = 0;
main_width = symbol->width;
strcpy(addon, "");
@@ -773,7 +744,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|| (symbol->symbology == BARCODE_ISBNX)) {
switch(ustrlen(local_text)) {
switch(tlen) {
case 13: /* EAN 13 */
case 16:
case 19:
@@ -805,7 +776,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
r = 0;
/* Isolate add-on text */
if(is_extendable(symbol->symbology)) {
for(i = 0; i < ustrlen(local_text); i++) {
for(i = 0; i < tlen; i++) {
if (latch == 1) {
addon[r] = local_text[i];
r++;
@@ -817,7 +788,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
}
addon[r] = '\0';
if(ustrlen(local_text) != 0) {
if(tlen) {
textoffset = 9;
} else {
textoffset = 0;
@@ -829,6 +800,9 @@ 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");
if(local_text)
free(local_text);
return ZERROR_ENCODING_PROBLEM;
} else {
for(i = 0; i < (image_width * image_height); i++) {
@@ -894,7 +868,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
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 */
switch(ustrlen(local_text)) {
switch(tlen) {
case 8: /* EAN-8 */
case 11:
case 14:
@@ -1105,13 +1079,17 @@ 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)) {
if((textdone == 0) && tlen) {
textpos = (image_width / 2);
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);
free(pixelbuf);
if (local_text)
free(local_text);
return error_number;
}

View File

@@ -5,7 +5,7 @@
;******************************************************************************
!define PRODUCT_NAME "Zint"
!define PRODUCT_EXE "qtZint.exe"
!define PRODUCT_VERSION "2.4.2.0"
!define PRODUCT_VERSION "2.4.2.2"
!define PRODUCT_WEB_SITE "http://www.zint.org.uk"
!define PRODUCT_PUBLISHER "Robin Stuart & BogDan Vatra"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_EXE}"