mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
reworked
This commit is contained in:
parent
bf2dbe7494
commit
4c45bac1ae
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
build/
|
||||
*~
|
||||
*.[ao]
|
||||
*.swp
|
||||
*.swo
|
||||
.directory
|
||||
|
@ -10,7 +10,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set (ZINT_VERSION_MAJOR 2)
|
||||
set (ZINT_VERSION_MINOR 4)
|
||||
set (ZINT_VERSION_RELEASE 2)
|
||||
set (ZINT_VERSION_RELEASE 3)
|
||||
set (ZINT_VERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}.${ZINT_VERSION_RELEASE}" )
|
||||
|
||||
add_definitions (-DZINT_VERSION=\"${ZINT_VERSION}\" -Wall)
|
||||
@ -30,8 +30,8 @@ endif (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
|
||||
IF(APPLE)
|
||||
IF (UNIVERSAL) # TODO: make univeral binary
|
||||
IF(NOT ZINT_HAS_BEEN_RUN_BEFORE and UNIVERAL)
|
||||
IF (UNIVERSAL) # TODO: make univeral binary
|
||||
IF(NOT ZINT_HAS_BEEN_RUN_BEFORE and UNIVERAL)
|
||||
IF(EXISTS /Developer/SDKs/MacOSX10.5.sdk OR EXISTS /SDKs/MacOSX10.5.sdk)
|
||||
SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -Wl -single_module " CACHE STRING "Flags used by the compiler during all build types." FORCE)
|
||||
|
11
INSTALL
11
INSTALL
@ -53,8 +53,9 @@ Studio is more involved! Full instructions are currently not ready for
|
||||
publication but will be placed on the project website as soon as possible.
|
||||
|
||||
Mac OSX:
|
||||
Efforts are currently under way to ease compiling on OSX using the CMake
|
||||
method. It may be possible to compile Zint using methods similar to those
|
||||
given above, but this has not been thoroughly tested yet. If you have any
|
||||
success with compiling Zint on OSX then please get in touch. An install
|
||||
binary for OSX is also in development.
|
||||
It is possible to compile Zint using methods similar to those
|
||||
given above, but this has not been thoroughly tested yet. An install
|
||||
binary for OSX is also in development. As of feb 2012 the easiest way to
|
||||
get zint install on Mac OSX is to use HomeBrew with:
|
||||
|
||||
brew install zint
|
||||
|
17
README
17
README
@ -59,24 +59,20 @@ Visual Studio. Correct bug preventing compilation without PNG support.
|
||||
Version 2.4.2:
|
||||
Fix bugs in batch processing - this now works from the command line.
|
||||
|
||||
Version 2.4.3:
|
||||
Some Windows-only fixes and changes
|
||||
|
||||
|
||||
CONTACT ME
|
||||
----------
|
||||
The home of libzint is:
|
||||
|
||||
<http://www.sourceforge.net/projects/zint>
|
||||
|
||||
and the home for Zint documentation is:
|
||||
|
||||
<http://www.zint.org.uk>
|
||||
|
||||
For feature requests or bug reports please join the mailing list at
|
||||
|
||||
<https://lists.sourceforge.net/lists/listinfo/zint-barcode>
|
||||
|
||||
or send an e-mail to
|
||||
|
||||
<zint-barcode@lists.sourceforge.net>
|
||||
|
||||
BEFORE POSTING TO THIS LIST
|
||||
---------------------------
|
||||
Please note the following points...
|
||||
@ -97,8 +93,3 @@ Please note the following points...
|
||||
* Please remember that Zint is developed by volunteers - don't be surprised
|
||||
if we are unable to help you or if it takes a long time to answer your
|
||||
questions.
|
||||
|
||||
Thanks for your interest in libzint.
|
||||
Happy encoding.
|
||||
|
||||
Robin.
|
||||
|
127
backend/aztec.c
127
backend/aztec.c
@ -97,7 +97,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Look for double character encoding possibilities */
|
||||
i = 0;
|
||||
do{
|
||||
@ -108,7 +108,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
mapshorten(charmap, typemap, i, maplength);
|
||||
maplength--;
|
||||
}
|
||||
|
||||
|
||||
if(((charmap[i] == 302) && (charmap[i + 1] == 1)) && ((typemap[i] == 24) && (typemap[i + 1] == 23))) {
|
||||
/* . SP combination */
|
||||
charmap[i] = 3;
|
||||
@ -116,7 +116,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
mapshorten(charmap, typemap, i, maplength);
|
||||
maplength--;
|
||||
}
|
||||
|
||||
|
||||
if(((charmap[i] == 301) && (charmap[i + 1] == 1)) && ((typemap[i] == 24) && (typemap[i + 1] == 23))) {
|
||||
/* , SP combination */
|
||||
charmap[i] = 4;
|
||||
@ -124,7 +124,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
mapshorten(charmap, typemap, i, maplength);
|
||||
maplength--;
|
||||
}
|
||||
|
||||
|
||||
if(((charmap[i] == 21) && (charmap[i + 1] == 1)) && ((typemap[i] == PUNC) && (typemap[i + 1] == 23))) {
|
||||
/* : SP combination */
|
||||
charmap[i] = 5;
|
||||
@ -132,10 +132,10 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
mapshorten(charmap, typemap, i, maplength);
|
||||
maplength--;
|
||||
}
|
||||
|
||||
|
||||
i++;
|
||||
}while(i < (maplength - 1));
|
||||
|
||||
|
||||
/* look for blocks of characters which use the same table */
|
||||
blocks = 1;
|
||||
blockmap[0][0] = typemap[0];
|
||||
@ -156,7 +156,6 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
if(blockmap[0][0] & 8) { blockmap[0][0] = 8; }
|
||||
|
||||
if(blocks > 1) {
|
||||
|
||||
/* look for adjacent blocks which can use the same table (left to right search) */
|
||||
for(i = 1; i < blocks; i++) {
|
||||
if(blockmap[0][i] & blockmap[0][i - 1]) {
|
||||
@ -183,7 +182,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
if(blockmap[0][i] & 2) { blockmap[0][i] = 2; }
|
||||
if(blockmap[0][i] & 1) { blockmap[0][i] = 1; }
|
||||
}
|
||||
|
||||
|
||||
/* Combine blocks of the same type */
|
||||
i = 0;
|
||||
do{
|
||||
@ -199,7 +198,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
}
|
||||
} while (i < blocks);
|
||||
}
|
||||
|
||||
|
||||
/* Put the adjusted block data back into typemap */
|
||||
j = 0;
|
||||
for(i = 0; i < blocks; i++) {
|
||||
@ -214,10 +213,10 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
}
|
||||
j += blockmap[1][i];
|
||||
}
|
||||
|
||||
|
||||
/* Don't shift an initial capital letter */
|
||||
if(typemap[0] == 65) { typemap[0] = 1; };
|
||||
|
||||
|
||||
/* Problem characters (those that appear in different tables with different values) can now be resolved into their tables */
|
||||
for(i = 0; i < maplength; i++) {
|
||||
if((charmap[i] >= 300) && (charmap[i] < 400)) {
|
||||
@ -248,7 +247,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
}
|
||||
}
|
||||
*binary_string = '\0';
|
||||
|
||||
|
||||
curtable = UPPER; /* start with UPPER table */
|
||||
lasttable = UPPER;
|
||||
for(i = 0; i < maplength; i++) {
|
||||
@ -568,20 +567,20 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
newtable = BINARY;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
bytes = 0;
|
||||
do{
|
||||
bytes++;
|
||||
}while(typemap[i + (bytes - 1)] == BINARY);
|
||||
bytes--;
|
||||
|
||||
|
||||
if(bytes > 2079) {
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
if(bytes > 31) { /* Put 00000 followed by 11-bit number of bytes less 31 */
|
||||
int adjusted;
|
||||
|
||||
|
||||
adjusted = bytes - 31;
|
||||
concat(binary_string, "00000");
|
||||
if(adjusted & 0x400) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
|
||||
@ -603,7 +602,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
if(bytes & 0x01) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
|
||||
}
|
||||
if(debug) printf("(%d bytes) ", bytes);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -644,13 +643,13 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(debug) printf("\n");
|
||||
|
||||
|
||||
if(strlen(binary_string) > 14970) {
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -680,7 +679,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Cannot encode in GS1 and Reader Initialisation mode at the same time");
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
|
||||
|
||||
switch(symbol->input_mode) {
|
||||
case DATA_MODE:
|
||||
case GS1_MODE:
|
||||
@ -702,25 +701,25 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
err_code = aztec_text_process(local_source, length, binary_string, gs1);
|
||||
|
||||
|
||||
|
||||
if(err_code != 0) {
|
||||
strcpy(symbol->errtxt, "Input too long or too many extended ASCII characters");
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
if(!((symbol->option_1 >= -1) && (symbol->option_1 <= 4))) {
|
||||
strcpy(symbol->errtxt, "Invalid error correction level - using default instead");
|
||||
err_code = WARN_INVALID_OPTION;
|
||||
symbol->option_1 = -1;
|
||||
}
|
||||
|
||||
|
||||
ecc_level = symbol->option_1;
|
||||
|
||||
|
||||
if((ecc_level == -1) || (ecc_level == 0)) {
|
||||
ecc_level = 2;
|
||||
}
|
||||
|
||||
|
||||
data_length = strlen(binary_string);
|
||||
|
||||
layers = 0; /* Keep compiler happy! */
|
||||
@ -796,42 +795,42 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(layers == 0) { /* Couldn't find a symbol which fits the data */
|
||||
strcpy(symbol->errtxt, "Input too long (too many bits for selected ECC)");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
/* Determine codeword bitlength - Table 3 */
|
||||
codeword_size = 6; /* if (layers <= 2) */
|
||||
if((layers >= 3) && (layers <= 8)) { codeword_size = 8; }
|
||||
if((layers >= 9) && (layers <= 22)) { codeword_size = 10; }
|
||||
if(layers >= 23) { codeword_size = 12; }
|
||||
|
||||
|
||||
j = 0; i = 0;
|
||||
do {
|
||||
if((j + 1) % codeword_size == 0) {
|
||||
/* Last bit of codeword */
|
||||
int t, done = 0;
|
||||
count = 0;
|
||||
|
||||
|
||||
/* Discover how many '1's in current codeword */
|
||||
for(t = 0; t < (codeword_size - 1); t++) {
|
||||
if(binary_string[(i - (codeword_size - 1)) + t] == '1') count++;
|
||||
}
|
||||
|
||||
|
||||
if(count == (codeword_size - 1)) {
|
||||
adjusted_string[j] = '0';
|
||||
j++;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
|
||||
if(count == 0) {
|
||||
adjusted_string[j] = '1';
|
||||
j++;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
|
||||
if(done == 0) {
|
||||
adjusted_string[j] = binary_string[i];
|
||||
j++;
|
||||
@ -845,10 +844,10 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
adjusted_string[j] = '\0';
|
||||
adjusted_length = strlen(adjusted_string);
|
||||
adjustment_size = adjusted_length - data_length;
|
||||
|
||||
|
||||
/* Add padding */
|
||||
remainder = adjusted_length % codeword_size;
|
||||
|
||||
|
||||
padbits = codeword_size - remainder;
|
||||
if(padbits == codeword_size) { padbits = 0; }
|
||||
|
||||
@ -856,7 +855,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
concat(adjusted_string, "1");
|
||||
}
|
||||
adjusted_length = strlen(adjusted_string);
|
||||
|
||||
|
||||
count = 0;
|
||||
for(i = (adjusted_length - codeword_size); i < adjusted_length; i++) {
|
||||
if(adjusted_string[i] == '1') { count++; }
|
||||
@ -872,7 +871,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} while(adjusted_length > data_maxsize);
|
||||
/* This loop will only repeat on the rare occasions when the rule about not having all 1s or all 0s
|
||||
means that the binary string has had to be lengthened beyond the maximum number of bits that can
|
||||
@ -900,31 +899,31 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
if((layers >= 3) && (layers <= 8)) { codeword_size = 8; }
|
||||
if((layers >= 9) && (layers <= 22)) { codeword_size = 10; }
|
||||
if(layers >= 23) { codeword_size = 12; }
|
||||
|
||||
|
||||
j = 0; i = 0;
|
||||
do {
|
||||
if((j + 1) % codeword_size == 0) {
|
||||
/* Last bit of codeword */
|
||||
int t, done = 0;
|
||||
count = 0;
|
||||
|
||||
|
||||
/* Discover how many '1's in current codeword */
|
||||
for(t = 0; t < (codeword_size - 1); t++) {
|
||||
if(binary_string[(i - (codeword_size - 1)) + t] == '1') count++;
|
||||
}
|
||||
|
||||
|
||||
if(count == (codeword_size - 1)) {
|
||||
adjusted_string[j] = '0';
|
||||
j++;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
|
||||
if(count == 0) {
|
||||
adjusted_string[j] = '1';
|
||||
j++;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
|
||||
if(done == 0) {
|
||||
adjusted_string[j] = binary_string[i];
|
||||
j++;
|
||||
@ -937,9 +936,9 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
} while (i <= (data_length + 1));
|
||||
adjusted_string[j] = '\0';
|
||||
adjusted_length = strlen(adjusted_string);
|
||||
|
||||
|
||||
remainder = adjusted_length % codeword_size;
|
||||
|
||||
|
||||
padbits = codeword_size - remainder;
|
||||
if(padbits == codeword_size) { padbits = 0; }
|
||||
|
||||
@ -947,7 +946,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
concat(adjusted_string, "1");
|
||||
}
|
||||
adjusted_length = strlen(adjusted_string);
|
||||
|
||||
|
||||
count = 0;
|
||||
for(i = (adjusted_length - codeword_size); i < adjusted_length; i++) {
|
||||
if(adjusted_string[i] == '1') { count++; }
|
||||
@ -965,7 +964,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Data too long for specified Aztec Code symbol size");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
if(debug) {
|
||||
printf("Codewords:\n");
|
||||
for(i = 0; i < (adjusted_length / codeword_size); i++) {
|
||||
@ -977,20 +976,20 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(reader && (layers > 22)) {
|
||||
strcpy(symbol->errtxt, "Data too long for reader initialisation symbol");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
data_blocks = adjusted_length / codeword_size;
|
||||
|
||||
|
||||
if(compact) {
|
||||
ecc_blocks = AztecCompactSizes[layers - 1] - data_blocks;
|
||||
} else {
|
||||
ecc_blocks = AztecSizes[layers - 1] - data_blocks;
|
||||
}
|
||||
|
||||
|
||||
if(debug) {
|
||||
printf("Generating a ");
|
||||
if(compact) { printf("compact"); } else { printf("full-size"); }
|
||||
@ -1010,7 +1009,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Copy across data into separate integers */
|
||||
memset(data_part,0,(data_blocks + 2)*sizeof(int));
|
||||
memset(ecc_part,0,(ecc_blocks + 2)*sizeof(int));
|
||||
|
||||
|
||||
/* Split into codewords and calculate reed-colomon error correction codes */
|
||||
switch(codeword_size) {
|
||||
case 6:
|
||||
@ -1126,15 +1125,15 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
rs_free();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Invert the data so that actual data is on the outside and reed-solomon on the inside */
|
||||
memset(bit_pattern,'0',20045);
|
||||
|
||||
|
||||
total_bits = (data_blocks + ecc_blocks) * codeword_size;
|
||||
for(i = 0; i < total_bits; i++) {
|
||||
bit_pattern[i] = adjusted_string[total_bits - i - 1];
|
||||
}
|
||||
|
||||
|
||||
/* Now add the symbol descriptor */
|
||||
memset(desc_data,0,4);
|
||||
memset(desc_ecc,0,6);
|
||||
@ -1183,7 +1182,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
descriptor[16] = '\0';
|
||||
if(debug) printf("Mode Message = %s\n", descriptor);
|
||||
}
|
||||
|
||||
|
||||
/* Split into 4-bit codewords */
|
||||
for(i = 0; i < 4; i++) {
|
||||
if(descriptor[i * 4] == '1') { desc_data[i] += 8; }
|
||||
@ -1216,7 +1215,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
rs_free();
|
||||
|
||||
|
||||
/* Merge descriptor with the rest of the symbol */
|
||||
for(i = 0; i < 40; i++) {
|
||||
if(compact) {
|
||||
@ -1228,7 +1227,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Plot all of the data into the symbol in pre-defined spiral pattern */
|
||||
if(compact) {
|
||||
|
||||
|
||||
for(y = AztecCompactOffset[layers - 1]; y < (27 - AztecCompactOffset[layers - 1]); y++) {
|
||||
for(x = AztecCompactOffset[layers - 1]; x < (27 - AztecCompactOffset[layers - 1]); x++) {
|
||||
if(CompactAztecMap[(y * 27) + x] == 1) {
|
||||
@ -1245,7 +1244,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
symbol->rows = 27 - (2 * AztecCompactOffset[layers - 1]);
|
||||
symbol->width = 27 - (2 * AztecCompactOffset[layers - 1]);
|
||||
} else {
|
||||
|
||||
|
||||
for(y = AztecOffset[layers - 1]; y < (151 - AztecOffset[layers - 1]); y++) {
|
||||
for(x = AztecOffset[layers - 1]; x < (151 - AztecOffset[layers - 1]); x++) {
|
||||
if(AztecMap[(y * 151) + x] == 1) {
|
||||
@ -1262,7 +1261,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
symbol->rows = 151 - (2 * AztecOffset[layers - 1]);
|
||||
symbol->width = 151 - (2 * AztecOffset[layers - 1]);
|
||||
}
|
||||
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
@ -1294,12 +1293,12 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
case 1: input_value = ctoi(source[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(input_value > 255) {
|
||||
strcpy(symbol->errtxt, "Input too large");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
|
||||
strcpy(binary_string, "");
|
||||
if(input_value & 0x80) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
|
||||
if(input_value & 0x40) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
|
||||
@ -1319,12 +1318,12 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
if(binary_string[(i * 4) + 2] == '1') { data_codewords[i] += 2; }
|
||||
if(binary_string[(i * 4) + 3] == '1') { data_codewords[i] += 1; }
|
||||
}
|
||||
|
||||
|
||||
rs_init_gf(0x13);
|
||||
rs_init_code(5, 1);
|
||||
rs_encode(2, data_codewords, ecc_codewords);
|
||||
rs_free();
|
||||
|
||||
|
||||
strcpy(binary_string, "");
|
||||
|
||||
for(i = 0; i < 5; i++) {
|
||||
@ -1353,6 +1352,6 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
symbol->rows = 11;
|
||||
symbol->width = 11;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
214
backend/code1.c
214
backend/code1.c
@ -49,7 +49,7 @@ void horiz(struct zint_symbol *symbol, int row_no, int full)
|
||||
void central_finder(struct zint_symbol *symbol, int start_row, int row_count, int full_rows)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
for(i = 0; i < row_count; i++) {
|
||||
if(i < full_rows) {
|
||||
horiz(symbol, start_row + (i * 2), 1);
|
||||
@ -106,18 +106,18 @@ int isedi(unsigned char input)
|
||||
int dq4bi(unsigned char source[], int sourcelen, int position)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
for(i = position; isedi(source[position + i]) && ((position + i) < sourcelen); i++);
|
||||
|
||||
|
||||
if((position + i) == sourcelen) {
|
||||
/* Reached end of input */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (source[position + i - 1] == 13) { return 1; }
|
||||
if (source[position + i - 1] == '*') { return 1; }
|
||||
if (source[position + i - 1] == '>') { return 1; }
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
|
||||
float ascii_count, c40_count, text_count, edi_count, byte_count;
|
||||
char reduced_char;
|
||||
int done, best_scheme, best_count, sp;
|
||||
|
||||
|
||||
/* Step J */
|
||||
if(current_mode == C1_ASCII) {
|
||||
ascii_count = 0.0;
|
||||
@ -141,18 +141,18 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
|
||||
edi_count = 2.0;
|
||||
byte_count = 3.0;
|
||||
}
|
||||
|
||||
|
||||
switch(current_mode) {
|
||||
case C1_C40: c40_count = 0.0; break;
|
||||
case C1_TEXT: text_count = 0.0; break;
|
||||
case C1_BYTE: byte_count = 0.0; break;
|
||||
case C1_EDI: edi_count = 0.0; break;
|
||||
}
|
||||
|
||||
|
||||
for(sp = position; (sp < sourcelen) && (sp <= (position + 8)); sp++) {
|
||||
|
||||
|
||||
if(source[sp] <= 127) { reduced_char = source[sp]; } else { reduced_char = source[sp] - 127; }
|
||||
|
||||
|
||||
/* Step L */
|
||||
if((source[sp] >= '0') && (source[sp] <= '9')) {
|
||||
ascii_count += 0.5;
|
||||
@ -164,7 +164,7 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
|
||||
ascii_count += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Step M */
|
||||
done = 0;
|
||||
if(reduced_char == ' ') { c40_count += (2.0 / 3.0); done = 1; }
|
||||
@ -172,7 +172,7 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
|
||||
if((reduced_char >= 'A') && (reduced_char <= 'Z')) { c40_count += (2.0 / 3.0); done = 1; }
|
||||
if(source[sp] > 127) { c40_count += (4.0 / 3.0); }
|
||||
if(done == 0) { c40_count += (4.0 / 3.0); }
|
||||
|
||||
|
||||
/* Step N */
|
||||
done = 0;
|
||||
if(reduced_char == ' ') { text_count += (2.0 / 3.0); done = 1; }
|
||||
@ -196,52 +196,52 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
|
||||
edi_count += (10.0 / 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Step P */
|
||||
if(gs1 && (source[sp] == '[')) { byte_count += 3.0; } else { byte_count += 1.0; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
ascii_count = froundup(ascii_count);
|
||||
c40_count = froundup(c40_count);
|
||||
text_count = froundup(text_count);
|
||||
edi_count = froundup(edi_count);
|
||||
byte_count = froundup(byte_count);
|
||||
best_scheme = C1_ASCII;
|
||||
|
||||
|
||||
if(sp == sourcelen) {
|
||||
/* Step K */
|
||||
best_count = edi_count;
|
||||
|
||||
|
||||
if(text_count <= best_count) {
|
||||
best_count = text_count;
|
||||
best_scheme = C1_TEXT;
|
||||
}
|
||||
|
||||
|
||||
if(c40_count <= best_count) {
|
||||
best_count = c40_count;
|
||||
best_scheme = C1_C40;
|
||||
}
|
||||
|
||||
|
||||
if(ascii_count <= best_count) {
|
||||
best_count = ascii_count;
|
||||
best_scheme = C1_ASCII;
|
||||
}
|
||||
|
||||
|
||||
if(byte_count <= best_count) {
|
||||
best_count = byte_count;
|
||||
best_scheme = C1_BYTE;
|
||||
}
|
||||
} else {
|
||||
/* Step Q */
|
||||
|
||||
|
||||
if(((edi_count + 1.0 <= ascii_count) && (edi_count + 1.0 <= c40_count)) &&
|
||||
((edi_count + 1.0 <= byte_count) && (edi_count + 1.0 <= text_count))) {
|
||||
best_scheme = C1_EDI;
|
||||
}
|
||||
|
||||
|
||||
if((c40_count + 1.0 <= ascii_count) && (c40_count + 1.0 <= text_count)) {
|
||||
|
||||
|
||||
if(c40_count < edi_count) {
|
||||
best_scheme = C1_C40;
|
||||
} else {
|
||||
@ -255,17 +255,17 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(((text_count + 1.0 <= ascii_count) && (text_count + 1.0 <= c40_count)) &&
|
||||
((text_count + 1.0 <= byte_count) && (text_count + 1.0 <= edi_count))) {
|
||||
best_scheme = C1_TEXT;
|
||||
}
|
||||
|
||||
|
||||
if(((ascii_count + 1.0 <= byte_count) && (ascii_count + 1.0 <= c40_count)) &&
|
||||
((ascii_count + 1.0 <= text_count) && (ascii_count + 1.0 <= edi_count))) {
|
||||
best_scheme = C1_ASCII;
|
||||
}
|
||||
|
||||
|
||||
if(((byte_count + 1.0 <= ascii_count) && (byte_count + 1.0 <= c40_count)) &&
|
||||
((byte_count + 1.0 <= text_count) && (byte_count + 1.0 <= edi_count))) {
|
||||
best_scheme = C1_BYTE;
|
||||
@ -286,7 +286,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
int edi_buffer[6], edi_p;
|
||||
char decimal_binary[40];
|
||||
int byte_start = 0;
|
||||
|
||||
|
||||
sp = 0;
|
||||
tp = 0;
|
||||
latch = 0;
|
||||
@ -297,14 +297,14 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
memset(edi_buffer, 0, 6);
|
||||
edi_p = 0;
|
||||
strcpy(decimal_binary, "");
|
||||
|
||||
|
||||
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }
|
||||
if(gs1) { target[tp] = 232; tp++; } /* FNC1 */
|
||||
|
||||
|
||||
/* Step A */
|
||||
current_mode = C1_ASCII;
|
||||
next_mode = C1_ASCII;
|
||||
|
||||
|
||||
do {
|
||||
if(current_mode != next_mode) {
|
||||
/* Change mode */
|
||||
@ -318,7 +318,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
|
||||
if((current_mode != C1_BYTE) && (next_mode == C1_BYTE)) { byte_start = tp; }
|
||||
current_mode = next_mode;
|
||||
|
||||
|
||||
if(current_mode == C1_ASCII) { /* Step B - ASCII encodation */
|
||||
next_mode = C1_ASCII;
|
||||
|
||||
@ -341,7 +341,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
for(i = 0; i < 13; i++) {
|
||||
if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
|
||||
}
|
||||
|
||||
|
||||
if (j == 13) {
|
||||
latch = 0;
|
||||
for(i = sp + 13; i < length; i++) {
|
||||
@ -354,7 +354,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(next_mode == C1_ASCII) { /* Step B3 */
|
||||
if(istwodigits(source, sp) && ((sp + 1) != length)) {
|
||||
target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130;
|
||||
@ -382,7 +382,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
for(i = 0; i < 7; i++) {
|
||||
if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
|
||||
}
|
||||
|
||||
|
||||
if (j == 7) {
|
||||
latch = 0;
|
||||
for(i = sp + 7; i < length; i++) {
|
||||
@ -402,7 +402,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
|
||||
/* Step B6 */
|
||||
next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
|
||||
|
||||
|
||||
if(next_mode == C1_ASCII) {
|
||||
if(source[sp] > 127) {
|
||||
/* Step B7 */
|
||||
@ -421,10 +421,10 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_C40) { /* Step C - C40 encodation */
|
||||
int shift_set, value, done = 0, latch = 0;
|
||||
|
||||
|
||||
next_mode = C1_C40;
|
||||
if(c40_p == 0) {
|
||||
if((length - sp) >= 12) {
|
||||
@ -459,12 +459,12 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
next_mode = C1_ASCII; done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!(done)) {
|
||||
next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(next_mode != C1_C40) {
|
||||
target[tp] = 255; tp++; /* Unlatch */
|
||||
} else {
|
||||
@ -477,24 +477,24 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
shift_set = c40_shift[source[sp]];
|
||||
value = c40_value[source[sp]];
|
||||
}
|
||||
|
||||
|
||||
if(gs1 && (source[sp] == '[')) {
|
||||
shift_set = 2;
|
||||
value = 27; /* FNC1 */
|
||||
}
|
||||
|
||||
|
||||
if(shift_set != 0) {
|
||||
c40_buffer[c40_p] = shift_set - 1; c40_p++;
|
||||
}
|
||||
c40_buffer[c40_p] = value; c40_p++;
|
||||
|
||||
|
||||
if(c40_p >= 3) {
|
||||
int iv;
|
||||
|
||||
|
||||
iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1;
|
||||
target[tp] = iv / 256; tp++;
|
||||
target[tp] = iv % 256; tp++;
|
||||
|
||||
|
||||
c40_buffer[0] = c40_buffer[3];
|
||||
c40_buffer[1] = c40_buffer[4];
|
||||
c40_buffer[2] = c40_buffer[5];
|
||||
@ -506,10 +506,10 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_TEXT) { /* Step D - Text encodation */
|
||||
int shift_set, value, done = 0, latch = 0;
|
||||
|
||||
|
||||
next_mode = C1_TEXT;
|
||||
if(text_p == 0) {
|
||||
if((length - sp) >= 12) {
|
||||
@ -544,12 +544,12 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
next_mode = C1_ASCII; done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!(done)) {
|
||||
next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(next_mode != C1_TEXT) {
|
||||
target[tp] = 255; tp++; /* Unlatch */
|
||||
} else {
|
||||
@ -562,24 +562,24 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
shift_set = text_shift[source[sp]];
|
||||
value = text_value[source[sp]];
|
||||
}
|
||||
|
||||
|
||||
if(gs1 && (source[sp] == '[')) {
|
||||
shift_set = 2;
|
||||
value = 27; /* FNC1 */
|
||||
}
|
||||
|
||||
|
||||
if(shift_set != 0) {
|
||||
text_buffer[text_p] = shift_set - 1; text_p++;
|
||||
}
|
||||
text_buffer[text_p] = value; text_p++;
|
||||
|
||||
|
||||
if(text_p >= 3) {
|
||||
int iv;
|
||||
|
||||
|
||||
iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1;
|
||||
target[tp] = iv / 256; tp++;
|
||||
target[tp] = iv % 256; tp++;
|
||||
|
||||
|
||||
text_buffer[0] = text_buffer[3];
|
||||
text_buffer[1] = text_buffer[4];
|
||||
text_buffer[2] = text_buffer[5];
|
||||
@ -591,7 +591,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_EDI) { /* Step E - EDI Encodation */
|
||||
int value = 0,latch = 0;
|
||||
|
||||
@ -629,12 +629,12 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
next_mode = C1_ASCII;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!((isedi(source[sp]) && isedi(source[sp + 1])) && isedi(source[sp + 2]))) {
|
||||
next_mode = C1_ASCII;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(next_mode != C1_EDI) {
|
||||
target[tp] = 255; tp++; /* Unlatch */
|
||||
} else {
|
||||
@ -644,16 +644,16 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
if(source[sp] == ' ') { value = 3; }
|
||||
if((source[sp] >= '0') && (source[sp] <= '9')) { value = source[sp] - '0' + 4; }
|
||||
if((source[sp] >= 'A') && (source[sp] <= 'Z')) { value = source[sp] - 'A' + 14; }
|
||||
|
||||
|
||||
edi_buffer[edi_p] = value; edi_p++;
|
||||
|
||||
|
||||
if(edi_p >= 3) {
|
||||
int iv;
|
||||
|
||||
|
||||
iv = (1600 * edi_buffer[0]) + (40 * edi_buffer[1]) + (edi_buffer[2]) + 1;
|
||||
target[tp] = iv / 256; tp++;
|
||||
target[tp] = iv % 256; tp++;
|
||||
|
||||
|
||||
edi_buffer[0] = edi_buffer[3];
|
||||
edi_buffer[1] = edi_buffer[4];
|
||||
edi_buffer[2] = edi_buffer[5];
|
||||
@ -665,12 +665,12 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_DECIMAL) { /* Step F - Decimal encodation */
|
||||
int value, decimal_count, data_left;
|
||||
|
||||
|
||||
next_mode = C1_DECIMAL;
|
||||
|
||||
|
||||
data_left = length - sp;
|
||||
decimal_count = 0;
|
||||
|
||||
@ -688,9 +688,9 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
int bits_left_in_byte, target_count;
|
||||
int sub_target;
|
||||
/* Finish Decimal mode and go back to ASCII */
|
||||
|
||||
|
||||
concat(decimal_binary, "111111"); /* Unlatch */
|
||||
|
||||
|
||||
target_count = 3;
|
||||
if(strlen(decimal_binary) <= 16) { target_count = 2; }
|
||||
if(strlen(decimal_binary) <= 8) { target_count = 1; }
|
||||
@ -714,11 +714,11 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
concat(decimal_binary, "1111");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(bits_left_in_byte == 6) {
|
||||
concat(decimal_binary, "01");
|
||||
}
|
||||
|
||||
|
||||
/* Binary buffer is full - transfer to target */
|
||||
if(target_count >= 1) {
|
||||
sub_target = 0;
|
||||
@ -756,7 +756,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
if(decimal_binary[23] == '1') { sub_target += 1; }
|
||||
target[tp] = sub_target; tp++;
|
||||
}
|
||||
|
||||
|
||||
next_mode = C1_ASCII;
|
||||
} else {
|
||||
/* There are three digits - convert the value to binary */
|
||||
@ -775,11 +775,11 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
|
||||
sp+= 3;
|
||||
}
|
||||
|
||||
|
||||
if(strlen(decimal_binary) >= 24) {
|
||||
int target1 = 0, target2 = 0, target3 = 0;
|
||||
char temp_binary[40];
|
||||
|
||||
|
||||
/* Binary buffer is full - transfer to target */
|
||||
if(decimal_binary[0] == '1') { target1 += 128; }
|
||||
if(decimal_binary[1] == '1') { target1 += 64; }
|
||||
@ -808,7 +808,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
target[tp] = target1; tp++;
|
||||
target[tp] = target2; tp++;
|
||||
target[tp] = target3; tp++;
|
||||
|
||||
|
||||
strcpy(temp_binary, "");
|
||||
if(strlen(decimal_binary) > 24) {
|
||||
for(i = 0; i <= (strlen(decimal_binary) - 24); i++) {
|
||||
@ -818,10 +818,10 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_BYTE) {
|
||||
next_mode = C1_BYTE;
|
||||
|
||||
|
||||
if(gs1 && (source[sp] == '[')) {
|
||||
next_mode = C1_ASCII;
|
||||
} else {
|
||||
@ -829,7 +829,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(next_mode != C1_BYTE) {
|
||||
/* Insert byte field length */
|
||||
if((tp - byte_start) <= 249) {
|
||||
@ -852,18 +852,18 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(tp > 1480) {
|
||||
/* Data is too large for symbol */
|
||||
strcpy(symbol->errtxt, "Input data too long");
|
||||
return 0;
|
||||
}
|
||||
} while (sp < length);
|
||||
|
||||
|
||||
/* Empty buffers */
|
||||
if(c40_p == 2) {
|
||||
int iv;
|
||||
|
||||
|
||||
c40_buffer[2] = 1;
|
||||
iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1;
|
||||
target[tp] = iv / 256; tp++;
|
||||
@ -872,7 +872,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
}
|
||||
if(c40_p == 1) {
|
||||
int iv;
|
||||
|
||||
|
||||
c40_buffer[1] = 1;
|
||||
c40_buffer[2] = 31; /* Pad */
|
||||
iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1;
|
||||
@ -882,7 +882,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
}
|
||||
if(text_p == 2) {
|
||||
int iv;
|
||||
|
||||
|
||||
text_buffer[2] = 1;
|
||||
iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1;
|
||||
target[tp] = iv / 256; tp++;
|
||||
@ -891,7 +891,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
}
|
||||
if(text_p == 1) {
|
||||
int iv;
|
||||
|
||||
|
||||
text_buffer[1] = 1;
|
||||
text_buffer[2] = 31; /* Pad */
|
||||
iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1;
|
||||
@ -899,32 +899,32 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
target[tp] = iv % 256; tp++;
|
||||
target[tp] = 255; tp++; /* Unlatch */
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_DECIMAL) {
|
||||
int bits_left_in_byte, target_count;
|
||||
int sub_target;
|
||||
/* Finish Decimal mode and go back to ASCII */
|
||||
|
||||
|
||||
concat(decimal_binary, "111111"); /* Unlatch */
|
||||
|
||||
|
||||
target_count = 3;
|
||||
if(strlen(decimal_binary) <= 16) { target_count = 2; }
|
||||
if(strlen(decimal_binary) <= 8) { target_count = 1; }
|
||||
bits_left_in_byte = (8 * target_count) - strlen(decimal_binary);
|
||||
if(bits_left_in_byte == 8) { bits_left_in_byte = 0; }
|
||||
|
||||
|
||||
if(bits_left_in_byte == 2) {
|
||||
concat(decimal_binary, "01");
|
||||
}
|
||||
|
||||
|
||||
if((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
|
||||
concat(decimal_binary, "1111");
|
||||
}
|
||||
|
||||
|
||||
if(bits_left_in_byte == 6) {
|
||||
concat(decimal_binary, "01");
|
||||
}
|
||||
|
||||
|
||||
/* Binary buffer is full - transfer to target */
|
||||
if(target_count >= 1) {
|
||||
sub_target = 0;
|
||||
@ -963,7 +963,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
target[tp] = sub_target; tp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(current_mode == C1_BYTE) {
|
||||
/* Insert byte field length */
|
||||
if((tp - byte_start) <= 249) {
|
||||
@ -1017,12 +1017,12 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
char datagrid[136][120];
|
||||
int row, col;
|
||||
int sub_version = 0;
|
||||
|
||||
|
||||
if((symbol->option_2 < 0) || (symbol->option_2 > 10)) {
|
||||
strcpy(symbol->errtxt, "Invalid symbol size");
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
|
||||
|
||||
if(symbol->option_2 == 9) {
|
||||
/* Version S */
|
||||
int codewords;
|
||||
@ -1030,7 +1030,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
unsigned int data[15], ecc[15];
|
||||
int stream[30];
|
||||
int block_width;
|
||||
|
||||
|
||||
if(length > 18) {
|
||||
strcpy(symbol->errtxt, "Input data too long");
|
||||
return ERROR_TOO_LONG;
|
||||
@ -1039,11 +1039,11 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
|
||||
sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */
|
||||
if(length <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */
|
||||
if(length <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */
|
||||
|
||||
|
||||
binary_load(elreg, (char *)source, length);
|
||||
hex_dump(elreg);
|
||||
|
||||
@ -1059,7 +1059,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
data[codewords - i - 1] += 8 * elreg[(i * 5) + 3];
|
||||
data[codewords - i - 1] += 16 * elreg[(i * 5) + 4];
|
||||
}
|
||||
|
||||
|
||||
rs_init_gf(0x25);
|
||||
rs_init_code(codewords, 1);
|
||||
rs_encode_long(codewords, data, ecc);
|
||||
@ -1097,7 +1097,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
symbol->rows = 8;
|
||||
symbol->width = 10 * sub_version + 1;
|
||||
}
|
||||
|
||||
|
||||
if(symbol->option_2 == 10) {
|
||||
/* Version T */
|
||||
unsigned int data[40], ecc[25];
|
||||
@ -1107,16 +1107,16 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
for(i = 0; i < 40; i++) { data[i] = 0; }
|
||||
data_length = c1_encode(symbol, source, data, length);
|
||||
|
||||
|
||||
if(data_length == 0) {
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
if(data_length > 38) {
|
||||
strcpy(symbol->errtxt, "Input data too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
size = 10;
|
||||
sub_version = 3; data_cw = 38; ecc_cw = 22; block_width = 12;
|
||||
if(data_length <= 24) { sub_version = 2; data_cw = 24; ecc_cw = 16; block_width = 8; }
|
||||
@ -1125,13 +1125,13 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for(i = data_length; i < data_cw; i++) {
|
||||
data[i] = 129; /* Pad */
|
||||
}
|
||||
|
||||
|
||||
/* Calculate error correction data */
|
||||
rs_init_gf(0x12d);
|
||||
rs_init_code(ecc_cw, 1);
|
||||
rs_encode_long(data_cw, data, ecc);
|
||||
rs_free();
|
||||
|
||||
|
||||
/* "Stream" combines data and error correction data */
|
||||
for(i = 0; i < data_cw; i++) {
|
||||
stream[i] = data[i];
|
||||
@ -1160,11 +1160,11 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
symbol->rows = 16;
|
||||
symbol->width = (sub_version * 16) + 1;
|
||||
}
|
||||
|
||||
|
||||
if((symbol->option_2 != 9) && (symbol->option_2 != 10)) {
|
||||
/* Version A to H */
|
||||
unsigned int data[1500], ecc[600];
|
||||
@ -1192,14 +1192,14 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for(i = data_length; i < c1_data_length[size - 1]; i++) {
|
||||
data[i] = 129; /* Pad */
|
||||
}
|
||||
|
||||
|
||||
/* Calculate error correction data */
|
||||
data_length = c1_data_length[size - 1];
|
||||
for(i = 0; i < 190; i++) { sub_data[i] = 0; }
|
||||
for(i = 0; i < 75; i++) { sub_ecc[i] = 0; }
|
||||
|
||||
data_blocks = c1_blocks[size - 1];
|
||||
|
||||
|
||||
rs_init_gf(0x12d);
|
||||
rs_init_code(c1_ecc_blocks[size - 1], 0);
|
||||
for(i = 0; i < data_blocks; i++) {
|
||||
@ -1213,7 +1213,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
rs_free();
|
||||
|
||||
|
||||
/* "Stream" combines data and error correction data */
|
||||
for(i = 0; i < data_length; i++) {
|
||||
stream[i] = data[i];
|
||||
@ -1253,7 +1253,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
symbol->rows = c1_height[size - 1];
|
||||
symbol->width = c1_width[size - 1];
|
||||
}
|
||||
|
||||
|
||||
switch(size) {
|
||||
case 1: /* Version A */
|
||||
central_finder(symbol, 6, 3, 1);
|
||||
@ -1510,6 +1510,6 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for(i = 0; i < symbol->rows; i++) {
|
||||
symbol->row_height[i] = 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ int validator(char test_string[], char source[])
|
||||
if (!(latch)) {
|
||||
return ERROR_INVALID_DATA; }
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ int escape_char_process(struct zint_symbol *my_symbol, unsigned char input_strin
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
|
||||
|
||||
do {
|
||||
if(input_string[i] == '\\') {
|
||||
switch(input_string[i + 1]) {
|
||||
@ -162,9 +162,9 @@ int escape_char_process(struct zint_symbol *my_symbol, unsigned char input_strin
|
||||
j++;
|
||||
} while (i < length);
|
||||
escaped_string[j] = '\0';
|
||||
|
||||
|
||||
error_number = ZBarcode_Encode(my_symbol, escaped_string, j);
|
||||
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
@ -291,6 +291,7 @@ int batch_process(struct zint_symbol *symbol, char *filename)
|
||||
error_number = ZBarcode_Encode_and_Print(symbol, buffer, posn, 0);
|
||||
if(error_number != 0) {
|
||||
fprintf(stderr, "On line %d: %s\n", line_count, symbol->errtxt);
|
||||
fflush(stderr);
|
||||
}
|
||||
ZBarcode_Clear(symbol);
|
||||
memset(buffer, 0, sizeof(unsigned char) * 7100);
|
||||
@ -302,6 +303,7 @@ int batch_process(struct zint_symbol *symbol, char *filename)
|
||||
}
|
||||
if(posn > 7090) {
|
||||
fprintf(stderr, "On line %d: Input data too long\n", line_count);
|
||||
fflush(stderr);
|
||||
do {
|
||||
character = fgetc(file);
|
||||
} while((!feof(file)) && (character != '\n'));
|
||||
@ -310,6 +312,7 @@ int batch_process(struct zint_symbol *symbol, char *filename)
|
||||
|
||||
if(character != '\n') {
|
||||
fprintf(stderr, "Warning: No newline at end of file\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
@ -438,6 +441,7 @@ int main(int argc, char **argv)
|
||||
if(my_symbol->scale < 0.01) {
|
||||
/* Zero and negative values are not permitted */
|
||||
fprintf(stderr, "Invalid scale value\n");
|
||||
fflush(stderr);
|
||||
my_symbol->scale = 1.0;
|
||||
}
|
||||
}
|
||||
@ -451,6 +455,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->border_width = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Border width out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "height")) {
|
||||
@ -463,6 +468,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->height = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Symbol height out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,6 +477,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->option_2 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Number of columns out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "vers")) {
|
||||
@ -478,6 +485,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->option_2 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Invalid QR Code version\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "secure")) {
|
||||
@ -485,6 +493,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->option_1 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "ECC level out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "primary")) {
|
||||
@ -492,6 +501,7 @@ int main(int argc, char **argv)
|
||||
strcpy(my_symbol->primary, optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Primary data string too long");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "mode")) {
|
||||
@ -499,6 +509,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->option_1 = optarg[0] - '0';
|
||||
} else {
|
||||
fprintf(stderr, "Invalid mode\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "rotate")) {
|
||||
@ -548,6 +559,7 @@ int main(int argc, char **argv)
|
||||
my_symbol->whitespace_width = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Whitespace value out of range");
|
||||
fflush(stderr);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -560,11 +572,13 @@ int main(int argc, char **argv)
|
||||
generated = 1;
|
||||
if(error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Cannot define data in batch mode");
|
||||
fflush(stderr);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -577,6 +591,7 @@ int main(int argc, char **argv)
|
||||
generated = 1;
|
||||
if(error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
@ -586,6 +601,7 @@ int main(int argc, char **argv)
|
||||
generated = 1;
|
||||
if(error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
@ -606,18 +622,21 @@ int main(int argc, char **argv)
|
||||
|
||||
default:
|
||||
fprintf(stderr, "?? getopt error 0%o\n", c);
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, "Invalid option ");
|
||||
while (optind < argc)
|
||||
fprintf(stderr, "%s", argv[optind++]);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
if(generated == 0) {
|
||||
fprintf(stderr, "error: No data received, no symbol generated\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
ZBarcode_Delete(my_symbol);
|
||||
|
@ -1,5 +1,5 @@
|
||||
Name: zint
|
||||
Version: 2.3.1
|
||||
Version: 2.4.3
|
||||
Release: 2%{?dist}
|
||||
Summary: A barcode generator and library
|
||||
License: GPLv3+
|
||||
@ -114,7 +114,7 @@ rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%doc COPYING readme
|
||||
%doc COPYING README
|
||||
%{_bindir}/%{name}
|
||||
%{_libdir}/libzint.so.*
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user