Code format and audit, part 1

Update copyright info, remove unused code, etc.
This commit is contained in:
Robin Stuart 2016-02-20 09:38:03 +00:00
parent ae335b104a
commit 77cdf77690
23 changed files with 21568 additions and 20025 deletions

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -39,331 +39,332 @@
#define inline _inline #define inline _inline
#endif #endif
static const char *C25MatrixTable[10] = {"113311", "311131", "131131", "331111", "113131", "313111", static const char *C25MatrixTable[10] = {
"133111", "111331", "311311", "131311"}; "113311", "311131", "131131", "331111", "113131", "313111",
"133111", "111331", "311311", "131311"
};
static const char *C25IndustTable[10] = {"1111313111", "3111111131", "1131111131", "3131111111", "1111311131", static const char *C25IndustTable[10] = {
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"}; "1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"
};
static const char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133", static const char *C25InterTable[10] = {
"31131", "13131"}; "11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
"31131", "13131"
};
static inline char check_digit(unsigned int count) static inline char check_digit(unsigned int count) {
{ return itoc((10 - (count % 10)) % 10);
return itoc((10 - (count % 10)) % 10);
} }
int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
{ /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number;
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
error_number = 0; int i, error_number;
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
if(length > 80) { error_number = 0;
strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
/* start character */ if (length > 80) {
strcpy(dest, "411111"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
for(i = 0; i < length; i++) { /* start character */
lookup(NEON, C25MatrixTable, source[i], dest); strcpy(dest, "411111");
}
/* Stop character */ for (i = 0; i < length; i++) {
concat (dest, "41111"); lookup(NEON, C25MatrixTable, source[i], dest);
}
expand(symbol, dest); /* Stop character */
ustrcpy(symbol->text, source); concat(dest, "41111");
return error_number;
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Industrial */
{ /* Code 2 of 5 Industrial */ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; /* 6 + 40 * 10 + 6 + 1 */ char dest[512]; /* 6 + 40 * 10 + 6 + 1 */
error_number = 0; error_number = 0;
if(length > 45) { if (length > 45) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid character in data"); strcpy(symbol->errtxt, "Invalid character in data");
return error_number; return error_number;
} }
/* start character */ /* start character */
strcpy(dest, "313111"); strcpy(dest, "313111");
for(i = 0; i < length; i++) { for (i = 0; i < length; i++) {
lookup(NEON, C25IndustTable, source[i], dest); lookup(NEON, C25IndustTable, source[i], dest);
} }
/* Stop character */ /* Stop character */
concat (dest, "31113"); concat(dest, "31113");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
return error_number; return error_number;
} }
int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 IATA */
{ /* Code 2 of 5 IATA */ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; /* 4 + 45 * 10 + 3 + 1 */ char dest[512]; /* 4 + 45 * 10 + 3 + 1 */
error_number = 0; error_number = 0;
if(length > 45) { if (length > 45) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
/* start */ /* start */
strcpy(dest, "1111"); strcpy(dest, "1111");
for(i = 0; i < length; i++) {
lookup(NEON, C25IndustTable, source[i], dest);
}
/* stop */ for (i = 0; i < length; i++) {
concat (dest, "311"); lookup(NEON, C25IndustTable, source[i], dest);
}
expand(symbol, dest); /* stop */
ustrcpy(symbol->text, source); concat(dest, "311");
return error_number;
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Data Logic */
{ /* Code 2 of 5 Data Logic */ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number;
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
error_number = 0; int i, error_number;
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
if(length > 80) { error_number = 0;
strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
/* start character */ if (length > 80) {
strcpy(dest, "1111"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
for(i = 0; i < length; i++) { /* start character */
lookup(NEON, C25MatrixTable, source[i], dest); strcpy(dest, "1111");
}
/* Stop character */ for (i = 0; i < length; i++) {
concat (dest, "311"); lookup(NEON, C25MatrixTable, source[i], dest);
}
expand(symbol, dest); /* Stop character */
ustrcpy(symbol->text, source); concat(dest, "311");
return error_number;
expand(symbol, dest);
ustrcpy(symbol->text, source);
return error_number;
} }
int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Interleaved */
{ /* Code 2 of 5 Interleaved */ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, k, error_number; int i, j, k, error_number;
char bars[7], spaces[7], mixed[14], dest[1000]; char bars[7], spaces[7], mixed[14], dest[1000];
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char temp[length + 2]; unsigned char temp[length + 2];
#else #else
unsigned char* temp = (unsigned char *)_alloca((length + 2) * sizeof(unsigned char)); unsigned char* temp = (unsigned char *) _alloca((length + 2) * sizeof (unsigned char));
#endif #endif
error_number = 0; error_number = 0;
if(length > 89) { if (length > 89) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
ustrcpy(temp, (unsigned char *) ""); ustrcpy(temp, (unsigned char *) "");
/* Input must be an even number of characters for Interlaced 2 of 5 to work: /* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered then add a leading zero */ if an odd number of characters has been entered then add a leading zero */
if (length & 1) if (length & 1) {
{ ustrcpy(temp, (unsigned char *) "0");
ustrcpy(temp, (unsigned char *) "0"); length++;
length++; }
} uconcat(temp, source);
uconcat(temp, source);
/* start character */ /* start character */
strcpy(dest, "1111"); strcpy(dest, "1111");
for(i = 0; i < length; i+=2 ) for (i = 0; i < length; i += 2) {
{ /* look up the bars and the spaces and put them in two strings */
/* look up the bars and the spaces and put them in two strings */ strcpy(bars, "");
strcpy(bars, ""); lookup(NEON, C25InterTable, temp[i], bars);
lookup(NEON, C25InterTable, temp[i], bars); strcpy(spaces, "");
strcpy(spaces, ""); lookup(NEON, C25InterTable, temp[i + 1], spaces);
lookup(NEON, C25InterTable, temp[i + 1], spaces);
/* then merge (interlace) the strings together */ /* then merge (interlace) the strings together */
k = 0; k = 0;
for(j = 0; j <= 4; j++) for (j = 0; j <= 4; j++) {
{ mixed[k] = bars[j];
mixed[k] = bars[j]; k++; k++;
mixed[k] = spaces[j]; k++; mixed[k] = spaces[j];
} k++;
mixed[k] = '\0'; }
concat (dest, mixed); mixed[k] = '\0';
} concat(dest, mixed);
}
/* Stop character */ /* Stop character */
concat (dest, "311"); concat(dest, "311");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, temp); ustrcpy(symbol->text, temp);
return error_number; return error_number;
} }
int itf14(struct zint_symbol *symbol, unsigned char source[], int length) /* Interleaved 2-of-5 (ITF) */
{ int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
error_number = 0; error_number = 0;
count = 0; count = 0;
if(length > 13) { if (length > 13) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid character in data"); strcpy(symbol->errtxt, "Invalid character in data");
return error_number; return error_number;
} }
/* Add leading zeros as required */ /* Add leading zeros as required */
zeroes = 13 - length; zeroes = 13 - length;
for(i = 0; i < zeroes; i++) { for (i = 0; i < zeroes; i++) {
localstr[i] = '0'; localstr[i] = '0';
} }
strcpy(localstr + zeroes, (char *)source); strcpy(localstr + zeroes, (char *) source);
/* Calculate the check digit - the same method used for EAN-13 */ /* Calculate the check digit - the same method used for EAN-13 */
for (i = 12; i >= 0; i--) {
count += ctoi(localstr[i]);
for (i = 12; i >= 0; i--) { if (!(i & 1)) {
count += ctoi(localstr[i]); count += 2 * ctoi(localstr[i]);
}
if (!(i & 1)) { }
count += 2 * ctoi(localstr[i]); localstr[13] = check_digit(count);
} localstr[14] = '\0';
} error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
localstr[13] = check_digit(count); ustrcpy(symbol->text, (unsigned char*) localstr);
localstr[14] = '\0'; return error_number;
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
ustrcpy(symbol->text, (unsigned char*)localstr);
return error_number;
} }
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) /* Deutshe Post Leitcode */
{ /* Deutshe Post Leitcode */ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
int zeroes; int zeroes;
error_number = 0; error_number = 0;
count = 0; count = 0;
if(length > 13) { if (length > 13) {
strcpy(symbol->errtxt, "Input wrong length"); strcpy(symbol->errtxt, "Input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
zeroes = 13 - length; zeroes = 13 - length;
for(i = 0; i < zeroes; i++) for (i = 0; i < zeroes; i++)
localstr[i] = '0'; localstr[i] = '0';
strcpy(localstr + zeroes, (char *)source); strcpy(localstr + zeroes, (char *) source);
for (i = 12; i >= 0; i--)
{
count += 4 * ctoi(localstr[i]);
if (i & 1) { for (i = 12; i >= 0; i--) {
count += 5 * ctoi(localstr[i]); count += 4 * ctoi(localstr[i]);
}
} if (i & 1) {
localstr[13] = check_digit(count); count += 5 * ctoi(localstr[i]);
localstr[14] = '\0'; }
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr)); }
ustrcpy(symbol->text, (unsigned char*)localstr); localstr[13] = check_digit(count);
return error_number; localstr[14] = '\0';
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
ustrcpy(symbol->text, (unsigned char*) localstr);
return error_number;
} }
int dpident(struct zint_symbol *symbol, unsigned char source[], int length) /* Deutsche Post Identcode */
{ /* Deutsche Post Identcode */ int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
count = 0; count = 0;
if(length > 11) { if (length > 11) {
strcpy(symbol->errtxt, "Input wrong length"); strcpy(symbol->errtxt, "Input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
zeroes = 11 - length; zeroes = 11 - length;
for(i = 0; i < zeroes; i++) for (i = 0; i < zeroes; i++)
localstr[i] = '0'; localstr[i] = '0';
strcpy(localstr + zeroes, (char *)source); strcpy(localstr + zeroes, (char *) source);
for (i = 10; i >= 0; i--)
{
count += 4 * ctoi(localstr[i]);
if (i & 1) { for (i = 10; i >= 0; i--) {
count += 5 * ctoi(localstr[i]); count += 4 * ctoi(localstr[i]);
}
} if (i & 1) {
localstr[11] = check_digit(count); count += 5 * ctoi(localstr[i]);
localstr[12] = '\0'; }
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr)); }
ustrcpy(symbol->text, (unsigned char*)localstr); localstr[11] = check_digit(count);
return error_number; localstr[12] = '\0';
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
ustrcpy(symbol->text, (unsigned char*) localstr);
return error_number;
} }

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -28,25 +28,31 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" #define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
static const char *AusNTable[10] = {"00", "01", "02", "10", "11", "12", "20", "21", "22", "30"}; static const char *AusNTable[10] = {
"00", "01", "02", "10", "11", "12", "20", "21", "22", "30"
};
static const char *AusCTable[64] = {"222", "300", "301", "302", "310", "311", "312", "320", "321", "322", static const char *AusCTable[64] = {
"000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110", "222", "300", "301", "302", "310", "311", "312", "320", "321", "322",
"111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221", "000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110",
"023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203", "111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221",
"213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333", "023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203",
"003", "013"}; "213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333",
"003", "013"
};
static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011", "012", "013", "020", "021", static const char *AusBarTable[64] = {
"022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112", "000", "001", "002", "003", "010", "011", "012", "013", "020", "021",
"113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203", "022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112",
"210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300", "113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203",
"301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331", "210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300",
"332", "333"}; "301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331",
"332", "333"
};
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -57,204 +63,191 @@ static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011",
#define inline _inline #define inline _inline
#endif #endif
static inline char convert_pattern(char data, int shift) static inline char convert_pattern(char data, int shift) {
{ return (data - '0') << shift;
return (data - '0') << shift;
} }
void rs_error(char data_pattern[]) /* Adds Reed-Solomon error correction to auspost */
{ void rs_error(char data_pattern[]) {
/* Adds Reed-Solomon error correction to auspost */ int reader, triple_writer = 0;
char triple[31], inv_triple[31];
unsigned char result[5];
int reader, triple_writer = 0; for (reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++) {
char triple[31], inv_triple[31]; triple[triple_writer] = convert_pattern(data_pattern[reader], 4)
unsigned char result[5]; + convert_pattern(data_pattern[reader + 1], 2)
+ convert_pattern(data_pattern[reader + 2], 0);
}
for(reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++) for (reader = 0; reader < triple_writer; reader++) {
{ inv_triple[reader] = triple[(triple_writer - 1) - reader];
triple[triple_writer] = convert_pattern(data_pattern[reader], 4) }
+ convert_pattern(data_pattern[reader + 1], 2)
+ convert_pattern(data_pattern[reader + 2], 0);
}
for(reader = 0; reader < triple_writer; reader++) rs_init_gf(0x43);
{ rs_init_code(4, 1);
inv_triple[reader] = triple[(triple_writer - 1) - reader]; rs_encode(triple_writer, (unsigned char*) inv_triple, result);
}
rs_init_gf(0x43); for (reader = 4; reader > 0; reader--) {
rs_init_code(4, 1); concat(data_pattern, AusBarTable[(int) result[reader - 1]]);
rs_encode(triple_writer, (unsigned char*) inv_triple, result); }
rs_free();
for(reader = 4; reader > 0; reader--)
{
concat(data_pattern, AusBarTable[(int)result[reader - 1]]);
}
rs_free();
} }
int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) /* Handles Australia Posts's 4 State Codes */
{ int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Handles Australia Posts's 4 State Codes */ /* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically
/* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically (i.e. the FCC doesn't need to be specified by the user) dependent
(i.e. the FCC doesn't need to be specified by the user) dependent on the length of the input string */
on the length of the input string */
/* The contents of data_pattern conform to the following standard: /* The contents of data_pattern conform to the following standard:
0 = Tracker, Ascender and Descender 0 = Tracker, Ascender and Descender
1 = Tracker and Ascender 1 = Tracker and Ascender
2 = Tracker and Descender 2 = Tracker and Descender
3 = Tracker only */ 3 = Tracker only */
int error_number, zeroes; int error_number, zeroes;
int writer; int writer;
unsigned int loopey, reader, h; unsigned int loopey, reader, h;
char data_pattern[200]; char data_pattern[200];
char fcc[3] = {0, 0}, dpid[10]; char fcc[3] = {0, 0}, dpid[10];
char localstr[30]; char localstr[30];
error_number = 0; error_number = 0;
strcpy(localstr, ""); strcpy(localstr, "");
/* Do all of the length checking first to avoid stack smashing */ /* Do all of the length checking first to avoid stack smashing */
if(symbol->symbology == BARCODE_AUSPOST) { if (symbol->symbology == BARCODE_AUSPOST) {
/* Format control code (FCC) */ /* Format control code (FCC) */
switch(length) switch (length) {
{ case 8:
case 8: strcpy(fcc, "11");
strcpy(fcc, "11"); break;
break; case 13:
case 13: strcpy(fcc, "59");
strcpy(fcc, "59"); break;
break; case 16:
case 16: strcpy(fcc, "59");
strcpy(fcc, "59"); error_number = is_sane(NEON, source, length);
error_number = is_sane(NEON, source, length); break;
break; case 18:
case 18: strcpy(fcc, "62");
strcpy(fcc, "62"); break;
break; case 23:
case 23: strcpy(fcc, "62");
strcpy(fcc, "62"); error_number = is_sane(NEON, source, length);
error_number = is_sane(NEON, source, length); break;
break; default:
default: strcpy(symbol->errtxt, "Auspost input is wrong length");
strcpy(symbol->errtxt, "Auspost input is wrong length"); return ZINT_ERROR_TOO_LONG;
return ZINT_ERROR_TOO_LONG; }
} if (error_number == ZINT_ERROR_INVALID_DATA) {
if(error_number == ZINT_ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data");
strcpy(symbol->errtxt, "Invalid characters in data"); return error_number;
return error_number; }
} } else {
} else { if (length > 8) {
if (length > 8) { strcpy(symbol->errtxt, "Auspost input is too long");
strcpy(symbol->errtxt, "Auspost input is too long"); return ZINT_ERROR_TOO_LONG;
return ZINT_ERROR_TOO_LONG; }
} switch (symbol->symbology) {
switch(symbol->symbology) { case BARCODE_AUSREPLY: strcpy(fcc, "45");
case BARCODE_AUSREPLY: strcpy(fcc, "45"); break; break;
case BARCODE_AUSROUTE: strcpy(fcc, "87"); break; case BARCODE_AUSROUTE: strcpy(fcc, "87");
case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break; break;
} case BARCODE_AUSREDIRECT: strcpy(fcc, "92");
break;
}
/* Add leading zeros as required */ /* Add leading zeros as required */
zeroes = 8 - length; zeroes = 8 - length;
memset(localstr, '0', zeroes); memset(localstr, '0', zeroes);
localstr[8] = '\0'; localstr[8] = '\0';
} }
concat(localstr, (char*)source); concat(localstr, (char*) source);
h = strlen(localstr); h = strlen(localstr);
error_number = is_sane(GDSET, (unsigned char *)localstr, h); error_number = is_sane(GDSET, (unsigned char *) localstr, h);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
/* Verifiy that the first 8 characters are numbers */ /* Verifiy that the first 8 characters are numbers */
memcpy(dpid, localstr, 8); memcpy(dpid, localstr, 8);
dpid[8] = '\0'; dpid[8] = '\0';
error_number = is_sane(NEON, (unsigned char *)dpid, strlen(dpid)); error_number = is_sane(NEON, (unsigned char *) dpid, strlen(dpid));
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in DPID"); strcpy(symbol->errtxt, "Invalid characters in DPID");
return error_number; return error_number;
} }
/* Start character */ /* Start character */
strcpy(data_pattern, "13"); strcpy(data_pattern, "13");
/* Encode the FCC */ /* Encode the FCC */
for(reader = 0; reader < 2; reader++) for (reader = 0; reader < 2; reader++) {
{ lookup(NEON, AusNTable, fcc[reader], data_pattern);
lookup(NEON, AusNTable, fcc[reader], data_pattern); }
}
/* printf("AUSPOST FCC: %s ", fcc); */ /* printf("AUSPOST FCC: %s ", fcc); */
/* Delivery Point Identifier (DPID) */ /* Delivery Point Identifier (DPID) */
for(reader = 0; reader < 8; reader++) for (reader = 0; reader < 8; reader++) {
{ lookup(NEON, AusNTable, dpid[reader], data_pattern);
lookup(NEON, AusNTable, dpid[reader], data_pattern); }
}
/* Customer Information */ /* Customer Information */
if(h > 8) if (h > 8) {
{ if ((h == 13) || (h == 18)) {
if((h == 13) || (h == 18)) { for (reader = 8; reader < h; reader++) {
for(reader = 8; reader < h; reader++) { lookup(GDSET, AusCTable, localstr[reader], data_pattern);
lookup(GDSET, AusCTable, localstr[reader], data_pattern); }
} } else if ((h == 16) || (h == 23)) {
} for (reader = 8; reader < h; reader++) {
else if((h == 16) || (h == 23)) { lookup(NEON, AusNTable, localstr[reader], data_pattern);
for(reader = 8; reader < h; reader++) { }
lookup(NEON, AusNTable, localstr[reader], data_pattern); }
} }
}
}
/* Filler bar */ /* Filler bar */
h = strlen(data_pattern); h = strlen(data_pattern);
switch (h) switch (h) {
{ case 22:
case 22: case 37:
case 37: case 52:
case 52: concat(data_pattern, "3");
concat(data_pattern, "3"); break;
break; default:
default: break;
break; }
}
/* Reed Solomon error correction */ /* Reed Solomon error correction */
rs_error(data_pattern); rs_error(data_pattern);
/* Stop character */ /* Stop character */
concat(data_pattern, "13"); concat(data_pattern, "13");
/* Turn the symbol into a bar pattern ready for plotting */ /* Turn the symbol into a bar pattern ready for plotting */
writer = 0; writer = 0;
h = strlen(data_pattern); h = strlen(data_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) {
if((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) set_module(symbol, 0, writer);
{ }
set_module(symbol, 0, writer); set_module(symbol, 1, writer);
} if ((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) {
set_module(symbol, 1, writer); set_module(symbol, 2, writer);
if((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) }
{ writer += 2;
set_module(symbol, 2, writer); }
}
writer += 2;
}
symbol->row_height[0] = 3; symbol->row_height[0] = 3;
symbol->row_height[1] = 2; symbol->row_height[1] = 2;
symbol->row_height[2] = 3; symbol->row_height[2] = 3;
symbol->rows = 3; symbol->rows = 3;
symbol->width = writer - 1; symbol->width = writer - 1;
return error_number; return error_number;
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -28,7 +28,7 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#define UPPER 1 #define UPPER 1
#define LOWER 2 #define LOWER 2
@ -39,112 +39,139 @@
static int AztecMap[22801]; static int AztecMap[22801];
static const int CompactAztecMap[] = { /* 27 x 27 data grid */ static const int CompactAztecMap[] = {
609,608,411,413,415,417,419,421,423,425,427,429,431,433,435,437,439,441,443,445,447,449,451,453,455,457,459, /* 27 x 27 data grid */
607,606,410,412,414,416,418,420,422,424,426,428,430,432,434,436,438,440,442,444,446,448,450,452,454,456,458, 609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459,
605,604,409,408,243,245,247,249,251,253,255,257,259,261,263,265,267,269,271,273,275,277,279,281,283,460,461, 607, 606, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458,
603,602,407,406,242,244,246,248,250,252,254,256,258,260,262,264,266,268,270,272,274,276,278,280,282,462,463, 605, 604, 409, 408, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 460, 461,
601,600,405,404,241,240,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,284,285,464,465, 603, 602, 407, 406, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 462, 463,
599,598,403,402,239,238,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,286,287,466,467, 601, 600, 405, 404, 241, 240, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 284, 285, 464, 465,
597,596,401,400,237,236,105,104,3,5,7,9,11,13,15,17,19,21,23,25,27,140,141,288,289,468,469, 599, 598, 403, 402, 239, 238, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 286, 287, 466, 467,
595,594,399,398,235,234,103,102,2,4,6,8,10,12,14,16,18,20,22,24,26,142,143,290,291,470,471, 597, 596, 401, 400, 237, 236, 105, 104, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 140, 141, 288, 289, 468, 469,
593,592,397,396,233,232,101,100,1,1,2000,2001,2002,2003,2004,2005,2006,0,1,28,29,144,145,292,293,472,473, 595, 594, 399, 398, 235, 234, 103, 102, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 142, 143, 290, 291, 470, 471,
591,590,395,394,231,230,99,98,1,1,1,1,1,1,1,1,1,1,1,30,31,146,147,294,295,474,475, 593, 592, 397, 396, 233, 232, 101, 100, 1, 1, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 0, 1, 28, 29, 144, 145, 292, 293, 472, 473,
589,588,393,392,229,228,97,96,2027,1,0,0,0,0,0,0,0,1,2007,32,33,148,149,296,297,476,477, 591, 590, 395, 394, 231, 230, 99, 98, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 30, 31, 146, 147, 294, 295, 474, 475,
587,586,391,390,227,226,95,94,2026,1,0,1,1,1,1,1,0,1,2008,34,35,150,151,298,299,478,479, 589, 588, 393, 392, 229, 228, 97, 96, 2027, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2007, 32, 33, 148, 149, 296, 297, 476, 477,
585,584,389,388,225,224,93,92,2025,1,0,1,0,0,0,1,0,1,2009,36,37,152,153,300,301,480,481, 587, 586, 391, 390, 227, 226, 95, 94, 2026, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2008, 34, 35, 150, 151, 298, 299, 478, 479,
583,582,387,386,223,222,91,90,2024,1,0,1,0,1,0,1,0,1,2010,38,39,154,155,302,303,482,483, 585, 584, 389, 388, 225, 224, 93, 92, 2025, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2009, 36, 37, 152, 153, 300, 301, 480, 481,
581,580,385,384,221,220,89,88,2023,1,0,1,0,0,0,1,0,1,2011,40,41,156,157,304,305,484,485, 583, 582, 387, 386, 223, 222, 91, 90, 2024, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2010, 38, 39, 154, 155, 302, 303, 482, 483,
579,578,383,382,219,218,87,86,2022,1,0,1,1,1,1,1,0,1,2012,42,43,158,159,306,307,486,487, 581, 580, 385, 384, 221, 220, 89, 88, 2023, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2011, 40, 41, 156, 157, 304, 305, 484, 485,
577,576,381,380,217,216,85,84,2021,1,0,0,0,0,0,0,0,1,2013,44,45,160,161,308,309,488,489, 579, 578, 383, 382, 219, 218, 87, 86, 2022, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2012, 42, 43, 158, 159, 306, 307, 486, 487,
575,574,379,378,215,214,83,82,0,1,1,1,1,1,1,1,1,1,1,46,47,162,163,310,311,490,491, 577, 576, 381, 380, 217, 216, 85, 84, 2021, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2013, 44, 45, 160, 161, 308, 309, 488, 489,
573,572,377,376,213,212,81,80,0,0,2020,2019,2018,2017,2016,2015,2014,0,0,48,49,164,165,312,313,492,493, 575, 574, 379, 378, 215, 214, 83, 82, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, 47, 162, 163, 310, 311, 490, 491,
571,570,375,374,211,210,78,76,74,72,70,68,66,64,62,60,58,56,54,50,51,166,167,314,315,494,495, 573, 572, 377, 376, 213, 212, 81, 80, 0, 0, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 0, 0, 48, 49, 164, 165, 312, 313, 492, 493,
569,568,373,372,209,208,79,77,75,73,71,69,67,65,63,61,59,57,55,52,53,168,169,316,317,496,497, 571, 570, 375, 374, 211, 210, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 50, 51, 166, 167, 314, 315, 494, 495,
567,566,371,370,206,204,202,200,198,196,194,192,190,188,186,184,182,180,178,176,174,170,171,318,319,498,499, 569, 568, 373, 372, 209, 208, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 52, 53, 168, 169, 316, 317, 496, 497,
565,564,369,368,207,205,203,201,199,197,195,193,191,189,187,185,183,181,179,177,175,172,173,320,321,500,501, 567, 566, 371, 370, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 170, 171, 318, 319, 498, 499,
563,562,366,364,362,360,358,356,354,352,350,348,346,344,342,340,338,336,334,332,330,328,326,322,323,502,503, 565, 564, 369, 368, 207, 205, 203, 201, 199, 197, 195, 193, 191, 189, 187, 185, 183, 181, 179, 177, 175, 172, 173, 320, 321, 500, 501,
561,560,367,365,363,361,359,357,355,353,351,349,347,345,343,341,339,337,335,333,331,329,327,324,325,504,505, 563, 562, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 322, 323, 502, 503,
558,556,554,552,550,548,546,544,542,540,538,536,534,532,530,528,526,524,522,520,518,516,514,512,510,506,507, 561, 560, 367, 365, 363, 361, 359, 357, 355, 353, 351, 349, 347, 345, 343, 341, 339, 337, 335, 333, 331, 329, 327, 324, 325, 504, 505,
559,557,555,553,551,549,547,545,543,541,539,537,535,533,531,529,527,525,523,521,519,517,515,513,511,508,509 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 506, 507,
559, 557, 555, 553, 551, 549, 547, 545, 543, 541, 539, 537, 535, 533, 531, 529, 527, 525, 523, 521, 519, 517, 515, 513, 511, 508, 509
}; };
const int AztecCodeSet[128] = { /* From Table 2 */ const int AztecCodeSet[128] = {
32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32, /* From Table 2 */
32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8, 32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32,
8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 4, 8, 4, 4, 4, 2, 2, 2, 8, 8, 8, 8, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 4, 8, 4, 4, 4, 2, 2, 2,
2, 2, 2, 8, 4, 8, 4, 4 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 8, 4, 8, 4, 4
}; };
const int AztecSymbolChar[128] = { /* From Table 2 */ const int AztecSymbolChar[128] = {
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19, /* From Table 2 */
20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19,
13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12,
23, 24, 25, 26, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 27, 21, 28, 22, 23, 24, 2, 3, 4, 23, 24, 25, 26, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 27, 21, 28, 22, 23, 24, 2, 3, 4,
25, 26, 27, 29, 25, 30, 26, 27 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 29, 25, 30, 26, 27
}; };
/* Problem characters are: /* Problem characters are:
300: Carriage Return (ASCII 13) 300: Carriage Return (ASCII 13)
301: Comma (ASCII 44) 301: Comma (ASCII 44)
302: Full Stop (ASCII 46) 302: Full Stop (ASCII 46)
*/ */
static const char *hexbit[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", static const char *hexbit[32] = {
"01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
"10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111" "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101",
"10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
}; };
static const char *pentbit[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", static const char *pentbit[16] = {
"1010", "1011", "1100", "1101", "1110", "1111" "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",
"1010", "1011", "1100", "1101", "1110", "1111"
}; };
static const char *tribit[8] = {"000", "001", "010", "011", "100", "101", "110", "111"}; static const char *tribit[8] = {
"000", "001", "010", "011", "100", "101", "110", "111"
static const int AztecSizes[32] = { /* Codewords per symbol */
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
}; };
static const int AztecCompactSizes[4] = { 17, 40, 51, 76 }; static const int AztecSizes[32] = {
/* Codewords per symbol */
static const int Aztec10DataSizes[32] = { /* Data bits per symbol maximum with 10% error correction */ 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730, 864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076,
15000, 15948, 16920, 17940
}; };
static const int Aztec23DataSizes[32] = { /* Data bits per symbol maximum with 23% error correction */ static const int AztecCompactSizes[4] = {
84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040, 17, 40, 51, 76
4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036,
12828, 13644, 14472, 15348
}; };
static const int Aztec36DataSizes[32] = { /* Data bits per symbol maximum with 36% error correction */ static const int Aztec10DataSizes[32] = {
66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350, /* Data bits per symbol maximum with 10% error correction */
3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656, 96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730,
11340, 12024, 12744 5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076,
15000, 15948, 16920, 17940
}; };
static const int Aztec50DataSizes[32] = { /* Data bits per symbol maximum with 50% error correction */ static const int Aztec23DataSizes[32] = {
48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610, /* Data bits per symbol maximum with 23% error correction */
2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316, 84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040,
8844, 9384, 9948 4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036,
12828, 13644, 14472, 15348
}; };
static const int AztecCompact10DataSizes [4] = { 78, 198, 336, 520 }; static const int Aztec36DataSizes[32] = {
static const int AztecCompact23DataSizes [4] = { 66, 168, 288, 440 }; /* Data bits per symbol maximum with 36% error correction */
static const int AztecCompact36DataSizes [4] = { 48, 138, 232, 360 }; 66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350,
static const int AztecCompact50DataSizes [4] = { 36, 102, 176, 280 }; 3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656,
11340, 12024, 12744
};
static const int Aztec50DataSizes[32] = {
/* Data bits per symbol maximum with 50% error correction */
48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610,
2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316,
8844, 9384, 9948
};
static const int AztecCompact10DataSizes [4] = {
78, 198, 336, 520
};
static const int AztecCompact23DataSizes [4] = {
66, 168, 288, 440
};
static const int AztecCompact36DataSizes [4] = {
48, 138, 232, 360
};
static const int AztecCompact50DataSizes [4] = {
36, 102, 176, 280
};
static const int AztecOffset[32] = { static const int AztecOffset[32] = {
66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21, 66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21,
19, 17, 15, 13, 10, 8, 6, 4, 2, 0 19, 17, 15, 13, 10, 8, 6, 4, 2, 0
}; };
static const int AztecCompactOffset[4] = { 6, 4, 2, 0 }; static const int AztecCompactOffset[4] = {
6, 4, 2, 0
};

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* In version 0.5 this file was 1,553 lines long! */ /* In version 0.5 this file was 1,553 lines long! */
@ -40,49 +40,58 @@
#define SODIUM "0123456789-" #define SODIUM "0123456789-"
#define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd" #define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
static const char *C11Table[11] = {"111121", "211121", "121121", "221111", "112121", "212111", "122111", static const char *C11Table[11] = {
"111221", "211211", "211111", "112111"}; "111121", "211121", "121121", "221111", "112121", "212111", "122111",
"111221", "211211", "211111", "112111"
};
/* Code 39 tables checked against ISO/IEC 16388:2007 */ /* Code 39 tables checked against ISO/IEC 16388:2007 */
/* Incorporates Table A1 */ /* Incorporates Table A1 */
static const char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111111", "1112211121", static const char *C39Table[43] = {
"2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121", /* Code 39 character assignments (Table 1) */
"1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121", "1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
"2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211", "2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121",
"1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211", "1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121",
"1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111", "2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211",
"1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211", "1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211",
"1211121211", "1112121211"}; "1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111",
/* Code 39 character assignments (Table 1) */ "1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211",
"1211121211", "1112121211"
};
static const char *EC39Ctrl[128] = {"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K", static const char *EC39Ctrl[128] = {
"$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z", /* Encoding the full ASCII character set in Code 39 (Table A2) */
"%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J", "%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K",
"/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F", "$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z",
"%G", "%H", "%I", "%J", "%V", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "%K", "%L", "%M", "%N", "%O", "/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F",
"%W", "+A", "+B", "+C", "+D", "+E", "+F", "+G", "+H", "+I", "+J", "+K", "+L", "+M", "+N", "+O", "%G", "%H", "%I", "%J", "%V", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"}; "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "%K", "%L", "%M", "%N", "%O",
/* Encoding the full ASCII character set in Code 39 (Table A2) */ "%W", "+A", "+B", "+C", "+D", "+E", "+F", "+G", "+H", "+I", "+J", "+K", "+L", "+M", "+N", "+O",
"+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"
};
static const char *C93Ctrl[128] = {"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK", static const char *C93Ctrl[128] = {
"aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ", "bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK",
"bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ", "aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ",
"+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF", "bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ",
"bG", "bH", "bI", "bJ", "bV", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bK", "bL", "bM", "bN", "bO", "bG", "bH", "bI", "bJ", "bV", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bK", "bL", "bM", "bN", "bO",
"dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"}; "bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO",
"dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"
};
static const char *C93Table[47] = {"131112", "111213", "111312", "111411", "121113", "121212", "121311", static const char *C93Table[47] = {
"111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111", "131112", "111213", "111312", "111411", "121113", "121212", "121311",
"112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122", "111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111",
"131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221", "112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122",
"122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131", "131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221",
"121221", "312111", "311121", "122211"}; "122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131",
"121221", "312111", "311121", "122211"
};
/* Global Variables for Channel Code */ /* Global Variables for Channel Code */
int S[11], B[11]; int S[11], B[11];
@ -95,356 +104,364 @@ void NextS(int Chan, int i, int MaxS, int MaxB);
void NextB(int Chan, int i, int MaxB, int MaxS); void NextB(int Chan, int i, int MaxB, int MaxS);
/* *********************** CODE 11 ******************** */ /* *********************** CODE 11 ******************** */
int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */
int code_11(struct zint_symbol *symbol, unsigned char source[], int length) unsigned int i;
{ /* Code 11 */ int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
int weight[128], error_number;
char dest[1024]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/
char checkstr[3];
unsigned int i; error_number = 0;
int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
int weight[128], error_number;
char dest[1024]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/
char checkstr[3];
error_number = 0; if (length > 121) {
strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SODIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
c_weight = 1;
c_count = 0;
k_weight = 1;
k_count = 0;
if(length > 121) { /* start character */
strcpy(symbol->errtxt, "Input too long"); strcpy(dest, "112211");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SODIUM, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
c_weight = 1;
c_count = 0;
k_weight = 1;
k_count = 0;
/* start character */ /* Draw main body of barcode */
strcpy(dest, "112211"); for (i = 0; i < length; i++) {
lookup(SODIUM, C11Table, source[i], dest);
if (source[i] == '-')
weight[i] = 10;
else
weight[i] = ctoi(source[i]);
}
/* Draw main body of barcode */ /* Calculate C checksum */
for(i = 0; i < length; i++) { for (h = length - 1; h >= 0; h--) {
lookup(SODIUM, C11Table, source[i], dest); c_count += (c_weight * weight[h]);
if(source[i] == '-') c_weight++;
weight[i] = 10;
else
weight[i] = ctoi(source[i]);
}
/* Calculate C checksum */ if (c_weight > 10) {
for(h = length - 1; h >= 0; h--) { c_weight = 1;
c_count += (c_weight * weight[h]); }
c_weight++; }
c_digit = c_count % 11;
if(c_weight > 10) { weight[length] = c_digit;
c_weight = 1;
}
}
c_digit = c_count % 11;
weight[length] = c_digit; /* Calculate K checksum */
for (h = length; h >= 0; h--) {
k_count += (k_weight * weight[h]);
k_weight++;
/* Calculate K checksum */ if (k_weight > 9) {
for(h = length; h >= 0; h--) { k_weight = 1;
k_count += (k_weight * weight[h]); }
k_weight++; }
k_digit = k_count % 11;
if(k_weight > 9) { checkstr[0] = itoc(c_digit);
k_weight = 1; checkstr[1] = itoc(k_digit);
} if (checkstr[0] == 'A') {
} checkstr[0] = '-';
k_digit = k_count % 11; }
if (checkstr[1] == 'A') {
checkstr[1] = '-';
}
checkstr[2] = '\0';
lookup(SODIUM, C11Table, checkstr[0], dest);
lookup(SODIUM, C11Table, checkstr[1], dest);
checkstr[0] = itoc(c_digit); /* Stop character */
checkstr[1] = itoc(k_digit); concat(dest, "11221");
if(checkstr[0] == 'A') { checkstr[0] = '-'; }
if(checkstr[1] == 'A') { checkstr[1] = '-'; }
checkstr[2] = '\0';
lookup(SODIUM, C11Table, checkstr[0], dest);
lookup(SODIUM, C11Table, checkstr[1], dest);
/* Stop character */ expand(symbol, dest);
concat (dest, "11221");
expand(symbol, dest); ustrcpy(symbol->text, source);
uconcat(symbol->text, (unsigned char*) checkstr);
ustrcpy(symbol->text, source); return error_number;
uconcat(symbol->text, (unsigned char*)checkstr);
return error_number;
} }
int c39(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 39 */
{ /* Code 39 */ int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned int i; unsigned int i;
unsigned int counter; unsigned int counter;
char check_digit; char check_digit;
int error_number; int error_number;
char dest[775]; char dest[775];
char localstr[2] = { 0 }; char localstr[2] = {0};
error_number = 0; error_number = 0;
counter = 0; counter = 0;
if((symbol->option_2 < 0) || (symbol->option_2 > 1)) { if ((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
symbol->option_2 = 0; symbol->option_2 = 0;
} }
if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) { if ((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} else if(length > 74) { } else if (length > 74) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
to_upper(source); to_upper(source);
error_number = is_sane(SILVER , source, length); error_number = is_sane(SILVER, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
/* Start character */ /* Start character */
strcpy(dest, "1211212111"); strcpy(dest, "1211212111");
for(i = 0; i < length; i++) { for (i = 0; i < length; i++) {
lookup(SILVER, C39Table, source[i], dest); lookup(SILVER, C39Table, source[i], dest);
counter += posn(SILVER, source[i]); counter += posn(SILVER, source[i]);
} }
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) { if ((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) {
counter = counter % 43; counter = counter % 43;
if(counter < 10) { if (counter < 10) {
check_digit = itoc(counter); check_digit = itoc(counter);
} else { } else {
if(counter < 36) { if (counter < 36) {
check_digit = (counter - 10) + 'A'; check_digit = (counter - 10) + 'A';
} else { } else {
switch(counter) { switch (counter) {
case 36: check_digit = '-'; break; case 36: check_digit = '-';
case 37: check_digit = '.'; break; break;
case 38: check_digit = ' '; break; case 37: check_digit = '.';
case 39: check_digit = '$'; break; break;
case 40: check_digit = '/'; break; case 38: check_digit = ' ';
case 41: check_digit = '+'; break; break;
case 42: check_digit = 37; break; case 39: check_digit = '$';
default: check_digit = ' '; break; /* Keep compiler happy */ break;
} case 40: check_digit = '/';
} break;
} case 41: check_digit = '+';
lookup(SILVER, C39Table, check_digit, dest); break;
case 42: check_digit = 37;
break;
default: check_digit = ' ';
break; /* Keep compiler happy */
}
}
}
lookup(SILVER, C39Table, check_digit, dest);
/* Display a space check digit as _, otherwise it looks like an error */ /* Display a space check digit as _, otherwise it looks like an error */
if(check_digit == ' ') { if (check_digit == ' ') {
check_digit = '_'; check_digit = '_';
} }
localstr[0] = check_digit; localstr[0] = check_digit;
localstr[1] = '\0'; localstr[1] = '\0';
} }
/* Stop character */ /* Stop character */
concat (dest, "121121211"); concat(dest, "121121211");
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) { if ((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
/* LOGMARS uses wider 'wide' bars than normal Code 39 */ /* LOGMARS uses wider 'wide' bars than normal Code 39 */
counter = strlen(dest); counter = strlen(dest);
for(i = 0; i < counter; i++) { for (i = 0; i < counter; i++) {
if(dest[i] == '2') { if (dest[i] == '2') {
dest[i] = '3'; dest[i] = '3';
} }
} }
} }
expand(symbol, dest); expand(symbol, dest);
if(symbol->symbology == BARCODE_CODE39) { if (symbol->symbology == BARCODE_CODE39) {
ustrcpy(symbol->text, (unsigned char*)"*"); ustrcpy(symbol->text, (unsigned char*) "*");
uconcat(symbol->text, source); uconcat(symbol->text, source);
uconcat(symbol->text, (unsigned char*)localstr); uconcat(symbol->text, (unsigned char*) localstr);
uconcat(symbol->text, (unsigned char*)"*"); uconcat(symbol->text, (unsigned char*) "*");
} else { } else {
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
uconcat(symbol->text, (unsigned char*)localstr); uconcat(symbol->text, (unsigned char*) localstr);
} }
return error_number; return error_number;
} }
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) /* Pharmazentral Nummer (PZN) */
{ /* Pharmazentral Nummer (PZN) */ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count, check_digit; unsigned int count, check_digit;
char localstr[10]; char localstr[10];
error_number = 0; error_number = 0;
count = 0; count = 0;
if(length > 6) { if (length > 6) {
strcpy(symbol->errtxt, "Input wrong length"); strcpy(symbol->errtxt, "Input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ZINT_ERROR_INVALID_DATA) { if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
localstr[0] = '-'; localstr[0] = '-';
zeroes = 6 - length + 1; zeroes = 6 - length + 1;
for(i = 1; i < zeroes; i++) for (i = 1; i < zeroes; i++)
localstr[i] = '0'; localstr[i] = '0';
strcpy(localstr + zeroes, (char *)source); strcpy(localstr + zeroes, (char *) source);
for (i = 1; i < 7; i++) { for (i = 1; i < 7; i++) {
count += (i + 1) * ctoi(localstr[i]); count += (i + 1) * ctoi(localstr[i]);
} }
check_digit = count%11; check_digit = count % 11;
if (check_digit == 11) { check_digit = 0; } if (check_digit == 11) {
localstr[7] = itoc(check_digit); check_digit = 0;
localstr[8] = '\0'; }
if(localstr[7] == 'A') { localstr[7] = itoc(check_digit);
strcpy(symbol->errtxt, "Invalid PZN Data"); localstr[8] = '\0';
return ZINT_ERROR_INVALID_DATA; if (localstr[7] == 'A') {
} strcpy(symbol->errtxt, "Invalid PZN Data");
error_number = c39(symbol, (unsigned char *)localstr, strlen(localstr)); return ZINT_ERROR_INVALID_DATA;
ustrcpy(symbol->text, (unsigned char *)"PZN"); }
uconcat(symbol->text, (unsigned char *)localstr); error_number = c39(symbol, (unsigned char *) localstr, strlen(localstr));
return error_number; ustrcpy(symbol->text, (unsigned char *) "PZN");
uconcat(symbol->text, (unsigned char *) localstr);
return error_number;
} }
/* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
/* ************** EXTENDED CODE 39 *************** */ unsigned char buffer[150] = {0};
unsigned int i;
int error_number;
int ec39(struct zint_symbol *symbol, unsigned char source[], int length) error_number = 0;
{ /* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
unsigned char buffer[150] = { 0 }; if (length > 74) {
unsigned int i; strcpy(symbol->errtxt, "Input too long");
int error_number; return ZINT_ERROR_TOO_LONG;
}
error_number = 0; /* Creates a buffer string and places control characters into it */
for (i = 0; i < length; i++) {
if (source[i] > 127) {
/* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "Invalid characters in input data");
return ZINT_ERROR_INVALID_DATA;
}
concat((char*) buffer, EC39Ctrl[source[i]]);
}
if(length > 74) { /* Then sends the buffer to the C39 function */
strcpy(symbol->errtxt, "Input too long"); error_number = c39(symbol, buffer, ustrlen(buffer));
return ZINT_ERROR_TOO_LONG;
}
/* Creates a buffer string and places control characters into it */ for (i = 0; i < length; i++)
for(i = 0; i < length; i++) { symbol->text[i] = source[i] ? source[i] : ' ';
if(source[i] > 127) { symbol->text[length] = '\0';
/* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "Invalid characters in input data");
return ZINT_ERROR_INVALID_DATA;
}
concat((char*)buffer, EC39Ctrl[source[i]]);
}
/* Then sends the buffer to the C39 function */ return error_number;
error_number = c39(symbol, buffer, ustrlen(buffer));
for(i = 0; i < length; i++)
symbol->text[i] = source[i] ? source[i] : ' ';
symbol->text[length] = '\0';
return error_number;
} }
/* ******************** CODE 93 ******************* */ /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
int c93(struct zint_symbol *symbol, unsigned char source[], int length) {
int c93(struct zint_symbol *symbol, unsigned char source[], int length) /* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
{ /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */ shift characters 1, 2, 3 and 4 respectively. These characters are never used by
c39() and ec39() */
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific int i;
shift characters 1, 2, 3 and 4 respectively. These characters are never used by int h, weight, c, k, values[128], error_number;
c39() and ec39() */ char buffer[220];
char dest[670];
char set_copy[] = SILVER;
int i; error_number = 0;
int h, weight, c, k, values[128], error_number;
char buffer[220];
char dest[670];
char set_copy[] = SILVER;
error_number = 0;
strcpy(buffer, ""); strcpy(buffer, "");
if(length > 107) { if (length > 107) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
/* Message Content */ /* Message Content */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (source[i] > 127) { if (source[i] > 127) {
/* Cannot encode extended ASCII */ /* Cannot encode extended ASCII */
strcpy(symbol->errtxt, "Invalid characters in input data"); strcpy(symbol->errtxt, "Invalid characters in input data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
concat(buffer, C93Ctrl[source[i]]); concat(buffer, C93Ctrl[source[i]]);
symbol->text[i] = source[i] ? source[i] : ' '; symbol->text[i] = source[i] ? source[i] : ' ';
} }
/* Now we can check the true length of the barcode */ /* Now we can check the true length of the barcode */
h = strlen(buffer); h = strlen(buffer);
if (h > 107) { if (h > 107) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
for (i = 0; i < h; i++) { for (i = 0; i < h; i++) {
values[i] = posn(SILVER, buffer[i]); values[i] = posn(SILVER, buffer[i]);
} }
/* Putting the data into dest[] is not done until after check digits are calculated */ /* Putting the data into dest[] is not done until after check digits are calculated */
/* Check digit C */ /* Check digit C */
c = 0; c = 0;
weight = 1; weight = 1;
for (i = h - 1; i >= 0; i--) { for (i = h - 1; i >= 0; i--) {
c += values[i] * weight; c += values[i] * weight;
weight++; weight++;
if (weight == 21) if (weight == 21)
weight = 1; weight = 1;
} }
c = c % 47; c = c % 47;
values[h] = c; values[h] = c;
buffer[h] = set_copy[c]; buffer[h] = set_copy[c];
/* Check digit K */ /* Check digit K */
k = 0; k = 0;
weight = 1; weight = 1;
for (i = h; i >= 0; i--) { for (i = h; i >= 0; i--) {
k += values[i] * weight; k += values[i] * weight;
weight++; weight++;
if(weight == 16) if (weight == 16)
weight = 1; weight = 1;
} }
k = k % 47; k = k % 47;
buffer[++h] = set_copy[k]; buffer[++h] = set_copy[k];
buffer[++h] = '\0'; buffer[++h] = '\0';
/* Start character */ /* Start character */
strcpy(dest, "111141"); strcpy(dest, "111141");
for(i = 0; i < h; i++) { for (i = 0; i < h; i++) {
lookup(SILVER, C93Table, buffer[i], dest); lookup(SILVER, C93Table, buffer[i], dest);
} }
/* Stop character */ /* Stop character */
concat(dest, "1111411"); concat(dest, "1111411");
expand(symbol, dest); expand(symbol, dest);
symbol->text[length] = set_copy[c]; symbol->text[length] = set_copy[c];
symbol->text[length + 1] = set_copy[k]; symbol->text[length + 1] = set_copy[k];
symbol->text[length + 2] = '\0'; symbol->text[length + 2] = '\0';
return error_number; return error_number;
} }
/* NextS() and NextB() are from ANSI/AIM BC12-1998 and are Copyright (c) AIM 1997 */ /* NextS() and NextB() are from ANSI/AIM BC12-1998 and are Copyright (c) AIM 1997 */
/* Their are used here on the understanding that they form part of the specification /* Their are used here on the understanding that they form part of the specification
for Channel Code and therefore their use is permitted under the following terms for Channel Code and therefore their use is permitted under the following terms
set out in that document: set out in that document:
@ -455,99 +472,127 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
assume no liability for the use of this document." */ assume no liability for the use of this document." */
void CheckCharacter() { void CheckCharacter() {
int i; int i;
char part[3]; char part[3];
if(value == target_value) { if (value == target_value) {
/* Target reached - save the generated pattern */ /* Target reached - save the generated pattern */
strcpy(pattern, "11110"); strcpy(pattern, "11110");
for(i = 0; i < 11; i++) { for (i = 0; i < 11; i++) {
part[0] = itoc(S[i]); part[0] = itoc(S[i]);
part[1] = itoc(B[i]); part[1] = itoc(B[i]);
part[2] = '\0'; part[2] = '\0';
concat(pattern, part); concat(pattern, part);
} }
} }
} }
void NextB(int Chan, int i, int MaxB, int MaxS) { void NextB(int Chan, int i, int MaxB, int MaxS) {
int b; int b;
b = (S[i]+B[i-1]+S[i-1]+B[i-2] > 4)? 1:2; b = (S[i] + B[i - 1] + S[i - 1] + B[i - 2] > 4) ? 1 : 2;
if (i < Chan+2) { if (i < Chan + 2) {
for (; b <= MaxB; b++) { for (; b <= MaxB; b++) {
B[i] = b; B[i] = b;
NextS(Chan,i+1,MaxS,MaxB+1-b); NextS(Chan, i + 1, MaxS, MaxB + 1 - b);
} }
} else if (b <= MaxB) { } else if (b <= MaxB) {
B[i] = MaxB; B[i] = MaxB;
CheckCharacter(); CheckCharacter();
value++; value++;
} }
} }
void NextS(int Chan, int i, int MaxS, int MaxB) { void NextS(int Chan, int i, int MaxS, int MaxB) {
int s; int s;
for (s = (i<Chan+2)? 1: MaxS; s <= MaxS; s++) { for (s = (i < Chan + 2) ? 1 : MaxS; s <= MaxS; s++) {
S[i] = s; S[i] = s;
NextB(Chan,i,MaxB,MaxS+1-s); NextB(Chan, i, MaxB, MaxS + 1 - s);
} }
} }
/* Channel Code - According to ANSI/AIM BC12-1998 */
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) { int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Channel Code - According to ANSI/AIM BC12-1998 */ int channels, i;
int error_number = 0, range = 0, zeroes;
char hrt[9];
int channels, i; target_value = 0;
int error_number = 0, range = 0, zeroes;
char hrt[9];
target_value = 0; if (length > 7) {
strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid characters in data");
return error_number;
}
if(length > 7) { if ((symbol->option_2 < 3) || (symbol->option_2 > 8)) {
strcpy(symbol->errtxt, "Input too long"); channels = 0;
return ZINT_ERROR_TOO_LONG; } else {
} channels = symbol->option_2;
error_number = is_sane(NEON, source, length); }
if(error_number == ZINT_ERROR_INVALID_DATA) { if (channels == 0) {
strcpy(symbol->errtxt, "Invalid characters in data"); channels = length + 1;
return error_number; }
} if (channels == 2) {
channels = 3;
}
if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; } for (i = 0; i < length; i++) {
if(channels == 0) { channels = length + 1; } target_value *= 10;
if(channels == 2) { channels = 3; } target_value += ctoi((char) source[i]);
}
for(i = 0; i < length; i++) { switch (channels) {
target_value *= 10; case 3: if (target_value > 26) {
target_value += ctoi((char) source[i]); range = 1;
} }
break;
case 4: if (target_value > 292) {
range = 1;
}
break;
case 5: if (target_value > 3493) {
range = 1;
}
break;
case 6: if (target_value > 44072) {
range = 1;
}
break;
case 7: if (target_value > 576688) {
range = 1;
}
break;
case 8: if (target_value > 7742862) {
range = 1;
}
break;
}
if (range) {
strcpy(symbol->errtxt, "Value out of range");
return ZINT_ERROR_INVALID_DATA;
}
switch(channels) { for (i = 0; i < 11; i++) {
case 3: if(target_value > 26) { range = 1; } break; B[i] = 0;
case 4: if(target_value > 292) { range = 1; } break; S[i] = 0;
case 5: if(target_value > 3493) { range = 1; } break; }
case 6: if(target_value > 44072) { range = 1; } break;
case 7: if(target_value > 576688) { range = 1; } break;
case 8: if(target_value > 7742862) { range = 1; } break;
}
if(range) {
strcpy(symbol->errtxt, "Value out of range");
return ZINT_ERROR_INVALID_DATA;
}
for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; } B[0] = S[1] = B[1] = S[2] = B[2] = 1;
value = 0;
NextS(channels, 3, channels, channels);
B[0] = S[1] = B[1] = S[2] = B[2] = 1; zeroes = channels - 1 - length;
value = 0; memset(hrt, '0', zeroes);
NextS(channels,3,channels,channels); strcpy(hrt + zeroes, (char *) source);
ustrcpy(symbol->text, (unsigned char *) hrt);
zeroes = channels - 1 - length; expand(symbol, pattern);
memset(hrt, '0', zeroes);
strcpy(hrt + zeroes, (char *)source);
ustrcpy(symbol->text, (unsigned char *)hrt);
expand(symbol, pattern); return error_number;
return error_number;
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,41 +28,71 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
static const int c40_shift[] = { static const int c40_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
static const int c40_value[] = { static const int c40_value[] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15,16,17,18,19,20,21,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39, 15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
};
static const int text_shift[] = { static const int text_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3
};
static const int text_value[] = { static const int text_value[] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26, 15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31
};
static const int c1_height[] = { 16, 22, 28, 40, 52, 70, 104, 148 }; static const int c1_height[] = {
static const int c1_width[] = { 18, 22, 32, 42, 54, 76, 98, 134 }; 16, 22, 28, 40, 52, 70, 104, 148
static const int c1_data_length[] = { 10, 19, 44, 91, 182, 370, 732, 1480 }; };
static const int c1_ecc_length[] = { 10, 16, 26, 44, 70, 140, 280, 560 };
static const int c1_blocks[] = { 1, 1, 1, 1, 1, 2, 4, 8 }; static const int c1_width[] = {
static const int c1_data_blocks[] = { 10, 19, 44, 91, 182, 185, 183, 185 }; 18, 22, 32, 42, 54, 76, 98, 134
static const int c1_ecc_blocks[] = { 10, 16, 26, 44, 70, 70, 70, 70 }; };
static const int c1_grid_width[] = { 4, 5, 7, 9, 12, 17, 22, 30 };
static const int c1_grid_height[] = { 5, 7, 10, 15, 21, 30, 46, 68 }; static const int c1_data_length[] = {
10, 19, 44, 91, 182, 370, 732, 1480
};
static const int c1_ecc_length[] = {
10, 16, 26, 44, 70, 140, 280, 560
};
static const int c1_blocks[] = {
1, 1, 1, 1, 1, 2, 4, 8
};
static const int c1_data_blocks[] = {
10, 19, 44, 91, 182, 185, 183, 185
};
static const int c1_ecc_blocks[] = {
10, 16, 26, 44, 70, 70, 70, 70
};
static const int c1_grid_width[] = {
4, 5, 7, 9, 12, 17, 22, 30
};
static const int c1_grid_height[] = {
5, 7, 10, 15, 21, 30, 46, 68
};
#define C1_ASCII 1 #define C1_ASCII 1
#define C1_C40 2 #define C1_C40 2

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -26,9 +26,9 @@
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -37,290 +37,299 @@
#include "code49.h" #include "code49.h"
#define INSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*" #define INSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*"
/* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */ /* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */
int code_49(struct zint_symbol *symbol, unsigned char source[], int length) int code_49(struct zint_symbol *symbol, unsigned char source[], int length) {
{ int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h;
int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h; char intermediate[170];
char intermediate[170]; int codewords[170], codeword_count;
int codewords[170], codeword_count; int c_grid[8][8]; /* Refers to table 3 */
int c_grid[8][8]; /* Refers to table 3 */ int w_grid[8][4]; /* Refets to table 2 */
int w_grid[8][4]; /* Refets to table 2 */ int pad_count = 0;
int pad_count = 0; char pattern[40];
char pattern[40]; int gs1;
int gs1;
if(length > 81) { if (length > 81) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } if (symbol->input_mode == GS1_MODE) {
gs1 = 1;
strcpy(intermediate, "*"); /* FNC1 */
} else {
gs1 = 0;
}
strcpy(intermediate, gs1 ? "*" : ""); /* FNC1 */ for (i = 0; i < length; i++) {
for(i = 0; i < length; i++) { if (source[i] > 127) {
if(source[i] > 127) { strcpy(symbol->errtxt, "Invalid characters in input data");
strcpy(symbol->errtxt, "Invalid characters in input data"); return ZINT_ERROR_INVALID_DATA;
return ZINT_ERROR_INVALID_DATA; }
} if (gs1 && (source[i] == '['))
if(gs1 && (source[i] == '[')) concat(intermediate, "*"); /* FNC1 */
concat(intermediate, "*"); /* FNC1 */ else
else concat(intermediate, c49_table7[source[i]]);
concat(intermediate, c49_table7[source[i]]); }
}
codeword_count = 0; codeword_count = 0;
i = 0; i = 0;
h = strlen(intermediate); h = strlen(intermediate);
do { do {
if((intermediate[i] >= '0') && (intermediate[i] <= '9')) { if ((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
/* Numeric data */ /* Numeric data */
for(j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++); for (j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++);
if(j >= 5) { if (j >= 5) {
/* Use Numeric Encodation Method */ /* Use Numeric Encodation Method */
int block_count, c; int block_count, c;
int block_remain; int block_remain;
int block_value; int block_value;
codewords[codeword_count] = 48; /* Numeric Shift */ codewords[codeword_count] = 48; /* Numeric Shift */
codeword_count++; codeword_count++;
block_count = j / 5; block_count = j / 5;
block_remain = j % 5; block_remain = j % 5;
for(c = 0; c < block_count; c++) { for (c = 0; c < block_count; c++) {
if((c == block_count - 1) && (block_remain == 2)) { if ((c == block_count - 1) && (block_remain == 2)) {
/* Rule (d) */ /* Rule (d) */
block_value = 100000; block_value = 100000;
block_value += ctoi(intermediate[i]) * 1000; block_value += ctoi(intermediate[i]) * 1000;
block_value += ctoi(intermediate[i + 1]) * 100; block_value += ctoi(intermediate[i + 1]) * 100;
block_value += ctoi(intermediate[i + 2]) * 10; block_value += ctoi(intermediate[i + 2]) * 10;
block_value += ctoi(intermediate[i + 3]); block_value += ctoi(intermediate[i + 3]);
codewords[codeword_count] = block_value / (48 * 48); codewords[codeword_count] = block_value / (48 * 48);
block_value = block_value - (48 * 48) * codewords[codeword_count]; block_value = block_value - (48 * 48) * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value / 48; codewords[codeword_count] = block_value / 48;
block_value = block_value - 48 * codewords[codeword_count]; block_value = block_value - 48 * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value; codewords[codeword_count] = block_value;
codeword_count++; codeword_count++;
i += 4; i += 4;
block_value = ctoi(intermediate[i]) * 100; block_value = ctoi(intermediate[i]) * 100;
block_value += ctoi(intermediate[i + 1]) * 10; block_value += ctoi(intermediate[i + 1]) * 10;
block_value += ctoi(intermediate[i + 2]); block_value += ctoi(intermediate[i + 2]);
codewords[codeword_count] = block_value / 48; codewords[codeword_count] = block_value / 48;
block_value = block_value - 48 * codewords[codeword_count]; block_value = block_value - 48 * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value; codewords[codeword_count] = block_value;
codeword_count++; codeword_count++;
i += 3; i += 3;
} else { } else {
block_value = ctoi(intermediate[i]) * 10000; block_value = ctoi(intermediate[i]) * 10000;
block_value += ctoi(intermediate[i + 1]) * 1000; block_value += ctoi(intermediate[i + 1]) * 1000;
block_value += ctoi(intermediate[i + 2]) * 100; block_value += ctoi(intermediate[i + 2]) * 100;
block_value += ctoi(intermediate[i + 3]) * 10; block_value += ctoi(intermediate[i + 3]) * 10;
block_value += ctoi(intermediate[i + 4]); block_value += ctoi(intermediate[i + 4]);
codewords[codeword_count] = block_value / (48 * 48); codewords[codeword_count] = block_value / (48 * 48);
block_value = block_value - (48 * 48) * codewords[codeword_count]; block_value = block_value - (48 * 48) * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value / 48; codewords[codeword_count] = block_value / 48;
block_value = block_value - 48 * codewords[codeword_count]; block_value = block_value - 48 * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value; codewords[codeword_count] = block_value;
codeword_count++; codeword_count++;
i += 5; i += 5;
} }
} }
switch(block_remain) { switch (block_remain) {
case 1: case 1:
/* Rule (a) */ /* Rule (a) */
codewords[codeword_count] = posn(INSET, intermediate[i]); codewords[codeword_count] = posn(INSET, intermediate[i]);
codeword_count++; codeword_count++;
i++; i++;
break; break;
case 3: case 3:
/* Rule (b) */ /* Rule (b) */
block_value = ctoi(intermediate[i]) * 100; block_value = ctoi(intermediate[i]) * 100;
block_value += ctoi(intermediate[i + 1]) * 10; block_value += ctoi(intermediate[i + 1]) * 10;
block_value += ctoi(intermediate[i + 2]); block_value += ctoi(intermediate[i + 2]);
codewords[codeword_count] = block_value / 48; codewords[codeword_count] = block_value / 48;
block_value = block_value - 48 * codewords[codeword_count]; block_value = block_value - 48 * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value; codewords[codeword_count] = block_value;
codeword_count++; codeword_count++;
i += 3; i += 3;
break; break;
case 4: case 4:
/* Rule (c) */ /* Rule (c) */
block_value = 100000; block_value = 100000;
block_value += ctoi(intermediate[i]) * 1000; block_value += ctoi(intermediate[i]) * 1000;
block_value += ctoi(intermediate[i + 1]) * 100; block_value += ctoi(intermediate[i + 1]) * 100;
block_value += ctoi(intermediate[i + 2]) * 10; block_value += ctoi(intermediate[i + 2]) * 10;
block_value += ctoi(intermediate[i + 3]); block_value += ctoi(intermediate[i + 3]);
codewords[codeword_count] = block_value / (48 * 48); codewords[codeword_count] = block_value / (48 * 48);
block_value = block_value - (48 * 48) * codewords[codeword_count]; block_value = block_value - (48 * 48) * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value / 48; codewords[codeword_count] = block_value / 48;
block_value = block_value - 48 * codewords[codeword_count]; block_value = block_value - 48 * codewords[codeword_count];
codeword_count++; codeword_count++;
codewords[codeword_count] = block_value; codewords[codeword_count] = block_value;
codeword_count++; codeword_count++;
i += 4; i += 4;
break; break;
} }
if(i < h) { if (i < h) {
/* There is more to add */ /* There is more to add */
codewords[codeword_count] = 48; /* Numeric Shift */ codewords[codeword_count] = 48; /* Numeric Shift */
codeword_count++; codeword_count++;
} }
} else { } else {
codewords[codeword_count] = posn(INSET, intermediate[i]); codewords[codeword_count] = posn(INSET, intermediate[i]);
codeword_count++; codeword_count++;
i++; i++;
} }
} else { } else {
codewords[codeword_count] = posn(INSET, intermediate[i]); codewords[codeword_count] = posn(INSET, intermediate[i]);
codeword_count++; codeword_count++;
i++; i++;
} }
} while(i < h); } while (i < h);
switch(codewords[0]) { /* Set starting mode value */ switch (codewords[0]) {
case 48: M = 2; break; /* Set starting mode value */
case 43: M = 4; break; case 48: M = 2;
case 44: M = 5; break; break;
default: M = 0; break; case 43: M = 4;
} break;
case 44: M = 5;
break;
default: M = 0;
break;
}
if(M != 0) { if (M != 0) {
for(i = 0; i < codeword_count; i++) { for (i = 0; i < codeword_count; i++) {
codewords[i] = codewords[i + 1]; codewords[i] = codewords[i + 1];
} }
codeword_count--; codeword_count--;
} }
if(codeword_count > 49) { if (codeword_count > 49) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
/* Place codewords in code character array (c grid) */ /* Place codewords in code character array (c grid) */
rows = 0; rows = 0;
do{ do {
for(i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
if(((rows * 7) + i) < codeword_count) { if (((rows * 7) + i) < codeword_count) {
c_grid[rows][i] = codewords[(rows * 7) + i]; c_grid[rows][i] = codewords[(rows * 7) + i];
} else { } else {
c_grid[rows][i] = 48; /* Pad */ c_grid[rows][i] = 48; /* Pad */
pad_count++; pad_count++;
} }
} }
rows++; rows++;
} while ((rows * 7) < codeword_count); } while ((rows * 7) < codeword_count);
if((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) { if ((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
/* Add a row */ /* Add a row */
for(i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
c_grid[rows][i] = 48; /* Pad */ c_grid[rows][i] = 48; /* Pad */
} }
rows++; rows++;
} }
/* Add row count and mode character */ /* Add row count and mode character */
c_grid[rows - 1][6] = (7 * (rows - 2)) + M; c_grid[rows - 1][6] = (7 * (rows - 2)) + M;
/* Add row check character */ /* Add row check character */
for(i = 0; i < rows - 1; i++) { for (i = 0; i < rows - 1; i++) {
int row_sum = 0; int row_sum = 0;
for(j = 0; j < 7; j++) { for (j = 0; j < 7; j++) {
row_sum += c_grid[i][j]; row_sum += c_grid[i][j];
} }
c_grid[i][7] = row_sum % 49; c_grid[i][7] = row_sum % 49;
} }
/* Calculate Symbol Check Characters */ /* Calculate Symbol Check Characters */
posn_val = 0; posn_val = 0;
x_count = c_grid[rows - 1][6] * 20; x_count = c_grid[rows - 1][6] * 20;
y_count = c_grid[rows - 1][6] * 16; y_count = c_grid[rows - 1][6] * 16;
z_count = c_grid[rows - 1][6] * 38; z_count = c_grid[rows - 1][6] * 38;
for(i = 0; i < rows - 1; i++) { for (i = 0; i < rows - 1; i++) {
for(j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
local_value = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1]; local_value = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
x_count += c49_x_weight[posn_val] * local_value; x_count += c49_x_weight[posn_val] * local_value;
y_count += c49_y_weight[posn_val] * local_value; y_count += c49_y_weight[posn_val] * local_value;
z_count += c49_z_weight[posn_val] * local_value; z_count += c49_z_weight[posn_val] * local_value;
posn_val++; posn_val++;
} }
} }
if(rows > 6) { if (rows > 6) {
/* Add Z Symbol Check */ /* Add Z Symbol Check */
c_grid[rows - 1][0] = (z_count % 2401) / 49; c_grid[rows - 1][0] = (z_count % 2401) / 49;
c_grid[rows - 1][1] = (z_count % 2401) % 49; c_grid[rows - 1][1] = (z_count % 2401) % 49;
} }
local_value = (c_grid[rows - 1][0] * 49) + c_grid[rows - 1][1]; local_value = (c_grid[rows - 1][0] * 49) + c_grid[rows - 1][1];
x_count += c49_x_weight[posn_val] * local_value; x_count += c49_x_weight[posn_val] * local_value;
y_count += c49_y_weight[posn_val] * local_value; y_count += c49_y_weight[posn_val] * local_value;
posn_val++; posn_val++;
/* Add Y Symbol Check */ /* Add Y Symbol Check */
c_grid[rows - 1][2] = (y_count % 2401) / 49; c_grid[rows - 1][2] = (y_count % 2401) / 49;
c_grid[rows - 1][3] = (y_count % 2401) % 49; c_grid[rows - 1][3] = (y_count % 2401) % 49;
local_value = (c_grid[rows - 1][2] * 49) + c_grid[rows - 1][3]; local_value = (c_grid[rows - 1][2] * 49) + c_grid[rows - 1][3];
x_count += c49_x_weight[posn_val] * local_value; x_count += c49_x_weight[posn_val] * local_value;
/* Add X Symbol Check */ /* Add X Symbol Check */
c_grid[rows - 1][4] = (x_count % 2401) / 49; c_grid[rows - 1][4] = (x_count % 2401) / 49;
c_grid[rows - 1][5] = (x_count % 2401) % 49; c_grid[rows - 1][5] = (x_count % 2401) % 49;
/* Add last row check character */ /* Add last row check character */
j = 0; j = 0;
for(i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
j += c_grid[rows - 1][i]; j += c_grid[rows - 1][i];
} }
c_grid[rows - 1][7] = j % 49; c_grid[rows - 1][7] = j % 49;
/* Transfer data to symbol character array (w grid) */ /* Transfer data to symbol character array (w grid) */
for(i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
for(j = 0; j < 4; j ++) { for (j = 0; j < 4; j++) {
w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1]; w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
} }
} }
for(i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
strcpy(pattern, "11"); /* Start character */ strcpy(pattern, "11"); /* Start character */
for(j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
if(i != (rows - 1)) { if (i != (rows - 1)) {
if(c49_table4[i][j] == 'E') { if (c49_table4[i][j] == 'E') {
/* Even Parity */ /* Even Parity */
concat(pattern, c49_appxe_even[w_grid[i][j]]); concat(pattern, c49_appxe_even[w_grid[i][j]]);
} else { } else {
/* Odd Parity */ /* Odd Parity */
concat(pattern, c49_appxe_odd[w_grid[i][j]]); concat(pattern, c49_appxe_odd[w_grid[i][j]]);
} }
} else { } else {
/* Last row uses all even parity */ /* Last row uses all even parity */
concat(pattern, c49_appxe_even[w_grid[i][j]]); concat(pattern, c49_appxe_even[w_grid[i][j]]);
} }
} }
concat(pattern, "4"); /* Stop character */ concat(pattern, "4"); /* Stop character */
/* Expand into symbol */ /* Expand into symbol */
symbol->row_height[i] = 10; symbol->row_height[i] = 10;
expand(symbol, pattern); expand(symbol, pattern);
} }
symbol->whitespace_width = 10; symbol->whitespace_width = 10;
symbol->output_options = BARCODE_BIND; symbol->output_options = BARCODE_BIND;
symbol->border_width = 2; symbol->border_width = 2;
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -26,360 +26,358 @@
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "common.h" #include "common.h"
/* Local replacement for strlen() with unsigned char strings */
int ustrlen(const unsigned char data[]) { int ustrlen(const unsigned char data[]) {
/* Local replacement for strlen() with unsigned char strings */ int i;
int i; for (i = 0; data[i]; i++);
for (i=0;data[i];i++);
return i; return i;
} }
void ustrcpy(unsigned char target[],const unsigned char source[]) { /* Local replacement for strcpy() with unsigned char strings */
/* Local replacement for strcpy() with unsigned char strings */ void ustrcpy(unsigned char target[], const unsigned char source[]) {
int i, len; int i, len;
len = ustrlen(source); len = ustrlen(source);
for(i = 0; i < len; i++) { for (i = 0; i < len; i++) {
target[i] = source[i]; target[i] = source[i];
} }
target[i] = '\0'; target[i] = '\0';
} }
void concat(char dest[],const char source[]) /* Concatinates dest[] with the contents of source[], copying /0 as well */
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */ void concat(char dest[], const char source[]) {
unsigned int i, j, n; unsigned int i, j, n;
j = strlen(dest); j = strlen(dest);
n = strlen(source); n = strlen(source);
for(i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
dest[i + j] = source[i]; } dest[i + j] = source[i];
}
} }
void uconcat(unsigned char dest[], const unsigned char source[]) /* Concatinates dest[] with the contents of source[], copying /0 as well */
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */ void uconcat(unsigned char dest[], const unsigned char source[]) {
unsigned int i, j; unsigned int i, j;
j = ustrlen(dest); j = ustrlen(dest);
for(i = 0; i <= ustrlen(source); i++) { for (i = 0; i <= ustrlen(source); i++) {
dest[i + j] = source[i]; } dest[i + j] = source[i];
}
} }
/* Converts a character 0-9 to its equivalent integer value */
int ctoi(char source) int ctoi(char source) {
{ /* Converts a character 0-9 to its equivalent integer value */ if ((source >= '0') && (source <= '9'))
if((source >= '0') && (source <= '9')) return (source - '0');
return (source - '0'); return (source - 'A' + 10);
return(source - 'A' + 10);
} }
char itoc(int source) /* Converts an integer value to its hexadecimal character */
{ /* Converts an integer value to its hexadecimal character */ char itoc(int source) {
if ((source >= 0) && (source <= 9)) { if ((source >= 0) && (source <= 9)) {
return ('0' + source); } return ('0' + source);
else { } else {
return ('A' + (source - 10)); } return ('A' + (source - 10));
}
} }
void to_upper(unsigned char source[]) /* Converts lower case characters to upper case in a string source[] */
{ /* Converts lower case characters to upper case in a string source[] */ void to_upper(unsigned char source[]) {
unsigned int i, src_len = ustrlen(source); unsigned int i, src_len = ustrlen(source);
for (i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
if ((source[i] >= 'a') && (source[i] <= 'z')) { if ((source[i] >= 'a') && (source[i] <= 'z')) {
source [i] = (source[i] - 'a') + 'A'; } source [i] = (source[i] - 'a') + 'A';
} }
}
} }
int is_sane(char test_string[], unsigned char source[], int length) /* Verifies that a string only uses valid characters */
{ /* Verifies that a string only uses valid characters */ int is_sane(char test_string[], unsigned char source[], int length) {
unsigned int i, j, latch; unsigned int i, j, latch;
unsigned int lt = strlen(test_string); unsigned int lt = strlen(test_string);
for(i = 0; i < length; i++) { for (i = 0; i < length; i++) {
latch = FALSE; latch = FALSE;
for(j = 0; j < lt; j++) { for (j = 0; j < lt; j++) {
if (source[i] == test_string[j]) { if (source[i] == test_string[j]) {
latch = TRUE; latch = TRUE;
break; break;
} }
} }
if (!(latch)) { if (!(latch)) {
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
} }
return 0; return 0;
} }
int posn(char set_string[], char data) /* Returns the position of data in set_string */
{ /* Returns the position of data in set_string */ int posn(char set_string[], char data) {
unsigned int i, n = strlen(set_string); unsigned int i, n = strlen(set_string);
for(i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (data == set_string[i]) { return i; } } if (data == set_string[i]) {
return 0; return i;
}
}
return 0;
} }
void lookup(char set_string[],const char *table[], char data, char dest[]) /* Replaces huge switch statements for looking up in tables */
{ /* Replaces huge switch statements for looking up in tables */ void lookup(char set_string[], const char *table[], char data, char dest[]) {
unsigned int i, n = strlen(set_string); unsigned int i, n = strlen(set_string);
for(i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (data == set_string[i]) { concat(dest, table[i]); } } if (data == set_string[i]) {
concat(dest, table[i]);
}
}
} }
int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) /* Return true (1) if a module is dark/black, orherwise false (0) */
{ int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) {
return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1; return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1;
#if 0
switch(x_sub) {
case 0: if((symbol->encoded_data[y_coord][x_char] & 0x01) != 0) { result = 1; } break;
case 1: if((symbol->encoded_data[y_coord][x_char] & 0x02) != 0) { result = 1; } break;
case 2: if((symbol->encoded_data[y_coord][x_char] & 0x04) != 0) { result = 1; } break;
case 3: if((symbol->encoded_data[y_coord][x_char] & 0x08) != 0) { result = 1; } break;
case 4: if((symbol->encoded_data[y_coord][x_char] & 0x10) != 0) { result = 1; } break;
case 5: if((symbol->encoded_data[y_coord][x_char] & 0x20) != 0) { result = 1; } break;
case 6: if((symbol->encoded_data[y_coord][x_char] & 0x40) != 0) { result = 1; } break;
}
return result;
#endif
} }
void set_module(struct zint_symbol *symbol, int y_coord, int x_coord) /* Set a module to dark/black */
{ void set_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
symbol->encoded_data[y_coord][x_coord / 7] |= 1 << (x_coord % 7); symbol->encoded_data[y_coord][x_coord / 7] |= 1 << (x_coord % 7);
#if 0
int x_char, x_sub;
x_char = x_coord / 7;
x_sub = x_coord % 7;
switch(x_sub) {
case 0: symbol->encoded_data[y_coord][x_char] += 0x01; break;
case 1: symbol->encoded_data[y_coord][x_char] += 0x02; break;
case 2: symbol->encoded_data[y_coord][x_char] += 0x04; break;
case 3: symbol->encoded_data[y_coord][x_char] += 0x08; break;
case 4: symbol->encoded_data[y_coord][x_char] += 0x10; break;
case 5: symbol->encoded_data[y_coord][x_char] += 0x20; break;
case 6: symbol->encoded_data[y_coord][x_char] += 0x40; break;
} /* The last binary digit is reserved for colour barcodes */
#endif
} }
void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) /* Set (or unset) a module to white */
{ void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
symbol->encoded_data[y_coord][x_coord / 7] &= ~(1 << (x_coord % 7)); symbol->encoded_data[y_coord][x_coord / 7] &= ~(1 << (x_coord % 7));
#if 0
int x_char, x_sub;
x_char = x_coord / 7;
x_sub = x_coord % 7;
switch(x_sub) {
case 0: symbol->encoded_data[y_coord][x_char] -= 0x01; break;
case 1: symbol->encoded_data[y_coord][x_char] -= 0x02; break;
case 2: symbol->encoded_data[y_coord][x_char] -= 0x04; break;
case 3: symbol->encoded_data[y_coord][x_char] -= 0x08; break;
case 4: symbol->encoded_data[y_coord][x_char] -= 0x10; break;
case 5: symbol->encoded_data[y_coord][x_char] -= 0x20; break;
case 6: symbol->encoded_data[y_coord][x_char] -= 0x40; break;
} /* The last binary digit is reserved for colour barcodes */
#endif
} }
void expand(struct zint_symbol *symbol, char data[]) /* Expands from a width pattern to a bit pattern */
{ /* Expands from a width pattern to a bit pattern */ void expand(struct zint_symbol *symbol, char data[]) {
unsigned int reader, n = strlen(data); unsigned int reader, n = strlen(data);
int writer, i; int writer, i;
char latch; char latch;
writer = 0; writer = 0;
latch = '1'; latch = '1';
for(reader = 0; reader < n; reader++) { for (reader = 0; reader < n; reader++) {
for(i = 0; i < ctoi(data[reader]); i++) { for (i = 0; i < ctoi(data[reader]); i++) {
if(latch == '1') { set_module(symbol, symbol->rows, writer); } if (latch == '1') {
writer++; set_module(symbol, symbol->rows, writer);
} }
writer++;
}
latch = (latch == '1' ? '0' : '1'); latch = (latch == '1' ? '0' : '1');
} }
if(symbol->symbology != BARCODE_PHARMA) { if (symbol->symbology != BARCODE_PHARMA) {
if(writer > symbol->width) { if (writer > symbol->width) {
symbol->width = writer; symbol->width = writer;
} }
} else { } else {
/* Pharmacode One ends with a space - adjust for this */ /* Pharmacode One ends with a space - adjust for this */
if(writer > symbol->width + 2) { if (writer > symbol->width + 2) {
symbol->width = writer - 2; symbol->width = writer - 2;
} }
} }
symbol->rows = symbol->rows + 1; symbol->rows = symbol->rows + 1;
} }
/* Indicates which symbologies can have row binding */
int is_stackable(int symbology) { int is_stackable(int symbology) {
/* Indicates which symbologies can have row binding */ if (symbology < BARCODE_PDF417) {
if(symbology < BARCODE_PDF417) { return 1; } return 1;
if(symbology == BARCODE_CODE128B) { return 1; } }
if(symbology == BARCODE_ISBNX) { return 1; } if (symbology == BARCODE_CODE128B) {
if(symbology == BARCODE_EAN14) { return 1; } return 1;
if(symbology == BARCODE_NVE18) { return 1; } }
if(symbology == BARCODE_KOREAPOST) { return 1; } if (symbology == BARCODE_ISBNX) {
if(symbology == BARCODE_PLESSEY) { return 1; } return 1;
if(symbology == BARCODE_TELEPEN_NUM) { return 1; } }
if(symbology == BARCODE_ITF14) { return 1; } if (symbology == BARCODE_EAN14) {
if(symbology == BARCODE_CODE32) { return 1; } return 1;
}
if (symbology == BARCODE_NVE18) {
return 1;
}
if (symbology == BARCODE_KOREAPOST) {
return 1;
}
if (symbology == BARCODE_PLESSEY) {
return 1;
}
if (symbology == BARCODE_TELEPEN_NUM) {
return 1;
}
if (symbology == BARCODE_ITF14) {
return 1;
}
if (symbology == BARCODE_CODE32) {
return 1;
}
return 0; return 0;
} }
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
int is_extendable(int symbology) { int is_extendable(int symbology) {
/* Indicates which symbols can have addon */ if (symbology == BARCODE_EANX) {
if(symbology == BARCODE_EANX) { return 1; } return 1;
if(symbology == BARCODE_UPCA) { return 1; } }
if(symbology == BARCODE_UPCE) { return 1; } if (symbology == BARCODE_UPCA) {
if(symbology == BARCODE_ISBNX) { return 1; } return 1;
if(symbology == BARCODE_UPCA_CC) { return 1; } }
if(symbology == BARCODE_UPCE_CC) { return 1; } if (symbology == BARCODE_UPCE) {
if(symbology == BARCODE_EANX_CC) { return 1; } return 1;
}
if (symbology == BARCODE_ISBNX) {
return 1;
}
if (symbology == BARCODE_UPCA_CC) {
return 1;
}
if (symbology == BARCODE_UPCE_CC) {
return 1;
}
if (symbology == BARCODE_EANX_CC) {
return 1;
}
return 0; return 0;
} }
int roundup(float input) int roundup(float input) {
{ float remainder;
float remainder; int integer_part;
int integer_part;
integer_part = (int)input; integer_part = (int) input;
remainder = input - integer_part; remainder = input - integer_part;
if(remainder > 0.1) { if (remainder > 0.1) {
integer_part++; integer_part++;
} }
return integer_part; return integer_part;
} }
int istwodigits(unsigned char source[], int position) int istwodigits(unsigned char source[], int position) {
{ if ((source[position] >= '0') && (source[position] <= '9')) {
if((source[position] >= '0') && (source[position] <= '9')) { if ((source[position + 1] >= '0') && (source[position + 1] <= '9')) {
if((source[position + 1] >= '0') && (source[position + 1] <= '9')) { return 1;
return 1; }
} }
}
return 0; return 0;
} }
float froundup(float input) float froundup(float input) {
{ float fraction, output = 0.0;
float fraction, output = 0.0;
fraction = input - (int)input; fraction = input - (int) input;
if(fraction > 0.01) { output = (input - fraction) + 1.0; } else { output = input; } if (fraction > 0.01) {
output = (input - fraction) + 1.0;
} else {
output = input;
}
return output; return output;
} }
int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) /* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
{ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) {
int j, i, next; 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];
j++;
next = i + 2;
}
if(source[i] == 0xC3) {
preprocessed[j] = source[i + 1] + 64;
j++;
next = i + 2;
}
}
if(next == -1) {
strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)");
return ZINT_ERROR_INVALID_DATA;
}
i = next;
} while(i < *length);
preprocessed[j] = '\0';
*length = j;
return 0; 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];
j++;
next = i + 2;
}
if (source[i] == 0xC3) {
preprocessed[j] = source[i + 1] + 64;
j++;
next = i + 2;
}
}
if (next == -1) {
strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)");
return ZINT_ERROR_INVALID_DATA;
}
i = next;
} while (i < *length);
preprocessed[j] = '\0';
*length = j;
return 0;
} }
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) {
{ int bpos, jpos, error_number;
int bpos, jpos, error_number; int next;
int next;
bpos = 0; bpos = 0;
jpos = 0; jpos = 0;
error_number = 0; error_number = 0;
next = 0; next = 0;
do { do {
if(source[bpos] <= 0x7f) { if (source[bpos] <= 0x7f) {
/* 1 byte mode (7-bit ASCII) */ /* 1 byte mode (7-bit ASCII) */
vals[jpos] = source[bpos]; vals[jpos] = source[bpos];
next = bpos + 1; next = bpos + 1;
jpos++; jpos++;
} else { } else {
if((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) { if ((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) {
strcpy(symbol->errtxt, "Corrupt Unicode data"); strcpy(symbol->errtxt, "Corrupt Unicode data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) { if ((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) {
strcpy(symbol->errtxt, "Overlong encoding not supported"); strcpy(symbol->errtxt, "Overlong encoding not supported");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) { if ((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) {
/* 2 byte mode */ /* 2 byte mode */
vals[jpos] = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f); vals[jpos] = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f);
next = bpos + 2; next = bpos + 2;
jpos++; jpos++;
} else } else
if((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) { if ((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) {
/* 3 byte mode */ /* 3 byte mode */
vals[jpos] = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f); vals[jpos] = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f);
next = bpos + 3; next = bpos + 3;
jpos ++; jpos++;
} else } else
if(source[bpos] >= 0xf0) { if (source[bpos] >= 0xf0) {
strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported"); strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
} }
bpos = next; bpos = next;
} while(bpos < *length); } while (bpos < *length);
*length = jpos; *length = jpos;
return error_number; return error_number;
} }

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -26,9 +26,9 @@
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* Used in some logic */ /* Used in some logic */
#ifndef __COMMON_H #ifndef __COMMON_H
@ -48,32 +48,31 @@
#include "zint.h" #include "zint.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif /* __cplusplus */ #endif /* __cplusplus */
extern int ustrlen(const unsigned char source[]); extern int ustrlen(const unsigned char source[]);
extern void ustrcpy(unsigned char target[], const unsigned char source[]); extern void ustrcpy(unsigned char target[], const unsigned char source[]);
extern void concat(char dest[], const char source[]); extern void concat(char dest[], const char source[]);
extern void uconcat(unsigned char dest[], const unsigned char source[]); extern void uconcat(unsigned char dest[], const unsigned char source[]);
extern int ctoi(char source); extern int ctoi(char source);
extern char itoc(int source); extern char itoc(int source);
extern void to_upper(unsigned char source[]); extern void to_upper(unsigned char source[]);
extern int is_sane(char test_string[], unsigned char source[], int length); extern int is_sane(char test_string[], unsigned char source[], int length);
extern void lookup(char set_string[],const char *table[], char data, char dest[]); extern void lookup(char set_string[], const char *table[], char data, char dest[]);
extern int posn(char set_string[], char data); extern int posn(char set_string[], char data);
extern void expand(struct zint_symbol *symbol, char data[]); extern void expand(struct zint_symbol *symbol, char data[]);
extern int is_stackable(int symbology); extern int is_stackable(int symbology);
extern int is_extendable(int symbology); extern int is_extendable(int symbology);
extern int roundup(float input); extern int roundup(float input);
extern int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord); extern int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord);
extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord); extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord);
extern void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord); extern void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord);
extern int istwodigits(unsigned char source[], int position); extern int istwodigits(unsigned char source[], int position);
extern float froundup(float input); extern float froundup(float input);
extern int parunmodd(unsigned char llyth); 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(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length);
extern int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length); extern int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

