Set latching problems with Code 128.

This commit is contained in:
hooper114 2009-05-13 08:01:30 +00:00
parent d6d88b6bc1
commit 2170302bf5
2 changed files with 45 additions and 20 deletions

View File

@ -198,7 +198,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
{ /* Handle Code 128 and NVE-18 */ { /* Handle Code 128 and NVE-18 */
int i, j, k, e_count, values[170], bar_characters, read, total_sum, nve_check; int i, j, k, e_count, values[170], bar_characters, read, total_sum, nve_check;
int error_number, indexchaine, indexliste, sourcelen; int error_number, indexchaine, indexliste, sourcelen;
char set[170], fset[170], mode, last_set, last_fset; char set[170], fset[170], mode, last_set, last_fset, current_set = ' ';
float glyph_count; float glyph_count;
char dest[1000]; char dest[1000];
@ -391,20 +391,24 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
case 'A': /* Start A */ case 'A': /* Start A */
concat(dest, C128Table[103]); concat(dest, C128Table[103]);
values[0] = 103; values[0] = 103;
current_set = 'A';
break; break;
case 'B': /* Start B */ case 'B': /* Start B */
concat(dest, C128Table[104]); concat(dest, C128Table[104]);
values[0] = 104; values[0] = 104;
current_set = 'B';
break; break;
case 'C': /* Start C */ case 'C': /* Start C */
concat(dest, C128Table[105]); concat(dest, C128Table[105]);
values[0] = 105; values[0] = 105;
current_set = 'C';
break; break;
} }
bar_characters++; bar_characters++;
last_set = set[0];
if(fset[0] == 'F') { if(fset[0] == 'F') {
switch(set[0]) { switch(current_set) {
case 'A': case 'A':
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
@ -425,21 +429,24 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
read = 0; read = 0;
do { do {
if((read != 0) && (set[read] != set[read - 1])) if((read != 0) && (set[read] != current_set))
{ /* Latch different code set */ { /* Latch different code set */
switch(set[read]) switch(set[read])
{ {
case 'A': concat(dest, C128Table[101]); case 'A': concat(dest, C128Table[101]);
values[bar_characters] = 101; values[bar_characters] = 101;
bar_characters++; bar_characters++;
current_set = 'A';
break; break;
case 'B': concat(dest, C128Table[100]); case 'B': concat(dest, C128Table[100]);
values[bar_characters] = 100; values[bar_characters] = 100;
bar_characters++; bar_characters++;
current_set = 'B';
break; break;
case 'C': concat(dest, C128Table[99]); case 'C': concat(dest, C128Table[99]);
values[bar_characters] = 99; values[bar_characters] = 99;
bar_characters++; bar_characters++;
current_set = 'C';
break; break;
} }
} }
@ -447,7 +454,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
if((read != 0) && (fset[read] != fset[read - 1])) { if((read != 0) && (fset[read] != fset[read - 1])) {
if(fset[read] == 'F') { if(fset[read] == 'F') {
/* Latch beginning of extended mode */ /* Latch beginning of extended mode */
switch(set[0]) { switch(current_set) {
case 'A': case 'A':
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
@ -465,7 +472,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
} }
if(fset[read - 1] == 'F') { if(fset[read - 1] == 'F') {
/* Latch end of extended mode */ /* Latch end of extended mode */
switch(set[0]) { switch(current_set) {
case 'A': case 'A':
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
@ -485,13 +492,11 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
if(fset[read] == 'f') { if(fset[read] == 'f') {
/* Shift extended mode */ /* Shift extended mode */
switch(set[read]) { switch(current_set) {
case 'a':
case 'A': case 'A':
concat(dest, C128Table[101]); concat(dest, C128Table[101]);
values[bar_characters] = 101; values[bar_characters] = 101;
break; break;
case 'b':
case 'B': case 'B':
concat(dest, C128Table[100]); concat(dest, C128Table[100]);
values[bar_characters] = 100; values[bar_characters] = 100;

View File

@ -117,7 +117,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
char width_pattern[100]; char width_pattern[100];
int current_row, rows_needed, flip_flop, looper, first_check, second_check; int current_row, rows_needed, flip_flop, looper, first_check, second_check;
int indexliste, indexchaine, pads_needed; int indexliste, indexchaine, pads_needed;
char set[160], fset[160], mode, last_set, last_fset; char set[160], fset[160], mode, last_set, last_fset, current_set;
unsigned int i, j, k, m, e_count, read, mx_reader, writer; unsigned int i, j, k, m, e_count, read, mx_reader, writer;
unsigned int values[160]; unsigned int values[160];
unsigned int bar_characters; unsigned int bar_characters;
@ -228,6 +228,23 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
} }
} }
/* Adjust for strings which start with shift characters - make them latch instead */
if(set[0] == 'a') {
i = 0;
do {
set[i] = 'A';
i++;
} while (set[i] == 'a');
}
if(set[0] == 'b') {
i = 0;
do {
set[i] = 'B';
i++;
} while (set[i] == 'b');
}
/* We have a problem with FNC1 in Code Set C to resolve */ /* We have a problem with FNC1 in Code Set C to resolve */
for(i = 0; i < input_length; i++) { for(i = 0; i < input_length; i++) {
if((set[i] == 'C') && (source[i] == '[')) { if((set[i] == 'C') && (source[i] == '[')) {
@ -332,8 +349,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */ values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
bar_characters++; bar_characters++;
current_set = set[0];
if(fset[0] == 'F') { if(fset[0] == 'F') {
switch(set[0]) { switch(current_set) {
case 'A': case 'A':
values[bar_characters] = 101; values[bar_characters] = 101;
values[bar_characters + 1] = 101; values[bar_characters + 1] = 101;
@ -346,11 +364,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
bar_characters += 2; bar_characters += 2;
} }
for(j = 0; j < ustrlen(source); j++) {
if(set[j] == 'a') { set[j] = 'A'; }
if(set[j] == 'b') { set[j] = 'B'; }
}
read = 0; read = 0;
/* Encode the data */ /* Encode the data */
do { do {
@ -362,10 +375,12 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
case 'A': case 'A':
values[bar_characters] = 101; values[bar_characters] = 101;
bar_characters++; bar_characters++;
current_set = 'A';
break; break;
case 'B': case 'B':
values[bar_characters] = 100; values[bar_characters] = 100;
bar_characters++; bar_characters++;
current_set = 'B';
break; break;
case 'C': case 'C':
if(!((read == 1) && (set[0] == 'B'))) { /* Not Mode C/Shift B */ if(!((read == 1) && (set[0] == 'B'))) { /* Not Mode C/Shift B */
@ -375,6 +390,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
bar_characters++; bar_characters++;
} }
} }
current_set = 'C';
break; break;
} }
} }
@ -382,7 +398,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
if((read != 0) && (fset[read] != fset[read - 1])) { if((read != 0) && (fset[read] != fset[read - 1])) {
if(fset[read] == 'F') { if(fset[read] == 'F') {
/* Latch beginning of extended mode */ /* Latch beginning of extended mode */
switch(set[0]) { switch(current_set) {
case 'A': case 'A':
values[bar_characters] = 101; values[bar_characters] = 101;
values[bar_characters + 1] = 101; values[bar_characters + 1] = 101;
@ -396,7 +412,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
} }
if(fset[read - 1] == 'F') { if(fset[read - 1] == 'F') {
/* Latch end of extended mode */ /* Latch end of extended mode */
switch(set[0]) { switch(current_set) {
case 'A': case 'A':
values[bar_characters] = 101; values[bar_characters] = 101;
values[bar_characters + 1] = 101; values[bar_characters + 1] = 101;
@ -412,7 +428,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
if(fset[i] == 'f') { if(fset[i] == 'f') {
/* Shift extended mode */ /* Shift extended mode */
switch(set[i]) { switch(current_set) {
case 'A': case 'A':
values[bar_characters] = 101; values[bar_characters] = 101;
break; break;
@ -432,10 +448,14 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
if(!((gs1) && (source[read] == '['))) { if(!((gs1) && (source[read] == '['))) {
switch(set[read]) switch(set[read])
{ /* Encode data characters */ { /* Encode data characters */
case 'A': c16k_set_a(source[read], values, &bar_characters, symbol->nullchar); case 'A':
case 'a':
c16k_set_a(source[read], values, &bar_characters, symbol->nullchar);
read++; read++;
break; break;
case 'B': c16k_set_b(source[read], values, &bar_characters); case 'B':
case 'b':
c16k_set_b(source[read], values, &bar_characters);
read++; read++;
break; break;
case 'C': c16k_set_c(source[read], source[read + 1], values, &bar_characters); case 'C': c16k_set_c(source[read], source[read + 1], values, &bar_characters);