From e6ace8a8553d32080eaf668cbbbeedee301e2766 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Sun, 7 Dec 2008 20:11:50 +0000 Subject: [PATCH] Add Korea Post --- backend/library.c | 3 ++- backend/postal.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ frontend/test.sh | 3 +++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/backend/library.c b/backend/library.c index 8e963aeb..858d6083 100644 --- a/backend/library.c +++ b/backend/library.c @@ -111,6 +111,7 @@ extern int ean_14(struct zint_symbol *symbol, unsigned char source[]); /* EAN-14 extern int nve_18(struct zint_symbol *symbol, unsigned char source[]); /* NVE-18 */ extern int microqr(struct zint_symbol *symbol, unsigned char source[]); /* Micro QR Code */ extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[]); /* Aztec Runes */ +extern int korea_post(struct zint_symbol *symbol, unsigned char source[]); /* Korea Post */ #ifndef NO_PNG int png_handle(struct zint_symbol *symbol, int rotate_angle); @@ -170,7 +171,6 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input) if((symbol->symbology == 64) || (symbol->symbology == 65)) { symbol->symbology = BARCODE_AUSPOST; } if(symbol->symbology == 73) { strcpy(symbol->errtxt, "Codablock E not supported [Z06]"); error_number = ERROR_INVALID_OPTION; } if(symbol->symbology == 76) { strcpy(symbol->errtxt, "Japanese Postal Code not supported [Z07]"); error_number = ERROR_INVALID_OPTION; } - if(symbol->symbology == 77) { strcpy(symbol->errtxt, "Korean Postal Code not supported [Z08]"); error_number = ERROR_INVALID_OPTION; } if(symbol->symbology == 78) { symbol->symbology = BARCODE_RSS14; } if(symbol->symbology == 83) { symbol->symbology = BARCODE_PLANET; } if(symbol->symbology == 88) { symbol->symbology = BARCODE_EAN128; } @@ -270,6 +270,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input) case BARCODE_EAN14: error_number = ean_14(symbol, input); break; case BARCODE_MICROQR: error_number = microqr(symbol, input); break; case BARCODE_AZRUNE: error_number = aztec_runes(symbol, input); break; + case BARCODE_KOREAPOST: error_number = korea_post(symbol, input); break; } if(error_number == 0) { error_number = error_buffer; diff --git a/backend/postal.c b/backend/postal.c index 0bf6558f..85b19f3c 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -48,6 +48,9 @@ static char *RoyalTable[36] = {"3300", "3210", "3201", "2310", "2301", "2211", " static char *FlatTable[10] = {"0504", "18", "0117", "0216", "0315", "0414", "0513", "0612", "0711", "0810"}; +static char *KoreaTable[10] = {"1313150613", "0713131313", "0417131313", "1506131313", + "0413171313", "17171313", "1315061313", "0413131713", "17131713", "13171713"}; + int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) { /* Handles the PostNet system used for Zip codes in the US */ @@ -199,6 +202,48 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[]) return error_number; } +int korea_post(struct zint_symbol *symbol, unsigned char source[]) +{ /* Korean Postal Authority */ + + int total, h, loop, check, zeroes, error_number; + char localstr[7], checkstr[3], dest[80]; + + error_number = 0; + h = ustrlen(source); + if(h > 6) { + strcpy(symbol->errtxt, "Input too long [771]"); + return ERROR_TOO_LONG; + } + error_number = is_sane(NESET, source); + if(error_number == ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data [772]"); + return error_number; + } + strcpy(localstr, ""); + zeroes = 6 - h; + for(loop = 0; loop < zeroes; loop++) + concat(localstr, "0"); + concat(localstr, (char *)source); + + total = 0; + for(loop = 0; loop < 6; loop++) { + total += ctoi(localstr[loop]); + } + check = 10 - (total % 10); + checkstr[0] = itoc(check); + checkstr[1] = '\0'; + concat(localstr, checkstr); + + strcpy(dest, ""); + for(loop = 5; loop >= 0; loop--) { + lookup(NESET, KoreaTable, localstr[loop], dest); + } + lookup(NESET, KoreaTable, localstr[6], dest); + expand(symbol, dest); + strcpy(symbol->text, localstr); + return error_number; +} + int fim(struct zint_symbol *symbol, unsigned char source[]) { /* The simplest barcode symbology ever! Supported by MS Word, so here it is! */ diff --git a/frontend/test.sh b/frontend/test.sh index 2051b279..4bffd0d0 100755 --- a/frontend/test.sh +++ b/frontend/test.sh @@ -176,6 +176,9 @@ echo testing Codablock-F echo testing NVE-18 ./zint -o bar75.png -b 75 --height=50 -d 76543210987654321 ./zint -o bar75.eps -b 75 --height=50 -d 76543210987654321 +echo testing Korea Post +./zint -o bar77.eps -b 77 --height=50 -d 123456 +./zint -o bar77.png -b 77 --height=50 -d 123456 echo testing GS1 DataBar Truncated ./zint -o bar78.eps -b 29 --height=13 -d 1234567890 ./zint -o bar78.png -b 29 --height=13 -d 1234567890