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
155
backend/2of5.c
155
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,34 +39,39 @@
|
||||
#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)
|
||||
{
|
||||
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) */
|
||||
/* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
|
||||
int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
|
||||
|
||||
error_number = 0;
|
||||
|
||||
if(length > 80) {
|
||||
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) {
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -74,32 +79,32 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l
|
||||
/* start character */
|
||||
strcpy(dest, "411111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "41111");
|
||||
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 */
|
||||
|
||||
error_number = 0;
|
||||
|
||||
if(length > 45) {
|
||||
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) {
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid character in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -107,31 +112,31 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
|
||||
/* start character */
|
||||
strcpy(dest, "313111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "31113");
|
||||
concat(dest, "31113");
|
||||
|
||||
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 */
|
||||
/* 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;
|
||||
|
||||
if(length > 45) {
|
||||
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) {
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -139,32 +144,32 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
/* start */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* stop */
|
||||
concat (dest, "311");
|
||||
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 */
|
||||
/* Code 2 of 5 Data Logic */
|
||||
int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
|
||||
int i, error_number;
|
||||
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
|
||||
if(length > 80) {
|
||||
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) {
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -172,32 +177,32 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "311");
|
||||
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];
|
||||
#ifndef _MSC_VER
|
||||
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;
|
||||
|
||||
if(length > 89) {
|
||||
if (length > 89) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
@ -210,8 +215,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char 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)
|
||||
{
|
||||
if (length & 1) {
|
||||
ustrcpy(temp, (unsigned char *) "0");
|
||||
length++;
|
||||
}
|
||||
@ -220,8 +224,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
|
||||
/* start character */
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i+=2 )
|
||||
{
|
||||
for (i = 0; i < length; i += 2) {
|
||||
/* look up the bars and the spaces and put them in two strings */
|
||||
strcpy(bars, "");
|
||||
lookup(NEON, C25InterTable, temp[i], bars);
|
||||
@ -230,17 +233,18 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
|
||||
|
||||
/* then merge (interlace) the strings together */
|
||||
k = 0;
|
||||
for(j = 0; j <= 4; j++)
|
||||
{
|
||||
mixed[k] = bars[j]; k++;
|
||||
mixed[k] = spaces[j]; k++;
|
||||
for (j = 0; j <= 4; j++) {
|
||||
mixed[k] = bars[j];
|
||||
k++;
|
||||
mixed[k] = spaces[j];
|
||||
k++;
|
||||
}
|
||||
mixed[k] = '\0';
|
||||
concat (dest, mixed);
|
||||
concat(dest, mixed);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "311");
|
||||
concat(dest, "311");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, temp);
|
||||
@ -248,8 +252,8 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
|
||||
|
||||
}
|
||||
|
||||
int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
/* Interleaved 2-of-5 (ITF) */
|
||||
int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
@ -258,26 +262,25 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
count = 0;
|
||||
|
||||
if(length > 13) {
|
||||
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) {
|
||||
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++) {
|
||||
for (i = 0; i < zeroes; i++) {
|
||||
localstr[i] = '0';
|
||||
}
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
/* Calculate the check digit - the same method used for EAN-13 */
|
||||
|
||||
for (i = 12; i >= 0; i--) {
|
||||
count += ctoi(localstr[i]);
|
||||
|
||||
@ -287,13 +290,13 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
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);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*) localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutshe Post Leitcode */
|
||||
/* Deutshe Post Leitcode */
|
||||
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
@ -301,23 +304,22 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
error_number = 0;
|
||||
count = 0;
|
||||
if(length > 13) {
|
||||
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) {
|
||||
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++)
|
||||
for (i = 0; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
for (i = 12; i >= 0; i--)
|
||||
{
|
||||
for (i = 12; i >= 0; i--) {
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
|
||||
if (i & 1) {
|
||||
@ -326,35 +328,34 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
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);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*) localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutsche Post Identcode */
|
||||
/* Deutsche Post Identcode */
|
||||
int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
|
||||
count = 0;
|
||||
if(length > 11) {
|
||||
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) {
|
||||
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++)
|
||||
for (i = 0; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
for (i = 10; i >= 0; i--)
|
||||
{
|
||||
for (i = 10; i >= 0; i--) {
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
|
||||
if (i & 1) {
|
||||
@ -363,7 +364,7 @@ int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
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);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *) localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*) localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
@ -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,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",
|
||||
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"};
|
||||
"003", "013"
|
||||
};
|
||||
|
||||
static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011", "012", "013", "020", "021",
|
||||
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"};
|
||||
"332", "333"
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -57,28 +63,23 @@ static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011",
|
||||
#define inline _inline
|
||||
#endif
|
||||
|
||||
static inline char convert_pattern(char data, int 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];
|
||||
|
||||
for(reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
for (reader = 0; reader < triple_writer; reader++) {
|
||||
inv_triple[reader] = triple[(triple_writer - 1) - reader];
|
||||
}
|
||||
|
||||
@ -86,16 +87,14 @@ void rs_error(char data_pattern[])
|
||||
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]]);
|
||||
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 */
|
||||
/* 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 */
|
||||
@ -117,10 +116,9 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
strcpy(localstr, "");
|
||||
|
||||
/* Do all of the length checking first to avoid stack smashing */
|
||||
if(symbol->symbology == BARCODE_AUSPOST) {
|
||||
if (symbol->symbology == BARCODE_AUSPOST) {
|
||||
/* Format control code (FCC) */
|
||||
switch(length)
|
||||
{
|
||||
switch (length) {
|
||||
case 8:
|
||||
strcpy(fcc, "11");
|
||||
break;
|
||||
@ -142,7 +140,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
strcpy(symbol->errtxt, "Auspost input is wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -151,10 +149,13 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
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;
|
||||
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 */
|
||||
@ -163,10 +164,10 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
localstr[8] = '\0';
|
||||
}
|
||||
|
||||
concat(localstr, (char*)source);
|
||||
concat(localstr, (char*) source);
|
||||
h = strlen(localstr);
|
||||
error_number = is_sane(GDSET, (unsigned char *)localstr, h);
|
||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
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;
|
||||
}
|
||||
@ -174,8 +175,8 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
/* 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) {
|
||||
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;
|
||||
}
|
||||
@ -184,29 +185,25 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
strcpy(data_pattern, "13");
|
||||
|
||||
/* Encode the FCC */
|
||||
for(reader = 0; reader < 2; reader++)
|
||||
{
|
||||
for (reader = 0; reader < 2; reader++) {
|
||||
lookup(NEON, AusNTable, fcc[reader], data_pattern);
|
||||
}
|
||||
|
||||
/* printf("AUSPOST FCC: %s ", fcc); */
|
||||
|
||||
/* Delivery Point Identifier (DPID) */
|
||||
for(reader = 0; reader < 8; reader++)
|
||||
{
|
||||
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++) {
|
||||
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++) {
|
||||
} else if ((h == 16) || (h == 23)) {
|
||||
for (reader = 8; reader < h; reader++) {
|
||||
lookup(NEON, AusNTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
@ -214,8 +211,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
|
||||
/* Filler bar */
|
||||
h = strlen(data_pattern);
|
||||
switch (h)
|
||||
{
|
||||
switch (h) {
|
||||
case 22:
|
||||
case 37:
|
||||
case 52:
|
||||
@ -234,15 +230,12 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
/* 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'))
|
||||
{
|
||||
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'))
|
||||
{
|
||||
if ((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) {
|
||||
set_module(symbol, 2, writer);
|
||||
}
|
||||
writer += 2;
|
||||
|
1148
backend/aztec.c
1148
backend/aztec.c
File diff suppressed because it is too large
Load Diff
121
backend/aztec.h
121
backend/aztec.h
@ -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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define UPPER 1
|
||||
#define LOWER 2
|
||||
@ -39,37 +39,39 @@
|
||||
|
||||
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 */
|
||||
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,
|
||||
@ -79,7 +81,8 @@ const int AztecCodeSet[128] = { /* From Table 2 */
|
||||
2, 2, 2, 8, 4, 8, 4, 4
|
||||
};
|
||||
|
||||
const int AztecSymbolChar[128] = { /* From Table 2 */
|
||||
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,
|
||||
@ -93,58 +96,82 @@ const int AztecSymbolChar[128] = { /* From Table 2 */
|
||||
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",
|
||||
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",
|
||||
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 char *tribit[8] = {
|
||||
"000", "001", "010", "011", "100", "101", "110", "111"
|
||||
};
|
||||
|
||||
static const int AztecSizes[32] = { /* Codewords per symbol */
|
||||
static const int AztecSizes[32] = {
|
||||
/* Codewords per symbol */
|
||||
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
|
||||
864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
|
||||
};
|
||||
|
||||
static const int AztecCompactSizes[4] = { 17, 40, 51, 76 };
|
||||
static const int AztecCompactSizes[4] = {
|
||||
17, 40, 51, 76
|
||||
};
|
||||
|
||||
static const int Aztec10DataSizes[32] = { /* Data bits per symbol maximum with 10% error correction */
|
||||
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 Aztec23DataSizes[32] = { /* Data bits per symbol maximum with 23% error correction */
|
||||
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 Aztec36DataSizes[32] = { /* Data bits per symbol maximum with 36% error correction */
|
||||
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 */
|
||||
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 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
|
||||
};
|
||||
|
||||
static const int AztecCompactOffset[4] = { 6, 4, 2, 0 };
|
||||
static const int AztecCompactOffset[4] = {
|
||||
6, 4, 2, 0
|
||||
};
|
||||
|
281
backend/code.c
281
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",
|
||||
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"};
|
||||
/* Code 39 character assignments (Table 1) */
|
||||
"1211121211", "1112121211"
|
||||
};
|
||||
|
||||
static const char *EC39Ctrl[128] = {"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K",
|
||||
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"};
|
||||
/* Encoding the full ASCII character set in Code 39 (Table A2) */
|
||||
"+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"
|
||||
};
|
||||
|
||||
static const char *C93Ctrl[128] = {"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK",
|
||||
static const char *C93Ctrl[128] = {
|
||||
"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"};
|
||||
"dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"
|
||||
};
|
||||
|
||||
static const char *C93Table[47] = {"131112", "111213", "111312", "111411", "121113", "121212", "121311",
|
||||
static const char *C93Table[47] = {
|
||||
"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"};
|
||||
"121221", "312111", "311121", "122211"
|
||||
};
|
||||
|
||||
/* Global Variables for Channel Code */
|
||||
int S[11], B[11];
|
||||
@ -95,9 +104,7 @@ 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;
|
||||
@ -107,12 +114,12 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
error_number = 0;
|
||||
|
||||
if(length > 121) {
|
||||
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) {
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -125,20 +132,20 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(dest, "112211");
|
||||
|
||||
/* Draw main body of barcode */
|
||||
for(i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(SODIUM, C11Table, source[i], dest);
|
||||
if(source[i] == '-')
|
||||
if (source[i] == '-')
|
||||
weight[i] = 10;
|
||||
else
|
||||
weight[i] = ctoi(source[i]);
|
||||
}
|
||||
|
||||
/* Calculate C checksum */
|
||||
for(h = length - 1; h >= 0; h--) {
|
||||
for (h = length - 1; h >= 0; h--) {
|
||||
c_count += (c_weight * weight[h]);
|
||||
c_weight++;
|
||||
|
||||
if(c_weight > 10) {
|
||||
if (c_weight > 10) {
|
||||
c_weight = 1;
|
||||
}
|
||||
}
|
||||
@ -147,11 +154,11 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
weight[length] = c_digit;
|
||||
|
||||
/* Calculate K checksum */
|
||||
for(h = length; h >= 0; h--) {
|
||||
for (h = length; h >= 0; h--) {
|
||||
k_count += (k_weight * weight[h]);
|
||||
k_weight++;
|
||||
|
||||
if(k_weight > 9) {
|
||||
if (k_weight > 9) {
|
||||
k_weight = 1;
|
||||
}
|
||||
}
|
||||
@ -159,48 +166,52 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
checkstr[0] = itoc(c_digit);
|
||||
checkstr[1] = itoc(k_digit);
|
||||
if(checkstr[0] == 'A') { checkstr[0] = '-'; }
|
||||
if(checkstr[1] == 'A') { checkstr[1] = '-'; }
|
||||
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");
|
||||
concat(dest, "11221");
|
||||
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)checkstr);
|
||||
uconcat(symbol->text, (unsigned char*) checkstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Code 39 */
|
||||
/* Code 39 */
|
||||
int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
unsigned int i;
|
||||
unsigned int counter;
|
||||
char check_digit;
|
||||
int error_number;
|
||||
char dest[775];
|
||||
char localstr[2] = { 0 };
|
||||
char localstr[2] = {0};
|
||||
|
||||
error_number = 0;
|
||||
counter = 0;
|
||||
|
||||
if((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
|
||||
if ((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
|
||||
symbol->option_2 = 0;
|
||||
}
|
||||
|
||||
if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
|
||||
if ((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
} else if(length > 74) {
|
||||
} 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) {
|
||||
error_number = is_sane(SILVER, source, length);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
@ -208,36 +219,44 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Start character */
|
||||
strcpy(dest, "1211212111");
|
||||
|
||||
for(i = 0; i < length; 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) {
|
||||
if (counter < 10) {
|
||||
check_digit = itoc(counter);
|
||||
} else {
|
||||
if(counter < 36) {
|
||||
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 */
|
||||
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 == ' ') {
|
||||
if (check_digit == ' ') {
|
||||
check_digit = '_';
|
||||
}
|
||||
|
||||
@ -246,13 +265,13 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "121121211");
|
||||
concat(dest, "121121211");
|
||||
|
||||
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
|
||||
if ((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
|
||||
/* LOGMARS uses wider 'wide' bars than normal Code 39 */
|
||||
counter = strlen(dest);
|
||||
for(i = 0; i < counter; i++) {
|
||||
if(dest[i] == '2') {
|
||||
for (i = 0; i < counter; i++) {
|
||||
if (dest[i] == '2') {
|
||||
dest[i] = '3';
|
||||
}
|
||||
}
|
||||
@ -260,20 +279,20 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
expand(symbol, dest);
|
||||
|
||||
if(symbol->symbology == BARCODE_CODE39) {
|
||||
ustrcpy(symbol->text, (unsigned char*)"*");
|
||||
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*)"*");
|
||||
uconcat(symbol->text, (unsigned char*) localstr);
|
||||
uconcat(symbol->text, (unsigned char*) "*");
|
||||
} else {
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)localstr);
|
||||
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;
|
||||
@ -282,81 +301,78 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
|
||||
error_number = 0;
|
||||
|
||||
count = 0;
|
||||
if(length > 6) {
|
||||
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) {
|
||||
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++)
|
||||
for (i = 1; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
strcpy(localstr + zeroes, (char *) source);
|
||||
|
||||
for (i = 1; i < 7; i++) {
|
||||
count += (i + 1) * ctoi(localstr[i]);
|
||||
}
|
||||
|
||||
check_digit = count%11;
|
||||
if (check_digit == 11) { check_digit = 0; }
|
||||
check_digit = count % 11;
|
||||
if (check_digit == 11) {
|
||||
check_digit = 0;
|
||||
}
|
||||
localstr[7] = itoc(check_digit);
|
||||
localstr[8] = '\0';
|
||||
if(localstr[7] == 'A') {
|
||||
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);
|
||||
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 *************** */
|
||||
|
||||
int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
|
||||
|
||||
unsigned char buffer[150] = { 0 };
|
||||
unsigned char buffer[150] = {0};
|
||||
unsigned int i;
|
||||
int error_number;
|
||||
|
||||
error_number = 0;
|
||||
|
||||
if(length > 74) {
|
||||
if (length > 74) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* Creates a buffer string and places control characters into it */
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] > 127) {
|
||||
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]]);
|
||||
concat((char*) buffer, EC39Ctrl[source[i]]);
|
||||
}
|
||||
|
||||
/* Then sends the buffer to the C39 function */
|
||||
error_number = c39(symbol, buffer, ustrlen(buffer));
|
||||
|
||||
for(i = 0; i < length; i++)
|
||||
for (i = 0; i < length; i++)
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
symbol->text[length] = '\0';
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* ******************** CODE 93 ******************* */
|
||||
|
||||
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 */
|
||||
/* 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) {
|
||||
|
||||
/* 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
|
||||
@ -371,7 +387,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
error_number = 0;
|
||||
strcpy(buffer, "");
|
||||
|
||||
if(length > 107) {
|
||||
if (length > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
@ -419,7 +435,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for (i = h; i >= 0; i--) {
|
||||
k += values[i] * weight;
|
||||
weight++;
|
||||
if(weight == 16)
|
||||
if (weight == 16)
|
||||
weight = 1;
|
||||
}
|
||||
k = k % 47;
|
||||
@ -429,7 +445,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Start character */
|
||||
strcpy(dest, "111141");
|
||||
|
||||
for(i = 0; i < h; i++) {
|
||||
for (i = 0; i < h; i++) {
|
||||
lookup(SILVER, C93Table, buffer[i], dest);
|
||||
}
|
||||
|
||||
@ -445,6 +461,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* 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:
|
||||
@ -458,10 +475,10 @@ void CheckCharacter() {
|
||||
int i;
|
||||
char part[3];
|
||||
|
||||
if(value == target_value) {
|
||||
if (value == target_value) {
|
||||
/* Target reached - save the generated pattern */
|
||||
strcpy(pattern, "11110");
|
||||
for(i = 0; i < 11; i++) {
|
||||
for (i = 0; i < 11; i++) {
|
||||
part[0] = itoc(S[i]);
|
||||
part[1] = itoc(B[i]);
|
||||
part[2] = '\0';
|
||||
@ -473,11 +490,11 @@ void CheckCharacter() {
|
||||
void NextB(int Chan, int i, int MaxB, int MaxS) {
|
||||
int b;
|
||||
|
||||
b = (S[i]+B[i-1]+S[i-1]+B[i-2] > 4)? 1:2;
|
||||
if (i < Chan+2) {
|
||||
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);
|
||||
NextS(Chan, i + 1, MaxS, MaxB + 1 - b);
|
||||
}
|
||||
} else if (b <= MaxB) {
|
||||
B[i] = MaxB;
|
||||
@ -489,63 +506,91 @@ void NextB(int Chan, int i, int MaxB, int MaxS) {
|
||||
void NextS(int Chan, int i, int MaxS, int MaxB) {
|
||||
int s;
|
||||
|
||||
for (s = (i<Chan+2)? 1: MaxS; s <= MaxS; s++) {
|
||||
for (s = (i < Chan + 2) ? 1 : MaxS; s <= MaxS; s++) {
|
||||
S[i] = s;
|
||||
NextB(Chan,i,MaxB,MaxS+1-s);
|
||||
NextB(Chan, i, MaxB, MaxS + 1 - s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Channel Code - According to ANSI/AIM BC12-1998 */
|
||||
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
/* Channel Code - According to ANSI/AIM BC12-1998 */
|
||||
|
||||
int channels, i;
|
||||
int error_number = 0, range = 0, zeroes;
|
||||
char hrt[9];
|
||||
|
||||
target_value = 0;
|
||||
|
||||
if(length > 7) {
|
||||
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) {
|
||||
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++) {
|
||||
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;
|
||||
switch (channels) {
|
||||
case 3: if (target_value > 26) {
|
||||
range = 1;
|
||||
}
|
||||
if(range) {
|
||||
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);
|
||||
NextS(channels, 3, channels, channels);
|
||||
|
||||
zeroes = channels - 1 - length;
|
||||
memset(hrt, '0', zeroes);
|
||||
strcpy(hrt + zeroes, (char *)source);
|
||||
ustrcpy(symbol->text, (unsigned char *)hrt);
|
||||
strcpy(hrt + zeroes, (char *) source);
|
||||
ustrcpy(symbol->text, (unsigned char *) hrt);
|
||||
|
||||
expand(symbol, pattern);
|
||||
|
||||
|
1272
backend/code1.c
1272
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 };
|
||||
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 };
|
||||
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
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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,11 +28,11 @@
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Updated to comply with BS EN 12323:2005 */
|
||||
|
||||
/* up to 77 characters or 154 numbers */
|
||||
/* Code 16k can hold up to 77 characters or 154 numbers */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -54,8 +54,9 @@
|
||||
|
||||
static int list[2][170];
|
||||
|
||||
/* EN 12323 Table 1 - "Code 16K" character encodations */
|
||||
static const char *C16KTable[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213",
|
||||
static const char *C16KTable[107] = {
|
||||
/* EN 12323 Table 1 - "Code 16K" character encodations */
|
||||
"212222", "222122", "222221", "121223", "121322", "131222", "122213",
|
||||
"122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222",
|
||||
"123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222",
|
||||
"321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323",
|
||||
@ -67,30 +68,38 @@ static const char *C16KTable[107] = {"212222", "222122", "222221", "121223", "12
|
||||
"134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112",
|
||||
"421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311",
|
||||
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
|
||||
"211133"};
|
||||
"211133"
|
||||
};
|
||||
|
||||
/* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */
|
||||
static const char *C16KStartStop[8] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "3112"};
|
||||
|
||||
static const char *C16KStartStop[8] = {
|
||||
/* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */
|
||||
"3211", "2221", "2122", "1411", "1132", "1231", "1114", "3112"
|
||||
};
|
||||
|
||||
/* EN 12323 Table 5 - Start and stop values defining row numbers */
|
||||
static const int C16KStartValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7};
|
||||
static const int C16KStopValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3};
|
||||
static const int C16KStartValues[16] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7
|
||||
};
|
||||
|
||||
void grwp16(int *indexliste)
|
||||
{
|
||||
static const int C16KStopValues[16] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3
|
||||
};
|
||||
|
||||
void grwp16(int *indexliste) {
|
||||
int i, j;
|
||||
|
||||
/* bring together same type blocks */
|
||||
if(*(indexliste) > 1) {
|
||||
if (*(indexliste) > 1) {
|
||||
i = 1;
|
||||
while(i < *(indexliste)) {
|
||||
if(list[1][i - 1] == list[1][i]) {
|
||||
while (i < *(indexliste)) {
|
||||
if (list[1][i - 1] == list[1][i]) {
|
||||
/* bring together */
|
||||
list[0][i - 1] = list[0][i - 1] + list[0][i];
|
||||
j = i + 1;
|
||||
|
||||
/* decreace the list */
|
||||
while(j < *(indexliste)) {
|
||||
while (j < *(indexliste)) {
|
||||
list[0][j - 1] = list[0][j];
|
||||
list[1][j - 1] = list[1][j];
|
||||
j++;
|
||||
@ -103,54 +112,123 @@ void grwp16(int *indexliste)
|
||||
}
|
||||
}
|
||||
|
||||
void dxsmooth16(int *indexliste)
|
||||
{ /* Implements rules from ISO 15417 Annex E */
|
||||
/* Implements rules from ISO 15417 Annex E */
|
||||
void dxsmooth16(int *indexliste) {
|
||||
int i, current, last, next, length;
|
||||
|
||||
for(i = 0; i < *(indexliste); i++) {
|
||||
for (i = 0; i < *(indexliste); i++) {
|
||||
current = list[1][i];
|
||||
length = list[0][i];
|
||||
if(i != 0) { last = list[1][i - 1]; } else { last = FALSE; }
|
||||
if(i != *(indexliste) - 1) { next = list[1][i + 1]; } else { next = FALSE; }
|
||||
|
||||
if(i == 0) { /* first block */
|
||||
if((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) { /* Rule 1a */ list[1][i] = LATCHC; }
|
||||
if(current == ABORC) {
|
||||
if(length >= 4) {/* Rule 1b */ list[1][i] = LATCHC; } else { list[1][i] = AORB; current = AORB; }
|
||||
}
|
||||
if(current == SHIFTA) { /* Rule 1c */ list[1][i] = LATCHA; }
|
||||
if((current == AORB) && (next == SHIFTA)) { /* Rule 1c */ list[1][i] = LATCHA; current = LATCHA; }
|
||||
if(current == AORB) { /* Rule 1d */ list[1][i] = LATCHB; }
|
||||
if (i != 0) {
|
||||
last = list[1][i - 1];
|
||||
} else {
|
||||
if((current == ABORC) && (length >= 4)) { /* Rule 3 */ list[1][i] = LATCHC; current = LATCHC; }
|
||||
if(current == ABORC) { list[1][i] = AORB; current = AORB; }
|
||||
if((current == AORB) && (last == LATCHA)) { list[1][i] = LATCHA; current = LATCHA; }
|
||||
if((current == AORB) && (last == LATCHB)) { list[1][i] = LATCHB; current = LATCHB; }
|
||||
if((current == AORB) && (next == SHIFTA)) { list[1][i] = LATCHA; current = LATCHA; }
|
||||
if((current == AORB) && (next == SHIFTB)) { list[1][i] = LATCHB; current = LATCHB; }
|
||||
if(current == AORB) { list[1][i] = LATCHB; current = LATCHB; }
|
||||
if((current == SHIFTA) && (length > 1)) { /* Rule 4 */ list[1][i] = LATCHA; current = LATCHA; }
|
||||
if((current == SHIFTB) && (length > 1)) { /* Rule 5 */ list[1][i] = LATCHB; current = LATCHB; }
|
||||
if((current == SHIFTA) && (last == LATCHA)) { list[1][i] = LATCHA; current = LATCHA; }
|
||||
if((current == SHIFTB) && (last == LATCHB)) { list[1][i] = LATCHB; current = LATCHB; }
|
||||
if((current == SHIFTA) && (last == LATCHC)) { list[1][i] = LATCHA; current = LATCHA; }
|
||||
if((current == SHIFTB) && (last == LATCHC)) { list[1][i] = LATCHB; current = LATCHB; }
|
||||
last = FALSE;
|
||||
}
|
||||
if (i != *(indexliste) - 1) {
|
||||
next = list[1][i + 1];
|
||||
} else {
|
||||
next = FALSE;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
/* first block */
|
||||
if ((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) {
|
||||
/* Rule 1a */
|
||||
list[1][i] = LATCHC;
|
||||
}
|
||||
if (current == ABORC) {
|
||||
if (length >= 4) {
|
||||
/* Rule 1b */
|
||||
list[1][i] = LATCHC;
|
||||
} else {
|
||||
list[1][i] = AORB;
|
||||
current = AORB;
|
||||
}
|
||||
}
|
||||
if (current == SHIFTA) {
|
||||
/* Rule 1c */
|
||||
list[1][i] = LATCHA;
|
||||
}
|
||||
if ((current == AORB) && (next == SHIFTA)) {
|
||||
/* Rule 1c */
|
||||
list[1][i] = LATCHA;
|
||||
current = LATCHA;
|
||||
}
|
||||
if (current == AORB) {
|
||||
/* Rule 1d */
|
||||
list[1][i] = LATCHB;
|
||||
}
|
||||
} else {
|
||||
if ((current == ABORC) && (length >= 4)) {
|
||||
/* Rule 3 */
|
||||
list[1][i] = LATCHC;
|
||||
current = LATCHC;
|
||||
}
|
||||
if (current == ABORC) {
|
||||
list[1][i] = AORB;
|
||||
current = AORB;
|
||||
}
|
||||
if ((current == AORB) && (last == LATCHA)) {
|
||||
list[1][i] = LATCHA;
|
||||
current = LATCHA;
|
||||
}
|
||||
if ((current == AORB) && (last == LATCHB)) {
|
||||
list[1][i] = LATCHB;
|
||||
current = LATCHB;
|
||||
}
|
||||
if ((current == AORB) && (next == SHIFTA)) {
|
||||
list[1][i] = LATCHA;
|
||||
current = LATCHA;
|
||||
}
|
||||
if ((current == AORB) && (next == SHIFTB)) {
|
||||
list[1][i] = LATCHB;
|
||||
current = LATCHB;
|
||||
}
|
||||
if (current == AORB) {
|
||||
list[1][i] = LATCHB;
|
||||
current = LATCHB;
|
||||
}
|
||||
if ((current == SHIFTA) && (length > 1)) {
|
||||
/* Rule 4 */
|
||||
list[1][i] = LATCHA;
|
||||
current = LATCHA;
|
||||
}
|
||||
if ((current == SHIFTB) && (length > 1)) {
|
||||
/* Rule 5 */
|
||||
list[1][i] = LATCHB;
|
||||
current = LATCHB;
|
||||
}
|
||||
if ((current == SHIFTA) && (last == LATCHA)) {
|
||||
list[1][i] = LATCHA;
|
||||
current = LATCHA;
|
||||
}
|
||||
if ((current == SHIFTB) && (last == LATCHB)) {
|
||||
list[1][i] = LATCHB;
|
||||
current = LATCHB;
|
||||
}
|
||||
if ((current == SHIFTA) && (last == LATCHC)) {
|
||||
list[1][i] = LATCHA;
|
||||
current = LATCHA;
|
||||
}
|
||||
if ((current == SHIFTB) && (last == LATCHC)) {
|
||||
list[1][i] = LATCHB;
|
||||
current = LATCHB;
|
||||
}
|
||||
} /* Rule 2 is implimented elsewhere, Rule 6 is implied */
|
||||
}
|
||||
grwp16(indexliste);
|
||||
|
||||
}
|
||||
|
||||
void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars)
|
||||
{
|
||||
if(source > 127) {
|
||||
if(source < 160) {
|
||||
void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars) {
|
||||
if (source > 127) {
|
||||
if (source < 160) {
|
||||
values[(*bar_chars)] = source + 64 - 128;
|
||||
} else {
|
||||
values[(*bar_chars)] = source - 32 - 128;
|
||||
}
|
||||
} else {
|
||||
if(source < 32) {
|
||||
if (source < 32) {
|
||||
values[(*bar_chars)] = source + 64;
|
||||
} else {
|
||||
values[(*bar_chars)] = source - 32;
|
||||
@ -159,9 +237,8 @@ void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_c
|
||||
(*bar_chars)++;
|
||||
}
|
||||
|
||||
void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_chars)
|
||||
{
|
||||
if(source > 127) {
|
||||
void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_chars) {
|
||||
if (source > 127) {
|
||||
values[(*bar_chars)] = source - 32 - 128;
|
||||
} else {
|
||||
values[(*bar_chars)] = source - 32;
|
||||
@ -169,8 +246,7 @@ void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_c
|
||||
(*bar_chars)++;
|
||||
}
|
||||
|
||||
void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars)
|
||||
{
|
||||
void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars) {
|
||||
int weight;
|
||||
|
||||
weight = (10 * ctoi(source_a)) + ctoi(source_b);
|
||||
@ -178,14 +254,13 @@ void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int val
|
||||
(*bar_chars)++;
|
||||
}
|
||||
|
||||
int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
char width_pattern[100];
|
||||
int current_row, rows_needed, flip_flop, looper, first_check, second_check;
|
||||
int indexliste, indexchaine, pads_needed, f_state;
|
||||
char set[160] = { ' ' }, fset[160] = { ' ' }, mode, last_set,current_set;
|
||||
unsigned int i, j, k, m,read, mx_reader, writer;
|
||||
unsigned int values[160] = { 0 };
|
||||
char set[160] = {' '}, fset[160] = {' '}, mode, last_set, current_set;
|
||||
unsigned int i, j, k, m, read, mx_reader, writer;
|
||||
unsigned int values[160] = {0};
|
||||
unsigned int bar_characters;
|
||||
float glyph_count;
|
||||
int errornum, first_sum, second_sum;
|
||||
@ -196,9 +271,13 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(width_pattern, "");
|
||||
input_length = length;
|
||||
|
||||
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }
|
||||
if (symbol->input_mode == GS1_MODE) {
|
||||
gs1 = 1;
|
||||
} else {
|
||||
gs1 = 0;
|
||||
}
|
||||
|
||||
if(input_length > 157) {
|
||||
if (input_length > 157) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
@ -206,22 +285,22 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
bar_characters = 0;
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < input_length; i++) {
|
||||
if(source[i] >=128) {
|
||||
for (i = 0; i < input_length; i++) {
|
||||
if (source[i] >= 128) {
|
||||
fset[i] = 'f';
|
||||
}
|
||||
}
|
||||
fset[i] = '\0';
|
||||
|
||||
/* Decide when to latch to extended mode */
|
||||
for(i = 0; i < input_length; i++) {
|
||||
for (i = 0; i < input_length; i++) {
|
||||
j = 0;
|
||||
if(fset[i] == 'f') {
|
||||
if (fset[i] == 'f') {
|
||||
do {
|
||||
j++;
|
||||
} while(fset[i + j] == 'f');
|
||||
if((j >= 5) || ((j >= 3) && ((i + j) == (input_length - 1)))) {
|
||||
for(k = 0; k <= j; k++) {
|
||||
} while (fset[i + j] == 'f');
|
||||
if ((j >= 5) || ((j >= 3) && ((i + j) == (input_length - 1)))) {
|
||||
for (k = 0; k <= j; k++) {
|
||||
fset[i + k] = 'F';
|
||||
}
|
||||
}
|
||||
@ -229,14 +308,14 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Decide if it is worth reverting to 646 encodation for a few characters */
|
||||
if(input_length > 1) {
|
||||
for(i = 1; i < input_length; i++) {
|
||||
if((fset[i - 1] == 'F') && (fset[i] == ' ')) {
|
||||
if (input_length > 1) {
|
||||
for (i = 1; i < input_length; i++) {
|
||||
if ((fset[i - 1] == 'F') && (fset[i] == ' ')) {
|
||||
/* Detected a change from 8859-1 to 646 - count how long for */
|
||||
for(j = 0; (fset[i + j] == ' ') && ((i + j) < input_length); j++);
|
||||
if((j < 5) || ((j < 3) && ((i + j) == (input_length - 1)))) {
|
||||
for (j = 0; (fset[i + j] == ' ') && ((i + j) < input_length); j++);
|
||||
if ((j < 5) || ((j < 3) && ((i + j) == (input_length - 1)))) {
|
||||
/* Change to shifting back rather than latching back */
|
||||
for(k = 0; k < j; k++) {
|
||||
for (k = 0; k < j; k++) {
|
||||
fset[i + k] = 'n';
|
||||
}
|
||||
}
|
||||
@ -248,9 +327,11 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
indexchaine = 0;
|
||||
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */
|
||||
if ((gs1) && (source[indexchaine] == '[')) {
|
||||
mode = ABORC;
|
||||
} /* FNC1 */
|
||||
|
||||
for(i = 0; i < 160; i++) {
|
||||
for (i = 0; i < 160; i++) {
|
||||
list[0][i] = 0;
|
||||
}
|
||||
|
||||
@ -260,7 +341,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
list[0][indexliste]++;
|
||||
indexchaine++;
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */
|
||||
if ((gs1) && (source[indexchaine] == '[')) {
|
||||
mode = ABORC;
|
||||
} /* FNC1 */
|
||||
}
|
||||
indexliste++;
|
||||
} while (indexchaine < input_length);
|
||||
@ -269,21 +352,26 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Put set data into set[] */
|
||||
read = 0;
|
||||
for(i = 0; i < indexliste; i++) {
|
||||
for(j = 0; j < list[0][i]; j++) {
|
||||
switch(list[1][i]) {
|
||||
case SHIFTA: set[read] = 'a'; break;
|
||||
case LATCHA: set[read] = 'A'; break;
|
||||
case SHIFTB: set[read] = 'b'; break;
|
||||
case LATCHB: set[read] = 'B'; break;
|
||||
case LATCHC: set[read] = 'C'; break;
|
||||
for (i = 0; i < indexliste; i++) {
|
||||
for (j = 0; j < list[0][i]; j++) {
|
||||
switch (list[1][i]) {
|
||||
case SHIFTA: set[read] = 'a';
|
||||
break;
|
||||
case LATCHA: set[read] = 'A';
|
||||
break;
|
||||
case SHIFTB: set[read] = 'b';
|
||||
break;
|
||||
case LATCHB: set[read] = 'B';
|
||||
break;
|
||||
case LATCHC: set[read] = 'C';
|
||||
break;
|
||||
}
|
||||
read++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust for strings which start with shift characters - make them latch instead */
|
||||
if(set[0] == 'a') {
|
||||
if (set[0] == 'a') {
|
||||
i = 0;
|
||||
do {
|
||||
set[i] = 'A';
|
||||
@ -291,7 +379,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
} while (set[i] == 'a');
|
||||
}
|
||||
|
||||
if(set[0] == 'b') {
|
||||
if (set[0] == 'b') {
|
||||
i = 0;
|
||||
do {
|
||||
set[i] = 'B';
|
||||
@ -301,11 +389,11 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Watch out for odd-length Mode C blocks */
|
||||
c_count = 0;
|
||||
for(i = 0; i < read; i++) {
|
||||
if(set[i] == 'C') {
|
||||
if(source[i] == '[') {
|
||||
if(c_count & 1) {
|
||||
if((i - c_count) != 0) {
|
||||
for (i = 0; i < read; i++) {
|
||||
if (set[i] == 'C') {
|
||||
if (source[i] == '[') {
|
||||
if (c_count & 1) {
|
||||
if ((i - c_count) != 0) {
|
||||
set[i - c_count] = 'B';
|
||||
} else {
|
||||
set[i - 1] = 'B';
|
||||
@ -316,8 +404,8 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
c_count++;
|
||||
}
|
||||
} else {
|
||||
if(c_count & 1) {
|
||||
if((i - c_count) != 0) {
|
||||
if (c_count & 1) {
|
||||
if ((i - c_count) != 0) {
|
||||
set[i - c_count] = 'B';
|
||||
} else {
|
||||
set[i - 1] = 'B';
|
||||
@ -326,15 +414,15 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
c_count = 0;
|
||||
}
|
||||
}
|
||||
if(c_count & 1) {
|
||||
if((i - c_count) != 0) {
|
||||
if (c_count & 1) {
|
||||
if ((i - c_count) != 0) {
|
||||
set[i - c_count] = 'B';
|
||||
} else {
|
||||
set[i - 1] = 'B';
|
||||
}
|
||||
}
|
||||
for(i = 1; i < read - 1; i++) {
|
||||
if((set[i] == 'C') && ((set[i - 1] == 'B') && (set[i + 1] == 'B'))) {
|
||||
for (i = 1; i < read - 1; i++) {
|
||||
if ((set[i] == 'C') && ((set[i - 1] == 'B') && (set[i + 1] == 'B'))) {
|
||||
set[i] = 'B';
|
||||
}
|
||||
}
|
||||
@ -342,53 +430,53 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Make sure the data will fit in the symbol */
|
||||
last_set = ' ';
|
||||
glyph_count = 0.0;
|
||||
for(i = 0; i < input_length; i++) {
|
||||
if((set[i] == 'a') || (set[i] == 'b')) {
|
||||
for (i = 0; i < input_length; i++) {
|
||||
if ((set[i] == 'a') || (set[i] == 'b')) {
|
||||
glyph_count = glyph_count + 1.0;
|
||||
}
|
||||
if((fset[i] == 'f') || (fset[i] == 'n')) {
|
||||
if ((fset[i] == 'f') || (fset[i] == 'n')) {
|
||||
glyph_count = glyph_count + 1.0;
|
||||
}
|
||||
if(((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
|
||||
if(set[i] != last_set) {
|
||||
if (((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
|
||||
if (set[i] != last_set) {
|
||||
last_set = set[i];
|
||||
glyph_count = glyph_count + 1.0;
|
||||
}
|
||||
}
|
||||
if(i == 0) {
|
||||
if((set[i] == 'B') && (set[1] == 'C')) {
|
||||
if (i == 0) {
|
||||
if ((set[i] == 'B') && (set[1] == 'C')) {
|
||||
glyph_count = glyph_count - 1.0;
|
||||
}
|
||||
if((set[i] == 'B') && (set[1] == 'B')) {
|
||||
if(set[2] == 'C') {
|
||||
if ((set[i] == 'B') && (set[1] == 'B')) {
|
||||
if (set[2] == 'C') {
|
||||
glyph_count = glyph_count - 1.0;
|
||||
}
|
||||
}
|
||||
if(fset[i] == 'F') {
|
||||
if (fset[i] == 'F') {
|
||||
glyph_count = glyph_count + 2.0;
|
||||
}
|
||||
} else {
|
||||
if((fset[i] == 'F') && (fset[i - 1] != 'F')) {
|
||||
if ((fset[i] == 'F') && (fset[i - 1] != 'F')) {
|
||||
glyph_count = glyph_count + 2.0;
|
||||
}
|
||||
if((fset[i] != 'F') && (fset[i - 1] == 'F')) {
|
||||
if ((fset[i] != 'F') && (fset[i - 1] == 'F')) {
|
||||
glyph_count = glyph_count + 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
if((set[i] == 'C') && (!((gs1) && (source[i] == '[')))) {
|
||||
if ((set[i] == 'C') && (!((gs1) && (source[i] == '[')))) {
|
||||
glyph_count = glyph_count + 0.5;
|
||||
} else {
|
||||
glyph_count = glyph_count + 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if((gs1) && (set[0] != 'A')) {
|
||||
if ((gs1) && (set[0] != 'A')) {
|
||||
/* FNC1 can be integrated with mode character */
|
||||
glyph_count--;
|
||||
}
|
||||
|
||||
if(glyph_count > 77.0) {
|
||||
if (glyph_count > 77.0) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
@ -396,52 +484,68 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Calculate how tall the symbol will be */
|
||||
glyph_count = glyph_count + 2.0;
|
||||
i = glyph_count;
|
||||
rows_needed = (i/5);
|
||||
if(i%5 > 0) { rows_needed++; }
|
||||
rows_needed = (i / 5);
|
||||
if (i % 5 > 0) {
|
||||
rows_needed++;
|
||||
}
|
||||
|
||||
if(rows_needed == 1) {
|
||||
if (rows_needed == 1) {
|
||||
rows_needed = 2;
|
||||
}
|
||||
|
||||
/* start with the mode character - Table 2 */
|
||||
m = 0;
|
||||
switch(set[0]) {
|
||||
case 'A': m = 0; break;
|
||||
case 'B': m = 1; break;
|
||||
case 'C': m = 2; break;
|
||||
switch (set[0]) {
|
||||
case 'A': m = 0;
|
||||
break;
|
||||
case 'B': m = 1;
|
||||
break;
|
||||
case 'C': m = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if(symbol->output_options & READER_INIT) {
|
||||
if(m == 2) { m = 5; }
|
||||
if(gs1) {
|
||||
if (symbol->output_options & READER_INIT) {
|
||||
if (m == 2) {
|
||||
m = 5;
|
||||
}
|
||||
if (gs1) {
|
||||
strcpy(symbol->errtxt, "Cannot use both GS1 mode and Reader Initialisation");
|
||||
return ZINT_ERROR_INVALID_OPTION;
|
||||
} else {
|
||||
if((set[0] == 'B') && (set[1] == 'C')) { m = 6; }
|
||||
if ((set[0] == 'B') && (set[1] == 'C')) {
|
||||
m = 6;
|
||||
}
|
||||
}
|
||||
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
|
||||
values[bar_characters + 1] = 96; /* FNC3 */
|
||||
bar_characters += 2;
|
||||
} else {
|
||||
if(gs1) {
|
||||
if (gs1) {
|
||||
/* Integrate FNC1 */
|
||||
switch(set[0]) {
|
||||
case 'B': m = 3; break;
|
||||
case 'C': m = 4; break;
|
||||
switch (set[0]) {
|
||||
case 'B': m = 3;
|
||||
break;
|
||||
case 'C': m = 4;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if((set[0] == 'B') && (set[1] == 'C')) { m = 5; }
|
||||
if(((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) { m = 6; }
|
||||
if ((set[0] == 'B') && (set[1] == 'C')) {
|
||||
m = 5;
|
||||
}
|
||||
if (((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) {
|
||||
m = 6;
|
||||
}
|
||||
}
|
||||
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
|
||||
bar_characters++;
|
||||
}
|
||||
|
||||
current_set = set[0];
|
||||
f_state = 0; /* f_state remembers if we are in Extended ASCII mode (value 1) or
|
||||
f_state = 0;
|
||||
/* f_state remembers if we are in Extended ASCII mode (value 1) or
|
||||
in ISO/IEC 646 mode (value 0) */
|
||||
if(fset[0] == 'F') {
|
||||
switch(current_set) {
|
||||
if (fset[0] == 'F') {
|
||||
switch (current_set) {
|
||||
case 'A':
|
||||
values[bar_characters] = 101;
|
||||
values[bar_characters + 1] = 101;
|
||||
@ -460,10 +564,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Encode the data */
|
||||
do {
|
||||
|
||||
if((read != 0) && (set[read] != set[read - 1]))
|
||||
{ /* Latch different code set */
|
||||
switch(set[read])
|
||||
{
|
||||
if ((read != 0) && (set[read] != set[read - 1])) {
|
||||
/* Latch different code set */
|
||||
switch (set[read]) {
|
||||
case 'A':
|
||||
values[bar_characters] = 101;
|
||||
bar_characters++;
|
||||
@ -475,8 +578,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
current_set = 'B';
|
||||
break;
|
||||
case 'C':
|
||||
if(!((read == 1) && (set[0] == 'B'))) { /* Not Mode C/Shift B */
|
||||
if(!((read == 2) && ((set[0] == 'B') && (set[1] == 'B')))) {
|
||||
if (!((read == 1) && (set[0] == 'B'))) {
|
||||
/* Not Mode C/Shift B */
|
||||
if (!((read == 2) && ((set[0] == 'B') && (set[1] == 'B')))) {
|
||||
/* Not Mode C/Double Shift B */
|
||||
values[bar_characters] = 99;
|
||||
bar_characters++;
|
||||
@ -486,11 +590,11 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* printf("tp8\n"); */
|
||||
if(read != 0) {
|
||||
if((fset[read] == 'F') && (f_state == 0)) {
|
||||
|
||||
if (read != 0) {
|
||||
if ((fset[read] == 'F') && (f_state == 0)) {
|
||||
/* Latch beginning of extended mode */
|
||||
switch(current_set) {
|
||||
switch (current_set) {
|
||||
case 'A':
|
||||
values[bar_characters] = 101;
|
||||
values[bar_characters + 1] = 101;
|
||||
@ -503,9 +607,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
bar_characters += 2;
|
||||
f_state = 1;
|
||||
}
|
||||
if((fset[read] == ' ') && (f_state == 1)) {
|
||||
if ((fset[read] == ' ') && (f_state == 1)) {
|
||||
/* Latch end of extended mode */
|
||||
switch(current_set) {
|
||||
switch (current_set) {
|
||||
case 'A':
|
||||
values[bar_characters] = 101;
|
||||
values[bar_characters + 1] = 101;
|
||||
@ -520,9 +624,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
|
||||
if((fset[i] == 'f') || (fset[i] == 'n')) {
|
||||
if ((fset[i] == 'f') || (fset[i] == 'n')) {
|
||||
/* Shift extended mode */
|
||||
switch(current_set) {
|
||||
switch (current_set) {
|
||||
case 'A':
|
||||
values[bar_characters] = 101; /* FNC 4 */
|
||||
break;
|
||||
@ -533,15 +637,14 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
bar_characters++;
|
||||
}
|
||||
|
||||
if((set[i] == 'a') || (set[i] == 'b')) {
|
||||
if ((set[i] == 'a') || (set[i] == 'b')) {
|
||||
/* Insert shift character */
|
||||
values[bar_characters] = 98;
|
||||
bar_characters++;
|
||||
}
|
||||
|
||||
if(!((gs1) && (source[read] == '['))) {
|
||||
switch(set[read])
|
||||
{ /* Encode data characters */
|
||||
if (!((gs1) && (source[read] == '['))) {
|
||||
switch (set[read]) { /* Encode data characters */
|
||||
case 'A':
|
||||
case 'a':
|
||||
c16k_set_a(source[read], values, &bar_characters);
|
||||
@ -561,17 +664,16 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
bar_characters++;
|
||||
read++;
|
||||
}
|
||||
/* printf("tp9 read=%d surrent set=%c\n", read, set[read]); */
|
||||
} while (read < ustrlen(source));
|
||||
|
||||
pads_needed = 5 - ((bar_characters + 2) % 5);
|
||||
if(pads_needed == 5) {
|
||||
if (pads_needed == 5) {
|
||||
pads_needed = 0;
|
||||
}
|
||||
if((bar_characters + pads_needed) < 8) {
|
||||
if ((bar_characters + pads_needed) < 8) {
|
||||
pads_needed += 8 - (bar_characters + pads_needed);
|
||||
}
|
||||
for(i = 0; i < pads_needed; i++) {
|
||||
for (i = 0; i < pads_needed; i++) {
|
||||
values[bar_characters] = 106;
|
||||
bar_characters++;
|
||||
}
|
||||
@ -579,10 +681,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Calculate check digits */
|
||||
first_sum = 0;
|
||||
second_sum = 0;
|
||||
for(i = 0; i < bar_characters; i++)
|
||||
{
|
||||
first_sum += (i+2) * values[i];
|
||||
second_sum += (i+1) * values[i];
|
||||
for (i = 0; i < bar_characters; i++) {
|
||||
first_sum += (i + 2) * values[i];
|
||||
second_sum += (i + 1) * values[i];
|
||||
}
|
||||
first_check = first_sum % 107;
|
||||
second_sum += first_check * (bar_characters + 1);
|
||||
@ -591,31 +692,33 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
values[bar_characters + 1] = second_check;
|
||||
bar_characters += 2;
|
||||
|
||||
for(current_row = 0; current_row < rows_needed; current_row++) {
|
||||
for (current_row = 0; current_row < rows_needed; current_row++) {
|
||||
|
||||
strcpy(width_pattern, "");
|
||||
concat(width_pattern, C16KStartStop[C16KStartValues[current_row]]);
|
||||
concat(width_pattern, "1");
|
||||
for(i = 0; i < 5; i++) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
concat(width_pattern, C16KTable[values[(current_row * 5) + i]]);
|
||||
/* printf("[%d] ", values[(current_row * 5) + i]); */
|
||||
|
||||
}
|
||||
concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]);
|
||||
/* printf("\n"); */
|
||||
|
||||
/* Write the information into the symbol */
|
||||
writer = 0;
|
||||
flip_flop = 1;
|
||||
for (mx_reader = 0; mx_reader < strlen(width_pattern); mx_reader++) {
|
||||
for(looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) {
|
||||
if(flip_flop == 1) {
|
||||
for (looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) {
|
||||
if (flip_flop == 1) {
|
||||
set_module(symbol, current_row, writer);
|
||||
writer++; }
|
||||
else {
|
||||
writer++; }
|
||||
writer++;
|
||||
} else {
|
||||
writer++;
|
||||
}
|
||||
}
|
||||
if (flip_flop == 0) {
|
||||
flip_flop = 1;
|
||||
} else {
|
||||
flip_flop = 0;
|
||||
}
|
||||
if(flip_flop == 0) { flip_flop = 1; } else { flip_flop = 0; }
|
||||
}
|
||||
symbol->row_height[current_row] = 10;
|
||||
}
|
||||
|
@ -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 <stdio.h>
|
||||
@ -37,10 +37,10 @@
|
||||
#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 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;
|
||||
@ -50,19 +50,23 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
char pattern[40];
|
||||
int gs1;
|
||||
|
||||
if(length > 81) {
|
||||
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 (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) {
|
||||
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] == '['))
|
||||
if (gs1 && (source[i] == '['))
|
||||
concat(intermediate, "*"); /* FNC1 */
|
||||
else
|
||||
concat(intermediate, c49_table7[source[i]]);
|
||||
@ -72,10 +76,10 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
i = 0;
|
||||
h = strlen(intermediate);
|
||||
do {
|
||||
if((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
|
||||
if ((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
|
||||
/* Numeric data */
|
||||
for(j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++);
|
||||
if(j >= 5) {
|
||||
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;
|
||||
@ -87,8 +91,8 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
block_count = j / 5;
|
||||
block_remain = j % 5;
|
||||
|
||||
for(c = 0; c < block_count; c++) {
|
||||
if((c == block_count - 1) && (block_remain == 2)) {
|
||||
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;
|
||||
@ -134,7 +138,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
|
||||
switch(block_remain) {
|
||||
switch (block_remain) {
|
||||
case 1:
|
||||
/* Rule (a) */
|
||||
codewords[codeword_count] = posn(INSET, intermediate[i]);
|
||||
@ -173,7 +177,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
i += 4;
|
||||
break;
|
||||
}
|
||||
if(i < h) {
|
||||
if (i < h) {
|
||||
/* There is more to add */
|
||||
codewords[codeword_count] = 48; /* Numeric Shift */
|
||||
codeword_count++;
|
||||
@ -188,32 +192,37 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
codeword_count++;
|
||||
i++;
|
||||
}
|
||||
} while(i < h);
|
||||
} 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++) {
|
||||
if (M != 0) {
|
||||
for (i = 0; i < codeword_count; i++) {
|
||||
codewords[i] = codewords[i + 1];
|
||||
}
|
||||
codeword_count--;
|
||||
}
|
||||
|
||||
if(codeword_count > 49) {
|
||||
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) {
|
||||
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 */
|
||||
@ -223,9 +232,9 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
rows++;
|
||||
} while ((rows * 7) < codeword_count);
|
||||
|
||||
if((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
|
||||
if ((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
|
||||
/* Add a row */
|
||||
for(i = 0; i < 7; i++) {
|
||||
for (i = 0; i < 7; i++) {
|
||||
c_grid[rows][i] = 48; /* Pad */
|
||||
}
|
||||
rows++;
|
||||
@ -235,10 +244,10 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
c_grid[rows - 1][6] = (7 * (rows - 2)) + M;
|
||||
|
||||
/* Add row check character */
|
||||
for(i = 0; i < rows - 1; i++) {
|
||||
for (i = 0; i < rows - 1; i++) {
|
||||
int row_sum = 0;
|
||||
|
||||
for(j = 0; j < 7; j++) {
|
||||
for (j = 0; j < 7; j++) {
|
||||
row_sum += c_grid[i][j];
|
||||
}
|
||||
c_grid[i][7] = row_sum % 49;
|
||||
@ -249,8 +258,8 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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++) {
|
||||
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;
|
||||
@ -259,7 +268,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
|
||||
if(rows > 6) {
|
||||
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;
|
||||
@ -283,23 +292,23 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Add last row check character */
|
||||
j = 0;
|
||||
for(i = 0; i < 7; i++) {
|
||||
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 ++) {
|
||||
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++) {
|
||||
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') {
|
||||
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 {
|
||||
|
@ -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.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* This data set taken from ANSI/AIM-BC6-2000, 4th April 2000 */
|
||||
|
||||
|
300
backend/common.c
300
backend/common.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,84 +28,87 @@
|
||||
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>
|
||||
#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++);
|
||||
for (i = 0; data[i]; i++);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void ustrcpy(unsigned char target[],const unsigned char source[]) {
|
||||
/* Local replacement for strcpy() with unsigned char strings */
|
||||
/* Local replacement for strcpy() with unsigned char strings */
|
||||
void ustrcpy(unsigned char target[], const unsigned char source[]) {
|
||||
int i, len;
|
||||
|
||||
len = ustrlen(source);
|
||||
for(i = 0; i < len; i++) {
|
||||
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 */
|
||||
/* 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]; }
|
||||
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 */
|
||||
/* 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]; }
|
||||
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'))
|
||||
/* 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);
|
||||
return (source - 'A' + 10);
|
||||
}
|
||||
|
||||
char itoc(int source)
|
||||
{ /* Converts an integer value to its hexadecimal character */
|
||||
/* Converts an integer value to its hexadecimal character */
|
||||
char itoc(int source) {
|
||||
if ((source >= 0) && (source <= 9)) {
|
||||
return ('0' + source); }
|
||||
else {
|
||||
return ('A' + (source - 10)); }
|
||||
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[] */
|
||||
/* 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'; }
|
||||
source [i] = (source[i] - 'a') + 'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int is_sane(char test_string[], unsigned char source[], int length)
|
||||
{ /* Verifies that a string only uses valid characters */
|
||||
/* Verifies that a string only uses valid characters */
|
||||
int is_sane(char test_string[], unsigned char source[], int length) {
|
||||
unsigned int i, j, latch;
|
||||
unsigned int lt = strlen(test_string);
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
latch = FALSE;
|
||||
for(j = 0; j < lt; j++) {
|
||||
for (j = 0; j < lt; j++) {
|
||||
if (source[i] == test_string[j]) {
|
||||
latch = TRUE;
|
||||
break;
|
||||
@ -119,86 +122,46 @@ int is_sane(char test_string[], unsigned char source[], int length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int posn(char set_string[], char data)
|
||||
{ /* Returns the position of data in set_string */
|
||||
/* Returns the position of data in set_string */
|
||||
int posn(char set_string[], char data) {
|
||||
unsigned int i, n = strlen(set_string);
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) { return i; } }
|
||||
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 */
|
||||
/* 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]); } }
|
||||
}
|
||||
|
||||
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;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) {
|
||||
concat(dest, table[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_module(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
{
|
||||
/* Return true (1) if a module is dark/black, orherwise false (0) */
|
||||
int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) {
|
||||
return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
#if 0
|
||||
int x_char, x_sub;
|
||||
|
||||
|
||||
x_char = x_coord / 7;
|
||||
x_sub = x_coord % 7;
|
||||
|
||||
switch(x_sub) {
|
||||
case 0: symbol->encoded_data[y_coord][x_char] += 0x01; break;
|
||||
case 1: symbol->encoded_data[y_coord][x_char] += 0x02; break;
|
||||
case 2: symbol->encoded_data[y_coord][x_char] += 0x04; break;
|
||||
case 3: symbol->encoded_data[y_coord][x_char] += 0x08; break;
|
||||
case 4: symbol->encoded_data[y_coord][x_char] += 0x10; break;
|
||||
case 5: symbol->encoded_data[y_coord][x_char] += 0x20; break;
|
||||
case 6: symbol->encoded_data[y_coord][x_char] += 0x40; break;
|
||||
} /* The last binary digit is reserved for colour barcodes */
|
||||
#endif
|
||||
}
|
||||
|
||||
void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
{
|
||||
/* Set (or unset) a module to white */
|
||||
void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
|
||||
symbol->encoded_data[y_coord][x_coord / 7] &= ~(1 << (x_coord % 7));
|
||||
#if 0
|
||||
int x_char, x_sub;
|
||||
|
||||
x_char = x_coord / 7;
|
||||
x_sub = x_coord % 7;
|
||||
|
||||
switch(x_sub) {
|
||||
case 0: symbol->encoded_data[y_coord][x_char] -= 0x01; break;
|
||||
case 1: symbol->encoded_data[y_coord][x_char] -= 0x02; break;
|
||||
case 2: symbol->encoded_data[y_coord][x_char] -= 0x04; break;
|
||||
case 3: symbol->encoded_data[y_coord][x_char] -= 0x08; break;
|
||||
case 4: symbol->encoded_data[y_coord][x_char] -= 0x10; break;
|
||||
case 5: symbol->encoded_data[y_coord][x_char] -= 0x20; break;
|
||||
case 6: symbol->encoded_data[y_coord][x_char] -= 0x40; break;
|
||||
} /* The last binary digit is reserved for colour barcodes */
|
||||
#endif
|
||||
}
|
||||
|
||||
void expand(struct zint_symbol *symbol, char data[])
|
||||
{ /* Expands from a width pattern to a bit pattern */
|
||||
/* Expands from a width pattern to a bit pattern */
|
||||
void expand(struct zint_symbol *symbol, char data[]) {
|
||||
|
||||
unsigned int reader, n = strlen(data);
|
||||
int writer, i;
|
||||
@ -207,76 +170,110 @@ void expand(struct zint_symbol *symbol, char data[])
|
||||
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); }
|
||||
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');
|
||||
}
|
||||
|
||||
if(symbol->symbology != BARCODE_PHARMA) {
|
||||
if(writer > symbol->width) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
int roundup(float input)
|
||||
{
|
||||
int roundup(float input) {
|
||||
float remainder;
|
||||
int integer_part;
|
||||
|
||||
integer_part = (int)input;
|
||||
integer_part = (int) input;
|
||||
remainder = input - integer_part;
|
||||
|
||||
if(remainder > 0.1) {
|
||||
if (remainder > 0.1) {
|
||||
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')) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -284,55 +281,56 @@ int istwodigits(unsigned char source[], int position)
|
||||
return 0;
|
||||
}
|
||||
|
||||
float froundup(float input)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length)
|
||||
{
|
||||
/* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
|
||||
int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) {
|
||||
int j, i, next;
|
||||
|
||||
/* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
|
||||
j = 0;
|
||||
i = 0;
|
||||
do {
|
||||
next = -1;
|
||||
if(source[i] < 128) {
|
||||
if (source[i] < 128) {
|
||||
preprocessed[j] = source[i];
|
||||
j++;
|
||||
next = i + 1;
|
||||
} else {
|
||||
if(source[i] == 0xC2) {
|
||||
if (source[i] == 0xC2) {
|
||||
preprocessed[j] = source[i + 1];
|
||||
j++;
|
||||
next = i + 2;
|
||||
}
|
||||
if(source[i] == 0xC3) {
|
||||
if (source[i] == 0xC3) {
|
||||
preprocessed[j] = source[i + 1] + 64;
|
||||
j++;
|
||||
next = i + 2;
|
||||
}
|
||||
}
|
||||
if(next == -1) {
|
||||
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);
|
||||
} while (i < *length);
|
||||
preprocessed[j] = '\0';
|
||||
*length = j;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length)
|
||||
{
|
||||
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) {
|
||||
int bpos, jpos, error_number;
|
||||
int next;
|
||||
|
||||
@ -342,34 +340,34 @@ int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[],
|
||||
next = 0;
|
||||
|
||||
do {
|
||||
if(source[bpos] <= 0x7f) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
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 ++;
|
||||
jpos++;
|
||||
} else
|
||||
if(source[bpos] >= 0xf0) {
|
||||
if (source[bpos] >= 0xf0) {
|
||||
strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
@ -377,7 +375,7 @@ int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[],
|
||||
|
||||
bpos = next;
|
||||
|
||||
} while(bpos < *length);
|
||||
} while (bpos < *length);
|
||||
*length = jpos;
|
||||
|
||||
return error_number;
|
||||
|
@ -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.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* 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 */
|
||||
|
1572
backend/composite.c
1572
backend/composite.c
File diff suppressed because it is too large
Load Diff
@ -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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define NUMERIC 110
|
||||
#define ALPHA 97
|
||||
|
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
|
||||
}
|
||||
@ -65,25 +64,29 @@ 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 };
|
||||
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 };
|
||||
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
|
||||
@ -105,7 +108,8 @@ static const int intsymbol[] = {
|
||||
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
|
||||
};
|
||||
|
||||
// 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
|
||||
@ -237,32 +242,39 @@ static const int intsymbol[] = {
|
||||
|
||||
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 };
|
||||
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 };
|
||||
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 };
|
||||
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 };
|
||||
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 };
|
||||
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 };
|
||||
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 };
|
||||
42, 56, 36, 48, 56, 68, 56, 68, 62, 62
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __IEC16022ECC200_H */
|
||||
#endif
|
||||
|
3316
backend/font.h
3316
backend/font.h
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/* gb2312.h - Unicode to GB 2312-1980 lookup table
|
||||
|
||||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
static const unsigned long int gb2312_lookup[] = {
|
||||
0x00A4, 0xA1E8,
|
||||
|
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
|
||||
@ -47,9 +47,13 @@ static const char shift_set[] = {
|
||||
';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
|
||||
};
|
||||
|
||||
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,
|
||||
@ -67,9 +71,17 @@ static const int gm_data_codewords[] = {
|
||||
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_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 */
|
||||
@ -141,31 +153,31 @@ static const int gm_ebeb[] = {
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
|
152
backend/gs1.c
152
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,8 +43,7 @@
|
||||
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)
|
||||
{
|
||||
void itostr(char ai_string[], int ai_value) {
|
||||
int thou, hund, ten, unit;
|
||||
char temp[2];
|
||||
|
||||
@ -55,8 +54,14 @@ void itostr(char ai_string[], int ai_value)
|
||||
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); }
|
||||
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);
|
||||
@ -64,8 +69,7 @@ void itostr(char ai_string[], int ai_value)
|
||||
concat(ai_string, ")");
|
||||
}
|
||||
|
||||
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[])
|
||||
{
|
||||
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) {
|
||||
int i, j, last_ai, ai_latch;
|
||||
char ai_string[6];
|
||||
int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length;
|
||||
@ -73,18 +77,18 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
int error_latch;
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if(source[i] >=128) {
|
||||
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) {
|
||||
if (source[i] < 32) {
|
||||
strcpy(symbol->errtxt, "Control characters are not supported by GS1");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
if(source[0] != '[') {
|
||||
if (source[0] != '[') {
|
||||
strcpy(symbol->errtxt, "Data does not start with an AI");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
@ -97,54 +101,65 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
min_ai_length = 5;
|
||||
j = 0;
|
||||
ai_latch = 0;
|
||||
for(i = 0; i < src_len; i++) {
|
||||
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] == ']') {
|
||||
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; }
|
||||
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; }
|
||||
if (bracket_level > max_bracket_level) {
|
||||
max_bracket_level = bracket_level;
|
||||
}
|
||||
if (ai_length > max_ai_length) {
|
||||
max_ai_length = ai_length;
|
||||
}
|
||||
}
|
||||
min_ai_length--;
|
||||
|
||||
if(bracket_level != 0) {
|
||||
if (bracket_level != 0) {
|
||||
/* Not all brackets are closed */
|
||||
strcpy(symbol->errtxt, "Malformed AI in input data (brackets don\'t match)");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(max_bracket_level > 1) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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] == '[') {
|
||||
for (i = 1; i < src_len; i++) {
|
||||
if (source[i - 1] == '[') {
|
||||
ai_location[ai_count] = i;
|
||||
j = 0;
|
||||
do {
|
||||
@ -157,10 +172,14 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < ai_count; 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]++; }
|
||||
if (ai_value[i] >= 100) {
|
||||
data_location[i]++;
|
||||
}
|
||||
if (ai_value[i] >= 1000) {
|
||||
data_location[i]++;
|
||||
}
|
||||
data_length[i] = 0;
|
||||
do {
|
||||
data_length[i]++;
|
||||
@ -168,8 +187,8 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
data_length[i]--;
|
||||
}
|
||||
|
||||
for(i = 0; i < ai_count; i++) {
|
||||
if(data_length[i] == 0) {
|
||||
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;
|
||||
@ -178,13 +197,22 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
|
||||
error_latch = 0;
|
||||
strcpy(ai_string, "");
|
||||
for(i = 0; i < ai_count; i++) {
|
||||
for (i = 0; i < ai_count; i++) {
|
||||
switch (ai_value[i]) {
|
||||
case 0: if(data_length[i] != 18) { error_latch = 1; } break;
|
||||
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 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:
|
||||
@ -193,8 +221,14 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
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 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:
|
||||
@ -204,9 +238,10 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
case 42:
|
||||
case 70:
|
||||
case 80:
|
||||
case 81: error_latch = 2; break;
|
||||
case 81: error_latch = 2;
|
||||
break;
|
||||
}
|
||||
if(
|
||||
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))
|
||||
@ -218,23 +253,23 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
) {
|
||||
error_latch = 2;
|
||||
}
|
||||
if((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) {
|
||||
if(data_length[i] != 6) {
|
||||
if ((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) {
|
||||
if (data_length[i] != 6) {
|
||||
error_latch = 1;
|
||||
}
|
||||
}
|
||||
if(
|
||||
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) {
|
||||
if ((ai_value[i] >= 410) && (ai_value[i] <= 415)) {
|
||||
if (data_length[i] != 13) {
|
||||
error_latch = 1;
|
||||
}
|
||||
}
|
||||
if(
|
||||
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))
|
||||
@ -243,20 +278,20 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
) {
|
||||
error_latch = 2;
|
||||
}
|
||||
if((error_latch < 4) && (error_latch > 0)) {
|
||||
if ((error_latch < 4) && (error_latch > 0)) {
|
||||
/* error has just been detected: capture AI */
|
||||
itostr(ai_string, ai_value[i]);
|
||||
error_latch += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if(error_latch == 5) {
|
||||
if (error_latch == 5) {
|
||||
strcpy(symbol->errtxt, "Invalid data length for AI ");
|
||||
concat(symbol->errtxt, ai_string);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(error_latch == 6) {
|
||||
if (error_latch == 6) {
|
||||
strcpy(symbol->errtxt, "Invalid AI value ");
|
||||
concat(symbol->errtxt, ai_string);
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
@ -266,13 +301,13 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
j = 0;
|
||||
last_ai = 0;
|
||||
ai_latch = 1;
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if((source[i] != '[') && (source[i] != ']')) {
|
||||
for (i = 0; i < src_len; i++) {
|
||||
if ((source[i] != '[') && (source[i] != ']')) {
|
||||
reduced[j++] = source[i];
|
||||
}
|
||||
if(source[i] == '[') {
|
||||
if (source[i] == '[') {
|
||||
/* Start of an AI string */
|
||||
if(ai_latch == 0) {
|
||||
if (ai_latch == 0) {
|
||||
reduced[j++] = '[';
|
||||
}
|
||||
ai_string[0] = source[i + 1];
|
||||
@ -282,7 +317,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
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(
|
||||
if (
|
||||
((last_ai >= 0) && (last_ai <= 4))
|
||||
|| ((last_ai >= 11) && (last_ai <= 20))
|
||||
|| (last_ai == 23) /* legacy support - see 5.3.8.2.2 */
|
||||
@ -300,21 +335,22 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[])
|
||||
{
|
||||
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]) {
|
||||
/* Only to keep the compiler happy */
|
||||
#ifndef _MSC_VER
|
||||
char temp[src_len + 5];
|
||||
#else
|
||||
char* temp = (char*)_alloca(src_len + 5);
|
||||
char* temp = (char*) _alloca(src_len + 5);
|
||||
#endif
|
||||
int error_number;
|
||||
|
||||
error_number = gs1_verify(symbol, source, src_len, temp);
|
||||
if(error_number != 0) { return error_number; }
|
||||
if (error_number != 0) {
|
||||
return error_number;
|
||||
}
|
||||
|
||||
if (strlen(temp) < src_len + 5) {
|
||||
ustrcpy(reduced, (unsigned char*)temp);
|
||||
ustrcpy(reduced, (unsigned char*) temp);
|
||||
return 0;
|
||||
}
|
||||
strcpy(symbol->errtxt, "ugs1_verify overflow");
|
||||
|
@ -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.
|
||||
*/
|
||||
*/
|
||||
#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