extended ASCII bug fix

This commit is contained in:
hooper114 2008-09-02 19:34:27 +00:00
parent 89f02b7dd5
commit 00aeeea0b1
2 changed files with 54 additions and 30 deletions

View File

@ -134,17 +134,26 @@ void dxsmooth(int *indexliste)
}
void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars)
{ /* Translate Code 128 Set A characters into barcodes */
/* This set handles all control characters NULL to US */
if(source > 127) {
concat(dest, C128Table[source + 64 - 128]);
values[(*bar_chars)] = source + 64 - 128;
if(source < 160) {
concat(dest, C128Table[(source - 128) + 64]);
values[(*bar_chars)] = (source - 128) + 64;
} else {
concat(dest, C128Table[(source - 128) - 32]);
values[(*bar_chars)] = (source - 128) - 32;
}
} else {
concat(dest, C128Table[source + 64]);
values[(*bar_chars)] = source + 64;
if(source < 32) {
concat(dest, C128Table[source + 64]);
values[(*bar_chars)] = source + 64;
} else {
concat(dest, C128Table[source - 32]);
values[(*bar_chars)] = source - 32;
}
}
(*bar_chars)++;
}
@ -184,6 +193,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
errornum = 0;
strcpy(dest, "");
sourcelen = strlen(source);
j = 0;
@ -236,24 +246,33 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
}
/* Detect extended ASCII characters */
for(i = 0; i < sourcelen; i++) {
if(source[i] >=128) {
for(i = 0; i < sourcelen; i++) {
if(source[i] >= 128) {
fset[i] = 'f';
} else {
fset[i] = ' ';
}
}
fset[i] = '\0';
/* Decide when to latch to extended mode - Annex E note 3 */
j = 0;
for(i = 0; i < sourcelen; i++) {
j = 0;
if(fset[i] == 'f') {
do {
j++;
} while(source[i + j] == 'f');
if((j >= 5) || ((j >= 3) && ((i + j) == sourcelen))) {
for(k = 0; k <= j; k++) {
source[i + k] = 'F';
}
j++;
} else {
j = 0;
}
if(j >= 5) {
for(k = i; k > (i - 5); k--) {
fset[k] = 'F';
}
}
if((j >= 3) && (i == (sourcelen - 1))) {
for(k = i; k > (i - 3); k--) {
fset[k] = 'F';
}
}
}
@ -385,6 +404,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
return ERROR_TOO_LONG;
}
/* So now we know what start character to use - we can get on with it! */
switch(set[0])
{
@ -489,13 +509,15 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
}
}
if(fset[i] == 'f') {
if(fset[read] == 'f') {
/* Shift extended mode */
switch(set[i]) {
switch(set[read]) {
case 'a':
case 'A':
concat(dest, C128Table[101]);
values[bar_characters] = 101;
break;
case 'b':
case 'B':
concat(dest, C128Table[100]);
values[bar_characters] = 100;
@ -504,7 +526,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
bar_characters++;
}
if((set[i] == 'a') || (set[i] == 'b')) {
if((set[read] == 'a') || (set[read] == 'b')) {
/* Insert shift character */
concat(dest, C128Table[98]);
values[bar_characters] = 98;
@ -526,12 +548,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
break;
}
/* printf("vals: ");
for(i = 0; i < bar_characters; i++) {
printf("%d, ", values[i]);
}
printf("\n"); */
} while (read < sourcelen);
/* check digit calculation */

View File

@ -107,9 +107,17 @@ void reysmooth(int *indexliste)
void c16k_set_a(unsigned char source, int values[], int *bar_chars)
{
if(source > 127) {
values[(*bar_chars)] = source + 64 - 128;
if(source < 160) {
values[(*bar_chars)] = source + 64 - 128;
} else {
values[(*bar_chars)] = source - 32 - 128;
}
} else {
values[(*bar_chars)] = source + 64;
if(source < 32) {
values[(*bar_chars)] = source + 64;
} else {
values[(*bar_chars)] = source - 32;
}
}
(*bar_chars)++;
}