mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
NULL character support
This commit is contained in:
@ -57,12 +57,13 @@ static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322",
|
||||
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
|
||||
"2331112"};
|
||||
|
||||
int parunmodd(unsigned char llyth);
|
||||
int parunmodd(unsigned char llyth, char nullchar);
|
||||
void grwp(int *indexliste);
|
||||
void dxsmooth(int *indexliste);
|
||||
|
||||
int a3_convert(unsigned char source) {
|
||||
int a3_convert(unsigned char source, char nullchar) {
|
||||
/* Annex A section 3 */
|
||||
if(source == nullchar) { return 64; }
|
||||
if(source < 32) { return source + 64; }
|
||||
if((source >= 32) && (source <= 127)) { return source - 32; }
|
||||
if((source >= 128) && (source <= 159)) { return (source - 128) + 64; }
|
||||
@ -70,8 +71,13 @@ int a3_convert(unsigned char source) {
|
||||
return (source - 128) - 32;
|
||||
}
|
||||
|
||||
int character_subset_select(unsigned char source[], int input_position) {
|
||||
int character_subset_select(unsigned char source[], int input_position, char nullchar) {
|
||||
/* Section 4.5.2 - Determining the Character Subset Selector in a Row */
|
||||
if(source[input_position] == nullchar) {
|
||||
/* NULL character */
|
||||
return MODEA;
|
||||
}
|
||||
|
||||
if((source[input_position] >= '0') && (source[input_position + 1] <= '9')) {
|
||||
/* Rule 1 */
|
||||
return MODEC;
|
||||
@ -91,7 +97,7 @@ int character_subset_select(unsigned char source[], int input_position) {
|
||||
return MODEB;
|
||||
}
|
||||
|
||||
int data_encode_blockf(unsigned char source[], int subset_selector[], int blockmatrix[][62], int *columns_needed, int *rows_needed, int *final_mode)
|
||||
int data_encode_blockf(unsigned char source[], int subset_selector[], int blockmatrix[][62], int *columns_needed, int *rows_needed, int *final_mode, char nullchar)
|
||||
{
|
||||
int i, input_position, input_length, current_mode, current_row, error_number;
|
||||
int column_position, c, done, exit_status;
|
||||
@ -112,7 +118,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
if(column_position == 0) {
|
||||
/* The Beginning of a row */
|
||||
c = (*columns_needed);
|
||||
current_mode = character_subset_select(source, input_position);
|
||||
current_mode = character_subset_select(source, input_position, nullchar);
|
||||
subset_selector[current_row] = current_mode;
|
||||
}
|
||||
|
||||
@ -121,15 +127,15 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
/* Ensure that there is sufficient encodation capacity to continue (using the rules of Annex B.2). */
|
||||
switch(current_mode) {
|
||||
case MODEA: /* Table B1 applies */
|
||||
if(parunmodd(source[input_position]) == ABORC) {
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
if(parunmodd(source[input_position], nullchar) == ABORC) {
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if((parunmodd(source[input_position]) == SHIFTB) && (c == 1)) {
|
||||
if((parunmodd(source[input_position], nullchar) == SHIFTB) && (c == 1)) {
|
||||
/* Needs two symbols */
|
||||
blockmatrix[current_row][column_position] = 100; /* Code B */
|
||||
column_position++;
|
||||
@ -161,15 +167,15 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
break;
|
||||
case MODEB: /* Table B2 applies */
|
||||
if(parunmodd(source[input_position]) == ABORC) {
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
if(parunmodd(source[input_position], nullchar) == ABORC) {
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if((parunmodd(source[input_position]) == SHIFTA) && (c == 1)) {
|
||||
if((parunmodd(source[input_position], nullchar) == SHIFTA) && (c == 1)) {
|
||||
/* Needs two symbols */
|
||||
blockmatrix[current_row][column_position] = 101; /* Code A */
|
||||
column_position++;
|
||||
@ -201,7 +207,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
break;
|
||||
case MODEC: /* Table B3 applies */
|
||||
if((parunmodd(source[input_position]) != ABORC) && (c == 1)) {
|
||||
if((parunmodd(source[input_position], nullchar) != ABORC) && (c == 1)) {
|
||||
/* Needs two symbols */
|
||||
blockmatrix[current_row][column_position] = 101; /* Code A */
|
||||
column_position++;
|
||||
@ -209,7 +215,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if(((parunmodd(source[input_position]) == ABORC) && (parunmodd(source[input_position + 1]) != ABORC))
|
||||
if(((parunmodd(source[input_position], nullchar) == ABORC) && (parunmodd(source[input_position + 1], nullchar) != ABORC))
|
||||
&& (c == 1)) {
|
||||
/* Needs two symbols */
|
||||
blockmatrix[current_row][column_position] = 101; /* Code A */
|
||||
@ -234,7 +240,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if(((parunmodd(source[input_position]) == AORB) || (parunmodd(source[input_position]) == SHIFTA)) && (current_mode == MODEA)) {
|
||||
if(((parunmodd(source[input_position], nullchar) == AORB) || (parunmodd(source[input_position], nullchar) == SHIFTA)) && (current_mode == MODEA)) {
|
||||
/* Annex B section 1 rule 2 */
|
||||
/* If in Code Subset A and the next data character can be encoded in Subset A encode the next
|
||||
character. */
|
||||
@ -244,7 +250,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -253,7 +259,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if(((parunmodd(source[input_position]) == AORB) || (parunmodd(source[input_position]) == SHIFTB)) && (current_mode == MODEB)) {
|
||||
if(((parunmodd(source[input_position], nullchar) == AORB) || (parunmodd(source[input_position], nullchar) == SHIFTB)) && (current_mode == MODEB)) {
|
||||
/* Annex B section 1 rule 3 */
|
||||
/* If in Code Subset B and the next data character can be encoded in subset B, encode the next
|
||||
character. */
|
||||
@ -263,7 +269,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -272,7 +278,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if(((parunmodd(source[input_position]) == ABORC) && (parunmodd(source[input_position + 1]) == ABORC)) && (current_mode == MODEC)) {
|
||||
if(((parunmodd(source[input_position], nullchar) == ABORC) && (parunmodd(source[input_position + 1], nullchar) == ABORC)) && (current_mode == MODEC)) {
|
||||
/* Annex B section 1 rule 4 */
|
||||
/* If in Code Subset C and the next data are 2 digits, encode them. */
|
||||
blockmatrix[current_row][column_position] = (ctoi(source[input_position]) * 10) + ctoi(source[input_position + 1]);
|
||||
@ -284,7 +290,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if(((current_mode == MODEA) || (current_mode == MODEB)) && (parunmodd(source[input_position]) == ABORC)) {
|
||||
if(((current_mode == MODEA) || (current_mode == MODEB)) && (parunmodd(source[input_position], nullchar) == ABORC)) {
|
||||
/* Count the number of numeric digits */
|
||||
/* If 4 or more numeric data characters occur together when in subsets A or B:
|
||||
a. If there is an even number of numeric data characters, insert a Code C character before the
|
||||
@ -292,7 +298,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
b. If there is an odd number of numeric data characters, insert a Code Set C character immedi-
|
||||
ately after the first numeric digit to change to subset C. */
|
||||
i = 0;
|
||||
do { i++; } while(parunmodd(source[input_position + i]) == ABORC);
|
||||
do { i++; } while(parunmodd(source[input_position + i], nullchar) == ABORC);
|
||||
i--;
|
||||
|
||||
if(i >= 4) {
|
||||
@ -309,14 +315,14 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
current_mode = MODEC;
|
||||
} else {
|
||||
/* Annex B section 1 rule 5b */
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
}
|
||||
done = 1;
|
||||
} else {
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -326,7 +332,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if((current_mode == MODEB) && (parunmodd(source[input_position]) == SHIFTA)) {
|
||||
if((current_mode == MODEB) && (parunmodd(source[input_position], nullchar) == SHIFTA)) {
|
||||
/* Annex B section 1 rule 6 */
|
||||
/* When in subset B and an ASCII control character occurs in the data:
|
||||
a. If there is a lower case character immediately following the control character, insert a Shift
|
||||
@ -343,7 +349,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -358,7 +364,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -369,14 +375,14 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if((current_mode == MODEA) && (parunmodd(source[input_position]) == SHIFTB)) {
|
||||
if((current_mode == MODEA) && (parunmodd(source[input_position], nullchar) == SHIFTB)) {
|
||||
/* Annex B section 1 rule 7 */
|
||||
/* When in subset A and a lower case character occurs in the data:
|
||||
a. If following that character, a control character occurs in the data before the occurrence of
|
||||
another lower case character, insert a Shift character before the lower case character.
|
||||
b. Otherwise, insert a Code B character before the lower case character to change to subset B. */
|
||||
if((parunmodd(source[input_position + 1]) == SHIFTA) &&
|
||||
(parunmodd(source[input_position + 2]) == SHIFTB)) {
|
||||
if((parunmodd(source[input_position + 1], nullchar) == SHIFTA) &&
|
||||
(parunmodd(source[input_position + 2], nullchar) == SHIFTB)) {
|
||||
/* Annex B section 1 rule 7a */
|
||||
blockmatrix[current_row][column_position] = 98; /* Shift */
|
||||
column_position++;
|
||||
@ -387,7 +393,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -402,7 +408,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -413,8 +419,8 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if((current_mode == MODEC) && ((parunmodd(source[input_position]) != ABORC) ||
|
||||
(parunmodd(source[input_position + 1]) != ABORC))) {
|
||||
if((current_mode == MODEC) && ((parunmodd(source[input_position], nullchar) != ABORC) ||
|
||||
(parunmodd(source[input_position + 1], nullchar) != ABORC))) {
|
||||
/* Annex B section 1 rule 8 */
|
||||
/* When in subset C and a non-numeric character (or a single digit) occurs in the data, insert a Code
|
||||
A or Code B character before that character, following rules 8a and 8b to determine between code
|
||||
@ -422,7 +428,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
a. If an ASCII control character (eg NUL) occurs in the data before any lower case character, use
|
||||
Code A.
|
||||
b. Otherwise use Code B. */
|
||||
if(parunmodd(source[input_position]) == SHIFTA) {
|
||||
if(parunmodd(source[input_position], nullchar) == SHIFTA) {
|
||||
/* Annex B section 1 rule 8a */
|
||||
blockmatrix[current_row][column_position] = 101; /* Code A */
|
||||
column_position++;
|
||||
@ -433,7 +439,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -449,7 +455,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
column_position++;
|
||||
c--;
|
||||
}
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
|
||||
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
|
||||
column_position++;
|
||||
c--;
|
||||
input_position++;
|
||||
@ -570,7 +576,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
|
||||
estimate_codelength = 0.0;
|
||||
last_mode = AORB; /* Codablock always starts with Code A */
|
||||
for(i = 0; i < input_length; i++) {
|
||||
this_mode = parunmodd(source[i]);
|
||||
this_mode = parunmodd(source[i], symbol->nullchar);
|
||||
if(this_mode != last_mode) {
|
||||
estimate_codelength += 1.0;
|
||||
}
|
||||
@ -597,7 +603,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
|
||||
}
|
||||
|
||||
/* Encode the data */
|
||||
error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode);
|
||||
error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode, symbol->nullchar);
|
||||
if(error_number > 0) {
|
||||
if(error_number == ERROR_TOO_LONG) {
|
||||
strcpy(symbol->errtxt, "Input data too long [743]");
|
||||
|
@ -326,13 +326,22 @@ int ec39(struct zint_symbol *symbol, unsigned char source[])
|
||||
/* Creates a buffer string and places control characters into it */
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
ascii_value = source[i];
|
||||
concat((char*)buffer, EC39Ctrl[ascii_value]);
|
||||
if(ascii_value == symbol->nullchar) {
|
||||
concat((char*)buffer, EC39Ctrl[0]);
|
||||
} else {
|
||||
concat((char*)buffer, EC39Ctrl[ascii_value]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Then sends the buffer to the C39 function */
|
||||
error_number = c39(symbol, buffer);
|
||||
|
||||
strcpy(symbol->text, (char*)source);
|
||||
for(i = 0; i < strlen(symbol->text); i++) {
|
||||
if(symbol->text[i] == symbol->nullchar) {
|
||||
symbol->text[i] = ' ';
|
||||
}
|
||||
}
|
||||
return error_number;
|
||||
}
|
||||
|
||||
@ -377,7 +386,11 @@ int c93(struct zint_symbol *symbol, unsigned char source[])
|
||||
/* Message Content */
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
ascii_value = source[i];
|
||||
concat(buffer, C93Ctrl[ascii_value]);
|
||||
if(ascii_value == symbol->nullchar) {
|
||||
concat(buffer, C93Ctrl[0]);
|
||||
} else {
|
||||
concat(buffer, C93Ctrl[ascii_value]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we can check the true length of the barcode */
|
||||
@ -446,5 +459,10 @@ int c93(struct zint_symbol *symbol, unsigned char source[])
|
||||
source[h + 2] = '\0';
|
||||
expand(symbol, dest);
|
||||
strcpy(symbol->text, (char*)source);
|
||||
for(i = 0; i < strlen(symbol->text); i++) {
|
||||
if(symbol->text[i] == symbol->nullchar) {
|
||||
symbol->text[i] = ' ';
|
||||
}
|
||||
}
|
||||
return error_number;
|
||||
}
|
||||
|
@ -57,11 +57,12 @@ static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322",
|
||||
"2331112"};
|
||||
/* Code 128 character encodation - Table 1 */
|
||||
|
||||
int parunmodd(unsigned char llyth)
|
||||
int parunmodd(unsigned char llyth, char nullchar)
|
||||
{
|
||||
int modd;
|
||||
modd = 0;
|
||||
|
||||
if(llyth == nullchar) { return SHIFTA; }
|
||||
if(llyth <= 31) { modd = SHIFTA; }
|
||||
if((llyth >= 32) && (llyth <= 95)) { modd = AORB; }
|
||||
if((llyth >= 48) && (llyth <= 57)) { modd = ABORC; }
|
||||
@ -136,10 +137,17 @@ void dxsmooth(int *indexliste)
|
||||
|
||||
}
|
||||
|
||||
void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars)
|
||||
void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars, char nullchr)
|
||||
{ /* Translate Code 128 Set A characters into barcodes */
|
||||
/* This set handles all control characters NULL to US */
|
||||
|
||||
if(source == nullchr) { /* Handle NULL character substitution */
|
||||
concat(dest, C128Table[64]);
|
||||
values[(*bar_chars)] = 64;
|
||||
(*bar_chars)++;
|
||||
return;
|
||||
}
|
||||
|
||||
if(source > 127) {
|
||||
if(source < 160) {
|
||||
concat(dest, C128Table[(source - 128) + 64]);
|
||||
@ -252,7 +260,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
indexliste = 0;
|
||||
indexchaine = 0;
|
||||
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
mode = parunmodd(source[indexchaine], symbol->nullchar);
|
||||
if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) {
|
||||
mode = AORB;
|
||||
}
|
||||
@ -266,7 +274,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
while ((list[1][indexliste] == mode) && (indexchaine < sourcelen)) {
|
||||
list[0][indexliste]++;
|
||||
indexchaine++;
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
mode = parunmodd(source[indexchaine], symbol->nullchar);
|
||||
if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) {
|
||||
mode = AORB;
|
||||
}
|
||||
@ -507,7 +515,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
switch(set[read])
|
||||
{ /* Encode data characters */
|
||||
case 'a':
|
||||
case 'A': c128_set_a(source[read], dest, values, &bar_characters);
|
||||
case 'A': c128_set_a(source[read], dest, values, &bar_characters, symbol->nullchar);
|
||||
read++;
|
||||
break;
|
||||
case 'b':
|
||||
@ -523,12 +531,15 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
/* check digit calculation */
|
||||
total_sum = 0;
|
||||
/*for(i = 0; i < bar_characters; i++) {
|
||||
printf("%d\n", values[i]);
|
||||
}*/
|
||||
|
||||
for(i = 0; i < bar_characters; i++)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
values[i] *= i;
|
||||
|
||||
}
|
||||
total_sum += values[i];
|
||||
}
|
||||
@ -538,6 +549,11 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
concat(dest, C128Table[106]);
|
||||
expand(symbol, dest);
|
||||
strcpy(symbol->text, (char*)source);
|
||||
for(i = 0; i < strlen(symbol->text); i++) {
|
||||
if(symbol->text[i] == symbol->nullchar) {
|
||||
symbol->text[i] = ' ';
|
||||
}
|
||||
}
|
||||
return errornum;
|
||||
}
|
||||
|
||||
@ -634,7 +650,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
indexliste = 0;
|
||||
indexchaine = 0;
|
||||
|
||||
mode = parunmodd(reduced[indexchaine]);
|
||||
mode = parunmodd(reduced[indexchaine], 0x00);
|
||||
if(reduced[indexchaine] == '[') {
|
||||
mode = ABORC;
|
||||
}
|
||||
@ -648,7 +664,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
while ((list[1][indexliste] == mode) && (indexchaine < strlen(reduced))) {
|
||||
list[0][indexliste]++;
|
||||
indexchaine++;
|
||||
mode = parunmodd(reduced[indexchaine]);
|
||||
mode = parunmodd(reduced[indexchaine], 0x00);
|
||||
if(reduced[indexchaine] == '[') {
|
||||
if(indexchaine % 2 == 0) {
|
||||
mode = ABORC;
|
||||
@ -780,7 +796,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
if(reduced[read] != '[') {
|
||||
switch(set[read])
|
||||
{ /* Encode data characters */
|
||||
case 'A': c128_set_a(reduced[read], dest, values, &bar_characters);
|
||||
case 'A': c128_set_a(reduced[read], dest, values, &bar_characters, 0x00);
|
||||
read++;
|
||||
break;
|
||||
case 'B': c128_set_b(reduced[read], dest, values, &bar_characters);
|
||||
|
@ -65,12 +65,18 @@ static char *C16KStartStop[8] = {"3211", "2221", "2122", "1411", "1132", "1231",
|
||||
static int C16KStartValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7};
|
||||
static int C16KStopValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3};
|
||||
|
||||
int parunmodd(unsigned char llyth);
|
||||
int parunmodd(unsigned char llyth, char nullchar);
|
||||
void grwp(int *indexliste);
|
||||
void dxsmooth(int *indexliste);
|
||||
|
||||
void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars)
|
||||
void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars, char nullchar)
|
||||
{
|
||||
if(source == nullchar) {
|
||||
values[(*bar_chars)] = 64;
|
||||
(*bar_chars)++;
|
||||
return;
|
||||
}
|
||||
|
||||
if(source > 127) {
|
||||
if(source < 160) {
|
||||
values[(*bar_chars)] = source + 64 - 128;
|
||||
@ -164,7 +170,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
|
||||
indexliste = 0;
|
||||
indexchaine = 0;
|
||||
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
mode = parunmodd(source[indexchaine], symbol->nullchar);
|
||||
|
||||
for(i = 0; i < 160; i++) {
|
||||
list[0][i] = 0;
|
||||
@ -175,7 +181,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
|
||||
while ((list[1][indexliste] == mode) && (indexchaine < input_length)) {
|
||||
list[0][indexliste]++;
|
||||
indexchaine++;
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
mode = parunmodd(source[indexchaine], symbol->nullchar);
|
||||
}
|
||||
indexliste++;
|
||||
} while (indexchaine < input_length);
|
||||
@ -385,7 +391,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
switch(set[read])
|
||||
{ /* Encode data characters */
|
||||
case 'A': c16k_set_a(source[read], values, &bar_characters);
|
||||
case 'A': c16k_set_a(source[read], values, &bar_characters, symbol->nullchar);
|
||||
read++;
|
||||
break;
|
||||
case 'B': c16k_set_b(source[read], values, &bar_characters);
|
||||
|
@ -360,7 +360,7 @@ int cc_b(struct zint_symbol *symbol, unsigned char source[], int cc_width)
|
||||
chainemc[mclength] = 920;
|
||||
mclength++;
|
||||
|
||||
byteprocess(chainemc, &mclength, data_string, 0, length, 0);
|
||||
byteprocess(chainemc, &mclength, data_string, 0, length, 0, 0x00);
|
||||
|
||||
/* Now figure out which variant of the symbol to use and load values accordingly */
|
||||
|
||||
@ -585,7 +585,7 @@ int cc_c(struct zint_symbol *symbol, unsigned char source[], int cc_width, int e
|
||||
chainemc[mclength] = 920; /* CC-C identifier */
|
||||
mclength++;
|
||||
|
||||
byteprocess(chainemc, &mclength, data_string, 0, length, 0);
|
||||
byteprocess(chainemc, &mclength, data_string, 0, length, 0, 0x00);
|
||||
|
||||
chainemc[0] = mclength;
|
||||
|
||||
|
@ -326,8 +326,8 @@ char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, char *enco
|
||||
t[tp++] = 238;
|
||||
enc = newenc;
|
||||
}
|
||||
t[tp++] = (v >> 8);
|
||||
t[tp++] = (v & 0xFF);
|
||||
t[tp++] = (int)(v / 256);
|
||||
t[tp++] = v % 256;
|
||||
p -= 3;
|
||||
out[0] = out[3];
|
||||
out[1] = out[4];
|
||||
@ -700,10 +700,10 @@ static char *encmake(int l, unsigned char *s, int *lenp, char exact)
|
||||
if (bl && b == E_BINARY)
|
||||
enc[p][(int)b].s += enc[p + 1][(int)b].s;
|
||||
/*
|
||||
* fprintf (stderr, "%d:", p); for (e = 0; e < E_MAX; e++) fprintf \
|
||||
* (stderr, " %c*%d/%d", encchr[e], enc[p][e].s, enc[p][e].t); \
|
||||
* fprintf (stderr, "\n");
|
||||
*/
|
||||
fprintf (stderr, "%d:", p); for (e = 0; e < E_MAX; e++) fprintf \
|
||||
(stderr, " %c*%d/%d", encchr[e], enc[p][e].s, enc[p][e].t); \
|
||||
fprintf (stderr, "\n");
|
||||
*/
|
||||
}
|
||||
encoding = safemalloc(l + 1);
|
||||
p = 0;
|
||||
@ -752,6 +752,8 @@ int iec16022ecc200(unsigned char *barcode, int barcodelen, struct zint_symbol *s
|
||||
int lend, *lenp;
|
||||
struct ecc200matrix_s *matrix;
|
||||
memset(binary, 0, sizeof(binary));
|
||||
unsigned char adjusted[barcodelen];
|
||||
int i;
|
||||
|
||||
lend = 0;
|
||||
lenp = &lend;
|
||||
@ -789,6 +791,15 @@ int iec16022ecc200(unsigned char *barcode, int barcodelen, struct zint_symbol *s
|
||||
case 30: W = 48; H = 16; break;
|
||||
default: W = 0; H = 0; break;
|
||||
}
|
||||
|
||||
/* Adjust for NULL characters */
|
||||
for(i = 0; i < barcodelen; i++) {
|
||||
if(barcode[i] == symbol->nullchar) {
|
||||
adjusted[i] = 0x00;
|
||||
} else {
|
||||
adjusted[i] = barcode[i];
|
||||
}
|
||||
}
|
||||
|
||||
// encoding
|
||||
if (W) { // known size
|
||||
@ -799,10 +810,10 @@ int iec16022ecc200(unsigned char *barcode, int barcodelen, struct zint_symbol *s
|
||||
}
|
||||
if (!encoding) {
|
||||
int len;
|
||||
char *e = encmake(barcodelen, barcode, &len, 1);
|
||||
char *e = encmake(barcodelen, adjusted, &len, 1);
|
||||
if (e && len != matrix->bytes) { // try not an exact fit
|
||||
free(e);
|
||||
e = encmake(barcodelen, barcode, &len, 0);
|
||||
e = encmake(barcodelen, adjusted, &len, 0);
|
||||
if (len > matrix->bytes) {
|
||||
strcpy(symbol->errtxt, "Cannot make barcode fit");
|
||||
if (e) free (e);
|
||||
@ -814,21 +825,22 @@ int iec16022ecc200(unsigned char *barcode, int barcodelen, struct zint_symbol *s
|
||||
} else {
|
||||
// find a suitable encoding
|
||||
if (encoding == NULL)
|
||||
encoding = encmake(barcodelen, barcode, NULL, 1);
|
||||
encoding = encmake(barcodelen, adjusted, NULL, 1);
|
||||
|
||||
if (encoding) { // find one that fits chosen encoding
|
||||
for (matrix = ecc200matrix; matrix->W; matrix++)
|
||||
if (ecc200encode(binary, matrix->bytes, barcode, barcodelen, encoding, 0))
|
||||
if (ecc200encode(binary, matrix->bytes, adjusted, barcodelen, encoding, 0)) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int len;
|
||||
char *e;
|
||||
e = encmake(barcodelen, barcode, &len, 1);
|
||||
e = encmake(barcodelen, adjusted, &len, 1);
|
||||
for (matrix = ecc200matrix;
|
||||
matrix->W && matrix->bytes != len; matrix++) ;
|
||||
if (e && !matrix->W) { // try for non exact fit
|
||||
free(e);
|
||||
e = encmake(barcodelen, barcode, &len, 0);
|
||||
e = encmake(barcodelen, adjusted, &len, 0);
|
||||
for (matrix = ecc200matrix; matrix->W && matrix->bytes < len; matrix++) ;
|
||||
}
|
||||
encoding = e;
|
||||
@ -840,11 +852,12 @@ int iec16022ecc200(unsigned char *barcode, int barcodelen, struct zint_symbol *s
|
||||
W = matrix->W;
|
||||
H = matrix->H;
|
||||
}
|
||||
if (!ecc200encode(binary, matrix->bytes, barcode, barcodelen, encoding, lenp)) {
|
||||
if (!ecc200encode(binary, matrix->bytes, adjusted, barcodelen, encoding, lenp)) {
|
||||
strcpy(symbol->errtxt, "Barcode too long");
|
||||
free(encoding);
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
|
||||
// ecc code
|
||||
ecc200(binary, matrix->bytes, matrix->datablock, matrix->rsblock);
|
||||
{ // placement
|
||||
|
@ -54,6 +54,7 @@ struct zint_symbol *ZBarcode_Create()
|
||||
symbol->row_height[i] = 0;
|
||||
}
|
||||
return symbol;
|
||||
symbol->nullchar = 0x00;
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,7 +112,7 @@ void maxi_bump(int set[], int character[], int bump_posn)
|
||||
}
|
||||
}
|
||||
|
||||
int maxi_text_process(int mode, unsigned char source[])
|
||||
int maxi_text_process(int mode, unsigned char source[], char nullchar)
|
||||
{
|
||||
/* Format text according to Appendix A */
|
||||
|
||||
@ -136,8 +136,13 @@ int maxi_text_process(int mode, unsigned char source[])
|
||||
for (i = 0; i < length; i++) {
|
||||
/* Look up characters in table from Appendix A - this gives
|
||||
value and code set for most characters */
|
||||
set[i] = maxiCodeSet[source[i]];
|
||||
character[i] = maxiSymbolChar[source[i]];
|
||||
if(source[i] == nullchar) {
|
||||
set[i] = maxiCodeSet[0];
|
||||
character[i] = maxiSymbolChar[0];
|
||||
} else {
|
||||
set[i] = maxiCodeSet[source[i]];
|
||||
character[i] = maxiSymbolChar[source[i]];
|
||||
}
|
||||
}
|
||||
|
||||
/* If a character can be represented in more than one code set,
|
||||
@ -623,7 +628,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[])
|
||||
maxi_codeword[0] = mode;
|
||||
}
|
||||
|
||||
i = maxi_text_process(mode, source);
|
||||
i = maxi_text_process(mode, source, symbol->nullchar);
|
||||
if(i == ERROR_TOO_LONG ) {
|
||||
strcpy(symbol->errtxt, "Input data too long [574]");
|
||||
return i;
|
||||
|
@ -63,11 +63,15 @@ static int MicroAutosize[56] =
|
||||
int liste[2][1000]; /* global - okay, so I got _almost_ everything local! */
|
||||
|
||||
/* 866 */
|
||||
int quelmode(char codeascii)
|
||||
int quelmode(char codeascii, char nullchar)
|
||||
{
|
||||
int mode;
|
||||
mode = BYT;
|
||||
|
||||
if(codeascii == nullchar) {
|
||||
return BYT;
|
||||
}
|
||||
|
||||
if((codeascii >= ' ') && (codeascii <= '~')) { mode = TEX; }
|
||||
if(codeascii == '\t') { mode = TEX; }
|
||||
if(codeascii == '\n') { mode = TEX; }
|
||||
@ -304,7 +308,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len
|
||||
}
|
||||
|
||||
/* 671 */
|
||||
void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block)
|
||||
void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block, char nullchar)
|
||||
{
|
||||
|
||||
int i, j, k, l, longueur;
|
||||
@ -343,16 +347,26 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start
|
||||
for(i = 0; i < 8; i++) {
|
||||
shiftup(y_reg);
|
||||
}
|
||||
|
||||
if((chaine[start + j + k] & 0x80) != 0) { y_reg[7] = 1; }
|
||||
if((chaine[start + j + k] & 0x40) != 0) { y_reg[6] = 1; }
|
||||
if((chaine[start + j + k] & 0x20) != 0) { y_reg[5] = 1; }
|
||||
if((chaine[start + j + k] & 0x10) != 0) { y_reg[4] = 1; }
|
||||
if((chaine[start + j + k] & 0x08) != 0) { y_reg[3] = 1; }
|
||||
if((chaine[start + j + k] & 0x04) != 0) { y_reg[2] = 1; }
|
||||
if((chaine[start + j + k] & 0x02) != 0) { y_reg[1] = 1; }
|
||||
if((chaine[start + j + k] & 0x01) != 0) { y_reg[0] = 1; }
|
||||
|
||||
if(chaine[start + j + k] == nullchar) {
|
||||
y_reg[7] = 0;
|
||||
y_reg[6] = 0;
|
||||
y_reg[5] = 0;
|
||||
y_reg[4] = 0;
|
||||
y_reg[3] = 0;
|
||||
y_reg[2] = 0;
|
||||
y_reg[1] = 0;
|
||||
y_reg[0] = 0;
|
||||
} else {
|
||||
if((chaine[start + j + k] & 0x80) != 0) { y_reg[7] = 1; }
|
||||
if((chaine[start + j + k] & 0x40) != 0) { y_reg[6] = 1; }
|
||||
if((chaine[start + j + k] & 0x20) != 0) { y_reg[5] = 1; }
|
||||
if((chaine[start + j + k] & 0x10) != 0) { y_reg[4] = 1; }
|
||||
if((chaine[start + j + k] & 0x08) != 0) { y_reg[3] = 1; }
|
||||
if((chaine[start + j + k] & 0x04) != 0) { y_reg[2] = 1; }
|
||||
if((chaine[start + j + k] & 0x02) != 0) { y_reg[1] = 1; }
|
||||
if((chaine[start + j + k] & 0x01) != 0) { y_reg[0] = 1; }
|
||||
}
|
||||
}
|
||||
|
||||
for(l = 0; l < 4; l++) {
|
||||
@ -481,7 +495,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[])
|
||||
indexliste = 0;
|
||||
indexchaine = 0;
|
||||
|
||||
mode = quelmode(chaine[indexchaine]);
|
||||
mode = quelmode(chaine[indexchaine], symbol->nullchar);
|
||||
|
||||
for(i = 0; i < 1000; i++) {
|
||||
liste[0][i] = 0;
|
||||
@ -493,7 +507,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[])
|
||||
while ((liste[1][indexliste] == mode) && (indexchaine < ustrlen(chaine))) {
|
||||
liste[0][indexliste]++;
|
||||
indexchaine++;
|
||||
mode = quelmode(chaine[indexchaine]);
|
||||
mode = quelmode(chaine[indexchaine], symbol->nullchar);
|
||||
}
|
||||
indexliste++;
|
||||
} while (indexchaine < ustrlen(chaine));
|
||||
@ -510,7 +524,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[])
|
||||
textprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i);
|
||||
break;
|
||||
case BYT: /* 670 - octet stream mode */
|
||||
byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i);
|
||||
byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i, symbol->nullchar);
|
||||
break;
|
||||
case NUM: /* 712 - numeric mode */
|
||||
numbprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i);
|
||||
@ -766,7 +780,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[])
|
||||
indexliste = 0;
|
||||
indexchaine = 0;
|
||||
|
||||
mode = quelmode(chaine[indexchaine]);
|
||||
mode = quelmode(chaine[indexchaine], symbol->nullchar);
|
||||
|
||||
for(i = 0; i < 1000; i++) {
|
||||
liste[0][i] = 0;
|
||||
@ -778,7 +792,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[])
|
||||
while ((liste[1][indexliste] == mode) && (indexchaine < ustrlen(chaine))) {
|
||||
liste[0][indexliste]++;
|
||||
indexchaine++;
|
||||
mode = quelmode(chaine[indexchaine]);
|
||||
mode = quelmode(chaine[indexchaine], symbol->nullchar);
|
||||
}
|
||||
indexliste++;
|
||||
} while (indexchaine < ustrlen(chaine));
|
||||
@ -795,7 +809,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[])
|
||||
textprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i);
|
||||
break;
|
||||
case BYT: /* 670 - octet stream mode */
|
||||
byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i);
|
||||
byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i, symbol->nullchar);
|
||||
break;
|
||||
case NUM: /* 712 - numeric mode */
|
||||
numbprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i);
|
||||
|
@ -435,4 +435,4 @@ static char *RAPC[53] = {"", "112231", "121231", "122131", "131131", "131221", "
|
||||
"112213", "112222", "112312", "112321", "111421", "111331", "111322", "111232", "111223",
|
||||
"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, char nullchar);
|
@ -80,7 +80,11 @@ int telepen(struct zint_symbol *symbol, unsigned char source[])
|
||||
for (i=0; i < ustrlen(source); i++)
|
||||
{
|
||||
ascii_value = source[i];
|
||||
concat(dest, TeleTable[ascii_value]);
|
||||
if(ascii_value == symbol->nullchar) {
|
||||
concat(dest, TeleTable[0]);
|
||||
} else {
|
||||
concat(dest, TeleTable[ascii_value]);
|
||||
}
|
||||
count += source[i];
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ struct zint_symbol {
|
||||
char encoded_data[178][1000];
|
||||
int row_height[155];
|
||||
char errtxt[100];
|
||||
char nullchar;
|
||||
};
|
||||
|
||||
/* Tbarcode 7 codes */
|
||||
|
Reference in New Issue
Block a user