mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Code format and audit, part 1
Update copyright info, remove unused code, etc.
This commit is contained in:
parent
ae335b104a
commit
77cdf77690
521
backend/2of5.c
521
backend/2of5.c
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -28,7 +28,7 @@
|
||||
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
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -39,331 +39,332 @@
|
||||
#define inline _inline
|
||||
#endif
|
||||
|
||||
static const char *C25MatrixTable[10] = {"113311", "311131", "131131", "331111", "113131", "313111",
|
||||
"133111", "111331", "311311", "131311"};
|
||||
static const char *C25MatrixTable[10] = {
|
||||
"113311", "311131", "131131", "331111", "113131", "313111",
|
||||
"133111", "111331", "311311", "131311"
|
||||
};
|
||||
|
||||
static const char *C25IndustTable[10] = {"1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
|
||||
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"};
|
||||
static const char *C25IndustTable[10] = {
|
||||
"1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
|
||||
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"
|
||||
};
|
||||
|
||||
static const char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
|
||||
"31131", "13131"};
|
||||
static const char *C25InterTable[10] = {
|
||||
"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
|
||||
"31131", "13131"
|
||||
};
|
||||
|
||||
static inline char check_digit(unsigned int count)
|
||||
{
|
||||
return itoc((10 - (count % 10)) % 10);
|
||||
static inline char check_digit(unsigned int count) {
|
||||
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) */
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
|
||||
/* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
|
||||
int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
error_number = 0;
|
||||
int i, error_number;
|
||||
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
|
||||
|
||||
if(length > 80) {
|
||||
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;
|
||||
}
|
||||
error_number = 0;
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "411111");
|
||||
if (length > 80) {
|
||||
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++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
/* start character */
|
||||
strcpy(dest, "411111");
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "41111");
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
/* Stop character */
|
||||
concat(dest, "41111");
|
||||
|
||||
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;
|
||||
char dest[512]; /* 6 + 40 * 10 + 6 + 1 */
|
||||
int i, error_number;
|
||||
char dest[512]; /* 6 + 40 * 10 + 6 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
error_number = 0;
|
||||
|
||||
if(length > 45) {
|
||||
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 character in data");
|
||||
return error_number;
|
||||
}
|
||||
if (length > 45) {
|
||||
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 character in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "313111");
|
||||
/* start character */
|
||||
strcpy(dest, "313111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "31113");
|
||||
/* Stop character */
|
||||
concat(dest, "31113");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Code 2 of 5 IATA */
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 45 * 10 + 3 + 1 */
|
||||
/* Code 2 of 5 IATA */
|
||||
int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 45 * 10 + 3 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
error_number = 0;
|
||||
|
||||
if(length > 45) {
|
||||
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 > 45) {
|
||||
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 */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
/* start */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
/* stop */
|
||||
concat (dest, "311");
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
/* stop */
|
||||
concat(dest, "311");
|
||||
|
||||
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 */
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
|
||||
/* Code 2 of 5 Data Logic */
|
||||
int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
error_number = 0;
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
|
||||
|
||||
if(length > 80) {
|
||||
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;
|
||||
}
|
||||
error_number = 0;
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
if (length > 80) {
|
||||
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++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "311");
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
/* Stop character */
|
||||
concat(dest, "311");
|
||||
|
||||
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;
|
||||
char bars[7], spaces[7], mixed[14], dest[1000];
|
||||
int i, j, k, error_number;
|
||||
char bars[7], spaces[7], mixed[14], dest[1000];
|
||||
#ifndef _MSC_VER
|
||||
unsigned char temp[length + 2];
|
||||
unsigned char temp[length + 2];
|
||||
#else
|
||||
unsigned char* temp = (unsigned char *)_alloca((length + 2) * sizeof(unsigned char));
|
||||
unsigned char* temp = (unsigned char *) _alloca((length + 2) * sizeof (unsigned char));
|
||||
#endif
|
||||
|
||||
error_number = 0;
|
||||
error_number = 0;
|
||||
|
||||
if(length > 89) {
|
||||
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 > 89) {
|
||||
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;
|
||||
}
|
||||
|
||||
ustrcpy(temp, (unsigned char *) "");
|
||||
/* 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 (length & 1)
|
||||
{
|
||||
ustrcpy(temp, (unsigned char *) "0");
|
||||
length++;
|
||||
}
|
||||
uconcat(temp, source);
|
||||
ustrcpy(temp, (unsigned char *) "");
|
||||
/* 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 (length & 1) {
|
||||
ustrcpy(temp, (unsigned char *) "0");
|
||||
length++;
|
||||
}
|
||||
uconcat(temp, source);
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i+=2 )
|
||||
{
|
||||
/* look up the bars and the spaces and put them in two strings */
|
||||
strcpy(bars, "");
|
||||
lookup(NEON, C25InterTable, temp[i], bars);
|
||||
strcpy(spaces, "");
|
||||
lookup(NEON, C25InterTable, temp[i + 1], spaces);
|
||||
for (i = 0; i < length; i += 2) {
|
||||
/* look up the bars and the spaces and put them in two strings */
|
||||
strcpy(bars, "");
|
||||
lookup(NEON, C25InterTable, temp[i], bars);
|
||||
strcpy(spaces, "");
|
||||
lookup(NEON, C25InterTable, temp[i + 1], spaces);
|
||||
|
||||
/* then merge (interlace) the strings together */
|
||||
k = 0;
|
||||
for(j = 0; j <= 4; j++)
|
||||
{
|
||||
mixed[k] = bars[j]; k++;
|
||||
mixed[k] = spaces[j]; k++;
|
||||
}
|
||||
mixed[k] = '\0';
|
||||
concat (dest, mixed);
|
||||
}
|
||||
/* then merge (interlace) the strings together */
|
||||
k = 0;
|
||||
for (j = 0; j <= 4; j++) {
|
||||
mixed[k] = bars[j];
|
||||
k++;
|
||||
mixed[k] = spaces[j];
|
||||
k++;
|
||||
}
|
||||
mixed[k] = '\0';
|
||||
concat(dest, mixed);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "311");
|
||||
/* Stop character */
|
||||
concat(dest, "311");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, temp);
|
||||
return error_number;
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, temp);
|
||||
return error_number;
|
||||
|
||||
}
|
||||
|
||||
int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
/* Interleaved 2-of-5 (ITF) */
|
||||
int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
|
||||
error_number = 0;
|
||||
error_number = 0;
|
||||
|
||||
count = 0;
|
||||
count = 0;
|
||||
|
||||
if(length > 13) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if (length > 13) {
|
||||
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 character in data");
|
||||
return error_number;
|
||||
}
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid character in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 13 - length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
localstr[i] = '0';
|
||||
}
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 13 - length;
|
||||
for (i = 0; i < zeroes; i++) {
|
||||
localstr[i] = '0';
|
||||
}
|
||||
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--) {
|
||||
count += 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));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
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));
|
||||
ustrcpy(symbol->text, (unsigned char*) localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutshe Post Leitcode */
|
||||
int i, error_number;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
int zeroes;
|
||||
/* Deutshe Post Leitcode */
|
||||
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
int zeroes;
|
||||
|
||||
error_number = 0;
|
||||
count = 0;
|
||||
if(length > 13) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
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;
|
||||
}
|
||||
error_number = 0;
|
||||
count = 0;
|
||||
if (length > 13) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
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;
|
||||
}
|
||||
|
||||
zeroes = 13 - length;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
for (i = 12; i >= 0; i--)
|
||||
{
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
zeroes = 13 - length;
|
||||
for (i = 0; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
if (i & 1) {
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
localstr[13] = check_digit(count);
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
for (i = 12; i >= 0; i--) {
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
|
||||
if (i & 1) {
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
localstr[13] = check_digit(count);
|
||||
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 */
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
/* Deutsche Post Identcode */
|
||||
int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
|
||||
count = 0;
|
||||
if(length > 11) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
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;
|
||||
}
|
||||
count = 0;
|
||||
if (length > 11) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
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;
|
||||
}
|
||||
|
||||
zeroes = 11 - length;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
for (i = 10; i >= 0; i--)
|
||||
{
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
zeroes = 11 - length;
|
||||
for (i = 0; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
if (i & 1) {
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
localstr[11] = check_digit(count);
|
||||
localstr[12] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
for (i = 10; i >= 0; i--) {
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
|
||||
if (i & 1) {
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
localstr[11] = check_digit(count);
|
||||
localstr[12] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*) localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
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
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
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
|
||||
without specific prior written permission.
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
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
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
#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",
|
||||
"000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110",
|
||||
"111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221",
|
||||
"023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203",
|
||||
"213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333",
|
||||
"003", "013"};
|
||||
static const char *AusCTable[64] = {
|
||||
"222", "300", "301", "302", "310", "311", "312", "320", "321", "322",
|
||||
"000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110",
|
||||
"111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221",
|
||||
"023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203",
|
||||
"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",
|
||||
"022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112",
|
||||
"113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203",
|
||||
"210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300",
|
||||
"301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331",
|
||||
"332", "333"};
|
||||
static const char *AusBarTable[64] = {
|
||||
"000", "001", "002", "003", "010", "011", "012", "013", "020", "021",
|
||||
"022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112",
|
||||
"113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203",
|
||||
"210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300",
|
||||
"301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331",
|
||||
"332", "333"
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -57,204 +63,191 @@ static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011",
|
||||
#define inline _inline
|
||||
#endif
|
||||
|
||||
static inline char convert_pattern(char data, int shift)
|
||||
{
|
||||
return (data - '0') << shift;
|
||||
static inline char convert_pattern(char data, int shift) {
|
||||
return (data - '0') << shift;
|
||||
}
|
||||
|
||||
void rs_error(char data_pattern[])
|
||||
{
|
||||
/* Adds Reed-Solomon error correction to auspost */
|
||||
/* Adds Reed-Solomon error correction to auspost */
|
||||
void rs_error(char data_pattern[]) {
|
||||
int reader, triple_writer = 0;
|
||||
char triple[31], inv_triple[31];
|
||||
unsigned char result[5];
|
||||
|
||||
int reader, triple_writer = 0;
|
||||
char triple[31], inv_triple[31];
|
||||
unsigned char result[5];
|
||||
for (reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++) {
|
||||
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 = 2; reader < strlen(data_pattern); reader += 3, triple_writer++)
|
||||
{
|
||||
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++) {
|
||||
inv_triple[reader] = triple[(triple_writer - 1) - reader];
|
||||
}
|
||||
|
||||
for(reader = 0; reader < triple_writer; reader++)
|
||||
{
|
||||
inv_triple[reader] = triple[(triple_writer - 1) - reader];
|
||||
}
|
||||
rs_init_gf(0x43);
|
||||
rs_init_code(4, 1);
|
||||
rs_encode(triple_writer, (unsigned char*) inv_triple, result);
|
||||
|
||||
rs_init_gf(0x43);
|
||||
rs_init_code(4, 1);
|
||||
rs_encode(triple_writer, (unsigned char*) inv_triple, result);
|
||||
|
||||
for(reader = 4; reader > 0; reader--)
|
||||
{
|
||||
concat(data_pattern, AusBarTable[(int)result[reader - 1]]);
|
||||
}
|
||||
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 */
|
||||
/* 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
|
||||
on the length of the input string */
|
||||
/* Handles Australia Posts's 4 State Codes */
|
||||
int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
/* 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
|
||||
on the length of the input string */
|
||||
|
||||
/* The contents of data_pattern conform to the following standard:
|
||||
0 = Tracker, Ascender and Descender
|
||||
1 = Tracker and Ascender
|
||||
2 = Tracker and Descender
|
||||
3 = Tracker only */
|
||||
int error_number, zeroes;
|
||||
int writer;
|
||||
unsigned int loopey, reader, h;
|
||||
/* The contents of data_pattern conform to the following standard:
|
||||
0 = Tracker, Ascender and Descender
|
||||
1 = Tracker and Ascender
|
||||
2 = Tracker and Descender
|
||||
3 = Tracker only */
|
||||
int error_number, zeroes;
|
||||
int writer;
|
||||
unsigned int loopey, reader, h;
|
||||
|
||||
char data_pattern[200];
|
||||
char fcc[3] = {0, 0}, dpid[10];
|
||||
char localstr[30];
|
||||
char data_pattern[200];
|
||||
char fcc[3] = {0, 0}, dpid[10];
|
||||
char localstr[30];
|
||||
|
||||
error_number = 0;
|
||||
strcpy(localstr, "");
|
||||
error_number = 0;
|
||||
strcpy(localstr, "");
|
||||
|
||||
/* Do all of the length checking first to avoid stack smashing */
|
||||
if(symbol->symbology == BARCODE_AUSPOST) {
|
||||
/* Format control code (FCC) */
|
||||
switch(length)
|
||||
{
|
||||
case 8:
|
||||
strcpy(fcc, "11");
|
||||
break;
|
||||
case 13:
|
||||
strcpy(fcc, "59");
|
||||
break;
|
||||
case 16:
|
||||
strcpy(fcc, "59");
|
||||
error_number = is_sane(NEON, source, length);
|
||||
break;
|
||||
case 18:
|
||||
strcpy(fcc, "62");
|
||||
break;
|
||||
case 23:
|
||||
strcpy(fcc, "62");
|
||||
error_number = is_sane(NEON, source, length);
|
||||
break;
|
||||
default:
|
||||
strcpy(symbol->errtxt, "Auspost input is wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
} else {
|
||||
if (length > 8) {
|
||||
strcpy(symbol->errtxt, "Auspost input is too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
switch(symbol->symbology) {
|
||||
case BARCODE_AUSREPLY: strcpy(fcc, "45"); break;
|
||||
case BARCODE_AUSROUTE: strcpy(fcc, "87"); break;
|
||||
case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break;
|
||||
}
|
||||
/* Do all of the length checking first to avoid stack smashing */
|
||||
if (symbol->symbology == BARCODE_AUSPOST) {
|
||||
/* Format control code (FCC) */
|
||||
switch (length) {
|
||||
case 8:
|
||||
strcpy(fcc, "11");
|
||||
break;
|
||||
case 13:
|
||||
strcpy(fcc, "59");
|
||||
break;
|
||||
case 16:
|
||||
strcpy(fcc, "59");
|
||||
error_number = is_sane(NEON, source, length);
|
||||
break;
|
||||
case 18:
|
||||
strcpy(fcc, "62");
|
||||
break;
|
||||
case 23:
|
||||
strcpy(fcc, "62");
|
||||
error_number = is_sane(NEON, source, length);
|
||||
break;
|
||||
default:
|
||||
strcpy(symbol->errtxt, "Auspost input is wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
} else {
|
||||
if (length > 8) {
|
||||
strcpy(symbol->errtxt, "Auspost input is too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
switch (symbol->symbology) {
|
||||
case BARCODE_AUSREPLY: strcpy(fcc, "45");
|
||||
break;
|
||||
case BARCODE_AUSROUTE: strcpy(fcc, "87");
|
||||
break;
|
||||
case BARCODE_AUSREDIRECT: strcpy(fcc, "92");
|
||||
break;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 8 - length;
|
||||
memset(localstr, '0', zeroes);
|
||||
localstr[8] = '\0';
|
||||
}
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 8 - length;
|
||||
memset(localstr, '0', zeroes);
|
||||
localstr[8] = '\0';
|
||||
}
|
||||
|
||||
concat(localstr, (char*)source);
|
||||
h = strlen(localstr);
|
||||
error_number = is_sane(GDSET, (unsigned char *)localstr, h);
|
||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
concat(localstr, (char*) source);
|
||||
h = strlen(localstr);
|
||||
error_number = is_sane(GDSET, (unsigned char *) localstr, h);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Verifiy that the first 8 characters are numbers */
|
||||
memcpy(dpid, localstr, 8);
|
||||
dpid[8] = '\0';
|
||||
error_number = is_sane(NEON, (unsigned char *)dpid, strlen(dpid));
|
||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in DPID");
|
||||
return error_number;
|
||||
}
|
||||
/* Verifiy that the first 8 characters are numbers */
|
||||
memcpy(dpid, localstr, 8);
|
||||
dpid[8] = '\0';
|
||||
error_number = is_sane(NEON, (unsigned char *) dpid, strlen(dpid));
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in DPID");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
strcpy(data_pattern, "13");
|
||||
/* Start character */
|
||||
strcpy(data_pattern, "13");
|
||||
|
||||
/* Encode the FCC */
|
||||
for(reader = 0; reader < 2; reader++)
|
||||
{
|
||||
lookup(NEON, AusNTable, fcc[reader], data_pattern);
|
||||
}
|
||||
/* Encode the FCC */
|
||||
for (reader = 0; reader < 2; reader++) {
|
||||
lookup(NEON, AusNTable, fcc[reader], data_pattern);
|
||||
}
|
||||
|
||||
/* printf("AUSPOST FCC: %s ", fcc); */
|
||||
/* printf("AUSPOST FCC: %s ", fcc); */
|
||||
|
||||
/* Delivery Point Identifier (DPID) */
|
||||
for(reader = 0; reader < 8; reader++)
|
||||
{
|
||||
lookup(NEON, AusNTable, dpid[reader], data_pattern);
|
||||
}
|
||||
/* Delivery Point Identifier (DPID) */
|
||||
for (reader = 0; reader < 8; reader++) {
|
||||
lookup(NEON, AusNTable, dpid[reader], data_pattern);
|
||||
}
|
||||
|
||||
/* Customer Information */
|
||||
if(h > 8)
|
||||
{
|
||||
if((h == 13) || (h == 18)) {
|
||||
for(reader = 8; reader < h; reader++) {
|
||||
lookup(GDSET, AusCTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
else if((h == 16) || (h == 23)) {
|
||||
for(reader = 8; reader < h; reader++) {
|
||||
lookup(NEON, AusNTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Customer Information */
|
||||
if (h > 8) {
|
||||
if ((h == 13) || (h == 18)) {
|
||||
for (reader = 8; reader < h; reader++) {
|
||||
lookup(GDSET, AusCTable, localstr[reader], data_pattern);
|
||||
}
|
||||
} else if ((h == 16) || (h == 23)) {
|
||||
for (reader = 8; reader < h; reader++) {
|
||||
lookup(NEON, AusNTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Filler bar */
|
||||
h = strlen(data_pattern);
|
||||
switch (h)
|
||||
{
|
||||
case 22:
|
||||
case 37:
|
||||
case 52:
|
||||
concat(data_pattern, "3");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* Filler bar */
|
||||
h = strlen(data_pattern);
|
||||
switch (h) {
|
||||
case 22:
|
||||
case 37:
|
||||
case 52:
|
||||
concat(data_pattern, "3");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Reed Solomon error correction */
|
||||
rs_error(data_pattern);
|
||||
/* Reed Solomon error correction */
|
||||
rs_error(data_pattern);
|
||||
|
||||
/* Stop character */
|
||||
concat(data_pattern, "13");
|
||||
/* Stop character */
|
||||
concat(data_pattern, "13");
|
||||
|
||||
/* Turn the symbol into a bar pattern ready for plotting */
|
||||
writer = 0;
|
||||
h = strlen(data_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0'))
|
||||
{
|
||||
set_module(symbol, 0, writer);
|
||||
}
|
||||
set_module(symbol, 1, writer);
|
||||
if((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0'))
|
||||
{
|
||||
set_module(symbol, 2, writer);
|
||||
}
|
||||
writer += 2;
|
||||
}
|
||||
/* Turn the symbol into a bar pattern ready for plotting */
|
||||
writer = 0;
|
||||
h = strlen(data_pattern);
|
||||
for (loopey = 0; loopey < h; loopey++) {
|
||||
if ((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) {
|
||||
set_module(symbol, 0, writer);
|
||||
}
|
||||
set_module(symbol, 1, writer);
|
||||
if ((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) {
|
||||
set_module(symbol, 2, writer);
|
||||
}
|
||||
writer += 2;
|
||||
}
|
||||
|
||||
symbol->row_height[0] = 3;
|
||||
symbol->row_height[1] = 2;
|
||||
symbol->row_height[2] = 3;
|
||||
symbol->row_height[0] = 3;
|
||||
symbol->row_height[1] = 2;
|
||||
symbol->row_height[2] = 3;
|
||||
|
||||
symbol->rows = 3;
|
||||
symbol->width = writer - 1;
|
||||
symbol->rows = 3;
|
||||
symbol->width = writer - 1;
|
||||
|
||||
return error_number;
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
2690
backend/aztec.c
2690
backend/aztec.c
File diff suppressed because it is too large
Load Diff
207
backend/aztec.h
207
backend/aztec.h
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
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
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
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
|
||||
without specific prior written permission.
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
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
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define UPPER 1
|
||||
#define LOWER 2
|
||||
@ -39,112 +39,139 @@
|
||||
|
||||
static int AztecMap[22801];
|
||||
|
||||
static const int CompactAztecMap[] = { /* 27 x 27 data grid */
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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
|
||||
static const int CompactAztecMap[] = {
|
||||
/* 27 x 27 data grid */
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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 */
|
||||
32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32,
|
||||
32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8,
|
||||
8, 8, 8, 8, 4, 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, 8, 4, 8, 4, 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,
|
||||
2, 2, 2, 8, 4, 8, 4, 4
|
||||
const int AztecCodeSet[128] = {
|
||||
/* From Table 2 */
|
||||
32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32,
|
||||
32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8,
|
||||
8, 8, 8, 8, 4, 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, 8, 4, 8, 4, 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,
|
||||
2, 2, 2, 8, 4, 8, 4, 4
|
||||
};
|
||||
|
||||
const int AztecSymbolChar[128] = { /* From Table 2 */
|
||||
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19,
|
||||
20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12,
|
||||
13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22,
|
||||
23, 24, 25, 26, 20, 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, 27, 21, 28, 22, 23, 24, 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, 29, 25, 30, 26, 27
|
||||
const int AztecSymbolChar[128] = {
|
||||
/* From Table 2 */
|
||||
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19,
|
||||
20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12,
|
||||
13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22,
|
||||
23, 24, 25, 26, 20, 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, 27, 21, 28, 22, 23, 24, 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, 29, 25, 30, 26, 27
|
||||
};
|
||||
|
||||
/* Problem characters are:
|
||||
300: Carriage Return (ASCII 13)
|
||||
301: Comma (ASCII 44)
|
||||
302: Full Stop (ASCII 46)
|
||||
*/
|
||||
300: Carriage Return (ASCII 13)
|
||||
301: Comma (ASCII 44)
|
||||
302: Full Stop (ASCII 46)
|
||||
*/
|
||||
|
||||
static const char *hexbit[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
|
||||
"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 *hexbit[32] = {
|
||||
"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
|
||||
"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",
|
||||
"1010", "1011", "1100", "1101", "1110", "1111"
|
||||
static const char *pentbit[16] = {
|
||||
"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 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 char *tribit[8] = {
|
||||
"000", "001", "010", "011", "100", "101", "110", "111"
|
||||
};
|
||||
|
||||
static const int AztecCompactSizes[4] = { 17, 40, 51, 76 };
|
||||
|
||||
static const int Aztec10DataSizes[32] = { /* Data bits per symbol maximum with 10% error correction */
|
||||
96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730,
|
||||
5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076,
|
||||
15000, 15948, 16920, 17940
|
||||
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 Aztec23DataSizes[32] = { /* Data bits per symbol maximum with 23% error correction */
|
||||
84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040,
|
||||
4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036,
|
||||
12828, 13644, 14472, 15348
|
||||
static const int AztecCompactSizes[4] = {
|
||||
17, 40, 51, 76
|
||||
};
|
||||
|
||||
static const int Aztec36DataSizes[32] = { /* Data bits per symbol maximum with 36% error correction */
|
||||
66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350,
|
||||
3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656,
|
||||
11340, 12024, 12744
|
||||
static const int Aztec10DataSizes[32] = {
|
||||
/* Data bits per symbol maximum with 10% error correction */
|
||||
96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730,
|
||||
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 */
|
||||
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 Aztec23DataSizes[32] = {
|
||||
/* Data bits per symbol maximum with 23% error correction */
|
||||
84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040,
|
||||
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 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 Aztec36DataSizes[32] = {
|
||||
/* Data bits per symbol maximum with 36% error correction */
|
||||
66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350,
|
||||
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] = {
|
||||
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
|
||||
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
|
||||
};
|
||||
|
||||
static const int AztecCompactOffset[4] = { 6, 4, 2, 0 };
|
||||
static const int AztecCompactOffset[4] = {
|
||||
6, 4, 2, 0
|
||||
};
|
||||
|
831
backend/code.c
831
backend/code.c
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -28,7 +28,7 @@
|
||||
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
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* In version 0.5 this file was 1,553 lines long! */
|
||||
|
||||
@ -40,49 +40,58 @@
|
||||
#define SODIUM "0123456789-"
|
||||
#define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
|
||||
|
||||
static const char *C11Table[11] = {"111121", "211121", "121121", "221111", "112121", "212111", "122111",
|
||||
"111221", "211211", "211111", "112111"};
|
||||
|
||||
static const char *C11Table[11] = {
|
||||
"111121", "211121", "121121", "221111", "112121", "212111", "122111",
|
||||
"111221", "211211", "211111", "112111"
|
||||
};
|
||||
|
||||
/* Code 39 tables checked against ISO/IEC 16388:2007 */
|
||||
|
||||
/* Incorporates Table A1 */
|
||||
|
||||
static const char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
|
||||
"2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121",
|
||||
"1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121",
|
||||
"2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211",
|
||||
"1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211",
|
||||
"1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111",
|
||||
"1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211",
|
||||
"1211121211", "1112121211"};
|
||||
/* Code 39 character assignments (Table 1) */
|
||||
static const char *C39Table[43] = {
|
||||
/* Code 39 character assignments (Table 1) */
|
||||
"1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
|
||||
"2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121",
|
||||
"1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121",
|
||||
"2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211",
|
||||
"1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211",
|
||||
"1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111",
|
||||
"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",
|
||||
"$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z",
|
||||
"%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J",
|
||||
"/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F",
|
||||
"%G", "%H", "%I", "%J", "%V", "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", "%K", "%L", "%M", "%N", "%O",
|
||||
"%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"};
|
||||
/* Encoding the full ASCII character set in Code 39 (Table A2) */
|
||||
static const char *EC39Ctrl[128] = {
|
||||
/* Encoding the full ASCII character set in Code 39 (Table A2) */
|
||||
"%U", "$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",
|
||||
"%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J",
|
||||
"/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F",
|
||||
"%G", "%H", "%I", "%J", "%V", "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", "%K", "%L", "%M", "%N", "%O",
|
||||
"%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",
|
||||
"aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ",
|
||||
"bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ",
|
||||
"+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF",
|
||||
"bG", "bH", "bI", "bJ", "bV", "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", "bK", "bL", "bM", "bN", "bO",
|
||||
"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 *C93Ctrl[128] = {
|
||||
"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK",
|
||||
"aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ",
|
||||
"bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ",
|
||||
"+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF",
|
||||
"bG", "bH", "bI", "bJ", "bV", "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", "bK", "bL", "bM", "bN", "bO",
|
||||
"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",
|
||||
"111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111",
|
||||
"112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122",
|
||||
"131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221",
|
||||
"122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131",
|
||||
"121221", "312111", "311121", "122211"};
|
||||
static const char *C93Table[47] = {
|
||||
"131112", "111213", "111312", "111411", "121113", "121212", "121311",
|
||||
"111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111",
|
||||
"112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122",
|
||||
"131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221",
|
||||
"122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131",
|
||||
"121221", "312111", "311121", "122211"
|
||||
};
|
||||
|
||||
/* Global Variables for Channel Code */
|
||||
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);
|
||||
|
||||
/* *********************** 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)
|
||||
{ /* Code 11 */
|
||||
unsigned int i;
|
||||
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;
|
||||
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;
|
||||
|
||||
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) {
|
||||
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;
|
||||
/* start character */
|
||||
strcpy(dest, "112211");
|
||||
|
||||
/* start character */
|
||||
strcpy(dest, "112211");
|
||||
/* Draw main body of barcode */
|
||||
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 */
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(SODIUM, C11Table, source[i], dest);
|
||||
if(source[i] == '-')
|
||||
weight[i] = 10;
|
||||
else
|
||||
weight[i] = ctoi(source[i]);
|
||||
}
|
||||
/* Calculate C checksum */
|
||||
for (h = length - 1; h >= 0; h--) {
|
||||
c_count += (c_weight * weight[h]);
|
||||
c_weight++;
|
||||
|
||||
/* Calculate C checksum */
|
||||
for(h = length - 1; h >= 0; h--) {
|
||||
c_count += (c_weight * weight[h]);
|
||||
c_weight++;
|
||||
if (c_weight > 10) {
|
||||
c_weight = 1;
|
||||
}
|
||||
}
|
||||
c_digit = c_count % 11;
|
||||
|
||||
if(c_weight > 10) {
|
||||
c_weight = 1;
|
||||
}
|
||||
}
|
||||
c_digit = c_count % 11;
|
||||
weight[length] = c_digit;
|
||||
|
||||
weight[length] = c_digit;
|
||||
/* Calculate K checksum */
|
||||
for (h = length; h >= 0; h--) {
|
||||
k_count += (k_weight * weight[h]);
|
||||
k_weight++;
|
||||
|
||||
/* Calculate K checksum */
|
||||
for(h = length; h >= 0; h--) {
|
||||
k_count += (k_weight * weight[h]);
|
||||
k_weight++;
|
||||
if (k_weight > 9) {
|
||||
k_weight = 1;
|
||||
}
|
||||
}
|
||||
k_digit = k_count % 11;
|
||||
|
||||
if(k_weight > 9) {
|
||||
k_weight = 1;
|
||||
}
|
||||
}
|
||||
k_digit = k_count % 11;
|
||||
checkstr[0] = itoc(c_digit);
|
||||
checkstr[1] = itoc(k_digit);
|
||||
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);
|
||||
|
||||
checkstr[0] = itoc(c_digit);
|
||||
checkstr[1] = itoc(k_digit);
|
||||
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 */
|
||||
concat(dest, "11221");
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "11221");
|
||||
expand(symbol, dest);
|
||||
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)checkstr);
|
||||
return error_number;
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*) checkstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Code 39 */
|
||||
unsigned int i;
|
||||
unsigned int counter;
|
||||
char check_digit;
|
||||
int error_number;
|
||||
char dest[775];
|
||||
char localstr[2] = { 0 };
|
||||
/* Code 39 */
|
||||
int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
unsigned int i;
|
||||
unsigned int counter;
|
||||
char check_digit;
|
||||
int error_number;
|
||||
char dest[775];
|
||||
char localstr[2] = {0};
|
||||
|
||||
error_number = 0;
|
||||
counter = 0;
|
||||
error_number = 0;
|
||||
counter = 0;
|
||||
|
||||
if((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
|
||||
symbol->option_2 = 0;
|
||||
}
|
||||
if ((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
|
||||
symbol->option_2 = 0;
|
||||
}
|
||||
|
||||
if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
} else if(length > 74) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
to_upper(source);
|
||||
error_number = is_sane(SILVER , source, length);
|
||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
if ((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
} else if (length > 74) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
to_upper(source);
|
||||
error_number = is_sane(SILVER, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
strcpy(dest, "1211212111");
|
||||
/* Start character */
|
||||
strcpy(dest, "1211212111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(SILVER, C39Table, source[i], dest);
|
||||
counter += posn(SILVER, source[i]);
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(SILVER, C39Table, source[i], dest);
|
||||
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;
|
||||
if(counter < 10) {
|
||||
check_digit = itoc(counter);
|
||||
} else {
|
||||
if(counter < 36) {
|
||||
check_digit = (counter - 10) + 'A';
|
||||
} else {
|
||||
switch(counter) {
|
||||
case 36: check_digit = '-'; break;
|
||||
case 37: check_digit = '.'; break;
|
||||
case 38: check_digit = ' '; break;
|
||||
case 39: check_digit = '$'; break;
|
||||
case 40: check_digit = '/'; break;
|
||||
case 41: check_digit = '+'; break;
|
||||
case 42: check_digit = 37; break;
|
||||
default: check_digit = ' '; break; /* Keep compiler happy */
|
||||
}
|
||||
}
|
||||
}
|
||||
lookup(SILVER, C39Table, check_digit, dest);
|
||||
counter = counter % 43;
|
||||
if (counter < 10) {
|
||||
check_digit = itoc(counter);
|
||||
} else {
|
||||
if (counter < 36) {
|
||||
check_digit = (counter - 10) + 'A';
|
||||
} else {
|
||||
switch (counter) {
|
||||
case 36: check_digit = '-';
|
||||
break;
|
||||
case 37: check_digit = '.';
|
||||
break;
|
||||
case 38: check_digit = ' ';
|
||||
break;
|
||||
case 39: check_digit = '$';
|
||||
break;
|
||||
case 40: check_digit = '/';
|
||||
break;
|
||||
case 41: check_digit = '+';
|
||||
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 */
|
||||
if(check_digit == ' ') {
|
||||
check_digit = '_';
|
||||
}
|
||||
/* Display a space check digit as _, otherwise it looks like an error */
|
||||
if (check_digit == ' ') {
|
||||
check_digit = '_';
|
||||
}
|
||||
|
||||
localstr[0] = check_digit;
|
||||
localstr[1] = '\0';
|
||||
}
|
||||
localstr[0] = check_digit;
|
||||
localstr[1] = '\0';
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "121121211");
|
||||
/* Stop character */
|
||||
concat(dest, "121121211");
|
||||
|
||||
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
|
||||
/* LOGMARS uses wider 'wide' bars than normal Code 39 */
|
||||
counter = strlen(dest);
|
||||
for(i = 0; i < counter; i++) {
|
||||
if(dest[i] == '2') {
|
||||
dest[i] = '3';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
|
||||
/* LOGMARS uses wider 'wide' bars than normal Code 39 */
|
||||
counter = strlen(dest);
|
||||
for (i = 0; i < counter; i++) {
|
||||
if (dest[i] == '2') {
|
||||
dest[i] = '3';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expand(symbol, dest);
|
||||
expand(symbol, dest);
|
||||
|
||||
if(symbol->symbology == BARCODE_CODE39) {
|
||||
ustrcpy(symbol->text, (unsigned char*)"*");
|
||||
uconcat(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)localstr);
|
||||
uconcat(symbol->text, (unsigned char*)"*");
|
||||
} else {
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)localstr);
|
||||
}
|
||||
return error_number;
|
||||
if (symbol->symbology == BARCODE_CODE39) {
|
||||
ustrcpy(symbol->text, (unsigned char*) "*");
|
||||
uconcat(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*) localstr);
|
||||
uconcat(symbol->text, (unsigned char*) "*");
|
||||
} else {
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*) localstr);
|
||||
}
|
||||
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;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[10];
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[10];
|
||||
|
||||
error_number = 0;
|
||||
error_number = 0;
|
||||
|
||||
count = 0;
|
||||
if(length > 6) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
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;
|
||||
}
|
||||
count = 0;
|
||||
if (length > 6) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
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;
|
||||
}
|
||||
|
||||
localstr[0] = '-';
|
||||
zeroes = 6 - length + 1;
|
||||
for(i = 1; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
localstr[0] = '-';
|
||||
zeroes = 6 - length + 1;
|
||||
for (i = 1; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
for (i = 1; i < 7; i++) {
|
||||
count += (i + 1) * ctoi(localstr[i]);
|
||||
}
|
||||
for (i = 1; i < 7; i++) {
|
||||
count += (i + 1) * ctoi(localstr[i]);
|
||||
}
|
||||
|
||||
check_digit = count%11;
|
||||
if (check_digit == 11) { check_digit = 0; }
|
||||
localstr[7] = itoc(check_digit);
|
||||
localstr[8] = '\0';
|
||||
if(localstr[7] == 'A') {
|
||||
strcpy(symbol->errtxt, "Invalid PZN Data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
error_number = c39(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char *)"PZN");
|
||||
uconcat(symbol->text, (unsigned char *)localstr);
|
||||
return error_number;
|
||||
check_digit = count % 11;
|
||||
if (check_digit == 11) {
|
||||
check_digit = 0;
|
||||
}
|
||||
localstr[7] = itoc(check_digit);
|
||||
localstr[8] = '\0';
|
||||
if (localstr[7] == 'A') {
|
||||
strcpy(symbol->errtxt, "Invalid PZN Data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
error_number = c39(symbol, (unsigned char *) localstr, strlen(localstr));
|
||||
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)
|
||||
{ /* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
|
||||
error_number = 0;
|
||||
|
||||
unsigned char buffer[150] = { 0 };
|
||||
unsigned int i;
|
||||
int error_number;
|
||||
if (length > 74) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
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) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
/* Then sends the buffer to the C39 function */
|
||||
error_number = c39(symbol, buffer, ustrlen(buffer));
|
||||
|
||||
/* 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]]);
|
||||
}
|
||||
for (i = 0; i < length; i++)
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
symbol->text[length] = '\0';
|
||||
|
||||
/* Then sends the buffer to the C39 function */
|
||||
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;
|
||||
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)
|
||||
{ /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
|
||||
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
|
||||
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
|
||||
shift characters 1, 2, 3 and 4 respectively. These characters are never used by
|
||||
c39() and ec39() */
|
||||
int i;
|
||||
int h, weight, c, k, values[128], error_number;
|
||||
char buffer[220];
|
||||
char dest[670];
|
||||
char set_copy[] = SILVER;
|
||||
|
||||
int i;
|
||||
int h, weight, c, k, values[128], error_number;
|
||||
char buffer[220];
|
||||
char dest[670];
|
||||
char set_copy[] = SILVER;
|
||||
|
||||
error_number = 0;
|
||||
error_number = 0;
|
||||
strcpy(buffer, "");
|
||||
|
||||
if(length > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if (length > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* Message Content */
|
||||
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(buffer, C93Ctrl[source[i]]);
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
}
|
||||
/* Message Content */
|
||||
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(buffer, C93Ctrl[source[i]]);
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
}
|
||||
|
||||
/* Now we can check the true length of the barcode */
|
||||
h = strlen(buffer);
|
||||
if (h > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
/* Now we can check the true length of the barcode */
|
||||
h = strlen(buffer);
|
||||
if (h > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
for (i = 0; i < h; i++) {
|
||||
values[i] = posn(SILVER, buffer[i]);
|
||||
}
|
||||
for (i = 0; i < h; 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 */
|
||||
c = 0;
|
||||
weight = 1;
|
||||
for (i = h - 1; i >= 0; i--) {
|
||||
c += values[i] * weight;
|
||||
weight++;
|
||||
if (weight == 21)
|
||||
weight = 1;
|
||||
}
|
||||
c = c % 47;
|
||||
values[h] = c;
|
||||
buffer[h] = set_copy[c];
|
||||
/* Check digit C */
|
||||
c = 0;
|
||||
weight = 1;
|
||||
for (i = h - 1; i >= 0; i--) {
|
||||
c += values[i] * weight;
|
||||
weight++;
|
||||
if (weight == 21)
|
||||
weight = 1;
|
||||
}
|
||||
c = c % 47;
|
||||
values[h] = c;
|
||||
buffer[h] = set_copy[c];
|
||||
|
||||
/* Check digit K */
|
||||
k = 0;
|
||||
weight = 1;
|
||||
for (i = h; i >= 0; i--) {
|
||||
k += values[i] * weight;
|
||||
weight++;
|
||||
if(weight == 16)
|
||||
weight = 1;
|
||||
}
|
||||
k = k % 47;
|
||||
buffer[++h] = set_copy[k];
|
||||
buffer[++h] = '\0';
|
||||
/* Check digit K */
|
||||
k = 0;
|
||||
weight = 1;
|
||||
for (i = h; i >= 0; i--) {
|
||||
k += values[i] * weight;
|
||||
weight++;
|
||||
if (weight == 16)
|
||||
weight = 1;
|
||||
}
|
||||
k = k % 47;
|
||||
buffer[++h] = set_copy[k];
|
||||
buffer[++h] = '\0';
|
||||
|
||||
/* Start character */
|
||||
strcpy(dest, "111141");
|
||||
/* Start character */
|
||||
strcpy(dest, "111141");
|
||||
|
||||
for(i = 0; i < h; i++) {
|
||||
lookup(SILVER, C93Table, buffer[i], dest);
|
||||
}
|
||||
for (i = 0; i < h; i++) {
|
||||
lookup(SILVER, C93Table, buffer[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat(dest, "1111411");
|
||||
expand(symbol, dest);
|
||||
/* Stop character */
|
||||
concat(dest, "1111411");
|
||||
expand(symbol, dest);
|
||||
|
||||
symbol->text[length] = set_copy[c];
|
||||
symbol->text[length + 1] = set_copy[k];
|
||||
symbol->text[length + 2] = '\0';
|
||||
symbol->text[length] = set_copy[c];
|
||||
symbol->text[length + 1] = set_copy[k];
|
||||
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 */
|
||||
|
||||
/* 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
|
||||
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." */
|
||||
|
||||
void CheckCharacter() {
|
||||
int i;
|
||||
char part[3];
|
||||
int i;
|
||||
char part[3];
|
||||
|
||||
if(value == target_value) {
|
||||
/* Target reached - save the generated pattern */
|
||||
strcpy(pattern, "11110");
|
||||
for(i = 0; i < 11; i++) {
|
||||
part[0] = itoc(S[i]);
|
||||
part[1] = itoc(B[i]);
|
||||
part[2] = '\0';
|
||||
concat(pattern, part);
|
||||
}
|
||||
}
|
||||
if (value == target_value) {
|
||||
/* Target reached - save the generated pattern */
|
||||
strcpy(pattern, "11110");
|
||||
for (i = 0; i < 11; i++) {
|
||||
part[0] = itoc(S[i]);
|
||||
part[1] = itoc(B[i]);
|
||||
part[2] = '\0';
|
||||
concat(pattern, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
if (i < Chan+2) {
|
||||
for (; b <= MaxB; b++) {
|
||||
B[i] = b;
|
||||
NextS(Chan,i+1,MaxS,MaxB+1-b);
|
||||
}
|
||||
} else if (b <= MaxB) {
|
||||
B[i] = MaxB;
|
||||
CheckCharacter();
|
||||
value++;
|
||||
}
|
||||
b = (S[i] + B[i - 1] + S[i - 1] + B[i - 2] > 4) ? 1 : 2;
|
||||
if (i < Chan + 2) {
|
||||
for (; b <= MaxB; b++) {
|
||||
B[i] = b;
|
||||
NextS(Chan, i + 1, MaxS, MaxB + 1 - b);
|
||||
}
|
||||
} else if (b <= MaxB) {
|
||||
B[i] = MaxB;
|
||||
CheckCharacter();
|
||||
value++;
|
||||
}
|
||||
}
|
||||
|
||||
void NextS(int Chan, int i, int MaxS, int MaxB) {
|
||||
int s;
|
||||
int s;
|
||||
|
||||
for (s = (i<Chan+2)? 1: MaxS; s <= MaxS; s++) {
|
||||
S[i] = s;
|
||||
NextB(Chan,i,MaxB,MaxS+1-s);
|
||||
}
|
||||
for (s = (i < Chan + 2) ? 1 : MaxS; s <= MaxS; s++) {
|
||||
S[i] = 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) {
|
||||
/* Channel Code - According to ANSI/AIM BC12-1998 */
|
||||
int channels, i;
|
||||
int error_number = 0, range = 0, zeroes;
|
||||
char hrt[9];
|
||||
|
||||
int channels, i;
|
||||
int error_number = 0, range = 0, zeroes;
|
||||
char hrt[9];
|
||||
target_value = 0;
|
||||
|
||||
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) {
|
||||
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 ((symbol->option_2 < 3) || (symbol->option_2 > 8)) {
|
||||
channels = 0;
|
||||
} else {
|
||||
channels = symbol->option_2;
|
||||
}
|
||||
if (channels == 0) {
|
||||
channels = length + 1;
|
||||
}
|
||||
if (channels == 2) {
|
||||
channels = 3;
|
||||
}
|
||||
|
||||
if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; }
|
||||
if(channels == 0) { channels = length + 1; }
|
||||
if(channels == 2) { channels = 3; }
|
||||
for (i = 0; i < length; i++) {
|
||||
target_value *= 10;
|
||||
target_value += ctoi((char) source[i]);
|
||||
}
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
target_value *= 10;
|
||||
target_value += ctoi((char) source[i]);
|
||||
}
|
||||
switch (channels) {
|
||||
case 3: if (target_value > 26) {
|
||||
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) {
|
||||
case 3: if(target_value > 26) { 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;
|
||||
}
|
||||
for (i = 0; i < 11; i++) {
|
||||
B[i] = 0;
|
||||
S[i] = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
value = 0;
|
||||
NextS(channels,3,channels,channels);
|
||||
zeroes = channels - 1 - length;
|
||||
memset(hrt, '0', zeroes);
|
||||
strcpy(hrt + zeroes, (char *) source);
|
||||
ustrcpy(symbol->text, (unsigned char *) hrt);
|
||||
|
||||
zeroes = channels - 1 - length;
|
||||
memset(hrt, '0', zeroes);
|
||||
strcpy(hrt + zeroes, (char *)source);
|
||||
ustrcpy(symbol->text, (unsigned char *)hrt);
|
||||
expand(symbol, pattern);
|
||||
|
||||
expand(symbol, pattern);
|
||||
|
||||
return error_number;
|
||||
return error_number;
|
||||
}
|
||||
|
3084
backend/code1.c
3084
backend/code1.c
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -28,41 +28,71 @@
|
||||
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
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
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,
|
||||
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, 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 };
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
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,
|
||||
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,
|
||||
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 };
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
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,
|
||||
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, 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 };
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
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,
|
||||
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,
|
||||
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 };
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
static const int c1_height[] = { 16, 22, 28, 40, 52, 70, 104, 148 };
|
||||
static const int c1_width[] = { 18, 22, 32, 42, 54, 76, 98, 134 };
|
||||
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 };
|
||||
static const int c1_height[] = {
|
||||
16, 22, 28, 40, 52, 70, 104, 148
|
||||
};
|
||||
|
||||
static const int c1_width[] = {
|
||||
18, 22, 32, 42, 54, 76, 98, 134
|
||||
};
|
||||
|
||||
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_C40 2
|
||||
|
1778
backend/code128.c
1778
backend/code128.c
File diff suppressed because it is too large
Load Diff
1149
backend/code16k.c
1149
backend/code16k.c
File diff suppressed because it is too large
Load Diff
527
backend/code49.c
527
backend/code49.c
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
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
|
||||
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
|
||||
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)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -37,290 +37,299 @@
|
||||
#include "code49.h"
|
||||
|
||||
#define INSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*"
|
||||
|
||||
/* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */
|
||||
|
||||
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;
|
||||
char intermediate[170];
|
||||
int codewords[170], codeword_count;
|
||||
int c_grid[8][8]; /* Refers to table 3 */
|
||||
int w_grid[8][4]; /* Refets to table 2 */
|
||||
int pad_count = 0;
|
||||
char pattern[40];
|
||||
int gs1;
|
||||
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;
|
||||
char intermediate[170];
|
||||
int codewords[170], codeword_count;
|
||||
int c_grid[8][8]; /* Refers to table 3 */
|
||||
int w_grid[8][4]; /* Refets to table 2 */
|
||||
int pad_count = 0;
|
||||
char pattern[40];
|
||||
int gs1;
|
||||
|
||||
if(length > 81) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }
|
||||
if (length > 81) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if (symbol->input_mode == GS1_MODE) {
|
||||
gs1 = 1;
|
||||
strcpy(intermediate, "*"); /* FNC1 */
|
||||
} else {
|
||||
gs1 = 0;
|
||||
}
|
||||
|
||||
strcpy(intermediate, gs1 ? "*" : ""); /* FNC1 */
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] > 127) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if(gs1 && (source[i] == '['))
|
||||
concat(intermediate, "*"); /* FNC1 */
|
||||
else
|
||||
concat(intermediate, c49_table7[source[i]]);
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
if (source[i] > 127) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (gs1 && (source[i] == '['))
|
||||
concat(intermediate, "*"); /* FNC1 */
|
||||
else
|
||||
concat(intermediate, c49_table7[source[i]]);
|
||||
}
|
||||
|
||||
codeword_count = 0;
|
||||
i = 0;
|
||||
h = strlen(intermediate);
|
||||
do {
|
||||
if((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
|
||||
/* Numeric data */
|
||||
for(j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++);
|
||||
if(j >= 5) {
|
||||
/* Use Numeric Encodation Method */
|
||||
int block_count, c;
|
||||
int block_remain;
|
||||
int block_value;
|
||||
codeword_count = 0;
|
||||
i = 0;
|
||||
h = strlen(intermediate);
|
||||
do {
|
||||
if ((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
|
||||
/* Numeric data */
|
||||
for (j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++);
|
||||
if (j >= 5) {
|
||||
/* Use Numeric Encodation Method */
|
||||
int block_count, c;
|
||||
int block_remain;
|
||||
int block_value;
|
||||
|
||||
codewords[codeword_count] = 48; /* Numeric Shift */
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = 48; /* Numeric Shift */
|
||||
codeword_count++;
|
||||
|
||||
block_count = j / 5;
|
||||
block_remain = j % 5;
|
||||
block_count = j / 5;
|
||||
block_remain = j % 5;
|
||||
|
||||
for(c = 0; c < block_count; c++) {
|
||||
if((c == block_count - 1) && (block_remain == 2)) {
|
||||
/* Rule (d) */
|
||||
block_value = 100000;
|
||||
block_value += ctoi(intermediate[i]) * 1000;
|
||||
block_value += ctoi(intermediate[i + 1]) * 100;
|
||||
block_value += ctoi(intermediate[i + 2]) * 10;
|
||||
block_value += ctoi(intermediate[i + 3]);
|
||||
for (c = 0; c < block_count; c++) {
|
||||
if ((c == block_count - 1) && (block_remain == 2)) {
|
||||
/* Rule (d) */
|
||||
block_value = 100000;
|
||||
block_value += ctoi(intermediate[i]) * 1000;
|
||||
block_value += ctoi(intermediate[i + 1]) * 100;
|
||||
block_value += ctoi(intermediate[i + 2]) * 10;
|
||||
block_value += ctoi(intermediate[i + 3]);
|
||||
|
||||
codewords[codeword_count] = block_value / (48 * 48);
|
||||
block_value = block_value - (48 * 48) * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 4;
|
||||
block_value = ctoi(intermediate[i]) * 100;
|
||||
block_value += ctoi(intermediate[i + 1]) * 10;
|
||||
block_value += ctoi(intermediate[i + 2]);
|
||||
codewords[codeword_count] = block_value / (48 * 48);
|
||||
block_value = block_value - (48 * 48) * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 4;
|
||||
block_value = ctoi(intermediate[i]) * 100;
|
||||
block_value += ctoi(intermediate[i + 1]) * 10;
|
||||
block_value += ctoi(intermediate[i + 2]);
|
||||
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 3;
|
||||
} else {
|
||||
block_value = ctoi(intermediate[i]) * 10000;
|
||||
block_value += ctoi(intermediate[i + 1]) * 1000;
|
||||
block_value += ctoi(intermediate[i + 2]) * 100;
|
||||
block_value += ctoi(intermediate[i + 3]) * 10;
|
||||
block_value += ctoi(intermediate[i + 4]);
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 3;
|
||||
} else {
|
||||
block_value = ctoi(intermediate[i]) * 10000;
|
||||
block_value += ctoi(intermediate[i + 1]) * 1000;
|
||||
block_value += ctoi(intermediate[i + 2]) * 100;
|
||||
block_value += ctoi(intermediate[i + 3]) * 10;
|
||||
block_value += ctoi(intermediate[i + 4]);
|
||||
|
||||
codewords[codeword_count] = block_value / (48 * 48);
|
||||
block_value = block_value - (48 * 48) * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 5;
|
||||
}
|
||||
}
|
||||
codewords[codeword_count] = block_value / (48 * 48);
|
||||
block_value = block_value - (48 * 48) * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 5;
|
||||
}
|
||||
}
|
||||
|
||||
switch(block_remain) {
|
||||
case 1:
|
||||
/* Rule (a) */
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
codeword_count++;
|
||||
i++;
|
||||
break;
|
||||
case 3:
|
||||
/* Rule (b) */
|
||||
block_value = ctoi(intermediate[i]) * 100;
|
||||
block_value += ctoi(intermediate[i + 1]) * 10;
|
||||
block_value += ctoi(intermediate[i + 2]);
|
||||
switch (block_remain) {
|
||||
case 1:
|
||||
/* Rule (a) */
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
codeword_count++;
|
||||
i++;
|
||||
break;
|
||||
case 3:
|
||||
/* Rule (b) */
|
||||
block_value = ctoi(intermediate[i]) * 100;
|
||||
block_value += ctoi(intermediate[i + 1]) * 10;
|
||||
block_value += ctoi(intermediate[i + 2]);
|
||||
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 3;
|
||||
break;
|
||||
case 4:
|
||||
/* Rule (c) */
|
||||
block_value = 100000;
|
||||
block_value += ctoi(intermediate[i]) * 1000;
|
||||
block_value += ctoi(intermediate[i + 1]) * 100;
|
||||
block_value += ctoi(intermediate[i + 2]) * 10;
|
||||
block_value += ctoi(intermediate[i + 3]);
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 3;
|
||||
break;
|
||||
case 4:
|
||||
/* Rule (c) */
|
||||
block_value = 100000;
|
||||
block_value += ctoi(intermediate[i]) * 1000;
|
||||
block_value += ctoi(intermediate[i + 1]) * 100;
|
||||
block_value += ctoi(intermediate[i + 2]) * 10;
|
||||
block_value += ctoi(intermediate[i + 3]);
|
||||
|
||||
codewords[codeword_count] = block_value / (48 * 48);
|
||||
block_value = block_value - (48 * 48) * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 4;
|
||||
break;
|
||||
}
|
||||
if(i < h) {
|
||||
/* There is more to add */
|
||||
codewords[codeword_count] = 48; /* Numeric Shift */
|
||||
codeword_count++;
|
||||
}
|
||||
} else {
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
codeword_count++;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
codeword_count++;
|
||||
i++;
|
||||
}
|
||||
} while(i < h);
|
||||
codewords[codeword_count] = block_value / (48 * 48);
|
||||
block_value = block_value - (48 * 48) * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value / 48;
|
||||
block_value = block_value - 48 * codewords[codeword_count];
|
||||
codeword_count++;
|
||||
codewords[codeword_count] = block_value;
|
||||
codeword_count++;
|
||||
i += 4;
|
||||
break;
|
||||
}
|
||||
if (i < h) {
|
||||
/* There is more to add */
|
||||
codewords[codeword_count] = 48; /* Numeric Shift */
|
||||
codeword_count++;
|
||||
}
|
||||
} else {
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
codeword_count++;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
codeword_count++;
|
||||
i++;
|
||||
}
|
||||
} while (i < h);
|
||||
|
||||
switch(codewords[0]) { /* Set starting mode value */
|
||||
case 48: M = 2; break;
|
||||
case 43: M = 4; break;
|
||||
case 44: M = 5; break;
|
||||
default: M = 0; break;
|
||||
}
|
||||
switch (codewords[0]) {
|
||||
/* Set starting mode value */
|
||||
case 48: M = 2;
|
||||
break;
|
||||
case 43: M = 4;
|
||||
break;
|
||||
case 44: M = 5;
|
||||
break;
|
||||
default: M = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if(M != 0) {
|
||||
for(i = 0; i < codeword_count; i++) {
|
||||
codewords[i] = codewords[i + 1];
|
||||
}
|
||||
codeword_count--;
|
||||
}
|
||||
if (M != 0) {
|
||||
for (i = 0; i < codeword_count; i++) {
|
||||
codewords[i] = codewords[i + 1];
|
||||
}
|
||||
codeword_count--;
|
||||
}
|
||||
|
||||
if(codeword_count > 49) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if (codeword_count > 49) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* Place codewords in code character array (c grid) */
|
||||
rows = 0;
|
||||
do{
|
||||
for(i = 0; i < 7; i++) {
|
||||
if(((rows * 7) + i) < codeword_count) {
|
||||
c_grid[rows][i] = codewords[(rows * 7) + i];
|
||||
} else {
|
||||
c_grid[rows][i] = 48; /* Pad */
|
||||
pad_count++;
|
||||
}
|
||||
}
|
||||
rows++;
|
||||
} while ((rows * 7) < codeword_count);
|
||||
/* Place codewords in code character array (c grid) */
|
||||
rows = 0;
|
||||
do {
|
||||
for (i = 0; i < 7; i++) {
|
||||
if (((rows * 7) + i) < codeword_count) {
|
||||
c_grid[rows][i] = codewords[(rows * 7) + i];
|
||||
} else {
|
||||
c_grid[rows][i] = 48; /* Pad */
|
||||
pad_count++;
|
||||
}
|
||||
}
|
||||
rows++;
|
||||
} while ((rows * 7) < codeword_count);
|
||||
|
||||
if((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
|
||||
/* Add a row */
|
||||
for(i = 0; i < 7; i++) {
|
||||
c_grid[rows][i] = 48; /* Pad */
|
||||
}
|
||||
rows++;
|
||||
}
|
||||
if ((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
|
||||
/* Add a row */
|
||||
for (i = 0; i < 7; i++) {
|
||||
c_grid[rows][i] = 48; /* Pad */
|
||||
}
|
||||
rows++;
|
||||
}
|
||||
|
||||
/* Add row count and mode character */
|
||||
c_grid[rows - 1][6] = (7 * (rows - 2)) + M;
|
||||
/* Add row count and mode character */
|
||||
c_grid[rows - 1][6] = (7 * (rows - 2)) + M;
|
||||
|
||||
/* Add row check character */
|
||||
for(i = 0; i < rows - 1; i++) {
|
||||
int row_sum = 0;
|
||||
/* Add row check character */
|
||||
for (i = 0; i < rows - 1; i++) {
|
||||
int row_sum = 0;
|
||||
|
||||
for(j = 0; j < 7; j++) {
|
||||
row_sum += c_grid[i][j];
|
||||
}
|
||||
c_grid[i][7] = row_sum % 49;
|
||||
}
|
||||
for (j = 0; j < 7; j++) {
|
||||
row_sum += c_grid[i][j];
|
||||
}
|
||||
c_grid[i][7] = row_sum % 49;
|
||||
}
|
||||
|
||||
/* Calculate Symbol Check Characters */
|
||||
posn_val = 0;
|
||||
x_count = c_grid[rows - 1][6] * 20;
|
||||
y_count = c_grid[rows - 1][6] * 16;
|
||||
z_count = c_grid[rows - 1][6] * 38;
|
||||
for(i = 0; i < rows - 1; i++) {
|
||||
for(j = 0; j < 4; j++) {
|
||||
local_value = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
|
||||
x_count += c49_x_weight[posn_val] * local_value;
|
||||
y_count += c49_y_weight[posn_val] * local_value;
|
||||
z_count += c49_z_weight[posn_val] * local_value;
|
||||
posn_val++;
|
||||
}
|
||||
}
|
||||
/* Calculate Symbol Check Characters */
|
||||
posn_val = 0;
|
||||
x_count = c_grid[rows - 1][6] * 20;
|
||||
y_count = c_grid[rows - 1][6] * 16;
|
||||
z_count = c_grid[rows - 1][6] * 38;
|
||||
for (i = 0; i < rows - 1; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
local_value = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
|
||||
x_count += c49_x_weight[posn_val] * local_value;
|
||||
y_count += c49_y_weight[posn_val] * local_value;
|
||||
z_count += c49_z_weight[posn_val] * local_value;
|
||||
posn_val++;
|
||||
}
|
||||
}
|
||||
|
||||
if(rows > 6) {
|
||||
/* Add Z Symbol Check */
|
||||
c_grid[rows - 1][0] = (z_count % 2401) / 49;
|
||||
c_grid[rows - 1][1] = (z_count % 2401) % 49;
|
||||
}
|
||||
if (rows > 6) {
|
||||
/* Add Z Symbol Check */
|
||||
c_grid[rows - 1][0] = (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];
|
||||
x_count += c49_x_weight[posn_val] * local_value;
|
||||
y_count += c49_y_weight[posn_val] * local_value;
|
||||
posn_val++;
|
||||
local_value = (c_grid[rows - 1][0] * 49) + c_grid[rows - 1][1];
|
||||
x_count += c49_x_weight[posn_val] * local_value;
|
||||
y_count += c49_y_weight[posn_val] * local_value;
|
||||
posn_val++;
|
||||
|
||||
/* Add Y Symbol Check */
|
||||
c_grid[rows - 1][2] = (y_count % 2401) / 49;
|
||||
c_grid[rows - 1][3] = (y_count % 2401) % 49;
|
||||
/* Add Y Symbol Check */
|
||||
c_grid[rows - 1][2] = (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];
|
||||
x_count += c49_x_weight[posn_val] * local_value;
|
||||
local_value = (c_grid[rows - 1][2] * 49) + c_grid[rows - 1][3];
|
||||
x_count += c49_x_weight[posn_val] * local_value;
|
||||
|
||||
/* Add X Symbol Check */
|
||||
c_grid[rows - 1][4] = (x_count % 2401) / 49;
|
||||
c_grid[rows - 1][5] = (x_count % 2401) % 49;
|
||||
/* Add X Symbol Check */
|
||||
c_grid[rows - 1][4] = (x_count % 2401) / 49;
|
||||
c_grid[rows - 1][5] = (x_count % 2401) % 49;
|
||||
|
||||
/* Add last row check character */
|
||||
j = 0;
|
||||
for(i = 0; i < 7; i++) {
|
||||
j += c_grid[rows - 1][i];
|
||||
}
|
||||
c_grid[rows - 1][7] = j % 49;
|
||||
/* Add last row check character */
|
||||
j = 0;
|
||||
for (i = 0; i < 7; i++) {
|
||||
j += c_grid[rows - 1][i];
|
||||
}
|
||||
c_grid[rows - 1][7] = j % 49;
|
||||
|
||||
/* Transfer data to symbol character array (w grid) */
|
||||
for(i = 0; i < rows; i++) {
|
||||
for(j = 0; j < 4; j ++) {
|
||||
w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
|
||||
}
|
||||
}
|
||||
/* Transfer data to symbol character array (w grid) */
|
||||
for (i = 0; i < rows; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < rows; i++) {
|
||||
strcpy(pattern, "11"); /* Start character */
|
||||
for(j = 0; j < 4; j++) {
|
||||
if(i != (rows - 1)) {
|
||||
if(c49_table4[i][j] == 'E') {
|
||||
/* Even Parity */
|
||||
concat(pattern, c49_appxe_even[w_grid[i][j]]);
|
||||
} else {
|
||||
/* Odd Parity */
|
||||
concat(pattern, c49_appxe_odd[w_grid[i][j]]);
|
||||
}
|
||||
} else {
|
||||
/* Last row uses all even parity */
|
||||
concat(pattern, c49_appxe_even[w_grid[i][j]]);
|
||||
}
|
||||
}
|
||||
concat(pattern, "4"); /* Stop character */
|
||||
for (i = 0; i < rows; i++) {
|
||||
strcpy(pattern, "11"); /* Start character */
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (i != (rows - 1)) {
|
||||
if (c49_table4[i][j] == 'E') {
|
||||
/* Even Parity */
|
||||
concat(pattern, c49_appxe_even[w_grid[i][j]]);
|
||||
} else {
|
||||
/* Odd Parity */
|
||||
concat(pattern, c49_appxe_odd[w_grid[i][j]]);
|
||||
}
|
||||
} else {
|
||||
/* Last row uses all even parity */
|
||||
concat(pattern, c49_appxe_even[w_grid[i][j]]);
|
||||
}
|
||||
}
|
||||
concat(pattern, "4"); /* Stop character */
|
||||
|
||||
/* Expand into symbol */
|
||||
symbol->row_height[i] = 10;
|
||||
expand(symbol, pattern);
|
||||
}
|
||||
/* Expand into symbol */
|
||||
symbol->row_height[i] = 10;
|
||||
expand(symbol, pattern);
|
||||
}
|
||||
|
||||
symbol->whitespace_width = 10;
|
||||
symbol->output_options = BARCODE_BIND;
|
||||
symbol->border_width = 2;
|
||||
symbol->whitespace_width = 10;
|
||||
symbol->output_options = BARCODE_BIND;
|
||||
symbol->border_width = 2;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
2276
backend/code49.h
2276
backend/code49.h
File diff suppressed because it is too large
Load Diff
562
backend/common.c
562
backend/common.c
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
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
|
||||
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
|
||||
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)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
/* Local replacement for strlen() with unsigned char strings */
|
||||
int ustrlen(const unsigned char data[]) {
|
||||
/* Local replacement for strlen() with unsigned char strings */
|
||||
int i;
|
||||
for (i=0;data[i];i++);
|
||||
int 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 */
|
||||
int i, len;
|
||||
/* Local replacement for strcpy() with unsigned char strings */
|
||||
void ustrcpy(unsigned char target[], const unsigned char source[]) {
|
||||
int i, len;
|
||||
|
||||
len = ustrlen(source);
|
||||
for(i = 0; i < len; i++) {
|
||||
target[i] = source[i];
|
||||
}
|
||||
target[i] = '\0';
|
||||
len = ustrlen(source);
|
||||
for (i = 0; i < len; i++) {
|
||||
target[i] = source[i];
|
||||
}
|
||||
target[i] = '\0';
|
||||
}
|
||||
|
||||
void concat(char dest[],const char source[])
|
||||
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */
|
||||
unsigned int i, j, n;
|
||||
/* Concatinates dest[] with the contents of source[], copying /0 as well */
|
||||
void concat(char dest[], const char source[]) {
|
||||
unsigned int i, j, n;
|
||||
|
||||
j = strlen(dest);
|
||||
n = strlen(source);
|
||||
for(i = 0; i <= n; i++) {
|
||||
dest[i + j] = source[i]; }
|
||||
j = strlen(dest);
|
||||
n = strlen(source);
|
||||
for (i = 0; i <= n; 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 */
|
||||
unsigned int i, j;
|
||||
/* Concatinates dest[] with the contents of source[], copying /0 as well */
|
||||
void uconcat(unsigned char dest[], const unsigned char source[]) {
|
||||
unsigned int i, j;
|
||||
|
||||
j = ustrlen(dest);
|
||||
for(i = 0; i <= ustrlen(source); i++) {
|
||||
dest[i + j] = source[i]; }
|
||||
j = ustrlen(dest);
|
||||
for (i = 0; i <= ustrlen(source); i++) {
|
||||
dest[i + j] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ctoi(char source)
|
||||
{ /* Converts a character 0-9 to its equivalent integer value */
|
||||
if((source >= '0') && (source <= '9'))
|
||||
return (source - '0');
|
||||
return(source - 'A' + 10);
|
||||
/* Converts a character 0-9 to its equivalent integer value */
|
||||
int ctoi(char source) {
|
||||
if ((source >= '0') && (source <= '9'))
|
||||
return (source - '0');
|
||||
return (source - 'A' + 10);
|
||||
}
|
||||
|
||||
char itoc(int source)
|
||||
{ /* Converts an integer value to its hexadecimal character */
|
||||
if ((source >= 0) && (source <= 9)) {
|
||||
return ('0' + source); }
|
||||
else {
|
||||
return ('A' + (source - 10)); }
|
||||
/* Converts an integer value to its hexadecimal character */
|
||||
char itoc(int source) {
|
||||
if ((source >= 0) && (source <= 9)) {
|
||||
return ('0' + source);
|
||||
} else {
|
||||
return ('A' + (source - 10));
|
||||
}
|
||||
}
|
||||
|
||||
void to_upper(unsigned char source[])
|
||||
{ /* Converts lower case characters to upper case in a string source[] */
|
||||
unsigned int i, src_len = ustrlen(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);
|
||||
|
||||
for (i = 0; i < src_len; i++) {
|
||||
if ((source[i] >= 'a') && (source[i] <= 'z')) {
|
||||
source [i] = (source[i] - 'a') + 'A'; }
|
||||
}
|
||||
for (i = 0; i < src_len; i++) {
|
||||
if ((source[i] >= 'a') && (source[i] <= 'z')) {
|
||||
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 */
|
||||
unsigned int i, j, latch;
|
||||
unsigned int lt = strlen(test_string);
|
||||
/* 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 lt = strlen(test_string);
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
latch = FALSE;
|
||||
for(j = 0; j < lt; j++) {
|
||||
if (source[i] == test_string[j]) {
|
||||
latch = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!(latch)) {
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
latch = FALSE;
|
||||
for (j = 0; j < lt; j++) {
|
||||
if (source[i] == test_string[j]) {
|
||||
latch = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!(latch)) {
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int posn(char set_string[], char data)
|
||||
{ /* Returns the position of data in set_string */
|
||||
unsigned int i, n = strlen(set_string);
|
||||
/* Returns the position of data in set_string */
|
||||
int posn(char set_string[], char data) {
|
||||
unsigned int i, n = strlen(set_string);
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) { return i; } }
|
||||
return 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) {
|
||||
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 */
|
||||
unsigned int i, n = strlen(set_string);
|
||||
/* 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);
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) { concat(dest, table[i]); } }
|
||||
for (i = 0; i < n; 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 (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
|
||||
/* 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;
|
||||
}
|
||||
|
||||
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);
|
||||
#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
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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));
|
||||
#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
|
||||
/* 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));
|
||||
}
|
||||
|
||||
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);
|
||||
int writer, i;
|
||||
char latch;
|
||||
unsigned int reader, n = strlen(data);
|
||||
int writer, i;
|
||||
char latch;
|
||||
|
||||
writer = 0;
|
||||
latch = '1';
|
||||
writer = 0;
|
||||
latch = '1';
|
||||
|
||||
for(reader = 0; reader < n; reader++) {
|
||||
for(i = 0; i < ctoi(data[reader]); i++) {
|
||||
if(latch == '1') { set_module(symbol, symbol->rows, writer); }
|
||||
writer++;
|
||||
}
|
||||
for (reader = 0; reader < n; reader++) {
|
||||
for (i = 0; i < ctoi(data[reader]); i++) {
|
||||
if (latch == '1') {
|
||||
set_module(symbol, symbol->rows, writer);
|
||||
}
|
||||
writer++;
|
||||
}
|
||||
|
||||
latch = (latch == '1' ? '0' : '1');
|
||||
}
|
||||
latch = (latch == '1' ? '0' : '1');
|
||||
}
|
||||
|
||||
if(symbol->symbology != BARCODE_PHARMA) {
|
||||
if(writer > symbol->width) {
|
||||
symbol->width = writer;
|
||||
}
|
||||
} else {
|
||||
/* Pharmacode One ends with a space - adjust for this */
|
||||
if(writer > symbol->width + 2) {
|
||||
symbol->width = writer - 2;
|
||||
}
|
||||
}
|
||||
symbol->rows = symbol->rows + 1;
|
||||
if (symbol->symbology != BARCODE_PHARMA) {
|
||||
if (writer > symbol->width) {
|
||||
symbol->width = writer;
|
||||
}
|
||||
} else {
|
||||
/* Pharmacode One ends with a space - adjust for this */
|
||||
if (writer > symbol->width + 2) {
|
||||
symbol->width = writer - 2;
|
||||
}
|
||||
}
|
||||
symbol->rows = symbol->rows + 1;
|
||||
}
|
||||
|
||||
/* Indicates which symbologies can have row binding */
|
||||
int is_stackable(int symbology) {
|
||||
/* Indicates which symbologies can have row binding */
|
||||
if(symbology < BARCODE_PDF417) { return 1; }
|
||||
if(symbology == BARCODE_CODE128B) { return 1; }
|
||||
if(symbology == BARCODE_ISBNX) { return 1; }
|
||||
if(symbology == BARCODE_EAN14) { 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; }
|
||||
if (symbology < BARCODE_PDF417) {
|
||||
return 1;
|
||||
}
|
||||
if (symbology == BARCODE_CODE128B) {
|
||||
return 1;
|
||||
}
|
||||
if (symbology == BARCODE_ISBNX) {
|
||||
return 1;
|
||||
}
|
||||
if (symbology == BARCODE_EAN14) {
|
||||
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) {
|
||||
/* Indicates which symbols can have addon */
|
||||
if(symbology == BARCODE_EANX) { return 1; }
|
||||
if(symbology == BARCODE_UPCA) { return 1; }
|
||||
if(symbology == BARCODE_UPCE) { 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; }
|
||||
if (symbology == BARCODE_EANX) {
|
||||
return 1;
|
||||
}
|
||||
if (symbology == BARCODE_UPCA) {
|
||||
return 1;
|
||||
}
|
||||
if (symbology == BARCODE_UPCE) {
|
||||
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)
|
||||
{
|
||||
float remainder;
|
||||
int integer_part;
|
||||
int roundup(float input) {
|
||||
float remainder;
|
||||
int integer_part;
|
||||
|
||||
integer_part = (int)input;
|
||||
remainder = input - integer_part;
|
||||
integer_part = (int) input;
|
||||
remainder = input - integer_part;
|
||||
|
||||
if(remainder > 0.1) {
|
||||
integer_part++;
|
||||
}
|
||||
if (remainder > 0.1) {
|
||||
integer_part++;
|
||||
}
|
||||
|
||||
return integer_part;
|
||||
return integer_part;
|
||||
}
|
||||
|
||||
int istwodigits(unsigned char source[], int position)
|
||||
{
|
||||
if((source[position] >= '0') && (source[position] <= '9')) {
|
||||
if((source[position + 1] >= '0') && (source[position + 1] <= '9')) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
int istwodigits(unsigned char source[], int position) {
|
||||
if ((source[position] >= '0') && (source[position] <= '9')) {
|
||||
if ((source[position + 1] >= '0') && (source[position + 1] <= '9')) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
float froundup(float input)
|
||||
{
|
||||
float fraction, output = 0.0;
|
||||
float froundup(float input) {
|
||||
float fraction, output = 0.0;
|
||||
|
||||
fraction = input - (int)input;
|
||||
if(fraction > 0.01) { output = (input - fraction) + 1.0; } else { output = input; }
|
||||
fraction = input - (int) 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)
|
||||
{
|
||||
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;
|
||||
/* 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;
|
||||
|
||||
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 bpos, jpos, error_number;
|
||||
int next;
|
||||
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) {
|
||||
int bpos, jpos, error_number;
|
||||
int next;
|
||||
|
||||
bpos = 0;
|
||||
jpos = 0;
|
||||
error_number = 0;
|
||||
next = 0;
|
||||
bpos = 0;
|
||||
jpos = 0;
|
||||
error_number = 0;
|
||||
next = 0;
|
||||
|
||||
do {
|
||||
if(source[bpos] <= 0x7f) {
|
||||
/* 1 byte mode (7-bit ASCII) */
|
||||
vals[jpos] = source[bpos];
|
||||
next = bpos + 1;
|
||||
jpos++;
|
||||
} else {
|
||||
if((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) {
|
||||
strcpy(symbol->errtxt, "Corrupt Unicode data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) {
|
||||
strcpy(symbol->errtxt, "Overlong encoding not supported");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
do {
|
||||
if (source[bpos] <= 0x7f) {
|
||||
/* 1 byte mode (7-bit ASCII) */
|
||||
vals[jpos] = source[bpos];
|
||||
next = bpos + 1;
|
||||
jpos++;
|
||||
} else {
|
||||
if ((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) {
|
||||
strcpy(symbol->errtxt, "Corrupt Unicode data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if ((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) {
|
||||
strcpy(symbol->errtxt, "Overlong encoding not supported");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) {
|
||||
/* 2 byte mode */
|
||||
vals[jpos] = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f);
|
||||
next = bpos + 2;
|
||||
jpos++;
|
||||
} else
|
||||
if((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) {
|
||||
/* 3 byte mode */
|
||||
vals[jpos] = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f);
|
||||
next = bpos + 3;
|
||||
jpos ++;
|
||||
} else
|
||||
if(source[bpos] >= 0xf0) {
|
||||
strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
if ((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) {
|
||||
/* 2 byte mode */
|
||||
vals[jpos] = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f);
|
||||
next = bpos + 2;
|
||||
jpos++;
|
||||
} else
|
||||
if ((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) {
|
||||
/* 3 byte mode */
|
||||
vals[jpos] = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f);
|
||||
next = bpos + 3;
|
||||
jpos++;
|
||||
} else
|
||||
if (source[bpos] >= 0xf0) {
|
||||
strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
bpos = next;
|
||||
bpos = next;
|
||||
|
||||
} while(bpos < *length);
|
||||
*length = jpos;
|
||||
} while (bpos < *length);
|
||||
*length = jpos;
|
||||
|
||||
return error_number;
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
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
|
||||
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
|
||||
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)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Used in some logic */
|
||||
#ifndef __COMMON_H
|
||||
@ -48,32 +48,31 @@
|
||||
#include "zint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern int ustrlen(const unsigned char source[]);
|
||||
extern void ustrcpy(unsigned char target[], const unsigned char source[]);
|
||||
extern void concat(char dest[], const char source[]);
|
||||
extern void uconcat(unsigned char dest[], const unsigned char source[]);
|
||||
extern int ctoi(char source);
|
||||
extern char itoc(int source);
|
||||
extern void to_upper(unsigned char source[]);
|
||||
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 int posn(char set_string[], char data);
|
||||
extern void expand(struct zint_symbol *symbol, char data[]);
|
||||
extern int is_stackable(int symbology);
|
||||
extern int is_extendable(int symbology);
|
||||
extern int roundup(float input);
|
||||
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 unset_module(struct zint_symbol *symbol, int y_coord, int x_coord);
|
||||
extern int istwodigits(unsigned char source[], int position);
|
||||
extern float froundup(float input);
|
||||
extern int parunmodd(unsigned char llyth);
|
||||
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 ustrlen(const unsigned char source[]);
|
||||
extern void ustrcpy(unsigned char target[], const unsigned char source[]);
|
||||
extern void concat(char dest[], const char source[]);
|
||||
extern void uconcat(unsigned char dest[], const unsigned char source[]);
|
||||
extern int ctoi(char source);
|
||||
extern char itoc(int source);
|
||||
extern void to_upper(unsigned char source[]);
|
||||
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 int posn(char set_string[], char data);
|
||||
extern void expand(struct zint_symbol *symbol, char data[]);
|
||||
extern int is_stackable(int symbology);
|
||||
extern int is_extendable(int symbology);
|
||||
extern int roundup(float input);
|
||||
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 unset_module(struct zint_symbol *symbol, int y_coord, int x_coord);
|
||||
extern int istwodigits(unsigned char source[], int position);
|
||||
extern float froundup(float input);
|
||||
extern int parunmodd(unsigned char llyth);
|
||||
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);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
3934
backend/composite.c
3934
backend/composite.c
File diff suppressed because it is too large
Load Diff
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
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
|
||||
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
|
||||
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)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define NUMERIC 110
|
||||
#define ALPHA 97
|
||||
@ -39,35 +39,35 @@
|
||||
|
||||
/* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */
|
||||
static const int ccaCoeffs[30] = {
|
||||
/* k = 4 */
|
||||
522, 568, 723, 809,
|
||||
/* k = 4 */
|
||||
522, 568, 723, 809,
|
||||
|
||||
/* k = 5 */
|
||||
427, 919, 460, 155, 566,
|
||||
/* k = 5 */
|
||||
427, 919, 460, 155, 566,
|
||||
|
||||
/* k = 6 */
|
||||
861, 285, 19, 803, 17, 766,
|
||||
/* k = 6 */
|
||||
861, 285, 19, 803, 17, 766,
|
||||
|
||||
/* k = 7 */
|
||||
76, 925, 537, 597, 784, 691, 437,
|
||||
/* k = 7 */
|
||||
76, 925, 537, 597, 784, 691, 437,
|
||||
|
||||
/* k = 8 */
|
||||
237, 308, 436, 284, 646, 653, 428, 379
|
||||
/* k = 8 */
|
||||
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 */
|
||||
static const int ccaVariants[51] = {
|
||||
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,
|
||||
0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22
|
||||
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,
|
||||
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 */
|
||||
static const int aRAPTable[68] = {
|
||||
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,
|
||||
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
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
/* Row Address Patterns are as defined in pdf417.h */
|
||||
|
2145
backend/dmatrix.c
2145
backend/dmatrix.c
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -28,7 +28,7 @@
|
||||
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
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
Containes Extended Rectangular Data Matrix (DMRE)
|
||||
@ -41,11 +41,10 @@
|
||||
#ifndef __IEC16022ECC200_H
|
||||
#define __IEC16022ECC200_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#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
|
||||
}
|
||||
@ -62,28 +61,32 @@ extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], i
|
||||
#define DM_BASE256 6
|
||||
|
||||
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,
|
||||
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, 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 };
|
||||
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
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,
|
||||
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,
|
||||
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 };
|
||||
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
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,
|
||||
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, 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 };
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
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,
|
||||
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,
|
||||
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 };
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
// Activate DMRE Extensions
|
||||
//#define DMRE
|
||||
@ -92,20 +95,21 @@ static const int text_value[] = {
|
||||
|
||||
// Position in option array [symbol option value - 1]
|
||||
// The position in the option array is by increasing total data codewords with square first
|
||||
|
||||
|
||||
static const int intsymbol[] = {
|
||||
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*/
|
||||
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*/
|
||||
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*/
|
||||
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*/
|
||||
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*/
|
||||
26, /* 41: 26x48 , 90*/ 29, /* 42: 26x64 ,118*/
|
||||
0 };
|
||||
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*/
|
||||
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*/
|
||||
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*/
|
||||
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*/
|
||||
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*/
|
||||
26, /* 41: 26x48 , 90*/ 29, /* 42: 26x64 ,118*/
|
||||
0
|
||||
};
|
||||
|
||||
// Number of DM Sizes
|
||||
#define DMSIZESCOUNT 42
|
||||
@ -115,120 +119,121 @@ static const int intsymbol[] = {
|
||||
// Horizontal matrix size
|
||||
|
||||
static const int matrixH[] = {
|
||||
/*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 */
|
||||
/*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 */
|
||||
/*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 */
|
||||
/*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 */
|
||||
/*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*/
|
||||
/*40*/ 132,/*132x132,1304*/144/*144x144,1558*/
|
||||
};
|
||||
/*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 */
|
||||
/*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 */
|
||||
/*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 */
|
||||
/*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 */
|
||||
/*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*/
|
||||
/*40*/ 132, /*132x132,1304*/144/*144x144,1558*/
|
||||
};
|
||||
|
||||
// Vertical matrix sizes
|
||||
|
||||
static const int matrixW[] = {
|
||||
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
|
||||
/*4*/ 32, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 48, /* 8x48 */ 20, /* 20x20 */ 36, /* 12x36 */ 64, /* 8x64 */
|
||||
/*12*/ 22, /* 22x22 */ 36, /* 16x36 */ 24, /* 24x24 */ 64, /* 12x64 */
|
||||
/*16*/ 26, /* 26x26 */ 48, /* 16x48 */ 32, /* 24x32 */ 32, /* 26x32 */
|
||||
/*20*/ 36, /* 24x36 */ 32, /* 32x32 */ 64, /* 16x64 */ 40, /* 26x40 */
|
||||
/*24*/ 48, /* 24x48 */ 36, /* 36x36 */ 48, /* 26x48 */ 64, /* 24x64 */
|
||||
/*28*/ 40, /* 40x40 */ 64, /* 26x64 */ 44, /* 44x44 */ 48, /* 48x48 */
|
||||
/*32*/ 52, /* 52x52 */ 64, /* 64x64 */ 72, /* 72x72 */ 80, /* 80x80 */
|
||||
/*36*/ 88, /* 88x88 */ 96, /* 96x96 */ 104,/*104x104*/ 120,/*120x120*/
|
||||
/*40*/ 132,/*132x132*/ 144 /*144x144*/
|
||||
};
|
||||
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
|
||||
/*4*/ 32, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 48, /* 8x48 */ 20, /* 20x20 */ 36, /* 12x36 */ 64, /* 8x64 */
|
||||
/*12*/ 22, /* 22x22 */ 36, /* 16x36 */ 24, /* 24x24 */ 64, /* 12x64 */
|
||||
/*16*/ 26, /* 26x26 */ 48, /* 16x48 */ 32, /* 24x32 */ 32, /* 26x32 */
|
||||
/*20*/ 36, /* 24x36 */ 32, /* 32x32 */ 64, /* 16x64 */ 40, /* 26x40 */
|
||||
/*24*/ 48, /* 24x48 */ 36, /* 36x36 */ 48, /* 26x48 */ 64, /* 24x64 */
|
||||
/*28*/ 40, /* 40x40 */ 64, /* 26x64 */ 44, /* 44x44 */ 48, /* 48x48 */
|
||||
/*32*/ 52, /* 52x52 */ 64, /* 64x64 */ 72, /* 72x72 */ 80, /* 80x80 */
|
||||
/*36*/ 88, /* 88x88 */ 96, /* 96x96 */ 104, /*104x104*/ 120, /*120x120*/
|
||||
/*40*/ 132, /*132x132*/ 144 /*144x144*/
|
||||
};
|
||||
|
||||
// Horizontal submodule size (including subfinder)
|
||||
|
||||
static const int matrixFH[] = {
|
||||
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */
|
||||
/*4*/ 8, /* 8x32 */ 16, /* 16x16 */ 12, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 8, /* 8x48 */ 20, /* 20x20 */ 12, /* 12x36 */ 8, /* 8x64 */
|
||||
/*12*/ 22, /* 22x22 */ 16, /* 16x36 */ 24, /* 24x24 */ 12, /* 12x64 */
|
||||
/*16*/ 26, /* 26x26 */ 16, /* 16x48 */ 24, /* 24x32 */ 26, /* 26x32 */
|
||||
/*20*/ 24, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 26, /* 26x40 */
|
||||
/*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 26, /* 26x48 */ 24, /* 24x64 */
|
||||
/*28*/ 20, /* 40x40 */ 26, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */
|
||||
/*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */
|
||||
/*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/
|
||||
/*40*/ 22, /*132x132*/ 24 /*144x144*/
|
||||
};
|
||||
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */
|
||||
/*4*/ 8, /* 8x32 */ 16, /* 16x16 */ 12, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 8, /* 8x48 */ 20, /* 20x20 */ 12, /* 12x36 */ 8, /* 8x64 */
|
||||
/*12*/ 22, /* 22x22 */ 16, /* 16x36 */ 24, /* 24x24 */ 12, /* 12x64 */
|
||||
/*16*/ 26, /* 26x26 */ 16, /* 16x48 */ 24, /* 24x32 */ 26, /* 26x32 */
|
||||
/*20*/ 24, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 26, /* 26x40 */
|
||||
/*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 26, /* 26x48 */ 24, /* 24x64 */
|
||||
/*28*/ 20, /* 40x40 */ 26, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */
|
||||
/*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */
|
||||
/*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/
|
||||
/*40*/ 22, /*132x132*/ 24 /*144x144*/
|
||||
};
|
||||
|
||||
// Vertical submodule size (including subfinder)
|
||||
|
||||
static const int matrixFW[] = {
|
||||
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
|
||||
/*4*/ 16, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 24, /* 8x48 */ 20, /* 20x20 */ 18, /* 12x36 */ 16, /* 8x64 */
|
||||
/*12*/ 22, /* 22x22 */ 18, /* 16x36 */ 24, /* 24x24 */ 16, /* 12x64 */
|
||||
/*16*/ 26, /* 26x26 */ 24, /* 16x48 */ 16, /* 24x32 */ 16, /* 26x32 */
|
||||
/*20*/ 18, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 20, /* 26x40 */
|
||||
/*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 24, /* 26x48 */ 16, /* 24x64 */
|
||||
/*28*/ 20, /* 40x40 */ 16, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */
|
||||
/*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */
|
||||
/*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/
|
||||
/*40*/ 22, /*132x132*/ 24 /*144x144*/
|
||||
};
|
||||
/*0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
|
||||
/*4*/ 16, /* 8x32 */ 16, /* 16x16 */ 26, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 24, /* 8x48 */ 20, /* 20x20 */ 18, /* 12x36 */ 16, /* 8x64 */
|
||||
/*12*/ 22, /* 22x22 */ 18, /* 16x36 */ 24, /* 24x24 */ 16, /* 12x64 */
|
||||
/*16*/ 26, /* 26x26 */ 24, /* 16x48 */ 16, /* 24x32 */ 16, /* 26x32 */
|
||||
/*20*/ 18, /* 24x36 */ 16, /* 32x32 */ 16, /* 16x64 */ 20, /* 26x40 */
|
||||
/*24*/ 24, /* 24x48 */ 18, /* 36x36 */ 24, /* 26x48 */ 16, /* 24x64 */
|
||||
/*28*/ 20, /* 40x40 */ 16, /* 26x64 */ 22, /* 44x44 */ 24, /* 48x48 */
|
||||
/*32*/ 26, /* 52x52 */ 16, /* 64x64 */ 18, /* 72x72 */ 20, /* 80x80 */
|
||||
/*36*/ 22, /* 88x88 */ 24, /* 96x96 */ 26, /*104x104*/ 20, /*120x120*/
|
||||
/*40*/ 22, /*132x132*/ 24 /*144x144*/
|
||||
};
|
||||
|
||||
// Total Data Codewords
|
||||
|
||||
static const int matrixbytes[] = {
|
||||
/*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
|
||||
/*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
|
||||
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */
|
||||
/*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */
|
||||
/*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */
|
||||
/*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108, /* 24x64 */
|
||||
/*28*/ 114, /* 40x40 */ 118, /* 26x64 */ 144, /* 44x44 */ 174, /* 48x48 */
|
||||
/*32*/ 204, /* 52x52 */ 280, /* 64x64 */ 368, /* 72x72 */ 456, /* 80x80 */
|
||||
/*36*/ 576, /* 88x88 */ 696, /* 96x96 */ 816, /*104x104*/ 1050, /*120x120*/
|
||||
/*40*/ 1304, /*132x132*/ 1558 /*144x144*/
|
||||
};
|
||||
/*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
|
||||
/*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
|
||||
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */
|
||||
/*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */
|
||||
/*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */
|
||||
/*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108, /* 24x64 */
|
||||
/*28*/ 114, /* 40x40 */ 118, /* 26x64 */ 144, /* 44x44 */ 174, /* 48x48 */
|
||||
/*32*/ 204, /* 52x52 */ 280, /* 64x64 */ 368, /* 72x72 */ 456, /* 80x80 */
|
||||
/*36*/ 576, /* 88x88 */ 696, /* 96x96 */ 816, /*104x104*/ 1050, /*120x120*/
|
||||
/*40*/ 1304, /*132x132*/ 1558 /*144x144*/
|
||||
};
|
||||
|
||||
// Data Codewords per RS-Block
|
||||
|
||||
static const int matrixdatablock[] = {
|
||||
/*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
|
||||
/*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
|
||||
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */
|
||||
/*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */
|
||||
/*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */
|
||||
/*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108,/* 24x64 */
|
||||
/*28*/ 114,/* 40x40 */ 118,/* 26x64 */ 144,/* 44x44 */ 174,/* 48x48 */
|
||||
/*32*/ 102,/* 52x52 */ 140,/* 64x64 */ 92, /* 72x72 */ 114,/* 80x80 */
|
||||
/*36*/ 144,/* 88x88 */ 174,/* 96x96 */ 136,/*104x104*/ 175,/*120x120*/
|
||||
/*40*/ 163,/*132x132*/ 156 /*144x144*/
|
||||
};
|
||||
/*0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
|
||||
/*4*/ 10, /* 8x32 */ 12, /* 16x16 */ 16, /* 12x26 */ 18, /* 18x18 */
|
||||
/*8*/ 18, /* 8x48 */ 22, /* 20x20 */ 22, /* 12x36 */ 24, /* 8x64 */
|
||||
/*12*/ 30, /* 22x22 */ 32, /* 16x36 */ 36, /* 24x24 */ 43, /* 12x64 */
|
||||
/*16*/ 44, /* 26x26 */ 49, /* 16x48 */ 49, /* 24x32 */ 52, /* 26x32 */
|
||||
/*20*/ 55, /* 24x36 */ 62, /* 32x32 */ 62, /* 16x64 */ 70, /* 26x40 */
|
||||
/*24*/ 80, /* 24x48 */ 86, /* 36x36 */ 90, /* 26x48 */ 108, /* 24x64 */
|
||||
/*28*/ 114, /* 40x40 */ 118, /* 26x64 */ 144, /* 44x44 */ 174, /* 48x48 */
|
||||
/*32*/ 102, /* 52x52 */ 140, /* 64x64 */ 92, /* 72x72 */ 114, /* 80x80 */
|
||||
/*36*/ 144, /* 88x88 */ 174, /* 96x96 */ 136, /*104x104*/ 175, /*120x120*/
|
||||
/*40*/ 163, /*132x132*/ 156 /*144x144*/
|
||||
};
|
||||
|
||||
// ECC Codewords per RS-Block
|
||||
|
||||
static const int matrixrsblock[] = {
|
||||
/*0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */
|
||||
/*4*/ 11, /* 8x32 */ 12, /* 16x16 */ 14, /* 12x26 */ 14, /* 18x18 */
|
||||
/*8*/ 15, /* 8x48 */ 18, /* 20x20 */ 18, /* 12x36 */ 18, /* 8x64 */
|
||||
/*12*/ 20, /* 22x22 */ 24, /* 16x36 */ 24, /* 24x24 */ 27, /* 12x64 */
|
||||
/*16*/ 28, /* 26x26 */ 28, /* 16x48 */ 28, /* 24x32 */ 32, /* 26x32 */
|
||||
/*20*/ 33, /* 24x36 */ 36, /* 32x32 */ 36, /* 16x64 */ 38, /* 26x40 */
|
||||
/*24*/ 41, /* 24x48 */ 42, /* 36x36 */ 42, /* 26x48 */ 46, /* 24x64 */
|
||||
/*28*/ 48, /* 40x40 */ 50, /* 26x64 */ 56, /* 44x44 */ 68, /* 48x48 */
|
||||
/*32*/ 42, /* 52x52 */ 56, /* 64x64 */ 36, /* 72x72 */ 48, /* 80x80 */
|
||||
/*36*/ 56, /* 88x88 */ 68, /* 96x96 */ 56, /*104x104*/ 68, /*120x120*/
|
||||
/*40*/ 62, /*132x132*/ 62 /*144x144*/
|
||||
};
|
||||
/*0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */
|
||||
/*4*/ 11, /* 8x32 */ 12, /* 16x16 */ 14, /* 12x26 */ 14, /* 18x18 */
|
||||
/*8*/ 15, /* 8x48 */ 18, /* 20x20 */ 18, /* 12x36 */ 18, /* 8x64 */
|
||||
/*12*/ 20, /* 22x22 */ 24, /* 16x36 */ 24, /* 24x24 */ 27, /* 12x64 */
|
||||
/*16*/ 28, /* 26x26 */ 28, /* 16x48 */ 28, /* 24x32 */ 32, /* 26x32 */
|
||||
/*20*/ 33, /* 24x36 */ 36, /* 32x32 */ 36, /* 16x64 */ 38, /* 26x40 */
|
||||
/*24*/ 41, /* 24x48 */ 42, /* 36x36 */ 42, /* 26x48 */ 46, /* 24x64 */
|
||||
/*28*/ 48, /* 40x40 */ 50, /* 26x64 */ 56, /* 44x44 */ 68, /* 48x48 */
|
||||
/*32*/ 42, /* 52x52 */ 56, /* 64x64 */ 36, /* 72x72 */ 48, /* 80x80 */
|
||||
/*36*/ 56, /* 88x88 */ 68, /* 96x96 */ 56, /*104x104*/ 68, /*120x120*/
|
||||
/*40*/ 62, /*132x132*/ 62 /*144x144*/
|
||||
};
|
||||
|
||||
#else
|
||||
// No Rectangular extensions
|
||||
|
||||
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
|
||||
#define DMSIZESCOUNT 30
|
||||
@ -236,33 +241,40 @@ static const int intsymbol[] = {
|
||||
#define INTSYMBOL144 29
|
||||
|
||||
static const int matrixH[] = {
|
||||
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 };
|
||||
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
|
||||
};
|
||||
|
||||
static const int matrixW[] = {
|
||||
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 };
|
||||
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
|
||||
};
|
||||
|
||||
static const int matrixFH[] = {
|
||||
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 };
|
||||
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
|
||||
};
|
||||
|
||||
static const int matrixFW[] = {
|
||||
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 };
|
||||
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
|
||||
};
|
||||
|
||||
static const int matrixbytes[] = {
|
||||
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 };
|
||||
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
|
||||
};
|
||||
|
||||
static const int matrixdatablock[] = {
|
||||
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 };
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
static const int matrixrsblock[] = {
|
||||
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 };
|
||||
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
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __IEC16022ECC200_H */
|
||||
#endif
|
||||
|
3326
backend/font.h
3326
backend/font.h
File diff suppressed because it is too large
Load Diff
14894
backend/gb2312.h
14894
backend/gb2312.h
File diff suppressed because it is too large
Load Diff
2005
backend/gridmtx.c
2005
backend/gridmtx.c
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/* gridmtx.h - definitions for Grid Matrix
|
||||
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -27,7 +27,7 @@
|
||||
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
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define GM_NUMBER 1
|
||||
#define GM_LOWER 2
|
||||
@ -40,132 +40,144 @@
|
||||
#define EUROPIUM "0123456789ABCDEFGHIJKLMOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
|
||||
|
||||
static const char shift_set[] = {
|
||||
/* 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 */
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* DLE -> US */
|
||||
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':',
|
||||
';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
|
||||
/* 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 */
|
||||
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_max_cw[] = { 11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313 };
|
||||
//static const int gm_total_cw[] = { 18, 50, 98, 162, 242, 338, 450, 578, 722, 882, 1058, 1250, 1458 };
|
||||
static const int gm_recommend_cw[] = {
|
||||
9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021
|
||||
};
|
||||
|
||||
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[] = {
|
||||
0, 15, 13, 11, 9,
|
||||
45, 40, 35, 30, 25,
|
||||
89, 79, 69, 59, 49,
|
||||
146, 130, 114, 98, 81,
|
||||
218, 194, 170, 146, 121,
|
||||
305, 271, 237, 203, 169,
|
||||
405, 360, 315, 270, 225,
|
||||
521, 463, 405, 347, 289,
|
||||
650, 578, 506, 434, 361,
|
||||
794, 706, 618, 530, 441,
|
||||
953, 847, 741, 635, 529,
|
||||
1125, 1000, 875, 750, 625,
|
||||
1313, 1167, 1021, 875, 729
|
||||
0, 15, 13, 11, 9,
|
||||
45, 40, 35, 30, 25,
|
||||
89, 79, 69, 59, 49,
|
||||
146, 130, 114, 98, 81,
|
||||
218, 194, 170, 146, 121,
|
||||
305, 271, 237, 203, 169,
|
||||
405, 360, 315, 270, 225,
|
||||
521, 463, 405, 347, 289,
|
||||
650, 578, 506, 434, 361,
|
||||
794, 706, 618, 530, 441,
|
||||
953, 847, 741, 635, 529,
|
||||
1125, 1000, 875, 750, 625,
|
||||
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_b1[] = { 1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6 };
|
||||
static const int gm_b2[] = { 0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6 };
|
||||
static const int gm_n1[] = {
|
||||
18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122
|
||||
};
|
||||
|
||||
static const int gm_ebeb[] = {
|
||||
/* E1 B3 E2 B4 */
|
||||
0, 0, 0, 0, // version 1
|
||||
3, 1, 0, 0,
|
||||
5, 1, 0, 0,
|
||||
7, 1, 0, 0,
|
||||
9, 1, 0, 0,
|
||||
5, 1, 0, 0, // version 2
|
||||
10, 1, 0, 0,
|
||||
15, 1, 0, 0,
|
||||
20, 1, 0, 0,
|
||||
25, 1, 0, 0,
|
||||
9, 1, 0, 0, // version 3
|
||||
19, 1, 0, 0,
|
||||
29, 1, 0, 0,
|
||||
39, 1, 0, 0,
|
||||
49, 1, 0, 0,
|
||||
8, 2, 0, 0, // version 4
|
||||
16, 2, 0, 0,
|
||||
24, 2, 0, 0,
|
||||
32, 2, 0, 0,
|
||||
41, 1, 10, 1,
|
||||
12, 2, 0, 0, // version 5
|
||||
24, 2, 0, 0,
|
||||
36, 2, 0, 0,
|
||||
48, 2, 0, 0,
|
||||
61, 1, 60, 1,
|
||||
11, 3, 0, 0, // version 6
|
||||
23, 1, 22, 2,
|
||||
34, 2, 33, 1,
|
||||
45, 3, 0, 0,
|
||||
57, 1, 56, 2,
|
||||
12, 1, 11, 3, // version 7
|
||||
23, 2, 22, 2,
|
||||
34, 3, 33, 1,
|
||||
45, 4, 0, 0,
|
||||
57, 1, 56, 3,
|
||||
12, 2, 11, 3, // version 8
|
||||
23, 5, 0, 0,
|
||||
35, 3, 34, 2,
|
||||
47, 1, 46, 4,
|
||||
58, 4, 57, 1,
|
||||
12, 6, 0, 0, // version 9
|
||||
24, 6, 0, 0,
|
||||
36, 6, 0, 0,
|
||||
48, 6, 0, 0,
|
||||
61, 1, 60, 5,
|
||||
13, 4, 12, 3, // version 10
|
||||
26, 1, 25, 6,
|
||||
38, 5, 37, 2,
|
||||
51, 2, 50, 5,
|
||||
63, 7, 0, 0,
|
||||
12, 6, 11, 3, // version 11
|
||||
24, 4, 23, 5,
|
||||
36, 2, 35, 7,
|
||||
47, 9, 0, 0,
|
||||
59, 7, 58, 2,
|
||||
13, 5, 12, 5, // version 12
|
||||
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_b1[] = {
|
||||
1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6
|
||||
};
|
||||
|
||||
static const int gm_b2[] = {
|
||||
0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6
|
||||
};
|
||||
|
||||
static const int gm_ebeb[] = {
|
||||
/* E1 B3 E2 B4 */
|
||||
0, 0, 0, 0, // version 1
|
||||
3, 1, 0, 0,
|
||||
5, 1, 0, 0,
|
||||
7, 1, 0, 0,
|
||||
9, 1, 0, 0,
|
||||
5, 1, 0, 0, // version 2
|
||||
10, 1, 0, 0,
|
||||
15, 1, 0, 0,
|
||||
20, 1, 0, 0,
|
||||
25, 1, 0, 0,
|
||||
9, 1, 0, 0, // version 3
|
||||
19, 1, 0, 0,
|
||||
29, 1, 0, 0,
|
||||
39, 1, 0, 0,
|
||||
49, 1, 0, 0,
|
||||
8, 2, 0, 0, // version 4
|
||||
16, 2, 0, 0,
|
||||
24, 2, 0, 0,
|
||||
32, 2, 0, 0,
|
||||
41, 1, 10, 1,
|
||||
12, 2, 0, 0, // version 5
|
||||
24, 2, 0, 0,
|
||||
36, 2, 0, 0,
|
||||
48, 2, 0, 0,
|
||||
61, 1, 60, 1,
|
||||
11, 3, 0, 0, // version 6
|
||||
23, 1, 22, 2,
|
||||
34, 2, 33, 1,
|
||||
45, 3, 0, 0,
|
||||
57, 1, 56, 2,
|
||||
12, 1, 11, 3, // version 7
|
||||
23, 2, 22, 2,
|
||||
34, 3, 33, 1,
|
||||
45, 4, 0, 0,
|
||||
57, 1, 56, 3,
|
||||
12, 2, 11, 3, // version 8
|
||||
23, 5, 0, 0,
|
||||
35, 3, 34, 2,
|
||||
47, 1, 46, 4,
|
||||
58, 4, 57, 1,
|
||||
12, 6, 0, 0, // version 9
|
||||
24, 6, 0, 0,
|
||||
36, 6, 0, 0,
|
||||
48, 6, 0, 0,
|
||||
61, 1, 60, 5,
|
||||
13, 4, 12, 3, // version 10
|
||||
26, 1, 25, 6,
|
||||
38, 5, 37, 2,
|
||||
51, 2, 50, 5,
|
||||
63, 7, 0, 0,
|
||||
12, 6, 11, 3, // version 11
|
||||
24, 4, 23, 5,
|
||||
36, 2, 35, 7,
|
||||
47, 9, 0, 0,
|
||||
59, 7, 58, 2,
|
||||
13, 5, 12, 5, // version 12
|
||||
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[] = {
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
};
|
||||
|
538
backend/gs1.c
538
backend/gs1.c
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -28,7 +28,7 @@
|
||||
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
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -43,280 +43,316 @@
|
||||
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 */
|
||||
|
||||
void itostr(char ai_string[], int ai_value)
|
||||
{
|
||||
int thou, hund, ten, unit;
|
||||
char temp[2];
|
||||
void itostr(char ai_string[], int ai_value) {
|
||||
int thou, hund, ten, unit;
|
||||
char temp[2];
|
||||
|
||||
strcpy(ai_string, "(");
|
||||
thou = ai_value / 1000;
|
||||
hund = (ai_value - (1000 * thou)) / 100;
|
||||
ten = (ai_value - ((1000 * thou) + (100 * hund))) / 10;
|
||||
unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten));
|
||||
strcpy(ai_string, "(");
|
||||
thou = ai_value / 1000;
|
||||
hund = (ai_value - (1000 * thou)) / 100;
|
||||
ten = (ai_value - ((1000 * thou) + (100 * hund))) / 10;
|
||||
unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten));
|
||||
|
||||
temp[1] = '\0';
|
||||
if(ai_value >= 1000) { temp[0] = itoc(thou); concat(ai_string, temp); }
|
||||
if(ai_value >= 100) { temp[0] = itoc(hund); concat(ai_string, temp); }
|
||||
temp[0] = itoc(ten);
|
||||
concat(ai_string, temp);
|
||||
temp[0] = itoc(unit);
|
||||
concat(ai_string, temp);
|
||||
concat(ai_string, ")");
|
||||
temp[1] = '\0';
|
||||
if (ai_value >= 1000) {
|
||||
temp[0] = itoc(thou);
|
||||
concat(ai_string, temp);
|
||||
}
|
||||
if (ai_value >= 100) {
|
||||
temp[0] = itoc(hund);
|
||||
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 i, j, last_ai, ai_latch;
|
||||
char ai_string[6];
|
||||
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 error_latch;
|
||||
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) {
|
||||
int i, j, last_ai, ai_latch;
|
||||
char ai_string[6];
|
||||
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 error_latch;
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if(source[i] >=128) {
|
||||
strcpy(symbol->errtxt, "Extended ASCII characters are not supported by GS1");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if(source[i] < 32) {
|
||||
strcpy(symbol->errtxt, "Control characters are not supported by GS1");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
/* Detect extended ASCII characters */
|
||||
for (i = 0; i < src_len; i++) {
|
||||
if (source[i] >= 128) {
|
||||
strcpy(symbol->errtxt, "Extended ASCII characters are not supported by GS1");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (source[i] < 32) {
|
||||
strcpy(symbol->errtxt, "Control characters are not supported by GS1");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
if(source[0] != '[') {
|
||||
strcpy(symbol->errtxt, "Data does not start with an AI");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (source[0] != '[') {
|
||||
strcpy(symbol->errtxt, "Data does not start with an AI");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
/* Check the position of the brackets */
|
||||
bracket_level = 0;
|
||||
max_bracket_level = 0;
|
||||
ai_length = 0;
|
||||
max_ai_length = 0;
|
||||
min_ai_length = 5;
|
||||
j = 0;
|
||||
ai_latch = 0;
|
||||
for(i = 0; i < src_len; i++) {
|
||||
ai_length += j;
|
||||
if(((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) { ai_latch = 1; }
|
||||
if(source[i] == '[') { bracket_level++; j = 1; }
|
||||
if(source[i] == ']') {
|
||||
bracket_level--;
|
||||
if(ai_length < min_ai_length) { min_ai_length = 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--;
|
||||
/* Check the position of the brackets */
|
||||
bracket_level = 0;
|
||||
max_bracket_level = 0;
|
||||
ai_length = 0;
|
||||
max_ai_length = 0;
|
||||
min_ai_length = 5;
|
||||
j = 0;
|
||||
ai_latch = 0;
|
||||
for (i = 0; i < src_len; i++) {
|
||||
ai_length += j;
|
||||
if (((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) {
|
||||
ai_latch = 1;
|
||||
}
|
||||
if (source[i] == '[') {
|
||||
bracket_level++;
|
||||
j = 1;
|
||||
}
|
||||
if (source[i] == ']') {
|
||||
bracket_level--;
|
||||
if (ai_length < min_ai_length) {
|
||||
min_ai_length = 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) {
|
||||
/* Not all brackets are closed */
|
||||
strcpy(symbol->errtxt, "Malformed AI in input data (brackets don\'t match)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (bracket_level != 0) {
|
||||
/* Not all brackets are closed */
|
||||
strcpy(symbol->errtxt, "Malformed AI in input data (brackets don\'t match)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(max_bracket_level > 1) {
|
||||
/* Nested brackets */
|
||||
strcpy(symbol->errtxt, "Found nested brackets in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (max_bracket_level > 1) {
|
||||
/* Nested brackets */
|
||||
strcpy(symbol->errtxt, "Found nested brackets in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(max_ai_length > 4) {
|
||||
/* AI is too long */
|
||||
strcpy(symbol->errtxt, "Invalid AI in input data (AI too long)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (max_ai_length > 4) {
|
||||
/* AI is too long */
|
||||
strcpy(symbol->errtxt, "Invalid AI in input data (AI too long)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(min_ai_length <= 1) {
|
||||
/* AI is too short */
|
||||
strcpy(symbol->errtxt, "Invalid AI in input data (AI too short)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (min_ai_length <= 1) {
|
||||
/* AI is too short */
|
||||
strcpy(symbol->errtxt, "Invalid AI in input data (AI too short)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(ai_latch == 1) {
|
||||
/* Non-numeric data in AI */
|
||||
strcpy(symbol->errtxt, "Invalid AI in input data (non-numeric characters in AI)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (ai_latch == 1) {
|
||||
/* Non-numeric data in AI */
|
||||
strcpy(symbol->errtxt, "Invalid AI in input data (non-numeric characters in AI)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
ai_count = 0;
|
||||
for(i = 1; i < src_len; i++) {
|
||||
if(source[i - 1] == '[') {
|
||||
ai_location[ai_count] = i;
|
||||
j = 0;
|
||||
do {
|
||||
ai_string[j] = source[i + j];
|
||||
j++;
|
||||
} while (ai_string[j - 1] != ']');
|
||||
ai_string[j - 1] = '\0';
|
||||
ai_value[ai_count] = atoi(ai_string);
|
||||
ai_count++;
|
||||
}
|
||||
}
|
||||
ai_count = 0;
|
||||
for (i = 1; i < src_len; i++) {
|
||||
if (source[i - 1] == '[') {
|
||||
ai_location[ai_count] = i;
|
||||
j = 0;
|
||||
do {
|
||||
ai_string[j] = source[i + j];
|
||||
j++;
|
||||
} while (ai_string[j - 1] != ']');
|
||||
ai_string[j - 1] = '\0';
|
||||
ai_value[ai_count] = atoi(ai_string);
|
||||
ai_count++;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < ai_count; i++) {
|
||||
data_location[i] = ai_location[i] + 3;
|
||||
if(ai_value[i] >= 100) { data_location[i]++; }
|
||||
if(ai_value[i] >= 1000) { data_location[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++) {
|
||||
data_location[i] = ai_location[i] + 3;
|
||||
if (ai_value[i] >= 100) {
|
||||
data_location[i]++;
|
||||
}
|
||||
if (ai_value[i] >= 1000) {
|
||||
data_location[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++) {
|
||||
if(data_length[i] == 0) {
|
||||
/* No data for given AI */
|
||||
strcpy(symbol->errtxt, "Empty data field in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < ai_count; i++) {
|
||||
if (data_length[i] == 0) {
|
||||
/* No data for given AI */
|
||||
strcpy(symbol->errtxt, "Empty data field in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
error_latch = 0;
|
||||
strcpy(ai_string, "");
|
||||
for(i = 0; i < ai_count; i++) {
|
||||
switch (ai_value[i]) {
|
||||
case 0: if(data_length[i] != 18) { error_latch = 1; } break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3: if(data_length[i] != 14) { error_latch = 1; } break;
|
||||
case 4: if(data_length[i] != 16) { error_latch = 1; } break;
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19: if(data_length[i] != 6) { error_latch = 1; } break;
|
||||
case 20: if(data_length[i] != 2) { error_latch = 1; } break;
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 70:
|
||||
case 80:
|
||||
case 81: error_latch = 2; break;
|
||||
}
|
||||
if(
|
||||
((ai_value[i] >= 100) && (ai_value[i] <= 179))
|
||||
|| ((ai_value[i] >= 1000) && (ai_value[i] <= 1799))
|
||||
|| ((ai_value[i] >= 200) && (ai_value[i] <= 229))
|
||||
|| ((ai_value[i] >= 2000) && (ai_value[i] <= 2299))
|
||||
|| ((ai_value[i] >= 300) && (ai_value[i] <= 309))
|
||||
|| ((ai_value[i] >= 3000) && (ai_value[i] <= 3099))
|
||||
|| ((ai_value[i] >= 31) && (ai_value[i] <= 36))
|
||||
|| ((ai_value[i] >= 310) && (ai_value[i] <= 369))
|
||||
) {
|
||||
error_latch = 2;
|
||||
}
|
||||
if((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) {
|
||||
if(data_length[i] != 6) {
|
||||
error_latch = 1;
|
||||
}
|
||||
}
|
||||
if(
|
||||
((ai_value[i] >= 370) && (ai_value[i] <= 379))
|
||||
|| ((ai_value[i] >= 3700) && (ai_value[i] <= 3799))
|
||||
) {
|
||||
error_latch = 2;
|
||||
}
|
||||
if((ai_value[i] >= 410) && (ai_value[i] <= 415)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
error_latch = 0;
|
||||
strcpy(ai_string, "");
|
||||
for (i = 0; i < ai_count; i++) {
|
||||
switch (ai_value[i]) {
|
||||
case 0: if (data_length[i] != 18) {
|
||||
error_latch = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3: if (data_length[i] != 14) {
|
||||
error_latch = 1;
|
||||
}
|
||||
break;
|
||||
case 4: if (data_length[i] != 16) {
|
||||
error_latch = 1;
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19: if (data_length[i] != 6) {
|
||||
error_latch = 1;
|
||||
}
|
||||
break;
|
||||
case 20: if (data_length[i] != 2) {
|
||||
error_latch = 1;
|
||||
}
|
||||
break;
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 70:
|
||||
case 80:
|
||||
case 81: error_latch = 2;
|
||||
break;
|
||||
}
|
||||
if (
|
||||
((ai_value[i] >= 100) && (ai_value[i] <= 179))
|
||||
|| ((ai_value[i] >= 1000) && (ai_value[i] <= 1799))
|
||||
|| ((ai_value[i] >= 200) && (ai_value[i] <= 229))
|
||||
|| ((ai_value[i] >= 2000) && (ai_value[i] <= 2299))
|
||||
|| ((ai_value[i] >= 300) && (ai_value[i] <= 309))
|
||||
|| ((ai_value[i] >= 3000) && (ai_value[i] <= 3099))
|
||||
|| ((ai_value[i] >= 31) && (ai_value[i] <= 36))
|
||||
|| ((ai_value[i] >= 310) && (ai_value[i] <= 369))
|
||||
) {
|
||||
error_latch = 2;
|
||||
}
|
||||
if ((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) {
|
||||
if (data_length[i] != 6) {
|
||||
error_latch = 1;
|
||||
}
|
||||
}
|
||||
if (
|
||||
((ai_value[i] >= 370) && (ai_value[i] <= 379))
|
||||
|| ((ai_value[i] >= 3700) && (ai_value[i] <= 3799))
|
||||
) {
|
||||
error_latch = 2;
|
||||
}
|
||||
if ((ai_value[i] >= 410) && (ai_value[i] <= 415)) {
|
||||
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) {
|
||||
strcpy(symbol->errtxt, "Invalid data length for AI ");
|
||||
concat(symbol->errtxt, ai_string);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (error_latch == 5) {
|
||||
strcpy(symbol->errtxt, "Invalid data length for AI ");
|
||||
concat(symbol->errtxt, ai_string);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(error_latch == 6) {
|
||||
strcpy(symbol->errtxt, "Invalid AI value ");
|
||||
concat(symbol->errtxt, ai_string);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
if (error_latch == 6) {
|
||||
strcpy(symbol->errtxt, "Invalid AI value ");
|
||||
concat(symbol->errtxt, ai_string);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
/* Resolve AI data - put resulting string in 'reduced' */
|
||||
j = 0;
|
||||
last_ai = 0;
|
||||
ai_latch = 1;
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if((source[i] != '[') && (source[i] != ']')) {
|
||||
reduced[j++] = source[i];
|
||||
}
|
||||
if(source[i] == '[') {
|
||||
/* Start of an AI string */
|
||||
if(ai_latch == 0) {
|
||||
reduced[j++] = '[';
|
||||
}
|
||||
ai_string[0] = source[i + 1];
|
||||
ai_string[1] = source[i + 2];
|
||||
ai_string[2] = '\0';
|
||||
last_ai = atoi(ai_string);
|
||||
ai_latch = 0;
|
||||
/* 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" */
|
||||
if(
|
||||
((last_ai >= 0) && (last_ai <= 4))
|
||||
|| ((last_ai >= 11) && (last_ai <= 20))
|
||||
|| (last_ai == 23) /* legacy support - see 5.3.8.2.2 */
|
||||
|| ((last_ai >= 31) && (last_ai <= 36))
|
||||
|| (last_ai == 41)
|
||||
) {
|
||||
ai_latch = 1;
|
||||
}
|
||||
}
|
||||
/* The ']' character is simply dropped from the input */
|
||||
}
|
||||
reduced[j] = '\0';
|
||||
/* Resolve AI data - put resulting string in 'reduced' */
|
||||
j = 0;
|
||||
last_ai = 0;
|
||||
ai_latch = 1;
|
||||
for (i = 0; i < src_len; i++) {
|
||||
if ((source[i] != '[') && (source[i] != ']')) {
|
||||
reduced[j++] = source[i];
|
||||
}
|
||||
if (source[i] == '[') {
|
||||
/* Start of an AI string */
|
||||
if (ai_latch == 0) {
|
||||
reduced[j++] = '[';
|
||||
}
|
||||
ai_string[0] = source[i + 1];
|
||||
ai_string[1] = source[i + 2];
|
||||
ai_string[2] = '\0';
|
||||
last_ai = atoi(ai_string);
|
||||
ai_latch = 0;
|
||||
/* 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" */
|
||||
if (
|
||||
((last_ai >= 0) && (last_ai <= 4))
|
||||
|| ((last_ai >= 11) && (last_ai <= 20))
|
||||
|| (last_ai == 23) /* legacy support - see 5.3.8.2.2 */
|
||||
|| ((last_ai >= 31) && (last_ai <= 36))
|
||||
|| (last_ai == 41)
|
||||
) {
|
||||
ai_latch = 1;
|
||||
}
|
||||
}
|
||||
/* The ']' character is simply dropped from the input */
|
||||
}
|
||||
reduced[j] = '\0';
|
||||
|
||||
/* the character '[' in the reduced string refers to the FNC1 character */
|
||||
return 0;
|
||||
/* the character '[' in the reduced string refers to the FNC1 character */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[])
|
||||
{
|
||||
/* Only to keep the compiler happy */
|
||||
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]) {
|
||||
/* Only to keep the compiler happy */
|
||||
#ifndef _MSC_VER
|
||||
char temp[src_len + 5];
|
||||
char temp[src_len + 5];
|
||||
#else
|
||||
char* temp = (char*)_alloca(src_len + 5);
|
||||
char* temp = (char*) _alloca(src_len + 5);
|
||||
#endif
|
||||
int error_number;
|
||||
int error_number;
|
||||
|
||||
error_number = gs1_verify(symbol, source, src_len, temp);
|
||||
if(error_number != 0) { return error_number; }
|
||||
error_number = gs1_verify(symbol, source, src_len, temp);
|
||||
if (error_number != 0) {
|
||||
return error_number;
|
||||
}
|
||||
|
||||
if (strlen(temp) < src_len + 5) {
|
||||
ustrcpy(reduced, (unsigned char*)temp);
|
||||
return 0;
|
||||
}
|
||||
strcpy(symbol->errtxt, "ugs1_verify overflow");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
if (strlen(temp) < src_len + 5) {
|
||||
ustrcpy(reduced, (unsigned char*) temp);
|
||||
return 0;
|
||||
}
|
||||
strcpy(symbol->errtxt, "ugs1_verify overflow");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
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
|
||||
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
|
||||
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)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
#ifndef __GS1_H
|
||||
#define __GS1_H
|
||||
|
||||
@ -36,8 +36,8 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
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 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[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user