File diff suppressed because it is too large Load Diff

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -26,9 +26,9 @@
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#define NUMERIC 110 #define NUMERIC 110
#define ALPHA 97 #define ALPHA 97
@ -39,35 +39,35 @@
/* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */ /* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */
static const int ccaCoeffs[30] = { static const int ccaCoeffs[30] = {
/* k = 4 */ /* k = 4 */
522, 568, 723, 809, 522, 568, 723, 809,
/* k = 5 */ /* k = 5 */
427, 919, 460, 155, 566, 427, 919, 460, 155, 566,
/* k = 6 */ /* k = 6 */
861, 285, 19, 803, 17, 766, 861, 285, 19, 803, 17, 766,
/* k = 7 */ /* k = 7 */
76, 925, 537, 597, 784, 691, 437, 76, 925, 537, 597, 784, 691, 437,
/* k = 8 */ /* k = 8 */
237, 308, 436, 284, 646, 653, 428, 379 237, 308, 436, 284, 646, 653, 428, 379
}; };
/* rows, error codewords, k-offset of valid CC-A sizes from ISO/IEC 24723:2006 Table 9 */ /* rows, error codewords, k-offset of valid CC-A sizes from ISO/IEC 24723:2006 Table 9 */
static const int ccaVariants[51] = { static const int ccaVariants[51] = {
5, 6, 7, 8, 9, 10, 12, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7, 5, 6, 7, 8, 9, 10, 12, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7,
4, 4, 5, 5, 6, 6, 7, 4, 5, 6, 7, 7, 4, 5, 6, 7, 8, 4, 4, 5, 5, 6, 6, 7, 4, 5, 6, 7, 7, 4, 5, 6, 7, 8,
0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22 0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22
}; };
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24723:2006 tables 10 and 11 */ /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24723:2006 tables 10 and 11 */
static const int aRAPTable[68] = { static const int aRAPTable[68] = {
39, 1, 32, 8, 14, 43, 20, 11, 1, 5, 15, 21, 40, 43, 46, 34, 29, 39, 1, 32, 8, 14, 43, 20, 11, 1, 5, 15, 21, 40, 43, 46, 34, 29,
0, 0, 0, 0, 0, 0, 0, 43, 33, 37, 47, 1, 20, 23, 26, 14, 9, 0, 0, 0, 0, 0, 0, 0, 43, 33, 37, 47, 1, 20, 23, 26, 14, 9,
19, 33, 12, 40, 46, 23, 52, 23, 13, 17, 27, 33, 52, 3, 6, 46, 41, 19, 33, 12, 40, 46, 23, 52, 23, 13, 17, 27, 33, 52, 3, 6, 46, 41,
6, 0, 3, 3, 3, 0, 3, 3, 0, 3, 6, 6, 0, 0, 0, 0, 3 6, 0, 3, 3, 3, 0, 3, 3, 0, 3, 6, 6, 0, 0, 0, 0, 3
}; };
/* Row Address Patterns are as defined in pdf417.h */ /* Row Address Patterns are as defined in pdf417.h */

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* /*
Containes Extended Rectangular Data Matrix (DMRE) Containes Extended Rectangular Data Matrix (DMRE)
@ -41,11 +41,10 @@
#ifndef __IEC16022ECC200_H #ifndef __IEC16022ECC200_H
#define __IEC16022ECC200_H #define __IEC16022ECC200_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif /* __cplusplus */ #endif /* __cplusplus */
extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length); extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length);
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -62,28 +61,32 @@ extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], i
#define DM_BASE256 6 #define DM_BASE256 6
static const int c40_shift[] = { static const int c40_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
static const int c40_value[] = { static const int c40_value[] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15,16,17,18,19,20,21,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39, 15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
};
static const int text_shift[] = { static const int text_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3
};
static const int text_value[] = { static const int text_value[] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26, 15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31
};
// Activate DMRE Extensions // Activate DMRE Extensions
//#define DMRE //#define DMRE
@ -92,20 +95,21 @@ static const int text_value[] = {
// Position in option array [symbol option value - 1] // Position in option array [symbol option value - 1]
// The position in the option array is by increasing total data codewords with square first // The position in the option array is by increasing total data codewords with square first
static const int intsymbol[] = { static const int intsymbol[] = {
0, /* 1: 10x10 , 3*/ 1, /* 2: 12x12 , 5*/ 3, /* 3: 14x14 , 8*/ 5, /* 4: 16x16 , 12*/ 0, /* 1: 10x10 , 3*/ 1, /* 2: 12x12 , 5*/ 3, /* 3: 14x14 , 8*/ 5, /* 4: 16x16 , 12*/
7, /* 5: 18x18 , 18*/ 9, /* 6: 20x20 , 22*/ 12, /* 7: 22x22 , 30*/ 14, /* 8: 24x24 , 36*/ 7, /* 5: 18x18 , 18*/ 9, /* 6: 20x20 , 22*/ 12, /* 7: 22x22 , 30*/ 14, /* 8: 24x24 , 36*/
16, /* 9: 26x26 , 44*/ 21, /* 10: 32x32 , 62*/ 25, /* 11: 36x36 , 86*/ 28, /* 12: 40x40 ,114*/ 16, /* 9: 26x26 , 44*/ 21, /* 10: 32x32 , 62*/ 25, /* 11: 36x36 , 86*/ 28, /* 12: 40x40 ,114*/
30, /* 13: 44x44 ,144*/ 31, /* 14: 48x48 ,174*/ 32, /* 15: 52x52 ,204*/ 33, /* 16: 64x64 ,280*/ 30, /* 13: 44x44 ,144*/ 31, /* 14: 48x48 ,174*/ 32, /* 15: 52x52 ,204*/ 33, /* 16: 64x64 ,280*/
34, /* 17: 72x72 ,368*/ 35, /* 18: 80x80 ,456*/ 36, /* 19: 88x88 ,576*/ 37, /* 20: 96x96 ,696*/ 34, /* 17: 72x72 ,368*/ 35, /* 18: 80x80 ,456*/ 36, /* 19: 88x88 ,576*/ 37, /* 20: 96x96 ,696*/
38, /* 21:104x104,816*/ 39, /* 22:120x120,1050*/40, /* 23:132x132,1304*/41, /* 24:144x144,1558*/ 38, /* 21:104x104,816*/ 39, /* 22:120x120,1050*/40, /* 23:132x132,1304*/41, /* 24:144x144,1558*/
2, /* 25: 8x18 , 5*/ 4, /* 26: 8x32 , 10*/ 6, /* 27: 12x26 , 16*/ 10, /* 28: 12x36 , 22*/ 2, /* 25: 8x18 , 5*/ 4, /* 26: 8x32 , 10*/ 6, /* 27: 12x26 , 16*/ 10, /* 28: 12x36 , 22*/
13, /* 29: 16x36 , 32*/ 17, /* 30: 16x48 , 49*/ 8, /* 31: 8x48 , 18*/ 11, /* 32: 8x64 , 24*/ 13, /* 29: 16x36 , 32*/ 17, /* 30: 16x48 , 49*/ 8, /* 31: 8x48 , 18*/ 11, /* 32: 8x64 , 24*/
15, /* 33: 12x64 , 43*/ 22, /* 34: 16x64 , 62*/ 18, /* 35: 24x32 , 49*/ 20, /* 36: 24x36 , 55*/ 15, /* 33: 12x64 , 43*/ 22, /* 34: 16x64 , 62*/ 18, /* 35: 24x32 , 49*/ 20, /* 36: 24x36 , 55*/
24, /* 37: 24x48 , 80*/ 27, /* 38: 24x64 ,108*/ 19, /* 39: 26x32 , 52*/ 23, /* 40: 26x40 , 70*/ 24, /* 37: 24x48 , 80*/ 27, /* 38: 24x64 ,108*/ 19, /* 39: 26x32 , 52*/ 23, /* 40: 26x40 , 70*/
26, /* 41: 26x48 , 90*/ 29, /* 42: 26x64 ,118*/ 26, /* 41: 26x48 , 90*/ 29, /* 42: 26x64 ,118*/
0 }; 0
};
// Number of DM Sizes // Number of DM Sizes
#define DMSIZESCOUNT 42 #define DMSIZESCOUNT 42
@ -115,120 +119,121 @@ static const int intsymbol[] = {
// Horizontal matrix size // Horizontal matrix size
static const int matrixH[] = { static const int matrixH[] = {
/*0*/ 10, /* 10x10 ,3 */ 12, /* 12x12 ,5 */ 8, /* 8x18 ,5 */ 14, /* 14x14 , 8 */ /*0*/ 10, /* 10x10 ,3 */ 12, /* 12x12 ,5 */ 8, /* 8x18 ,5 */ 14, /* 14x14 , 8 */
/*4*/ 8, /* 8x32 ,10 */ 16, /* 16x16 ,12 */ 12, /* 12x26 ,16 */ 18, /* 18x18 ,18 */ /*4*/ 8, /* 8x32 ,10 */ 16, /* 16x16 ,12 */ 12, /* 12x26 ,16 */ 18, /* 18x18 ,18 */
/*8*/ 8, /* 8x48 ,18 */ 20, /* 20x20 ,22 */ 12, /* 12x36 ,22 */ 8, /* 8x64 ,24 */ /*8*/ 8, /* 8x48 ,18 */ 20, /* 20x20 ,22 */ 12, /* 12x36 ,22 */ 8, /* 8x64 ,24 */
/*12*/ 22, /* 22x22 ,30 */ 16, /* 16x36 ,32 */ 24, /* 24x24 ,36 */ 12, /* 12x64 ,43 */ /*12*/ 22, /* 22x22 ,30 */ 16, /* 16x36 ,32 */ 24, /* 24x24 ,36 */ 12, /* 12x64 ,43 */
/*16*/ 26, /* 26x26 ,44 */ 16, /* 16x48 ,49 */ 24, /* 24x32 ,49 */ 26, /* 26x32 ,52 */ /*16*/ 26, /* 26x26 ,44 */ 16, /* 16x48 ,49 */ 24, /* 24x32 ,49 */ 26, /* 26x32 ,52 */
/*20*/ 24, /* 24x36 ,55 */ 32, /* 32x32 ,62 */ 16, /* 16x64 ,62 */ 26, /* 26x40 ,70 */ /*20*/ 24, /* 24x36 ,55 */ 32, /* 32x32 ,62 */ 16, /* 16x64 ,62 */ 26, /* 26x40 ,70 */
/*24*/ 24, /* 24x48 ,80 */ 36, /* 36x36 ,86 */ 26, /* 26x48 ,90 */ 24, /* 24x64 ,108*/ /*24*/ 24, /* 24x48 ,80 */ 36, /* 36x36 ,86 */ 26, /* 26x48 ,90 */ 24, /* 24x64 ,108*/
/*28*/ 40, /* 40x40 ,114*/ 26, /* 26x64 ,118*/ 44, /* 44x44 ,144*/ 48, /* 48x48,174 */ /*28*/ 40, /* 40x40 ,114*/ 26, /* 26x64 ,118*/ 44, /* 44x44 ,144*/ 48, /* 48x48,174 */
/*32*/ 52, /* 52x52,204 */ 64, /* 64x64,280 */ 72, /* 72x72,368 */ 80, /* 80x80,456 */ /*32*/ 52, /* 52x52,204 */ 64, /* 64x64,280 */ 72, /* 72x72,368 */ 80, /* 80x80,456 */
/*36*/ 88, /* 88x88,576 */ 96, /* 96x96,696 */ 104,/*104x104,816*/ 120,/*120x120,1050*/ /*36*/ 88, /* 88x88,576 */ 96, /* 96x96,696 */ 104, /*104x104,816*/ 120, /*120x120,1050*/
/*40*/ 132,/*132x132,1304*/144/*144x144,1558*/ /*40*/ 132, /*132x132,1304*/144/*144x144,1558*/
}; };
// Vertical matrix sizes // Vertical matrix sizes
static const int matrixW[] = { static const int matrixW[] = {
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */ /*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
/*4*/ 32, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */ /*4*/ 32, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
/*8*/ 48, /* 8x48 */ 20, /* 20x20 */ 36, /* 12x36 */ 64, /* 8x64 */ /*8*/ 48, /* 8x48 */ 20, /* 20x20 */ 36, /* 12x36 */ 64, /* 8x64 */
/*12*/ 22, /* 22x22 */ 36, /* 16x36 */ 24, /* 24x24 */ 64, /* 12x64 */ /*12*/ 22, /* 22x22 */ 36, /* 16x36 */ 24, /* 24x24 */ 64, /* 12x64 */
/*16*/ 26, /* 26x26 */ 48, /* 16x48 */ 32, /* 24x32 */ 32, /* 26x32 */ /*16*/ 26, /* 26x26 */ 48, /* 16x48 */ 32, /* 24x32 */ 32, /* 26x32 */
/*20*/ 36, /* 24x36 */ 32, /* 32x32 */ 64, /* 16x64 */ 40, /* 26x40 */ /*20*/ 36, /* 24x36 */ 32, /* 32x32 */ 64, /* 16x64 */ 40, /* 26x40 */
/*24*/ 48, /* 24x48 */ 36, /* 36x36 */ 48, /* 26x48 */ 64, /* 24x64 */ /*24*/ 48, /* 24x48 */ 36, /* 36x36 */ 48, /* 26x48 */ 64, /* 24x64 */
/*28*/ 40, /* 40x40 */ 64, /* 26x64 */ 44, /* 44x44 */ 48, /* 48x48 */ /*28*/ 40, /* 40x40 */ 64, /* 26x64 */ 44, /* 44x44 */ 48, /* 48x48 */
/*32*/ 52, /* 52x52 */ 64, /* 64x64 */ 72, /* 72x72 */ 80, /* 80x80 */ /*32*/ 52, /* 52x52 */ 64, /* 64x64 */ 72, /* 72x72 */ 80, /* 80x80 */
/*36*/ 88, /* 88x88 */ 96, /* 96x96 */ 104,/*104x104*/ 120,/*120x120*/ /*36*/ 88, /* 88x88 */ 96, /* 96x96 */ 104, /*104x104*/ 120, /*120x120*/
/*40*/ 132,/*132x132*/ 144 /*144x144*/ /*40*/ 132, /*132x132*/ 144 /*144x144*/
}; };
// Horizontal submodule size (including subfinder) // Horizontal submodule size (including subfinder)
static const int matrixFH[] = { static const int matrixFH[] = {
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */ /*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */
/*4*/ 8, /* 8x32 */ 16, /* 16x16 */ 12, /* 12x26 */ 18, /* 18x18 */ /*4*/ 8, /* 8x32 */ 16, /* 16x16 */ 12, /* 12x26 */ 18, /* 18x18 */
/*8*/ 8, /* 8x48 */ 20, /* 20x20 */ 12, /* 12x36 */ 8, /* 8x64 */ /*8*/ 8, /* 8x48 */ 20, /* 20x20 */ 12, /* 12x36 */ 8, /* 8x64 */
/*12*/ 22, /* 22x22 */ 16, /* 16x36 */ 24, /* 24x24 */ 12, /* 12x64 */ /*12*/ 22, /* 22x22 */ 16, /* 16x36 */ 24, /* 24x24 */ 12, /* 12x64 */
/*16*/ 26, /* 26x26 */ 16, /* 16x48 */ 24, /* 24x32 */ 26, /* 26x32 */ /*16*/ 26, /* 26x26 */ 16, /* 16x48 */ 24, /* 24x32 */ 26, /* 26x32 */
/*20*/ 24, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 26, /* 26x40 */ /*20*/ 24, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 26, /* 26x40 */
/*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 26, /* 26x48 */ 24, /* 24x64 */ /*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 26, /* 26x48 */ 24, /* 24x64 */
/*28*/ 20, /* 40x40 */ 26, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */ /*28*/ 20, /* 40x40 */ 26, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */
/*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */ /*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */
/*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/ /*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/
/*40*/ 22, /*132x132*/ 24 /*144x144*/ /*40*/ 22, /*132x132*/ 24 /*144x144*/
}; };
// Vertical submodule size (including subfinder) // Vertical submodule size (including subfinder)
static const int matrixFW[] = { static const int matrixFW[] = {
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */ /*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
/*4*/ 16, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */ /*4*/ 16, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
/*8*/ 24, /* 8x48 */ 20, /* 20x20 */ 18, /* 12x36 */ 16, /* 8x64 */ /*8*/ 24, /* 8x48 */ 20, /* 20x20 */ 18, /* 12x36 */ 16, /* 8x64 */
/*12*/ 22, /* 22x22 */ 18, /* 16x36 */ 24, /* 24x24 */ 16, /* 12x64 */ /*12*/ 22, /* 22x22 */ 18, /* 16x36 */ 24, /* 24x24 */ 16, /* 12x64 */
/*16*/ 26, /* 26x26 */ 24, /* 16x48 */ 16, /* 24x32 */ 16, /* 26x32 */ /*16*/ 26, /* 26x26 */ 24, /* 16x48 */ 16, /* 24x32 */ 16, /* 26x32 */
/*20*/ 18, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 20, /* 26x40 */ /*20*/ 18, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 20, /* 26x40 */
/*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 24, /* 26x48 */ 16, /* 24x64 */ /*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 24, /* 26x48 */ 16, /* 24x64 */
/*28*/ 20, /* 40x40 */ 16, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */ /*28*/ 20, /* 40x40 */ 16, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */
/*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */ /*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */
/*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/ /*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/
/*40*/ 22, /*132x132*/ 24 /*144x144*/ /*40*/ 22, /*132x132*/ 24 /*144x144*/
}; };
// Total Data Codewords // Total Data Codewords
static const int matrixbytes[] = { static const int matrixbytes[] = {
/*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */ /*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
/*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */ /*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
/*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */ /*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */ /*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */
/*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */ /*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */
/*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */ /*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */
/*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108, /* 24x64 */ /*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108, /* 24x64 */
/*28*/ 114, /* 40x40 */ 118, /* 26x64 */ 144, /* 44x44 */ 174, /* 48x48 */ /*28*/ 114, /* 40x40 */ 118, /* 26x64 */ 144, /* 44x44 */ 174, /* 48x48 */
/*32*/ 204, /* 52x52 */ 280, /* 64x64 */ 368, /* 72x72 */ 456, /* 80x80 */ /*32*/ 204, /* 52x52 */ 280, /* 64x64 */ 368, /* 72x72 */ 456, /* 80x80 */
/*36*/ 576, /* 88x88 */ 696, /* 96x96 */ 816, /*104x104*/ 1050, /*120x120*/ /*36*/ 576, /* 88x88 */ 696, /* 96x96 */ 816, /*104x104*/ 1050, /*120x120*/
/*40*/ 1304, /*132x132*/ 1558 /*144x144*/ /*40*/ 1304, /*132x132*/ 1558 /*144x144*/
}; };
// Data Codewords per RS-Block // Data Codewords per RS-Block
static const int matrixdatablock[] = { static const int matrixdatablock[] = {
/*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */ /*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
/*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */ /*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
/*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */ /*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */ /*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */
/*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */ /*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */
/*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */ /*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */
/*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108,/* 24x64 */ /*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108, /* 24x64 */
/*28*/ 114,/* 40x40 */ 118,/* 26x64 */ 144,/* 44x44 */ 174,/* 48x48 */ /*28*/ 114, /* 40x40 */ 118, /* 26x64 */ 144, /* 44x44 */ 174, /* 48x48 */
/*32*/ 102,/* 52x52 */ 140,/* 64x64 */ 92, /* 72x72 */ 114,/* 80x80 */ /*32*/ 102, /* 52x52 */ 140, /* 64x64 */ 92, /* 72x72 */ 114, /* 80x80 */
/*36*/ 144,/* 88x88 */ 174,/* 96x96 */ 136,/*104x104*/ 175,/*120x120*/ /*36*/ 144, /* 88x88 */ 174, /* 96x96 */ 136, /*104x104*/ 175, /*120x120*/
/*40*/ 163,/*132x132*/ 156 /*144x144*/ /*40*/ 163, /*132x132*/ 156 /*144x144*/
}; };
// ECC Codewords per RS-Block // ECC Codewords per RS-Block
static const int matrixrsblock[] = { static const int matrixrsblock[] = {
/*0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */ /*0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */
/*4*/ 11, /* 8x32 */ 12, /* 16x16 */ 14, /* 12x26 */ 14, /* 18x18 */ /*4*/ 11, /* 8x32 */ 12, /* 16x16 */ 14, /* 12x26 */ 14, /* 18x18 */
/*8*/ 15, /* 8x48 */ 18, /* 20x20 */ 18, /* 12x36 */ 18, /* 8x64 */ /*8*/ 15, /* 8x48 */ 18, /* 20x20 */ 18, /* 12x36 */ 18, /* 8x64 */
/*12*/ 20, /* 22x22 */ 24, /* 16x36 */ 24, /* 24x24 */ 27, /* 12x64 */ /*12*/ 20, /* 22x22 */ 24, /* 16x36 */ 24, /* 24x24 */ 27, /* 12x64 */
/*16*/ 28, /* 26x26 */ 28, /* 16x48 */ 28, /* 24x32 */ 32, /* 26x32 */ /*16*/ 28, /* 26x26 */ 28, /* 16x48 */ 28, /* 24x32 */ 32, /* 26x32 */
/*20*/ 33, /* 24x36 */ 36, /* 32x32 */ 36, /* 16x64 */ 38, /* 26x40 */ /*20*/ 33, /* 24x36 */ 36, /* 32x32 */ 36, /* 16x64 */ 38, /* 26x40 */
/*24*/ 41, /* 24x48 */ 42, /* 36x36 */ 42, /* 26x48 */ 46, /* 24x64 */ /*24*/ 41, /* 24x48 */ 42, /* 36x36 */ 42, /* 26x48 */ 46, /* 24x64 */
/*28*/ 48, /* 40x40 */ 50, /* 26x64 */ 56, /* 44x44 */ 68, /* 48x48 */ /*28*/ 48, /* 40x40 */ 50, /* 26x64 */ 56, /* 44x44 */ 68, /* 48x48 */
/*32*/ 42, /* 52x52 */ 56, /* 64x64 */ 36, /* 72x72 */ 48, /* 80x80 */ /*32*/ 42, /* 52x52 */ 56, /* 64x64 */ 36, /* 72x72 */ 48, /* 80x80 */
/*36*/ 56, /* 88x88 */ 68, /* 96x96 */ 56, /*104x104*/ 68, /*120x120*/ /*36*/ 56, /* 88x88 */ 68, /* 96x96 */ 56, /*104x104*/ 68, /*120x120*/
/*40*/ 62, /*132x132*/ 62 /*144x144*/ /*40*/ 62, /*132x132*/ 62 /*144x144*/
}; };
#else #else
// No Rectangular extensions // No Rectangular extensions
static const int intsymbol[] = { static const int intsymbol[] = {
0,1,3,5,7,8,10,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,2,4,6,9,11,14 }; 0, 1, 3, 5, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2, 4, 6, 9, 11, 14
};
// Number of DM Sizes // Number of DM Sizes
#define DMSIZESCOUNT 30 #define DMSIZESCOUNT 30
@ -236,33 +241,40 @@ static const int intsymbol[] = {
#define INTSYMBOL144 29 #define INTSYMBOL144 29
static const int matrixH[] = { static const int matrixH[] = {
10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 32, 36, 40, 44, 48, 10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 32, 36, 40, 44, 48,
52, 64, 72, 80, 88, 96, 104, 120, 132, 144 }; 52, 64, 72, 80, 88, 96, 104, 120, 132, 144
};
static const int matrixW[] = { static const int matrixW[] = {
10, 12, 18, 14, 32, 16, 26, 18, 20, 36, 22, 36, 24, 26, 48, 32, 36, 40, 44, 10, 12, 18, 14, 32, 16, 26, 18, 20, 36, 22, 36, 24, 26, 48, 32, 36, 40, 44,
48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144 }; 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144
};
static const int matrixFH[] = { static const int matrixFH[] = {
10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 16, 18, 20, 22, 24, 10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 16, 18, 20, 22, 24,
26, 16, 18, 20, 22, 24, 26, 20, 22, 24 }; 26, 16, 18, 20, 22, 24, 26, 20, 22, 24
};
static const int matrixFW[] = { static const int matrixFW[] = {
10, 12, 18, 14, 16, 16, 26, 18, 20, 18, 22, 18, 24, 26, 24, 16, 18, 20, 22, 10, 12, 18, 14, 16, 16, 26, 18, 20, 18, 22, 18, 24, 26, 24, 16, 18, 20, 22,
24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24 }; 24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24
};
static const int matrixbytes[] = { static const int matrixbytes[] = {
3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144,
174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558 }; 174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558
};
static const int matrixdatablock[] = { static const int matrixdatablock[] = {
3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144,
174, 102, 140, 92, 114, 144, 174, 136, 175, 163, 156 }; 174, 102, 140, 92, 114, 144, 174, 136, 175, 163, 156
};
static const int matrixrsblock[] = { static const int matrixrsblock[] = {
5, 7, 7, 10, 11, 12, 14, 14, 18, 18, 20, 24, 24, 28, 28, 36, 42, 48, 56, 68, 5, 7, 7, 10, 11, 12, 14, 14, 18, 18, 20, 24, 24, 28, 28, 36, 42, 48, 56, 68,
42, 56, 36, 48, 56, 68, 56, 68, 62, 62 }; 42, 56, 36, 48, 56, 68, 56, 68, 62, 62
};
#endif #endif
#endif /* __IEC16022ECC200_H */ #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/* gridmtx.h - definitions for Grid Matrix /* gridmtx.h - definitions for Grid Matrix
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -27,7 +27,7 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#define GM_NUMBER 1 #define GM_NUMBER 1
#define GM_LOWER 2 #define GM_LOWER 2
@ -40,132 +40,144 @@
#define EUROPIUM "0123456789ABCDEFGHIJKLMOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz " #define EUROPIUM "0123456789ABCDEFGHIJKLMOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
static const char shift_set[] = { static const char shift_set[] = {
/* From Table 7 - Encoding of control characters */ /* From Table 7 - Encoding of control characters */
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* NULL -> SI */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* NULL -> SI */
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* DLE -> US */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* DLE -> US */
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':',
';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~' ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
}; };
static const int gm_recommend_cw[] = { 9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021 }; static const int gm_recommend_cw[] = {
static const int gm_max_cw[] = { 11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313 }; 9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021
//static const int gm_total_cw[] = { 18, 50, 98, 162, 242, 338, 450, 578, 722, 882, 1058, 1250, 1458 }; };
static const int gm_max_cw[] = {
11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313
};
static const int gm_data_codewords[] = { static const int gm_data_codewords[] = {
0, 15, 13, 11, 9, 0, 15, 13, 11, 9,
45, 40, 35, 30, 25, 45, 40, 35, 30, 25,
89, 79, 69, 59, 49, 89, 79, 69, 59, 49,
146, 130, 114, 98, 81, 146, 130, 114, 98, 81,
218, 194, 170, 146, 121, 218, 194, 170, 146, 121,
305, 271, 237, 203, 169, 305, 271, 237, 203, 169,
405, 360, 315, 270, 225, 405, 360, 315, 270, 225,
521, 463, 405, 347, 289, 521, 463, 405, 347, 289,
650, 578, 506, 434, 361, 650, 578, 506, 434, 361,
794, 706, 618, 530, 441, 794, 706, 618, 530, 441,
953, 847, 741, 635, 529, 953, 847, 741, 635, 529,
1125, 1000, 875, 750, 625, 1125, 1000, 875, 750, 625,
1313, 1167, 1021, 875, 729 1313, 1167, 1021, 875, 729
}; };
static const int gm_n1[] = { 18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122 }; static const int gm_n1[] = {
static const int gm_b1[] = { 1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6 }; 18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122
static const int gm_b2[] = { 0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6 }; };
static const int gm_ebeb[] = { static const int gm_b1[] = {
/* E1 B3 E2 B4 */ 1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6
0, 0, 0, 0, // version 1 };
3, 1, 0, 0,
5, 1, 0, 0, static const int gm_b2[] = {
7, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6
9, 1, 0, 0, };
5, 1, 0, 0, // version 2
10, 1, 0, 0, static const int gm_ebeb[] = {
15, 1, 0, 0, /* E1 B3 E2 B4 */
20, 1, 0, 0, 0, 0, 0, 0, // version 1
25, 1, 0, 0, 3, 1, 0, 0,
9, 1, 0, 0, // version 3 5, 1, 0, 0,
19, 1, 0, 0, 7, 1, 0, 0,
29, 1, 0, 0, 9, 1, 0, 0,
39, 1, 0, 0, 5, 1, 0, 0, // version 2
49, 1, 0, 0, 10, 1, 0, 0,
8, 2, 0, 0, // version 4 15, 1, 0, 0,
16, 2, 0, 0, 20, 1, 0, 0,
24, 2, 0, 0, 25, 1, 0, 0,
32, 2, 0, 0, 9, 1, 0, 0, // version 3
41, 1, 10, 1, 19, 1, 0, 0,
12, 2, 0, 0, // version 5 29, 1, 0, 0,
24, 2, 0, 0, 39, 1, 0, 0,
36, 2, 0, 0, 49, 1, 0, 0,
48, 2, 0, 0, 8, 2, 0, 0, // version 4
61, 1, 60, 1, 16, 2, 0, 0,
11, 3, 0, 0, // version 6 24, 2, 0, 0,
23, 1, 22, 2, 32, 2, 0, 0,
34, 2, 33, 1, 41, 1, 10, 1,
45, 3, 0, 0, 12, 2, 0, 0, // version 5
57, 1, 56, 2, 24, 2, 0, 0,
12, 1, 11, 3, // version 7 36, 2, 0, 0,
23, 2, 22, 2, 48, 2, 0, 0,
34, 3, 33, 1, 61, 1, 60, 1,
45, 4, 0, 0, 11, 3, 0, 0, // version 6
57, 1, 56, 3, 23, 1, 22, 2,
12, 2, 11, 3, // version 8 34, 2, 33, 1,
23, 5, 0, 0, 45, 3, 0, 0,
35, 3, 34, 2, 57, 1, 56, 2,
47, 1, 46, 4, 12, 1, 11, 3, // version 7
58, 4, 57, 1, 23, 2, 22, 2,
12, 6, 0, 0, // version 9 34, 3, 33, 1,
24, 6, 0, 0, 45, 4, 0, 0,
36, 6, 0, 0, 57, 1, 56, 3,
48, 6, 0, 0, 12, 2, 11, 3, // version 8
61, 1, 60, 5, 23, 5, 0, 0,
13, 4, 12, 3, // version 10 35, 3, 34, 2,
26, 1, 25, 6, 47, 1, 46, 4,
38, 5, 37, 2, 58, 4, 57, 1,
51, 2, 50, 5, 12, 6, 0, 0, // version 9
63, 7, 0, 0, 24, 6, 0, 0,
12, 6, 11, 3, // version 11 36, 6, 0, 0,
24, 4, 23, 5, 48, 6, 0, 0,
36, 2, 35, 7, 61, 1, 60, 5,
47, 9, 0, 0, 13, 4, 12, 3, // version 10
59, 7, 58, 2, 26, 1, 25, 6,
13, 5, 12, 5, // version 12 38, 5, 37, 2,
25, 10, 0, 0, 51, 2, 50, 5,
38, 5, 37, 5, 63, 7, 0, 0,
50, 10, 0, 0, 12, 6, 11, 3, // version 11
63, 5, 62, 5, 24, 4, 23, 5,
13, 1, 12, 11, //version 13 36, 2, 35, 7,
25, 3, 24, 9, 47, 9, 0, 0,
37, 5, 36, 7, 59, 7, 58, 2,
49, 7, 48, 5, 13, 5, 12, 5, // version 12
61, 9, 60, 3 25, 10, 0, 0,
38, 5, 37, 5,
50, 10, 0, 0,
63, 5, 62, 5,
13, 1, 12, 11, //version 13
25, 3, 24, 9,
37, 5, 36, 7,
49, 7, 48, 5,
61, 9, 60, 3
}; };
static const int gm_macro_matrix[] = { static const int gm_macro_matrix[] = {
728,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650, 728, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650,
727,624,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,651, 727, 624, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 651,
726,623,528,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,553,652, 726, 623, 528, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 553, 652,
725,622,527,440,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,463,554,653, 725, 622, 527, 440, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 463, 554, 653,
724,621,526,439,360,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,381,464,555,654, 724, 621, 526, 439, 360, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 381, 464, 555, 654,
723,620,525,438,359,288,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,307,382,465,556,655, 723, 620, 525, 438, 359, 288, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 307, 382, 465, 556, 655,
722,619,524,437,358,287,224,169,170,171,172,173,174,175,176,177,178,179,180,181,182,241,308,383,466,557,656, 722, 619, 524, 437, 358, 287, 224, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 241, 308, 383, 466, 557, 656,
721,618,523,436,357,286,223,168,121,122,123,124,125,126,127,128,129,130,131,132,183,242,309,384,467,558,657, 721, 618, 523, 436, 357, 286, 223, 168, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 183, 242, 309, 384, 467, 558, 657,
720,617,522,435,356,285,222,167,120,81,82,83,84,85,86,87,88,89,90,133,184,243,310,385,468,559,658, 720, 617, 522, 435, 356, 285, 222, 167, 120, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 133, 184, 243, 310, 385, 468, 559, 658,
719,616,521,434,355,284,221,166,119,80,49,50,51,52,53,54,55,56,91,134,185,244,311,386,469,560,659, 719, 616, 521, 434, 355, 284, 221, 166, 119, 80, 49, 50, 51, 52, 53, 54, 55, 56, 91, 134, 185, 244, 311, 386, 469, 560, 659,
718,615,520,433,354,283,220,165,118,79,48,25,26,27,28,29,30,57,92,135,186,245,312,387,470,561,660, 718, 615, 520, 433, 354, 283, 220, 165, 118, 79, 48, 25, 26, 27, 28, 29, 30, 57, 92, 135, 186, 245, 312, 387, 470, 561, 660,
717,614,519,432,353,282,219,164,117,78,47,24,9,10,11,12,31,58,93,136,187,246,313,388,471,562,661, 717, 614, 519, 432, 353, 282, 219, 164, 117, 78, 47, 24, 9, 10, 11, 12, 31, 58, 93, 136, 187, 246, 313, 388, 471, 562, 661,
716,613,518,431,352,281,218,163,116,77,46,23,8,1,2,13,32,59,94,137,188,247,314,389,472,563,662, 716, 613, 518, 431, 352, 281, 218, 163, 116, 77, 46, 23, 8, 1, 2, 13, 32, 59, 94, 137, 188, 247, 314, 389, 472, 563, 662,
715,612,517,430,351,280,217,162,115,76,45,22,7,0,3,14,33,60,95,138,189,248,315,390,473,564,663, 715, 612, 517, 430, 351, 280, 217, 162, 115, 76, 45, 22, 7, 0, 3, 14, 33, 60, 95, 138, 189, 248, 315, 390, 473, 564, 663,
714,611,516,429,350,279,216,161,114,75,44,21,6,5,4,15,34,61,96,139,190,249,316,391,474,565,664, 714, 611, 516, 429, 350, 279, 216, 161, 114, 75, 44, 21, 6, 5, 4, 15, 34, 61, 96, 139, 190, 249, 316, 391, 474, 565, 664,
713,610,515,428,349,278,215,160,113,74,43,20,19,18,17,16,35,62,97,140,191,250,317,392,475,566,665, 713, 610, 515, 428, 349, 278, 215, 160, 113, 74, 43, 20, 19, 18, 17, 16, 35, 62, 97, 140, 191, 250, 317, 392, 475, 566, 665,
712,609,514,427,348,277,214,159,112,73,42,41,40,39,38,37,36,63,98,141,192,251,318,393,476,567,666, 712, 609, 514, 427, 348, 277, 214, 159, 112, 73, 42, 41, 40, 39, 38, 37, 36, 63, 98, 141, 192, 251, 318, 393, 476, 567, 666,
711,608,513,426,347,276,213,158,111,72,71,70,69,68,67,66,65,64,99,142,193,252,319,394,477,568,667, 711, 608, 513, 426, 347, 276, 213, 158, 111, 72, 71, 70, 69, 68, 67, 66, 65, 64, 99, 142, 193, 252, 319, 394, 477, 568, 667,
710,607,512,425,346,275,212,157,110,109,108,107,106,105,104,103,102,101,100,143,194,253,320,395,478,569,668, 710, 607, 512, 425, 346, 275, 212, 157, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 143, 194, 253, 320, 395, 478, 569, 668,
709,606,511,424,345,274,211,156,155,154,153,152,151,150,149,148,147,146,145,144,195,254,321,396,479,570,669, 709, 606, 511, 424, 345, 274, 211, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 195, 254, 321, 396, 479, 570, 669,
708,605,510,423,344,273,210,209,208,207,206,205,204,203,202,201,200,199,198,197,196,255,322,397,480,571,670, 708, 605, 510, 423, 344, 273, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, 255, 322, 397, 480, 571, 670,
707,604,509,422,343,272,271,270,269,268,267,266,265,264,263,262,261,260,259,258,257,256,323,398,481,572,671, 707, 604, 509, 422, 343, 272, 271, 270, 269, 268, 267, 266, 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, 323, 398, 481, 572, 671,
706,603,508,421,342,341,340,339,338,337,336,335,334,333,332,331,330,329,328,327,326,325,324,399,482,573,672, 706, 603, 508, 421, 342, 341, 340, 339, 338, 337, 336, 335, 334, 333, 332, 331, 330, 329, 328, 327, 326, 325, 324, 399, 482, 573, 672,
705,602,507,420,419,418,417,416,415,414,413,412,411,410,409,408,407,406,405,404,403,402,401,400,483,574,673, 705, 602, 507, 420, 419, 418, 417, 416, 415, 414, 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, 402, 401, 400, 483, 574, 673,
704,601,506,505,504,503,502,501,500,499,498,497,496,495,494,493,492,491,490,489,488,487,486,485,484,575,674, 704, 601, 506, 505, 504, 503, 502, 501, 500, 499, 498, 497, 496, 495, 494, 493, 492, 491, 490, 489, 488, 487, 486, 485, 484, 575, 674,
703,600,599,598,597,596,595,594,593,592,591,590,589,588,587,586,585,584,583,582,581,580,579,578,577,576,675, 703, 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, 590, 589, 588, 587, 586, 585, 584, 583, 582, 581, 580, 579, 578, 577, 576, 675,
702,701,700,699,698,697,696,695,694,693,692,691,690,689,688,687,686,685,684,683,682,681,680,679,678,677,676, 702, 701, 700, 699, 698, 697, 696, 695, 694, 693, 692, 691, 690, 689, 688, 687, 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, 676,
}; };

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -43,280 +43,316 @@
to be bulletproof, nor does it report very accurately what problem was found to be bulletproof, nor does it report very accurately what problem was found
or where, but should prevent some of the more common encoding errors */ or where, but should prevent some of the more common encoding errors */
void itostr(char ai_string[], int ai_value) void itostr(char ai_string[], int ai_value) {
{ int thou, hund, ten, unit;
int thou, hund, ten, unit; char temp[2];
char temp[2];
strcpy(ai_string, "("); strcpy(ai_string, "(");
thou = ai_value / 1000; thou = ai_value / 1000;
hund = (ai_value - (1000 * thou)) / 100; hund = (ai_value - (1000 * thou)) / 100;
ten = (ai_value - ((1000 * thou) + (100 * hund))) / 10; ten = (ai_value - ((1000 * thou) + (100 * hund))) / 10;
unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten)); unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten));
temp[1] = '\0'; temp[1] = '\0';
if(ai_value >= 1000) { temp[0] = itoc(thou); concat(ai_string, temp); } if (ai_value >= 1000) {
if(ai_value >= 100) { temp[0] = itoc(hund); concat(ai_string, temp); } temp[0] = itoc(thou);
temp[0] = itoc(ten); concat(ai_string, temp);
concat(ai_string, temp); }
temp[0] = itoc(unit); if (ai_value >= 100) {
concat(ai_string, temp); temp[0] = itoc(hund);
concat(ai_string, ")"); concat(ai_string, temp);
}
temp[0] = itoc(ten);
concat(ai_string, temp);
temp[0] = itoc(unit);
concat(ai_string, temp);
concat(ai_string, ")");
} }
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) {
{ int i, j, last_ai, ai_latch;
int i, j, last_ai, ai_latch; char ai_string[6];
char ai_string[6]; int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length;
int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length; int ai_value[100], ai_location[100], ai_count, data_location[100], data_length[100];
int ai_value[100], ai_location[100], ai_count, data_location[100], data_length[100]; int error_latch;
int error_latch;
/* Detect extended ASCII characters */ /* Detect extended ASCII characters */
for(i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
if(source[i] >=128) { if (source[i] >= 128) {
strcpy(symbol->errtxt, "Extended ASCII characters are not supported by GS1"); strcpy(symbol->errtxt, "Extended ASCII characters are not supported by GS1");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if(source[i] < 32) { if (source[i] < 32) {
strcpy(symbol->errtxt, "Control characters are not supported by GS1"); strcpy(symbol->errtxt, "Control characters are not supported by GS1");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
} }
if(source[0] != '[') { if (source[0] != '[') {
strcpy(symbol->errtxt, "Data does not start with an AI"); strcpy(symbol->errtxt, "Data does not start with an AI");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
/* Check the position of the brackets */ /* Check the position of the brackets */
bracket_level = 0; bracket_level = 0;
max_bracket_level = 0; max_bracket_level = 0;
ai_length = 0; ai_length = 0;
max_ai_length = 0; max_ai_length = 0;
min_ai_length = 5; min_ai_length = 5;
j = 0; j = 0;
ai_latch = 0; ai_latch = 0;
for(i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
ai_length += j; ai_length += j;
if(((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) { ai_latch = 1; } if (((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) {
if(source[i] == '[') { bracket_level++; j = 1; } ai_latch = 1;
if(source[i] == ']') { }
bracket_level--; if (source[i] == '[') {
if(ai_length < min_ai_length) { min_ai_length = ai_length; } bracket_level++;
j = 0; j = 1;
ai_length = 0; }
} if (source[i] == ']') {
if(bracket_level > max_bracket_level) { max_bracket_level = bracket_level; } bracket_level--;
if(ai_length > max_ai_length) { max_ai_length = ai_length; } if (ai_length < min_ai_length) {
} min_ai_length = ai_length;
min_ai_length--; }
j = 0;
ai_length = 0;
}
if (bracket_level > max_bracket_level) {
max_bracket_level = bracket_level;
}
if (ai_length > max_ai_length) {
max_ai_length = ai_length;
}
}
min_ai_length--;
if(bracket_level != 0) { if (bracket_level != 0) {
/* Not all brackets are closed */ /* Not all brackets are closed */
strcpy(symbol->errtxt, "Malformed AI in input data (brackets don\'t match)"); strcpy(symbol->errtxt, "Malformed AI in input data (brackets don\'t match)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if(max_bracket_level > 1) { if (max_bracket_level > 1) {
/* Nested brackets */ /* Nested brackets */
strcpy(symbol->errtxt, "Found nested brackets in input data"); strcpy(symbol->errtxt, "Found nested brackets in input data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if(max_ai_length > 4) { if (max_ai_length > 4) {
/* AI is too long */ /* AI is too long */
strcpy(symbol->errtxt, "Invalid AI in input data (AI too long)"); strcpy(symbol->errtxt, "Invalid AI in input data (AI too long)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if(min_ai_length <= 1) { if (min_ai_length <= 1) {
/* AI is too short */ /* AI is too short */
strcpy(symbol->errtxt, "Invalid AI in input data (AI too short)"); strcpy(symbol->errtxt, "Invalid AI in input data (AI too short)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if(ai_latch == 1) { if (ai_latch == 1) {
/* Non-numeric data in AI */ /* Non-numeric data in AI */
strcpy(symbol->errtxt, "Invalid AI in input data (non-numeric characters in AI)"); strcpy(symbol->errtxt, "Invalid AI in input data (non-numeric characters in AI)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
ai_count = 0; ai_count = 0;
for(i = 1; i < src_len; i++) { for (i = 1; i < src_len; i++) {
if(source[i - 1] == '[') { if (source[i - 1] == '[') {
ai_location[ai_count] = i; ai_location[ai_count] = i;
j = 0; j = 0;
do { do {
ai_string[j] = source[i + j]; ai_string[j] = source[i + j];
j++; j++;
} while (ai_string[j - 1] != ']'); } while (ai_string[j - 1] != ']');
ai_string[j - 1] = '\0'; ai_string[j - 1] = '\0';
ai_value[ai_count] = atoi(ai_string); ai_value[ai_count] = atoi(ai_string);
ai_count++; ai_count++;
} }
} }
for(i = 0; i < ai_count; i++) { for (i = 0; i < ai_count; i++) {
data_location[i] = ai_location[i] + 3; data_location[i] = ai_location[i] + 3;
if(ai_value[i] >= 100) { data_location[i]++; } if (ai_value[i] >= 100) {
if(ai_value[i] >= 1000) { data_location[i]++; } data_location[i]++;
data_length[i] = 0; }
do { if (ai_value[i] >= 1000) {
data_length[i]++; data_location[i]++;
} while ((source[data_location[i] + data_length[i] - 1] != '[') && (data_location[i] + data_length[i] <= src_len)); }
data_length[i]--; data_length[i] = 0;
} do {
data_length[i]++;
} while ((source[data_location[i] + data_length[i] - 1] != '[') && (data_location[i] + data_length[i] <= src_len));
data_length[i]--;
}
for(i = 0; i < ai_count; i++) { for (i = 0; i < ai_count; i++) {
if(data_length[i] == 0) { if (data_length[i] == 0) {
/* No data for given AI */ /* No data for given AI */
strcpy(symbol->errtxt, "Empty data field in input data"); strcpy(symbol->errtxt, "Empty data field in input data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
} }
error_latch = 0; error_latch = 0;
strcpy(ai_string, ""); strcpy(ai_string, "");
for(i = 0; i < ai_count; i++) { for (i = 0; i < ai_count; i++) {
switch (ai_value[i]) { switch (ai_value[i]) {
case 0: if(data_length[i] != 18) { error_latch = 1; } break; case 0: if (data_length[i] != 18) {
case 1: error_latch = 1;
case 2: }
case 3: if(data_length[i] != 14) { error_latch = 1; } break; break;
case 4: if(data_length[i] != 16) { error_latch = 1; } break; case 1:
case 11: case 2:
case 12: case 3: if (data_length[i] != 14) {
case 13: error_latch = 1;
case 14: }
case 15: break;
case 16: case 4: if (data_length[i] != 16) {
case 17: error_latch = 1;
case 18: }
case 19: if(data_length[i] != 6) { error_latch = 1; } break; break;
case 20: if(data_length[i] != 2) { error_latch = 1; } break; case 11:
case 23: case 12:
case 24: case 13:
case 25: case 14:
case 39: case 15:
case 40: case 16:
case 41: case 17:
case 42: case 18:
case 70: case 19: if (data_length[i] != 6) {
case 80: error_latch = 1;
case 81: error_latch = 2; break; }
} break;
if( case 20: if (data_length[i] != 2) {
((ai_value[i] >= 100) && (ai_value[i] <= 179)) error_latch = 1;
|| ((ai_value[i] >= 1000) && (ai_value[i] <= 1799)) }
|| ((ai_value[i] >= 200) && (ai_value[i] <= 229)) break;
|| ((ai_value[i] >= 2000) && (ai_value[i] <= 2299)) case 23:
|| ((ai_value[i] >= 300) && (ai_value[i] <= 309)) case 24:
|| ((ai_value[i] >= 3000) && (ai_value[i] <= 3099)) case 25:
|| ((ai_value[i] >= 31) && (ai_value[i] <= 36)) case 39:
|| ((ai_value[i] >= 310) && (ai_value[i] <= 369)) case 40:
) { case 41:
error_latch = 2; case 42:
} case 70:
if((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) { case 80:
if(data_length[i] != 6) { case 81: error_latch = 2;
error_latch = 1; break;
} }
} if (
if( ((ai_value[i] >= 100) && (ai_value[i] <= 179))
((ai_value[i] >= 370) && (ai_value[i] <= 379)) || ((ai_value[i] >= 1000) && (ai_value[i] <= 1799))
|| ((ai_value[i] >= 3700) && (ai_value[i] <= 3799)) || ((ai_value[i] >= 200) && (ai_value[i] <= 229))
) { || ((ai_value[i] >= 2000) && (ai_value[i] <= 2299))
error_latch = 2; || ((ai_value[i] >= 300) && (ai_value[i] <= 309))
} || ((ai_value[i] >= 3000) && (ai_value[i] <= 3099))
if((ai_value[i] >= 410) && (ai_value[i] <= 415)) { || ((ai_value[i] >= 31) && (ai_value[i] <= 36))
if(data_length[i] != 13) { || ((ai_value[i] >= 310) && (ai_value[i] <= 369))
error_latch = 1; ) {
} error_latch = 2;
} }
if( if ((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) {
((ai_value[i] >= 4100) && (ai_value[i] <= 4199)) if (data_length[i] != 6) {
|| ((ai_value[i] >= 700) && (ai_value[i] <= 703)) error_latch = 1;
|| ((ai_value[i] >= 800) && (ai_value[i] <= 810)) }
|| ((ai_value[i] >= 900) && (ai_value[i] <= 999)) }
|| ((ai_value[i] >= 9000) && (ai_value[i] <= 9999)) if (
) { ((ai_value[i] >= 370) && (ai_value[i] <= 379))
error_latch = 2; || ((ai_value[i] >= 3700) && (ai_value[i] <= 3799))
} ) {
if((error_latch < 4) && (error_latch > 0)) { error_latch = 2;
/* error has just been detected: capture AI */ }
itostr(ai_string, ai_value[i]); if ((ai_value[i] >= 410) && (ai_value[i] <= 415)) {
error_latch += 4; if (data_length[i] != 13) {
} error_latch = 1;
} }
}
if (
((ai_value[i] >= 4100) && (ai_value[i] <= 4199))
|| ((ai_value[i] >= 700) && (ai_value[i] <= 703))
|| ((ai_value[i] >= 800) && (ai_value[i] <= 810))
|| ((ai_value[i] >= 900) && (ai_value[i] <= 999))
|| ((ai_value[i] >= 9000) && (ai_value[i] <= 9999))
) {
error_latch = 2;
}
if ((error_latch < 4) && (error_latch > 0)) {
/* error has just been detected: capture AI */
itostr(ai_string, ai_value[i]);
error_latch += 4;
}
}
if(error_latch == 5) { if (error_latch == 5) {
strcpy(symbol->errtxt, "Invalid data length for AI "); strcpy(symbol->errtxt, "Invalid data length for AI ");
concat(symbol->errtxt, ai_string); concat(symbol->errtxt, ai_string);
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if(error_latch == 6) { if (error_latch == 6) {
strcpy(symbol->errtxt, "Invalid AI value "); strcpy(symbol->errtxt, "Invalid AI value ");
concat(symbol->errtxt, ai_string); concat(symbol->errtxt, ai_string);
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
/* Resolve AI data - put resulting string in 'reduced' */ /* Resolve AI data - put resulting string in 'reduced' */
j = 0; j = 0;
last_ai = 0; last_ai = 0;
ai_latch = 1; ai_latch = 1;
for(i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
if((source[i] != '[') && (source[i] != ']')) { if ((source[i] != '[') && (source[i] != ']')) {
reduced[j++] = source[i]; reduced[j++] = source[i];
} }
if(source[i] == '[') { if (source[i] == '[') {
/* Start of an AI string */ /* Start of an AI string */
if(ai_latch == 0) { if (ai_latch == 0) {
reduced[j++] = '['; reduced[j++] = '[';
} }
ai_string[0] = source[i + 1]; ai_string[0] = source[i + 1];
ai_string[1] = source[i + 2]; ai_string[1] = source[i + 2];
ai_string[2] = '\0'; ai_string[2] = '\0';
last_ai = atoi(ai_string); last_ai = atoi(ai_string);
ai_latch = 0; ai_latch = 0;
/* The following values from "GS-1 General Specification version 8.0 issue 2, May 2008" /* The following values from "GS-1 General Specification version 8.0 issue 2, May 2008"
figure 5.4.8.2.1 - 1 "Element Strings with Pre-Defined Length Using Application Identifiers" */ figure 5.4.8.2.1 - 1 "Element Strings with Pre-Defined Length Using Application Identifiers" */
if( if (
((last_ai >= 0) && (last_ai <= 4)) ((last_ai >= 0) && (last_ai <= 4))
|| ((last_ai >= 11) && (last_ai <= 20)) || ((last_ai >= 11) && (last_ai <= 20))
|| (last_ai == 23) /* legacy support - see 5.3.8.2.2 */ || (last_ai == 23) /* legacy support - see 5.3.8.2.2 */
|| ((last_ai >= 31) && (last_ai <= 36)) || ((last_ai >= 31) && (last_ai <= 36))
|| (last_ai == 41) || (last_ai == 41)
) { ) {
ai_latch = 1; ai_latch = 1;
} }
} }
/* The ']' character is simply dropped from the input */ /* The ']' character is simply dropped from the input */
} }
reduced[j] = '\0'; reduced[j] = '\0';
/* 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[], const unsigned int src_len, unsigned char reduced[]) int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]) {
{ /* Only to keep the compiler happy */
/* Only to keep the compiler happy */
#ifndef _MSC_VER #ifndef _MSC_VER
char temp[src_len + 5]; char temp[src_len + 5];
#else #else
char* temp = (char*)_alloca(src_len + 5); char* temp = (char*) _alloca(src_len + 5);
#endif #endif
int error_number; int error_number;
error_number = gs1_verify(symbol, source, src_len, temp); error_number = gs1_verify(symbol, source, src_len, temp);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
if (strlen(temp) < src_len + 5) { if (strlen(temp) < src_len + 5) {
ustrcpy(reduced, (unsigned char*)temp); ustrcpy(reduced, (unsigned char*) temp);
return 0; return 0;
} }
strcpy(symbol->errtxt, "ugs1_verify overflow"); strcpy(symbol->errtxt, "ugs1_verify overflow");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }

View File

@ -2,20 +2,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors 3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -26,9 +26,9 @@
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
#ifndef __GS1_H #ifndef __GS1_H
#define __GS1_H #define __GS1_H
@ -36,8 +36,8 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
extern int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]); extern int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]);
extern int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]); extern int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]);
#ifdef __cplusplus #ifdef __cplusplus
} }