diff --git a/backend/code.c b/backend/code.c index 0e29f2c2..08d6d945 100644 --- a/backend/code.c +++ b/backend/code.c @@ -223,7 +223,7 @@ int c39(struct zint_symbol *symbol, unsigned char source[]) /* Stop character */ concat (dest, "121121211"); - if(symbol->symbology == BARCODE_LOGMARS) { + if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) { /* LOGMARS uses wider 'wide' bars than normal Code 39 */ for(i = 0; i < strlen(dest); i++) { if(dest[i] == '2') { diff --git a/backend/library.c b/backend/library.c index c11e43dd..5fb8aa10 100644 --- a/backend/library.c +++ b/backend/library.c @@ -24,6 +24,8 @@ #include "common.h" #include "gs1.h" +#define HIBCSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" + struct zint_symbol *ZBarcode_Create() { struct zint_symbol *symbol; @@ -140,6 +142,91 @@ void error_tag(char error_string[], int error_number) } } +int hibc(struct zint_symbol *symbol, unsigned char source[]) +{ + int counter, srclen, error_number, i; + char to_process[40], temp[3], check_digit; + + srclen = ustrlen(source); + strcpy(temp, ""); + + to_upper(source); + if(srclen > 36) { + strcpy(symbol->errtxt, "Data too long for HIBC LIC"); + return ERROR_TOO_LONG; + } + error_number = is_sane(HIBCSET , source); + if(error_number == ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data [082]"); + return error_number; + } + + strcpy(to_process, "+"); + counter = 41; + for(i = 0; i < ustrlen(source); i++) { + counter += posn(HIBCSET, source[i]); + } + counter = counter % 43; + + if(counter < 10) { + check_digit = itoc(counter); + } else { + if(counter < 36) { + check_digit = (counter - 10) + 'A'; + } else { + switch(counter) { + case 36: check_digit = '-'; break; + case 37: check_digit = '.'; break; + case 38: check_digit = ' '; break; + case 39: check_digit = '$'; break; + case 40: check_digit = '/'; break; + case 41: check_digit = '+'; break; + case 42: check_digit = 37; break; + default: check_digit = ' '; break; /* Keep compiler happy */ + } + } + } + + temp[0] = check_digit; + temp[1] = '\0'; + + concat(to_process, (char *)source); + concat(to_process, temp); + + switch(symbol->symbology) { + case BARCODE_HIBC_128: + error_number = code_128(symbol, (unsigned char *)to_process); + strcpy(symbol->text, "*"); + concat(symbol->text, to_process); + concat(symbol->text, "*"); + break; + case BARCODE_HIBC_39: + error_number = c39(symbol, (unsigned char *)to_process); + strcpy(symbol->text, "*"); + concat(symbol->text, to_process); + concat(symbol->text, "*"); + break; + case BARCODE_HIBC_DM: + error_number = dmatrix(symbol, (unsigned char *)to_process); + break; + case BARCODE_HIBC_QR: + error_number = qr_code(symbol, (unsigned char *)to_process); + break; + case BARCODE_HIBC_PDF: + error_number = pdf417enc(symbol, (unsigned char *)to_process); + break; + case BARCODE_HIBC_MICPDF: + error_number = micro_pdf417(symbol, (unsigned char *)to_process); + break; + case BARCODE_HIBC_BLOCKF: + error_number = codablock(symbol, (unsigned char *)to_process); + break; + } + + return error_number; +} + + int eci_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[]) { int j, i, next, input_length; @@ -265,7 +352,14 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) if(symbol->symbology == 88) { symbol->symbology = BARCODE_EAN128; } if(symbol->symbology == 91) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z09]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } if((symbol->symbology >= 94) && (symbol->symbology <= 96)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z10]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } - if((symbol->symbology >= 98) && (symbol->symbology <= 127)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z10]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology == 100) { symbol->symbology = BARCODE_HIBC_128; } + if(symbol->symbology == 101) { symbol->symbology = BARCODE_HIBC_39; } + if(symbol->symbology == 103) { symbol->symbology = BARCODE_HIBC_DM; } + if(symbol->symbology == 105) { symbol->symbology = BARCODE_HIBC_QR; } + if(symbol->symbology == 107) { symbol->symbology = BARCODE_HIBC_PDF; } + if(symbol->symbology == 109) { symbol->symbology = BARCODE_HIBC_MICPDF; } + if(symbol->symbology == 111) { symbol->symbology = BARCODE_HIBC_BLOCKF; } + if((symbol->symbology >= 112) && (symbol->symbology <= 127)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z10]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } /* Everything from 128 up is Zint-specific */ if(symbol->symbology >= 140) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z11]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } @@ -385,6 +479,13 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) case BARCODE_MICROQR: error_number = microqr(symbol, preprocessed); break; case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed); break; case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed); break; + case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed); break; + case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed); break; + case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed); break; + case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed); break; + case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed); break; + case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed); break; + case BARCODE_HIBC_BLOCKF: error_number = hibc(symbol, preprocessed); break; } if(error_number == 0) { error_number = error_buffer; diff --git a/backend/png.c b/backend/png.c index 0ecc8f6a..c12be71a 100644 --- a/backend/png.c +++ b/backend/png.c @@ -777,7 +777,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle) /* Put boundary bars or box around symbol */ if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { - if(symbol->symbology != BARCODE_CODABLOCKF) { + if((symbol->symbology != BARCODE_CODABLOCKF) && (symbol->symbology != BARCODE_HIBC_BLOCKF)) { /* boundary bars */ draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * scaler, textoffset * scaler, symbol->border_width * scaler, image_width, image_height); draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, symbol->border_width * scaler, image_width, image_height); diff --git a/backend/ps.c b/backend/ps.c index a5710e70..ea852a88 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -703,6 +703,7 @@ int ps_plot(struct zint_symbol *symbol) switch(symbol->symbology) { case BARCODE_CODABLOCKF: + case BARCODE_HIBC_BLOCKF: fprintf(feps, "TE\n"); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, xoffset * scaler, symbol->width * scaler); diff --git a/backend/zint.h b/backend/zint.h index 8afcf6f1..4508295d 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -114,6 +114,15 @@ struct zint_symbol { #define BARCODE_DAFT 93 #define BARCODE_MICROQR 97 +/* Tbarcode 9 codes */ +#define BARCODE_HIBC_128 98 +#define BARCODE_HIBC_39 99 +#define BARCODE_HIBC_DM 102 +#define BARCODE_HIBC_QR 104 +#define BARCODE_HIBC_PDF 106 +#define BARCODE_HIBC_MICPDF 108 +#define BARCODE_HIBC_BLOCKF 110 + /* Zint specific */ #define BARCODE_AZRUNE 128 #define BARCODE_CODE32 129 diff --git a/frontend/test.sh b/frontend/test.sh index e92b65fa..17266313 100755 --- a/frontend/test.sh +++ b/frontend/test.sh @@ -232,6 +232,27 @@ echo testing DAFT Code echo testing Micro QR Code ./zint -o bar97.eps -b 97 -d "MicroQR Code" ./zint -o bar97.png -b 97 -d "MicroQR Code" +echo testing HIBC LIC 128 +./zint -o bar98.eps -b 98 -d "A99912345/9901510X3" +./zint -o bar98.png -b 98 -d "A99912345/9901510X3" +echo testing HIBC LIC 39 +./zint -o bar99.eps -b 99 -d "A123BJC5D6E71" +./zint -o bar99.png -b 99 -d "A123BJC5D6E71" +echo testing HIBC LIC Data Matrix +./zint -o bar102.eps -b 102 -d "A99912345/9901510X3" +./zint -o bar102.png -b 102 -d "A99912345/9901510X3" +echo testing HIBC LIC QR-Code +./zint -o bar104.eps -b 104 -d "A99912345/9901510X3" +./zint -o bar104.png -b 104 -d "A99912345/9901510X3" +echo testing HIBC LIC PDF417 +./zint -o bar106.eps -b 106 -d "A99912345/9901510X3" +./zint -o bar106.png -b 106 -d "A99912345/9901510X3" +echo testing HIBC LIC MicroPDF417 +./zint -o bar108.eps -b 108 -d "A99912345/9901510X3" +./zint -o bar108.png -b 108 -d "A99912345/9901510X3" +echo testing HIBC LIC Codablock F +./zint -o bar110.eps -b 110 -d "A99912345/9901510X3" +./zint -o bar110.png -b 110 -d "A99912345/9901510X3" echo testing Aztec Runes ./zint -o bar128.eps -b 128 -d 125 ./zint -o bar128.png -b 128 -d 125