mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Add leading zeroes rather than fail
This commit is contained in:
parent
0400d9d280
commit
3db0fa77e4
@ -241,16 +241,17 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
int itf14(struct zint_symbol *symbol, unsigned char source[])
|
||||
{
|
||||
int i, error_number, h;
|
||||
int i, error_number, h, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[15];
|
||||
|
||||
error_number = 0;
|
||||
|
||||
count = 0;
|
||||
h = ustrlen(source);
|
||||
|
||||
if(h != 13) {
|
||||
strcpy(symbol->errtxt, "Input wrong length [891]");
|
||||
if(h > 13) {
|
||||
strcpy(symbol->errtxt, "Input too long [891]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
@ -260,23 +261,31 @@ int itf14(struct zint_symbol *symbol, unsigned char source[])
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
strcpy(localstr, "");
|
||||
zeroes = 13 - ustrlen(source);
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(localstr, "0");
|
||||
}
|
||||
concat(localstr, (char *)source);
|
||||
|
||||
/* Calculate the check digit - the same method used for EAN-13 */
|
||||
|
||||
for (i = h - 1; i >= 0; i--)
|
||||
{
|
||||
count += ctoi(source[i]);
|
||||
count += ctoi(localstr[i]);
|
||||
|
||||
if (!((i%2) == 0))
|
||||
{
|
||||
count += 2 * ctoi(source[i]);
|
||||
count += 2 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
source[h] = itoc(check_digit);
|
||||
source[h + 1] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, source);
|
||||
strcpy(symbol->text, (char*)source);
|
||||
localstr[h] = itoc(check_digit);
|
||||
localstr[h + 1] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr);
|
||||
strcpy(symbol->text, localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
@ -284,11 +293,13 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[])
|
||||
{ /* Deutshe Post Leitcode */
|
||||
int i, error_number;
|
||||
unsigned int h, count, check_digit;
|
||||
char localstr[15], checkstr[3];
|
||||
int zeroes;
|
||||
|
||||
error_number = 0;
|
||||
count = 0;
|
||||
h = ustrlen(source);
|
||||
if(h != 13) {
|
||||
if(h > 13) {
|
||||
strcpy(symbol->errtxt, "Input wrong length [211]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
@ -298,32 +309,40 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[])
|
||||
return error_number;
|
||||
}
|
||||
|
||||
for (i = h - 1; i >= 0; i--)
|
||||
strcpy(localstr, "");
|
||||
zeroes = 13 - h;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
|
||||
for (i = 12; i >= 0; i--)
|
||||
{
|
||||
count += 4 * ctoi(source[i]);
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
|
||||
if (!((i%2) == 0))
|
||||
{
|
||||
count += 5 * ctoi(source[i]);
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
source[h] = itoc(check_digit);
|
||||
source[h + 1] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, source);
|
||||
strcpy(symbol->text, (char*)source);
|
||||
checkstr[0] = itoc(check_digit);
|
||||
checkstr[1] = '\0';
|
||||
strcpy(localstr, checkstr);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr);
|
||||
strcpy(symbol->text, localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int dpident(struct zint_symbol *symbol, unsigned char source[])
|
||||
{ /* Deutsche Post Identcode */
|
||||
int i, error_number;
|
||||
int i, error_number, zeroes;
|
||||
unsigned int h, count, check_digit;
|
||||
char localstr[13], checkstr[3];
|
||||
|
||||
count = 0;
|
||||
h = ustrlen(source);
|
||||
if(h != 11) {
|
||||
if(h > 11) {
|
||||
strcpy(symbol->errtxt, "Input wrong length [221]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
@ -333,20 +352,27 @@ int dpident(struct zint_symbol *symbol, unsigned char source[])
|
||||
return error_number;
|
||||
}
|
||||
|
||||
for (i = h - 1; i >= 0; i--)
|
||||
strcpy(localstr, "");
|
||||
zeroes = 11 - h;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
strcpy(localstr, "0");
|
||||
strcpy(localstr, (char *)source);
|
||||
|
||||
for (i = 10; i >= 0; i--)
|
||||
{
|
||||
count += 4 * ctoi(source[i]);
|
||||
count += 4 * ctoi(localstr[i]);
|
||||
|
||||
if (!((i%2) == 0))
|
||||
{
|
||||
count += 5 * ctoi(source[i]);
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
source[h] = itoc(check_digit);
|
||||
source[h + 1] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, source);
|
||||
strcpy(symbol->text, (char*)source);
|
||||
checkstr[0] = itoc(check_digit);
|
||||
checkstr[1] = '\0';
|
||||
strcpy(localstr, checkstr);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr);
|
||||
strcpy(symbol->text, localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
@ -110,9 +110,10 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[])
|
||||
char data_pattern[200];
|
||||
char fcc[3], dpid[10];
|
||||
unsigned int loopey, reader;
|
||||
int writer;
|
||||
int writer, i;
|
||||
strcpy (data_pattern, "");
|
||||
int errno;
|
||||
int errno, zeroes;
|
||||
char localstr[30];
|
||||
|
||||
errno = 0;
|
||||
|
||||
@ -135,8 +136,8 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[])
|
||||
return errno;
|
||||
}
|
||||
} else {
|
||||
if(ustrlen(source) != 8) {
|
||||
strcpy(symbol->errtxt, "Auspost input is wrong length [633]");
|
||||
if(ustrlen(source) > 8) {
|
||||
strcpy(symbol->errtxt, "Auspost input is too long [633]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
switch(symbol->symbology) {
|
||||
@ -144,10 +145,17 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[])
|
||||
case BARCODE_AUSROUTE: strcpy(fcc, "87"); break;
|
||||
case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
strcpy(localstr, "");
|
||||
zeroes = 8 - ustrlen(source);
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(localstr, "0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
errno = is_sane(GDSET, source);
|
||||
concat(localstr, (char*)source);
|
||||
errno = is_sane(GDSET, (unsigned char *)localstr);
|
||||
if(errno == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [634]");
|
||||
return errno;
|
||||
@ -155,10 +163,10 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
/* Verifiy that the first 8 characters are numbers */
|
||||
for(loopey = 0; loopey < 8; loopey++) {
|
||||
dpid[loopey] = source[loopey];
|
||||
dpid[loopey] = localstr[loopey];
|
||||
}
|
||||
dpid[8] = '\0';
|
||||
errno = is_sane(NESET, (unsigned char*)dpid);
|
||||
errno = is_sane(NESET, (unsigned char *)dpid);
|
||||
if(errno == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in DPID [635]");
|
||||
return errno;
|
||||
@ -182,16 +190,16 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[])
|
||||
}
|
||||
|
||||
/* Customer Information */
|
||||
if(ustrlen(source) > 8)
|
||||
if(strlen(localstr) > 8)
|
||||
{
|
||||
if((ustrlen(source) == 13) || (ustrlen(source) == 18)) {
|
||||
for(reader = 8; reader < ustrlen(source); reader++) {
|
||||
lookup(GDSET, AusCTable, source[reader], data_pattern);
|
||||
if((strlen(localstr) == 13) || (strlen(localstr) == 18)) {
|
||||
for(reader = 8; reader < strlen(localstr); reader++) {
|
||||
lookup(GDSET, AusCTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
if((ustrlen(source) == 16) || (ustrlen(source) == 23)) {
|
||||
for(reader = 8; reader < ustrlen(source); reader++) {
|
||||
lookup(NESET, AusNTable, source[reader], data_pattern);
|
||||
if((strlen(localstr) == 16) || (strlen(localstr) == 23)) {
|
||||
for(reader = 8; reader < strlen(localstr); reader++) {
|
||||
lookup(NESET, AusNTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -214,37 +214,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* Add check digit if encoding an NVE18 symbol */
|
||||
if(symbol->symbology == BARCODE_NVE18) {
|
||||
errornum = is_sane(NESET, source);
|
||||
if(errornum == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [202]");
|
||||
return errornum;
|
||||
}
|
||||
if(sourcelen != 17) {
|
||||
strcpy(symbol->errtxt, "Input wrong length [203]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
for(i = sourcelen + 2; i > 1; i--) {
|
||||
source[i] = source[i - 2];
|
||||
}
|
||||
source[0] = '0';
|
||||
source[1] = '0';
|
||||
total_sum = 0;
|
||||
for(i = 0; i < 19; i++)
|
||||
{
|
||||
if((i % 2) == 0) {
|
||||
total_sum += 3 * ctoi(source[i]);
|
||||
} else {
|
||||
total_sum += ctoi(source[i]);
|
||||
}
|
||||
|
||||
}
|
||||
nve_check = 10 - total_sum%10;
|
||||
source[sourcelen + 1] = '\0';
|
||||
source[sourcelen] = itoc(nve_check);
|
||||
}
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < sourcelen; i++) {
|
||||
if(source[i] >= 128) {
|
||||
@ -899,17 +868,60 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[])
|
||||
return errornum;
|
||||
}
|
||||
|
||||
int nve_18(struct zint_symbol *symbol, unsigned char source[])
|
||||
{
|
||||
/* Add check digit if encoding an NVE18 symbol */
|
||||
int error_number, zeroes, i, nve_check, total_sum, sourcelen;
|
||||
unsigned char localstr[20], checkstr[3];
|
||||
|
||||
sourcelen = ustrlen(source);
|
||||
if(sourcelen > 17) {
|
||||
strcpy(symbol->errtxt, "Input too long [203]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
error_number = is_sane(NESET, source);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [202]");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
strcpy(localstr, "00");
|
||||
zeroes = 17 - sourcelen;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
|
||||
total_sum = 0;
|
||||
for(i = 0; i < 19; i++)
|
||||
{
|
||||
if((i % 2) == 0) {
|
||||
total_sum += 3 * ctoi(localstr[i]);
|
||||
} else {
|
||||
total_sum += ctoi(localstr[i]);
|
||||
}
|
||||
|
||||
}
|
||||
nve_check = 10 - total_sum%10;
|
||||
checkstr[1] = '\0';
|
||||
checkstr[0] = itoc(nve_check);
|
||||
concat(localstr, checkstr);
|
||||
error_number = code_128(symbol, localstr);
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ean_14(struct zint_symbol *symbol, unsigned char source[])
|
||||
{
|
||||
/* EAN-14 - A version of EAN-128 */
|
||||
int input_length, i, count, check_digit;
|
||||
int error_number;
|
||||
int error_number, zeroes;
|
||||
unsigned char ean128_equiv[20];
|
||||
|
||||
memset(ean128_equiv, 0, 20);
|
||||
input_length = ustrlen(source);
|
||||
|
||||
if(input_length != 13) {
|
||||
if(input_length > 13) {
|
||||
strcpy(symbol->errtxt, "Input wrong length [721]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
@ -920,6 +932,10 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[])
|
||||
return error_number;
|
||||
}
|
||||
concat((char*)ean128_equiv, "[01]");
|
||||
zeroes = 13 - input_length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(ean128_equiv, "0");
|
||||
}
|
||||
concat((char*)ean128_equiv, (char*)source);
|
||||
|
||||
count = 0;
|
||||
|
@ -108,6 +108,7 @@ extern int code32(struct zint_symbol *symbol, unsigned char source[]); /* Italia
|
||||
extern int codablock(struct zint_symbol *symbol, unsigned char source[]); /* Codablock F */
|
||||
extern int daft_code(struct zint_symbol *symbol, unsigned char source[]); /* DAFT Code */
|
||||
extern int ean_14(struct zint_symbol *symbol, unsigned char source[]); /* EAN-14 */
|
||||
extern int nve_18(struct zint_symbol *symbol, unsigned char source[]); /* NVE-18 */
|
||||
|
||||
#ifndef NO_PNG
|
||||
int png_handle(struct zint_symbol *symbol, int rotate_angle);
|
||||
@ -217,7 +218,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input)
|
||||
case BARCODE_LOGMARS: error_number = c39(symbol, input); break;
|
||||
case BARCODE_CODE128: error_number = code_128(symbol, input); break;
|
||||
case BARCODE_CODE128B: error_number = code_128(symbol, input); break;
|
||||
case BARCODE_NVE18: error_number = code_128(symbol, input); break;
|
||||
case BARCODE_NVE18: error_number = nve_18(symbol, input); break;
|
||||
case BARCODE_CODE11: error_number = code_11(symbol, input); break;
|
||||
case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, input); break;
|
||||
case BARCODE_TELEPEN: error_number = telepen(symbol, input); break;
|
||||
|
@ -319,16 +319,16 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[])
|
||||
/* Handles Dutch Post TNT KIX symbols */
|
||||
/* The same as RM4SCC but without check digit */
|
||||
/* Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
|
||||
char height_pattern[50];
|
||||
char height_pattern[50], localstr[13];
|
||||
unsigned int loopey;
|
||||
int writer, i;
|
||||
int error_number;
|
||||
int error_number, zeroes;
|
||||
strcpy(height_pattern, "");
|
||||
|
||||
error_number = 0;
|
||||
|
||||
to_upper(source);
|
||||
if(ustrlen(source) != 11) {
|
||||
if(ustrlen(source) > 11) {
|
||||
strcpy(symbol->errtxt, "Input too long [901]");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
@ -337,8 +337,17 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[])
|
||||
strcpy(symbol->errtxt, "Invalid characters in data [902]");
|
||||
return error_number;
|
||||
}
|
||||
for (i = 0; i < ustrlen(source); i++) {
|
||||
lookup(KRSET, RoyalTable, source[i], height_pattern);
|
||||
|
||||
/* Add leading zeroes */
|
||||
strcpy(localstr, "");
|
||||
zeroes = 11 - ustrlen(source);
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
|
||||
/* Encode data */
|
||||
for (i = 0; i < 11; i++) {
|
||||
lookup(KRSET, RoyalTable, localstr[i], height_pattern);
|
||||
}
|
||||
|
||||
writer = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user