Code format and audit, part 2

Update copyright info, remove unused code, etc.
This commit is contained in:
Robin Stuart 2016-02-20 10:50:15 +00:00
parent 77cdf77690
commit 8a88ffdd7b
14 changed files with 5878 additions and 5631 deletions

View File

@ -1366,7 +1366,6 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length) {
} }
binary_load(elreg, (char *) source, length); binary_load(elreg, (char *) source, length);
hex_dump(elreg);
for (i = 0; i < 15; i++) { for (i = 0; i < 15; i++) {
data[i] = 0; data[i] = 0;

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -56,7 +56,8 @@ static const short int BCD[40] = {
/* The following lookup tables were generated using the code in Appendix C */ /* The following lookup tables were generated using the code in Appendix C */
static const unsigned short AppxD_I[1287] = { /* Appendix D Table 1 - 5 of 13 characters */ static const unsigned short AppxD_I[1287] = {
/* Appendix D Table 1 - 5 of 13 characters */
0x001F, 0x1F00, 0x002F, 0x1E80, 0x0037, 0x1D80, 0x003B, 0x1B80, 0x003D, 0x1780, 0x001F, 0x1F00, 0x002F, 0x1E80, 0x0037, 0x1D80, 0x003B, 0x1B80, 0x003D, 0x1780,
0x003E, 0x0F80, 0x004F, 0x1E40, 0x0057, 0x1D40, 0x005B, 0x1B40, 0x005D, 0x1740, 0x003E, 0x0F80, 0x004F, 0x1E40, 0x0057, 0x1D40, 0x005B, 0x1B40, 0x005D, 0x1740,
0x005E, 0x0F40, 0x0067, 0x1CC0, 0x006B, 0x1AC0, 0x006D, 0x16C0, 0x006E, 0x0EC0, 0x005E, 0x0F40, 0x0067, 0x1CC0, 0x006B, 0x1AC0, 0x006D, 0x16C0, 0x006E, 0x0EC0,
@ -185,9 +186,11 @@ static const unsigned short AppxD_I[1287] = { /* Appendix D Table 1 - 5 of 13 ch
0x1415, 0x1505, 0x1423, 0x1885, 0x1425, 0x1485, 0x1443, 0x1845, 0x1483, 0x1825, 0x1415, 0x1505, 0x1423, 0x1885, 0x1425, 0x1485, 0x1443, 0x1845, 0x1483, 0x1825,
0x1503, 0x1815, 0x1603, 0x180D, 0x1807, 0x1C03, 0x180B, 0x1A03, 0x1813, 0x1903, 0x1503, 0x1815, 0x1603, 0x180D, 0x1807, 0x1C03, 0x180B, 0x1A03, 0x1813, 0x1903,
0x1823, 0x1883, 0x1843, 0x1445, 0x1249, 0x1151, 0x10E1, 0x0C46, 0x0A4A, 0x0952, 0x1823, 0x1883, 0x1843, 0x1445, 0x1249, 0x1151, 0x10E1, 0x0C46, 0x0A4A, 0x0952,
0x08E2, 0x064C, 0x0554, 0x04E4, 0x0358, 0x02E8, 0x01F0 }; 0x08E2, 0x064C, 0x0554, 0x04E4, 0x0358, 0x02E8, 0x01F0
};
static const unsigned short AppxD_II[78] = { /* Appendix D Table II - 2 of 13 characters */ static const unsigned short AppxD_II[78] = {
/* Appendix D Table II - 2 of 13 characters */
0x0003, 0x1800, 0x0005, 0x1400, 0x0006, 0x0C00, 0x0009, 0x1200, 0x000A, 0x0A00, 0x0003, 0x1800, 0x0005, 0x1400, 0x0006, 0x0C00, 0x0009, 0x1200, 0x000A, 0x0A00,
0x000C, 0x0600, 0x0011, 0x1100, 0x0012, 0x0900, 0x0014, 0x0500, 0x0018, 0x0300, 0x000C, 0x0600, 0x0011, 0x1100, 0x0012, 0x0900, 0x0014, 0x0500, 0x0018, 0x0300,
0x0021, 0x1080, 0x0022, 0x0880, 0x0024, 0x0480, 0x0028, 0x0280, 0x0030, 0x0180, 0x0021, 0x1080, 0x0022, 0x0880, 0x0024, 0x0480, 0x0028, 0x0280, 0x0030, 0x0180,
@ -195,15 +198,18 @@ static const unsigned short AppxD_II[78] = { /* Appendix D Table II - 2 of 13 ch
0x0060, 0x00C0, 0x0081, 0x1020, 0x0082, 0x0820, 0x0084, 0x0420, 0x0088, 0x0220, 0x0060, 0x00C0, 0x0081, 0x1020, 0x0082, 0x0820, 0x0084, 0x0420, 0x0088, 0x0220,
0x0090, 0x0120, 0x0101, 0x1010, 0x0102, 0x0810, 0x0104, 0x0410, 0x0108, 0x0210, 0x0090, 0x0120, 0x0101, 0x1010, 0x0102, 0x0810, 0x0104, 0x0410, 0x0108, 0x0210,
0x0201, 0x1008, 0x0202, 0x0808, 0x0204, 0x0408, 0x0401, 0x1004, 0x0402, 0x0804, 0x0201, 0x1008, 0x0202, 0x0808, 0x0204, 0x0408, 0x0401, 0x1004, 0x0402, 0x0804,
0x0801, 0x1002, 0x1001, 0x0802, 0x0404, 0x0208, 0x0110, 0x00A0 }; 0x0801, 0x1002, 0x1001, 0x0802, 0x0404, 0x0208, 0x0110, 0x00A0
};
static const int AppxD_IV[130] = { /* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */ static const int AppxD_IV[130] = {
/* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */
67, 6, 78, 16, 86, 95, 34, 40, 45, 113, 117, 121, 62, 87, 18, 104, 41, 76, 57, 119, 115, 72, 97, 67, 6, 78, 16, 86, 95, 34, 40, 45, 113, 117, 121, 62, 87, 18, 104, 41, 76, 57, 119, 115, 72, 97,
2, 127, 26, 105, 35, 122, 52, 114, 7, 24, 82, 68, 63, 94, 44, 77, 112, 70, 100, 39, 30, 107, 2, 127, 26, 105, 35, 122, 52, 114, 7, 24, 82, 68, 63, 94, 44, 77, 112, 70, 100, 39, 30, 107,
15, 125, 85, 10, 65, 54, 88, 20, 106, 46, 66, 8, 116, 29, 61, 99, 80, 90, 37, 123, 51, 25, 84, 15, 125, 85, 10, 65, 54, 88, 20, 106, 46, 66, 8, 116, 29, 61, 99, 80, 90, 37, 123, 51, 25, 84,
129, 56, 4, 109, 96, 28, 36, 47, 11, 71, 33, 102, 21, 9, 17, 49, 124, 79, 64, 91, 42, 69, 53, 129, 56, 4, 109, 96, 28, 36, 47, 11, 71, 33, 102, 21, 9, 17, 49, 124, 79, 64, 91, 42, 69, 53,
60, 14, 1, 27, 103, 126, 75, 89, 50, 120, 19, 32, 110, 92, 111, 130, 59, 31, 12, 81, 43, 55, 60, 14, 1, 27, 103, 126, 75, 89, 50, 120, 19, 32, 110, 92, 111, 130, 59, 31, 12, 81, 43, 55,
5, 74, 22, 101, 128, 58, 118, 48, 108, 38, 98, 93, 23, 83, 13, 73, 3 }; 5, 74, 22, 101, 128, 58, 118, 48, 108, 38, 98, 93, 23, 83, 13, 73, 3
};
/*************************************************************************** /***************************************************************************
** USPS_MSB_Math_CRC11GenerateFrameCheckSequence ** USPS_MSB_Math_CRC11GenerateFrameCheckSequence
@ -216,10 +222,7 @@ static const int AppxD_IV[130] = { /* Appendix D Table IV - Bar-to-Character Map
** Outputs: ** Outputs:
** return unsigned short - 11 bit Frame Check Sequence (right justified) ** return unsigned short - 11 bit Frame Check Sequence (right justified)
***************************************************************************/ ***************************************************************************/
extern unsigned short extern unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned char *ByteArrayPtr) {
USPS_MSB_Math_CRC11GenerateFrameCheckSequence( unsigned char *ByteArrayPtr )
{
unsigned short GeneratorPolynomial = 0x0F35; unsigned short GeneratorPolynomial = 0x0F35;
unsigned short FrameCheckSequence = 0x07FF; unsigned short FrameCheckSequence = 0x07FF;
unsigned short Data; unsigned short Data;
@ -228,8 +231,7 @@ extern unsigned short
/* Do most significant byte skipping the 2 most significant bits */ /* Do most significant byte skipping the 2 most significant bits */
Data = *ByteArrayPtr << 5; Data = *ByteArrayPtr << 5;
ByteArrayPtr++; ByteArrayPtr++;
for ( Bit = 2; Bit < 8; Bit++ ) for (Bit = 2; Bit < 8; Bit++) {
{
if ((FrameCheckSequence ^ Data) & 0x400) if ((FrameCheckSequence ^ Data) & 0x400)
FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial;
else else
@ -238,12 +240,10 @@ extern unsigned short
Data <<= 1; Data <<= 1;
} }
/* Do rest of the bytes */ /* Do rest of the bytes */
for ( ByteIndex = 1; ByteIndex < 13; ByteIndex++ ) for (ByteIndex = 1; ByteIndex < 13; ByteIndex++) {
{
Data = *ByteArrayPtr << 3; Data = *ByteArrayPtr << 3;
ByteArrayPtr++; ByteArrayPtr++;
for ( Bit = 0; Bit < 8; Bit++ ) for (Bit = 0; Bit < 8; Bit++) {
{
if ((FrameCheckSequence ^ Data) & 0x0400) { if ((FrameCheckSequence ^ Data) & 0x0400) {
FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial; FrameCheckSequence = (FrameCheckSequence << 1) ^ GeneratorPolynomial;
} else { } else {
@ -256,8 +256,7 @@ extern unsigned short
return FrameCheckSequence; return FrameCheckSequence;
} }
void breakup(short int fcs_bit[], unsigned short usps_crc) void breakup(short int fcs_bit[], unsigned short usps_crc) {
{
int i; int i;
for (i = 0; i < 13; i++) { for (i = 0; i < 13; i++) {
@ -317,8 +316,7 @@ void breakup(short int fcs_bit[], unsigned short usps_crc)
} }
} }
int imail(struct zint_symbol *symbol, unsigned char source[], int length) int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
{
char data_pattern[200]; char data_pattern[200];
int error_number; int error_number;
int i, j, read; int i, j, read;
@ -522,9 +520,6 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
binary_add(accum, y_reg); binary_add(accum, y_reg);
} }
/* printf("Binary data 1: ");
hex_dump(accum); */
/* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */ /* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */
accum[103] = 0; accum[103] = 0;
@ -545,7 +540,6 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
} }
usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array); usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array);
/* printf("FCS 2: %4.4X\n", usps_crc); */
/* *** Step 3 - Conversion from Binary Data to Codewords *** */ /* *** Step 3 - Conversion from Binary Data to Codewords *** */
@ -614,12 +608,6 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
/* printf("Codewords 3: ");
for(i = 0; i < 10; i++) {
printf("%d ", codeword[i]);
}
printf("\n"); */
/* *** Step 4 - Inserting Additional Information into Codewords *** */ /* *** Step 4 - Inserting Additional Information into Codewords *** */
codeword[9] = codeword[9] * 2; codeword[9] = codeword[9] * 2;
@ -628,12 +616,6 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
codeword[0] += 659; codeword[0] += 659;
} }
/* printf("Codewords 4b: ");
for(i = 0; i < 10; i++) {
printf("%d ", codeword[i]);
}
printf("\n"); */
/* *** Step 5 - Conversion from Codewords to Characters *** */ /* *** Step 5 - Conversion from Codewords to Characters *** */
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
@ -644,12 +626,6 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
/* printf("Characters 5a: ");
for(i = 0; i < 10; i++) {
printf("%4.4X ", characters[i]);
}
printf("\n"); */
breakup(bit_pattern, usps_crc); breakup(bit_pattern, usps_crc);
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
@ -658,12 +634,6 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
/* printf("Characters 5b: ");
for(i = 0; i < 10; i++) {
printf("%4.4X ", characters[i]);
}
printf("\n"); */
/* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */ /* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
@ -687,15 +657,12 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
/* Translate 4-state data pattern to symbol */ /* Translate 4-state data pattern to symbol */
read = 0; read = 0;
for(i = 0; i < strlen(data_pattern); i++) for (i = 0; i < strlen(data_pattern); i++) {
{ if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) {
if((data_pattern[i] == '1') || (data_pattern[i] == '0'))
{
set_module(symbol, 0, read); set_module(symbol, 0, read);
} }
set_module(symbol, 1, read); set_module(symbol, 1, read);
if((data_pattern[i] == '2') || (data_pattern[i] == '0')) if ((data_pattern[i] == '2') || (data_pattern[i] == '0')) {
{
set_module(symbol, 2, read); set_module(symbol, 2, read);
} }
read += 2; read += 2;

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -45,51 +45,59 @@ static const short int BCD[40] = {
0, 1, 1, 0, 0, 1, 1, 0,
1, 1, 1, 0, 1, 1, 1, 0,
0, 0, 0, 1, 0, 0, 0, 1,
1, 0, 0, 1 }; 1, 0, 0, 1
};
void binary_add(short int accumulator[], short int input_buffer[]) void binary_add(short int accumulator[], short int input_buffer[]) { /* Binary addition */
{ /* Binary addition */
int i, carry, done; int i, carry, done;
carry = 0; carry = 0;
for (i = 0; i < 112; i++) { for (i = 0; i < 112; i++) {
done = 0; done = 0;
if(((input_buffer[i] == 0) && (accumulator[i] == 0)) && ((carry == 0) && (done == 0))) { if (((input_buffer[i] == 0) && (accumulator[i] == 0))
&& ((carry == 0) && (done == 0))) {
accumulator[i] = 0; accumulator[i] = 0;
carry = 0; carry = 0;
done = 1; done = 1;
} }
if(((input_buffer[i] == 0) && (accumulator[i] == 0)) && ((carry == 1) && (done == 0))) { if (((input_buffer[i] == 0) && (accumulator[i] == 0))
&& ((carry == 1) && (done == 0))) {
accumulator[i] = 1; accumulator[i] = 1;
carry = 0; carry = 0;
done = 1; done = 1;
} }
if(((input_buffer[i] == 0) && (accumulator[i] == 1)) && ((carry == 0) && (done == 0))) { if (((input_buffer[i] == 0) && (accumulator[i] == 1))
&& ((carry == 0) && (done == 0))) {
accumulator[i] = 1; accumulator[i] = 1;
carry = 0; carry = 0;
done = 1; done = 1;
} }
if(((input_buffer[i] == 0) && (accumulator[i] == 1)) && ((carry == 1) && (done == 0))) { if (((input_buffer[i] == 0) && (accumulator[i] == 1))
&& ((carry == 1) && (done == 0))) {
accumulator[i] = 0; accumulator[i] = 0;
carry = 1; carry = 1;
done = 1; done = 1;
} }
if(((input_buffer[i] == 1) && (accumulator[i] == 0)) && ((carry == 0) && (done == 0))) { if (((input_buffer[i] == 1) && (accumulator[i] == 0))
&& ((carry == 0) && (done == 0))) {
accumulator[i] = 1; accumulator[i] = 1;
carry = 0; carry = 0;
done = 1; done = 1;
} }
if(((input_buffer[i] == 1) && (accumulator[i] == 0)) && ((carry == 1) && (done == 0))) { if (((input_buffer[i] == 1) && (accumulator[i] == 0))
&& ((carry == 1) && (done == 0))) {
accumulator[i] = 0; accumulator[i] = 0;
carry = 1; carry = 1;
done = 1; done = 1;
} }
if(((input_buffer[i] == 1) && (accumulator[i] == 1)) && ((carry == 0) && (done == 0))) { if (((input_buffer[i] == 1) && (accumulator[i] == 1))
&& ((carry == 0) && (done == 0))) {
accumulator[i] = 0; accumulator[i] = 0;
carry = 1; carry = 1;
done = 1; done = 1;
} }
if(((input_buffer[i] == 1) && (accumulator[i] == 1)) && ((carry == 1) && (done == 0))) { if (((input_buffer[i] == 1) && (accumulator[i] == 1))
&& ((carry == 1) && (done == 0))) {
accumulator[i] = 1; accumulator[i] = 1;
carry = 1; carry = 1;
done = 1; done = 1;
@ -97,8 +105,8 @@ void binary_add(short int accumulator[], short int input_buffer[])
} }
} }
void binary_subtract(short int accumulator[], short int input_buffer[]) void binary_subtract(short int accumulator[], short int input_buffer[]) {
{ /* 2's compliment subtraction */ /* 2's compliment subtraction */
/* take input_buffer from accumulator and put answer in accumulator */ /* take input_buffer from accumulator and put answer in accumulator */
int i; int i;
short int sub_buffer[112]; short int sub_buffer[112];
@ -120,8 +128,7 @@ void binary_subtract(short int accumulator[], short int input_buffer[])
binary_add(accumulator, sub_buffer); binary_add(accumulator, sub_buffer);
} }
void shiftdown(short int buffer[]) void shiftdown(short int buffer[]) {
{
int i; int i;
buffer[102] = 0; buffer[102] = 0;
@ -132,8 +139,7 @@ void shiftdown(short int buffer[])
} }
} }
void shiftup(short int buffer[]) void shiftup(short int buffer[]) {
{
int i; int i;
for (i = 102; i > 0; i--) { for (i = 102; i > 0; i--) {
@ -143,8 +149,7 @@ void shiftup(short int buffer[])
buffer[0] = 0; buffer[0] = 0;
} }
short int islarger(short int accum[], short int reg[]) short int islarger(short int accum[], short int reg[]) {
{
/* Returns 1 if accum[] is larger than reg[], else 0 */ /* Returns 1 if accum[] is larger than reg[], else 0 */
int i, latch, larger; int i, latch, larger;
latch = 0; latch = 0;
@ -166,8 +171,7 @@ short int islarger(short int accum[], short int reg[])
return larger; return larger;
} }
void binary_load(short int reg[], char data[], const unsigned int src_len) void binary_load(short int reg[], char data[], const unsigned int src_len) {
{
int read, i; int read, i;
short int temp[112] = {0}; short int temp[112] = {0};
@ -197,42 +201,3 @@ void binary_load(short int reg[], char data[], const unsigned int src_len)
} }
} }
void hex_dump(short int input_buffer[])
{
int i, digit, byte_space;
byte_space = 1;
for(i = 100; i >= 0; i-=4) {
digit = 0;
digit += 1 * input_buffer[i];
digit += 2 * input_buffer[i + 1];
digit += 4 * input_buffer[i + 2];
digit += 8 * input_buffer[i + 3];
switch(digit) {
case 0: printf("0"); break;
case 1: printf("1"); break;
case 2: printf("2"); break;
case 3: printf("3"); break;
case 4: printf("4"); break;
case 5: printf("5"); break;
case 6: printf("6"); break;
case 7: printf("7"); break;
case 8: printf("8"); break;
case 9: printf("9"); break;
case 10: printf("A"); break;
case 11: printf("B"); break;
case 12: printf("C"); break;
case 13: printf("D"); break;
case 14: printf("E"); break;
case 15: printf("F"); break;
}
if(byte_space == 1) {
byte_space = 0;
} else {
byte_space = 1;
printf(" ");
}
}
printf("\n");
}

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -42,7 +42,6 @@ extern void binary_subtract(short int accumulator[], short int input_buffer[]);
extern void shiftdown(short int buffer[]); extern void shiftdown(short int buffer[]);
extern void shiftup(short int buffer[]); extern void shiftup(short int buffer[]);
extern short int islarger(short int accum[], short int reg[]); extern short int islarger(short int accum[], short int reg[]);
extern void hex_dump(short int input_buffer[]);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,7 +1,7 @@
/* library.c - external functions of libzint /* library.c - external functions of libzint
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -41,8 +41,7 @@
#define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" #define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
struct zint_symbol *ZBarcode_Create() struct zint_symbol *ZBarcode_Create() {
{
struct zint_symbol *symbol; struct zint_symbol *symbol;
int i; int i;
@ -77,8 +76,7 @@ struct zint_symbol *ZBarcode_Create()
return symbol; return symbol;
} }
void ZBarcode_Clear(struct zint_symbol *symbol) void ZBarcode_Clear(struct zint_symbol *symbol) {
{
int i, j; int i, j;
for (i = 0; i < symbol->rows; i++) { for (i = 0; i < symbol->rows; i++) {
@ -90,8 +88,7 @@ void ZBarcode_Clear(struct zint_symbol *symbol)
symbol->width = 0; symbol->width = 0;
memset(symbol->text, 0, 128); memset(symbol->text, 0, 128);
symbol->errtxt[0] = '\0'; symbol->errtxt[0] = '\0';
if (symbol->bitmap != NULL) if (symbol->bitmap != NULL) {
{
free(symbol->bitmap); free(symbol->bitmap);
symbol->bitmap = NULL; symbol->bitmap = NULL;
} }
@ -99,8 +96,7 @@ void ZBarcode_Clear(struct zint_symbol *symbol)
symbol->bitmap_height = 0; symbol->bitmap_height = 0;
} }
void ZBarcode_Delete(struct zint_symbol *symbol) void ZBarcode_Delete(struct zint_symbol *symbol) {
{
if (symbol->bitmap != NULL) if (symbol->bitmap != NULL)
free(symbol->bitmap); free(symbol->bitmap);
@ -196,8 +192,7 @@ extern int bmp_handle(struct zint_symbol *symbol, int rotate_angle);
extern int ps_plot(struct zint_symbol *symbol); extern int ps_plot(struct zint_symbol *symbol);
extern int svg_plot(struct zint_symbol *symbol); extern int svg_plot(struct zint_symbol *symbol);
void error_tag(char error_string[], int error_number) void error_tag(char error_string[], int error_number) {
{
char error_buffer[100]; char error_buffer[100];
if (error_number != 0) { if (error_number != 0) {
@ -213,9 +208,8 @@ void error_tag(char error_string[], int error_number)
} }
} }
int dump_plot(struct zint_symbol *symbol)
{
/* Output a hexadecimal representation of the rendered symbol */ /* Output a hexadecimal representation of the rendered symbol */
int dump_plot(struct zint_symbol *symbol) {
FILE *f; FILE *f;
int i, r; int i, r;
int byt; int byt;
@ -268,8 +262,8 @@ int dump_plot(struct zint_symbol *symbol)
return 0; return 0;
} }
int hibc(struct zint_symbol *symbol, unsigned char source[], int length) /* Process health industry bar code data */
{ int hibc(struct zint_symbol *symbol, unsigned char source[], int length) {
int counter, error_number, i; int counter, error_number, i;
char to_process[40], temp[2], check_digit; char to_process[40], temp[2], check_digit;
@ -298,14 +292,22 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
check_digit = (counter - 10) + 'A'; check_digit = (counter - 10) + 'A';
} else { } else {
switch (counter) { switch (counter) {
case 36: check_digit = '-'; break; case 36: check_digit = '-';
case 37: check_digit = '.'; break; break;
case 38: check_digit = ' '; break; case 37: check_digit = '.';
case 39: check_digit = '$'; break; break;
case 40: check_digit = '/'; break; case 38: check_digit = ' ';
case 41: check_digit = '+'; break; break;
case 42: check_digit = '%'; break; case 39: check_digit = '$';
default: check_digit = ' '; break; /* Keep compiler happy */ break;
case 40: check_digit = '/';
break;
case 41: check_digit = '+';
break;
case 42: check_digit = '%';
break;
default: check_digit = ' ';
break; /* Keep compiler happy */
} }
} }
} }
@ -351,8 +353,7 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int gs1_compliant(int symbology) int gs1_compliant(int symbology) {
{
/* Returns 1 if symbology supports GS1 data */ /* Returns 1 if symbology supports GS1 data */
int result = 0; int result = 0;
@ -384,8 +385,7 @@ int gs1_compliant(int symbology)
return result; return result;
} }
int ZBarcode_ValidID(int symbol_id) int ZBarcode_ValidID(int symbol_id) {
{
/* Checks whether a symbology is supported */ /* Checks whether a symbology is supported */
int result = 0; int result = 0;
@ -480,22 +480,23 @@ int ZBarcode_ValidID(int symbol_id)
return result; return result;
} }
int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) {
{
int error_number = 0; int error_number = 0;
/* These are the "elite" standards which can support multiple character sets */ /* These are the "elite" standards which can support multiple character sets */
switch (symbol->symbology) { switch (symbol->symbology) {
case BARCODE_QRCODE: error_number = qr_code(symbol, source, length); break; case BARCODE_QRCODE: error_number = qr_code(symbol, source, length);
case BARCODE_MICROQR: error_number = microqr(symbol, source, length); break; break;
case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length); break; case BARCODE_MICROQR: error_number = microqr(symbol, source, length);
break;
case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length);
break;
} }
return error_number; return error_number;
} }
int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) {
{
/* These are the "norm" standards which only support Latin-1 at most */ /* These are the "norm" standards which only support Latin-1 at most */
int error_number = 0; int error_number = 0;
@ -525,97 +526,177 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt
break; break;
case UNICODE_MODE: case UNICODE_MODE:
error_number = latin1_process(symbol, source, preprocessed, &length); error_number = latin1_process(symbol, source, preprocessed, &length);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
break; break;
} }
switch (symbol->symbology) { switch (symbol->symbology) {
case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, length); break; case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, length);
case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length); break; break;
case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length); break; case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length);
case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length); break; break;
case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length); break; case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length);
case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length); break; break;
case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length); break; case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length);
case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, length); break; break;
case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, length); break; case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length);
case BARCODE_EANX: error_number = eanx(symbol, preprocessed, length); break; break;
case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, length); break; case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length);
case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length); break; break;
case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length); break; case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length);
case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length); break; break;
case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length); break; case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, length);
case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length); break; break;
case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length); break; case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, length);
case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, length); break; break;
case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, length); break; case BARCODE_EANX: error_number = eanx(symbol, preprocessed, length);
case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length); break; break;
case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length); break; case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, length);
case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length); break; break;
case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length); break; case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length);
case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length); break; break;
case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length); break; case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length);
case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length); break; break;
case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length); break; case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length);
case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length); break; break;
case BARCODE_FIM: error_number = fim(symbol, preprocessed, length); break; case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length);
case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length); break; break;
case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length); break; case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length);
case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length); break; break;
case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, length); break; case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length);
case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, length); break; break;
case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, length); break; case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, length);
case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, length); break; break;
case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length); break; case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, length);
case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length); break; break;
case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, length); break; case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length);
case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, length); break; break;
case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, length); break; case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length);
case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, length); break; break;
case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, length); break; case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length);
case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, length); break; break;
case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, length); break; case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length);
case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, length); break; break;
case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, length); break; case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length);
case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, length); break; break;
case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, length); break; case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length);
case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, length); break; break;
case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, length); break; case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length);
case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, length); break; break;
case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, length); break; case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length);
case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, length); break; break;
case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, length); break; case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length);
case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, length); break; break;
case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length); break; case BARCODE_FIM: error_number = fim(symbol, preprocessed, length);
case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length); break; break;
case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length); break; case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length);
case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, length); break; break;
case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length); break; case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length);
case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length); break; break;
case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, length); break; case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length);
case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, length); break; break;
case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, length); break; case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, length);
case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, length); break; break;
case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, length); break; case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, length);
case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, length); break; break;
case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, length); break; case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, length);
case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length); break; break;
case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length); break; case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, length);
case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length); break; break;
case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length); break; case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length);
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length); break; break;
case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, length); break; case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length);
case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, length); break; break;
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length); break; case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, length);
case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length); break; break;
case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length); break; case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, length);
break;
case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, length);
break;
case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, length);
break;
case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, length);
break;
case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, length);
break;
case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, length);
break;
case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, length);
break;
case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length);
break;
case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length);
break;
case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length);
break;
case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, length);
break;
case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length);
break;
case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length);
break;
case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length);
break;
case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length);
break;
case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length);
break;
case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length);
break;
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length);
break;
case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, length);
break;
case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, length);
break;
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length);
break;
case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length);
break;
case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length);
break;
} }
return error_number; return error_number;
} }
int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) {
{
int error_number, error_buffer, i; int error_number, error_buffer, i;
#ifdef _MSC_VER #ifdef _MSC_VER
unsigned char* local_source; unsigned char* local_source;
@ -641,43 +722,128 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
#endif #endif
/* First check the symbology field */ /* First check the symbology field */
if(symbol->symbology < 1) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } if (symbol->symbology < 1) {
strcpy(symbol->errtxt, "Symbology out of range, using Code 128");
symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION;
}
/* symbol->symbologys 1 to 86 are defined by tbarcode */ /* symbol->symbologys 1 to 86 are defined by tbarcode */
if(symbol->symbology == 5) { symbol->symbology = BARCODE_C25MATRIX; } if (symbol->symbology == 5) {
if((symbol->symbology >= 10) && (symbol->symbology <= 12)) { symbol->symbology = BARCODE_EANX; } symbol->symbology = BARCODE_C25MATRIX;
if((symbol->symbology == 14) || (symbol->symbology == 15)) { symbol->symbology = BARCODE_EANX; } }
if(symbol->symbology == 17) { symbol->symbology = BARCODE_UPCA; } if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) {
if(symbol->symbology == 19) { strcpy(symbol->errtxt, "Codabar 18 not supported, using Codabar"); symbol->symbology = BARCODE_CODABAR; error_number = ZINT_WARN_INVALID_OPTION; } symbol->symbology = BARCODE_EANX;
if(symbol->symbology == 26) { symbol->symbology = BARCODE_UPCA; } }
if(symbol->symbology == 27) { strcpy(symbol->errtxt, "UPCD1 not supported"); error_number = ZINT_ERROR_INVALID_OPTION; } if ((symbol->symbology == 14) || (symbol->symbology == 15)) {
if(symbol->symbology == 33) { symbol->symbology = BARCODE_EAN128; } symbol->symbology = BARCODE_EANX;
if((symbol->symbology == 35) || (symbol->symbology == 36)) { symbol->symbology = BARCODE_UPCA; } }
if((symbol->symbology == 38) || (symbol->symbology == 39)) { symbol->symbology = BARCODE_UPCE; } if (symbol->symbology == 17) {
if((symbol->symbology >= 41) && (symbol->symbology <= 45)) { symbol->symbology = BARCODE_POSTNET; } symbol->symbology = BARCODE_UPCA;
if(symbol->symbology == 46) { symbol->symbology = BARCODE_PLESSEY; } }
if(symbol->symbology == 48) { symbol->symbology = BARCODE_NVE18; } if (symbol->symbology == 19) {
if(symbol->symbology == 54) { strcpy(symbol->errtxt, "General Parcel Code not supported, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } strcpy(symbol->errtxt, "Codabar 18 not supported, using Codabar");
if((symbol->symbology == 59) || (symbol->symbology == 61)) { symbol->symbology = BARCODE_CODE128; } symbol->symbology = BARCODE_CODABAR;
if(symbol->symbology == 62) { symbol->symbology = BARCODE_CODE93; } error_number = ZINT_WARN_INVALID_OPTION;
if((symbol->symbology == 64) || (symbol->symbology == 65)) { symbol->symbology = BARCODE_AUSPOST; } }
if(symbol->symbology == 73) { strcpy(symbol->errtxt, "Codablock E not supported"); error_number = ZINT_ERROR_INVALID_OPTION; } if (symbol->symbology == 26) {
if(symbol->symbology == 78) { symbol->symbology = BARCODE_RSS14; } symbol->symbology = BARCODE_UPCA;
if(symbol->symbology == 83) { symbol->symbology = BARCODE_PLANET; } }
if(symbol->symbology == 88) { symbol->symbology = BARCODE_EAN128; } if (symbol->symbology == 27) {
if(symbol->symbology == 91) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } strcpy(symbol->errtxt, "UPCD1 not supported");
if((symbol->symbology >= 94) && (symbol->symbology <= 96)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } error_number = ZINT_ERROR_INVALID_OPTION;
if(symbol->symbology == 100) { symbol->symbology = BARCODE_HIBC_128; } }
if(symbol->symbology == 101) { symbol->symbology = BARCODE_HIBC_39; } if (symbol->symbology == 33) {
if(symbol->symbology == 103) { symbol->symbology = BARCODE_HIBC_DM; } symbol->symbology = BARCODE_EAN128;
if(symbol->symbology == 105) { symbol->symbology = BARCODE_HIBC_QR; } }
if(symbol->symbology == 107) { symbol->symbology = BARCODE_HIBC_PDF; } if ((symbol->symbology == 35) || (symbol->symbology == 36)) {
if(symbol->symbology == 109) { symbol->symbology = BARCODE_HIBC_MICPDF; } symbol->symbology = BARCODE_UPCA;
if(symbol->symbology == 111) { symbol->symbology = BARCODE_HIBC_BLOCKF; } }
if((symbol->symbology >= 113) && (symbol->symbology <= 127)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } if ((symbol->symbology == 38) || (symbol->symbology == 39)) {
symbol->symbology = BARCODE_UPCE;
}
if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) {
symbol->symbology = BARCODE_POSTNET;
}
if (symbol->symbology == 46) {
symbol->symbology = BARCODE_PLESSEY;
}
if (symbol->symbology == 48) {
symbol->symbology = BARCODE_NVE18;
}
if (symbol->symbology == 54) {
strcpy(symbol->errtxt, "General Parcel Code not supported, using Code 128");
symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION;
}
if ((symbol->symbology == 59) || (symbol->symbology == 61)) {
symbol->symbology = BARCODE_CODE128;
}
if (symbol->symbology == 62) {
symbol->symbology = BARCODE_CODE93;
}
if ((symbol->symbology == 64) || (symbol->symbology == 65)) {
symbol->symbology = BARCODE_AUSPOST;
}
if (symbol->symbology == 73) {
strcpy(symbol->errtxt, "Codablock E not supported");
error_number = ZINT_ERROR_INVALID_OPTION;
}
if (symbol->symbology == 78) {
symbol->symbology = BARCODE_RSS14;
}
if (symbol->symbology == 83) {
symbol->symbology = BARCODE_PLANET;
}
if (symbol->symbology == 88) {
symbol->symbology = BARCODE_EAN128;
}
if (symbol->symbology == 91) {
strcpy(symbol->errtxt, "Symbology out of range, using Code 128");
symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION;
}
if ((symbol->symbology >= 94) && (symbol->symbology <= 96)) {
strcpy(symbol->errtxt, "Symbology out of range, using Code 128");
symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION;
}
if (symbol->symbology == 100) {
symbol->symbology = BARCODE_HIBC_128;
}
if (symbol->symbology == 101) {
symbol->symbology = BARCODE_HIBC_39;
}
if (symbol->symbology == 103) {
symbol->symbology = BARCODE_HIBC_DM;
}
if (symbol->symbology == 105) {
symbol->symbology = BARCODE_HIBC_QR;
}
if (symbol->symbology == 107) {
symbol->symbology = BARCODE_HIBC_PDF;
}
if (symbol->symbology == 109) {
symbol->symbology = BARCODE_HIBC_MICPDF;
}
if (symbol->symbology == 111) {
symbol->symbology = BARCODE_HIBC_BLOCKF;
}
if ((symbol->symbology >= 113) && (symbol->symbology <= 127)) {
strcpy(symbol->errtxt, "Symbology out of range, using Code 128");
symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION;
}
/* Everything from 128 up is Zint-specific */ /* Everything from 128 up is Zint-specific */
if(symbol->symbology >= 143) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } if (symbol->symbology >= 143) {
if((symbol->symbology == BARCODE_CODABLOCKF) || (symbol->symbology == BARCODE_HIBC_BLOCKF)) { strcpy(symbol->errtxt, "Codablock F not supported"); error_number = ZINT_ERROR_INVALID_OPTION; } strcpy(symbol->errtxt, "Symbology out of range, using Code 128");
symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION;
}
if ((symbol->symbology == BARCODE_CODABLOCKF) || (symbol->symbology == BARCODE_HIBC_BLOCKF)) {
strcpy(symbol->errtxt, "Codablock F not supported");
error_number = ZINT_ERROR_INVALID_OPTION;
}
if (error_number > 4) { if (error_number > 4) {
error_tag(symbol->errtxt, error_number); error_tag(symbol->errtxt, error_number);
@ -686,7 +852,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
error_buffer = error_number; error_buffer = error_number;
} }
if((symbol->input_mode < 0) || (symbol->input_mode > 2)) { symbol->input_mode = DATA_MODE; } if ((symbol->input_mode < 0) || (symbol->input_mode > 2)) {
symbol->input_mode = DATA_MODE;
}
if (symbol->input_mode == GS1_MODE) { if (symbol->input_mode == GS1_MODE) {
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
@ -697,7 +865,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
} }
if (gs1_compliant(symbol->symbology) == 1) { if (gs1_compliant(symbol->symbology) == 1) {
error_number = ugs1_verify(symbol, source, length, local_source); error_number = ugs1_verify(symbol, source, length, local_source);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
length = ustrlen(local_source); length = ustrlen(local_source);
} else { } else {
strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode");
@ -733,12 +903,10 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
error_number = error_buffer; error_number = error_buffer;
} }
error_tag(symbol->errtxt, error_number); error_tag(symbol->errtxt, error_number);
/*printf("%s\n",symbol->text);*/
return error_number; return error_number;
} }
int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) {
{
int error_number; int error_number;
char output[4]; char output[4];
@ -762,7 +930,9 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle)
#ifndef NO_PNG #ifndef NO_PNG
if (!(strcmp(output, "PNG"))) { if (!(strcmp(output, "PNG"))) {
if(symbol->scale < 1.0) { symbol->text[0] = '\0'; } if (symbol->scale < 1.0) {
symbol->text[0] = '\0';
}
error_number = png_handle(symbol, rotate_angle); error_number = png_handle(symbol, rotate_angle);
} else } else
#endif #endif
@ -774,8 +944,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle)
} else } else
if (!(strcmp(output, "SVG"))) { if (!(strcmp(output, "SVG"))) {
error_number = svg_plot(symbol); error_number = svg_plot(symbol);
} else } else {
{
strcpy(symbol->errtxt, "Unknown output format"); strcpy(symbol->errtxt, "Unknown output format");
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION); error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
@ -790,8 +959,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle)
return error_number; return error_number;
} }
int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) {
{
int error_number; int error_number;
switch (rotate_angle) { switch (rotate_angle) {
@ -810,8 +978,7 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle)
return error_number; return error_number;
} }
int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
{
int error_number; int error_number;
error_number = 0; error_number = 0;
@ -825,8 +992,7 @@ int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input,
return error_number; return error_number;
} }
int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
{
int error_number; int error_number;
error_number = 0; error_number = 0;
@ -840,8 +1006,7 @@ int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input,
return error_number; return error_number;
} }
int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
{
FILE *file; FILE *file;
unsigned char *buffer; unsigned char *buffer;
unsigned long fileLen; unsigned long fileLen;
@ -882,11 +1047,9 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
/* Read file contents into buffer */ /* Read file contents into buffer */
do do {
{
n = fread(buffer + nRead, 1, fileLen - nRead, file); n = fread(buffer + nRead, 1, fileLen - nRead, file);
if (ferror(file)) if (ferror(file)) {
{
strcpy(symbol->errtxt, strerror(errno)); strcpy(symbol->errtxt, strerror(errno));
nRead = 0; nRead = 0;
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
@ -900,8 +1063,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
return ret; return ret;
} }
int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) {
{
int error_number; int error_number;
error_number = 0; error_number = 0;
@ -914,8 +1076,7 @@ int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, i
return ZBarcode_Print(symbol, rotate_angle); return ZBarcode_Print(symbol, rotate_angle);
} }
int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle) int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle) {
{
int error_number; int error_number;
error_number = 0; error_number = 0;
@ -938,8 +1099,7 @@ int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename,
* dimensions. The symbol->scale and symbol->height values are totally ignored in this case. * dimensions. The symbol->scale and symbol->height values are totally ignored in this case.
* *
*/ */
int ZBarcode_Render(struct zint_symbol *symbol, float width, float height) int ZBarcode_Render(struct zint_symbol *symbol, float width, float height) {
{
// Send the request to the render_plot method // Send the request to the render_plot method
return render_plot(symbol, width, height); return render_plot(symbol, width, height);
} }

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2010 Robin Stuart <robin@zint.org.uk> Copyright (C) 2010-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -45,9 +45,8 @@
int maxi_codeword[144]; int maxi_codeword[144];
void maxi_do_primary_check( )
{
/* Handles error correction of primary message */ /* Handles error correction of primary message */
void maxi_do_primary_check() {
unsigned char data[15]; unsigned char data[15];
unsigned char results[15]; unsigned char results[15];
int j; int j;
@ -67,9 +66,8 @@ void maxi_do_primary_check( )
rs_free(); rs_free();
} }
void maxi_do_secondary_chk_odd( int ecclen )
{
/* Handles error correction of odd characters in secondary */ /* Handles error correction of odd characters in secondary */
void maxi_do_secondary_chk_odd(int ecclen) {
unsigned char data[100]; unsigned char data[100];
unsigned char results[30]; unsigned char results[30];
int j; int j;
@ -92,9 +90,8 @@ void maxi_do_secondary_chk_odd( int ecclen )
rs_free(); rs_free();
} }
void maxi_do_secondary_chk_even(int ecclen )
{
/* Handles error correction of even characters in secondary */ /* Handles error correction of even characters in secondary */
void maxi_do_secondary_chk_even(int ecclen) {
unsigned char data[100]; unsigned char data[100];
unsigned char results[30]; unsigned char results[30];
int j; int j;
@ -117,9 +114,8 @@ void maxi_do_secondary_chk_even(int ecclen )
rs_free(); rs_free();
} }
void maxi_bump(int set[], int character[], int bump_posn)
{
/* Moves everything up so that a shift or latch can be inserted */ /* Moves everything up so that a shift or latch can be inserted */
void maxi_bump(int set[], int character[], int bump_posn) {
int i; int i;
for (i = 143; i > bump_posn; i--) { for (i = 143; i > bump_posn; i--) {
@ -128,10 +124,8 @@ void maxi_bump(int set[], int character[], int bump_posn)
} }
} }
int maxi_text_process(int mode, unsigned char source[], int length)
{
/* Format text according to Appendix A */ /* Format text according to Appendix A */
int maxi_text_process(int mode, unsigned char source[], int length) {
/* This code doesn't make use of [Lock in C], [Lock in D] /* This code doesn't make use of [Lock in C], [Lock in D]
and [Lock in E] and so is not always the most efficient at and [Lock in E] and so is not always the most efficient at
compressing data, but should suffice for most applications */ compressing data, but should suffice for most applications */
@ -326,7 +320,11 @@ int maxi_text_process(int mode, unsigned char source[], int length)
} }
/* Find candidates for number compression */ /* Find candidates for number compression */
if((mode == 2) || (mode ==3)) { j = 0; } else { j = 9; } if ((mode == 2) || (mode == 3)) {
j = 0;
} else {
j = 9;
}
/* Number compression not allowed in primary message */ /* Number compression not allowed in primary message */
count = 0; count = 0;
for (i = j; i < 143; i++) { for (i = j; i < 143; i++) {
@ -499,9 +497,8 @@ int maxi_text_process(int mode, unsigned char source[], int length)
return 0; return 0;
} }
void maxi_do_primary_2(char postcode[], int country, int service)
{
/* Format structured primary for Mode 2 */ /* Format structured primary for Mode 2 */
void maxi_do_primary_2(char postcode[], int country, int service) {
int postcode_length, postcode_num, i; int postcode_length, postcode_num, i;
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
@ -525,9 +522,8 @@ void maxi_do_primary_2(char postcode[], int country, int service)
maxi_codeword[9] = ((service & 0x3f0) >> 4); maxi_codeword[9] = ((service & 0x3f0) >> 4);
} }
void maxi_do_primary_3(char postcode[], int country, int service)
{
/* Format structured primary for Mode 3 */ /* Format structured primary for Mode 3 */
void maxi_do_primary_3(char postcode[], int country, int service) {
int i, h; int i, h;
h = strlen(postcode); h = strlen(postcode);
@ -557,8 +553,7 @@ void maxi_do_primary_3(char postcode[], int country, int service)
maxi_codeword[9] = ((service & 0x3f0) >> 4); maxi_codeword[9] = ((service & 0x3f0) >> 4);
} }
int maxicode(struct zint_symbol *symbol, unsigned char source[], int length) int maxicode(struct zint_symbol *symbol, unsigned char source[], int length) {
{
int i, j, block, bit, mode, countrycode = 0, service = 0, lp = 0; int i, j, block, bit, mode, countrycode = 0, service = 0, lp = 0;
int bit_pattern[7], internal_error = 0, eclen, error_number; int bit_pattern[7], internal_error = 0, eclen, error_number;
char postcode[12], countrystr[4], servicestr[4]; char postcode[12], countrystr[4], servicestr[4];
@ -583,7 +578,9 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
break; break;
case UNICODE_MODE: case UNICODE_MODE:
error_number = latin1_process(symbol, source, local_source, &length); error_number = latin1_process(symbol, source, local_source, &length);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
break; break;
} }
memset(maxi_codeword, 0, sizeof (maxi_codeword)); memset(maxi_codeword, 0, sizeof (maxi_codeword));
@ -633,8 +630,9 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
postcode[i] = '\0'; postcode[i] = '\0';
} }
} }
} else if (mode == 3) {
postcode[6] = '\0';
} }
else if(mode == 3) { postcode[6] = '\0'; }
countrystr[0] = symbol->primary[9]; countrystr[0] = symbol->primary[9];
countrystr[1] = symbol->primary[10]; countrystr[1] = symbol->primary[10];
@ -649,8 +647,12 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
countrycode = atoi(countrystr); countrycode = atoi(countrystr);
service = atoi(servicestr); service = atoi(servicestr);
if(mode == 2) { maxi_do_primary_2(postcode, countrycode, service); } if (mode == 2) {
if(mode == 3) { maxi_do_primary_3(postcode, countrycode, service); } maxi_do_primary_2(postcode, countrycode, service);
}
if (mode == 3) {
maxi_do_primary_3(postcode, countrycode, service);
}
} else { } else {
maxi_codeword[0] = mode; maxi_codeword[0] = mode;
} }

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -30,7 +30,8 @@
SUCH DAMAGE. SUCH DAMAGE.
*/ */
static const int MaxiGrid[] = { /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence */ /* 30 x 33 data grid */ static const int MaxiGrid[] = {
/* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence */ /* 30 x 33 data grid */
122, 121, 128, 127, 134, 133, 140, 139, 146, 145, 152, 151, 158, 157, 164, 163, 170, 169, 176, 175, 182, 181, 188, 187, 194, 193, 200, 199, 0, 0, 122, 121, 128, 127, 134, 133, 140, 139, 146, 145, 152, 151, 158, 157, 164, 163, 170, 169, 176, 175, 182, 181, 188, 187, 194, 193, 200, 199, 0, 0,
124, 123, 130, 129, 136, 135, 142, 141, 148, 147, 154, 153, 160, 159, 166, 165, 172, 171, 178, 177, 184, 183, 190, 189, 196, 195, 202, 201, 817, 0, 124, 123, 130, 129, 136, 135, 142, 141, 148, 147, 154, 153, 160, 159, 166, 165, 172, 171, 178, 177, 184, 183, 190, 189, 196, 195, 202, 201, 817, 0,
126, 125, 132, 131, 138, 137, 144, 143, 150, 149, 156, 155, 162, 161, 168, 167, 174, 173, 180, 179, 186, 185, 192, 191, 198, 197, 204, 203, 819, 818, 126, 125, 132, 131, 138, 137, 144, 143, 150, 149, 156, 155, 162, 161, 168, 167, 174, 173, 180, 179, 186, 185, 192, 191, 198, 197, 204, 203, 819, 818,
@ -66,7 +67,8 @@ static const int MaxiGrid[] = { /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequ
738, 737, 744, 743, 750, 749, 756, 755, 762, 761, 768, 767, 774, 773, 780, 779, 786, 785, 792, 791, 798, 797, 804, 803, 810, 809, 816, 815, 864, 863 738, 737, 744, 743, 750, 749, 756, 755, 762, 761, 768, 767, 774, 773, 780, 779, 786, 785, 792, 791, 798, 797, 804, 803, 810, 809, 816, 815, 864, 863
}; };
static const int maxiCodeSet[256] = { /* from Appendix A - ASCII character to Code Set (e.g. 2 = Set B) */ static const int maxiCodeSet[256] = {
/* from Appendix A - ASCII character to Code Set (e.g. 2 = Set B) */
/* set 0 refers to special characters that fit into more than one set (e.g. GS) */ /* set 0 refers to special characters that fit into more than one set (e.g. GS) */
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, 2, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, 2, 1, 1, 1, 1, 1, 1,
@ -83,7 +85,8 @@ static const int maxiCodeSet[256] = { /* from Appendix A - ASCII character to Co
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
}; };
static const int maxiSymbolChar[256] = { /* from Appendix A - ASCII character to symbol value */ static const int maxiSymbolChar[256] = {
/* from Appendix A - ASCII character to symbol value */
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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, 30, 28, 29, 30, 35, 32, 53, 34, 35, 36, 37, 38, 39, 20, 21, 22, 23, 24, 25, 26, 30, 28, 29, 30, 35, 32, 53, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 37, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 37,

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -40,12 +40,13 @@ extern int c39(struct zint_symbol *symbol, unsigned char source[], int length);
#define CALCIUM "0123456789-$:/.+ABCD" #define CALCIUM "0123456789-$:/.+ABCD"
static const char *CodaTable[20] = {"11111221", "11112211", "11121121", "22111111", "11211211", "21111211", static const char *CodaTable[20] = {
"11111221", "11112211", "11121121", "22111111", "11211211", "21111211",
"12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121", "12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121",
"21212111", "11212121", "11221211", "12121121", "11121221", "11122211"}; "21212111", "11212121", "11221211", "12121121", "11121221", "11122211"
};
int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
{
/* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other /* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other
commonly used one-dimensional barcode schemes, pharmacode does not store the data in a commonly used one-dimensional barcode schemes, pharmacode does not store the data in a
form corresponding to the human-readable digits; the number is encoded in binary, rather form corresponding to the human-readable digits; the number is encoded in binary, rather
@ -82,8 +83,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
do do {
{
if (!(tester & 1)) { if (!(tester & 1)) {
concat(inter, "W"); concat(inter, "W");
tester = (tester - 2) / 2; tester = (tester - 2) / 2;
@ -91,8 +91,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
concat(inter, "N"); concat(inter, "N");
tester = (tester - 1) / 2; tester = (tester - 1) / 2;
} }
} } while (tester != 0);
while(tester != 0);
h = strlen(inter) - 1; h = strlen(inter) - 1;
*dest = '\0'; *dest = '\0';
@ -109,8 +108,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
{
/* This code uses the Two Track Pharamacode defined in the document at /* This code uses the Two Track Pharamacode defined in the document at
http://www.laetus.com/laetus.php?request=file&id=69 and using a modified http://www.laetus.com/laetus.php?request=file&id=69 and using a modified
algorithm from the One Track system. This standard accepts integet values algorithm from the One Track system. This standard accepts integet values
@ -123,15 +121,13 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
tester = atoi((char*) source); tester = atoi((char*) source);
if((tester < 4) || (tester > 64570080)) if ((tester < 4) || (tester > 64570080)) {
{
strcpy(symbol->errtxt, "Data out of range"); strcpy(symbol->errtxt, "Data out of range");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
error_number = 0; error_number = 0;
strcpy(inter, ""); strcpy(inter, "");
do do {
{
switch (tester % 3) { switch (tester % 3) {
case 0: case 0:
concat(inter, "3"); concat(inter, "3");
@ -146,12 +142,10 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
tester = (tester - 2) / 3; tester = (tester - 2) / 3;
break; break;
} }
} } while (tester != 0);
while(tester != 0);
h = strlen(inter) - 1; h = strlen(inter) - 1;
for(counter = h; counter >= 0; counter--) for (counter = h; counter >= 0; counter--) {
{
dest[h - counter] = inter[counter]; dest[h - counter] = inter[counter];
} }
dest[h + 1] = '\0'; dest[h + 1] = '\0';
@ -159,8 +153,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
return error_number; return error_number;
} }
int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) {
{
/* Draws the patterns for two track pharmacode */ /* Draws the patterns for two track pharmacode */
char height_pattern[200]; char height_pattern[200];
unsigned int loopey, h; unsigned int loopey, h;
@ -184,14 +177,11 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
writer = 0; writer = 0;
h = strlen(height_pattern); h = strlen(height_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) {
if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3'))
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) {
{
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
} }
writer += 2; writer += 2;
@ -203,8 +193,8 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int codabar(struct zint_symbol *symbol, unsigned char source[], int length) /* The Codabar system consisting of simple substitution */
{ /* The Codabar system consisting of simple substitution */ int codabar(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; char dest[512];
@ -223,21 +213,19 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
/* Codabar must begin and end with the characters A, B, C or D */ /* Codabar must begin and end with the characters A, B, C or D */
if((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') && (source[0] != 'D')) if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C')
{ && (source[0] != 'D')) {
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
if ((source[length - 1] != 'A') && (source[length - 1] != 'B') && if ((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
(source[length - 1] != 'C') && (source[length - 1] != 'D')) (source[length - 1] != 'C') && (source[length - 1] != 'D')) {
{
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
for(i = 0; i < length; i++) for (i = 0; i < length; i++) {
{
lookup(CALCIUM, CodaTable, source[i], dest); lookup(CALCIUM, CodaTable, source[i], dest);
} }
@ -246,8 +234,8 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int code32(struct zint_symbol *symbol, unsigned char source[], int length) /* Italian Pharmacode */
{ /* Italian Pharmacode */ int code32(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, zeroes, error_number, checksum, checkpart, checkdigit; int i, zeroes, error_number, checksum, checkpart, checkdigit;
char localstr[10], risultante[7]; char localstr[10], risultante[7];
long int pharmacode, remainder, devisor; long int pharmacode, remainder, devisor;
@ -309,7 +297,9 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
risultante[6] = '\0'; risultante[6] = '\0';
/* Plot the barcode using Code 39 */ /* Plot the barcode using Code 39 */
error_number = c39(symbol, (unsigned char*) risultante, strlen(risultante)); error_number = c39(symbol, (unsigned char*) risultante, strlen(risultante));
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
/* Override the normal text output with the Pharmacode number */ /* Override the normal text output with the Pharmacode number */
ustrcpy(symbol->text, (unsigned char*) "A"); ustrcpy(symbol->text, (unsigned char*) "A");

View File

@ -1,7 +1,7 @@
/* pdf417.c - Handles PDF417 stacked symbology */ /* pdf417.c - Handles PDF417 stacked symbology */
/* Zint - A barcode generating program using libpng /* Zint - A barcode generating program using libpng
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Portions Copyright (C) 2004 Grandzebu Portions Copyright (C) 2004 Grandzebu
Bug Fixes thanks to KL Chin <klchin@users.sourceforge.net> Bug Fixes thanks to KL Chin <klchin@users.sourceforge.net>
@ -41,8 +41,6 @@
symbol->option_2 is used to adjust the width of the resulting symbol (i.e. the symbol->option_2 is used to adjust the width of the resulting symbol (i.e. the
number of codeword columns not including row start and end data) */ number of codeword columns not including row start and end data) */
/* @(#) $Id: pdf417.c,v 1.21 2010/01/28 17:55:59 hooper114 Exp $ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -64,40 +62,45 @@
/* text mode processing tables */ /* text mode processing tables */
static const int asciix[95] = { 7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4, static const int asciix[95] = {
7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 12, 8, 8, 4, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 12, 8, 8, 4, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 8, 8, 8, 8 }; 2, 2, 2, 2, 8, 8, 8, 8
};
static const int asciiy[95] = { 26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3, static const int asciiy[95] = {
26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 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, 4, 5, 6, 24, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 4, 5, 6, 24, 7, 8, 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, 21, 27, 9 }; 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 21, 27, 9
};
/* Automatic sizing table */ /* Automatic sizing table */
static const int MicroAutosize[56] = static const int MicroAutosize[56] ={
{ 4, 6, 7, 8, 10, 12, 13, 14, 16, 18, 19, 20, 24, 29, 30, 33, 34, 37, 39, 46, 54, 58, 70, 72, 82, 90, 108, 126, 4, 6, 7, 8, 10, 12, 13, 14, 16, 18, 19, 20, 24, 29, 30, 33, 34, 37, 39, 46, 54, 58, 70, 72, 82, 90, 108, 126,
1, 14, 2, 7, 3, 25, 8, 16, 5, 17, 9, 6, 10, 11, 28, 12, 19, 13, 29, 20, 30, 21, 22, 31, 23, 32, 33, 34 1, 14, 2, 7, 3, 25, 8, 16, 5, 17, 9, 6, 10, 11, 28, 12, 19, 13, 29, 20, 30, 21, 22, 31, 23, 32, 33, 34
}; };
int liste[2][1000]; /* global - okay, so I got _almost_ everything local! */ int liste[2][1000]; /* global */
/* 866 */ /* 866 */
int quelmode(char codeascii) int quelmode(char codeascii) {
{
int mode = BYT; int mode = BYT;
if ((codeascii == '\t') || (codeascii == '\n') || (codeascii == '\r') || ((codeascii >= ' ') && (codeascii <= '~'))) { mode = TEX; } if ((codeascii == '\t') || (codeascii == '\n') || (codeascii == '\r') || ((codeascii >= ' ') && (codeascii <= '~'))) {
else if((codeascii >= '0') && (codeascii <= '9')) { mode = NUM; } mode = TEX;
} else if ((codeascii >= '0') && (codeascii <= '9')) {
mode = NUM;
}
/* 876 */ /* 876 */
return mode; return mode;
} }
/* 844 */ /* 844 */
void regroupe(int *indexliste) void regroupe(int *indexliste) {
{
int i, j; int i, j;
/* bring together same type blocks */ /* bring together same type blocks */
@ -125,31 +128,58 @@ void regroupe(int *indexliste)
} }
/* 478 */ /* 478 */
void pdfsmooth(int *indexliste) void pdfsmooth(int *indexliste) {
{
int i, crnt, last, next, length; int i, crnt, last, next, length;
for (i = 0; i < *(indexliste); i++) { for (i = 0; i < *(indexliste); i++) {
crnt = liste[1][i]; crnt = liste[1][i];
length = liste[0][i]; length = liste[0][i];
if(i != 0) { last = liste[1][i - 1]; } else { last = FALSE; } if (i != 0) {
if(i != *(indexliste) - 1) { next = liste[1][i + 1]; } else { next = FALSE; } last = liste[1][i - 1];
} else {
last = FALSE;
}
if (i != *(indexliste) - 1) {
next = liste[1][i + 1];
} else {
next = FALSE;
}
if (crnt == NUM) { if (crnt == NUM) {
if(i == 0) { /* first block */ if (i == 0) {
if(*(indexliste) > 1) { /* and there are others */ /* first block */
if((next == TEX) && (length < 8)) { liste[1][i] = TEX;} if (*(indexliste) > 1) {
if((next == BYT) && (length == 1)) { liste[1][i] = BYT; } /* and there are others */
if ((next == TEX) && (length < 8)) {
liste[1][i] = TEX;
}
if ((next == BYT) && (length == 1)) {
liste[1][i] = BYT;
}
} }
} else { } else {
if(i == *(indexliste) - 1) { /* last block */ if (i == *(indexliste) - 1) {
if((last == TEX) && (length < 7)) { liste[1][i] = TEX; } /* last block */
if((last == BYT) && (length == 1)) { liste[1][i] = BYT; } if ((last == TEX) && (length < 7)) {
} else { /* not first or last block */ liste[1][i] = TEX;
if(((last == BYT) && (next == BYT)) && (length < 4)) { liste[1][i] = BYT; } }
if(((last == BYT) && (next == TEX)) && (length < 4)) { liste[1][i] = TEX; } if ((last == BYT) && (length == 1)) {
if(((last == TEX) && (next == BYT)) && (length < 5)) { liste[1][i] = TEX; } liste[1][i] = BYT;
if(((last == TEX) && (next == TEX)) && (length < 8)) { liste[1][i] = TEX; } }
} else {
/* not first or last block */
if (((last == BYT) && (next == BYT)) && (length < 4)) {
liste[1][i] = BYT;
}
if (((last == BYT) && (next == TEX)) && (length < 4)) {
liste[1][i] = TEX;
}
if (((last == TEX) && (next == BYT)) && (length < 5)) {
liste[1][i] = TEX;
}
if (((last == TEX) && (next == TEX)) && (length < 8)) {
liste[1][i] = TEX;
}
} }
} }
} }
@ -159,15 +189,31 @@ void pdfsmooth(int *indexliste)
for (i = 0; i < *(indexliste); i++) { for (i = 0; i < *(indexliste); i++) {
crnt = liste[1][i]; crnt = liste[1][i];
length = liste[0][i]; length = liste[0][i];
if(i != 0) { last = liste[1][i - 1]; } else { last = FALSE; } if (i != 0) {
if(i != *(indexliste) - 1) { next = liste[1][i + 1]; } else { next = FALSE; } last = liste[1][i - 1];
} else {
last = FALSE;
}
if (i != *(indexliste) - 1) {
next = liste[1][i + 1];
} else {
next = FALSE;
}
if((crnt == TEX) && (i > 0)) { /* not the first */ if ((crnt == TEX) && (i > 0)) {
if(i == *(indexliste) - 1) { /* the last one */ /* not the first */
if((last == BYT) && (length == 1)) { liste[1][i] = BYT; } if (i == *(indexliste) - 1) {
} else { /* not the last one */ /* the last one */
if(((last == BYT) && (next == BYT)) && (length < 5)) { liste[1][i] = BYT; } if ((last == BYT) && (length == 1)) {
if((((last == BYT) && (next != BYT)) || ((last != BYT) && (next == BYT))) && (length < 3)) { liste[1][i] = BYT;
}
} else {
/* not the last one */
if (((last == BYT) && (next == BYT)) && (length < 5)) {
liste[1][i] = BYT;
}
if ((((last == BYT) && (next != BYT)) || ((last != BYT)
&& (next == BYT))) && (length < 3)) {
liste[1][i] = BYT; liste[1][i] = BYT;
} }
} }
@ -178,8 +224,7 @@ void pdfsmooth(int *indexliste)
} }
/* 547 */ /* 547 */
void textprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) void textprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) {
{
int j, indexlistet, curtable, listet[2][5000], chainet[5000], wnet; int j, indexlistet, curtable, listet[2][5000], chainet[5000], wnet;
char codeascii; char codeascii;
@ -193,29 +238,41 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len
for (indexlistet = 0; indexlistet < length; indexlistet++) { for (indexlistet = 0; indexlistet < length; indexlistet++) {
codeascii = chaine[start + indexlistet]; codeascii = chaine[start + indexlistet];
switch (codeascii) { switch (codeascii) {
case '\t': listet[0][indexlistet] = 12; listet[1][indexlistet] = 12; break; case '\t': listet[0][indexlistet] = 12;
case '\n': listet[0][indexlistet] = 8; listet[1][indexlistet] = 15; break; listet[1][indexlistet] = 12;
case 13: listet[0][indexlistet] = 12; listet[1][indexlistet] = 11; break; break;
case '\n': listet[0][indexlistet] = 8;
listet[1][indexlistet] = 15;
break;
case 13: listet[0][indexlistet] = 12;
listet[1][indexlistet] = 11;
break;
default: listet[0][indexlistet] = asciix[codeascii - 32]; default: listet[0][indexlistet] = asciix[codeascii - 32];
listet[1][indexlistet] = asciiy[codeascii - 32]; break; listet[1][indexlistet] = asciiy[codeascii - 32];
break;
} }
} }
/* 570 */ /* 570 */
curtable = 1; /* default table */ curtable = 1; /* default table */
for (j = 0; j < length; j++) { for (j = 0; j < length; j++) {
if(listet[0][j] & curtable) { /* The character is in the current table */ if (listet[0][j] & curtable) {
/* The character is in the current table */
chainet[wnet] = listet[1][j]; chainet[wnet] = listet[1][j];
wnet++; wnet++;
} else { /* Obliged to change table */ } else {
/* Obliged to change table */
int flag = FALSE; /* True if we change table for only one character */ int flag = FALSE; /* True if we change table for only one character */
if (j == (length - 1)) { if (j == (length - 1)) {
flag = TRUE; flag = TRUE;
} else { } else {
if(!(listet[0][j] & listet[0][j + 1])) { flag = TRUE; } if (!(listet[0][j] & listet[0][j + 1])) {
flag = TRUE;
}
} }
if (flag) { /* we change only one character - look for temporary switch */ if (flag) {
/* we change only one character - look for temporary switch */
if ((listet[0][j] & 1) && (curtable == 2)) { /* T_UPP */ if ((listet[0][j] & 1) && (curtable == 2)) { /* T_UPP */
chainet[wnet] = 27; chainet[wnet] = 27;
chainet[wnet + 1] = listet[1][j]; chainet[wnet + 1] = listet[1][j];
@ -255,41 +312,82 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len
case 11: case 11:
case 13: case 13:
case 15: case 15:
newtable = 1; break; newtable = 1;
break;
case 6: case 6:
case 10: case 10:
case 14: case 14:
newtable = 2; break; newtable = 2;
break;
case 12: case 12:
newtable = 4; break; newtable = 4;
break;
} }
/* 619 - select the switch */ /* 619 - select the switch */
switch (curtable) { switch (curtable) {
case 1: case 1:
switch (newtable) { switch (newtable) {
case 2: chainet[wnet] = 27; wnet++; break; case 2: chainet[wnet] = 27;
case 4: chainet[wnet] = 28; wnet++; break; wnet++;
case 8: chainet[wnet] = 28; wnet++; chainet[wnet] = 25; wnet++; break; break;
} break; case 4: chainet[wnet] = 28;
wnet++;
break;
case 8: chainet[wnet] = 28;
wnet++;
chainet[wnet] = 25;
wnet++;
break;
}
break;
case 2: case 2:
switch (newtable) { switch (newtable) {
case 1: chainet[wnet] = 28; wnet++; chainet[wnet] = 28; wnet++; break; case 1: chainet[wnet] = 28;
case 4: chainet[wnet] = 28; wnet++; break; wnet++;
case 8: chainet[wnet] = 28; wnet++; chainet[wnet] = 25; wnet++; break; chainet[wnet] = 28;
} break; wnet++;
break;
case 4: chainet[wnet] = 28;
wnet++;
break;
case 8: chainet[wnet] = 28;
wnet++;
chainet[wnet] = 25;
wnet++;
break;
}
break;
case 4: case 4:
switch (newtable) { switch (newtable) {
case 1: chainet[wnet] = 28; wnet++; break; case 1: chainet[wnet] = 28;
case 2: chainet[wnet] = 27; wnet++; break; wnet++;
case 8: chainet[wnet] = 25; wnet++; break; break;
} break; case 2: chainet[wnet] = 27;
wnet++;
break;
case 8: chainet[wnet] = 25;
wnet++;
break;
}
break;
case 8: case 8:
switch (newtable) { switch (newtable) {
case 1: chainet[wnet] = 29; wnet++; break; case 1: chainet[wnet] = 29;
case 2: chainet[wnet] = 29; wnet++; chainet[wnet] = 27; wnet++; break; wnet++;
case 4: chainet[wnet] = 29; wnet++; chainet[wnet] = 28; wnet++; break; break;
} break; case 2: chainet[wnet] = 29;
wnet++;
chainet[wnet] = 27;
wnet++;
break;
case 4: chainet[wnet] = 29;
wnet++;
chainet[wnet] = 28;
wnet++;
break;
}
break;
} }
curtable = newtable; curtable = newtable;
/* 659 - at last we add the character */ /* 659 - at last we add the character */
@ -319,8 +417,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len
} }
/* 671 */ /* 671 */
void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block) void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block) {
{
int debug = 0; int debug = 0;
int len = 0; int len = 0;
unsigned int chunkLen = 0; unsigned int chunkLen = 0;
@ -337,7 +434,9 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
if (length == 1) { if (length == 1) {
chainemc[(*mclength)++] = 913; chainemc[(*mclength)++] = 913;
chainemc[(*mclength)++] = chaine[start]; chainemc[(*mclength)++] = chaine[start];
if(debug) { printf("913 %d\n", chainemc[*mclength - 1]); } if (debug) {
printf("913 %d\n", chainemc[*mclength - 1]);
}
} else { } else {
/* select the switch for multiple of 6 bytes */ /* select the switch for multiple of 6 bytes */
if (length % 6 == 0) { if (length % 6 == 0) {
@ -348,11 +447,9 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
if (debug) printf("901 "); if (debug) printf("901 ");
} }
while (len < length) while (len < length) {
{
chunkLen = length - len; chunkLen = length - len;
if (6 <= chunkLen) /* Take groups of 6 */ if (6 <= chunkLen) /* Take groups of 6 */ {
{
chunkLen = 6; chunkLen = 6;
len += chunkLen; len += chunkLen;
#if defined(_MSC_VER) && _MSC_VER == 1200 #if defined(_MSC_VER) && _MSC_VER == 1200
@ -361,8 +458,7 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
total = 0ULL; total = 0ULL;
#endif #endif
while (chunkLen--) while (chunkLen--) {
{
mantisa = chaine[start++]; mantisa = chaine[start++];
#if defined(_MSC_VER) && _MSC_VER == 1200 #if defined(_MSC_VER) && _MSC_VER == 1200
total |= mantisa << (uint64_t) (chunkLen * 8); total |= mantisa << (uint64_t) (chunkLen * 8);
@ -373,8 +469,7 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
chunkLen = 5; chunkLen = 5;
while (chunkLen--) while (chunkLen--) {
{
#if defined(_MSC_VER) && _MSC_VER == 1200 #if defined(_MSC_VER) && _MSC_VER == 1200
chainemc[*mclength + chunkLen] = (int) (total % 900); chainemc[*mclength + chunkLen] = (int) (total % 900);
total /= 900; total /= 900;
@ -384,12 +479,9 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
#endif #endif
} }
*mclength += 5; *mclength += 5;
} } else /* If it remain a group of less than 6 bytes */ {
else /* If it remain a group of less than 6 bytes */
{
len += chunkLen; len += chunkLen;
while (chunkLen--) while (chunkLen--) {
{
chainemc[(*mclength)++] = chaine[start++]; chainemc[(*mclength)++] = chaine[start++];
} }
} }
@ -398,8 +490,7 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
} }
/* 712 */ /* 712 */
void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int length, int block) {
{
int j, loop, longueur, dummy[100], dumlength, diviseur, nombre; int j, loop, longueur, dummy[100], dumlength, diviseur, nombre;
char chainemod[50], chainemult[100], temp; char chainemod[50], chainemult[100], temp;
@ -416,7 +507,9 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len
dumlength = 0; dumlength = 0;
strcpy(chainemod, ""); strcpy(chainemod, "");
longueur = length - j; longueur = length - j;
if(longueur > 44) { longueur = 44; } if (longueur > 44) {
longueur = 44;
}
concat(chainemod, "1"); concat(chainemod, "1");
for (loop = 1; loop <= longueur; loop++) { for (loop = 1; loop <= longueur; loop++) {
chainemod[loop] = chaine[start + loop + j - 1]; chainemod[loop] = chaine[start + loop + j - 1];
@ -435,7 +528,9 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len
chainemod[loop] = chainemod[loop + 1]; chainemod[loop] = chainemod[loop + 1];
} }
if (nombre < diviseur) { if (nombre < diviseur) {
if (strlen(chainemult) != 0) { concat(chainemult, "0"); } if (strlen(chainemult) != 0) {
concat(chainemult, "0");
}
} else { } else {
temp = (nombre / diviseur) + '0'; temp = (nombre / diviseur) + '0';
chainemult[strlen(chainemult) + 1] = '\0'; chainemult[strlen(chainemult) + 1] = '\0';
@ -462,8 +557,7 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len
} }
/* 366 */ /* 366 */
int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
{
int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset; int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset;
int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr; int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr;
char codebarre[140], pattern[580]; char codebarre[140], pattern[580];
@ -500,10 +594,14 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
printf("Len: %d Type: ", liste[0][i]); printf("Len: %d Type: ", liste[0][i]);
switch (liste[1][i]) { switch (liste[1][i]) {
case TEX: printf("Text\n"); break; case TEX: printf("Text\n");
case BYT: printf("Byte\n"); break; break;
case NUM: printf("Number\n"); break; case BYT: printf("Byte\n");
default: printf("ERROR\n"); break; break;
case NUM: printf("Number\n");
break;
default: printf("ERROR\n");
break;
} }
} }
} }
@ -541,18 +639,27 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
/* 752 - Now take care of the number of CWs per row */ /* 752 - Now take care of the number of CWs per row */
if (symbol->option_1 < 0) { if (symbol->option_1 < 0) {
symbol->option_1 = 6; symbol->option_1 = 6;
if(mclength <= 863) { symbol->option_1 = 5; } if (mclength <= 863) {
if(mclength <= 320) { symbol->option_1 = 4; } symbol->option_1 = 5;
if(mclength <= 160) { symbol->option_1 = 3; } }
if(mclength <= 40) { symbol->option_1 = 2; } if (mclength <= 320) {
symbol->option_1 = 4;
}
if (mclength <= 160) {
symbol->option_1 = 3;
}
if (mclength <= 40) {
symbol->option_1 = 2;
}
} }
k = 1; k = 1;
for(loop = 1; loop <= (symbol->option_1 + 1); loop++) for (loop = 1; loop <= (symbol->option_1 + 1); loop++) {
{
k *= 2; k *= 2;
} }
longueur = mclength; longueur = mclength;
if(symbol->option_2 > 30) { symbol->option_2 = 30; } if (symbol->option_2 > 30) {
symbol->option_2 = 30;
}
if (symbol->option_2 < 1) { if (symbol->option_2 < 1) {
symbol->option_2 = 0.5 + sqrt((longueur + k) / 3.0); symbol->option_2 = 0.5 + sqrt((longueur + k) / 3.0);
} }
@ -576,7 +683,9 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
if ((longueur / symbol->option_2) < 3) { if ((longueur / symbol->option_2) < 3) {
i = (symbol->option_2 * 3) - longueur; /* A bar code must have at least three rows */ i = (symbol->option_2 * 3) - longueur; /* A bar code must have at least three rows */
} else { } else {
if((longueur % symbol->option_2) > 0) { i = symbol->option_2 - (longueur % symbol->option_2); } if ((longueur % symbol->option_2) > 0) {
i = symbol->option_2 - (longueur % symbol->option_2);
}
} }
/* We add the padding */ /* We add the padding */
while (i > 0) { while (i > 0) {
@ -593,15 +702,24 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
/* 796 - we now take care of the Reed Solomon codes */ /* 796 - we now take care of the Reed Solomon codes */
switch (symbol->option_1) { switch (symbol->option_1) {
case 1: offset = 2; break; case 1: offset = 2;
case 2: offset = 6; break; break;
case 3: offset = 14; break; case 2: offset = 6;
case 4: offset = 30; break; break;
case 5: offset = 62; break; case 3: offset = 14;
case 6: offset = 126; break; break;
case 7: offset = 254; break; case 4: offset = 30;
case 8: offset = 510; break; break;
default: offset = 0; break; case 5: offset = 62;
break;
case 6: offset = 126;
break;
case 7: offset = 254;
break;
case 8: offset = 510;
break;
default: offset = 0;
break;
} }
longueur = mclength; longueur = mclength;
@ -634,12 +752,6 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
} }
k = (i / 3) * 30; k = (i / 3) * 30;
switch (i % 3) { switch (i % 3) {
/* follows this pattern from US Patent 5,243,655:
Row 0: L0 (row #, # of rows) R0 (row #, # of columns)
Row 1: L1 (row #, security level) R1 (row #, # of rows)
Row 2: L2 (row #, # of columns) R2 (row #, security level)
Row 3: L3 (row #, # of rows) R3 (row #, # of columns)
etc. */
case 0: case 0:
dummy[0] = k + c1; dummy[0] = k + c1;
dummy[symbol->option_2 + 1] = k + c3; dummy[symbol->option_2 + 1] = k + c3;
@ -658,9 +770,12 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
/* truncated - so same as before except knock off the last 5 chars */ /* truncated - so same as before except knock off the last 5 chars */
for (j = 0; j <= symbol->option_2; j++) { for (j = 0; j <= symbol->option_2; j++) {
switch (i % 3) { switch (i % 3) {
case 1: offset = 929; break; case 1: offset = 929;
case 2: offset = 1858; break; break;
default: offset = 0; break; case 2: offset = 1858;
break;
default: offset = 0;
break;
} }
concat(codebarre, codagemc[offset + dummy[j]]); concat(codebarre, codagemc[offset + dummy[j]]);
concat(codebarre, "*"); concat(codebarre, "*");
@ -669,9 +784,12 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
/* normal PDF417 symbol */ /* normal PDF417 symbol */
for (j = 0; j <= symbol->option_2 + 1; j++) { for (j = 0; j <= symbol->option_2 + 1; j++) {
switch (i % 3) { switch (i % 3) {
case 1: offset = 929; /* cluster(3) */ break; case 1: offset = 929;
case 2: offset = 1858; /* cluster(6) */ break; /* cluster(3) */ break;
default: offset = 0; /* cluster(0) */ break; case 2: offset = 1858;
/* cluster(6) */ break;
default: offset = 0;
/* cluster(0) */ break;
} }
concat(codebarre, codagemc[offset + dummy[j]]); concat(codebarre, codagemc[offset + dummy[j]]);
concat(codebarre, "*"); concat(codebarre, "*");
@ -684,7 +802,9 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
lookup(BRSET, PDFttf, codebarre[loop], pattern); lookup(BRSET, PDFttf, codebarre[loop], pattern);
} }
for (loop = 0; loop < strlen(pattern); loop++) { for (loop = 0; loop < strlen(pattern); loop++) {
if(pattern[loop] == '1') { set_module(symbol, i, loop); } if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
} }
if (symbol->height == 0) { if (symbol->height == 0) {
symbol->row_height[i] = 3; symbol->row_height[i] = 3;
@ -698,8 +818,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
} }
/* 345 */ /* 345 */
int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) {
{
int codeerr, error_number; int codeerr, error_number;
error_number = 0; error_number = 0;
@ -748,10 +867,8 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
/* like PDF417 only much smaller! */
int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
{ /* like PDF417 only much smaller! */
int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset; int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset;
int total, chainemc[2700], mclength, dummy[5], codeerr; int total, chainemc[2700], mclength, dummy[5], codeerr;
char codebarre[100], pattern[580]; char codebarre[100], pattern[580];
@ -791,10 +908,14 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
printf("len: %d type: ", liste[0][i]); printf("len: %d type: ", liste[0][i]);
switch (liste[1][i]) { switch (liste[1][i]) {
case TEX: printf("TEXT\n"); break; case TEX: printf("TEXT\n");
case BYT: printf("BYTE\n"); break; break;
case NUM: printf("NUMBER\n"); break; case BYT: printf("BYTE\n");
default: printf("*ERROR*\n"); break; break;
case NUM: printf("NUMBER\n");
break;
default: printf("*ERROR*\n");
break;
} }
} }
} }
@ -869,51 +990,111 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
if (symbol->option_2 == 1) { if (symbol->option_2 == 1) {
/* the user specified 1 column and the data does fit */ /* the user specified 1 column and the data does fit */
variant = 6; variant = 6;
if(mclength <= 16) { variant = 5; } if (mclength <= 16) {
if(mclength <= 12) { variant = 4; } variant = 5;
if(mclength <= 10) { variant = 3; } }
if(mclength <= 7) { variant = 2; } if (mclength <= 12) {
if(mclength <= 4) { variant = 1; } variant = 4;
}
if (mclength <= 10) {
variant = 3;
}
if (mclength <= 7) {
variant = 2;
}
if (mclength <= 4) {
variant = 1;
}
} }
if (symbol->option_2 == 2) { if (symbol->option_2 == 2) {
/* the user specified 2 columns and the data does fit */ /* the user specified 2 columns and the data does fit */
variant = 13; variant = 13;
if(mclength <= 33) { variant = 12; } if (mclength <= 33) {
if(mclength <= 29) { variant = 11; } variant = 12;
if(mclength <= 24) { variant = 10; } }
if(mclength <= 19) { variant = 9; } if (mclength <= 29) {
if(mclength <= 13) { variant = 8; } variant = 11;
if(mclength <= 8) { variant = 7; } }
if (mclength <= 24) {
variant = 10;
}
if (mclength <= 19) {
variant = 9;
}
if (mclength <= 13) {
variant = 8;
}
if (mclength <= 8) {
variant = 7;
}
} }
if (symbol->option_2 == 3) { if (symbol->option_2 == 3) {
/* the user specified 3 columns and the data does fit */ /* the user specified 3 columns and the data does fit */
variant = 23; variant = 23;
if(mclength <= 70) { variant = 22; } if (mclength <= 70) {
if(mclength <= 58) { variant = 21; } variant = 22;
if(mclength <= 46) { variant = 20; } }
if(mclength <= 34) { variant = 19; } if (mclength <= 58) {
if(mclength <= 24) { variant = 18; } variant = 21;
if(mclength <= 18) { variant = 17; } }
if(mclength <= 14) { variant = 16; } if (mclength <= 46) {
if(mclength <= 10) { variant = 15; } variant = 20;
if(mclength <= 6) { variant = 14; } }
if (mclength <= 34) {
variant = 19;
}
if (mclength <= 24) {
variant = 18;
}
if (mclength <= 18) {
variant = 17;
}
if (mclength <= 14) {
variant = 16;
}
if (mclength <= 10) {
variant = 15;
}
if (mclength <= 6) {
variant = 14;
}
} }
if (symbol->option_2 == 4) { if (symbol->option_2 == 4) {
/* the user specified 4 columns and the data does fit */ /* the user specified 4 columns and the data does fit */
variant = 34; variant = 34;
if(mclength <= 108) { variant = 33; } if (mclength <= 108) {
if(mclength <= 90) { variant = 32; } variant = 33;
if(mclength <= 72) { variant = 31; } }
if(mclength <= 54) { variant = 30; } if (mclength <= 90) {
if(mclength <= 39) { variant = 29; } variant = 32;
if(mclength <= 30) { variant = 28; } }
if(mclength <= 24) { variant = 27; } if (mclength <= 72) {
if(mclength <= 18) { variant = 26; } variant = 31;
if(mclength <= 12) { variant = 25; } }
if(mclength <= 8) { variant = 24; } if (mclength <= 54) {
variant = 30;
}
if (mclength <= 39) {
variant = 29;
}
if (mclength <= 30) {
variant = 28;
}
if (mclength <= 24) {
variant = 27;
}
if (mclength <= 18) {
variant = 26;
}
if (mclength <= 12) {
variant = 25;
}
if (mclength <= 8) {
variant = 24;
}
} }
if (variant == 0) { if (variant == 0) {
@ -967,7 +1148,9 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
} }
for (j = 0; j < k; j++) { for (j = 0; j < k; j++) {
if(mccorrection[j] != 0) { mccorrection[j] = 929 - mccorrection[j]; } if (mccorrection[j] != 0) {
mccorrection[j] = 929 - mccorrection[j];
}
} }
/* we add these codes to the string */ /* we add these codes to the string */
for (i = k - 1; i >= 0; i--) { for (i = k - 1; i >= 0; i--) {
@ -994,7 +1177,8 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
LeftRAP = LeftRAPStart; LeftRAP = LeftRAPStart;
CentreRAP = CentreRAPStart; CentreRAP = CentreRAPStart;
RightRAP = RightRAPStart; RightRAP = RightRAPStart;
Cluster = StartCluster; /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */ Cluster = StartCluster;
/* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */
if (debug) printf("\nInternal row representation:\n"); if (debug) printf("\nInternal row representation:\n");
for (i = 0; i < symbol->rows; i++) { for (i = 0; i < symbol->rows; i++) {
@ -1069,7 +1253,9 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
/* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ /* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */
for (loop = 0; loop < strlen(pattern); loop++) { for (loop = 0; loop < strlen(pattern); loop++) {
if(pattern[loop] == '1') { set_module(symbol, i, loop); } if (pattern[loop] == '1') {
set_module(symbol, i, loop);
}
} }
symbol->row_height[i] = 2; symbol->row_height[i] = 2;
@ -1095,4 +1281,3 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length)
return codeerr; return codeerr;
} }

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Portions Copyright (C) 2004 Grandzebu Portions Copyright (C) 2004 Grandzebu
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -126,10 +126,12 @@ static const int coefrs[1022] = {
447, 171, 616, 464, 190, 531, 297, 321, 762, 752, 533, 175, 134, 14, 381, 433, 447, 171, 616, 464, 190, 531, 297, 321, 762, 752, 533, 175, 134, 14, 381, 433,
717, 45, 111, 20, 596, 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, 717, 45, 111, 20, 596, 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780,
407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, 223, 849, 647, 407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, 223, 849, 647,
63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263 }; 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263
};
static const char *codagemc[2787] = { "urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA", "uls", "pBk", "eBA", static const char *codagemc[2787] = {
"urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA", "uls", "pBk", "eBA",
"pAs", "eAk", "prA", "uvs", "xhy", "pnk", "utw", "xgz", "fDA", "pls", "fBk", "frA", "pvs", "pAs", "eAk", "prA", "uvs", "xhy", "pnk", "utw", "xgz", "fDA", "pls", "fBk", "frA", "pvs",
"uxy", "fnk", "ptw", "uwz", "fls", "psy", "fvs", "pxy", "ftw", "pwz", "fxy", "yrx", "ufk", "uxy", "fnk", "ptw", "uwz", "fls", "psy", "fvs", "pxy", "ftw", "pwz", "fxy", "yrx", "ufk",
"xFw", "ymz", "onA", "uds", "xEy", "olk", "ucw", "dBA", "oks", "uci", "dAk", "okg", "dAc", "xFw", "ymz", "onA", "uds", "xEy", "olk", "ucw", "dBA", "oks", "uci", "dAk", "okg", "dAc",
@ -343,10 +345,12 @@ static const char *codagemc[2787] = { "urA", "xfs", "ypy", "unk", "xdw", "yoz",
"lyo", "szf", "lym", "lyl", "Bwo", "kyf", "Dxo", "lyv", "Dxm", "Bwl", "Dxl", "Awf", "Bwv", "lyo", "szf", "lym", "lyl", "Bwo", "kyf", "Dxo", "lyv", "Dxm", "Bwl", "Dxl", "Awf", "Bwv",
"Dxv", "tze", "tzd", "lye", "nyu", "lyd", "nyt", "Bwe", "Dwu", "Bwd", "bxu", "Dwt", "bxt", "Dxv", "tze", "tzd", "lye", "nyu", "lyd", "nyt", "Bwe", "Dwu", "Bwd", "bxu", "Dwt", "bxt",
"tzF", "lyF", "nyh", "BwF", "Dwh", "bwx", "Aiq", "Ain", "Ayo", "kjf", "Aym", "Ayl", "Aif", "tzF", "lyF", "nyh", "BwF", "Dwh", "bwx", "Aiq", "Ain", "Ayo", "kjf", "Aym", "Ayl", "Aif",
"Ayv", "kze", "kzd", "Aye", "Byu", "Ayd", "Byt", "szp" }; "Ayv", "kze", "kzd", "Aye", "Byu", "Ayd", "Byt", "szp"
};
static const char *PDFttf[35] = {
/* converts values into bar patterns - replacing Grand Zebu's true type font */ /* converts values into bar patterns - replacing Grand Zebu's true type font */
static const char *PDFttf[35] = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
"01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001",
"10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010",
"11011", "11100", "11101", "11110", "11111", "01", "1111111101010100", "11111101000101001"}; "11011", "11100", "11101", "11110", "11111", "01", "1111111101010100", "11111101000101001"};
@ -413,37 +417,44 @@ static const int Microcoeffs[344] = {
923, 797, 576, 875, 156, 706, 63, 81, 257, 874, 411, 416, 778, 50, 205, 303, 923, 797, 576, 875, 156, 706, 63, 81, 257, 874, 411, 416, 778, 50, 205, 303,
188, 535, 909, 155, 637, 230, 534, 96, 575, 102, 264, 233, 919, 593, 865, 26, 188, 535, 909, 155, 637, 230, 534, 96, 575, 102, 264, 233, 919, 593, 865, 26,
579, 623, 766, 146, 10, 739, 246, 127, 71, 244, 211, 477, 920, 876, 427, 820, 579, 623, 766, 146, 10, 739, 246, 127, 71, 244, 211, 477, 920, 876, 427, 820,
718, 435 }; 718, 435
};
/* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */ /* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */
static const int MicroVariants[170] = static const int MicroVariants[170] ={
{ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44,
7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50,
0, 0, 0, 7, 7, 7, 7, 15, 15, 24, 34, 57, 84, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294, 7, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294 }; 0, 0, 0, 7, 7, 7, 7, 15, 15, 24, 34, 57, 84, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294, 7, 45, 70, 99, 115, 133, 154, 180, 212, 250, 294
};
/* rows, columns, error codewords, k-offset */ /* rows, columns, error codewords, k-offset */
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */ /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */
static const int RAPTable[136] = static const int RAPTable[136] ={
{ 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25,
9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49,
0, 3, 6, 0, 6, 0, 0, 0, 3, 6, 0, 6, 6, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0, 3, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0 }; 0, 3, 6, 0, 6, 0, 0, 0, 3, 6, 0, 6, 6, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0, 3, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0
};
/* Left and Right Row Address Pattern from Table 2 */ /* Left and Right Row Address Pattern from Table 2 */
static const char *RAPLR[53] = {"", "221311", "311311", "312211", "222211", "213211", "214111", "223111", static const char *RAPLR[53] = {
"", "221311", "311311", "312211", "222211", "213211", "214111", "223111",
"313111", "322111", "412111", "421111", "331111", "241111", "232111", "231211", "321211", "313111", "322111", "412111", "421111", "331111", "241111", "232111", "231211", "321211",
"411211", "411121", "411112", "321112", "312112", "311212", "311221", "311131", "311122", "411211", "411121", "411112", "321112", "312112", "311212", "311221", "311131", "311122",
"311113", "221113", "221122", "221131", "221221", "222121", "312121", "321121", "231121", "311113", "221113", "221122", "221131", "221221", "222121", "312121", "321121", "231121",
"231112", "222112", "213112", "212212", "212221", "212131", "212122", "212113", "211213", "231112", "222112", "213112", "212212", "212221", "212131", "212122", "212113", "211213",
"211123", "211132", "211141", "211231", "211222", "211312", "211321", "211411", "212311" }; "211123", "211132", "211141", "211231", "211222", "211312", "211321", "211411", "212311"
};
/* Centre Row Address Pattern from Table 2 */ /* Centre Row Address Pattern from Table 2 */
static const char *RAPC[53] = {"", "112231", "121231", "122131", "131131", "131221", "132121", "141121", static const char *RAPC[53] = {
"", "112231", "121231", "122131", "131131", "131221", "132121", "141121",
"141211", "142111", "133111", "132211", "131311", "122311", "123211", "124111", "115111", "141211", "142111", "133111", "132211", "131311", "122311", "123211", "124111", "115111",
"114211", "114121", "123121", "123112", "122212", "122221", "121321", "121411", "112411", "114211", "114121", "123121", "123112", "122212", "122221", "121321", "121411", "112411",
"113311", "113221", "113212", "113122", "122122", "131122", "131113", "122113", "113113", "113311", "113221", "113212", "113122", "122122", "131122", "131113", "122113", "113113",
"112213", "112222", "112312", "112321", "111421", "111331", "111322", "111232", "111223", "112213", "112222", "112312", "112321", "111421", "111331", "111322", "111232", "111223",
"111133", "111124", "111214", "112114", "121114", "121123", "121132", "112132", "112141" }; "111133", "111124", "111214", "112114", "121114", "121123", "121132", "112132", "112141"
};
void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block); void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block);

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -37,16 +37,19 @@
#define SSET "0123456789ABCDEF" #define SSET "0123456789ABCDEF"
static const char *PlessTable[16] = {"13131313", "31131313", "13311313", "31311313", "13133113", "31133113", static const char *PlessTable[16] = {
"13131313", "31131313", "13311313", "31311313", "13133113", "31133113",
"13313113", "31313113", "13131331", "31131331", "13311331", "31311331", "13133131", "13313113", "31313113", "13131331", "31131331", "13311331", "31311331", "13133131",
"31133131", "13313131", "31313131"}; "31133131", "13313131", "31313131"
};
static const char *MSITable[10] = {"12121212", "12121221", "12122112", "12122121", "12211212", "12211221", static const char *MSITable[10] = {
"12212112", "12212121", "21121212", "21121221"}; "12121212", "12121221", "12122112", "12122121", "12211212", "12211221",
"12212112", "12212121", "21121212", "21121221"
};
/* Not MSI/Plessey but the older Plessey standard */
int plessey(struct zint_symbol *symbol, unsigned char source[], int length) int plessey(struct zint_symbol *symbol, unsigned char source[], int length) {
{ /* Not MSI/Plessey but the older Plessey standard */
unsigned int i, check; unsigned int i, check;
unsigned char *checkptr; unsigned char *checkptr;
@ -71,8 +74,7 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(dest, "31311331"); strcpy(dest, "31311331");
/* Data area */ /* Data area */
for(i = 0; i < length; i++) for (i = 0; i < length; i++) {
{
check = posn(SSET, source[i]); check = posn(SSET, source[i]);
lookup(SSET, PlessTable, source[i], dest); lookup(SSET, PlessTable, source[i], dest);
checkptr[4 * i] = check & 1; checkptr[4 * i] = check & 1;
@ -92,10 +94,11 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
} }
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
switch(checkptr[length * 4 + i]) switch (checkptr[length * 4 + i]) {
{ case 0: concat(dest, "13");
case 0: concat(dest, "13"); break; break;
case 1: concat(dest, "31"); break; case 1: concat(dest, "31");
break;
} }
} }
@ -108,8 +111,8 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) /* Plain MSI Plessey - does not calculate any check character */
{ /* Plain MSI Plessey - does not calculate any check character */ int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned int i; unsigned int i;
char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */ char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */
@ -122,8 +125,7 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length)
/* start character */ /* start character */
strcpy(dest, "21"); strcpy(dest, "21");
for(i = 0; i < length; i++) for (i = 0; i < length; i++) {
{
lookup(NEON, MSITable, source[i], dest); lookup(NEON, MSITable, source[i], dest);
} }
@ -135,9 +137,10 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length)
return 0; return 0;
} }
int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int length) /* MSI Plessey with Modulo 10 check digit - algorithm from Barcode Island
{ /* MSI Plessey with Modulo 10 check digit - algorithm from Barcode Island * http://www.barcodeisland.com/ */
http://www.barcodeisland.com/ */ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned long i, wright, dau, pedwar, pump, n; unsigned long i, wright, dau, pedwar, pump, n;
char un[200], tri[32]; char un[200], tri[32];
@ -155,16 +158,14 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le
strcpy(dest, "21"); strcpy(dest, "21");
/* draw data section */ /* draw data section */
for(i = 0; i < length; i++) for (i = 0; i < length; i++) {
{
lookup(NEON, MSITable, source[i], dest); lookup(NEON, MSITable, source[i], dest);
} }
/* calculate check digit */ /* calculate check digit */
wright = 0; wright = 0;
n = !(length & 1); n = !(length & 1);
for(i = n; i < length; i += 2) for (i = n; i < length; i += 2) {
{
un[wright++] = source[i]; un[wright++] = source[i];
} }
un[wright] = '\0'; un[wright] = '\0';
@ -176,20 +177,17 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le
pedwar = 0; pedwar = 0;
h = strlen(tri); h = strlen(tri);
for(i = 0; i < h; i++) for (i = 0; i < h; i++) {
{
pedwar += ctoi(tri[i]); pedwar += ctoi(tri[i]);
} }
n = length & 1; n = length & 1;
for(i = n; i < length; i+=2) for (i = n; i < length; i += 2) {
{
pedwar += ctoi(source[i]); pedwar += ctoi(source[i]);
} }
pump = (10 - pedwar % 10); pump = (10 - pedwar % 10);
if(pump == 10) if (pump == 10) {
{
pump = 0; pump = 0;
} }
@ -206,9 +204,10 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le
return error_number; return error_number;
} }
int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) /* MSI Plessey with two Modulo 10 check digits - algorithm from
{ /* MSI Plessey with two Modulo 10 check digits - algorithm from * Barcode Island http://www.barcodeisland.com/ */
Barcode Island http://www.barcodeisland.com/ */ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) {
unsigned long i, n, wright, dau, pedwar, pump, chwech; unsigned long i, n, wright, dau, pedwar, pump, chwech;
char un[16], tri[32]; char un[16], tri[32];
@ -217,7 +216,8 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
error_number = 0; error_number = 0;
if(src_len > 18) { /* No Entry Stack Smashers! limit because of str->number conversion*/ if (src_len > 18) {
/* No Entry Stack Smashers! limit because of str->number conversion*/
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
@ -226,8 +226,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
strcpy(dest, "21"); strcpy(dest, "21");
/* draw data section */ /* draw data section */
for(i = 0; i < src_len; i++) for (i = 0; i < src_len; i++) {
{
lookup(NEON, MSITable, source[i], dest); lookup(NEON, MSITable, source[i], dest);
} }
@ -235,8 +234,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
wright = 0; wright = 0;
n = !(src_len & 1); n = !(src_len & 1);
for(i = n; i < src_len; i += 2) for (i = n; i < src_len; i += 2) {
{
un[wright++] = source[i]; un[wright++] = source[i];
} }
un[wright] = '\0'; un[wright] = '\0';
@ -248,28 +246,24 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
pedwar = 0; pedwar = 0;
h = strlen(tri); h = strlen(tri);
for(i = 0; i < h; i++) for (i = 0; i < h; i++) {
{
pedwar += ctoi(tri[i]); pedwar += ctoi(tri[i]);
} }
n = src_len & 1; n = src_len & 1;
for(i = n; i < src_len; i += 2) for (i = n; i < src_len; i += 2) {
{
pedwar += ctoi(source[i]); pedwar += ctoi(source[i]);
} }
pump = 10 - pedwar % 10; pump = 10 - pedwar % 10;
if(pump == 10) if (pump == 10) {
{
pump = 0; pump = 0;
} }
/* calculate second check digit */ /* calculate second check digit */
wright = 0; wright = 0;
n = src_len & 1; n = src_len & 1;
for(i = n; i < src_len; i += 2) for (i = n; i < src_len; i += 2) {
{
un[wright++] = source[i]; un[wright++] = source[i];
} }
un[wright++] = itoc(pump); un[wright++] = itoc(pump);
@ -282,21 +276,18 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
pedwar = 0; pedwar = 0;
h = strlen(tri); h = strlen(tri);
for(i = 0; i < h; i++) for (i = 0; i < h; i++) {
{
pedwar += ctoi(tri[i]); pedwar += ctoi(tri[i]);
} }
i = !(src_len & 1); i = !(src_len & 1);
for(; i < src_len; i += 2) for (; i < src_len; i += 2) {
{
pedwar += ctoi(source[i]); pedwar += ctoi(source[i]);
} }
chwech = 10 - pedwar % 10; chwech = 10 - pedwar % 10;
if(chwech == 10) if (chwech == 10) {
{
chwech = 0; chwech = 0;
} }
@ -317,13 +308,10 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
return error_number; return error_number;
} }
int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len)
{
/* Calculate a Modulo 11 check digit using the system discussed on Wikipedia - /* Calculate a Modulo 11 check digit using the system discussed on Wikipedia -
see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */ see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */
int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) {
/* uses the IBM weight system */ /* uses the IBM weight system */
int i, weight, x, check; int i, weight, x, check;
int error_number; int error_number;
char dest[1000]; char dest[1000];
@ -339,8 +327,7 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const
strcpy(dest, "21"); strcpy(dest, "21");
/* draw data section */ /* draw data section */
for(i = 0; i < src_len; i++) for (i = 0; i < src_len; i++) {
{
lookup(NEON, MSITable, source[i], dest); lookup(NEON, MSITable, source[i], dest);
} }
@ -379,12 +366,10 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const
return error_number; return error_number;
} }
int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) /* Combining the Barcode Island and Wikipedia code
{ * Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */
/* Combining the Barcode Island and Wikipedia code */ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) {
/* Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */
/* Weighted using the IBM system */ /* Weighted using the IBM system */
unsigned long i, weight, x, check, wright, dau, pedwar, pump, h; unsigned long i, weight, x, check, wright, dau, pedwar, pump, h;
long si; long si;
char un[16], tri[16]; char un[16], tri[16];
@ -404,8 +389,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons
strcpy(dest, "21"); strcpy(dest, "21");
/* draw data section */ /* draw data section */
for(i = 0; i < src_len; i++) for (i = 0; i < src_len; i++) {
{
lookup(NEON, MSITable, source[i], dest); lookup(NEON, MSITable, source[i], dest);
} }
@ -437,8 +421,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons
/* calculate second (mod 10) check digit */ /* calculate second (mod 10) check digit */
wright = 0; wright = 0;
i = !(temp_len & 1); i = !(temp_len & 1);
for(; i < temp_len; i += 2) for (; i < temp_len; i += 2) {
{
un[wright++] = temp[i]; un[wright++] = temp[i];
} }
un[wright] = '\0'; un[wright] = '\0';
@ -450,20 +433,17 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons
pedwar = 0; pedwar = 0;
h = strlen(tri); h = strlen(tri);
for(i = 0; i < h; i++) for (i = 0; i < h; i++) {
{
pedwar += ctoi(tri[i]); pedwar += ctoi(tri[i]);
} }
i = temp_len & 1; i = temp_len & 1;
for(; i < temp_len; i+=2) for (; i < temp_len; i += 2) {
{
pedwar += ctoi(temp[i]); pedwar += ctoi(temp[i]);
} }
pump = 10 - pedwar % 10; pump = 10 - pedwar % 10;
if(pump == 10) if (pump == 10) {
{
pump = 0; pump = 0;
} }
@ -497,11 +477,16 @@ int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) {
} }
switch (symbol->option_2) { switch (symbol->option_2) {
case 0: error_number = msi_plessey(symbol, source, length); break; case 0: error_number = msi_plessey(symbol, source, length);
case 1: error_number = msi_plessey_mod10(symbol, source, length); break; break;
case 2: error_number = msi_plessey_mod1010(symbol, source, length); break; case 1: error_number = msi_plessey_mod10(symbol, source, length);
case 3: error_number = msi_plessey_mod11(symbol, source, length); break; break;
case 4: error_number = msi_plessey_mod1110(symbol, source, length); break; case 2: error_number = msi_plessey_mod1010(symbol, source, length);
break;
case 3: error_number = msi_plessey_mod11(symbol, source, length);
break;
case 4: error_number = msi_plessey_mod1110(symbol, source, length);
break;
} }
return error_number; return error_number;

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -58,6 +58,7 @@
#define BMP_DATA 200 #define BMP_DATA 200
#ifndef NO_PNG #ifndef NO_PNG
struct mainprog_info_type { struct mainprog_info_type {
long width; long width;
long height; long height;
@ -65,15 +66,15 @@ struct mainprog_info_type {
jmp_buf jmpbuf; jmp_buf jmpbuf;
}; };
static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) {
{
struct mainprog_info_type *graphic; struct mainprog_info_type *graphic;
fprintf(stderr, "writepng libpng error: %s\n", msg); fprintf(stderr, "writepng libpng error: %s\n", msg);
fflush(stderr); fflush(stderr);
graphic = (struct mainprog_info_type*) png_get_error_ptr(png_ptr); graphic = (struct mainprog_info_type*) png_get_error_ptr(png_ptr);
if (graphic == NULL) { /* we are completely hosed now */ if (graphic == NULL) {
/* we are completely hosed now */
fprintf(stderr, fprintf(stderr,
"writepng severe error: jmpbuf not recoverable; terminating.\n"); "writepng severe error: jmpbuf not recoverable; terminating.\n");
fflush(stderr); fflush(stderr);
@ -82,8 +83,7 @@ static void writepng_error_handler(png_structp png_ptr, png_const_charp msg)
longjmp(graphic->jmpbuf, 1); longjmp(graphic->jmpbuf, 1);
} }
int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) {
{
struct mainprog_info_type wpng_info; struct mainprog_info_type wpng_info;
struct mainprog_info_type *graphic; struct mainprog_info_type *graphic;
png_structp png_ptr; png_structp png_ptr;
@ -205,8 +205,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
for (row = 0; row < image_height; row++) { for (row = 0; row < image_height; row++) {
for (column = 0; column < image_width; column++) { for (column = 0; column < image_width; column++) {
i = column * 3; i = column * 3;
switch(*(pixelbuf + (image_width * row) + column)) switch (*(pixelbuf + (image_width * row) + column)) {
{
case '1': case '1':
outdata[i] = fgred; outdata[i] = fgred;
outdata[i + 1] = fggrn; outdata[i + 1] = fggrn;
@ -229,8 +228,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
for (row = 0; row < image_width; row++) { for (row = 0; row < image_width; row++) {
for (column = 0; column < image_height; column++) { for (column = 0; column < image_height; column++) {
i = column * 3; i = column * 3;
switch(*(pixelbuf + (image_width * (image_height - column - 1)) + row)) switch (*(pixelbuf + (image_width * (image_height - column - 1)) + row)) {
{
case '1': case '1':
outdata[i] = fgred; outdata[i] = fgred;
outdata[i + 1] = fggrn; outdata[i + 1] = fggrn;
@ -254,8 +252,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
for (row = 0; row < image_height; row++) { for (row = 0; row < image_height; row++) {
for (column = 0; column < image_width; column++) { for (column = 0; column < image_width; column++) {
i = column * 3; i = column * 3;
switch(*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) switch (*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) {
{
case '1': case '1':
outdata[i] = fgred; outdata[i] = fgred;
outdata[i + 1] = fggrn; outdata[i + 1] = fggrn;
@ -279,8 +276,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
for (row = 0; row < image_width; row++) { for (row = 0; row < image_width; row++) {
for (column = 0; column < image_height; column++) { for (column = 0; column < image_height; column++) {
i = column * 3; i = column * 3;
switch(*(pixelbuf + (image_width * column) + (image_width - row - 1))) switch (*(pixelbuf + (image_width * column) + (image_width - row - 1))) {
{
case '1': case '1':
outdata[i] = fgred; outdata[i] = fgred;
outdata[i + 1] = fggrn; outdata[i + 1] = fggrn;
@ -316,8 +312,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
} }
#endif /* NO_PNG */ #endif /* NO_PNG */
int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) {
{
int i, row, column, errno; int i, row, column, errno;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
@ -376,8 +371,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
case 0: /* Plot the right way up */ case 0: /* Plot the right way up */
for (row = 0; row < image_height; row++) { for (row = 0; row < image_height; row++) {
for (column = 0; column < image_width; column++) { for (column = 0; column < image_width; column++) {
switch(*(pixelbuf + (image_width * row) + column)) switch (*(pixelbuf + (image_width * row) + column)) {
{
case '1': case '1':
symbol->bitmap[i++] = fgred; symbol->bitmap[i++] = fgred;
symbol->bitmap[i++] = fggrn; symbol->bitmap[i++] = fggrn;
@ -396,8 +390,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
case 90: /* Plot 90 degrees clockwise */ case 90: /* Plot 90 degrees clockwise */
for (row = 0; row < image_width; row++) { for (row = 0; row < image_width; row++) {
for (column = 0; column < image_height; column++) { for (column = 0; column < image_height; column++) {
switch(*(pixelbuf + (image_width * (image_height - column - 1)) + row)) switch (*(pixelbuf + (image_width * (image_height - column - 1)) + row)) {
{
case '1': case '1':
symbol->bitmap[i++] = fgred; symbol->bitmap[i++] = fgred;
symbol->bitmap[i++] = fggrn; symbol->bitmap[i++] = fggrn;
@ -416,8 +409,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
case 180: /* Plot upside down */ case 180: /* Plot upside down */
for (row = 0; row < image_height; row++) { for (row = 0; row < image_height; row++) {
for (column = 0; column < image_width; column++) { for (column = 0; column < image_width; column++) {
switch(*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) switch (*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1))) {
{
case '1': case '1':
symbol->bitmap[i++] = fgred; symbol->bitmap[i++] = fgred;
symbol->bitmap[i++] = fggrn; symbol->bitmap[i++] = fggrn;
@ -436,8 +428,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
case 270: /* Plot 90 degrees anti-clockwise */ case 270: /* Plot 90 degrees anti-clockwise */
for (row = 0; row < image_width; row++) { for (row = 0; row < image_width; row++) {
for (column = 0; column < image_height; column++) { for (column = 0; column < image_height; column++) {
switch(*(pixelbuf + (image_width * column) + (image_width - row - 1))) switch (*(pixelbuf + (image_width * column) + (image_width - row - 1))) {
{
case '1': case '1':
symbol->bitmap[i++] = fgred; symbol->bitmap[i++] = fgred;
symbol->bitmap[i++] = fggrn; symbol->bitmap[i++] = fggrn;
@ -458,15 +449,16 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
return 0; return 0;
} }
int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle, int image_type) int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle, int image_type) {
{
int error_number; int error_number;
float scaler = symbol->scale; float scaler = symbol->scale;
char *scaled_pixelbuf; char *scaled_pixelbuf;
int horiz, vert, i; int horiz, vert, i;
int scale_width, scale_height; int scale_width, scale_height;
if(scaler == 0) { scaler = 0.5; } if (scaler == 0) {
scaler = 0.5;
}
scale_width = image_width * scaler; scale_width = image_width * scaler;
scale_height = image_height * scaler; scale_height = image_height * scaler;
@ -501,8 +493,7 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
return error_number; return error_number;
} }
void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_width, int image_height) void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_width, int image_height) {
{
/* Draw a rectangle */ /* Draw a rectangle */
int i, j, png_ypos; int i, j, png_ypos;
@ -524,22 +515,14 @@ int bullseye_pixel(int row, int col) {
return_val = 0; return_val = 0;
block_pos = col % 8; block_pos = col % 8;
switch(block_pos) { if (block_val & (0x80 >> block_pos)) {
case 0: if((block_val & 0x80) != 0) { return_val = 1; } break; return_val = 1;
case 1: if((block_val & 0x40) != 0) { return_val = 1; } break;
case 2: if((block_val & 0x20) != 0) { return_val = 1; } break;
case 3: if((block_val & 0x10) != 0) { return_val = 1; } break;
case 4: if((block_val & 0x08) != 0) { return_val = 1; } break;
case 5: if((block_val & 0x04) != 0) { return_val = 1; } break;
case 6: if((block_val & 0x02) != 0) { return_val = 1; } break;
case 7: if((block_val & 0x01) != 0) { return_val = 1; } break;
} }
return return_val; return return_val;
} }
void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset) void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset) {
{
/* Central bullseye in Maxicode symbols */ /* Central bullseye in Maxicode symbols */
int i, j; int i, j;
@ -553,8 +536,7 @@ void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset)
} }
} }
void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) {
{
/* Put a hexagon into the pixel buffer */ /* Put a hexagon into the pixel buffer */
int i, j; int i, j;
@ -567,16 +549,19 @@ void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn)
} }
} }
void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int smalltext, int image_width, int image_height) void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int smalltext, int image_width, int image_height) {
{
/* Put a letter into a position */ /* Put a letter into a position */
int skip, i, j, glyph_no, alphabet; int skip, i, j, glyph_no, alphabet;
skip = 0; skip = 0;
alphabet = 0; alphabet = 0;
if(letter < 33) { skip = 1; } if (letter < 33) {
if((letter > 127) && (letter < 161)) { skip = 1; } skip = 1;
}
if ((letter > 127) && (letter < 161)) {
skip = 1;
}
if (skip == 0) { if (skip == 0) {
if (letter > 128) { if (letter > 128) {
@ -618,9 +603,8 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int
} }
} }
void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int smalltext, int image_width, int image_height)
{
/* Plot a string into the pixel buffer */ /* Plot a string into the pixel buffer */
void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int smalltext, int image_width, int image_height) {
int i, string_length, string_left_hand; int i, string_length, string_left_hand;
string_length = strlen(input_string); string_length = strlen(input_string);
@ -632,8 +616,7 @@ void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int sm
} }
int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) {
{
int i, row, column, xposn, yposn; int i, row, column, xposn, yposn;
int image_height, image_width; int image_height, image_width;
char *pixelbuf; char *pixelbuf;
@ -691,8 +674,7 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
} }
/* Convert UTF-8 to Latin1 Codepage for the interpretation line */ /* Convert UTF-8 to Latin1 Codepage for the interpretation line */
void to_latin1(unsigned char source[], unsigned char preprocessed[]) void to_latin1(unsigned char source[], unsigned char preprocessed[]) {
{
int j, i, input_length; int j, i, input_length;
input_length = ustrlen(source); input_length = ustrlen(source);
@ -730,8 +712,7 @@ void to_latin1(unsigned char source[], unsigned char preprocessed[])
return; return;
} }
int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) {
{
int textdone, main_width, comp_offset, large_bar_count; int textdone, main_width, comp_offset, large_bar_count;
char textpart[10], addon[6]; char textpart[10], addon[6];
float addon_text_posn, preset_height, large_bar_height; float addon_text_posn, preset_height, large_bar_height;
@ -1135,8 +1116,8 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
} }
#ifndef NO_PNG #ifndef NO_PNG
int png_handle(struct zint_symbol *symbol, int rotate_angle)
{ int png_handle(struct zint_symbol *symbol, int rotate_angle) {
int error; int error;
if (symbol->symbology == BARCODE_MAXICODE) { if (symbol->symbology == BARCODE_MAXICODE) {
@ -1150,8 +1131,7 @@ int png_handle(struct zint_symbol *symbol, int rotate_angle)
} }
#endif /* NO_PNG */ #endif /* NO_PNG */
int bmp_handle(struct zint_symbol *symbol, int rotate_angle) int bmp_handle(struct zint_symbol *symbol, int rotate_angle) {
{
int error; int error;
if (symbol->symbology == BARCODE_MAXICODE) { if (symbol->symbology == BARCODE_MAXICODE) {
@ -1162,4 +1142,3 @@ int bmp_handle(struct zint_symbol *symbol, int rotate_angle)
return error; return error;
} }

View File

@ -1,7 +1,8 @@
/* postal.c - Handles PostNet, PLANET, FIM. RM4SCC and Flattermarken */ /* postal.c - Handles PostNet, PLANET, FIM. RM4SCC and Flattermarken */
/* Zint - A barcode generating program using libpng /*
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> libzint - the open source barcode library
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Including bug fixes by Bryan Hatton Including bug fixes by Bryan Hatton
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -45,33 +46,46 @@
#define SHKASUTSET "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define SHKASUTSET "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
/* PostNet number encoding table - In this table L is long as S is short */ /* PostNet number encoding table - In this table L is long as S is short */
static const char *PNTable[10] = {"LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS", "SLLSS", "LSSSL", static const char *PNTable[10] = {
"LSSLS", "LSLSS"}; "LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS", "SLLSS", "LSSSL",
static const char *PLTable[10] = {"SSLLL", "LLLSS", "LLSLS", "LLSSL", "LSLLS", "LSLSL", "LSSLL", "SLLLS", "LSSLS", "LSLSS"
"SLLSL", "SLSLL"}; };
static const char *RoyalValues[36] = {"11", "12", "13", "14", "15", "10", "21", "22", "23", "24", "25", static const char *PLTable[10] = {
"SSLLL", "LLLSS", "LLSLS", "LLSSL", "LSLLS", "LSLSL", "LSSLL", "SLLLS",
"SLLSL", "SLSLL"
};
static const char *RoyalValues[36] = {
"11", "12", "13", "14", "15", "10", "21", "22", "23", "24", "25",
"20", "31", "32", "33", "34", "35", "30", "41", "42", "43", "44", "45", "40", "51", "52", "20", "31", "32", "33", "34", "35", "30", "41", "42", "43", "44", "45", "40", "51", "52",
"53", "54", "55", "50", "01", "02", "03", "04", "05", "00"}; "53", "54", "55", "50", "01", "02", "03", "04", "05", "00"
};
/* 0 = Full, 1 = Ascender, 2 = Descender, 3 = Tracker */ /* 0 = Full, 1 = Ascender, 2 = Descender, 3 = Tracker */
static const char *RoyalTable[36] = {"3300", "3210", "3201", "2310", "2301", "2211", "3120", "3030", "3021", static const char *RoyalTable[36] = {
"3300", "3210", "3201", "2310", "2301", "2211", "3120", "3030", "3021",
"2130", "2121", "2031", "3102", "3012", "3003", "2112", "2103", "2013", "1320", "1230", "2130", "2121", "2031", "3102", "3012", "3003", "2112", "2103", "2013", "1320", "1230",
"1221", "0330", "0321", "0231", "1302", "1212", "1203", "0312", "0303", "0213", "1122", "1221", "0330", "0321", "0231", "1302", "1212", "1203", "0312", "0303", "0213", "1122",
"1032", "1023", "0132", "0123", "0033"}; "1032", "1023", "0132", "0123", "0033"
};
static const char *FlatTable[10] = {"0504", "18", "0117", "0216", "0315", "0414", "0513", "0612", "0711", static const char *FlatTable[10] = {
"0810"}; "0504", "18", "0117", "0216", "0315", "0414", "0513", "0612", "0711", "0810"
};
static const char *KoreaTable[10] = {"1313150613", "0713131313", "0417131313", "1506131313", static const char *KoreaTable[10] = {
"0413171313", "17171313", "1315061313", "0413131713", "17131713", "13171713"}; "1313150613", "0713131313", "0417131313", "1506131313",
"0413171313", "17171313", "1315061313", "0413131713", "17131713", "13171713"
};
static const char *JapanTable[19] = {"114", "132", "312", "123", "141", "321", "213", "231", "411", "144", static const char *JapanTable[19] = {
"414", "324", "342", "234", "432", "243", "423", "441", "111"}; "114", "132", "312", "123", "141", "321", "213", "231", "411", "144",
"414", "324", "342", "234", "432", "243", "423", "441", "111"
};
int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length)
{
/* Handles the PostNet system used for Zip codes in the US */ /* Handles the PostNet system used for Zip codes in the US */
int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
unsigned int i, sum, check_digit; unsigned int i, sum, check_digit;
int error_number; int error_number;
@ -91,8 +105,7 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
/* start character */ /* start character */
strcpy(dest, "L"); strcpy(dest, "L");
for (i=0; i < length; i++) for (i = 0; i < length; i++) {
{
lookup(NEON, PNTable, source[i], dest); lookup(NEON, PNTable, source[i], dest);
sum += ctoi(source[i]); sum += ctoi(source[i]);
} }
@ -106,9 +119,8 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
return error_number; return error_number;
} }
int post_plot(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* Puts PostNet barcodes into the pattern matrix */ /* Puts PostNet barcodes into the pattern matrix */
int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */ char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */
unsigned int loopey, h; unsigned int loopey, h;
int writer; int writer;
@ -123,10 +135,8 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[], int length)
writer = 0; writer = 0;
h = strlen(height_pattern); h = strlen(height_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if (height_pattern[loopey] == 'L') {
if(height_pattern[loopey] == 'L')
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
@ -140,9 +150,8 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length)
{
/* Handles the PLANET system used for item tracking in the US */ /* Handles the PLANET system used for item tracking in the US */
int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
unsigned int i, sum, check_digit; unsigned int i, sum, check_digit;
int error_number; int error_number;
@ -162,8 +171,7 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
/* start character */ /* start character */
strcpy(dest, "L"); strcpy(dest, "L");
for (i=0; i < length; i++) for (i = 0; i < length; i++) {
{
lookup(NEON, PLTable, source[i], dest); lookup(NEON, PLTable, source[i], dest);
sum += ctoi(source[i]); sum += ctoi(source[i]);
} }
@ -177,9 +185,8 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
return error_number; return error_number;
} }
int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* Puts PLANET barcodes into the pattern matrix */ /* Puts PLANET barcodes into the pattern matrix */
int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */ char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */
unsigned int loopey, h; unsigned int loopey, h;
int writer; int writer;
@ -194,10 +201,8 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
writer = 0; writer = 0;
h = strlen(height_pattern); h = strlen(height_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if (height_pattern[loopey] == 'L') {
if(height_pattern[loopey] == 'L')
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
@ -210,9 +215,8 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) /* Korean Postal Authority */
{ /* Korean Postal Authority */ int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) {
int total, loop, check, zeroes, error_number; int total, loop, check, zeroes, error_number;
char localstr[8], dest[80]; char localstr[8], dest[80];
@ -235,7 +239,9 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[], int length)
total += ctoi(localstr[loop]); total += ctoi(localstr[loop]);
} }
check = 10 - (total % 10); check = 10 - (total % 10);
if(check == 10) { check = 0; } if (check == 10) {
check = 0;
}
localstr[6] = itoc(check); localstr[6] = itoc(check);
localstr[7] = '\0'; localstr[7] = '\0';
*dest = '\0'; *dest = '\0';
@ -248,10 +254,10 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int fim(struct zint_symbol *symbol, unsigned char source[], int length) /* The simplest barcode symbology ever! Supported by MS Word, so here it is!
{ glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */
/* The simplest barcode symbology ever! Supported by MS Word, so here it is! */ int fim(struct zint_symbol *symbol, unsigned char source[], int length) {
/* glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */
char dest[16] = {0}; char dest[16] = {0};
@ -287,9 +293,8 @@ int fim(struct zint_symbol *symbol, unsigned char source[], int length)
return 0; return 0;
} }
char rm4scc(char source[], unsigned char dest[], int length)
{
/* Handles the 4 State barcodes used in the UK by Royal Mail */ /* Handles the 4 State barcodes used in the UK by Royal Mail */
char rm4scc(char source[], unsigned char dest[], int length) {
unsigned int i; unsigned int i;
int top, bottom, row, column, check_digit; int top, bottom, row, column, check_digit;
char values[3], set_copy[] = KRSET; char values[3], set_copy[] = KRSET;
@ -310,8 +315,12 @@ char rm4scc(char source[], unsigned char dest[], int length)
/* Calculate the check digit */ /* Calculate the check digit */
row = (top % 6) - 1; row = (top % 6) - 1;
column = (bottom % 6) - 1; column = (bottom % 6) - 1;
if(row == -1) { row = 5; } if (row == -1) {
if(column == -1) { column = 5; } row = 5;
}
if (column == -1) {
column = 5;
}
check_digit = (6 * row) + column; check_digit = (6 * row) + column;
concat((char*) dest, RoyalTable[check_digit]); concat((char*) dest, RoyalTable[check_digit]);
@ -321,9 +330,8 @@ char rm4scc(char source[], unsigned char dest[], int length)
return set_copy[check_digit]; return set_copy[check_digit];
} }
int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* Puts RM4SCC into the data matrix */ /* Puts RM4SCC into the data matrix */
int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[200]; char height_pattern[200];
unsigned int loopey, h; unsigned int loopey, h;
int writer; int writer;
@ -346,15 +354,12 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
writer = 0; writer = 0;
h = strlen(height_pattern); h = strlen(height_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
{
set_module(symbol, 2, writer); set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
@ -369,11 +374,10 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) /* Handles Dutch Post TNT KIX symbols
{ The same as RM4SCC but without check digit
/* Handles Dutch Post TNT KIX symbols */ Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
/* The same as RM4SCC but without check digit */ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
char height_pattern[50], localstr[20]; char height_pattern[50], localstr[20];
unsigned int loopey; unsigned int loopey;
int writer, i, h; int writer, i, h;
@ -393,10 +397,6 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
/* Add leading zeroes */
/* zeroes = 11 - length;
memset(localstr, '0', zeroes);
strcpy(localstr + zeroes, (char *)source);*/
strcpy(localstr, (char *) source); strcpy(localstr, (char *) source);
/* Encode data */ /* Encode data */
@ -406,15 +406,12 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
writer = 0; writer = 0;
h = strlen(height_pattern); h = strlen(height_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
{
set_module(symbol, 2, writer); set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
@ -429,10 +426,8 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int daft_code(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* Handles DAFT Code symbols */ /* Handles DAFT Code symbols */
/* Presumably 'daft' doesn't mean the same thing in Germany as it does in the UK! */ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[100]; char height_pattern[100];
unsigned int loopey, h; unsigned int loopey, h;
int writer, i, error_number; int writer, i, error_number;
@ -452,23 +447,28 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length)
} }
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if(source[i] == 'D') { concat(height_pattern, "2"); } if (source[i] == 'D') {
if(source[i] == 'A') { concat(height_pattern, "1"); } concat(height_pattern, "2");
if(source[i] == 'F') { concat(height_pattern, "0"); } }
if(source[i] == 'T') { concat(height_pattern, "3"); } if (source[i] == 'A') {
concat(height_pattern, "1");
}
if (source[i] == 'F') {
concat(height_pattern, "0");
}
if (source[i] == 'T') {
concat(height_pattern, "3");
}
} }
writer = 0; writer = 0;
h = strlen(height_pattern); h = strlen(height_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
{
set_module(symbol, 2, writer); set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
@ -483,9 +483,8 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) /* Flattermarken - Not really a barcode symbology! */
{ /* Flattermarken - Not really a barcode symbology and (in my opinion) probably not much use int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) {
but it's supported by TBarCode so it's supported by Zint! */
int loop, error_number; int loop, error_number;
char dest[512]; /* 90 * 4 + 1 ~ */ char dest[512]; /* 90 * 4 + 1 ~ */
@ -509,8 +508,8 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length
return error_number; return error_number;
} }
int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) /* Japanese Postal Code (Kasutama Barcode) */
{ /* Japanese Postal Code (Kasutama Barcode) */ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number, h; int error_number, h;
char pattern[69]; char pattern[69];
int writer, loopey, inter_posn, i, sum, check; int writer, loopey, inter_posn, i, sum, check;
@ -573,32 +572,35 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length)
for (i = 0; i < 20; i++) { for (i = 0; i < 20; i++) {
concat(pattern, JapanTable[posn(KASUTSET, inter[i])]); concat(pattern, JapanTable[posn(KASUTSET, inter[i])]);
sum += posn(CHKASUTSET, inter[i]); sum += posn(CHKASUTSET, inter[i]);
/* printf("%c (%d)\n", inter[i], posn(CHKASUTSET, inter[i])); */
} }
/* Calculate check digit */ /* Calculate check digit */
check = 19 - (sum % 19); check = 19 - (sum % 19);
if(check == 19) { check = 0; } if (check == 19) {
if(check <= 9) { check_char = check + '0'; } check = 0;
if(check == 10) { check_char = '-'; } }
if(check >= 11) { check_char = (check - 11) + 'a'; } if (check <= 9) {
check_char = check + '0';
}
if (check == 10) {
check_char = '-';
}
if (check >= 11) {
check_char = (check - 11) + 'a';
}
concat(pattern, JapanTable[posn(KASUTSET, check_char)]); concat(pattern, JapanTable[posn(KASUTSET, check_char)]);
/* printf("check %c (%d)\n", check_char, check); */
concat(pattern, "31"); /* Stop */ concat(pattern, "31"); /* Stop */
/* Resolve pattern to 4-state symbols */ /* Resolve pattern to 4-state symbols */
writer = 0; writer = 0;
h = strlen(pattern); h = strlen(pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) {
if((pattern[loopey] == '2') || (pattern[loopey] == '1'))
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
if((pattern[loopey] == '3') || (pattern[loopey] == '1')) if ((pattern[loopey] == '3') || (pattern[loopey] == '1')) {
{
set_module(symbol, 2, writer); set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;