mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-12 22:25:59 -04:00
#209 rss.c, composite.c; DBAR_EXP encodation methods; symbol NO_PNG out.gif
This commit is contained in:
parent
2b85585e69
commit
bee5f08f50
24 changed files with 1309 additions and 1257 deletions
405
backend/upcean.c
405
backend/upcean.c
|
@ -79,17 +79,13 @@ static const char *EANsetB[10] = {
|
|||
};
|
||||
|
||||
/* Calculate the correct check digit for a UPC barcode */
|
||||
static char upc_check(char source[]) {
|
||||
unsigned int i, count, check_digit;
|
||||
static char upc_check(const char source[], const int length) {
|
||||
int i, count, check_digit;
|
||||
|
||||
count = 0;
|
||||
|
||||
for (i = 0; i < strlen(source); i++) {
|
||||
count += ctoi(source[i]);
|
||||
|
||||
if (!(i & 1)) {
|
||||
count += 2 * (ctoi(source[i]));
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
count += (i & 1) ? ctoi(source[i]) : 3 * ctoi(source[i]);
|
||||
}
|
||||
|
||||
check_digit = 10 - (count % 10);
|
||||
|
@ -100,115 +96,88 @@ static char upc_check(char source[]) {
|
|||
}
|
||||
|
||||
/* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */
|
||||
static void upca_draw(char source[], char dest[]) {
|
||||
unsigned int i, half_way, length = strlen(source);
|
||||
static void upca_draw(const char source[], const int length, unsigned char dest[]) {
|
||||
int i, half_way;
|
||||
|
||||
half_way = length / 2;
|
||||
|
||||
/* start character */
|
||||
strcat(dest, "111");
|
||||
ustrcat(dest, "111");
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
if (i == half_way) {
|
||||
/* middle character - separates manufacturer no. from product no. */
|
||||
/* also inverts right hand characters */
|
||||
strcat(dest, "11111");
|
||||
ustrcat(dest, "11111");
|
||||
}
|
||||
|
||||
lookup(NEON, EANsetA, source[i], dest);
|
||||
lookup(NEON, EANsetA, source[i], (char *) dest);
|
||||
}
|
||||
|
||||
/* stop character */
|
||||
strcat(dest, "111");
|
||||
ustrcat(dest, "111");
|
||||
}
|
||||
|
||||
/* Make a UPC A barcode when we haven't been given the check digit */
|
||||
static int upca(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||
int length;
|
||||
static int upca(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[]) {
|
||||
char gtin[15];
|
||||
int error_number = 0;
|
||||
|
||||
strcpy(gtin, (char*) source);
|
||||
length = strlen(gtin);
|
||||
ustrcpy(gtin, source);
|
||||
|
||||
if (length == 11) {
|
||||
gtin[length] = upc_check(gtin);
|
||||
gtin[length + 1] = '\0';
|
||||
gtin[length++] = upc_check(gtin, 11);
|
||||
gtin[length] = '\0';
|
||||
} else {
|
||||
gtin[length - 1] = '\0';
|
||||
if (source[length - 1] != upc_check(gtin)) {
|
||||
if (source[length - 1] != upc_check(gtin, 11)) {
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("UPC-A: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin, upc_check(gtin));
|
||||
printf("UPC-A: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin,
|
||||
upc_check(gtin, 11));
|
||||
}
|
||||
strcpy(symbol->errtxt, "270: Invalid check digit");
|
||||
return ZINT_ERROR_INVALID_CHECK;
|
||||
}
|
||||
gtin[length - 1] = upc_check(gtin);
|
||||
}
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("UPC-A: %s, gtin: %s, Check digit: %c\n", source, gtin, length == 11 ? gtin[length] : gtin[length - 1]);
|
||||
printf("UPC-A: %s, gtin: %s, Check digit: %c\n", source, gtin,
|
||||
length == 11 ? gtin[length] : gtin[length - 1]);
|
||||
}
|
||||
|
||||
upca_draw(gtin, dest);
|
||||
upca_draw(gtin, length, dest);
|
||||
ustrcpy(symbol->text, gtin);
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* UPC E is a zero-compressed version of UPC A */
|
||||
static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||
unsigned int i, num_system, length;
|
||||
char emode, equivalent[12], check_digit, parity[8], temp[9];
|
||||
static int upce(struct zint_symbol *symbol, unsigned char source[], int length, unsigned char dest[]) {
|
||||
int i, num_system;
|
||||
char emode, equivalent[12], check_digit, parity[8];
|
||||
char hrt[9];
|
||||
int error_number = 0;
|
||||
|
||||
/* 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) {
|
||||
switch (source[0]) {
|
||||
case '0': num_system = 0;
|
||||
break;
|
||||
case '1': num_system = 1;
|
||||
break;
|
||||
default: num_system = 0;
|
||||
/* First source char ignored */
|
||||
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);
|
||||
if ((symbol->symbology != BARCODE_UPCE_CHK && length == 7) || length == 8) {
|
||||
switch (source[0]) {
|
||||
case '0': num_system = 0;
|
||||
break;
|
||||
case '1': num_system = 1;
|
||||
break;
|
||||
default: num_system = 0;
|
||||
/* First source char ignored */
|
||||
break;
|
||||
}
|
||||
ustrcpy(hrt, source);
|
||||
for (i = 1; i <= length; i++) {
|
||||
source[i - 1] = hrt[i];
|
||||
}
|
||||
length--;
|
||||
} 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;
|
||||
/* First source char ignored */
|
||||
break;
|
||||
}
|
||||
strcpy(temp, (char*) source);
|
||||
strcpy(hrt, (char*) source);
|
||||
for (i = 1; i <= 8; i++) {
|
||||
source[i - 1] = temp[i];
|
||||
}
|
||||
} else {
|
||||
num_system = 0;
|
||||
hrt[0] = '0';
|
||||
hrt[1] = '\0';
|
||||
strcat(hrt, (char*) source);
|
||||
}
|
||||
/* Length 6 with no check digit, or length 7 with check digit, system 0, insert leading zero */
|
||||
num_system = 0;
|
||||
hrt[0] = '0';
|
||||
hrt[1] = '\0';
|
||||
ustrncat(hrt, source, length);
|
||||
}
|
||||
|
||||
/* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */
|
||||
|
@ -217,7 +186,7 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||
equivalent[i] = '0';
|
||||
}
|
||||
if (num_system == 1) {
|
||||
equivalent[0] = temp[0];
|
||||
equivalent[0] = hrt[0];
|
||||
}
|
||||
equivalent[1] = source[0];
|
||||
equivalent[2] = source[1];
|
||||
|
@ -271,7 +240,7 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||
|
||||
/* Get the check digit from the expanded UPCA code */
|
||||
|
||||
check_digit = upc_check(equivalent);
|
||||
check_digit = upc_check(equivalent, 11);
|
||||
|
||||
/* Use the number system and check digit information to choose a parity scheme */
|
||||
if (num_system == 1) {
|
||||
|
@ -283,20 +252,19 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||
/* Take all this information and make the barcode pattern */
|
||||
|
||||
/* start character */
|
||||
strcat(dest, "111");
|
||||
ustrcat(dest, "111");
|
||||
|
||||
length = ustrlen(source);
|
||||
for (i = 0; i < length; i++) {
|
||||
switch (parity[i]) {
|
||||
case 'A': lookup(NEON, EANsetA, source[i], dest);
|
||||
case 'A': lookup(NEON, EANsetA, source[i], (char *) dest);
|
||||
break;
|
||||
case 'B': lookup(NEON, EANsetB, source[i], dest);
|
||||
case 'B': lookup(NEON, EANsetB, source[i], (char *) dest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* stop character */
|
||||
strcat(dest, "111111");
|
||||
ustrcat(dest, "111111");
|
||||
|
||||
if (symbol->symbology != BARCODE_UPCE_CHK) {
|
||||
hrt[7] = check_digit;
|
||||
|
@ -304,7 +272,8 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||
} else {
|
||||
if (hrt[7] != check_digit) {
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("UPC-E: Invalid check digit %s, equivalent: %s, hrt: %s, Check digit: %c\n", source, equivalent, hrt, check_digit);
|
||||
printf("UPC-E: Invalid check digit %s, equivalent: %s, hrt: %s, Check digit: %c\n", source,
|
||||
equivalent, hrt, check_digit);
|
||||
}
|
||||
strcpy(symbol->errtxt, "274: Invalid check digit");
|
||||
return ZINT_ERROR_INVALID_CHECK;
|
||||
|
@ -320,22 +289,22 @@ static int upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||
}
|
||||
|
||||
/* EAN-2 and EAN-5 add-on codes */
|
||||
static void add_on(unsigned char source[], char dest[], int addon_gap) {
|
||||
static void add_on(const unsigned char source[], const int length, unsigned char dest[], const int addon_gap) {
|
||||
char parity[6];
|
||||
unsigned int i, code_type, length;
|
||||
int i, code_type;
|
||||
|
||||
/* If an add-on then append with space */
|
||||
if (addon_gap != 0) {
|
||||
i = strlen(dest);
|
||||
i = (int) ustrlen(dest);
|
||||
dest[i] = itoc(addon_gap);
|
||||
dest[i + 1] = '\0';
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
strcat(dest, "112");
|
||||
ustrcat(dest, "112");
|
||||
|
||||
/* Determine EAN2 or EAN5 add-on */
|
||||
if (ustrlen(source) == 2) {
|
||||
if (length == 2) {
|
||||
code_type = EAN2;
|
||||
} else {
|
||||
code_type = EAN5;
|
||||
|
@ -364,38 +333,32 @@ static void add_on(unsigned char source[], char dest[], int addon_gap) {
|
|||
strcpy(parity, EAN5Parity[parity_bit]);
|
||||
}
|
||||
|
||||
length = ustrlen(source);
|
||||
for (i = 0; i < length; i++) {
|
||||
switch (parity[i]) {
|
||||
case 'A': lookup(NEON, EANsetA, source[i], dest);
|
||||
case 'A': lookup(NEON, EANsetA, source[i], (char *) dest);
|
||||
break;
|
||||
case 'B': lookup(NEON, EANsetB, source[i], dest);
|
||||
case 'B': lookup(NEON, EANsetB, source[i], (char *) dest);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Glyph separator */
|
||||
if (i != (ustrlen(source) - 1)) {
|
||||
strcat(dest, "11");
|
||||
if (i != (length - 1)) {
|
||||
ustrcat(dest, "11");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************ EAN-13 ****************** */
|
||||
|
||||
/* Calculate the correct check digit for a EAN-13 barcode */
|
||||
static char ean_check(char source[]) {
|
||||
/* Calculate the correct check digit for a EAN-13 barcode (including ISBN(13)) */
|
||||
static char ean_check(const char source[], const int length) {
|
||||
int i;
|
||||
unsigned int h, count, check_digit;
|
||||
int count, check_digit;
|
||||
|
||||
count = 0;
|
||||
|
||||
h = strlen(source);
|
||||
for (i = h - 1; i >= 0; i--) {
|
||||
count += ctoi(source[i]);
|
||||
|
||||
if (i & 1) {
|
||||
count += 2 * ctoi(source[i]);
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
count += (i & 1) ? 3 * ctoi(source[i]) : ctoi(source[i]);
|
||||
}
|
||||
check_digit = 10 - (count % 10);
|
||||
if (check_digit == 10) {
|
||||
|
@ -404,34 +367,32 @@ static char ean_check(char source[]) {
|
|||
return itoc(check_digit);
|
||||
}
|
||||
|
||||
static int ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||
unsigned int length, i, half_way;
|
||||
static int ean13(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[]) {
|
||||
int i, half_way;
|
||||
char parity[6];
|
||||
char gtin[15];
|
||||
int error_number = 0;
|
||||
|
||||
strcpy(parity, "");
|
||||
strcpy(gtin, (char*) source);
|
||||
parity[0] = '\0';
|
||||
ustrcpy(gtin, source);
|
||||
|
||||
/* Add the appropriate check digit */
|
||||
length = strlen(gtin);
|
||||
|
||||
if (length == 12) {
|
||||
gtin[length] = ean_check(gtin);
|
||||
gtin[length + 1] = '\0';
|
||||
gtin[length++] = ean_check(gtin, 12);
|
||||
gtin[length] = '\0';
|
||||
} else {
|
||||
gtin[length - 1] = '\0';
|
||||
if (source[length - 1] != ean_check(gtin)) {
|
||||
if (source[length - 1] != ean_check(gtin, 12)) {
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("EAN-13 Invalid check digit: %s, gtin: %s, Check digit: %c\n", source, gtin, ean_check(gtin));
|
||||
printf("EAN-13 Invalid check digit: %s, gtin: %s, Check digit: %c\n", source, gtin,
|
||||
ean_check(gtin, 12));
|
||||
}
|
||||
strcpy(symbol->errtxt, "275: Invalid check digit");
|
||||
return ZINT_ERROR_INVALID_CHECK;
|
||||
}
|
||||
gtin[length - 1] = ean_check(gtin);
|
||||
}
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("EAN-13: %s, gtin: %s, Check digit: %c\n", source, gtin, length == 12 ? gtin[length] : gtin[length - 1]);
|
||||
printf("EAN-13: %s, gtin: %s, Check digit: %c\n", source, gtin, gtin[length - 1]);
|
||||
}
|
||||
|
||||
/* Get parity for first half of the symbol */
|
||||
|
@ -441,93 +402,69 @@ static int ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]
|
|||
half_way = 7;
|
||||
|
||||
/* start character */
|
||||
strcat(dest, "111");
|
||||
length = strlen(gtin);
|
||||
ustrcat(dest, "111");
|
||||
for (i = 1; i < length; i++) {
|
||||
if (i == half_way) {
|
||||
/* middle character - separates manufacturer no. from product no. */
|
||||
/* also inverses right hand characters */
|
||||
strcat(dest, "11111");
|
||||
ustrcat(dest, "11111");
|
||||
}
|
||||
|
||||
if (((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) {
|
||||
lookup(NEON, EANsetB, gtin[i], dest);
|
||||
lookup(NEON, EANsetB, gtin[i], (char *) dest);
|
||||
} else {
|
||||
lookup(NEON, EANsetA, gtin[i], dest);
|
||||
lookup(NEON, EANsetA, gtin[i], (char *) dest);
|
||||
}
|
||||
}
|
||||
|
||||
/* stop character */
|
||||
strcat(dest, "111");
|
||||
ustrcat(dest, "111");
|
||||
ustrcpy(symbol->text, gtin);
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Make an EAN-8 barcode when we haven't been given the check digit */
|
||||
static int ean8(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||
static int ean8(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[]) {
|
||||
/* EAN-8 is basically the same as UPC-A but with fewer digits */
|
||||
int length;
|
||||
char gtin[10];
|
||||
int error_number = 0;
|
||||
|
||||
strcpy(gtin, (char*) source);
|
||||
length = strlen(gtin);
|
||||
ustrcpy(gtin, source);
|
||||
|
||||
if (length == 7) {
|
||||
gtin[length] = upc_check(gtin);
|
||||
gtin[length + 1] = '\0';
|
||||
gtin[length++] = upc_check(gtin, 7);
|
||||
gtin[length] = '\0';
|
||||
} else {
|
||||
gtin[length - 1] = '\0';
|
||||
if (source[length - 1] != upc_check(gtin)) {
|
||||
if (source[length - 1] != upc_check(gtin, 7)) {
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("EAN-8: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin, upc_check(gtin));
|
||||
printf("EAN-8: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin,
|
||||
upc_check(gtin, 7));
|
||||
}
|
||||
strcpy(symbol->errtxt, "276: Invalid check digit");
|
||||
return ZINT_ERROR_INVALID_CHECK;
|
||||
}
|
||||
gtin[length - 1] = upc_check(gtin);
|
||||
}
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("EAN-8: %s, gtin: %s, Check digit: %c\n", source, gtin, length == 7 ? gtin[length] : gtin[length - 1]);
|
||||
printf("EAN-8: %s, gtin: %s, Check digit: %c\n", source, gtin,
|
||||
length == 7 ? gtin[length] : gtin[length - 1]);
|
||||
}
|
||||
|
||||
upca_draw(gtin, dest);
|
||||
upca_draw(gtin, length, dest);
|
||||
ustrcpy(symbol->text, gtin);
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* For ISBN(13) only */
|
||||
static char isbn13_check(unsigned char source[]) {
|
||||
unsigned int i, weight, sum, check, h;
|
||||
|
||||
sum = 0;
|
||||
weight = 1;
|
||||
h = ustrlen(source) - 1;
|
||||
|
||||
for (i = 0; i < h; i++) {
|
||||
sum += ctoi(source[i]) * weight;
|
||||
if (weight == 1) weight = 3;
|
||||
else weight = 1;
|
||||
}
|
||||
|
||||
check = sum % 10;
|
||||
check = 10 - check;
|
||||
if (check == 10) check = 0;
|
||||
return itoc(check);
|
||||
}
|
||||
|
||||
/* For ISBN(10) and SBN only */
|
||||
static char isbn_check(unsigned char source[]) {
|
||||
unsigned int i, weight, sum, check, h;
|
||||
static char isbn_check(const unsigned char source[], const int length) {
|
||||
int i, weight, sum, check;
|
||||
char check_char;
|
||||
|
||||
sum = 0;
|
||||
weight = 1;
|
||||
h = ustrlen(source) - 1;
|
||||
|
||||
for (i = 0; i < h; i++) {
|
||||
for (i = 0; i < length; i++) { /* Length will always be 9 */
|
||||
sum += ctoi(source[i]) * weight;
|
||||
weight++;
|
||||
}
|
||||
|
@ -541,7 +478,7 @@ static char isbn_check(unsigned char source[]) {
|
|||
}
|
||||
|
||||
/* Make an EAN-13 barcode from an SBN or ISBN */
|
||||
static int isbn(struct zint_symbol *symbol, unsigned char source[], const size_t src_len, char dest[]) {
|
||||
static int isbn(struct zint_symbol *symbol, unsigned char source[], const int src_len, unsigned char dest[]) {
|
||||
int i, error_number;
|
||||
char check_digit;
|
||||
|
||||
|
@ -565,8 +502,11 @@ static int isbn(struct zint_symbol *symbol, unsigned char source[], const size_t
|
|||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
check_digit = isbn13_check(source);
|
||||
check_digit = ean_check((const char *) source, 12);
|
||||
if (source[src_len - 1] != check_digit) {
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("ISBN: Invalid check digit %s, Check digit: %c\n", source, check_digit);
|
||||
}
|
||||
strcpy(symbol->errtxt, "280: Incorrect ISBN check");
|
||||
return ZINT_ERROR_INVALID_CHECK;
|
||||
}
|
||||
|
@ -582,8 +522,11 @@ static int isbn(struct zint_symbol *symbol, unsigned char source[], const size_t
|
|||
}
|
||||
|
||||
if (src_len == 9 || src_len == 10) /* Using 10 digit ISBN or 9 digit SBN padded with leading zero */ {
|
||||
check_digit = isbn_check(source);
|
||||
if (check_digit != source[ustrlen(source) - 1]) {
|
||||
check_digit = isbn_check(source, 9);
|
||||
if (check_digit != source[9]) {
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("ISBN(10)/SBN: Invalid check digit %s, Check digit: %c\n", source, check_digit);
|
||||
}
|
||||
strcpy(symbol->errtxt, src_len == 9 ? "281: Incorrect SBN check" : "281: Incorrect ISBN check");
|
||||
return ZINT_ERROR_INVALID_CHECK;
|
||||
}
|
||||
|
@ -596,16 +539,17 @@ static int isbn(struct zint_symbol *symbol, unsigned char source[], const size_t
|
|||
source[12] = '\0';
|
||||
}
|
||||
|
||||
return ean13(symbol, source, dest);
|
||||
return ean13(symbol, source, 12, dest);
|
||||
}
|
||||
|
||||
/* Add leading zeroes to EAN and UPC strings */
|
||||
INTERNAL void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsigned char local_source[], int *p_with_addon) {
|
||||
INTERNAL void ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char source[],
|
||||
unsigned char local_source[], int *p_with_addon) {
|
||||
unsigned char first_part[20], second_part[7], zfirst_part[20], zsecond_part[7];
|
||||
int with_addon = 0;
|
||||
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h;
|
||||
|
||||
h = ustrlen(source);
|
||||
h = (int) ustrlen(source);
|
||||
for (i = 0; i < h; i++) {
|
||||
if (source[i] == '+') {
|
||||
with_addon = 1;
|
||||
|
@ -633,46 +577,52 @@ INTERNAL void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char sourc
|
|||
second_part[second_len] = '\0';
|
||||
|
||||
/* Calculate target lengths */
|
||||
if (second_len <= 5) {
|
||||
zsecond_len = 5;
|
||||
}
|
||||
if (second_len <= 2) {
|
||||
zsecond_len = 2;
|
||||
}
|
||||
if (second_len == 0) {
|
||||
zsecond_len = 0;
|
||||
} else {
|
||||
if (second_len <= 5) {
|
||||
if (second_len <= 2) {
|
||||
zsecond_len = 2;
|
||||
} else {
|
||||
zsecond_len = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (symbol->symbology) {
|
||||
case BARCODE_EANX:
|
||||
case BARCODE_EANX_CC:
|
||||
if (first_len <= 12) {
|
||||
zfirst_len = 12;
|
||||
}
|
||||
if (first_len <= 7) {
|
||||
zfirst_len = 7;
|
||||
if (first_len <= 7) {
|
||||
zfirst_len = 7;
|
||||
} else {
|
||||
zfirst_len = 12;
|
||||
}
|
||||
}
|
||||
if (second_len == 0 && symbol->symbology == BARCODE_EANX) { /* No composite EAN-2/5 */
|
||||
if (first_len <= 5) {
|
||||
zfirst_len = 5;
|
||||
}
|
||||
if (first_len <= 2) {
|
||||
zfirst_len = 2;
|
||||
if (first_len <= 2) {
|
||||
zfirst_len = 2;
|
||||
} else {
|
||||
zfirst_len = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BARCODE_EANX_CHK:
|
||||
if (first_len <= 13) {
|
||||
zfirst_len = 13;
|
||||
}
|
||||
if (first_len <= 8) {
|
||||
zfirst_len = 8;
|
||||
if (first_len <= 8) {
|
||||
zfirst_len = 8;
|
||||
} else {
|
||||
zfirst_len = 13;
|
||||
}
|
||||
}
|
||||
if (second_len == 0) {
|
||||
if (first_len <= 5) {
|
||||
zfirst_len = 5;
|
||||
}
|
||||
if (first_len <= 2) {
|
||||
zfirst_len = 2;
|
||||
if (first_len <= 2) {
|
||||
zfirst_len = 2;
|
||||
} else {
|
||||
zfirst_len = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -687,16 +637,14 @@ INTERNAL void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char sourc
|
|||
case BARCODE_UPCE_CC:
|
||||
if (first_len == 7) {
|
||||
zfirst_len = 7;
|
||||
}
|
||||
if (first_len <= 6) {
|
||||
} else if (first_len <= 6) {
|
||||
zfirst_len = 6;
|
||||
}
|
||||
break;
|
||||
case BARCODE_UPCE_CHK:
|
||||
if (first_len == 8) {
|
||||
zfirst_len = 8;
|
||||
}
|
||||
if (first_len <= 7) {
|
||||
} else if (first_len <= 7) {
|
||||
zfirst_len = 7;
|
||||
}
|
||||
break;
|
||||
|
@ -711,21 +659,21 @@ INTERNAL void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char sourc
|
|||
/* Add leading zeroes */
|
||||
zfirst_part[0] = '\0';
|
||||
for (i = 0; i < (zfirst_len - first_len); i++) {
|
||||
strcat((char*) zfirst_part, "0");
|
||||
ustrcat(zfirst_part, "0");
|
||||
}
|
||||
strcat((char*) zfirst_part, (char*) first_part);
|
||||
ustrcat(zfirst_part, first_part);
|
||||
|
||||
zsecond_part[0] = '\0';
|
||||
for (i = 0; i < (zsecond_len - second_len); i++) {
|
||||
strcat((char*) zsecond_part, "0");
|
||||
ustrcat(zsecond_part, "0");
|
||||
}
|
||||
strcat((char*) zsecond_part, (char*) second_part);
|
||||
ustrcat(zsecond_part, second_part);
|
||||
|
||||
/* Copy adjusted data back to local_source */
|
||||
strcat((char*) local_source, (char*) zfirst_part);
|
||||
if (ustrlen(zsecond_part)) {
|
||||
strcat((char*) local_source, "+");
|
||||
strcat((char*) local_source, (char*) zsecond_part);
|
||||
ustrcat(local_source, zfirst_part);
|
||||
if (*zsecond_part) {
|
||||
ustrcat(local_source, "+");
|
||||
ustrcat(local_source, zsecond_part);
|
||||
}
|
||||
|
||||
if (p_with_addon) {
|
||||
|
@ -737,10 +685,11 @@ INTERNAL void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char sourc
|
|||
INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
|
||||
unsigned char first_part[20] = {0}, second_part[7] = {0}, dest[1000] = {0};
|
||||
unsigned char local_source[21] = {0}; /* Allow 13 + "+" + 6 (too long add-on) + 1 */
|
||||
unsigned int latch, reader, writer;
|
||||
int latch, reader, writer;
|
||||
int with_addon;
|
||||
int error_number, i, plus_count;
|
||||
int addon_gap = 0;
|
||||
int first_part_len, second_part_len;
|
||||
|
||||
latch = FALSE;
|
||||
writer = 0;
|
||||
|
@ -781,6 +730,7 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
|
||||
reader = 0;
|
||||
if (with_addon) {
|
||||
int local_length = (int) ustrlen(local_source);
|
||||
do {
|
||||
if (local_source[reader] == '+') {
|
||||
first_part[writer] = '\0';
|
||||
|
@ -798,39 +748,42 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
reader++;
|
||||
writer++;
|
||||
}
|
||||
} while (reader <= ustrlen(local_source));
|
||||
} while (reader <= local_length);
|
||||
|
||||
if (symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK || symbol->symbology == BARCODE_UPCA_CC) {
|
||||
if (symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK
|
||||
|| symbol->symbology == BARCODE_UPCA_CC) {
|
||||
addon_gap = symbol->option_2 >= 9 && symbol->option_2 <= 12 ? symbol->option_2 : 9;
|
||||
} else {
|
||||
addon_gap = symbol->option_2 >= 7 && symbol->option_2 <= 12 ? symbol->option_2 : 7;
|
||||
}
|
||||
} else {
|
||||
strcpy((char*) first_part, (char*) local_source);
|
||||
ustrcpy(first_part, local_source);
|
||||
}
|
||||
|
||||
first_part_len = (int) ustrlen(first_part);
|
||||
|
||||
switch (symbol->symbology) {
|
||||
case BARCODE_EANX:
|
||||
case BARCODE_EANX_CHK:
|
||||
switch (ustrlen(first_part)) {
|
||||
case 2: add_on(first_part, (char*) dest, 0);
|
||||
switch (first_part_len) {
|
||||
case 2: add_on(first_part, first_part_len, dest, 0);
|
||||
ustrcpy(symbol->text, first_part);
|
||||
break;
|
||||
case 5: add_on(first_part, (char*) dest, 0);
|
||||
case 5: add_on(first_part, first_part_len, dest, 0);
|
||||
ustrcpy(symbol->text, first_part);
|
||||
break;
|
||||
case 7:
|
||||
case 8: error_number = ean8(symbol, first_part, (char*) dest);
|
||||
case 8: error_number = ean8(symbol, first_part, first_part_len, dest);
|
||||
break;
|
||||
case 12:
|
||||
case 13: error_number = ean13(symbol, first_part, (char*) dest);
|
||||
case 13: error_number = ean13(symbol, first_part, first_part_len, dest);
|
||||
break;
|
||||
default: strcpy(symbol->errtxt, "286: Input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
break;
|
||||
case BARCODE_EANX_CC:
|
||||
switch (ustrlen(first_part)) { /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */
|
||||
switch (first_part_len) { /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */
|
||||
case 7: set_module(symbol, symbol->rows, 1);
|
||||
set_module(symbol, symbol->rows, 67);
|
||||
set_module(symbol, symbol->rows + 1, 0);
|
||||
|
@ -841,7 +794,7 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
symbol->row_height[symbol->rows + 1] = 2;
|
||||
symbol->row_height[symbol->rows + 2] = 2;
|
||||
symbol->rows += 3;
|
||||
error_number = ean8(symbol, first_part, (char*) dest);
|
||||
error_number = ean8(symbol, first_part, first_part_len, dest);
|
||||
break;
|
||||
case 12:
|
||||
case 13:set_module(symbol, symbol->rows, 1);
|
||||
|
@ -854,7 +807,7 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
symbol->row_height[symbol->rows + 1] = 2;
|
||||
symbol->row_height[symbol->rows + 2] = 2;
|
||||
symbol->rows += 3;
|
||||
error_number = ean13(symbol, first_part, (char*) dest);
|
||||
error_number = ean13(symbol, first_part, first_part_len, dest);
|
||||
break;
|
||||
default: strcpy(symbol->errtxt, "287: Input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
|
@ -862,15 +815,15 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
break;
|
||||
case BARCODE_UPCA:
|
||||
case BARCODE_UPCA_CHK:
|
||||
if ((ustrlen(first_part) == 11) || (ustrlen(first_part) == 12)) {
|
||||
error_number = upca(symbol, first_part, (char*) dest);
|
||||
if ((first_part_len == 11) || (first_part_len == 12)) {
|
||||
error_number = upca(symbol, first_part, first_part_len, dest);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "288: Input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
break;
|
||||
case BARCODE_UPCA_CC:
|
||||
if (ustrlen(first_part) == 11 || ustrlen(first_part) == 12) {
|
||||
if (first_part_len == 11 || first_part_len == 12) {
|
||||
set_module(symbol, symbol->rows, 1);
|
||||
set_module(symbol, symbol->rows, 95);
|
||||
set_module(symbol, symbol->rows + 1, 0);
|
||||
|
@ -881,7 +834,7 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
symbol->row_height[symbol->rows + 1] = 2;
|
||||
symbol->row_height[symbol->rows + 2] = 2;
|
||||
symbol->rows += 3;
|
||||
error_number = upca(symbol, first_part, (char*) dest);
|
||||
error_number = upca(symbol, first_part, first_part_len, dest);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "289: Input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
|
@ -889,15 +842,15 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
break;
|
||||
case BARCODE_UPCE:
|
||||
case BARCODE_UPCE_CHK:
|
||||
if ((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= (symbol->symbology == BARCODE_UPCE ? 7 : 8))) {
|
||||
error_number = upce(symbol, first_part, (char*) dest);
|
||||
if ((first_part_len >= 6) && (first_part_len <= (symbol->symbology == BARCODE_UPCE ? 7 : 8))) {
|
||||
error_number = upce(symbol, first_part, first_part_len, dest);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "290: Input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
break;
|
||||
case BARCODE_UPCE_CC:
|
||||
if ((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
|
||||
if ((first_part_len >= 6) && (first_part_len <= 7)) {
|
||||
set_module(symbol, symbol->rows, 1);
|
||||
set_module(symbol, symbol->rows, 51);
|
||||
set_module(symbol, symbol->rows + 1, 0);
|
||||
|
@ -908,14 +861,14 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
symbol->row_height[symbol->rows + 1] = 2;
|
||||
symbol->row_height[symbol->rows + 2] = 2;
|
||||
symbol->rows += 3;
|
||||
error_number = upce(symbol, first_part, (char*) dest);
|
||||
error_number = upce(symbol, first_part, first_part_len, dest);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "291: Input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
break;
|
||||
case BARCODE_ISBNX:
|
||||
error_number = isbn(symbol, first_part, ustrlen(first_part), (char*) dest);
|
||||
error_number = isbn(symbol, first_part, first_part_len, dest);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -923,24 +876,26 @@ INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_le
|
|||
return error_number;
|
||||
}
|
||||
|
||||
switch (ustrlen(second_part)) {
|
||||
second_part_len = (int) ustrlen(second_part);
|
||||
|
||||
switch (second_part_len) {
|
||||
case 0: break;
|
||||
case 2:
|
||||
add_on(second_part, (char*) dest, addon_gap);
|
||||
strcat((char*) symbol->text, "+");
|
||||
strcat((char*) symbol->text, (char*) second_part);
|
||||
add_on(second_part, second_part_len, dest, addon_gap);
|
||||
ustrcat(symbol->text, "+");
|
||||
ustrcat(symbol->text, second_part);
|
||||
break;
|
||||
case 5:
|
||||
add_on(second_part, (char*) dest, addon_gap);
|
||||
strcat((char*) symbol->text, "+");
|
||||
strcat((char*) symbol->text, (char*) second_part);
|
||||
add_on(second_part, second_part_len, dest, addon_gap);
|
||||
ustrcat(symbol->text, "+");
|
||||
ustrcat(symbol->text, second_part);
|
||||
break;
|
||||
default:
|
||||
strcpy(symbol->errtxt, "292: Add-on input wrong length");
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
expand(symbol, (char*) dest);
|
||||
expand(symbol, (const char *) dest);
|
||||
|
||||
switch (symbol->symbology) {
|
||||
case BARCODE_EANX_CC:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue