mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-12 22:25:59 -04:00
Add Channel Code
This commit is contained in:
parent
cd614f42f7
commit
0e560805b4
8 changed files with 232 additions and 17 deletions
144
backend/code.c
144
backend/code.c
|
@ -73,6 +73,16 @@ static char *C93Table[47] = {"131112", "111213", "111312", "111411", "121113", "
|
|||
"122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131",
|
||||
"121221", "312111", "311121", "122211"};
|
||||
|
||||
/* Global Variables for Channel Code */
|
||||
int S[11], B[11];
|
||||
long value;
|
||||
long target_value;
|
||||
char pattern[30];
|
||||
|
||||
/* Function Prototypes */
|
||||
void NextS(int Chan, int i, int MaxS, int MaxB);
|
||||
void NextB(int Chan, int i, int MaxB, int MaxS);
|
||||
|
||||
/* *********************** CODE 11 ******************** */
|
||||
|
||||
int code_11(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
@ -88,12 +98,12 @@ int code_11(struct zint_symbol *symbol, unsigned char source[])
|
|||
strcpy(dest, "");
|
||||
|
||||
if(ustrlen(source) > 80) {
|
||||
strcpy(symbol->errtxt, "Input too long [011]");
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NASET, source);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [012]");
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
c_weight = 1;
|
||||
|
@ -170,12 +180,12 @@ int c39(struct zint_symbol *symbol, unsigned char source[])
|
|||
|
||||
to_upper(source);
|
||||
if(ustrlen(source) > 45) {
|
||||
strcpy(symbol->errtxt, "Input too long [081]");
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(TCSET , source);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [082]");
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
@ -257,12 +267,12 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[])
|
|||
count = 0;
|
||||
h = ustrlen(source);
|
||||
if(h > 6) {
|
||||
strcpy(symbol->errtxt, "Input wrong length [521]");
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [522]");
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
@ -310,7 +320,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[])
|
|||
/* only stops strings which are far too long - actual length of the barcode
|
||||
depends on the type of data being encoded - if it's too long it's picked up
|
||||
by c39() */
|
||||
strcpy(symbol->errtxt, "Input too long [091]");
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
@ -318,7 +328,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[])
|
|||
for(i = 0; i < ustrlen(source); i++) {
|
||||
if(source[i] > 127) {
|
||||
/* Cannot encode extended ASCII */
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data [092]");
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
@ -368,14 +378,14 @@ int c93(struct zint_symbol *symbol, unsigned char source[])
|
|||
if(ustrlen(source) > 45) {
|
||||
/* This stops rediculously long input - the actual length of the barcode
|
||||
depends on the type of data */
|
||||
strcpy(symbol->errtxt, "Input too long [251]");
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
if(source[i] > 127) {
|
||||
/* Cannot encode extended ASCII */
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data [252]");
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +405,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[])
|
|||
|
||||
/* Now we can check the true length of the barcode */
|
||||
if(strlen(buffer) > 45) {
|
||||
strcpy(symbol->errtxt, "Input too long [253]");
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
@ -466,3 +476,115 @@ int c93(struct zint_symbol *symbol, unsigned char source[])
|
|||
}
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* NextS() and NextB() are from ANSI/AIM BC12-1998 and are Copyright (c) AIM 1997 */
|
||||
/* Their are used here on the understanding that they form part of the specification
|
||||
for Channel Code and therefore their use is permitted under the following terms
|
||||
set out in that document:
|
||||
|
||||
"It is the intent and understanding of AIM [t]hat the symbology presented in this
|
||||
specification is entirely in the public domain and free of all use restrictions,
|
||||
licenses and fees. AIM USA, its memer companies, or individual officers
|
||||
assume no liability for the use of this document." */
|
||||
|
||||
void CheckCharacter() {
|
||||
int i;
|
||||
char part[3];
|
||||
|
||||
if(value == target_value) {
|
||||
/* Target reached - save the generated pattern */
|
||||
strcpy(pattern, "11110");
|
||||
for(i = 0; i < 11; i++) {
|
||||
part[0] = itoc(S[i]);
|
||||
part[1] = itoc(B[i]);
|
||||
part[2] = '\0';
|
||||
concat(pattern, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NextB(int Chan, int i, int MaxB, int MaxS) {
|
||||
int b;
|
||||
|
||||
b = (S[i]+B[i-1]+S[i-1]+B[i-2] > 4)? 1:2;
|
||||
if (i < Chan+2) {
|
||||
for (; b <= MaxB; b++) {
|
||||
B[i] = b;
|
||||
NextS(Chan,i+1,MaxS,MaxB+1-b);
|
||||
}
|
||||
} else if (b <= MaxB) {
|
||||
B[i] = MaxB;
|
||||
CheckCharacter();
|
||||
value++;
|
||||
}
|
||||
}
|
||||
|
||||
void NextS(int Chan, int i, int MaxS, int MaxB) {
|
||||
int s;
|
||||
|
||||
for (s = (i<Chan+2)? 1: MaxS; s <= MaxS; s++) {
|
||||
S[i] = s;
|
||||
NextB(Chan,i,MaxB,MaxS+1-s);
|
||||
}
|
||||
}
|
||||
|
||||
int channel_code(struct zint_symbol *symbol, unsigned char source[]) {
|
||||
/* Channel Code - According to ANSI/AIM BC12-1998 */
|
||||
|
||||
int input_length, channels, i;
|
||||
int error_number = 0, range = 0, zeroes;
|
||||
char hrt[9];
|
||||
|
||||
input_length = ustrlen(source);
|
||||
target_value = 0;
|
||||
|
||||
if(input_length > 7) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; }
|
||||
if(channels == 0) { channels = input_length + 1; }
|
||||
if(channels == 2) { channels = 3; }
|
||||
|
||||
for(i = 0; i < input_length; i++) {
|
||||
target_value *= 10;
|
||||
target_value += ctoi((char) source[i]);
|
||||
}
|
||||
|
||||
switch(channels) {
|
||||
case 3: if(target_value > 26) { range = 1; } break;
|
||||
case 4: if(target_value > 292) { range = 1; } break;
|
||||
case 5: if(target_value > 3493) { range = 1; } break;
|
||||
case 6: if(target_value > 44072) { range = 1; } break;
|
||||
case 7: if(target_value > 576688) { range = 1; } break;
|
||||
case 8: if(target_value > 7742862) { range = 1; } break;
|
||||
}
|
||||
if(range) {
|
||||
strcpy(symbol->errtxt, "Value out of range");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; }
|
||||
|
||||
B[0] = S[1] = B[1] = S[2] = B[2] = 1;
|
||||
value = 0;
|
||||
NextS(channels,3,channels,channels);
|
||||
|
||||
strcpy(hrt, "");
|
||||
zeroes = channels - 1 - input_length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(hrt, "0");
|
||||
}
|
||||
concat(hrt, (char *)source);
|
||||
ustrcpy(symbol->text, (unsigned char *)hrt);
|
||||
|
||||
expand(symbol, pattern);
|
||||
|
||||
return error_number;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue