mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Code format and audit, part 2
Update copyright info, remove unused code, etc.
This commit is contained in:
parent
77cdf77690
commit
8a88ffdd7b
@ -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;
|
||||||
|
217
backend/imail.c
217
backend/imail.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence"
|
/* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence"
|
||||||
is Copyright (C) 2006 United States Postal Service */
|
is Copyright (C) 2006 United States Postal Service */
|
||||||
@ -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
|
||||||
@ -215,11 +221,8 @@ 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,9 +231,8 @@ 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
|
||||||
FrameCheckSequence = (FrameCheckSequence << 1);
|
FrameCheckSequence = (FrameCheckSequence << 1);
|
||||||
@ -238,13 +240,11 @@ 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 {
|
||||||
FrameCheckSequence = (FrameCheckSequence << 1);
|
FrameCheckSequence = (FrameCheckSequence << 1);
|
||||||
@ -256,69 +256,67 @@ 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++) {
|
||||||
fcs_bit[i] = 0;
|
fcs_bit[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(usps_crc >= 4096) {
|
if (usps_crc >= 4096) {
|
||||||
fcs_bit[12] = 1;
|
fcs_bit[12] = 1;
|
||||||
usps_crc -= 4096;
|
usps_crc -= 4096;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 2048) {
|
if (usps_crc >= 2048) {
|
||||||
fcs_bit[11] = 1;
|
fcs_bit[11] = 1;
|
||||||
usps_crc -= 2048;
|
usps_crc -= 2048;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 1024) {
|
if (usps_crc >= 1024) {
|
||||||
fcs_bit[10] = 1;
|
fcs_bit[10] = 1;
|
||||||
usps_crc -= 1024;
|
usps_crc -= 1024;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 512) {
|
if (usps_crc >= 512) {
|
||||||
fcs_bit[9] = 1;
|
fcs_bit[9] = 1;
|
||||||
usps_crc -= 512;
|
usps_crc -= 512;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 256) {
|
if (usps_crc >= 256) {
|
||||||
fcs_bit[8] = 1;
|
fcs_bit[8] = 1;
|
||||||
usps_crc -= 256;
|
usps_crc -= 256;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 128) {
|
if (usps_crc >= 128) {
|
||||||
fcs_bit[7] = 1;
|
fcs_bit[7] = 1;
|
||||||
usps_crc -= 128;
|
usps_crc -= 128;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 64) {
|
if (usps_crc >= 64) {
|
||||||
fcs_bit[6] = 1;
|
fcs_bit[6] = 1;
|
||||||
usps_crc -= 64;
|
usps_crc -= 64;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 32) {
|
if (usps_crc >= 32) {
|
||||||
fcs_bit[5] = 1;
|
fcs_bit[5] = 1;
|
||||||
usps_crc -= 32;
|
usps_crc -= 32;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 16) {
|
if (usps_crc >= 16) {
|
||||||
fcs_bit[4] = 1;
|
fcs_bit[4] = 1;
|
||||||
usps_crc -= 16;
|
usps_crc -= 16;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 8) {
|
if (usps_crc >= 8) {
|
||||||
fcs_bit[3] = 1;
|
fcs_bit[3] = 1;
|
||||||
usps_crc -= 8;
|
usps_crc -= 8;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 4) {
|
if (usps_crc >= 4) {
|
||||||
fcs_bit[2] = 1;
|
fcs_bit[2] = 1;
|
||||||
usps_crc -= 4;
|
usps_crc -= 4;
|
||||||
}
|
}
|
||||||
if(usps_crc >= 2) {
|
if (usps_crc >= 2) {
|
||||||
fcs_bit[1] = 1;
|
fcs_bit[1] = 1;
|
||||||
usps_crc -= 2;
|
usps_crc -= 2;
|
||||||
}
|
}
|
||||||
if(usps_crc == 1) {
|
if (usps_crc == 1) {
|
||||||
fcs_bit[0] = 1;
|
fcs_bit[0] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -332,12 +330,12 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 32) {
|
if (length > 32) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SODIUM, source, length);
|
error_number = is_sane(SODIUM, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
@ -349,13 +347,13 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
read = 0;
|
read = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
for(i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
if(source[i] == '-') {
|
if (source[i] == '-') {
|
||||||
tracker[read] = '\0';
|
tracker[read] = '\0';
|
||||||
j = 1;
|
j = 1;
|
||||||
read = 0;
|
read = 0;
|
||||||
} else {
|
} else {
|
||||||
if(j == 0) {
|
if (j == 0) {
|
||||||
/* reading tracker */
|
/* reading tracker */
|
||||||
tracker[read] = source[i];
|
tracker[read] = source[i];
|
||||||
read++;
|
read++;
|
||||||
@ -366,17 +364,17 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(j == 0) {
|
if (j == 0) {
|
||||||
tracker[read] = '\0';
|
tracker[read] = '\0';
|
||||||
} else {
|
} else {
|
||||||
zip[read] = '\0';
|
zip[read] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(tracker) != 20) {
|
if (strlen(tracker) != 20) {
|
||||||
strcpy(symbol->errtxt, "Invalid length tracking code");
|
strcpy(symbol->errtxt, "Invalid length tracking code");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
if(strlen(zip) > 11) {
|
if (strlen(zip) > 11) {
|
||||||
strcpy(symbol->errtxt, "Invalid ZIP code");
|
strcpy(symbol->errtxt, "Invalid ZIP code");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
@ -385,17 +383,17 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* Routing code first */
|
/* Routing code first */
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
accum[i] = 0;
|
accum[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(read = 0; read < strlen(zip); read++) {
|
for (read = 0; read < strlen(zip); read++) {
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
x_reg[i] = accum[i];
|
x_reg[i] = accum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
binary_add(accum, x_reg);
|
binary_add(accum, x_reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,7 +401,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1];
|
x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1];
|
||||||
x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2];
|
x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2];
|
||||||
x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3];
|
x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3];
|
||||||
for(i = 4; i < 112; i++) {
|
for (i = 4; i < 112; i++) {
|
||||||
x_reg[i] = 0;
|
x_reg[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,17 +410,17 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* add weight to routing code */
|
/* add weight to routing code */
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
x_reg[i] = accum[i];
|
x_reg[i] = accum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(zip) > 9) {
|
if (strlen(zip) > 9) {
|
||||||
strcpy(zip_adder, "1000100001");
|
strcpy(zip_adder, "1000100001");
|
||||||
} else {
|
} else {
|
||||||
if(strlen(zip) > 5) {
|
if (strlen(zip) > 5) {
|
||||||
strcpy(zip_adder, "100001");
|
strcpy(zip_adder, "100001");
|
||||||
} else {
|
} else {
|
||||||
if(strlen(zip) > 0) {
|
if (strlen(zip) > 0) {
|
||||||
strcpy(zip_adder, "1");
|
strcpy(zip_adder, "1");
|
||||||
} else {
|
} else {
|
||||||
strcpy(zip_adder, "0");
|
strcpy(zip_adder, "0");
|
||||||
@ -430,17 +428,17 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
accum[i] = 0;
|
accum[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(read = 0; read < strlen(zip_adder); read++) {
|
for (read = 0; read < strlen(zip_adder); read++) {
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
y_reg[i] = accum[i];
|
y_reg[i] = accum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
binary_add(accum, y_reg);
|
binary_add(accum, y_reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +446,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1];
|
y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1];
|
||||||
y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2];
|
y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2];
|
||||||
y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3];
|
y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3];
|
||||||
for(i = 4; i < 112; i++) {
|
for (i = 4; i < 112; i++) {
|
||||||
y_reg[i] = 0;
|
y_reg[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,11 +458,11 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
/* tracking code */
|
/* tracking code */
|
||||||
|
|
||||||
/* multiply by 10 */
|
/* multiply by 10 */
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
y_reg[i] = accum[i];
|
y_reg[i] = accum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
binary_add(accum, y_reg);
|
binary_add(accum, y_reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,18 +471,18 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1];
|
y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1];
|
||||||
y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2];
|
y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2];
|
||||||
y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3];
|
y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3];
|
||||||
for(i = 4; i < 112; i++) {
|
for (i = 4; i < 112; i++) {
|
||||||
y_reg[i] = 0;
|
y_reg[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
binary_add(accum, y_reg);
|
binary_add(accum, y_reg);
|
||||||
|
|
||||||
/* multiply by 5 */
|
/* multiply by 5 */
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
y_reg[i] = accum[i];
|
y_reg[i] = accum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
binary_add(accum, y_reg);
|
binary_add(accum, y_reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +491,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1];
|
y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1];
|
||||||
y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2];
|
y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2];
|
||||||
y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3];
|
y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3];
|
||||||
for(i = 4; i < 112; i++) {
|
for (i = 4; i < 112; i++) {
|
||||||
y_reg[i] = 0;
|
y_reg[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,13 +499,13 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* and then the rest */
|
/* and then the rest */
|
||||||
|
|
||||||
for(read = 2; read < strlen(tracker); read++) {
|
for (read = 2; read < strlen(tracker); read++) {
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
y_reg[i] = accum[i];
|
y_reg[i] = accum[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
binary_add(accum, y_reg);
|
binary_add(accum, y_reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,23 +513,20 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1];
|
y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1];
|
||||||
y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2];
|
y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2];
|
||||||
y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3];
|
y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3];
|
||||||
for(i = 4; i < 112; i++) {
|
for (i = 4; i < 112; i++) {
|
||||||
y_reg[i] = 0;
|
y_reg[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
accum[102] = 0;
|
accum[102] = 0;
|
||||||
|
|
||||||
memset(byte_array, 0, 13);
|
memset(byte_array, 0, 13);
|
||||||
for(j = 0; j < 13; j++) {
|
for (j = 0; j < 13; j++) {
|
||||||
i = 96 - (8 * j);
|
i = 96 - (8 * j);
|
||||||
byte_array[j] = 0;
|
byte_array[j] = 0;
|
||||||
byte_array[j] += accum[i];
|
byte_array[j] += accum[i];
|
||||||
@ -545,12 +540,11 @@ 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 *** */
|
||||||
|
|
||||||
/* start with codeword J which is base 636 */
|
/* start with codeword J which is base 636 */
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
x_reg[i] = 0;
|
x_reg[i] = 0;
|
||||||
y_reg[i] = 0;
|
y_reg[i] = 0;
|
||||||
}
|
}
|
||||||
@ -562,9 +556,9 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
x_reg[95] = 1;
|
x_reg[95] = 1;
|
||||||
x_reg[94] = 1;
|
x_reg[94] = 1;
|
||||||
|
|
||||||
for(i = 92; i >= 0; i--) {
|
for (i = 92; i >= 0; i--) {
|
||||||
y_reg[i] = islarger(accum, x_reg);
|
y_reg[i] = islarger(accum, x_reg);
|
||||||
if(y_reg[i] == 1) {
|
if (y_reg[i] == 1) {
|
||||||
binary_subtract(accum, x_reg);
|
binary_subtract(accum, x_reg);
|
||||||
}
|
}
|
||||||
shiftdown(x_reg);
|
shiftdown(x_reg);
|
||||||
@ -576,8 +570,8 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* then codewords I to B with base 1365 */
|
/* then codewords I to B with base 1365 */
|
||||||
|
|
||||||
for(j = 8; j > 0; j--) {
|
for (j = 8; j > 0; j--) {
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
accum[i] = y_reg[i];
|
accum[i] = y_reg[i];
|
||||||
y_reg[i] = 0;
|
y_reg[i] = 0;
|
||||||
x_reg[i] = 0;
|
x_reg[i] = 0;
|
||||||
@ -588,9 +582,9 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
x_reg[95] = 1;
|
x_reg[95] = 1;
|
||||||
x_reg[93] = 1;
|
x_reg[93] = 1;
|
||||||
x_reg[91] = 1;
|
x_reg[91] = 1;
|
||||||
for(i = 91; i >= 0; i--) {
|
for (i = 91; i >= 0; i--) {
|
||||||
y_reg[i] = islarger(accum, x_reg);
|
y_reg[i] = islarger(accum, x_reg);
|
||||||
if(y_reg[i] == 1) {
|
if (y_reg[i] == 1) {
|
||||||
binary_subtract(accum, x_reg);
|
binary_subtract(accum, x_reg);
|
||||||
}
|
}
|
||||||
shiftdown(x_reg);
|
shiftdown(x_reg);
|
||||||
@ -607,79 +601,55 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
(y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) +
|
(y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) +
|
||||||
(y_reg[1] * 2) + y_reg[0];
|
(y_reg[1] * 2) + y_reg[0];
|
||||||
|
|
||||||
for(i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
if(codeword[i] == 1365) {
|
if (codeword[i] == 1365) {
|
||||||
codeword[i] = 0;
|
codeword[i] = 0;
|
||||||
codeword[i + 1]++;
|
codeword[i + 1]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
||||||
|
|
||||||
if(usps_crc >= 1024) {
|
if (usps_crc >= 1024) {
|
||||||
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++) {
|
||||||
if(codeword[i] < 1287) {
|
if (codeword[i] < 1287) {
|
||||||
characters[i] = AppxD_I[codeword[i]];
|
characters[i] = AppxD_I[codeword[i]];
|
||||||
} else {
|
} else {
|
||||||
characters[i] = AppxD_II[codeword[i] - 1287];
|
characters[i] = AppxD_II[codeword[i] - 1287];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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++) {
|
||||||
if(bit_pattern[i] == 1) {
|
if (bit_pattern[i] == 1) {
|
||||||
characters[i] = 0x1FFF - characters[i];
|
characters[i] = 0x1FFF - characters[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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++) {
|
||||||
breakup(bit_pattern, characters[i]);
|
breakup(bit_pattern, characters[i]);
|
||||||
for(j = 0; j < 13; j++) {
|
for (j = 0; j < 13; j++) {
|
||||||
bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j];
|
bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(data_pattern, "");
|
strcpy(data_pattern, "");
|
||||||
temp[1] = '\0';
|
temp[1] = '\0';
|
||||||
for(i = 0; i < 65; i++) {
|
for (i = 0; i < 65; i++) {
|
||||||
j = 0;
|
j = 0;
|
||||||
if(bar_map[i] == 0)
|
if (bar_map[i] == 0)
|
||||||
j += 1;
|
j += 1;
|
||||||
if(bar_map[i + 65] == 0)
|
if (bar_map[i + 65] == 0)
|
||||||
j += 2;
|
j += 2;
|
||||||
temp[0] = itoc(j);
|
temp[0] = itoc(j);
|
||||||
concat(data_pattern, temp);
|
concat(data_pattern, temp);
|
||||||
@ -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;
|
||||||
|
117
backend/large.c
117
backend/large.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -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,14 +105,14 @@ 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];
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
if(input_buffer[i] == 0) {
|
if (input_buffer[i] == 0) {
|
||||||
sub_buffer[i] = 1;
|
sub_buffer[i] = 1;
|
||||||
} else {
|
} else {
|
||||||
sub_buffer[i] = 0;
|
sub_buffer[i] = 0;
|
||||||
@ -114,37 +122,34 @@ void binary_subtract(short int accumulator[], short int input_buffer[])
|
|||||||
|
|
||||||
sub_buffer[0] = 1;
|
sub_buffer[0] = 1;
|
||||||
|
|
||||||
for(i = 1; i < 112; i++) {
|
for (i = 1; i < 112; i++) {
|
||||||
sub_buffer[i] = 0;
|
sub_buffer[i] = 0;
|
||||||
}
|
}
|
||||||
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;
|
||||||
buffer[103] = 0;
|
buffer[103] = 0;
|
||||||
|
|
||||||
for(i = 0; i < 102; i++) {
|
for (i = 0; i < 102; i++) {
|
||||||
buffer[i] = buffer[i + 1];
|
buffer[i] = buffer[i + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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--) {
|
||||||
buffer[i] = buffer[i - 1];
|
buffer[i] = buffer[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -153,11 +158,11 @@ short int islarger(short int accum[], short int reg[])
|
|||||||
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if((accum[i] == 1) && (reg[i] == 0)) {
|
if ((accum[i] == 1) && (reg[i] == 0)) {
|
||||||
latch = 1;
|
latch = 1;
|
||||||
larger = 1;
|
larger = 1;
|
||||||
}
|
}
|
||||||
if((accum[i] == 0) && (reg[i] == 1)) {
|
if ((accum[i] == 0) && (reg[i] == 1)) {
|
||||||
latch = 1;
|
latch = 1;
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
@ -166,22 +171,21 @@ 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};
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
reg[i] = 0;
|
reg[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(read = 0; read < src_len; read++) {
|
for (read = 0; read < src_len; read++) {
|
||||||
|
|
||||||
for(i = 0; i < 112; i++) {
|
for (i = 0; i < 112; i++) {
|
||||||
temp[i] = reg[i];
|
temp[i] = reg[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
binary_add(reg, temp);
|
binary_add(reg, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +193,7 @@ void binary_load(short int reg[], char data[], const unsigned int src_len)
|
|||||||
temp[1] = BCD[(ctoi(data[read]) * 4) + 1];
|
temp[1] = BCD[(ctoi(data[read]) * 4) + 1];
|
||||||
temp[2] = BCD[(ctoi(data[read]) * 4) + 2];
|
temp[2] = BCD[(ctoi(data[read]) * 4) + 2];
|
||||||
temp[3] = BCD[(ctoi(data[read]) * 4) + 3];
|
temp[3] = BCD[(ctoi(data[read]) * 4) + 3];
|
||||||
for(i = 4; i < 112; i++) {
|
for (i = 4; i < 112; i++) {
|
||||||
temp[i] = 0;
|
temp[i] = 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");
|
|
||||||
}
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes corrections thanks to Monica Swanson @ Source Technologies */
|
/* Includes corrections thanks to Monica Swanson @ Source Technologies */
|
||||||
|
|
||||||
@ -45,9 +45,8 @@
|
|||||||
|
|
||||||
int maxi_codeword[144];
|
int maxi_codeword[144];
|
||||||
|
|
||||||
void maxi_do_primary_check( )
|
/* Handles error correction of primary message */
|
||||||
{
|
void maxi_do_primary_check() {
|
||||||
/* Handles error correction of primary message */
|
|
||||||
unsigned char data[15];
|
unsigned char data[15];
|
||||||
unsigned char results[15];
|
unsigned char results[15];
|
||||||
int j;
|
int j;
|
||||||
@ -57,19 +56,18 @@ void maxi_do_primary_check( )
|
|||||||
rs_init_gf(0x43);
|
rs_init_gf(0x43);
|
||||||
rs_init_code(ecclen, 1);
|
rs_init_code(ecclen, 1);
|
||||||
|
|
||||||
for(j = 0; j < datalen; j += 1)
|
for (j = 0; j < datalen; j += 1)
|
||||||
data[j] = maxi_codeword[j];
|
data[j] = maxi_codeword[j];
|
||||||
|
|
||||||
rs_encode(datalen, data, results);
|
rs_encode(datalen, data, results);
|
||||||
|
|
||||||
for ( j = 0; j < ecclen; j += 1)
|
for (j = 0; j < ecclen; j += 1)
|
||||||
maxi_codeword[ datalen + j] = results[ecclen - 1 - j];
|
maxi_codeword[ datalen + j] = results[ecclen - 1 - j];
|
||||||
rs_free();
|
rs_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
void maxi_do_secondary_chk_odd( int ecclen )
|
/* Handles error correction of odd characters in secondary */
|
||||||
{
|
void maxi_do_secondary_chk_odd(int ecclen) {
|
||||||
/* Handles error correction of odd characters in secondary */
|
|
||||||
unsigned char data[100];
|
unsigned char data[100];
|
||||||
unsigned char results[30];
|
unsigned char results[30];
|
||||||
int j;
|
int j;
|
||||||
@ -81,20 +79,19 @@ void maxi_do_secondary_chk_odd( int ecclen )
|
|||||||
if (ecclen == 20)
|
if (ecclen == 20)
|
||||||
datalen = 84;
|
datalen = 84;
|
||||||
|
|
||||||
for(j = 0; j < datalen; j += 1)
|
for (j = 0; j < datalen; j += 1)
|
||||||
if (j & 1) // odd
|
if (j & 1) // odd
|
||||||
data[(j-1)/2] = maxi_codeword[j + 20];
|
data[(j - 1) / 2] = maxi_codeword[j + 20];
|
||||||
|
|
||||||
rs_encode(datalen/2, data, results);
|
rs_encode(datalen / 2, data, results);
|
||||||
|
|
||||||
for ( j = 0; j < (ecclen); j += 1)
|
for (j = 0; j < (ecclen); j += 1)
|
||||||
maxi_codeword[ datalen + (2 *j) + 1 + 20 ] = results[ecclen - 1 - j];
|
maxi_codeword[ datalen + (2 * j) + 1 + 20 ] = results[ecclen - 1 - j];
|
||||||
rs_free();
|
rs_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
void maxi_do_secondary_chk_even(int ecclen )
|
/* Handles error correction of even characters in secondary */
|
||||||
{
|
void maxi_do_secondary_chk_even(int ecclen) {
|
||||||
/* Handles error correction of even characters in secondary */
|
|
||||||
unsigned char data[100];
|
unsigned char data[100];
|
||||||
unsigned char results[30];
|
unsigned char results[30];
|
||||||
int j;
|
int j;
|
||||||
@ -106,43 +103,40 @@ void maxi_do_secondary_chk_even(int ecclen )
|
|||||||
rs_init_gf(0x43);
|
rs_init_gf(0x43);
|
||||||
rs_init_code(ecclen, 1);
|
rs_init_code(ecclen, 1);
|
||||||
|
|
||||||
for(j = 0; j < datalen + 1; j += 1)
|
for (j = 0; j < datalen + 1; j += 1)
|
||||||
if (!(j & 1)) // even
|
if (!(j & 1)) // even
|
||||||
data[j/2] = maxi_codeword[j + 20];
|
data[j / 2] = maxi_codeword[j + 20];
|
||||||
|
|
||||||
rs_encode(datalen/2, data, results);
|
rs_encode(datalen / 2, data, results);
|
||||||
|
|
||||||
for ( j = 0; j < (ecclen); j += 1)
|
for (j = 0; j < (ecclen); j += 1)
|
||||||
maxi_codeword[ datalen + (2 *j) + 20] = results[ecclen - 1 - j];
|
maxi_codeword[ datalen + (2 * j) + 20] = results[ecclen - 1 - j];
|
||||||
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 */
|
||||||
{
|
void maxi_bump(int set[], int character[], int bump_posn) {
|
||||||
/* Moves everything up so that a shift or latch can be inserted */
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 143; i > bump_posn; i--) {
|
for (i = 143; i > bump_posn; i--) {
|
||||||
set[i] = set[i - 1];
|
set[i] = set[i - 1];
|
||||||
character[i] = character[i - 1];
|
character[i] = character[i - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxi_text_process(int mode, unsigned char source[], int length)
|
/* Format text according to Appendix A */
|
||||||
{
|
int maxi_text_process(int mode, unsigned char source[], int length) {
|
||||||
/* Format text according to Appendix A */
|
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
|
||||||
int set[144], character[144], i, j, done, count, current_set;
|
int set[144], character[144], i, j, done, count, current_set;
|
||||||
|
|
||||||
if(length > 138) {
|
if (length > 138) {
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 144; i++) {
|
for (i = 0; i < 144; i++) {
|
||||||
set[i] = -1;
|
set[i] = -1;
|
||||||
character[i] = 0;
|
character[i] = 0;
|
||||||
}
|
}
|
||||||
@ -156,24 +150,24 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* If a character can be represented in more than one code set,
|
/* If a character can be represented in more than one code set,
|
||||||
pick which version to use */
|
pick which version to use */
|
||||||
if(set[0] == 0) {
|
if (set[0] == 0) {
|
||||||
if(character[0] == 13) {
|
if (character[0] == 13) {
|
||||||
character[0] = 0;
|
character[0] = 0;
|
||||||
}
|
}
|
||||||
set[0] = 1;
|
set[0] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < length; i++) {
|
for (i = 1; i < length; i++) {
|
||||||
if(set[i] == 0) {
|
if (set[i] == 0) {
|
||||||
done = 0;
|
done = 0;
|
||||||
/* Special character */
|
/* Special character */
|
||||||
if(character[i] == 13) {
|
if (character[i] == 13) {
|
||||||
/* Carriage Return */
|
/* Carriage Return */
|
||||||
if(set[i - 1] == 5) {
|
if (set[i - 1] == 5) {
|
||||||
character[i] = 13;
|
character[i] = 13;
|
||||||
set[i] = 5;
|
set[i] = 5;
|
||||||
} else {
|
} else {
|
||||||
if((i != length - 1) && (set[i + 1] == 5)) {
|
if ((i != length - 1) && (set[i + 1] == 5)) {
|
||||||
character[i] = 13;
|
character[i] = 13;
|
||||||
set[i] = 5;
|
set[i] = 5;
|
||||||
} else {
|
} else {
|
||||||
@ -184,9 +178,9 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 28) && (done == 0)) {
|
if ((character[i] == 28) && (done == 0)) {
|
||||||
/* FS */
|
/* FS */
|
||||||
if(set[i - 1] == 5) {
|
if (set[i - 1] == 5) {
|
||||||
character[i] = 32;
|
character[i] = 32;
|
||||||
set[i] = 5;
|
set[i] = 5;
|
||||||
} else {
|
} else {
|
||||||
@ -195,9 +189,9 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 29) && (done == 0)) {
|
if ((character[i] == 29) && (done == 0)) {
|
||||||
/* GS */
|
/* GS */
|
||||||
if(set[i - 1] == 5) {
|
if (set[i - 1] == 5) {
|
||||||
character[i] = 33;
|
character[i] = 33;
|
||||||
set[i] = 5;
|
set[i] = 5;
|
||||||
} else {
|
} else {
|
||||||
@ -206,9 +200,9 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 30) && (done == 0)) {
|
if ((character[i] == 30) && (done == 0)) {
|
||||||
/* RS */
|
/* RS */
|
||||||
if(set[i - 1] == 5) {
|
if (set[i - 1] == 5) {
|
||||||
character[i] = 34;
|
character[i] = 34;
|
||||||
set[i] = 5;
|
set[i] = 5;
|
||||||
} else {
|
} else {
|
||||||
@ -217,27 +211,27 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 32) && (done == 0)) {
|
if ((character[i] == 32) && (done == 0)) {
|
||||||
/* Space */
|
/* Space */
|
||||||
if(set[i - 1] == 1) {
|
if (set[i - 1] == 1) {
|
||||||
character[i] = 32;
|
character[i] = 32;
|
||||||
set[i] = 1;
|
set[i] = 1;
|
||||||
}
|
}
|
||||||
if(set[i - 1] == 2) {
|
if (set[i - 1] == 2) {
|
||||||
character[i] = 47;
|
character[i] = 47;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
}
|
}
|
||||||
if(set[i - 1] >= 3) {
|
if (set[i - 1] >= 3) {
|
||||||
if(i != length - 1) {
|
if (i != length - 1) {
|
||||||
if(set[i + 1] == 1) {
|
if (set[i + 1] == 1) {
|
||||||
character[i] = 32;
|
character[i] = 32;
|
||||||
set[i] = 1;
|
set[i] = 1;
|
||||||
}
|
}
|
||||||
if(set[i + 1] == 2) {
|
if (set[i + 1] == 2) {
|
||||||
character[i] = 47;
|
character[i] = 47;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
}
|
}
|
||||||
if(set[i + 1] >= 3) {
|
if (set[i + 1] >= 3) {
|
||||||
character[i] = 59;
|
character[i] = 59;
|
||||||
set[i] = set[i - 1];
|
set[i] = set[i - 1];
|
||||||
}
|
}
|
||||||
@ -249,13 +243,13 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 44) && (done == 0)) {
|
if ((character[i] == 44) && (done == 0)) {
|
||||||
/* Comma */
|
/* Comma */
|
||||||
if(set[i - 1] == 2) {
|
if (set[i - 1] == 2) {
|
||||||
character[i] = 48;
|
character[i] = 48;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
if((i != length - 1) && (set[i + 1] == 2)) {
|
if ((i != length - 1) && (set[i + 1] == 2)) {
|
||||||
character[i] = 48;
|
character[i] = 48;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
@ -265,13 +259,13 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 46) && (done == 0)) {
|
if ((character[i] == 46) && (done == 0)) {
|
||||||
/* Full Stop */
|
/* Full Stop */
|
||||||
if(set[i - 1] == 2) {
|
if (set[i - 1] == 2) {
|
||||||
character[i] = 49;
|
character[i] = 49;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
if((i != length - 1) && (set[i + 1] == 2)) {
|
if ((i != length - 1) && (set[i + 1] == 2)) {
|
||||||
character[i] = 49;
|
character[i] = 49;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
@ -281,13 +275,13 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 47) && (done == 0)) {
|
if ((character[i] == 47) && (done == 0)) {
|
||||||
/* Slash */
|
/* Slash */
|
||||||
if(set[i - 1] == 2) {
|
if (set[i - 1] == 2) {
|
||||||
character[i] = 50;
|
character[i] = 50;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
if((i != length - 1) && (set[i + 1] == 2)) {
|
if ((i != length - 1) && (set[i + 1] == 2)) {
|
||||||
character[i] = 50;
|
character[i] = 50;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
@ -297,13 +291,13 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((character[i] == 58) && (done == 0)) {
|
if ((character[i] == 58) && (done == 0)) {
|
||||||
/* Colon */
|
/* Colon */
|
||||||
if(set[i - 1] == 2) {
|
if (set[i - 1] == 2) {
|
||||||
character[i] = 51;
|
character[i] = 51;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
if((i != length - 1) && (set[i + 1] == 2)) {
|
if ((i != length - 1) && (set[i + 1] == 2)) {
|
||||||
character[i] = 51;
|
character[i] = 51;
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
@ -315,9 +309,9 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = length; i < 144; i++) {
|
for (i = length; i < 144; i++) {
|
||||||
/* Add the padding */
|
/* Add the padding */
|
||||||
if(set[length - 1] == 2) {
|
if (set[length - 1] == 2) {
|
||||||
set[i] = 2;
|
set[i] = 2;
|
||||||
} else {
|
} else {
|
||||||
set[i] = 1;
|
set[i] = 1;
|
||||||
@ -326,17 +320,21 @@ 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++) {
|
||||||
if((set[i] == 1) && ((character[i] >= 48) && (character[i] <= 57))) {
|
if ((set[i] == 1) && ((character[i] >= 48) && (character[i] <= 57))) {
|
||||||
/* Character is a number */
|
/* Character is a number */
|
||||||
count++;
|
count++;
|
||||||
} else {
|
} else {
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
if(count == 9) {
|
if (count == 9) {
|
||||||
/* Nine digits in a row can be compressed */
|
/* Nine digits in a row can be compressed */
|
||||||
set[i] = 6;
|
set[i] = 6;
|
||||||
set[i - 1] = 6;
|
set[i - 1] = 6;
|
||||||
@ -356,12 +354,12 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
|
|
||||||
if((set[i] != current_set) && (set[i] != 6)) {
|
if ((set[i] != current_set) && (set[i] != 6)) {
|
||||||
switch(set[i]) {
|
switch (set[i]) {
|
||||||
case 1:
|
case 1:
|
||||||
if(set[i + 1] == 1) {
|
if (set[i + 1] == 1) {
|
||||||
if(set[i + 2] == 1) {
|
if (set[i + 2] == 1) {
|
||||||
if(set[i + 3] == 1) {
|
if (set[i + 3] == 1) {
|
||||||
/* Latch A */
|
/* Latch A */
|
||||||
maxi_bump(set, character, i);
|
maxi_bump(set, character, i);
|
||||||
character[i] = 63;
|
character[i] = 63;
|
||||||
@ -389,7 +387,7 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(set[i + 1] == 2) {
|
if (set[i + 1] == 2) {
|
||||||
/* Latch B */
|
/* Latch B */
|
||||||
maxi_bump(set, character, i);
|
maxi_bump(set, character, i);
|
||||||
character[i] = 63;
|
character[i] = 63;
|
||||||
@ -424,7 +422,7 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
} while(i < 145);
|
} while (i < 145);
|
||||||
|
|
||||||
/* Number compression has not been forgotten! - It's handled below */
|
/* Number compression has not been forgotten! - It's handled below */
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -434,7 +432,7 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
char substring[11];
|
char substring[11];
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
for(j = 0; j < 9; j++) {
|
for (j = 0; j < 9; j++) {
|
||||||
substring[j] = character[i + j];
|
substring[j] = character[i + j];
|
||||||
}
|
}
|
||||||
substring[9] = '\0';
|
substring[9] = '\0';
|
||||||
@ -448,7 +446,7 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
character[i + 5] = (value & 0x3f);
|
character[i + 5] = (value & 0x3f);
|
||||||
|
|
||||||
i += 6;
|
i += 6;
|
||||||
for(j = i; j < 140; j++) {
|
for (j = i; j < 140; j++) {
|
||||||
set[j] = set[j + 3];
|
set[j] = set[j + 3];
|
||||||
character[j] = character[j + 3];
|
character[j] = character[j + 3];
|
||||||
}
|
}
|
||||||
@ -458,40 +456,40 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
|||||||
}
|
}
|
||||||
} while (i <= 143);
|
} while (i <= 143);
|
||||||
|
|
||||||
if(((mode ==2) || (mode == 3)) && (length > 84)) {
|
if (((mode == 2) || (mode == 3)) && (length > 84)) {
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((mode == 4) || (mode == 6)) && (length > 93)) {
|
if (((mode == 4) || (mode == 6)) && (length > 93)) {
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((mode == 5) && (length > 77)) {
|
if ((mode == 5) && (length > 77)) {
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Copy the encoded text into the codeword array */
|
/* Copy the encoded text into the codeword array */
|
||||||
if((mode == 2) || (mode == 3)) {
|
if ((mode == 2) || (mode == 3)) {
|
||||||
for(i = 0; i < 84; i++) { /* secondary only */
|
for (i = 0; i < 84; i++) { /* secondary only */
|
||||||
maxi_codeword[i + 20] = character[i];
|
maxi_codeword[i + 20] = character[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((mode == 4) || (mode == 6)) {
|
if ((mode == 4) || (mode == 6)) {
|
||||||
for(i = 0; i < 9; i++) { /* primary */
|
for (i = 0; i < 9; i++) { /* primary */
|
||||||
maxi_codeword[i + 1] = character[i];
|
maxi_codeword[i + 1] = character[i];
|
||||||
}
|
}
|
||||||
for(i = 0; i < 84; i++) { /* secondary */
|
for (i = 0; i < 84; i++) { /* secondary */
|
||||||
maxi_codeword[i + 20] = character[i + 9];
|
maxi_codeword[i + 20] = character[i + 9];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mode == 5) {
|
if (mode == 5) {
|
||||||
for(i = 0; i < 9; i++) { /* primary */
|
for (i = 0; i < 9; i++) { /* primary */
|
||||||
maxi_codeword[i + 1] = character[i];
|
maxi_codeword[i + 1] = character[i];
|
||||||
}
|
}
|
||||||
for(i = 0; i < 68; i++) { /* secondary */
|
for (i = 0; i < 68; i++) { /* secondary */
|
||||||
maxi_codeword[i + 20] = character[i + 9];
|
maxi_codeword[i + 20] = character[i + 9];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -499,13 +497,12 @@ 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 */
|
||||||
{
|
void maxi_do_primary_2(char postcode[], int country, int service) {
|
||||||
/* Format structured primary for Mode 2 */
|
|
||||||
int postcode_length, postcode_num, i;
|
int postcode_length, postcode_num, i;
|
||||||
|
|
||||||
for(i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
if((postcode[i] < '0') || (postcode[i] > '9')) {
|
if ((postcode[i] < '0') || (postcode[i] > '9')) {
|
||||||
postcode[i] = '\0';
|
postcode[i] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,19 +522,18 @@ 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 */
|
||||||
{
|
void maxi_do_primary_3(char postcode[], int country, int service) {
|
||||||
/* Format structured primary for Mode 3 */
|
|
||||||
int i, h;
|
int i, h;
|
||||||
|
|
||||||
h = strlen(postcode);
|
h = strlen(postcode);
|
||||||
to_upper((unsigned char*)postcode);
|
to_upper((unsigned char*) postcode);
|
||||||
for(i = 0; i < h; i++) {
|
for (i = 0; i < h; i++) {
|
||||||
if((postcode[i] >= 'A') && (postcode[i] <= 'Z')) {
|
if ((postcode[i] >= 'A') && (postcode[i] <= 'Z')) {
|
||||||
/* (Capital) letters shifted to Code Set A values */
|
/* (Capital) letters shifted to Code Set A values */
|
||||||
postcode[i] -= 64;
|
postcode[i] -= 64;
|
||||||
}
|
}
|
||||||
if(((postcode[i] == 27) || (postcode[i] == 31)) || ((postcode[i] == 33) || (postcode[i] >= 59))) {
|
if (((postcode[i] == 27) || (postcode[i] == 31)) || ((postcode[i] == 33) || (postcode[i] >= 59))) {
|
||||||
/* Not a valid postcode character */
|
/* Not a valid postcode character */
|
||||||
postcode[i] = ' ';
|
postcode[i] = ' ';
|
||||||
}
|
}
|
||||||
@ -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];
|
||||||
@ -566,7 +561,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
unsigned char local_source[length + 1];
|
unsigned char local_source[length + 1];
|
||||||
#else
|
#else
|
||||||
unsigned char* local_source = (unsigned char*)_alloca(length + 1);
|
unsigned char* local_source = (unsigned char*) _alloca(length + 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mode = symbol->option_1;
|
mode = symbol->option_1;
|
||||||
@ -575,7 +570,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
strcpy(servicestr, "");
|
strcpy(servicestr, "");
|
||||||
|
|
||||||
/* The following to be replaced by ECI handling */
|
/* The following to be replaced by ECI handling */
|
||||||
switch(symbol->input_mode) {
|
switch (symbol->input_mode) {
|
||||||
case DATA_MODE:
|
case DATA_MODE:
|
||||||
case GS1_MODE:
|
case GS1_MODE:
|
||||||
memcpy(local_source, source, length);
|
memcpy(local_source, source, length);
|
||||||
@ -583,19 +578,21 @@ 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));
|
||||||
|
|
||||||
if(mode == -1) { /* If mode is unspecified */
|
if (mode == -1) { /* If mode is unspecified */
|
||||||
lp = strlen(symbol->primary);
|
lp = strlen(symbol->primary);
|
||||||
if(lp == 0) {
|
if (lp == 0) {
|
||||||
mode = 4;
|
mode = 4;
|
||||||
} else {
|
} else {
|
||||||
mode = 2;
|
mode = 2;
|
||||||
for(i = 0; i < 10 && i < lp; i++) {
|
for (i = 0; i < 10 && i < lp; i++) {
|
||||||
if((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) {
|
if ((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) {
|
||||||
mode = 3;
|
mode = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -603,22 +600,22 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((mode < 2) || (mode > 6)) { /* Only codes 2 to 6 supported */
|
if ((mode < 2) || (mode > 6)) { /* Only codes 2 to 6 supported */
|
||||||
strcpy(symbol->errtxt, "Invalid Maxicode Mode");
|
strcpy(symbol->errtxt, "Invalid Maxicode Mode");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */
|
if ((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */
|
||||||
if(lp == 0){ /* Mode set manually means lp doesn't get set */
|
if (lp == 0) { /* Mode set manually means lp doesn't get set */
|
||||||
lp = strlen( symbol->primary );
|
lp = strlen(symbol->primary);
|
||||||
}
|
}
|
||||||
if(lp != 15) {
|
if (lp != 15) {
|
||||||
strcpy(symbol->errtxt, "Invalid Primary String");
|
strcpy(symbol->errtxt, "Invalid Primary String");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 9; i < 15; i++) { /* check that country code and service are numeric */
|
for (i = 9; i < 15; i++) { /* check that country code and service are numeric */
|
||||||
if((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) {
|
if ((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) {
|
||||||
strcpy(symbol->errtxt, "Invalid Primary String");
|
strcpy(symbol->errtxt, "Invalid Primary String");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
@ -627,14 +624,15 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
memcpy(postcode, symbol->primary, 9);
|
memcpy(postcode, symbol->primary, 9);
|
||||||
postcode[9] = '\0';
|
postcode[9] = '\0';
|
||||||
|
|
||||||
if(mode == 2) {
|
if (mode == 2) {
|
||||||
for(i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
if(postcode[i] == ' ') {
|
if (postcode[i] == ' ') {
|
||||||
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,14 +647,18 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = maxi_text_process(mode, local_source, length);
|
i = maxi_text_process(mode, local_source, length);
|
||||||
if(i == ZINT_ERROR_TOO_LONG ) {
|
if (i == ZINT_ERROR_TOO_LONG) {
|
||||||
strcpy(symbol->errtxt, "Input data too long");
|
strcpy(symbol->errtxt, "Input data too long");
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -664,21 +666,21 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
/* All the data is sorted - now do error correction */
|
/* All the data is sorted - now do error correction */
|
||||||
maxi_do_primary_check(); /* always EEC */
|
maxi_do_primary_check(); /* always EEC */
|
||||||
|
|
||||||
if ( mode == 5 )
|
if (mode == 5)
|
||||||
eclen = 56; // 68 data codewords , 56 error corrections
|
eclen = 56; // 68 data codewords , 56 error corrections
|
||||||
else
|
else
|
||||||
eclen = 40; // 84 data codewords, 40 error corrections
|
eclen = 40; // 84 data codewords, 40 error corrections
|
||||||
|
|
||||||
maxi_do_secondary_chk_even(eclen/2); // do error correction of even
|
maxi_do_secondary_chk_even(eclen / 2); // do error correction of even
|
||||||
maxi_do_secondary_chk_odd(eclen/2); // do error correction of odd
|
maxi_do_secondary_chk_odd(eclen / 2); // do error correction of odd
|
||||||
|
|
||||||
/* Copy data into symbol grid */
|
/* Copy data into symbol grid */
|
||||||
for(i = 0; i < 33; i++) {
|
for (i = 0; i < 33; i++) {
|
||||||
for(j = 0; j < 30; j++) {
|
for (j = 0; j < 30; j++) {
|
||||||
block = (MaxiGrid[(i * 30) + j] + 5) / 6;
|
block = (MaxiGrid[(i * 30) + j] + 5) / 6;
|
||||||
bit = (MaxiGrid[(i * 30) + j] + 5) % 6;
|
bit = (MaxiGrid[(i * 30) + j] + 5) % 6;
|
||||||
|
|
||||||
if(block != 0) {
|
if (block != 0) {
|
||||||
|
|
||||||
bit_pattern[0] = (maxi_codeword[block - 1] & 0x20) >> 5;
|
bit_pattern[0] = (maxi_codeword[block - 1] & 0x20) >> 5;
|
||||||
bit_pattern[1] = (maxi_codeword[block - 1] & 0x10) >> 4;
|
bit_pattern[1] = (maxi_codeword[block - 1] & 0x10) >> 4;
|
||||||
@ -687,7 +689,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
bit_pattern[4] = (maxi_codeword[block - 1] & 0x2) >> 1;
|
bit_pattern[4] = (maxi_codeword[block - 1] & 0x2) >> 1;
|
||||||
bit_pattern[5] = (maxi_codeword[block - 1] & 0x1);
|
bit_pattern[5] = (maxi_codeword[block - 1] & 0x1);
|
||||||
|
|
||||||
if(bit_pattern[bit] != 0) {
|
if (bit_pattern[bit] != 0) {
|
||||||
set_module(symbol, i, j);
|
set_module(symbol, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,9 +28,10 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const int 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,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This file contains the pixel-by-pixel representation of maxicode glyphs
|
/* This file contains the pixel-by-pixel representation of maxicode glyphs
|
||||||
at a resolution of 12 pixels per millimeter. hexagon[] is taken directly
|
at a resolution of 12 pixels per millimeter. hexagon[] is taken directly
|
||||||
@ -52,98 +52,98 @@ static const int hexagon[120] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const unsigned int bullseye_compressed[] = {
|
static const unsigned int bullseye_compressed[] = {
|
||||||
0,0,0,0,0,255,248,0,0,0,0,0,
|
0, 0, 0, 0, 0, 255, 248, 0, 0, 0, 0, 0,
|
||||||
0,0,0,0,31,255,255,192,0,0,0,0,
|
0, 0, 0, 0, 31, 255, 255, 192, 0, 0, 0, 0,
|
||||||
0,0,0,1,255,255,255,252,0,0,0,0,
|
0, 0, 0, 1, 255, 255, 255, 252, 0, 0, 0, 0,
|
||||||
0,0,0,7,255,255,255,255,0,0,0,0,
|
0, 0, 0, 7, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||||
0,0,0,31,255,255,255,255,192,0,0,0,
|
0, 0, 0, 31, 255, 255, 255, 255, 192, 0, 0, 0,
|
||||||
0,0,0,127,255,255,255,255,240,0,0,0,
|
0, 0, 0, 127, 255, 255, 255, 255, 240, 0, 0, 0,
|
||||||
0,0,1,255,255,255,255,255,252,0,0,0,
|
0, 0, 1, 255, 255, 255, 255, 255, 252, 0, 0, 0,
|
||||||
0,0,7,255,255,255,255,255,255,0,0,0,
|
0, 0, 7, 255, 255, 255, 255, 255, 255, 0, 0, 0,
|
||||||
0,0,15,255,255,0,7,255,255,128,0,0,
|
0, 0, 15, 255, 255, 0, 7, 255, 255, 128, 0, 0,
|
||||||
0,0,63,255,240,0,0,127,255,224,0,0,
|
0, 0, 63, 255, 240, 0, 0, 127, 255, 224, 0, 0,
|
||||||
0,0,127,255,128,0,0,15,255,240,0,0,
|
0, 0, 127, 255, 128, 0, 0, 15, 255, 240, 0, 0,
|
||||||
0,0,255,252,0,0,0,1,255,248,0,0,
|
0, 0, 255, 252, 0, 0, 0, 1, 255, 248, 0, 0,
|
||||||
0,1,255,240,0,0,0,0,127,252,0,0,
|
0, 1, 255, 240, 0, 0, 0, 0, 127, 252, 0, 0,
|
||||||
0,3,255,224,0,0,0,0,63,254,0,0,
|
0, 3, 255, 224, 0, 0, 0, 0, 63, 254, 0, 0,
|
||||||
0,7,255,128,0,0,0,0,15,255,0,0,
|
0, 7, 255, 128, 0, 0, 0, 0, 15, 255, 0, 0,
|
||||||
0,15,255,0,0,0,0,0,7,255,128,0,
|
0, 15, 255, 0, 0, 0, 0, 0, 7, 255, 128, 0,
|
||||||
0,31,252,0,0,127,240,0,1,255,192,0,
|
0, 31, 252, 0, 0, 127, 240, 0, 1, 255, 192, 0,
|
||||||
0,63,248,0,7,255,255,0,0,255,224,0,
|
0, 63, 248, 0, 7, 255, 255, 0, 0, 255, 224, 0,
|
||||||
0,127,240,0,63,255,255,224,0,127,240,0,
|
0, 127, 240, 0, 63, 255, 255, 224, 0, 127, 240, 0,
|
||||||
0,127,224,0,255,255,255,248,0,63,240,0,
|
0, 127, 224, 0, 255, 255, 255, 248, 0, 63, 240, 0,
|
||||||
0,255,192,1,255,255,255,252,0,31,248,0,
|
0, 255, 192, 1, 255, 255, 255, 252, 0, 31, 248, 0,
|
||||||
1,255,128,7,255,255,255,255,0,15,252,0,
|
1, 255, 128, 7, 255, 255, 255, 255, 0, 15, 252, 0,
|
||||||
1,255,0,15,255,255,255,255,128,7,252,0,
|
1, 255, 0, 15, 255, 255, 255, 255, 128, 7, 252, 0,
|
||||||
3,255,0,63,255,255,255,255,224,7,254,0,
|
3, 255, 0, 63, 255, 255, 255, 255, 224, 7, 254, 0,
|
||||||
3,254,0,127,255,192,31,255,240,3,254,0,
|
3, 254, 0, 127, 255, 192, 31, 255, 240, 3, 254, 0,
|
||||||
7,252,0,255,252,0,1,255,248,1,255,0,
|
7, 252, 0, 255, 252, 0, 1, 255, 248, 1, 255, 0,
|
||||||
7,252,1,255,240,0,0,127,252,1,255,0,
|
7, 252, 1, 255, 240, 0, 0, 127, 252, 1, 255, 0,
|
||||||
15,248,1,255,192,0,0,31,252,0,255,128,
|
15, 248, 1, 255, 192, 0, 0, 31, 252, 0, 255, 128,
|
||||||
15,240,3,255,128,0,0,15,254,0,127,128,
|
15, 240, 3, 255, 128, 0, 0, 15, 254, 0, 127, 128,
|
||||||
31,240,7,255,0,0,0,7,255,0,127,192,
|
31, 240, 7, 255, 0, 0, 0, 7, 255, 0, 127, 192,
|
||||||
31,224,7,254,0,0,0,3,255,0,63,192,
|
31, 224, 7, 254, 0, 0, 0, 3, 255, 0, 63, 192,
|
||||||
63,224,15,252,0,0,0,1,255,128,63,224,
|
63, 224, 15, 252, 0, 0, 0, 1, 255, 128, 63, 224,
|
||||||
63,224,31,248,0,63,192,0,255,192,63,224,
|
63, 224, 31, 248, 0, 63, 192, 0, 255, 192, 63, 224,
|
||||||
63,192,31,240,0,255,240,0,127,192,31,224,
|
63, 192, 31, 240, 0, 255, 240, 0, 127, 192, 31, 224,
|
||||||
63,192,63,224,3,255,252,0,63,224,31,224,
|
63, 192, 63, 224, 3, 255, 252, 0, 63, 224, 31, 224,
|
||||||
127,192,63,224,7,255,254,0,63,224,31,240,
|
127, 192, 63, 224, 7, 255, 254, 0, 63, 224, 31, 240,
|
||||||
127,128,63,192,15,255,255,0,31,224,15,240,
|
127, 128, 63, 192, 15, 255, 255, 0, 31, 224, 15, 240,
|
||||||
127,128,127,192,31,255,255,128,31,240,15,240,
|
127, 128, 127, 192, 31, 255, 255, 128, 31, 240, 15, 240,
|
||||||
127,128,127,128,63,255,255,192,15,240,15,240,
|
127, 128, 127, 128, 63, 255, 255, 192, 15, 240, 15, 240,
|
||||||
127,128,127,128,63,255,255,192,15,240,15,240,
|
127, 128, 127, 128, 63, 255, 255, 192, 15, 240, 15, 240,
|
||||||
255,0,127,128,127,240,255,224,15,240,7,240,
|
255, 0, 127, 128, 127, 240, 255, 224, 15, 240, 7, 240,
|
||||||
255,0,255,128,127,192,63,224,15,248,7,240,
|
255, 0, 255, 128, 127, 192, 63, 224, 15, 248, 7, 240,
|
||||||
255,0,255,0,255,128,31,240,7,248,7,240,
|
255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,128,31,240,7,248,7,240,
|
255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,0,15,240,7,248,7,240,
|
255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,0,15,240,7,248,7,240,
|
255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,0,15,240,7,248,7,240,
|
255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,0,15,240,7,248,7,240,
|
255, 0, 255, 0, 255, 0, 15, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,128,31,240,7,248,7,240,
|
255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,255,128,31,240,7,248,7,240,
|
255, 0, 255, 0, 255, 128, 31, 240, 7, 248, 7, 240,
|
||||||
255,0,255,0,127,192,63,224,7,248,7,240,
|
255, 0, 255, 0, 127, 192, 63, 224, 7, 248, 7, 240,
|
||||||
255,0,255,128,127,240,255,224,15,248,7,240,
|
255, 0, 255, 128, 127, 240, 255, 224, 15, 248, 7, 240,
|
||||||
255,0,127,128,63,255,255,192,15,240,7,240,
|
255, 0, 127, 128, 63, 255, 255, 192, 15, 240, 7, 240,
|
||||||
127,128,127,128,63,255,255,192,15,240,15,240,
|
127, 128, 127, 128, 63, 255, 255, 192, 15, 240, 15, 240,
|
||||||
127,128,127,128,31,255,255,128,15,240,15,240,
|
127, 128, 127, 128, 31, 255, 255, 128, 15, 240, 15, 240,
|
||||||
127,128,127,192,15,255,255,0,31,240,15,240,
|
127, 128, 127, 192, 15, 255, 255, 0, 31, 240, 15, 240,
|
||||||
127,128,63,192,7,255,254,0,31,224,15,240,
|
127, 128, 63, 192, 7, 255, 254, 0, 31, 224, 15, 240,
|
||||||
127,192,63,224,3,255,252,0,63,224,31,240,
|
127, 192, 63, 224, 3, 255, 252, 0, 63, 224, 31, 240,
|
||||||
63,192,63,224,0,255,240,0,63,224,31,224,
|
63, 192, 63, 224, 0, 255, 240, 0, 63, 224, 31, 224,
|
||||||
63,192,31,240,0,63,192,0,127,192,31,224,
|
63, 192, 31, 240, 0, 63, 192, 0, 127, 192, 31, 224,
|
||||||
63,224,31,248,0,0,0,0,255,192,63,224,
|
63, 224, 31, 248, 0, 0, 0, 0, 255, 192, 63, 224,
|
||||||
63,224,15,252,0,0,0,1,255,128,63,224,
|
63, 224, 15, 252, 0, 0, 0, 1, 255, 128, 63, 224,
|
||||||
31,224,7,254,0,0,0,3,255,0,63,192,
|
31, 224, 7, 254, 0, 0, 0, 3, 255, 0, 63, 192,
|
||||||
31,240,7,255,0,0,0,7,255,0,127,192,
|
31, 240, 7, 255, 0, 0, 0, 7, 255, 0, 127, 192,
|
||||||
15,240,3,255,128,0,0,15,254,0,127,128,
|
15, 240, 3, 255, 128, 0, 0, 15, 254, 0, 127, 128,
|
||||||
15,248,1,255,192,0,0,31,252,0,255,128,
|
15, 248, 1, 255, 192, 0, 0, 31, 252, 0, 255, 128,
|
||||||
7,252,1,255,240,0,0,127,252,1,255,0,
|
7, 252, 1, 255, 240, 0, 0, 127, 252, 1, 255, 0,
|
||||||
7,252,0,255,252,0,1,255,248,1,255,0,
|
7, 252, 0, 255, 252, 0, 1, 255, 248, 1, 255, 0,
|
||||||
3,254,0,127,255,192,31,255,240,3,254,0,
|
3, 254, 0, 127, 255, 192, 31, 255, 240, 3, 254, 0,
|
||||||
3,255,0,63,255,255,255,255,224,7,254,0,
|
3, 255, 0, 63, 255, 255, 255, 255, 224, 7, 254, 0,
|
||||||
1,255,0,15,255,255,255,255,128,7,252,0,
|
1, 255, 0, 15, 255, 255, 255, 255, 128, 7, 252, 0,
|
||||||
1,255,128,7,255,255,255,255,0,15,252,0,
|
1, 255, 128, 7, 255, 255, 255, 255, 0, 15, 252, 0,
|
||||||
0,255,192,1,255,255,255,252,0,31,248,0,
|
0, 255, 192, 1, 255, 255, 255, 252, 0, 31, 248, 0,
|
||||||
0,127,224,0,255,255,255,248,0,63,240,0,
|
0, 127, 224, 0, 255, 255, 255, 248, 0, 63, 240, 0,
|
||||||
0,127,240,0,63,255,255,224,0,127,240,0,
|
0, 127, 240, 0, 63, 255, 255, 224, 0, 127, 240, 0,
|
||||||
0,63,248,0,7,255,255,0,0,255,224,0,
|
0, 63, 248, 0, 7, 255, 255, 0, 0, 255, 224, 0,
|
||||||
0,31,252,0,0,127,240,0,1,255,192,0,
|
0, 31, 252, 0, 0, 127, 240, 0, 1, 255, 192, 0,
|
||||||
0,15,255,0,0,0,0,0,7,255,128,0,
|
0, 15, 255, 0, 0, 0, 0, 0, 7, 255, 128, 0,
|
||||||
0,7,255,128,0,0,0,0,15,255,0,0,
|
0, 7, 255, 128, 0, 0, 0, 0, 15, 255, 0, 0,
|
||||||
0,3,255,224,0,0,0,0,63,254,0,0,
|
0, 3, 255, 224, 0, 0, 0, 0, 63, 254, 0, 0,
|
||||||
0,1,255,240,0,0,0,0,127,252,0,0,
|
0, 1, 255, 240, 0, 0, 0, 0, 127, 252, 0, 0,
|
||||||
0,0,255,252,0,0,0,1,255,248,0,0,
|
0, 0, 255, 252, 0, 0, 0, 1, 255, 248, 0, 0,
|
||||||
0,0,127,255,128,0,0,15,255,240,0,0,
|
0, 0, 127, 255, 128, 0, 0, 15, 255, 240, 0, 0,
|
||||||
0,0,63,255,240,0,0,127,255,224,0,0,
|
0, 0, 63, 255, 240, 0, 0, 127, 255, 224, 0, 0,
|
||||||
0,0,15,255,255,0,7,255,255,128,0,0,
|
0, 0, 15, 255, 255, 0, 7, 255, 255, 128, 0, 0,
|
||||||
0,0,7,255,255,255,255,255,255,0,0,0,
|
0, 0, 7, 255, 255, 255, 255, 255, 255, 0, 0, 0,
|
||||||
0,0,1,255,255,255,255,255,252,0,0,0,
|
0, 0, 1, 255, 255, 255, 255, 255, 252, 0, 0, 0,
|
||||||
0,0,0,127,255,255,255,255,240,0,0,0,
|
0, 0, 0, 127, 255, 255, 255, 255, 240, 0, 0, 0,
|
||||||
0,0,0,31,255,255,255,255,192,0,0,0,
|
0, 0, 0, 31, 255, 255, 255, 255, 192, 0, 0, 0,
|
||||||
0,0,0,7,255,255,255,255,0,0,0,0,
|
0, 0, 0, 7, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||||
0,0,0,1,255,255,255,252,0,0,0,0,
|
0, 0, 0, 1, 255, 255, 255, 252, 0, 0, 0, 0,
|
||||||
0,0,0,0,31,255,255,192,0,0,0,0,
|
0, 0, 0, 0, 31, 255, 255, 192, 0, 0, 0, 0,
|
||||||
0,0,0,0,0,255,248,0,0,0,0,0
|
0, 0, 0, 0, 0, 255, 248, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -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
|
||||||
@ -60,44 +61,42 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
unsigned long int tester;
|
unsigned long int tester;
|
||||||
int counter, error_number, h;
|
int counter, error_number, h;
|
||||||
char inter[18] = { 0 }; /* 131070 -> 17 bits */
|
char inter[18] = {0}; /* 131070 -> 17 bits */
|
||||||
char dest[64]; /* 17 * 2 + 1 */
|
char dest[64]; /* 17 * 2 + 1 */
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 6) {
|
if (length > 6) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
tester = atoi((char*)source);
|
tester = atoi((char*) source);
|
||||||
|
|
||||||
if((tester < 3) || (tester > 131070)) {
|
if ((tester < 3) || (tester > 131070)) {
|
||||||
strcpy(symbol->errtxt, "Data out of range");
|
strcpy(symbol->errtxt, "Data out of range");
|
||||||
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;
|
||||||
} else {
|
} else {
|
||||||
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';
|
||||||
for(counter = h; counter >= 0; counter--) {
|
for (counter = h; counter >= 0; counter--) {
|
||||||
if(inter[counter] == 'W') {
|
if (inter[counter] == 'W') {
|
||||||
concat(dest, "32");
|
concat(dest, "32");
|
||||||
} else {
|
} else {
|
||||||
concat(dest, "12");
|
concat(dest, "12");
|
||||||
@ -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
|
||||||
@ -121,18 +119,16 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
|
|||||||
char inter[17];
|
char inter[17];
|
||||||
int error_number;
|
int error_number;
|
||||||
|
|
||||||
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");
|
||||||
tester = (tester - 3) / 3;
|
tester = (tester - 3) / 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;
|
||||||
@ -168,30 +161,27 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
int error_number = 0;
|
int error_number = 0;
|
||||||
strcpy(height_pattern, "");
|
strcpy(height_pattern, "");
|
||||||
|
|
||||||
if(length > 8) {
|
if (length > 8) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
error_number = pharma_two_calc(symbol, source, height_pattern);
|
error_number = pharma_two_calc(symbol, source, height_pattern);
|
||||||
if(error_number != 0) {
|
if (error_number != 0) {
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
@ -212,32 +202,30 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
error_number = 0;
|
error_number = 0;
|
||||||
strcpy(dest, "");
|
strcpy(dest, "");
|
||||||
|
|
||||||
if(length > 60) { /* No stack smashing please */
|
if (length > 60) { /* No stack smashing please */
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
to_upper(source);
|
to_upper(source);
|
||||||
error_number = is_sane(CALCIUM, source, length);
|
error_number = is_sane(CALCIUM, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
/* 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;
|
||||||
@ -255,12 +243,12 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
char tabella[34];
|
char tabella[34];
|
||||||
|
|
||||||
/* Validate the input */
|
/* Validate the input */
|
||||||
if(length > 8) {
|
if (length > 8) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
@ -268,16 +256,16 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
/* Add leading zeros as required */
|
/* Add leading zeros as required */
|
||||||
zeroes = 8 - length;
|
zeroes = 8 - length;
|
||||||
memset(localstr, '0', zeroes);
|
memset(localstr, '0', zeroes);
|
||||||
strcpy(localstr + zeroes, (char*)source);
|
strcpy(localstr + zeroes, (char*) source);
|
||||||
|
|
||||||
/* Calculate the check digit */
|
/* Calculate the check digit */
|
||||||
checksum = 0;
|
checksum = 0;
|
||||||
checkpart = 0;
|
checkpart = 0;
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
checkpart = ctoi(localstr[i * 2]);
|
checkpart = ctoi(localstr[i * 2]);
|
||||||
checksum += checkpart;
|
checksum += checkpart;
|
||||||
checkpart = 2 * (ctoi(localstr[(i * 2) + 1]));
|
checkpart = 2 * (ctoi(localstr[(i * 2) + 1]));
|
||||||
if(checkpart >= 10) {
|
if (checkpart >= 10) {
|
||||||
checksum += (checkpart - 10) + 1;
|
checksum += (checkpart - 10) + 1;
|
||||||
} else {
|
} else {
|
||||||
checksum += checkpart;
|
checksum += checkpart;
|
||||||
@ -294,7 +282,7 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* Convert from decimal to base-32 */
|
/* Convert from decimal to base-32 */
|
||||||
devisor = 33554432;
|
devisor = 33554432;
|
||||||
for(i = 5; i >= 0; i--) {
|
for (i = 5; i >= 0; i--) {
|
||||||
codeword[i] = pharmacode / devisor;
|
codeword[i] = pharmacode / devisor;
|
||||||
remainder = pharmacode % devisor;
|
remainder = pharmacode % devisor;
|
||||||
pharmacode = remainder;
|
pharmacode = remainder;
|
||||||
@ -303,17 +291,19 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
/* Look up values in 'Tabella di conversione' */
|
/* Look up values in 'Tabella di conversione' */
|
||||||
strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
|
strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
|
||||||
for(i = 5; i >= 0; i--) {
|
for (i = 5; i >= 0; i--) {
|
||||||
risultante[5 - i] = tabella[codeword[i]];
|
risultante[5 - i] = tabella[codeword[i]];
|
||||||
}
|
}
|
||||||
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");
|
||||||
uconcat(symbol->text, (unsigned char*)localstr);
|
uconcat(symbol->text, (unsigned char*) localstr);
|
||||||
|
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
773
backend/pdf417.c
773
backend/pdf417.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||||
@ -29,7 +29,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* this file contains the character table, the pre-calculated coefficients and the
|
/* this file contains the character table, the pre-calculated coefficients and the
|
||||||
codeword patterns taken from lines 416 to 454 of pdf417.frm */
|
codeword patterns taken from lines 416 to 454 of pdf417.frm */
|
||||||
@ -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"
|
||||||
|
};
|
||||||
|
|
||||||
/* converts values into bar patterns - replacing Grand Zebu's true type font */
|
static const char *PDFttf[35] = {
|
||||||
static const char *PDFttf[35] = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
|
/* converts values into bar patterns - replacing Grand Zebu's true type font */
|
||||||
|
"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);
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -37,48 +37,50 @@
|
|||||||
|
|
||||||
|
|
||||||
#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;
|
||||||
static const char grid[9] = {1,1,1,1,0,1,0,0,1};
|
static const char grid[9] = {1, 1, 1, 1, 0, 1, 0, 0, 1};
|
||||||
char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */
|
char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */
|
||||||
int error_number;
|
int error_number;
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 65) {
|
if (length > 65) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, source, length);
|
error_number = is_sane(SSET, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
checkptr = (unsigned char *)calloc (1, length * 4 + 8);
|
checkptr = (unsigned char *) calloc(1, length * 4 + 8);
|
||||||
|
|
||||||
/* Start character */
|
/* Start character */
|
||||||
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;
|
||||||
checkptr[4*i+1] = (check >> 1) & 1;
|
checkptr[4 * i + 1] = (check >> 1) & 1;
|
||||||
checkptr[4*i+2] = (check >> 2) & 1;
|
checkptr[4 * i + 2] = (check >> 2) & 1;
|
||||||
checkptr[4*i+3] = (check >> 3) & 1;
|
checkptr[4 * i + 3] = (check >> 3) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CRC check digit code adapted from code by Leonid A. Broukhis
|
/* CRC check digit code adapted from code by Leonid A. Broukhis
|
||||||
@ -88,14 +90,15 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
int j;
|
int j;
|
||||||
if (checkptr[i])
|
if (checkptr[i])
|
||||||
for (j = 0; j < 9; j++)
|
for (j = 0; j < 9; j++)
|
||||||
checkptr[i+j] ^= grid[j];
|
checkptr[i + j] ^= grid[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
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,13 +111,13 @@ 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 */
|
||||||
|
|
||||||
if(length > 55) {
|
if (length > 55) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
@ -122,22 +125,22 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop character */
|
/* Stop character */
|
||||||
concat (dest, "121");
|
concat(dest, "121");
|
||||||
|
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
ustrcpy(symbol->text, source);
|
ustrcpy(symbol->text, source);
|
||||||
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];
|
||||||
@ -146,7 +149,7 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le
|
|||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 18) {
|
if (length > 18) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +195,7 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le
|
|||||||
lookup(NEON, MSITable, itoc(pump), dest);
|
lookup(NEON, MSITable, itoc(pump), dest);
|
||||||
|
|
||||||
/* Stop character */
|
/* Stop character */
|
||||||
concat (dest, "121");
|
concat(dest, "121");
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
|
|
||||||
ustrcpy(symbol->text, source);
|
ustrcpy(symbol->text, source);
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +296,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
|
|||||||
lookup(NEON, MSITable, itoc(chwech), dest);
|
lookup(NEON, MSITable, itoc(chwech), dest);
|
||||||
|
|
||||||
/* Stop character */
|
/* Stop character */
|
||||||
concat (dest, "121");
|
concat(dest, "121");
|
||||||
|
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
|
|
||||||
@ -317,20 +308,17 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons
|
|||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calculate a Modulo 11 check digit using the system discussed on Wikipedia -
|
||||||
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 -
|
|
||||||
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];
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(src_len > 55) {
|
if (src_len > 55) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
@ -339,24 +327,23 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate check digit */
|
/* calculate check digit */
|
||||||
x = 0;
|
x = 0;
|
||||||
weight = 2;
|
weight = 2;
|
||||||
for(i = src_len - 1; i >= 0; i--) {
|
for (i = src_len - 1; i >= 0; i--) {
|
||||||
x += weight * ctoi(source[i]);
|
x += weight * ctoi(source[i]);
|
||||||
weight++;
|
weight++;
|
||||||
if(weight > 7) {
|
if (weight > 7) {
|
||||||
weight = 2;
|
weight = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
check = (11 - (x % 11)) % 11;
|
check = (11 - (x % 11)) % 11;
|
||||||
if(check == 10) {
|
if (check == 10) {
|
||||||
lookup(NEON, MSITable, '1', dest);
|
lookup(NEON, MSITable, '1', dest);
|
||||||
lookup(NEON, MSITable, '0', dest);
|
lookup(NEON, MSITable, '0', dest);
|
||||||
} else {
|
} else {
|
||||||
@ -364,13 +351,13 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "121");
|
concat(dest, "121");
|
||||||
|
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
|
|
||||||
ustrcpy(symbol->text, source);
|
ustrcpy(symbol->text, source);
|
||||||
if(check == 10) {
|
if (check == 10) {
|
||||||
concat((char* )symbol->text, "10");
|
concat((char*) symbol->text, "10");
|
||||||
} else {
|
} else {
|
||||||
symbol->text[src_len] = itoc(check);
|
symbol->text[src_len] = itoc(check);
|
||||||
symbol->text[src_len + 1] = '\0';
|
symbol->text[src_len + 1] = '\0';
|
||||||
@ -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];
|
||||||
@ -395,7 +380,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons
|
|||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(src_len > 18) {
|
if (src_len > 18) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
@ -404,18 +389,17 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate first (mod 11) digit */
|
/* calculate first (mod 11) digit */
|
||||||
x = 0;
|
x = 0;
|
||||||
weight = 2;
|
weight = 2;
|
||||||
for(si = src_len - 1; si >= 0; si--) {
|
for (si = src_len - 1; si >= 0; si--) {
|
||||||
x += weight * ctoi(source[si]);
|
x += weight * ctoi(source[si]);
|
||||||
weight++;
|
weight++;
|
||||||
if(weight > 7) {
|
if (weight > 7) {
|
||||||
weight = 2;
|
weight = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,10 +407,10 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons
|
|||||||
check = (11 - (x % 11)) % 11;
|
check = (11 - (x % 11)) % 11;
|
||||||
ustrcpy(temp, source);
|
ustrcpy(temp, source);
|
||||||
temp_len = src_len;
|
temp_len = src_len;
|
||||||
if(check == 10) {
|
if (check == 10) {
|
||||||
lookup(NEON, MSITable, '1', dest);
|
lookup(NEON, MSITable, '1', dest);
|
||||||
lookup(NEON, MSITable, '0', dest);
|
lookup(NEON, MSITable, '0', dest);
|
||||||
uconcat(temp, (unsigned char *)"10");
|
uconcat(temp, (unsigned char *) "10");
|
||||||
temp_len += 2;
|
temp_len += 2;
|
||||||
} else {
|
} else {
|
||||||
lookup(NEON, MSITable, itoc(check), dest);
|
lookup(NEON, MSITable, itoc(check), 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +451,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons
|
|||||||
lookup(NEON, MSITable, itoc(pump), dest);
|
lookup(NEON, MSITable, itoc(pump), dest);
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "121");
|
concat(dest, "121");
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
|
|
||||||
temp[temp_len++] = itoc(pump);
|
temp[temp_len++] = itoc(pump);
|
||||||
@ -486,22 +466,27 @@ int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
int error_number;
|
int error_number;
|
||||||
|
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number != 0) {
|
if (error_number != 0) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if((symbol->option_2 < 0) || (symbol->option_2 > 4)) {
|
if ((symbol->option_2 < 0) || (symbol->option_2 > 4)) {
|
||||||
symbol->option_2 = 0;
|
symbol->option_2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
383
backend/png.c
383
backend/png.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -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;
|
||||||
@ -95,12 +95,12 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
unsigned char outdata[image_width * 3];
|
unsigned char outdata[image_width * 3];
|
||||||
#else
|
#else
|
||||||
unsigned char* outdata = (unsigned char*)_alloca(image_width * 3);
|
unsigned char* outdata = (unsigned char*) _alloca(image_width * 3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
graphic = &wpng_info;
|
graphic = &wpng_info;
|
||||||
|
|
||||||
switch(rotate_angle) {
|
switch (rotate_angle) {
|
||||||
case 0:
|
case 0:
|
||||||
case 180:
|
case 180:
|
||||||
graphic->width = image_width;
|
graphic->width = image_width;
|
||||||
@ -114,23 +114,23 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* sort out colour options */
|
/* sort out colour options */
|
||||||
to_upper((unsigned char*)symbol->fgcolour);
|
to_upper((unsigned char*) symbol->fgcolour);
|
||||||
to_upper((unsigned char*)symbol->bgcolour);
|
to_upper((unsigned char*) symbol->bgcolour);
|
||||||
|
|
||||||
if(strlen(symbol->fgcolour) != 6) {
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
if(strlen(symbol->bgcolour) != 6) {
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
if (errno == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
|
errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
if (errno == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
@ -144,7 +144,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
|
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
|
||||||
|
|
||||||
/* Open output file in binary mode */
|
/* Open output file in binary mode */
|
||||||
if((symbol->output_options & BARCODE_STDOUT) != 0) {
|
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
|
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
|
||||||
strcpy(symbol->errtxt, "Can't open output file");
|
strcpy(symbol->errtxt, "Can't open output file");
|
||||||
@ -184,7 +184,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
png_init_io(png_ptr, graphic->outfile);
|
png_init_io(png_ptr, graphic->outfile);
|
||||||
|
|
||||||
/* set compression */
|
/* set compression */
|
||||||
png_set_compression_level(png_ptr,9);
|
png_set_compression_level(png_ptr, 9);
|
||||||
|
|
||||||
/* set Header block */
|
/* set Header block */
|
||||||
png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height,
|
png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height,
|
||||||
@ -200,13 +200,12 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
|
|
||||||
/* Pixel Plotting */
|
/* Pixel Plotting */
|
||||||
|
|
||||||
switch(rotate_angle) {
|
switch (rotate_angle) {
|
||||||
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++) {
|
||||||
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;
|
||||||
@ -226,11 +225,10 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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++) {
|
||||||
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;
|
||||||
@ -251,11 +249,10 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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++) {
|
||||||
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;
|
||||||
@ -276,11 +273,10 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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++) {
|
||||||
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;
|
||||||
@ -307,7 +303,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
|
|
||||||
/* make sure we have disengaged */
|
/* make sure we have disengaged */
|
||||||
if (png_ptr && info_ptr) png_destroy_write_struct(&png_ptr, &info_ptr);
|
if (png_ptr && info_ptr) png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
if(symbol->output_options & BARCODE_STDOUT) {
|
if (symbol->output_options & BARCODE_STDOUT) {
|
||||||
fflush(wpng_info.outfile);
|
fflush(wpng_info.outfile);
|
||||||
} else {
|
} else {
|
||||||
fclose(wpng_info.outfile);
|
fclose(wpng_info.outfile);
|
||||||
@ -316,12 +312,11 @@ 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;
|
||||||
|
|
||||||
switch(rotate_angle) {
|
switch (rotate_angle) {
|
||||||
case 0:
|
case 0:
|
||||||
case 180:
|
case 180:
|
||||||
symbol->bitmap_width = image_width;
|
symbol->bitmap_width = image_width;
|
||||||
@ -341,23 +336,23 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
|
|
||||||
|
|
||||||
/* sort out colour options */
|
/* sort out colour options */
|
||||||
to_upper((unsigned char*)symbol->fgcolour);
|
to_upper((unsigned char*) symbol->fgcolour);
|
||||||
to_upper((unsigned char*)symbol->bgcolour);
|
to_upper((unsigned char*) symbol->bgcolour);
|
||||||
|
|
||||||
if(strlen(symbol->fgcolour) != 6) {
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
if(strlen(symbol->bgcolour) != 6) {
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
if (errno == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->fgcolour));
|
errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
|
||||||
if (errno == ZINT_ERROR_INVALID_DATA) {
|
if (errno == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
@ -372,12 +367,11 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
|
|
||||||
/* Pixel Plotting */
|
/* Pixel Plotting */
|
||||||
i = 0;
|
i = 0;
|
||||||
switch(rotate_angle) {
|
switch (rotate_angle) {
|
||||||
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;
|
||||||
@ -394,10 +388,9 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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;
|
||||||
@ -414,10 +407,9 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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;
|
||||||
@ -434,10 +426,9 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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;
|
||||||
|
|
||||||
@ -475,18 +467,18 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
|
|||||||
printf("Insufficient memory for pixel buffer");
|
printf("Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_ENCODING_PROBLEM;
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
||||||
} else {
|
} else {
|
||||||
for(i = 0; i < (scale_width * scale_height); i++) {
|
for (i = 0; i < (scale_width * scale_height); i++) {
|
||||||
*(scaled_pixelbuf + i) = '0';
|
*(scaled_pixelbuf + i) = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(vert = 0; vert < scale_height; vert++) {
|
for (vert = 0; vert < scale_height; vert++) {
|
||||||
for(horiz = 0; horiz < scale_width; horiz++) {
|
for (horiz = 0; horiz < scale_width; horiz++) {
|
||||||
*(scaled_pixelbuf + (vert * scale_width) + horiz) = *(pixelbuf + ((int)(vert / scaler) * image_width) + (int)(horiz / scaler));
|
*(scaled_pixelbuf + (vert * scale_width) + horiz) = *(pixelbuf + ((int) (vert / scaler) * image_width) + (int) (horiz / scaler));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image_type == PNG_DATA) {
|
if (image_type == PNG_DATA) {
|
||||||
#ifndef NO_PNG
|
#ifndef NO_PNG
|
||||||
error_number = png_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle);
|
error_number = png_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle);
|
||||||
#else
|
#else
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -510,8 +501,8 @@ void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_
|
|||||||
/* This fudge is needed because EPS measures height from the bottom up but
|
/* This fudge is needed because EPS measures height from the bottom up but
|
||||||
PNG measures y position from the top down */
|
PNG measures y position from the top down */
|
||||||
|
|
||||||
for(i = (xpos); i < (xpos + xlen); i++) {
|
for (i = (xpos); i < (xpos + xlen); i++) {
|
||||||
for( j = (png_ypos); j < (png_ypos + ylen); j++) {
|
for (j = (png_ypos); j < (png_ypos + ylen); j++) {
|
||||||
*(pixelbuf + (image_width * j) + i) = '1';
|
*(pixelbuf + (image_width * j) + i) = '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,28 +515,20 @@ 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;
|
||||||
|
|
||||||
for(j = 103; j < 196; j++) {
|
for (j = 103; j < 196; j++) {
|
||||||
for(i = 0; i < 93; i++) {
|
for (i = 0; i < 93; i++) {
|
||||||
if(bullseye_pixel(j - 103, i)) {
|
if (bullseye_pixel(j - 103, i)) {
|
||||||
/* if(bullseye[(((j - 103) * 93) + i)] == 1) { */
|
/* if(bullseye[(((j - 103) * 93) + i)] == 1) { */
|
||||||
*(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1';
|
*(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1';
|
||||||
}
|
}
|
||||||
@ -553,62 +536,64 @@ 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;
|
||||||
|
|
||||||
for(i = 0; i < 12; i++) {
|
for (i = 0; i < 12; i++) {
|
||||||
for(j = 0; j < 10; j++) {
|
for (j = 0; j < 10; j++) {
|
||||||
if(hexagon[(i * 10) + j] == 1) {
|
if (hexagon[(i * 10) + j] == 1) {
|
||||||
*(pixelbuf + (image_width * i) + (image_width * yposn) + xposn + j) = '1';
|
*(pixelbuf + (image_width * i) + (image_width * yposn) + xposn + j) = '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
alphabet = 1;
|
alphabet = 1;
|
||||||
glyph_no = letter - 161;
|
glyph_no = letter - 161;
|
||||||
} else {
|
} else {
|
||||||
glyph_no = letter - 33;
|
glyph_no = letter - 33;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(smalltext) {
|
if (smalltext) {
|
||||||
for(i = 0; i <= 8; i++) {
|
for (i = 0; i <= 8; i++) {
|
||||||
for(j = 0; j < 5; j++) {
|
for (j = 0; j < 5; j++) {
|
||||||
if(alphabet == 0) {
|
if (alphabet == 0) {
|
||||||
if(small_font[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
|
if (small_font[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
|
||||||
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(small_font_extended[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
|
if (small_font_extended[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
|
||||||
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(i = 0; i <= 13; i++) {
|
for (i = 0; i <= 13; i++) {
|
||||||
for(j = 0; j < 7 ; j++) {
|
for (j = 0; j < 7; j++) {
|
||||||
if(alphabet == 0) {
|
if (alphabet == 0) {
|
||||||
if(ascii_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) {
|
if (ascii_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) {
|
||||||
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(ascii_ext_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) {
|
if (ascii_ext_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) {
|
||||||
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -618,22 +603,20 @@ 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 */
|
||||||
{
|
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 */
|
|
||||||
int i, string_length, string_left_hand;
|
int i, string_length, string_left_hand;
|
||||||
|
|
||||||
string_length = strlen(input_string);
|
string_length = strlen(input_string);
|
||||||
string_left_hand = xposn - ((7 * string_length) / 2);
|
string_left_hand = xposn - ((7 * string_length) / 2);
|
||||||
|
|
||||||
for(i = 0; i < string_length; i++) {
|
for (i = 0; i < string_length; i++) {
|
||||||
draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height);
|
draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -649,19 +632,19 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
printf("Insifficient memory for pixel buffer");
|
printf("Insifficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_ENCODING_PROBLEM;
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
||||||
} else {
|
} else {
|
||||||
for(i = 0; i < (image_width * image_height); i++) {
|
for (i = 0; i < (image_width * image_height); i++) {
|
||||||
*(pixelbuf + i) = '0';
|
*(pixelbuf + i) = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_bullseye(pixelbuf, image_width, (2 * xoffset), (2 * yoffset));
|
draw_bullseye(pixelbuf, image_width, (2 * xoffset), (2 * yoffset));
|
||||||
|
|
||||||
for(row = 0; row < symbol->rows; row++) {
|
for (row = 0; row < symbol->rows; row++) {
|
||||||
yposn = row * 9;
|
yposn = row * 9;
|
||||||
for(column = 0; column < symbol->width; column++) {
|
for (column = 0; column < symbol->width; column++) {
|
||||||
xposn = column * 10;
|
xposn = column * 10;
|
||||||
if(module_is_set(symbol, row, column)) {
|
if (module_is_set(symbol, row, column)) {
|
||||||
if(row & 1) {
|
if (row & 1) {
|
||||||
/* Odd (reduced) row */
|
/* Odd (reduced) row */
|
||||||
xposn += 5;
|
xposn += 5;
|
||||||
draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset));
|
draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset));
|
||||||
@ -673,26 +656,25 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
||||||
/* boundary bars */
|
/* boundary bars */
|
||||||
draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * 2, image_width, image_height);
|
draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * 2), symbol->border_width * 2, image_width, image_height);
|
draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * 2), symbol->border_width * 2, image_width, image_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
draw_bar(pixelbuf, 0, symbol->border_width * 2, 0, image_height, image_width, image_height);
|
draw_bar(pixelbuf, 0, symbol->border_width * 2, 0, image_height, image_width, image_height);
|
||||||
draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * 2), symbol->border_width * 2, 0, image_height, image_width, image_height);
|
draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * 2), symbol->border_width * 2, 0, image_height, image_width, image_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);
|
error_number = png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);
|
||||||
free(pixelbuf);
|
free(pixelbuf);
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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);
|
||||||
@ -717,7 +699,7 @@ void to_latin1(unsigned char source[], unsigned char preprocessed[])
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Process ASCII (< 80h), all other unicode points are ignored */
|
/* Process ASCII (< 80h), all other unicode points are ignored */
|
||||||
if(source[i] < 128) {
|
if (source[i] < 128) {
|
||||||
preprocessed[j] = source[i];
|
preprocessed[j] = source[i];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
@ -746,10 +727,10 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
unsigned char local_text[ustrlen(symbol->text) + 1];
|
unsigned char local_text[ustrlen(symbol->text) + 1];
|
||||||
#else
|
#else
|
||||||
unsigned char* local_text = (unsigned char*)_alloca(ustrlen(symbol->text) + 1);
|
unsigned char* local_text = (unsigned char*) _alloca(ustrlen(symbol->text) + 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(symbol->show_hrt != 0) {
|
if (symbol->show_hrt != 0) {
|
||||||
to_latin1(symbol->text, local_text);
|
to_latin1(symbol->text, local_text);
|
||||||
} else {
|
} else {
|
||||||
local_text[0] = '\0';
|
local_text[0] = '\0';
|
||||||
@ -761,7 +742,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
comp_offset = 0;
|
comp_offset = 0;
|
||||||
addon_text_posn = 0.0;
|
addon_text_posn = 0.0;
|
||||||
row_height = 0;
|
row_height = 0;
|
||||||
if(symbol->output_options & SMALL_TEXT) {
|
if (symbol->output_options & SMALL_TEXT) {
|
||||||
smalltext = 1;
|
smalltext = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,9 +752,9 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
|
|
||||||
large_bar_count = 0;
|
large_bar_count = 0;
|
||||||
preset_height = 0.0;
|
preset_height = 0.0;
|
||||||
for(i = 0; i < symbol->rows; i++) {
|
for (i = 0; i < symbol->rows; i++) {
|
||||||
preset_height += symbol->row_height[i];
|
preset_height += symbol->row_height[i];
|
||||||
if(symbol->row_height[i] == 0) {
|
if (symbol->row_height[i] == 0) {
|
||||||
large_bar_count++;
|
large_bar_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -785,18 +766,18 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
||||||
comp_offset++;
|
comp_offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
||||||
|| (symbol->symbology == BARCODE_ISBNX)) {
|
|| (symbol->symbology == BARCODE_ISBNX)) {
|
||||||
switch(ustrlen(local_text)) {
|
switch (ustrlen(local_text)) {
|
||||||
case 13: /* EAN 13 */
|
case 13: /* EAN 13 */
|
||||||
case 16:
|
case 16:
|
||||||
case 19:
|
case 19:
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
}
|
}
|
||||||
main_width = 96 + comp_offset;
|
main_width = 96 + comp_offset;
|
||||||
@ -807,14 +788,14 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_width = 96 + comp_offset;
|
main_width = 96 + comp_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_width = 51 + comp_offset;
|
main_width = 51 + comp_offset;
|
||||||
}
|
}
|
||||||
@ -823,8 +804,8 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
latch = 0;
|
latch = 0;
|
||||||
r = 0;
|
r = 0;
|
||||||
/* Isolate add-on text */
|
/* Isolate add-on text */
|
||||||
if(is_extendable(symbol->symbology)) {
|
if (is_extendable(symbol->symbology)) {
|
||||||
for(i = 0; i < ustrlen(local_text); i++) {
|
for (i = 0; i < ustrlen(local_text); i++) {
|
||||||
if (latch == 1) {
|
if (latch == 1) {
|
||||||
addon[r] = local_text[i];
|
addon[r] = local_text[i];
|
||||||
r++;
|
r++;
|
||||||
@ -836,7 +817,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
}
|
}
|
||||||
addon[r] = '\0';
|
addon[r] = '\0';
|
||||||
|
|
||||||
if(ustrlen(local_text) != 0) {
|
if (ustrlen(local_text) != 0) {
|
||||||
textoffset = 9;
|
textoffset = 9;
|
||||||
} else {
|
} else {
|
||||||
textoffset = 0;
|
textoffset = 0;
|
||||||
@ -850,12 +831,12 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
printf("Insufficient memory for pixel buffer");
|
printf("Insufficient memory for pixel buffer");
|
||||||
return ZINT_ERROR_ENCODING_PROBLEM;
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
||||||
} else {
|
} else {
|
||||||
for(i = 0; i < (image_width * image_height); i++) {
|
for (i = 0; i < (image_width * image_height); i++) {
|
||||||
*(pixelbuf + i) = '0';
|
*(pixelbuf + i) = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
||||||
default_text_posn = image_height - 17;
|
default_text_posn = image_height - 17;
|
||||||
} else {
|
} else {
|
||||||
default_text_posn = image_height - 17 - symbol->border_width - symbol->border_width;
|
default_text_posn = image_height - 17 - symbol->border_width - symbol->border_width;
|
||||||
@ -866,20 +847,20 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
row_height = 0;
|
row_height = 0;
|
||||||
|
|
||||||
/* Plot the body of the symbol to the pixel buffer */
|
/* Plot the body of the symbol to the pixel buffer */
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
|
this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
|
||||||
row_posn += row_height;
|
row_posn += row_height;
|
||||||
plot_yposn = next_yposn;
|
plot_yposn = next_yposn;
|
||||||
if(symbol->row_height[this_row] == 0) {
|
if (symbol->row_height[this_row] == 0) {
|
||||||
row_height = large_bar_height;
|
row_height = large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_height = symbol->row_height[this_row];
|
row_height = symbol->row_height[this_row];
|
||||||
}
|
}
|
||||||
next_yposn = (int)(row_posn + row_height);
|
next_yposn = (int) (row_posn + row_height);
|
||||||
plot_height = next_yposn - plot_yposn;
|
plot_height = next_yposn - plot_yposn;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if(module_is_set(symbol, this_row, 0)) {
|
if (module_is_set(symbol, this_row, 0)) {
|
||||||
latch = 1;
|
latch = 1;
|
||||||
} else {
|
} else {
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -890,13 +871,13 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
||||||
if((addon_latch == 0) && (r == 0) && (i > main_width)) {
|
if ((addon_latch == 0) && (r == 0) && (i > main_width)) {
|
||||||
plot_height = (int)(row_height - 5.0);
|
plot_height = (int) (row_height - 5.0);
|
||||||
plot_yposn = (int)(row_posn - 5.0);
|
plot_yposn = (int) (row_posn - 5.0);
|
||||||
addon_text_posn = row_posn + row_height - 8.0;
|
addon_text_posn = row_posn + row_height - 8.0;
|
||||||
addon_latch = 1;
|
addon_latch = 1;
|
||||||
}
|
}
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
draw_bar(pixelbuf, (i + xoffset) * 2, block_width * 2, plot_yposn * 2, plot_height * 2, image_width, image_height);
|
draw_bar(pixelbuf, (i + xoffset) * 2, block_width * 2, plot_yposn * 2, plot_height * 2, image_width, image_height);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -913,31 +894,31 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
|
|
||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) {
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) {
|
||||||
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
||||||
switch(ustrlen(local_text)) {
|
switch (ustrlen(local_text)) {
|
||||||
case 8: /* EAN-8 */
|
case 8: /* EAN-8 */
|
||||||
case 11:
|
case 11:
|
||||||
case 14:
|
case 14:
|
||||||
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (32 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (32 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (34 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (34 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (64 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (64 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (66 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (66 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i];
|
textpart[i] = symbol->text[i];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
textpos = 2 * (17 + xoffset);
|
textpos = 2 * (17 + xoffset);
|
||||||
|
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i + 4];
|
textpart[i] = symbol->text[i + 4];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
textpos = 2 * (50 + xoffset);
|
textpos = 2 * (50 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = 2 * (xoffset + 86);
|
textpos = 2 * (xoffset + 86);
|
||||||
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
||||||
@ -952,31 +933,31 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
case 13: /* EAN 13 */
|
case 13: /* EAN 13 */
|
||||||
case 16:
|
case 16:
|
||||||
case 19:
|
case 19:
|
||||||
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (92 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (92 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (94 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (94 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
|
|
||||||
textpart[0] = symbol->text[0];
|
textpart[0] = symbol->text[0];
|
||||||
textpart[1] = '\0';
|
textpart[1] = '\0';
|
||||||
textpos = 2 * (-7 + xoffset);
|
textpos = 2 * (-7 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
textpos = 2 * (24 + xoffset);
|
textpos = 2 * (24 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 7];
|
textpart[i] = symbol->text[i + 7];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
textpos = 2 * (71 + xoffset);
|
textpos = 2 * (71 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = 2 * (xoffset + 114);
|
textpos = 2 * (xoffset + 114);
|
||||||
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
||||||
@ -1001,9 +982,9 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
} else {
|
} else {
|
||||||
/* a space */
|
/* a space */
|
||||||
@ -1011,8 +992,8 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
}
|
}
|
||||||
i += block_width;
|
i += block_width;
|
||||||
} while (i < 11 + comp_offset);
|
} while (i < 11 + comp_offset);
|
||||||
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
latch = 1;
|
latch = 1;
|
||||||
i = 85 + comp_offset;
|
i = 85 + comp_offset;
|
||||||
do {
|
do {
|
||||||
@ -1020,9 +1001,9 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
} else {
|
} else {
|
||||||
/* a space */
|
/* a space */
|
||||||
@ -1034,13 +1015,13 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
textpart[1] = '\0';
|
textpart[1] = '\0';
|
||||||
textpos = 2 * (-5 + xoffset);
|
textpos = 2 * (-5 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[5] = '\0';
|
textpart[5] = '\0';
|
||||||
textpos = 2 * (27 + xoffset);
|
textpos = 2 * (27 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 6];
|
textpart[i] = symbol->text[i + 6];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -1051,7 +1032,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
textpos = 2 * (100 + xoffset);
|
textpos = 2 * (100 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = 2 * (xoffset + 116);
|
textpos = 2 * (xoffset + 116);
|
||||||
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
||||||
@ -1066,17 +1047,17 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
||||||
/* guard bar extensions and text formatting for UPCE */
|
/* guard bar extensions and text formatting for UPCE */
|
||||||
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (50 + xoffset) * 2, 1 * 2, (4 + (int)yoffset) * 2, 5 * 2, image_width, image_height);
|
draw_bar(pixelbuf, (50 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
|
||||||
|
|
||||||
textpart[0] = symbol->text[0];
|
textpart[0] = symbol->text[0];
|
||||||
textpart[1] = '\0';
|
textpart[1] = '\0';
|
||||||
textpos = 2 * (-5 + xoffset);
|
textpos = 2 * (-5 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -1087,7 +1068,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
textpos = 2 * (55 + xoffset);
|
textpos = 2 * (55 + xoffset);
|
||||||
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = 2 * (xoffset + 70);
|
textpos = 2 * (xoffset + 70);
|
||||||
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
|
||||||
@ -1103,43 +1084,43 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
|
|||||||
xoffset -= comp_offset;
|
xoffset -= comp_offset;
|
||||||
|
|
||||||
/* Put boundary bars or box around symbol */
|
/* Put boundary bars or box around symbol */
|
||||||
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
||||||
/* boundary bars */
|
/* boundary bars */
|
||||||
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height);
|
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height);
|
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height);
|
||||||
if((symbol->output_options & BARCODE_BIND) != 0) {
|
if ((symbol->output_options & BARCODE_BIND) != 0) {
|
||||||
if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
||||||
/* row binding */
|
/* row binding */
|
||||||
for(r = 1; r < symbol->rows; r++) {
|
for (r = 1; r < symbol->rows; r++) {
|
||||||
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height);
|
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
draw_bar(pixelbuf, 0, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height);
|
draw_bar(pixelbuf, 0, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height);
|
||||||
draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * 2, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height);
|
draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * 2, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put the human readable text at the bottom */
|
/* Put the human readable text at the bottom */
|
||||||
if((textdone == 0) && (ustrlen(local_text) != 0)) {
|
if ((textdone == 0) && (ustrlen(local_text) != 0)) {
|
||||||
textpos = (image_width / 2);
|
textpos = (image_width / 2);
|
||||||
draw_string(pixelbuf, (char*)local_text, textpos, default_text_posn, smalltext, image_width, image_height);
|
draw_string(pixelbuf, (char*) local_text, textpos, default_text_posn, smalltext, image_width, image_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);
|
error_number = png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);
|
||||||
free(pixelbuf);
|
free(pixelbuf);
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
#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) {
|
||||||
error = maxi_png_plot(symbol, rotate_angle, PNG_DATA);
|
error = maxi_png_plot(symbol, rotate_angle, PNG_DATA);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -1150,11 +1131,10 @@ 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) {
|
||||||
error = maxi_png_plot(symbol, rotate_angle, BMP_DATA);
|
error = maxi_png_plot(symbol, rotate_angle, BMP_DATA);
|
||||||
} else {
|
} else {
|
||||||
error = png_plot(symbol, rotate_angle, BMP_DATA);
|
error = png_plot(symbol, rotate_angle, BMP_DATA);
|
||||||
@ -1162,4 +1142,3 @@ int bmp_handle(struct zint_symbol *symbol, int rotate_angle)
|
|||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
314
backend/postal.c
314
backend/postal.c
@ -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
|
||||||
@ -28,7 +29,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -45,44 +46,57 @@
|
|||||||
#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 */
|
||||||
{
|
int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
|
||||||
/* Handles the PostNet system used for Zip codes in the US */
|
|
||||||
unsigned int i, sum, check_digit;
|
unsigned int i, sum, check_digit;
|
||||||
int error_number;
|
int error_number;
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 38) {
|
if (length > 38) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
@ -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]);
|
||||||
}
|
}
|
||||||
@ -101,14 +114,13 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
|||||||
concat(dest, PNTable[check_digit]);
|
concat(dest, PNTable[check_digit]);
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "L");
|
concat(dest, "L");
|
||||||
|
|
||||||
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 */
|
||||||
{
|
int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||||
/* Puts PostNet barcodes into the pattern matrix */
|
|
||||||
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;
|
||||||
@ -117,16 +129,14 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
error_number = postnet(symbol, source, height_pattern, length);
|
error_number = postnet(symbol, source, height_pattern, length);
|
||||||
if(error_number != 0) {
|
if (error_number != 0) {
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,20 +150,19 @@ 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 */
|
||||||
{
|
int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
|
||||||
/* Handles the PLANET system used for item tracking in the US */
|
|
||||||
unsigned int i, sum, check_digit;
|
unsigned int i, sum, check_digit;
|
||||||
int error_number;
|
int error_number;
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 38) {
|
if (length > 38) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
@ -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]);
|
||||||
}
|
}
|
||||||
@ -172,14 +180,13 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
|||||||
concat(dest, PLTable[check_digit]);
|
concat(dest, PLTable[check_digit]);
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "L");
|
concat(dest, "L");
|
||||||
|
|
||||||
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 */
|
||||||
{
|
int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||||
/* Puts PLANET barcodes into the pattern matrix */
|
|
||||||
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;
|
||||||
@ -188,16 +195,14 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
error_number = planet(symbol, source, height_pattern, length);
|
error_number = planet(symbol, source, height_pattern, length);
|
||||||
if(error_number != 0) {
|
if (error_number != 0) {
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,57 +215,58 @@ 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];
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
if(length > 6) {
|
if (length > 6) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
zeroes = 6 - length;
|
zeroes = 6 - length;
|
||||||
memset(localstr, '0', zeroes);
|
memset(localstr, '0', zeroes);
|
||||||
strcpy(localstr + zeroes, (char *)source);
|
strcpy(localstr + zeroes, (char *) source);
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
for(loop = 0; loop < 6; loop++) {
|
for (loop = 0; loop < 6; loop++) {
|
||||||
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';
|
||||||
for(loop = 5; loop >= 0; loop--) {
|
for (loop = 5; loop >= 0; loop--) {
|
||||||
lookup(NEON, KoreaTable, localstr[loop], dest);
|
lookup(NEON, KoreaTable, localstr[loop], dest);
|
||||||
}
|
}
|
||||||
lookup(NEON, KoreaTable, localstr[6], dest);
|
lookup(NEON, KoreaTable, localstr[6], dest);
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
ustrcpy(symbol->text, (unsigned char*) localstr);
|
||||||
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 };
|
|
||||||
|
|
||||||
if(length > 1) {
|
char dest[16] = {0};
|
||||||
|
|
||||||
|
if (length > 1) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch((char)source[0]) {
|
switch ((char) source[0]) {
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
strcpy(dest, "111515111");
|
strcpy(dest, "111515111");
|
||||||
@ -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 */
|
||||||
{
|
char rm4scc(char source[], unsigned char dest[], int length) {
|
||||||
/* Handles the 4 State barcodes used in the UK by Royal Mail */
|
|
||||||
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;
|
||||||
@ -298,10 +303,10 @@ char rm4scc(char source[], unsigned char dest[], int length)
|
|||||||
bottom = 0;
|
bottom = 0;
|
||||||
|
|
||||||
/* start character */
|
/* start character */
|
||||||
strcpy((char*)dest, "1");
|
strcpy((char*) dest, "1");
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
lookup(KRSET, RoyalTable, source[i], (char*)dest);
|
lookup(KRSET, RoyalTable, source[i], (char*) dest);
|
||||||
strcpy(values, RoyalValues[posn(KRSET, source[i])]);
|
strcpy(values, RoyalValues[posn(KRSET, source[i])]);
|
||||||
top += ctoi(values[0]);
|
top += ctoi(values[0]);
|
||||||
bottom += ctoi(values[1]);
|
bottom += ctoi(values[1]);
|
||||||
@ -310,20 +315,23 @@ 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]);
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat ((char*)dest, "0");
|
concat((char*) dest, "0");
|
||||||
|
|
||||||
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 */
|
||||||
{
|
int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||||
/* Puts RM4SCC into the data matrix */
|
|
||||||
char height_pattern[200];
|
char height_pattern[200];
|
||||||
unsigned int loopey, h;
|
unsigned int loopey, h;
|
||||||
int writer;
|
int writer;
|
||||||
@ -332,29 +340,26 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 120) {
|
if (length > 120) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
to_upper(source);
|
to_upper(source);
|
||||||
error_number = is_sane(KRSET, source, length);
|
error_number = is_sane(KRSET, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
/*check = */rm4scc((char*)source, (unsigned char*)height_pattern, length);
|
/*check = */rm4scc((char*) source, (unsigned char*) height_pattern, 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;
|
||||||
@ -382,22 +386,18 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 18) {
|
if (length > 18) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
to_upper(source);
|
to_upper(source);
|
||||||
error_number = is_sane(KRSET, source, length);
|
error_number = is_sane(KRSET, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add leading zeroes */
|
strcpy(localstr, (char *) source);
|
||||||
/* zeroes = 11 - length;
|
|
||||||
memset(localstr, '0', zeroes);
|
|
||||||
strcpy(localstr + zeroes, (char *)source);*/
|
|
||||||
strcpy(localstr, (char *)source);
|
|
||||||
|
|
||||||
/* Encode data */
|
/* Encode data */
|
||||||
for (i = 0; i < 18; i++) {
|
for (i = 0; i < 18; i++) {
|
||||||
@ -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,46 +426,49 @@ 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 */
|
||||||
{
|
int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||||
/* Handles DAFT Code symbols */
|
|
||||||
/* Presumably 'daft' doesn't mean the same thing in Germany as it does in the UK! */
|
|
||||||
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;
|
||||||
strcpy(height_pattern, "");
|
strcpy(height_pattern, "");
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
if(length > 50) {
|
if (length > 50) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
to_upper((unsigned char*)source);
|
to_upper((unsigned char*) source);
|
||||||
error_number = is_sane(DAFTSET, (unsigned char*)source, length);
|
error_number = is_sane(DAFTSET, (unsigned char*) source, length);
|
||||||
|
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,25 +483,24 @@ 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 ~ */
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
if(length > 90) {
|
if (length > 90) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
error_number = is_sane(NEON, source, length);
|
error_number = is_sane(NEON, source, length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
for(loop = 0; loop < length; loop++) {
|
for (loop = 0; loop < length; loop++) {
|
||||||
lookup(NEON, FlatTable, source[loop], dest);
|
lookup(NEON, FlatTable, source[loop], dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
@ -520,85 +519,88 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length)
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
char local_source[length + 1];
|
char local_source[length + 1];
|
||||||
#else
|
#else
|
||||||
char* local_source = (char*)_alloca(length + 1);
|
char* local_source = (char*) _alloca(length + 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inter_posn = 0;
|
inter_posn = 0;
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
strcpy(local_source, (char*)source);
|
strcpy(local_source, (char*) source);
|
||||||
for(i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
local_source[i] = source[i];
|
local_source[i] = source[i];
|
||||||
}
|
}
|
||||||
to_upper((unsigned char*)local_source);
|
to_upper((unsigned char*) local_source);
|
||||||
error_number = is_sane(SHKASUTSET, (unsigned char*)local_source, length);
|
error_number = is_sane(SHKASUTSET, (unsigned char*) local_source, length);
|
||||||
|
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
memset(inter, 'd', 20);/* Pad character CC4 */
|
memset(inter, 'd', 20); /* Pad character CC4 */
|
||||||
inter[20] = '\0';
|
inter[20] = '\0';
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
inter_posn = 0;
|
inter_posn = 0;
|
||||||
do {
|
do {
|
||||||
if(((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) {
|
if (((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) {
|
||||||
inter[inter_posn] = local_source[i];
|
inter[inter_posn] = local_source[i];
|
||||||
inter_posn++;
|
inter_posn++;
|
||||||
} else {
|
} else {
|
||||||
if((local_source[i] >= 'A') && (local_source[i] <= 'J')) {
|
if ((local_source[i] >= 'A') && (local_source[i] <= 'J')) {
|
||||||
inter[inter_posn] = 'a';
|
inter[inter_posn] = 'a';
|
||||||
inter[inter_posn + 1] = local_source[i] - 'A' + '0';
|
inter[inter_posn + 1] = local_source[i] - 'A' + '0';
|
||||||
inter_posn += 2;
|
inter_posn += 2;
|
||||||
}
|
}
|
||||||
if((local_source[i] >= 'K') && (local_source[i] <= 'T')) {
|
if ((local_source[i] >= 'K') && (local_source[i] <= 'T')) {
|
||||||
inter[inter_posn] = 'b';
|
inter[inter_posn] = 'b';
|
||||||
inter[inter_posn + 1] = local_source[i] - 'K' + '0';
|
inter[inter_posn + 1] = local_source[i] - 'K' + '0';
|
||||||
inter_posn += 2;
|
inter_posn += 2;
|
||||||
}
|
}
|
||||||
if((local_source[i] >= 'U') && (local_source[i] <= 'Z')) {
|
if ((local_source[i] >= 'U') && (local_source[i] <= 'Z')) {
|
||||||
inter[inter_posn] = 'c';
|
inter[inter_posn] = 'c';
|
||||||
inter[inter_posn + 1] = local_source[i] - 'U' + '0';
|
inter[inter_posn + 1] = local_source[i] - 'U' + '0';
|
||||||
inter_posn += 2;
|
inter_posn += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}while((i < length) && (inter_posn < 20));
|
} while ((i < length) && (inter_posn < 20));
|
||||||
inter[20] = '\0';
|
inter[20] = '\0';
|
||||||
|
|
||||||
strcpy(pattern, "13"); /* Start */
|
strcpy(pattern, "13"); /* Start */
|
||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user