Add option to include check digit in UPC/EAN data, and validate before encoding

Fixes #5
This commit is contained in:
Robin Stuart 2016-10-28 19:43:08 +01:00
parent 9024006ca8
commit d875318b3d
5 changed files with 253 additions and 141 deletions

View File

@ -505,6 +505,7 @@ int ZBarcode_ValidID(int symbol_id) {
case BARCODE_CODE39: case BARCODE_CODE39:
case BARCODE_EXCODE39: case BARCODE_EXCODE39:
case BARCODE_EANX: case BARCODE_EANX:
case BARCODE_EANX_CHK:
case BARCODE_EAN128: case BARCODE_EAN128:
case BARCODE_CODABAR: case BARCODE_CODABAR:
case BARCODE_CODE128: case BARCODE_CODE128:
@ -519,7 +520,9 @@ int ZBarcode_ValidID(int symbol_id) {
case BARCODE_RSS_EXP: case BARCODE_RSS_EXP:
case BARCODE_TELEPEN: case BARCODE_TELEPEN:
case BARCODE_UPCA: case BARCODE_UPCA:
case BARCODE_UPCA_CHK:
case BARCODE_UPCE: case BARCODE_UPCE:
case BARCODE_UPCE_CHK:
case BARCODE_POSTNET: case BARCODE_POSTNET:
case BARCODE_MSI_PLESSEY: case BARCODE_MSI_PLESSEY:
case BARCODE_FIM: case BARCODE_FIM:
@ -540,6 +543,7 @@ int ZBarcode_ValidID(int symbol_id) {
case BARCODE_RM4SCC: case BARCODE_RM4SCC:
case BARCODE_DATAMATRIX: case BARCODE_DATAMATRIX:
case BARCODE_EAN14: case BARCODE_EAN14:
case BARCODE_EAN14_CHK:
case BARCODE_NVE18: case BARCODE_NVE18:
case BARCODE_JAPANPOST: case BARCODE_JAPANPOST:
case BARCODE_KOREAPOST: case BARCODE_KOREAPOST:
@ -663,11 +667,13 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, in_length); case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, in_length);
break; break;
case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, in_length); case BARCODE_UPCA:
break; case BARCODE_UPCA_CHK:
case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, in_length); case BARCODE_UPCE:
break; case BARCODE_UPCE_CHK:
case BARCODE_EANX: error_number = eanx(symbol, preprocessed, in_length); case BARCODE_EANX:
case BARCODE_EANX_CHK:
error_number = eanx(symbol, preprocessed, in_length);
break; break;
case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, in_length); case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, in_length);
break; break;
@ -683,9 +689,9 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, in_length); case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, in_length);
break; break;
case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, in_length); case BARCODE_CODE128:
break; case BARCODE_CODE128B:
case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, in_length); error_number = code_128(symbol, preprocessed, in_length);
break; break;
case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, in_length); case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, in_length);
break; break;
@ -713,13 +719,11 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, in_length); case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, in_length);
break; break;
case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, in_length); case BARCODE_AUSPOST:
break; case BARCODE_AUSREPLY:
case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, in_length); case BARCODE_AUSROUTE:
break; case BARCODE_AUSREDIRECT:
case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, in_length); error_number = australia_post(symbol, preprocessed, in_length);
break;
case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, in_length);
break; break;
case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, in_length); case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, in_length);
break; break;
@ -729,37 +733,28 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, in_length); case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, in_length);
break; break;
case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, in_length); case BARCODE_RSS14:
break; case BARCODE_RSS14STACK:
case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, in_length); case BARCODE_RSS14STACK_OMNI:
break; error_number = rss14(symbol, preprocessed, in_length);
case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, in_length);
break; break;
case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, in_length); case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, in_length);
break; break;
case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, in_length); case BARCODE_RSS_EXP:
case BARCODE_RSS_EXPSTACK:
error_number = rssexpanded(symbol, preprocessed, in_length);
break; break;
case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, in_length); case BARCODE_EANX_CC:
break; case BARCODE_EAN128_CC:
case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, in_length); case BARCODE_RSS14_CC:
break; case BARCODE_RSS_LTD_CC:
case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, in_length); case BARCODE_RSS_EXP_CC:
break; case BARCODE_UPCA_CC:
case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, in_length); case BARCODE_UPCE_CC:
break; case BARCODE_RSS14STACK_CC:
case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, in_length); case BARCODE_RSS14_OMNI_CC:
break; case BARCODE_RSS_EXPSTACK_CC:
case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, in_length); error_number = composite(symbol, preprocessed, in_length);
break;
case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, in_length);
break;
case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, in_length);
break;
case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, in_length);
break;
case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, in_length);
break;
case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, in_length);
break; break;
case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, in_length); case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, in_length);
break; break;
@ -767,27 +762,23 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, in_length); case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, in_length);
break; break;
case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, in_length); case BARCODE_EAN14:
case BARCODE_EAN14_CHK:
error_number = ean_14(symbol, preprocessed, in_length);
break; break;
case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, in_length); case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, in_length);
break; break;
case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, in_length); case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, in_length);
break; break;
case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, in_length); case BARCODE_HIBC_128:
break; case BARCODE_HIBC_39:
case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, in_length); case BARCODE_HIBC_DM:
break; case BARCODE_HIBC_QR:
case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, in_length); case BARCODE_HIBC_PDF:
break; case BARCODE_HIBC_MICPDF:
case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, in_length); case BARCODE_HIBC_AZTEC:
break; case BARCODE_HIBC_BLOCKF:
case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, in_length); error_number = hibc(symbol, preprocessed, in_length);
break;
case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, in_length);
break;
case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, in_length);
break;
case BARCODE_HIBC_BLOCKF: error_number = hibc(symbol, preprocessed, in_length);
break; break;
case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, in_length); case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, in_length);
break; break;
@ -799,9 +790,9 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, in_length); case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, in_length);
break; break;
case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, in_length); case BARCODE_PDF417:
break; case BARCODE_PDF417TRUNC:
case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, in_length); error_number = pdf417enc(symbol, preprocessed, in_length);
break; break;
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, in_length); case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, in_length);
break; break;
@ -861,7 +852,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) { if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) {
symbol->symbology = BARCODE_EANX; symbol->symbology = BARCODE_EANX;
} }
if ((symbol->symbology == 14) || (symbol->symbology == 15)) { if (symbol->symbology == 15) {
symbol->symbology = BARCODE_EANX; symbol->symbology = BARCODE_EANX;
} }
if (symbol->symbology == 17) { if (symbol->symbology == 17) {
@ -882,10 +873,10 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
if (symbol->symbology == 33) { if (symbol->symbology == 33) {
symbol->symbology = BARCODE_EAN128; symbol->symbology = BARCODE_EAN128;
} }
if ((symbol->symbology == 35) || (symbol->symbology == 36)) { if (symbol->symbology == 36) {
symbol->symbology = BARCODE_UPCA; symbol->symbology = BARCODE_UPCA;
} }
if ((symbol->symbology == 38) || (symbol->symbology == 39)) { if (symbol->symbology == 38) {
symbol->symbology = BARCODE_UPCE; symbol->symbology = BARCODE_UPCE;
} }
if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) { if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) {

View File

@ -124,25 +124,38 @@ void upca_draw(char source[], char dest[]) {
} }
/* Make a UPC A barcode when we haven't been given the check digit */ /* Make a UPC A barcode when we haven't been given the check digit */
void upca(struct zint_symbol *symbol, unsigned char source[], char dest[]) { int upca(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
int length; int length;
char gtin[15]; char gtin[15];
strcpy(gtin, (char*) source); strcpy(gtin, (char*) source);
length = strlen(gtin); length = strlen(gtin);
if (length == 11) {
gtin[length] = upc_check(gtin); gtin[length] = upc_check(gtin);
gtin[length + 1] = '\0'; gtin[length + 1] = '\0';
} else {
gtin[length - 1] = '\0';
if (source[length - 1] != upc_check(gtin)) {
strcpy(symbol->errtxt, "Invalid check digit");
return ZINT_ERROR_INVALID_DATA;
}
gtin[length - 1] = upc_check(gtin);
}
upca_draw(gtin, dest); upca_draw(gtin, dest);
ustrcpy(symbol->text, (unsigned char*) gtin); ustrcpy(symbol->text, (unsigned char*) gtin);
return 0;
} }
/* UPC E is a zero-compressed version of UPC A */ /* UPC E is a zero-compressed version of UPC A */
void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) { int upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
unsigned int i, num_system; unsigned int i, num_system;
char emode, equivalent[12], check_digit, parity[8], temp[8]; char emode, equivalent[12], check_digit, parity[8], temp[8];
char hrt[9]; char hrt[9];
/* Two number systems can be used - system 0 and system 1 */ /* Two number systems can be used - system 0 and system 1 */
if (symbol->symbology != BARCODE_UPCE_CHK) {
/* No check digit in input data */
if (ustrlen(source) == 7) { if (ustrlen(source) == 7) {
switch (source[0]) { switch (source[0]) {
case '0': num_system = 0; case '0': num_system = 0;
@ -164,6 +177,30 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
hrt[1] = '\0'; hrt[1] = '\0';
strcat(hrt, (char*) source); strcat(hrt, (char*) source);
} }
} else {
/* Check digit is included in input data */
if (ustrlen(source) == 8) {
switch (source[0]) {
case '0': num_system = 0;
break;
case '1': num_system = 1;
break;
default: num_system = 0;
source[0] = '0';
break;
}
strcpy(temp, (char*) source);
strcpy(hrt, (char*) source);
for (i = 1; i <= 7; i++) {
source[i - 1] = temp[i];
}
} else {
num_system = 0;
hrt[0] = '0';
hrt[1] = '\0';
strcat(hrt, (char*) source);
}
}
/* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */ /* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */
emode = source[5]; emode = source[5];
@ -193,6 +230,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) { if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */ /* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
strcpy(symbol->errtxt, "Invalid UPC-E data"); strcpy(symbol->errtxt, "Invalid UPC-E data");
return ZINT_ERROR_INVALID_DATA;
} }
break; break;
case '4': case '4':
@ -202,6 +240,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
if (source[3] == '0') { if (source[3] == '0') {
/* Note 2 - "X4 shall not be equal to 0" */ /* Note 2 - "X4 shall not be equal to 0" */
strcpy(symbol->errtxt, "Invalid UPC-E data"); strcpy(symbol->errtxt, "Invalid UPC-E data");
return ZINT_ERROR_INVALID_DATA;
} }
break; break;
case '5': case '5':
@ -216,6 +255,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
if (source[4] == '0') { if (source[4] == '0') {
/* Note 3 - "X5 shall not be equal to 0" */ /* Note 3 - "X5 shall not be equal to 0" */
strcpy(symbol->errtxt, "Invalid UPC-E data"); strcpy(symbol->errtxt, "Invalid UPC-E data");
return ZINT_ERROR_INVALID_DATA;
} }
break; break;
} }
@ -248,9 +288,17 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
/* stop character */ /* stop character */
strcat(dest, "111111"); strcat(dest, "111111");
if (symbol->symbology != BARCODE_UPCE_CHK) {
hrt[7] = check_digit; hrt[7] = check_digit;
hrt[8] = '\0'; hrt[8] = '\0';
} else {
if (hrt[7] != check_digit) {
strcpy(symbol->errtxt, "Invalid check digit");
return ZINT_ERROR_INVALID_DATA;
}
}
ustrcpy(symbol->text, (unsigned char*) hrt); ustrcpy(symbol->text, (unsigned char*) hrt);
return 0;
} }
/* EAN-2 and EAN-5 add-on codes */ /* EAN-2 and EAN-5 add-on codes */
@ -335,7 +383,7 @@ char ean_check(char source[]) {
return itoc(check_digit); return itoc(check_digit);
} }
void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]) { int ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
unsigned int length, i, half_way; unsigned int length, i, half_way;
char parity[6]; char parity[6];
char gtin[15]; char gtin[15];
@ -345,8 +393,18 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
/* Add the appropriate check digit */ /* Add the appropriate check digit */
length = strlen(gtin); length = strlen(gtin);
if (length == 12) {
gtin[length] = ean_check(gtin); gtin[length] = ean_check(gtin);
gtin[length + 1] = '\0'; gtin[length + 1] = '\0';
} else {
gtin[length - 1] = '\0';
if (source[length - 1] != ean_check(gtin)) {
strcpy(symbol->errtxt, "Invalid check digit");
return ZINT_ERROR_INVALID_DATA;
}
gtin[length - 1] = ean_check(gtin);
}
/* Get parity for first half of the symbol */ /* Get parity for first half of the symbol */
lookup(SODIUM, EAN13Parity, gtin[0], parity); lookup(SODIUM, EAN13Parity, gtin[0], parity);
@ -375,20 +433,33 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
strcat(dest, "111"); strcat(dest, "111");
ustrcpy(symbol->text, (unsigned char*) gtin); ustrcpy(symbol->text, (unsigned char*) gtin);
return 0;
} }
/* Make an EAN-8 barcode when we haven't been given the check digit */ /* Make an EAN-8 barcode when we haven't been given the check digit */
void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[]) { int ean8(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
/* EAN-8 is basically the same as UPC-A but with fewer digits */ /* EAN-8 is basically the same as UPC-A but with fewer digits */
int length; int length;
char gtin[10]; char gtin[10];
strcpy(gtin, (char*) source); strcpy(gtin, (char*) source);
length = strlen(gtin); length = strlen(gtin);
if (length == 7) {
gtin[length] = upc_check(gtin); gtin[length] = upc_check(gtin);
gtin[length + 1] = '\0'; gtin[length + 1] = '\0';
} else {
gtin[length - 1] = '\0';
if (source[length - 1] != upc_check(gtin)) {
strcpy(symbol->errtxt, "Invalid check digit");
return ZINT_ERROR_INVALID_DATA;
}
gtin[length - 1] = upc_check(gtin);
}
upca_draw(gtin, dest); upca_draw(gtin, dest);
ustrcpy(symbol->text, (unsigned char*) gtin); ustrcpy(symbol->text, (unsigned char*) gtin);
return 0;
} }
/* For ISBN(13) only */ /* For ISBN(13) only */
@ -577,10 +648,29 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi
} }
} }
break; break;
case BARCODE_EANX_CHK:
if (first_len <= 13) {
zfirst_len = 13;
}
if (first_len <= 8) {
zfirst_len = 8;
}
if (second_len == 0) {
if (first_len <= 5) {
zfirst_len = 5;
}
if (first_len <= 2) {
zfirst_len = 2;
}
}
break;
case BARCODE_UPCA: case BARCODE_UPCA:
case BARCODE_UPCA_CC: case BARCODE_UPCA_CC:
zfirst_len = 11; zfirst_len = 11;
break; break;
case BARCODE_UPCA_CHK:
zfirst_len = 12;
break;
case BARCODE_UPCE: case BARCODE_UPCE:
case BARCODE_UPCE_CC: case BARCODE_UPCE_CC:
if (first_len == 7) { if (first_len == 7) {
@ -590,6 +680,14 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi
zfirst_len = 6; zfirst_len = 6;
} }
break; break;
case BARCODE_UPCE_CHK:
if (first_len == 8) {
zfirst_len = 8;
}
if (first_len <= 7) {
zfirst_len = 7;
}
break;
case BARCODE_ISBNX: case BARCODE_ISBNX:
if (first_len <= 9) { if (first_len <= 9) {
zfirst_len = 9; zfirst_len = 9;
@ -687,6 +785,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
switch (symbol->symbology) { switch (symbol->symbology) {
case BARCODE_EANX: case BARCODE_EANX:
case BARCODE_EANX_CHK:
switch (ustrlen(first_part)) { switch (ustrlen(first_part)) {
case 2: add_on(first_part, (char*) dest, 0); case 2: add_on(first_part, (char*) dest, 0);
ustrcpy(symbol->text, first_part); ustrcpy(symbol->text, first_part);
@ -694,9 +793,11 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
case 5: add_on(first_part, (char*) dest, 0); case 5: add_on(first_part, (char*) dest, 0);
ustrcpy(symbol->text, first_part); ustrcpy(symbol->text, first_part);
break; break;
case 7: ean8(symbol, first_part, (char*) dest); case 7:
case 8: error_number = ean8(symbol, first_part, (char*) dest);
break; break;
case 12: ean13(symbol, first_part, (char*) dest); case 12:
case 13: error_number = ean13(symbol, first_part, (char*) dest);
break; break;
default: strcpy(symbol->errtxt, "Invalid length input"); default: strcpy(symbol->errtxt, "Invalid length input");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
@ -714,7 +815,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 1] = 2;
symbol->row_height[symbol->rows + 2] = 2; symbol->row_height[symbol->rows + 2] = 2;
symbol->rows += 3; symbol->rows += 3;
ean8(symbol, first_part, (char*) dest); error_number = ean8(symbol, first_part, (char*) dest);
break; break;
case 12:set_module(symbol, symbol->rows, 1); case 12:set_module(symbol, symbol->rows, 1);
set_module(symbol, symbol->rows, 95); set_module(symbol, symbol->rows, 95);
@ -726,15 +827,16 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 1] = 2;
symbol->row_height[symbol->rows + 2] = 2; symbol->row_height[symbol->rows + 2] = 2;
symbol->rows += 3; symbol->rows += 3;
ean13(symbol, first_part, (char*) dest); error_number = ean13(symbol, first_part, (char*) dest);
break; break;
default: strcpy(symbol->errtxt, "Invalid length EAN input"); default: strcpy(symbol->errtxt, "Invalid length EAN input");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
break; break;
case BARCODE_UPCA: case BARCODE_UPCA:
if (ustrlen(first_part) == 11) { case BARCODE_UPCA_CHK:
upca(symbol, first_part, (char*) dest); if ((ustrlen(first_part) == 11) || (ustrlen(first_part) == 12)) {
error_number = upca(symbol, first_part, (char*) dest);
} else { } else {
strcpy(symbol->errtxt, "Input wrong length"); strcpy(symbol->errtxt, "Input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
@ -752,15 +854,16 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 1] = 2;
symbol->row_height[symbol->rows + 2] = 2; symbol->row_height[symbol->rows + 2] = 2;
symbol->rows += 3; symbol->rows += 3;
upca(symbol, first_part, (char*) dest); error_number = upca(symbol, first_part, (char*) dest);
} else { } else {
strcpy(symbol->errtxt, "UPCA input wrong length"); strcpy(symbol->errtxt, "UPCA input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
break; break;
case BARCODE_UPCE: case BARCODE_UPCE:
if ((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) { case BARCODE_UPCE_CHK:
upce(symbol, first_part, (char*) dest); if ((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 8)) {
error_number = upce(symbol, first_part, (char*) dest);
} else { } else {
strcpy(symbol->errtxt, "Input wrong length"); strcpy(symbol->errtxt, "Input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
@ -778,7 +881,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 1] = 2;
symbol->row_height[symbol->rows + 2] = 2; symbol->row_height[symbol->rows + 2] = 2;
symbol->rows += 3; symbol->rows += 3;
upce(symbol, first_part, (char*) dest); error_number = upce(symbol, first_part, (char*) dest);
} else { } else {
strcpy(symbol->errtxt, "UPCE input wrong length"); strcpy(symbol->errtxt, "UPCE input wrong length");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
@ -786,11 +889,13 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
break; break;
case BARCODE_ISBNX: case BARCODE_ISBNX:
error_number = isbn(symbol, first_part, ustrlen(first_part), (char*) dest); error_number = isbn(symbol, first_part, ustrlen(first_part), (char*) dest);
break;
}
if (error_number > 4) { if (error_number > 4) {
return error_number; return error_number;
} }
break;
}
switch (ustrlen(second_part)) { switch (ustrlen(second_part)) {
case 0: break; case 0: break;
case 2: case 2:
@ -827,9 +932,5 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
break; break;
} }
return 0;
if ((symbol->errtxt[0] == 'w') && (error_number == 0)) {
error_number = 1; /* flag UPC-E warnings */
}
return error_number;
} }

View File

@ -109,6 +109,7 @@ extern "C" {
#define BARCODE_CODE39 8 #define BARCODE_CODE39 8
#define BARCODE_EXCODE39 9 #define BARCODE_EXCODE39 9
#define BARCODE_EANX 13 #define BARCODE_EANX 13
#define BARCODE_EANX_CHK 14
#define BARCODE_EAN128 16 #define BARCODE_EAN128 16
#define BARCODE_CODABAR 18 #define BARCODE_CODABAR 18
#define BARCODE_CODE128 20 #define BARCODE_CODE128 20
@ -123,7 +124,9 @@ extern "C" {
#define BARCODE_RSS_EXP 31 #define BARCODE_RSS_EXP 31
#define BARCODE_TELEPEN 32 #define BARCODE_TELEPEN 32
#define BARCODE_UPCA 34 #define BARCODE_UPCA 34
#define BARCODE_UPCA_CHK 35
#define BARCODE_UPCE 37 #define BARCODE_UPCE 37
#define BARCODE_UPCE_CHK 38
#define BARCODE_POSTNET 40 #define BARCODE_POSTNET 40
#define BARCODE_MSI_PLESSEY 47 #define BARCODE_MSI_PLESSEY 47
#define BARCODE_FIM 49 #define BARCODE_FIM 49

View File

@ -236,6 +236,7 @@ Numeric Value | Barcode Name
8 | Code 3 of 9 (Code 39) 8 | Code 3 of 9 (Code 39)
9 | Extended Code 3 of 9 (Code 39+) 9 | Extended Code 3 of 9 (Code 39+)
13 | EAN (Including EAN-8 and EAN-13) 13 | EAN (Including EAN-8 and EAN-13)
14 | EAN + Check Digit
16 | GS1-128 (UCC.EAN-128) 16 | GS1-128 (UCC.EAN-128)
18 | Codabar 18 | Codabar
20 | Code 128 (automatic subset switching) 20 | Code 128 (automatic subset switching)
@ -250,7 +251,9 @@ Numeric Value | Barcode Name
31 | GS1 DataBar Extended 31 | GS1 DataBar Extended
32 | Telepen Alpha 32 | Telepen Alpha
34 | UPC A 34 | UPC A
35 | UPC A + Check Digit
37 | UPC E 37 | UPC E
38 | UPC E + Check Digit
40 | PostNet 40 | PostNet
47 | MSI Plessey 47 | MSI Plessey
49 | FIM 49 | FIM
@ -893,6 +896,7 @@ Value |
8 | BARCODE_CODE39 | Code 3 of 9 (Code 39) 8 | BARCODE_CODE39 | Code 3 of 9 (Code 39)
9 | BARCODE_EXCODE39 | Extended Code 3 of 9 (Code 39+) 9 | BARCODE_EXCODE39 | Extended Code 3 of 9 (Code 39+)
13 | BARCODE_EANX | EAN 13 | BARCODE_EANX | EAN
14 | BARCODE_EANX_CHK | EAN + Check Digit
16 | BARCODE_EAN128 | GS1-128 (UCC.EAN-128) 16 | BARCODE_EAN128 | GS1-128 (UCC.EAN-128)
18 | BARCODE_CODABAR | Codabar 18 | BARCODE_CODABAR | Codabar
20 | BARCODE_CODE128 | Code 128 (automatic subset switching) 20 | BARCODE_CODE128 | Code 128 (automatic subset switching)
@ -907,7 +911,9 @@ Value |
31 | BARCODE_RSS_EXP | GS1 DataBar Extended 31 | BARCODE_RSS_EXP | GS1 DataBar Extended
32 | BARCODE_TELEPEN | Telepen Alpha 32 | BARCODE_TELEPEN | Telepen Alpha
34 | BARCODE_UPCA | UPC A 34 | BARCODE_UPCA | UPC A
35 | BARCODE_UPCA_CHK | UPC A + Check Digit
37 | BARCODE_UPCE | UPC E 37 | BARCODE_UPCE | UPC E
38 | BARCODE_UPCE | UPC E + Check Digit
40 | BARCODE_POSTNET | PostNet 40 | BARCODE_POSTNET | PostNet
47 | BARCODE_MSI_PLESSEY | MSI Plessey 47 | BARCODE_MSI_PLESSEY | MSI Plessey
49 | BARCODE_FIM | FIM 49 | BARCODE_FIM | FIM
@ -1123,6 +1129,9 @@ my_symbol->symbology = BARCODE_UPCA;
error = ZBarcode_Encode_and_Print(my_symbol, "72527270270+12345"); error = ZBarcode_Encode_and_Print(my_symbol, "72527270270+12345");
If your input data already includes the check digit symbology 35 can be used
which takes a 12 digit input and validates the check digit before encoding.
6.1.3.2 UPC Version E 6.1.3.2 UPC Version E
--------------------- ---------------------
UPC-E is a zero-compressed version of UPC-A developed for smaller packages. The UPC-E is a zero-compressed version of UPC-A developed for smaller packages. The
@ -1140,6 +1149,9 @@ my_symbol->symbology = BARCODE_UPCE;
error = ZBarcode_Encode_and_Print(my_symbol, "1123456"); error = ZBarcode_Encode_and_Print(my_symbol, "1123456");
If your input data already includes the check digit symbology 38 can be used
which takes a 7 or 8 digit input and validates the check digit before encoding.
6.1.4 European Article Number (EN 797) 6.1.4 European Article Number (EN 797)
-------------------------------------- --------------------------------------
6.1.4.1 EAN-2, EAN-5, EAN-8 and EAN-13 6.1.4.1 EAN-2, EAN-5, EAN-8 and EAN-13
@ -1167,6 +1179,10 @@ error = ZBarcode_Encode_and_Print(my_symbol, "7432365+54321");
All of the EAN symbols include check digits which are added by Zint. All of the EAN symbols include check digits which are added by Zint.
If you are encoding an EAN-8 or EAN-13 symbol and your data already includes
the check digit then you can use symbology 14 which takes an 8 or 13 digit input
and validates the check digit before encoding.
6.1.4.2 SBN, ISBN and ISBN-13 6.1.4.2 SBN, ISBN and ISBN-13
----------------------------- -----------------------------
EAN-13 symbols (also known as Bookland EAN-13) can also be produced from EAN-13 symbols (also known as Bookland EAN-13) can also be produced from

View File

@ -37,35 +37,36 @@
/* Print list of supported symbologies */ /* Print list of supported symbologies */
void types(void) { void types(void) {
printf( " 1: Code 11 52: PZN 92: Aztec Code\n" printf( " 1: Code 11 50: Logmars 90: KIX Code\n"
" 2: Standard 2of5 53: Pharma Two-Track 93: DAFT Code\n" " 2: Standard 2of5 51: Pharma One-Track 92: Aztec Code\n"
" 3: Interleaved 2of5 55: PDF417 97: Micro QR Code\n" " 3: Interleaved 2of5 52: PZN 93: DAFT Code\n"
" 4: IATA 2of5 56: PDF417 Trunc 98: HIBC Code 128\n" " 4: IATA 2of5 53: Pharma Two-Track 97: Micro QR Code\n"
" 6: Data Logic 57: Maxicode 99: HIBC Code 39\n" " 6: Data Logic 55: PDF417 98: HIBC Code 128\n"
" 7: Industrial 2of5 58: QR Code 102: HIBC Data Matrix\n" " 7: Industrial 2of5 56: PDF417 Trunc 99: HIBC Code 39\n"
" 8: Code 39 60: Code 128-B 104: HIBC QR Code\n" " 8: Code 39 57: Maxicode 102: HIBC Data Matrix\n"
" 9: Extended Code 39 63: AP Standard Customer 106: HIBC PDF417\n" " 9: Extended Code 39 58: QR Code 104: HIBC QR Code\n"
"13: EAN 66: AP Reply Paid 108: HIBC MicroPDF417\n" "13: EAN 60: Code 128-B 106: HIBC PDF417\n"
"16: GS1-128 67: AP Routing 110: HIBC Codablock-F\n" "14: EAN + Check 63: AP Standard Customer 108: HIBC MicroPDF417"
"18: Codabar 68: AP Redirection 112: HIBC Aztec Code\n" "16: GS1-128 66: AP Reply Paid 110: HIBC Codablock-F\n"
"20: Code 128 69: ISBN 115: DotCode\n" "18: Codabar 67: AP Routing 112: HIBC Aztec Code\n"
"21: Leitcode 70: RM4SCC 116: Han Xin Code\n" "20: Code 128 68: AP Redirection 115: DotCode\n"
"22: Identcode 71: Data Matrix 128: Aztec Runes\n" "21: Leitcode 69: ISBN 116: Han Xin Code\n"
"23: Code 16k 72: EAN-14 129: Code 32\n" "22: Identcode 70: RM4SCC 128: Aztec Runes\n"
"24: Code 49 74: Codablock-F 130: Comp EAN\n" "23: Code 16k 71: Data Matrix 129: Code 32\n"
"25: Code 93 75: NVE-18 131: Comp GS1-128\n" "24: Code 49 72: EAN-14 130: Comp EAN\n"
"28: Flattermarken 76: Japanese Post 132: Comp DataBar Omni\n" "25: Code 93 74: Codablock-F 131: Comp GS1-128\n"
"29: GS1 DataBar Omni 77: Korea Post 133: Comp DataBar Ltd\n" "28: Flattermarken 75: NVE-18 132: Comp DataBar Omni\n"
"30: GS1 DataBar Ltd 79: GS1 DataBar Stack 134: Comp DataBar ExpOm\n" "29: GS1 DataBar Omni 76: Japanese Post 133: Comp DataBar Ltd\n"
"31: GS1 DataBar ExpOm 80: GS1 DataBar Stack Omni 135: Comp UPC-A\n" "30: GS1 DataBar Ltd 77: Korea Post 134: Comp DataBar ExpOm\n"
"32: Telepen Alpha 81: GS1 DataBar ESO 136: Comp UPC-E\n" "31: GS1 DataBar ExpOm 79: GS1 DataBar Stack 135: Comp UPC-A\n"
"34: UPC-A 82: Planet 137: Comp DataBar Stack\n" "32: Telepen Alpha 80: GS1 DataBar Stack Omni 136: Comp UPC-E\n"
"37: UPC-E 84: MicroPDF 138: Comp DataBar Stack Omni\n" "34: UPC-A 81: GS1 DataBar ESO 137: Comp DataBar Stack\n"
"40: Postnet 85: USPS OneCode 139: Comp DataBar ESO\n" "35: UPC-A + Check 82: Planet 138: Comp DataBar Stack Omni\n"
"47: MSI Plessey 86: UK Plessey 140: Channel Code\n" "37: UPC-E 84: MicroPDF 139: Comp DataBar ESO\n"
"49: FIM 87: Telepen Numeric 141: Code One\n" "38: UPC-E + Check 85: USPS OneCode 140: Channel Code\n"
"50: Logmars 89: ITF-14 142: Grid Matrix\n" "40: Postnet 86: UK Plessey 141: Code One\n"
"51: Pharma One-Track 90: KIX Code\n" "47: MSI Plessey 87: Telepen Numeric 142: Grid Matrix\n"
"49: FIM 89: ITF-14\n"
); );
} }