From c6728f4c17d0a2f50441cb88427eb3656a10432d Mon Sep 17 00:00:00 2001 From: hooper114 Date: Tue, 13 Jan 2009 20:42:45 +0000 Subject: [PATCH] Allow FNC1 to be implied by mode character in Code 16k and pass reduced string of correct signedness --- backend/code16k.c | 23 ++++++++++++++++++++--- backend/gs1.c | 18 +++++++++++++++++- backend/gs1.h | 3 ++- backend/library.c | 3 ++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/backend/code16k.c b/backend/code16k.c index 3f138318..551da627 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -290,6 +290,12 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) 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) { strcpy(symbol->errtxt, "Input too long [232]"); return ERROR_TOO_LONG; @@ -306,14 +312,24 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) } /* start with the mode character - Table 2 */ + read = 0; m = 0; switch(set[0]) { case 'A': m = 0; break; case 'B': m = 1; 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 */ bar_characters++; @@ -332,7 +348,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) } /* Encode the data */ - read = 0; do { 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"); for(i = 0; i < 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]]); + /* printf("\n"); */ /* Write the information into the symbol */ writer = 0; diff --git a/backend/gs1.c b/backend/gs1.c index f37dd95c..0f6b0b21 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -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 */ return 0; -} \ No newline at end of file +} + +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; +} diff --git a/backend/gs1.h b/backend/gs1.h index 7d593716..2cfd315a 100644 --- a/backend/gs1.h +++ b/backend/gs1.h @@ -19,4 +19,5 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[]); \ No newline at end of file +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[]); \ No newline at end of file diff --git a/backend/library.c b/backend/library.c index 25ac1c60..5b8d2d8b 100644 --- a/backend/library.c +++ b/backend/library.c @@ -283,7 +283,8 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) break; case GS1_MODE: if(gs1_compliant(symbol->symbology) == 1) { - ustrcpy(preprocessed, source); + error_number = ugs1_verify(symbol, source, preprocessed); + if(error_number != 0) { return error_number; } } else { strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); return ERROR_INVALID_OPTION;