From 13f4a3547d56d0c3f6cfa3c6bb2c6998f333841e Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Mon, 3 Aug 2020 12:13:05 +0100 Subject: [PATCH] New symbology: DPD Code (variation of Code 128) --- backend/code128.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ backend/code128.h | 2 ++ backend/library.c | 13 +++++++- backend/zint.h | 1 + docs/manual.txt | 8 +++++ frontend/main.c | 62 +++++++++++++++++++-------------------- 6 files changed, 129 insertions(+), 32 deletions(-) diff --git a/backend/code128.c b/backend/code128.c index a460de99..ac597d74 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -1105,3 +1105,78 @@ INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int leng return error_number; } + +/* DPD (Deutsher Paket Dienst) Code */ +/* Specification at ftp://dpd.at/Datenspezifikationen/EN/gbs_V4.0.2_hauptdokument.pdf + * or https://docplayer.net/33728877-Dpd-parcel-label-specification.html */ +INTERNAL int dpd_parcel(struct zint_symbol *symbol, unsigned char source[], int length) { + int error_number = 0; + int i, p; + char identifier; + const int mod = 36; + int cd; // Check digit + + if (length != 28) { + strcpy(symbol->errtxt, "349: DPD input wrong length"); + return ZINT_ERROR_TOO_LONG; + } + + identifier = source[0]; + source[0] = 'A'; + + to_upper(source); + error_number = is_sane(KRSET, source, length); + if (error_number == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "350: Invalid character in DPD data"); + return error_number; + } + + if ((identifier < 32) || (identifier > 127)) { + strcpy(symbol->errtxt, "351: Invalid DPD identifier"); + return ZINT_ERROR_INVALID_DATA; + } + + source[0] = identifier; + error_number = code_128(symbol, source, length); + + cd = mod; + + p = 0; + for (i = 1; i < length; i++) { + symbol->text[p] = source[i]; + p++; + + cd += posn(KRSET, source[i]); + if (cd > mod) cd -= mod; + cd *= 2; + if (cd >= (mod + 1)) cd -= mod + 1; + + switch (i) { + case 4: + case 7: + case 11: + case 15: + case 19: + case 21: + case 24: + case 27: + symbol->text[p] = ' '; + p++; + break; + } + } + + cd = mod + 1 - cd; + if (cd == mod) cd = 0; + + if (cd < 10) { + symbol->text[p] = cd + '0'; + } else { + symbol->text[p] = (cd - 10) + 'A'; + } + p++; + + symbol->text[p] = '\0'; + + return error_number; +} diff --git a/backend/code128.h b/backend/code128.h index 0b1f0425..7f3a73bc 100644 --- a/backend/code128.h +++ b/backend/code128.h @@ -46,6 +46,8 @@ extern "C" { #define LATCHC 95 #define AORB 96 #define ABORC 97 + +#define KRSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" INTERNAL int parunmodd(const unsigned char llyth); INTERNAL void dxsmooth(int list[2][C128_MAX], int *indexliste); diff --git a/backend/library.c b/backend/library.c index 8b8e76ae..0eadcc3d 100644 --- a/backend/library.c +++ b/backend/library.c @@ -95,6 +95,10 @@ void ZBarcode_Clear(struct zint_symbol *symbol) { free(symbol->bitmap); symbol->bitmap = NULL; } + if (symbol->alphamap != NULL) { + free(symbol->alphamap); + symbol->alphamap = NULL; + } symbol->bitmap_width = 0; symbol->bitmap_height = 0; @@ -105,6 +109,8 @@ void ZBarcode_Clear(struct zint_symbol *symbol) { void ZBarcode_Delete(struct zint_symbol *symbol) { if (symbol->bitmap != NULL) free(symbol->bitmap); + if (symbol->alphamap != NULL) + free(symbol->alphamap); // If there is a rendered version, ensure its memory is released vector_free(symbol); @@ -178,6 +184,7 @@ INTERNAL int vin(struct zint_symbol *symbol, const unsigned char source[], const INTERNAL int mailmark(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* Royal Mail 4-state Mailmark */ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* Ultracode */ INTERNAL int rmqr(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* rMQR */ +INTERNAL int dpd_parcel(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* DPD Code */ INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EPS/EMF/SVG */ @@ -501,6 +508,7 @@ static int is_linear(const int symbology) { case BARCODE_UPCE_CC: case BARCODE_CHANNEL: case BARCODE_VIN: + case BARCODE_DPD: result = 1; break; } @@ -632,6 +640,7 @@ int ZBarcode_ValidID(int symbol_id) { case BARCODE_MAILMARK: case BARCODE_ULTRA: case BARCODE_RMQR: + case BARCODE_DPD: result = 1; break; } @@ -852,6 +861,8 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour break; case BARCODE_ULTRA: error_number = ultracode(symbol, preprocessed, in_length); break; + case BARCODE_DPD: error_number = dpd_parcel(symbol, preprocessed, in_length); + break; } return error_number; @@ -1076,7 +1087,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; } - if ((symbol->symbology >= 94) && (symbol->symbology <= 96)) { + if ((symbol->symbology >= 94) && (symbol->symbology <= 95)) { strcpy(symbol->errtxt, "213: Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = ZINT_WARN_INVALID_OPTION; diff --git a/backend/zint.h b/backend/zint.h index 1b6de080..0d427ccb 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -188,6 +188,7 @@ extern "C" { #define BARCODE_KIX 90 #define BARCODE_AZTEC 92 #define BARCODE_DAFT 93 +#define BARCODE_DPD 96 #define BARCODE_MICROQR 97 /* Tbarcode 9 codes */ diff --git a/docs/manual.txt b/docs/manual.txt index 99b62379..364cb4ac 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -313,6 +313,7 @@ Numeric Value | Barcode Name 90 | Dutch Post KIX Code 92 | Aztec Code 93 | DAFT Code +96 | DPD Code 97 | Micro QR Code 98 | HIBC Code 128 99 | HIBC Code 39 @@ -1087,6 +1088,7 @@ Value | 90 | BARCODE_KIX | Dutch Post KIX Code 92 | BARCODE_AZTEC | Aztec Code 93 | BARCODE_DAFT | DAFT Code +96 | BARCODE_DPD | DPD Code 97 | BARCODE_MICROQR | Micro QR Code 98 | BARCODE_HIBC_128 | HIBC Code 128 99 | BARCODE_HIBC_39 | HIBC Code 39 @@ -1536,6 +1538,12 @@ This option adds a leading '+' character and a trailing modulo-49 check digit to a standard Code 128 symbol as required by the Health Industry Barcode standards. +6.1.11.7 DPD Code +----------------- +Another variation of Code 128 as used by DPD (Deutsher Paket Dienst). Requires +a 28 character alphanumeric input. Zint formats human readable text as +specified by DPD and adds a modulo-36 check character. + 6.1.12 GS1 DataBar (ISO 24724) ------------------------------ Previously known as RSS (Reduced Spaced Symbology) these symbols are due to diff --git a/frontend/main.c b/frontend/main.c index 80b4f089..4592af4e 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -38,37 +38,37 @@ /* Print list of supported symbologies */ static void types(void) { - printf( " 1: Code 11 52: PZN 97: Micro QR Code\n" - " 2: Standard 2of5 53: Pharma Two-Track 98: HIBC Code 128\n" - " 3: Interleaved 2of5 55: PDF417 99: HIBC Code 39\n" - " 4: IATA 2of5 56: Compact PDF417 102: HIBC Data Matrix\n" - " 6: Data Logic 57: Maxicode 104: HIBC QR Code\n" - " 7: Industrial 2of5 58: QR Code 106: HIBC PDF417\n" - " 8: Code 39 60: Code 128-B 108: HIBC MicroPDF417\n" - " 9: Extended Code 39 63: AP Standard Customer 110: HIBC Codablock-F\n" - "13: EAN 66: AP Reply Paid 112: HIBC Aztec Code\n" - "14: EAN + Check 67: AP Routing 115: DotCode\n" - "16: GS1-128 68: AP Redirection 116: Han Xin Code\n" - "18: Codabar 69: ISBN 121: RM Mailmark\n" - "20: Code 128 70: RM4SCC 128: Aztec Runes\n" - "21: Leitcode 71: Data Matrix 129: Code 32\n" - "22: Identcode 72: EAN-14 130: Comp EAN\n" - "23: Code 16k 73: VIN 131: Comp GS1-128\n" - "24: Code 49 74: Codablock-F 132: Comp DataBar Omni\n" - "25: Code 93 75: NVE-18 133: Comp DataBar Ltd\n" - "28: Flattermarken 76: Japanese Post 134: Comp DataBar Exp\n" - "29: GS1 DataBar Omni 77: Korea Post 135: Comp UPC-A\n" - "30: GS1 DataBar Ltd 79: GS1 DataBar Stack 136: Comp UPC-E\n" - "31: GS1 DataBar Exp 80: GS1 DataBar Stack Omni 137: Comp DataBar Stack\n" - "32: Telepen Alpha 81: GS1 DataBar Exp Stack 138: Comp DataBar Stack Omni\n" - "34: UPC-A 82: Planet 139: Comp DataBar Exp Stack\n" - "35: UPC-A + Check 84: MicroPDF 140: Channel Code\n" - "37: UPC-E 85: USPS Intelligent Mail 141: Code One\n" - "38: UPC-E + Check 86: UK Plessey 142: Grid Matrix\n" - "40: Postnet 87: Telepen Numeric 143: UPNQR\n" - "47: MSI Plessey 89: ITF-14 144: Ultracode\n" - "49: FIM 90: KIX Code 145: rMQR\n" - "50: Logmars 92: Aztec Code\n" + printf( " 1: Code 11 52: PZN 96: DPD Code\n" + " 2: Standard 2of5 53: Pharma Two-Track 97: Micro QR Code\n" + " 3: Interleaved 2of5 55: PDF417 98: HIBC Code 128\n" + " 4: IATA 2of5 56: Compact PDF417 99: HIBC Code 39\n" + " 6: Data Logic 57: Maxicode 102: HIBC Data Matrix\n" + " 7: Industrial 2of5 58: QR Code 104: HIBC QR Code\n" + " 8: Code 39 60: Code 128-B 106: HIBC PDF417\n" + " 9: Extended Code 39 63: AP Standard Customer 108: HIBC MicroPDF417\n" + "13: EAN 66: AP Reply Paid 110: HIBC Codablock-F\n" + "14: EAN + Check 67: AP Routing 112: HIBC Aztec Code\n" + "16: GS1-128 68: AP Redirection 115: DotCode\n" + "18: Codabar 69: ISBN 116: Han Xin Code\n" + "20: Code 128 70: RM4SCC 121: RM Mailmark\n" + "21: Leitcode 71: Data Matrix 128: Aztec Runes\n" + "22: Identcode 72: EAN-14 129: Code 32\n" + "23: Code 16k 73: VIN 130: Comp EAN\n" + "24: Code 49 74: Codablock-F 131: Comp GS1-128\n" + "25: Code 93 75: NVE-18 132: Comp DataBar Omni\n" + "28: Flattermarken 76: Japanese Post 133: Comp DataBar Ltd\n" + "29: GS1 DataBar Omni 77: Korea Post 134: Comp DataBar Exp\n" + "30: GS1 DataBar Ltd 79: GS1 DataBar Stack 135: Comp UPC-A\n" + "31: GS1 DataBar Exp 80: GS1 DataBar Stack Omni 136: Comp UPC-E\n" + "32: Telepen Alpha 81: GS1 DataBar Exp Stack 137: Comp DataBar Stack\n" + "34: UPC-A 82: Planet 138: Comp DataBar Stack Omni\n" + "35: UPC-A + Check 84: MicroPDF 139: Comp DataBar Exp Stack\n" + "37: UPC-E 85: USPS Intelligent Mail 140: Channel Code\n" + "38: UPC-E + Check 86: UK Plessey 141: Code One\n" + "40: Postnet 87: Telepen Numeric 142: Grid Matrix\n" + "47: MSI Plessey 89: ITF-14 143: UPNQR\n" + "49: FIM 90: KIX Code 144: Ultracode\n" + "50: Logmars 92: Aztec Code 145: rMQR\n" "51: Pharma One-Track 93: DAFT Code\n" ); }