New symbology: DPD Code (variation of Code 128)

This commit is contained in:
Robin Stuart 2020-08-03 12:13:05 +01:00
parent 42e866c889
commit 13f4a3547d
6 changed files with 129 additions and 32 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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;

View file

@ -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 */