From de08d8a885f61d437249304d7c3c798c5680dfa8 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Sat, 14 Mar 2009 11:04:52 +0000 Subject: [PATCH] Add Japanese Post Barcode --- backend/DEVELOPER | 1 + backend/library.c | 3 +- backend/postal.c | 114 ++++++++++++++++++++++++++++++++++++++++++++-- backend/zint.h | 1 + frontend/main.c | 53 ++++++++++----------- frontend/test.sh | 16 ++++--- readme | 1 - 7 files changed, 152 insertions(+), 37 deletions(-) diff --git a/backend/DEVELOPER b/backend/DEVELOPER index 49c89d93..25a1adeb 100644 --- a/backend/DEVELOPER +++ b/backend/DEVELOPER @@ -95,6 +95,7 @@ postal.c: DAFT Code Flattermarken Korean Postal Code + Japanese Postal Code qr.c: QR Code (libqrencode) diff --git a/backend/library.c b/backend/library.c index a37f324a..a3b40713 100644 --- a/backend/library.c +++ b/backend/library.c @@ -119,6 +119,7 @@ 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 */ +extern int japan_post(struct zint_symbol *symbol, unsigned char source[]); /* Japanese Post */ #ifndef NO_PNG int png_handle(struct zint_symbol *symbol, int rotate_angle); @@ -414,7 +415,6 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) if(symbol->symbology == 62) { symbol->symbology = BARCODE_CODE93; } 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 == 78) { symbol->symbology = BARCODE_RSS14; } if(symbol->symbology == 83) { symbol->symbology = BARCODE_PLANET; } if(symbol->symbology == 88) { symbol->symbology = BARCODE_EAN128; } @@ -563,6 +563,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) 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; + case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed); break; } if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { diff --git a/backend/postal.c b/backend/postal.c index ec8bbf23..74582fa7 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -25,7 +25,11 @@ #include "common.h" #define BESET "ABCD" +#define DAFTSET "DAFT" #define KRSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define KASUTSET "1234567890-abcdefgh" +#define CHKASUTSET "0123456789-abcdefgh" +#define SHKASUTSET "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* PostNet number encoding table - In this table L is long as S is short */ static char *PNTable[10] = {"LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS", "SLLSS", "LSSSL", @@ -51,6 +55,9 @@ static char *FlatTable[10] = {"0504", "18", "0117", "0216", "0315", "0414", "051 static char *KoreaTable[10] = {"1313150613", "0713131313", "0417131313", "1506131313", "0413171313", "17171313", "1315061313", "0413131713", "17131713", "13171713"}; +static char *JapanTable[19] = {"114", "132", "312", "123", "141", "321", "213", "231", "411", "144", + "414", "324", "342", "234", "432", "243", "423", "441", "111"}; + int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) { /* Handles the PostNet system used for Zip codes in the US */ @@ -411,16 +418,22 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[]) int input_length; char height_pattern[100], local_source[55]; unsigned int loopey; - int writer, i; + int writer, i, error_number; strcpy(height_pattern, ""); + error_number = 0; input_length = ustrlen(source); strcpy(local_source, (char*)source); if(input_length > 50) { - strcpy(symbol->errtxt, "Input too long [931]"); + strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } to_upper((unsigned char*)local_source); + error_number = is_sane(DAFTSET, (unsigned char*)local_source); + if(error_number == ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } for (i = 0; i < input_length; i++) { if(local_source[i] == 'D') { concat(height_pattern, "2"); } @@ -450,7 +463,7 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[]) symbol->rows = 3; symbol->width = writer - 1; - return 0; + return error_number; } int flattermarken(struct zint_symbol *symbol, unsigned char source[]) @@ -479,3 +492,98 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[]) expand(symbol, dest); return error_number; } + +int japan_post(struct zint_symbol *symbol, unsigned char source[]) +{ /* Japanese Postal Code (Kasutama Barcode) */ + int input_length, error_number; + char pattern[65]; + int writer, loopey, inter_posn, i, inter_length, sum, check; + char check_char; + + input_length = ustrlen(source); + inter_length = input_length * 2; + if(inter_length < 20) { inter_length = 20; } + char inter[inter_length]; + char local_source[input_length]; + inter_posn = 0; + error_number = 0; + + strcpy(local_source, (char*)source); + to_upper((unsigned char*)local_source); + error_number = is_sane(SHKASUTSET, (unsigned char*)local_source); + if(error_number == ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in data"); + return error_number; + } + + for(i = 0; i < (inter_length * 2); i++) { + inter[i] = 'd'; /* Pad character CC4 */ + } + + for(i = 0; i < input_length; i++) { + if(((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) { + inter[inter_posn] = local_source[i]; + inter_posn++; + } else { + if((local_source[i] >= 'A') && (local_source[i] <= 'J')) { + inter[inter_posn] = 'a'; + inter[inter_posn + 1] = local_source[i] - 'A' + '0'; + inter_posn += 2; + } + if((local_source[i] >= 'K') && (local_source[i] <= 'T')) { + inter[inter_posn] = 'b'; + inter[inter_posn + 1] = local_source[i] - 'K' + '0'; + inter_posn += 2; + } + if((local_source[i] >= 'U') && (local_source[i] <= 'Z')) { + inter[inter_posn] = 'c'; + inter[inter_posn + 1] = local_source[i] - 'U' + '0'; + inter_posn += 2; + } + } + } + + strcpy(pattern, "13"); /* Start */ + + sum = 0; + for(i = 0; i < 20; i++) { + concat(pattern, JapanTable[posn(KASUTSET, inter[i])]); + sum += posn(CHKASUTSET, inter[i]); + /* printf("%c (%d)\n", inter[i], posn(CHKASUTSET, inter[i])); */ + } + + /* Calculate check digit */ + check = 19 - (sum % 19); + if(check == 19) { check = 0; } + if(check <= 9) { check_char = check + '0'; } + if(check == 10) { check_char = '-'; } + if(check >= 11) { check_char = (check - 11) + 'a'; } + concat(pattern, JapanTable[posn(KASUTSET, check_char)]); + /* printf("check %c (%d)\n", check_char, check); */ + + concat(pattern, "31"); /* Stop */ + + /* Resolve pattern to 4-state symbols */ + writer = 0; + for(loopey = 0; loopey < strlen(pattern); loopey++) + { + if((pattern[loopey] == '2') || (pattern[loopey] == '1')) + { + symbol->encoded_data[0][writer] = '1'; + } + symbol->encoded_data[1][writer] = '1'; + if((pattern[loopey] == '3') || (pattern[loopey] == '1')) + { + symbol->encoded_data[2][writer] = '1'; + } + writer += 2; + } + + symbol->row_height[0] = 2; + symbol->row_height[1] = 2; + symbol->row_height[2] = 2; + symbol->rows = 3; + symbol->width = writer - 1; + + return error_number; +} diff --git a/backend/zint.h b/backend/zint.h index 2260554c..7aa96926 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -97,6 +97,7 @@ struct zint_symbol { #define BARCODE_EAN14 72 #define BARCODE_CODABLOCKF 74 #define BARCODE_NVE18 75 +#define BARCODE_JAPANPOST 76 #define BARCODE_KOREAPOST 77 #define BARCODE_RSS14STACK 79 #define BARCODE_RSS14STACK_OMNI 80 diff --git a/frontend/main.c b/frontend/main.c index e68a6f3c..24a3a9a4 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -28,32 +28,33 @@ #define NESET "0123456789" void types(void) { - printf( " 1: Code 11 50: Logmars 86: UK Plessey\n" - " 2: Standard 2 of 5 51: Pharma One-Track 87: Telepen Numeric\n" - " 3: Interleaved 2 of 5 52: PZN 89: ITF-14\n" - " 4: IATA 2 of 5 53: Pharma Two-Track 90: KIX Code\n" - " 6: Data Logic 55: PDF417 92: Aztec Code\n" - " 7: Industrial 2 of 5 56: PDF417 Trunc 93: DAFT Code\n" - " 8: Code 39 57: Maxicode 97: Micro QR Code\n" - " 9: Extended Code 39 58: QR Code 98: HIBC Code 128\n" - " 13: EAN 60: Code 128-B 99: HIBC Code 39\n" - " 16: GS1-128 63: AP Standard Customer 102: HIBC Data Matrix\n" - " 18: Codabar 66: AP Reply Paid 104: HIBC QR Code\n" - " 20: Code 128 67: AP Routing 106: HIBC PDF417\n" - " 21: Leitcode 68: AP Redirection 108: HIBC MicroPDF417\n" - " 22: Identcode 69: ISBN 110: HIBC Codablock-F\n" - " 23: Code 16k 70: RM4SCC 128: Aztec Runes\n" - " 25: Code 93 71: Data Matrix 129: Code 23\n" - " 28: Flattermarken 72: EAN-14 130: Comp + EAN\n" - " 29: Databar-14 74: Codablock-F 131: Comp + GS1-128\n" - " 30: Databar Limited 75: NVE-18 132: Comp + Databar-14\n" - " 31: Databar Extended 77: Korea Post 133: Comp + Databar Ltd\n" - " 32: Telepen Alpha 79: Databar-14 Stack 134: Comp + Databar Ext\n" - " 34: UPC-A 80: Databar-14 Stack Omni 135: Comp + UPC-A\n" - " 37: UPC-E 81: Databar Extended Stack 136: Comp + UPC-E\n" - " 40: Postnet 82: Planet 137: Comp + Databar-14 Stack\n" - " 47: MSI Plessey 84: MicroPDF 138: Comp + Databar Stack Omni\n" - " 49: FIM 85: USPS OneCode 139: Comp + Databar Ext Stack\n" + printf( " 1: Code 11 51: Pharma One-Track 87: Telepen Numeric\n" + " 2: Standard 2 of 5 52: PZN 89: ITF-14\n" + " 3: Interleaved 2 of 5 53: Pharma Two-Track 90: KIX Code\n" + " 4: IATA 2 of 5 55: PDF417 92: Aztec Code\n" + " 6: Data Logic 56: PDF417 Trunc 93: DAFT Code\n" + " 7: Industrial 2 of 5 57: Maxicode 97: Micro QR Code\n" + " 8: Code 39 58: QR Code 98: HIBC Code 128\n" + " 9: Extended Code 39 60: Code 128-B 99: HIBC Code 39\n" + " 13: EAN 63: AP Standard Customer 102: HIBC Data Matrix\n" + " 16: GS1-128 66: AP Reply Paid 104: HIBC QR Code\n" + " 18: Codabar 67: AP Routing 106: HIBC PDF417\n" + " 20: Code 128 68: AP Redirection 108: HIBC MicroPDF417\n" + " 21: Leitcode 69: ISBN 110: HIBC Codablock-F\n" + " 22: Identcode 70: RM4SCC 128: Aztec Runes\n" + " 23: Code 16k 71: Data Matrix 129: Code 23\n" + " 25: Code 93 72: EAN-14 130: Comp + EAN\n" + " 28: Flattermarken 74: Codablock-F 131: Comp + GS1-128\n" + " 29: Databar-14 75: NVE-18 132: Comp + Databar-14\n" + " 30: Databar Limited 76: Japanese Post 133: Comp + Databar Ltd\n" + " 31: Databar Extended 77: Korea Post 134: Comp + Databar Ext\n" + " 32: Telepen Alpha 79: Databar-14 Stack 135: Comp + UPC-A\n" + " 34: UPC-A 80: Databar-14 Stack Omni 136: Comp + UPC-E\n" + " 37: UPC-E 81: Databar Extended Stack 137: Comp + Databar-14 Stack\n" + " 40: Postnet 82: Planet 138: Comp + Databar Stack Omni\n" + " 47: MSI Plessey 84: MicroPDF 139: Comp + Databar Ext Stack\n" + " 49: FIM 85: USPS OneCode\n" + " 50: Logmars 86: UK Plessey\n" ); } diff --git a/frontend/test.sh b/frontend/test.sh index e6199f42..2d8995ec 100755 --- a/frontend/test.sh +++ b/frontend/test.sh @@ -182,9 +182,9 @@ echo testing QR Code ./zint -o bar58.png -b 58 --border=10 -d "Demonstration QR Code symbol generated by libzint" ./zint -o bar58.eps -b 58 --border=10 -d "Demonstration QR Code symbol generated by libzint" ./zint -o bar58.svg -b 58 --border=10 -d "Demonstration QR Code symbol generated by libzint" -./zint -o bar58k.png -b 58 --kanji --border=10 -d "登録商標です。" -./zint -o bar58k.eps -b 58 --kanji --border=10 -d "登録商標です。" -./zint -o bar58k.svg -b 58 --kanji --border=10 -d "登録商標です。" +./zint -o bar58k.png -b 58 --kanji --border=10 -d "画像内の単語を非表示にする" +./zint -o bar58k.eps -b 58 --kanji --border=10 -d "画像内の単語を非表示にする" +./zint -o bar58k.svg -b 58 --kanji --border=10 -d "画像内の単語を非表示にする" echo testing Code 128 Subset B ./zint -o bar60.png -b 60 --height=50 --border=10 -d 87654321 ./zint -o bar60.eps -b 60 --height=50 --border=10 -d 87654321 @@ -247,6 +247,10 @@ echo testing NVE-18 ./zint -o bar75.png -b 75 --height=50 --border=10 -d 76543210987654321 ./zint -o bar75.eps -b 75 --height=50 --border=10 -d 76543210987654321 ./zint -o bar75.svg -b 75 --height=50 --border=10 -d 76543210987654321 +echo testing Japanese Post +./zint -o bar76.png -b 76 --border=10 -d 10000131-3-2-503 +./zint -o bar76.eps -b 76 --border=10 -d 10000131-3-2-503 +./zint -o bar76.svg -b 76 --border=10 -d 10000131-3-2-503 echo testing Korea Post ./zint -o bar77.png -b 77 --height=50 --border=10 -d 123456 ./zint -o bar77.eps -b 77 --height=50 --border=10 -d 123456 @@ -314,9 +318,9 @@ echo testing Micro QR Code ./zint -o bar97.png -b 97 --border=10 -d "MicroQR Code" ./zint -o bar97.eps -b 97 --border=10 -d "MicroQR Code" ./zint -o bar97.svg -b 97 --border=10 -d "MicroQR Code" -./zint -o bar97k.png -b 97 --kanji --border=10 -d "登録商標です。" -./zint -o bar97k.eps -b 97 --kanji --border=10 -d "登録商標です。" -./zint -o bar97k.svg -b 97 --kanji --border=10 -d "登録商標です。" +./zint -o bar97k.png -b 97 --kanji --border=10 -d "小さい" +./zint -o bar97k.eps -b 97 --kanji --border=10 -d "小さい" +./zint -o bar97k.svg -b 97 --kanji --border=10 -d "小さい" echo testing HIBC LIC 128 ./zint -o bar98.png -b 98 --border=10 -d "A99912345/9901510X3" ./zint -o bar98.eps -b 98 --border=10 -d "A99912345/9901510X3" diff --git a/readme b/readme index ac677910..daf8980f 100644 --- a/readme +++ b/readme @@ -106,7 +106,6 @@ Research not yet been found. * DPD Code * Italian Postal Code - * Japanese Postal Code Coming Soon -----------