Allow FNC1 to be implied by mode character in Code 16k and pass reduced string of correct signedness

This commit is contained in:
hooper114 2009-01-13 20:42:45 +00:00
parent 9b569c8717
commit c6728f4c17
4 changed files with 41 additions and 6 deletions

View File

@ -290,6 +290,12 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
glyph_count = glyph_count + 1.0; glyph_count = glyph_count + 1.0;
} }
} }
if((gs1) && (set[0] != 'A')) {
/* FNC1 can be integrated with mode character */
glyph_count--;
}
if(glyph_count > 77.0) { if(glyph_count > 77.0) {
strcpy(symbol->errtxt, "Input too long [232]"); strcpy(symbol->errtxt, "Input too long [232]");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -306,14 +312,24 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
} }
/* start with the mode character - Table 2 */ /* start with the mode character - Table 2 */
read = 0;
m = 0; m = 0;
switch(set[0]) { switch(set[0]) {
case 'A': m = 0; break; case 'A': m = 0; break;
case 'B': m = 1; break; case 'B': m = 1; break;
case 'C': m = 2; break; case 'C': m = 2; break;
} }
if((set[0] == 'B') && (set[1] == 'C')) { m = 5; }
if(((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) { m = 6; } if(gs1) {
/* Integrate FNC1 */
switch(set[0]) {
case 'B': m = 3; read = 1; break;
case 'C': m = 4; read = 1; break;
}
} else {
if((set[0] == 'B') && (set[1] == 'C')) { m = 5; }
if(((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) { m = 6; }
}
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++;
@ -332,7 +348,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
} }
/* Encode the data */ /* Encode the data */
read = 0;
do { do {
if((read != 0) && (set[read] != set[read - 1])) if((read != 0) && (set[read] != set[read - 1]))
@ -463,9 +478,11 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
concat(width_pattern, "1"); concat(width_pattern, "1");
for(i = 0; i < 5; i++) { for(i = 0; i < 5; i++) {
concat(width_pattern, C16KTable[values[(current_row * 5) + i]]); concat(width_pattern, C16KTable[values[(current_row * 5) + i]]);
/* printf("[%d] ", values[(current_row * 5) + i]); */
} }
concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]); concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]);
/* printf("\n"); */
/* Write the information into the symbol */ /* Write the information into the symbol */
writer = 0; writer = 0;

View File

@ -246,4 +246,20 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
/* the character '[' in the reduced string refers to the FNC1 character */ /* the character '[' in the reduced string refers to the FNC1 character */
return 0; return 0;
} }
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], unsigned char reduced[])
{
/* Only to keep the compiler happy */
char temp[ustrlen(source) + 5];
int error_number, i;
error_number = gs1_verify(symbol, source, temp);
if(error_number != 0) { return error_number; }
for(i = 0; i <= strlen(temp); i++) {
reduced[i] = (unsigned char)temp[i];
}
return 0;
}

View File

@ -19,4 +19,5 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[]); int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[]);
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], unsigned char reduced[]);

View File

@ -283,7 +283,8 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source)
break; break;
case GS1_MODE: case GS1_MODE:
if(gs1_compliant(symbol->symbology) == 1) { if(gs1_compliant(symbol->symbology) == 1) {
ustrcpy(preprocessed, source); error_number = ugs1_verify(symbol, source, preprocessed);
if(error_number != 0) { return error_number; }
} else { } else {
strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode");
return ERROR_INVALID_OPTION; return ERROR_INVALID_OPTION;