diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 5f2c4dd8..e3b246fc 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -8,7 +8,7 @@ find_package(Qr) set(zint_COMMON_SRCS common.c library.c ps.c large.c reedsol.c gs1.c svg.c) set(zint_ONEDIM_SRCS code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c) set(zint_POSTAL_SRCS postal.c auspost.c imail.c) -set(zint_TWODIM_SRCS code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c micqr.c maxicode.c composite.c aztec.c code49.c) +set(zint_TWODIM_SRCS code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c micqr.c maxicode.c composite.c aztec.c code49.c code1.c) set(zint_SRCS ${zint_COMMON_SRCS} ${zint_ONEDIM_SRCS} ${zint_POSTAL_SRCS} ${zint_TWODIM_SRCS} ) if(PNG_FOUND) diff --git a/backend/Makefile b/backend/Makefile index 03867661..04c30ae6 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -25,8 +25,8 @@ ONEDIM:= code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c ONEDIM_OBJ:= code.o code128.o 2of5.o upcean.o telepen.o medical.o plessey.o rss.o POSTAL:= postal.c auspost.c imail.c POSTAL_OBJ:= postal.o auspost.o imail.o -TWODIM:= code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c maxicode.c composite.c aztec.c micqr.c code49.c -TWODIM_OBJ:= code16k.o blockf.o dmatrix.o dm200.o pdf417.o qr.o maxicode.o composite.o aztec.o micqr.o code49.o +TWODIM:= code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c maxicode.c composite.c aztec.c micqr.c code49.c code1.c +TWODIM_OBJ:= code16k.o blockf.o dmatrix.o dm200.o pdf417.o qr.o maxicode.o composite.o aztec.o micqr.o code49.o code1.o LIBS:= `libpng12-config --I_opts --L_opts --ldflags` -lz -lm ifeq ($(NO_QR),true) @@ -36,7 +36,7 @@ DEFINES:= LIBS+= -lqrencode endif -libzint: code.c code128.c 2of5.c upcean.c medical.c telepen.c plessey.c postal.c auspost.c imail.c code16k.c dmatrix.c dm200.c reedsol.c pdf417.c maxicode.c rss.c common.c png.c library.c ps.c qr.c large.c composite.c aztec.c blockf.c micqr.c gs1.c svg.c code49.c +libzint: code.c code128.c 2of5.c upcean.c medical.c telepen.c plessey.c postal.c auspost.c imail.c code16k.c dmatrix.c dm200.c reedsol.c pdf417.c maxicode.c rss.c common.c png.c library.c ps.c qr.c large.c composite.c aztec.c blockf.c micqr.c gs1.c svg.c code49.c code1.c $(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(ONEDIM) $(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(POSTAL) $(CC) -Wall -fPIC $(DEFINES) $(CFLAGS) $(ZINT_VERSION) -c $(TWODIM) diff --git a/backend/code1.c b/backend/code1.c new file mode 100644 index 00000000..47d823cc --- /dev/null +++ b/backend/code1.c @@ -0,0 +1,1316 @@ +/* code1.c - USS Code One */ + +/* + libzint - the open source barcode library + Copyright (C) 2009 Robin Stuart + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "common.h" +#include "code1.h" +#include "reedsol.h" +#include +#include +#include + +void horiz(struct zint_symbol *symbol, int row_no, int full) +{ + int i; + + if(full) { + for(i = 0; i < symbol->width; i++) { + set_module(symbol, row_no, i); + } + } else { + for(i = 1; i < symbol->width - 1; i++) { + set_module(symbol, row_no, i); + } + } +} + +void central_finder(struct zint_symbol *symbol, int start_row, int row_count, int full_rows) +{ + int i; + + for(i = 0; i < row_count; i++) { + if(i < full_rows) { + horiz(symbol, start_row + (i * 2), 1); + } else { + horiz(symbol, start_row + (i * 2), 0); + if(i != row_count - 1) { + set_module(symbol, start_row + (i * 2) + 1, 1); + set_module(symbol, start_row + (i * 2) + 1, symbol->width - 2); + } + } + } +} + +void vert(struct zint_symbol *symbol, int column, int height, int top) +{ + int i; + + if(top) { + for (i = 0; i < height; i++) { + set_module(symbol, i, column); + } + } else { + for (i = 0; i < height; i++) { + set_module(symbol, symbol->rows - i - 1, column); + } + } +} + +void spigot(struct zint_symbol *symbol, int row_no) +{ + int i; + + for(i = symbol->width - 1; i > 0; i--) { + if(module_is_set(symbol, row_no, i - 1)) { + set_module(symbol, row_no, i); + } + } +} + +int isedi(unsigned char input) +{ + int result = 0; + + if(input == 13) { result = 1; } + if(input == '*') { result = 1; } + if(input == '>') { result = 1; } + if(input == ' ') { result = 1; } + if((input >= '0') && (input <= '9')) { result = 1; } + if((input >= 'A') && (input <= 'Z')) { result = 1; } + + return result; +} + +int dq4bi(unsigned char source[], int sourcelen, int position) +{ + int i; + + for(i = position; isedi(source[position + i]) && ((position + i) < sourcelen); i++); + + if((position + i) == sourcelen) { + /* Reached end of input */ + return 0; + } + + if (source[position + i - 1] == 13) { return 1; } + if (source[position + i - 1] == '*') { return 1; } + if (source[position + i - 1] == '>') { return 1; } + + return 0; +} + +int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int current_mode, int gs1) +{ + float ascii_count, c40_count, text_count, edi_count, byte_count; + char reduced_char; + int done, best_scheme, best_count, sp; + + /* Step J */ + if(current_mode == C1_ASCII) { + ascii_count = 0.0; + c40_count = 1.0; + text_count = 1.0; + edi_count = 1.0; + byte_count = 2.0; + } else { + ascii_count = 1.0; + c40_count = 2.0; + text_count = 2.0; + edi_count = 2.0; + byte_count = 3.0; + } + + switch(current_mode) { + case C1_C40: c40_count = 0.0; break; + case C1_TEXT: text_count = 0.0; break; + case C1_BYTE: byte_count = 0.0; break; + case C1_EDI: edi_count = 0.0; break; + } + + for(sp = position; (sp < sourcelen) && (sp <= (position + 8)); sp++) { + + if(source[sp] <= 127) { reduced_char = source[sp]; } else { reduced_char = source[sp] - 127; } + + /* Step L */ + if((source[sp] >= '0') && (source[sp] <= '9')) { + ascii_count += 0.5; + } else { + ascii_count = froundup(ascii_count); + if(source[sp] > 127) { + ascii_count += 2.0; + } else { + ascii_count += 1.0; + } + } + + /* Step M */ + done = 0; + if(reduced_char == ' ') { c40_count += (2.0 / 3.0); done = 1; } + if((reduced_char >= '0') && (reduced_char <= '9')) { c40_count += (2.0 / 3.0); done = 1; } + if((reduced_char >= 'A') && (reduced_char <= 'Z')) { c40_count += (2.0 / 3.0); done = 1; } + if(source[sp] > 127) { c40_count += (4.0 / 3.0); } + if(done == 0) { c40_count += (4.0 / 3.0); } + + /* Step N */ + done = 0; + if(reduced_char == ' ') { text_count += (2.0 / 3.0); done = 1; } + if((reduced_char >= '0') && (reduced_char <= '9')) { text_count += (2.0 / 3.0); done = 1; } + if((reduced_char >= 'a') && (reduced_char <= 'z')) { text_count += (2.0 / 3.0); done = 1; } + if(source[sp] > 127) { text_count += (4.0 / 3.0); } + if(done == 0) { text_count += (4.0 / 3.0); } + + /* Step O */ + done = 0; + if(source[sp] == 13) { edi_count += (2.0 / 3.0); done = 1; } + if(source[sp] == '*') { edi_count += (2.0 / 3.0); done = 1; } + if(source[sp] == '>') { edi_count += (2.0 / 3.0); done = 1; } + if(source[sp] == ' ') { edi_count += (2.0 / 3.0); done = 1; } + if((source[sp] >= '0') && (source[sp] <= '9')) { edi_count += (2.0 / 3.0); done = 1; } + if((source[sp] >= 'A') && (source[sp] <= 'Z')) { edi_count += (2.0 / 3.0); done = 1; } + if(source[sp] > 127) { + edi_count += (13.0 / 3.0); + } else { + if(done == 0) { + edi_count += (10.0 / 3.0); + } + } + + /* Step P */ + if(gs1 && (source[sp] == '[')) { byte_count += 3.0; } else { byte_count += 1.0; } + + } + + ascii_count = froundup(ascii_count); + c40_count = froundup(c40_count); + text_count = froundup(text_count); + edi_count = froundup(edi_count); + byte_count = froundup(byte_count); + best_scheme = C1_ASCII; + + if(sp == sourcelen) { + /* Step K */ + best_count = edi_count; + + if(text_count <= best_count) { + best_count = text_count; + best_scheme = C1_TEXT; + } + + if(c40_count <= best_count) { + best_count = c40_count; + best_scheme = C1_C40; + } + + if(ascii_count <= best_count) { + best_count = ascii_count; + best_scheme = C1_ASCII; + } + + if(byte_count <= best_count) { + best_count = byte_count; + best_scheme = C1_BYTE; + } + } else { + /* Step Q */ + + if(((edi_count + 1.0 <= ascii_count) && (edi_count + 1.0 <= c40_count)) && + ((edi_count + 1.0 <= byte_count) && (edi_count + 1.0 <= text_count))) { + best_scheme = C1_EDI; + } + + if((c40_count + 1.0 <= ascii_count) && (c40_count + 1.0 <= text_count)) { + + if(c40_count < edi_count) { + best_scheme = C1_C40; + } else { + done = 0; + if(c40_count == edi_count) { + if(dq4bi(source, sourcelen, position)) { + best_scheme = C1_EDI; + } else { + best_scheme = C1_C40; + } + } + } + } + + if(((text_count + 1.0 <= ascii_count) && (text_count + 1.0 <= c40_count)) && + ((text_count + 1.0 <= byte_count) && (text_count + 1.0 <= edi_count))) { + best_scheme = C1_TEXT; + } + + if(((ascii_count + 1.0 <= byte_count) && (ascii_count + 1.0 <= c40_count)) && + ((ascii_count + 1.0 <= text_count) && (ascii_count + 1.0 <= edi_count))) { + best_scheme = C1_ASCII; + } + + if(((byte_count + 1.0 <= ascii_count) && (byte_count + 1.0 <= c40_count)) && + ((byte_count + 1.0 <= text_count) && (byte_count + 1.0 <= edi_count))) { + best_scheme = C1_BYTE; + } + } + + //printf("\n> scores: ASCII %.2f C40 %.2f TEXT %.2f EDI %.2f BYTE %.2f\n", ascii_count, c40_count, text_count, edi_count, byte_count); + + return best_scheme; +} + +int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int target[]) +{ + int inputlen = ustrlen(source); + int current_mode, next_mode; + int sp, tp, gs1, i, j, latch; + int c40_buffer[6], c40_p; + int text_buffer[6], text_p; + int edi_buffer[6], edi_p; + char decimal_binary[40]; + int byte_start; + + if(symbol->nullchar != 0x00) { + for(i = 0; i < inputlen; i++) { + if(source[i] == symbol->nullchar) { + source[i] = 0x00; + } + } + } + + sp = 0; + tp = 0; + latch = 0; + memset(c40_buffer, 0, 6); + c40_p = 0; + memset(text_buffer, 0, 6); + text_p = 0; + memset(edi_buffer, 0, 6); + edi_p = 0; + strcpy(decimal_binary, ""); + + if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } + if(gs1) { target[tp] = 232; tp++; } /* FNC1 */ + + /* Step A */ + current_mode = C1_ASCII; + next_mode = C1_ASCII; + + do { + if(current_mode != next_mode) { + /* Change mode */ + switch(next_mode) { + case C1_C40: target[tp] = 230; tp++; break; + case C1_TEXT: target[tp] = 239; tp++; break; + case C1_EDI: target[tp] = 238; tp++; break; + case C1_BYTE: target[tp] = 231; tp++; break; + } + } + + if((current_mode != C1_BYTE) && (next_mode == C1_BYTE)) { byte_start = tp; } + current_mode = next_mode; + + if(current_mode == C1_ASCII) { /* Step B - ASCII encodation */ + next_mode = C1_ASCII; + + if((inputlen - sp) >= 21) { /* Step B1 */ + j = 0; + + for(i = 0; i < 21; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 21) { + next_mode = C1_DECIMAL; + strcpy(decimal_binary, "1111"); + } + } + + if((next_mode == C1_ASCII) && ((inputlen - sp) >= 13)) { /* Step B2 */ + j = 0; + + for(i = 0; i < 13; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 13) { + latch = 0; + for(i = sp + 13; i < inputlen; i++) { + if(!((source[sp + i] >= '0') && (source[sp + i] <= '9'))) { latch = 1; } + } + + if(!(latch)) { + next_mode = C1_DECIMAL; + strcpy(decimal_binary, "1111"); + } + } + } + + if(next_mode == C1_ASCII) { /* Step B3 */ + if(istwodigits(source, sp) && ((sp + 1) != inputlen)) { + target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; + tp++; + sp += 2; + } else { + if((gs1) && (source[sp] == '[')) { + if((inputlen - sp) >= 15) { /* Step B4 */ + j = 0; + + for(i = 0; i < 15; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 15) { + target[tp] = 236; /* FNC1 and change to Decimal */ + tp++; sp++; + next_mode = C1_DECIMAL; + } + } + + if((inputlen - sp) >= 7) { /* Step B5 */ + j = 0; + + for(i = 0; i < 7; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 7) { + latch = 0; + for(i = sp + 7; i < inputlen; i++) { + if(!((source[sp + i] >= '0') && (source[sp + i] <= '9'))) { latch = 1; } + } + + if(!(latch)) { + target[tp] = 236; /* FNC1 and change to Decimal */ + tp++; sp++; + next_mode = C1_DECIMAL; + } + } + } + } + + if(next_mode == C1_ASCII) { + + /* Step B6 */ + next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + + if(next_mode == C1_ASCII) { + if(source[sp] > 127) { + /* Step B7 */ + target[tp] = 235; tp++; /* FNC4 */ + target[tp] = (source[sp] - 128) + 1; tp++; sp++; + } else { + /* Step B8 */ + if((gs1) && (source[sp] == '[')) { + target[tp] = 232; tp++; sp++; /* FNC1 */ + } else { + target[tp] = source[sp] + 1; tp++; sp++; + } + } + } + } + } + } + } + + if(current_mode == C1_C40) { /* Step C - C40 encodation */ + int shift_set, value, done = 0, latch = 0; + + next_mode = C1_C40; + if(c40_p == 0) { + if((inputlen - sp) >= 12) { + j = 0; + + for(i = 0; i < 12; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 12) { + next_mode = C1_ASCII; done = 1; + } + } + + if((inputlen - sp) >= 8) { + j = 0; + + for(i = 0; i < 8; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if((inputlen - sp) == 8) { + latch = 1; + } else { + latch = 1; + for(j = sp + 8; j < inputlen; j++) { + if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; } + } + } + + if ((j == 8) && latch) { + next_mode = C1_ASCII; done = 1; + } + } + + if(!(done)) { + next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + } + } + + if(next_mode != C1_C40) { + target[tp] = 255; tp++; /* Unlatch */ + } else { + if(source[sp] > 127) { + c40_buffer[c40_p] = 1; c40_p++; + c40_buffer[c40_p] = 30; c40_p++; /* Upper Shift */ + shift_set = c40_shift[source[sp] - 128]; + value = c40_value[source[sp] - 128]; + } else { + shift_set = c40_shift[source[sp]]; + value = c40_value[source[sp]]; + } + + if(gs1 && (source[sp] == '[')) { + shift_set = 2; + value = 27; /* FNC1 */ + } + + if(shift_set != 0) { + c40_buffer[c40_p] = shift_set - 1; c40_p++; + } + c40_buffer[c40_p] = value; c40_p++; + + if(c40_p >= 3) { + int iv; + + iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + + c40_buffer[0] = c40_buffer[3]; + c40_buffer[1] = c40_buffer[4]; + c40_buffer[2] = c40_buffer[5]; + c40_buffer[3] = 0; + c40_buffer[4] = 0; + c40_buffer[5] = 0; + c40_p -= 3; + } + sp++; + } + } + + if(current_mode == C1_TEXT) { /* Step D - Text encodation */ + int shift_set, value, done = 0, latch = 0; + + next_mode = C1_TEXT; + if(text_p == 0) { + if((inputlen - sp) >= 12) { + j = 0; + + for(i = 0; i < 12; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 12) { + next_mode = C1_ASCII; done = 1; + } + } + + if((inputlen - sp) >= 8) { + j = 0; + + for(i = 0; i < 8; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if((inputlen - sp) == 8) { + latch = 1; + } else { + latch = 1; + for(j = sp + 8; j < inputlen; j++) { + if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; } + } + } + + if ((j == 8) && latch) { + next_mode = C1_ASCII; done = 1; + } + } + + if(!(done)) { + next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + } + } + + if(next_mode != C1_TEXT) { + target[tp] = 255; tp++; /* Unlatch */ + } else { + if(source[sp] > 127) { + text_buffer[text_p] = 1; text_p++; + text_buffer[text_p] = 30; text_p++; /* Upper Shift */ + shift_set = text_shift[source[sp] - 128]; + value = text_value[source[sp] - 128]; + } else { + shift_set = text_shift[source[sp]]; + value = text_value[source[sp]]; + } + + if(gs1 && (source[sp] == '[')) { + shift_set = 2; + value = 27; /* FNC1 */ + } + + if(shift_set != 0) { + text_buffer[text_p] = shift_set - 1; text_p++; + } + text_buffer[text_p] = value; text_p++; + + if(text_p >= 3) { + int iv; + + iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + + text_buffer[0] = text_buffer[3]; + text_buffer[1] = text_buffer[4]; + text_buffer[2] = text_buffer[5]; + text_buffer[3] = 0; + text_buffer[4] = 0; + text_buffer[5] = 0; + text_p -= 3; + } + sp++; + } + } + + if(current_mode == C1_EDI) { /* Step E - EDI Encodation */ + int value = 0, done = 0, latch = 0; + + next_mode = C1_EDI; + if(edi_p == 0) { + if((inputlen - sp) >= 12) { + j = 0; + + for(i = 0; i < 12; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if (j == 12) { + next_mode = C1_ASCII; done = 1; + } + } + + if((inputlen - sp) >= 8) { + j = 0; + + for(i = 0; i < 8; i++) { + if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } + } + + if((inputlen - sp) == 8) { + latch = 1; + } else { + latch = 1; + for(j = sp + 8; j < inputlen; j++) { + if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; } + } + } + + if ((j == 8) && latch) { + next_mode = C1_ASCII; done = 1; + } + } + + if(!((isedi(source[sp]) && isedi(source[sp + 1])) && isedi(source[sp + 2]))) { + next_mode = C1_ASCII; + } + } + + if(next_mode != C1_EDI) { + target[tp] = 255; tp++; /* Unlatch */ + } else { + if(source[sp] == 13) { value = 0; } + if(source[sp] == '*') { value = 1; } + if(source[sp] == '>') { value = 2; } + if(source[sp] == ' ') { value = 3; } + if((source[sp] >= '0') && (source[sp] <= '9')) { value = source[sp] - '0' + 4; } + if((source[sp] >= 'A') && (source[sp] <= 'Z')) { value = source[sp] - 'A' + 14; } + + edi_buffer[edi_p] = value; edi_p++; + + if(edi_p >= 3) { + int iv; + + iv = (1600 * edi_buffer[0]) + (40 * edi_buffer[1]) + (edi_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + + edi_buffer[0] = edi_buffer[3]; + edi_buffer[1] = edi_buffer[4]; + edi_buffer[2] = edi_buffer[5]; + edi_buffer[3] = 0; + edi_buffer[4] = 0; + edi_buffer[5] = 0; + edi_p -= 3; + } + sp++; + } + } + + if(current_mode == C1_DECIMAL) { /* Step F - Decimal encodation */ + int value, decimal_count, data_left; + + next_mode = C1_DECIMAL; + + data_left = inputlen - sp; + decimal_count = 0; + + if(data_left >= 1) { + if((source[sp] >= '0') && (source[sp] <= '9')) { decimal_count = 1; } + } + if(data_left >= 2) { + if((decimal_count == 1) && ((source[sp + 1] >= '0') && (source[sp + 1] <= '9'))) { decimal_count = 2; } + } + if(data_left >= 3) { + if((decimal_count == 2) && ((source[sp + 2] >= '0') && (source[sp + 2] <= '9'))) { decimal_count = 3; } + } + + if(decimal_count != 3) { + int bits_left_in_byte, target_count; + int sub_target; + /* Finish Decimal mode and go back to ASCII */ + + concat(decimal_binary, "111111"); /* Unlatch */ + + target_count = 3; + if(strlen(decimal_binary) <= 16) { target_count = 2; } + if(strlen(decimal_binary) <= 8) { target_count = 1; } + bits_left_in_byte = (8 * target_count) - strlen(decimal_binary); + if(bits_left_in_byte == 8) { bits_left_in_byte = 0; } + + if(bits_left_in_byte == 2) { + concat(decimal_binary, "01"); + } + + if((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) { + if(decimal_count >= 1) { + int sub_value = ctoi(source[sp]) + 1; + + if(sub_value & 0x08) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(sub_value & 0x04) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(sub_value & 0x02) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(sub_value & 0x01) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + sp++; + } else { + concat(decimal_binary, "1111"); + } + } + + if(bits_left_in_byte == 6) { + concat(decimal_binary, "01"); + } + + /* Binary buffer is full - transfer to target */ + if(target_count >= 1) { + sub_target = 0; + if(decimal_binary[0] == '1') { sub_target += 128; } + if(decimal_binary[1] == '1') { sub_target += 64; } + if(decimal_binary[2] == '1') { sub_target += 32; } + if(decimal_binary[3] == '1') { sub_target += 16; } + if(decimal_binary[4] == '1') { sub_target += 8; } + if(decimal_binary[5] == '1') { sub_target += 4; } + if(decimal_binary[6] == '1') { sub_target += 2; } + if(decimal_binary[7] == '1') { sub_target += 1; } + target[tp] = sub_target; tp++; + } + if(target_count >= 2) { + sub_target = 0; + if(decimal_binary[8] == '1') { sub_target += 128; } + if(decimal_binary[9] == '1') { sub_target += 64; } + if(decimal_binary[10] == '1') { sub_target += 32; } + if(decimal_binary[11] == '1') { sub_target += 16; } + if(decimal_binary[12] == '1') { sub_target += 8; } + if(decimal_binary[13] == '1') { sub_target += 4; } + if(decimal_binary[14] == '1') { sub_target += 2; } + if(decimal_binary[15] == '1') { sub_target += 1; } + target[tp] = sub_target; tp++; + } + if(target_count == 3) { + sub_target = 0; + if(decimal_binary[16] == '1') { sub_target += 128; } + if(decimal_binary[17] == '1') { sub_target += 64; } + if(decimal_binary[18] == '1') { sub_target += 32; } + if(decimal_binary[19] == '1') { sub_target += 16; } + if(decimal_binary[20] == '1') { sub_target += 8; } + if(decimal_binary[21] == '1') { sub_target += 4; } + if(decimal_binary[22] == '1') { sub_target += 2; } + if(decimal_binary[23] == '1') { sub_target += 1; } + target[tp] = sub_target; tp++; + } + + next_mode = C1_ASCII; + } else { + /* There are three digits - convert the value to binary */ + value = (100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1; + + if(value & 0x200) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x100) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x80) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x40) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x20) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x10) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x08) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x04) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x02) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + if(value & 0x01) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); } + + sp+= 3; + } + + if(strlen(decimal_binary) >= 24) { + int target1 = 0, target2 = 0, target3 = 0; + char temp_binary[40]; + + /* Binary buffer is full - transfer to target */ + if(decimal_binary[0] == '1') { target1 += 128; } + if(decimal_binary[1] == '1') { target1 += 64; } + if(decimal_binary[2] == '1') { target1 += 32; } + if(decimal_binary[3] == '1') { target1 += 16; } + if(decimal_binary[4] == '1') { target1 += 8; } + if(decimal_binary[5] == '1') { target1 += 4; } + if(decimal_binary[6] == '1') { target1 += 2; } + if(decimal_binary[7] == '1') { target1 += 1; } + if(decimal_binary[8] == '1') { target2 += 128; } + if(decimal_binary[9] == '1') { target2 += 64; } + if(decimal_binary[10] == '1') { target2 += 32; } + if(decimal_binary[11] == '1') { target2 += 16; } + if(decimal_binary[12] == '1') { target2 += 8; } + if(decimal_binary[13] == '1') { target2 += 4; } + if(decimal_binary[14] == '1') { target2 += 2; } + if(decimal_binary[15] == '1') { target2 += 1; } + if(decimal_binary[16] == '1') { target3 += 128; } + if(decimal_binary[17] == '1') { target3 += 64; } + if(decimal_binary[18] == '1') { target3 += 32; } + if(decimal_binary[19] == '1') { target3 += 16; } + if(decimal_binary[20] == '1') { target3 += 8; } + if(decimal_binary[21] == '1') { target3 += 4; } + if(decimal_binary[22] == '1') { target3 += 2; } + if(decimal_binary[23] == '1') { target3 += 1; } + target[tp] = target1; tp++; + target[tp] = target2; tp++; + target[tp] = target3; tp++; + + strcpy(temp_binary, ""); + if(strlen(decimal_binary) > 24) { + for(i = 0; i <= (strlen(decimal_binary) - 24); i++) { + temp_binary[i] = decimal_binary[i + 24]; + } + strcpy(decimal_binary, temp_binary); + } + } + } + + if(current_mode == C1_BYTE) { + next_mode = C1_BYTE; + + if(gs1 && (source[sp] == '[')) { + next_mode = C1_ASCII; + } else { + if(source[sp] <= 127) { + next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + } + } + + if(next_mode != C1_BYTE) { + /* Insert byte field length */ + if((tp - byte_start) <= 249) { + for(i = tp; i >= byte_start; i--) { + target[i + 1] = target[i]; + } + target[byte_start] = (tp - byte_start); + tp++; + } else { + for(i = tp; i >= byte_start; i--) { + target[i + 2] = target[i]; + } + target[byte_start] = 249 + ((tp - byte_start) / 250); + target[byte_start + 1] = ((tp - byte_start) % 250); + tp += 2; + } + } else { + target[tp] = source[sp]; + tp++; + sp++; + } + } + + if(tp > 1480) { + /* Data is too large for symbol */ + strcpy(symbol->errtxt, "Input data too long"); + return 0; + } + } while (sp < inputlen); + + /* Empty buffers */ + if(c40_p == 2) { + int iv; + + c40_buffer[2] = 1; + iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + target[tp] = 255; tp++; /* Unlatch */ + } + if(c40_p == 1) { + int iv; + + c40_buffer[1] = 1; + c40_buffer[2] = 31; /* Pad */ + iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + target[tp] = 255; tp++; /* Unlatch */ + } + if(text_p == 2) { + int iv; + + text_buffer[2] = 1; + iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + target[tp] = 255; tp++; /* Unlatch */ + } + if(text_p == 1) { + int iv; + + text_buffer[1] = 1; + text_buffer[2] = 31; /* Pad */ + iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1; + target[tp] = iv / 256; tp++; + target[tp] = iv % 256; tp++; + target[tp] = 255; tp++; /* Unlatch */ + } + + if(current_mode == C1_DECIMAL) { + int bits_left_in_byte, target_count; + int sub_target; + /* Finish Decimal mode and go back to ASCII */ + + concat(decimal_binary, "111111"); /* Unlatch */ + + target_count = 3; + if(strlen(decimal_binary) <= 16) { target_count = 2; } + if(strlen(decimal_binary) <= 8) { target_count = 1; } + bits_left_in_byte = (8 * target_count) - strlen(decimal_binary); + if(bits_left_in_byte == 8) { bits_left_in_byte = 0; } + + if(bits_left_in_byte == 2) { + concat(decimal_binary, "01"); + } + + if((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) { + concat(decimal_binary, "1111"); + } + + if(bits_left_in_byte == 6) { + concat(decimal_binary, "01"); + } + + /* Binary buffer is full - transfer to target */ + if(target_count >= 1) { + sub_target = 0; + if(decimal_binary[0] == '1') { sub_target += 128; } + if(decimal_binary[1] == '1') { sub_target += 64; } + if(decimal_binary[2] == '1') { sub_target += 32; } + if(decimal_binary[3] == '1') { sub_target += 16; } + if(decimal_binary[4] == '1') { sub_target += 8; } + if(decimal_binary[5] == '1') { sub_target += 4; } + if(decimal_binary[6] == '1') { sub_target += 2; } + if(decimal_binary[7] == '1') { sub_target += 1; } + target[tp] = sub_target; tp++; + } + if(target_count >= 2) { + sub_target = 0; + if(decimal_binary[8] == '1') { sub_target += 128; } + if(decimal_binary[9] == '1') { sub_target += 64; } + if(decimal_binary[10] == '1') { sub_target += 32; } + if(decimal_binary[11] == '1') { sub_target += 16; } + if(decimal_binary[12] == '1') { sub_target += 8; } + if(decimal_binary[13] == '1') { sub_target += 4; } + if(decimal_binary[14] == '1') { sub_target += 2; } + if(decimal_binary[15] == '1') { sub_target += 1; } + target[tp] = sub_target; tp++; + } + if(target_count == 3) { + sub_target = 0; + if(decimal_binary[16] == '1') { sub_target += 128; } + if(decimal_binary[17] == '1') { sub_target += 64; } + if(decimal_binary[18] == '1') { sub_target += 32; } + if(decimal_binary[19] == '1') { sub_target += 16; } + if(decimal_binary[20] == '1') { sub_target += 8; } + if(decimal_binary[21] == '1') { sub_target += 4; } + if(decimal_binary[22] == '1') { sub_target += 2; } + if(decimal_binary[23] == '1') { sub_target += 1; } + target[tp] = sub_target; tp++; + } + } + + if(current_mode == C1_BYTE) { + /* Insert byte field length */ + if((tp - byte_start) <= 249) { + for(i = tp; i >= byte_start; i--) { + target[i + 1] = target[i]; + } + target[byte_start] = (tp - byte_start); + tp++; + } else { + for(i = tp; i >= byte_start; i--) { + target[i + 2] = target[i]; + } + target[byte_start] = 249 + ((tp - byte_start) / 250); + target[byte_start + 1] = ((tp - byte_start) % 250); + tp += 2; + } + } + + /* Re-check length of data */ + if(tp > 1480) { + /* Data is too large for symbol */ + strcpy(symbol->errtxt, "Input data too long"); + return 0; + } + /* + printf("targets:\n"); + for(i = 0; i < tp; i++) { + printf("[%d]", target[i]); + } + printf("\n"); + */ + return tp; +} + +void block_copy(struct zint_symbol *symbol, char grid[][120], int start_row, int start_col, int height, int width, int row_offset, int col_offset) { + int i, j; + + for(i = start_row; i < (start_row + height); i++) { + for(j = start_col; j < (start_col + width); j++) { + if(grid[i][j] == '1') { + set_module(symbol, i + row_offset, j + col_offset); + } + } + } +} + +int code_one(struct zint_symbol *symbol, unsigned char source[]) +{ + int size = 1, i, j, data_blocks; + unsigned int data[1500], ecc[600]; + unsigned int sub_data[190], sub_ecc[75]; + unsigned int stream[2100]; + int data_length; + char datagrid[136][120]; + int row, col; + + if((symbol->option_2 < 0) || (symbol->option_2 > 8)) { + strcpy(symbol->errtxt, "Invalid symbol size"); + return ERROR_INVALID_OPTION; + } + + for(i = 0; i < 1500; i++) { data[i] = 0; } + data_length = c1_encode(symbol, source, data); + + if(data_length == 0) { + return ERROR_TOO_LONG; + } + + printf("len: %d\n", data_length); + + for(i = 7; i >= 0; i--) { + if(c1_data_length[i] >= data_length) { + size = i + 1; + } + } + + printf("size %d\n", size); + + if(symbol->option_2 > size) { + size = symbol->option_2; + } + + for(i = data_length; i < c1_data_length[size - 1]; i++) { + data[i] = 129; /* Pad */ + } + + /* Calculate error correction data */ + data_length = c1_data_length[size - 1]; + for(i = 0; i < 190; i++) { sub_data[i] = 0; } + for(i = 0; i < 75; i++) { sub_ecc[i] = 0; } + + data_blocks = c1_blocks[size - 1]; + + rs_init_gf(0x12D); + rs_init_code(c1_ecc_blocks[size - 1], 1); + for(i = 0; i < data_blocks; i++) { + for(j = 0; j < c1_data_blocks[size - 1]; j++) { + + sub_data[j] = data[j * data_blocks + i]; + } + rs_encode_long(c1_data_blocks[size - 1], sub_data, sub_ecc); + for(j = 0; j < c1_ecc_blocks[size - 1]; j++) { + ecc[c1_ecc_length[size - 1] - (j * data_blocks + i) - 1] = sub_ecc[j]; + } + } + rs_free(); + + /* "Stream" combines data and error correction data */ + for(i = 0; i < data_length; i++) { + stream[i] = data[i]; + } + for(i = 0; i < c1_ecc_length[size - 1]; i++) { + stream[data_length + i] = ecc[i]; + } + + for(i = 0; i < 136; i++) { + for(j = 0; j < 120; j++) { + datagrid[i][j] = '0'; + } + } + + i = 0; + for(row = 0; row < c1_grid_height[size - 1]; row++) { + for(col = 0; col < c1_grid_width[size - 1]; col++) { + if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; } + if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; } + if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; } + if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; } + if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; } + if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; } + if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; } + if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; } + i++; + } + } + + for(i = 0; i < (c1_grid_height[size - 1] * 2); i++) { + for(j = 0; j < (c1_grid_width[size - 1] * 4); j++) { + printf("%c", datagrid[i][j]); + } + printf("\n"); + } + + for(i = 0; i < c1_ecc_length[size - 1] + data_length; i++) { + printf("%d ",stream[i]); + } + printf("\n"); + + symbol->rows = c1_height[size - 1]; + symbol->width = c1_width[size - 1]; + + switch(size) { + case 1: /* Version A */ + central_finder(symbol, 6, 3, 1); + vert(symbol, 4, 6, 1); + vert(symbol, 12, 5, 0); + set_module(symbol, 5, 12); + spigot(symbol, 0); + spigot(symbol, 15); + block_copy(symbol, datagrid, 0, 0, 5, 4, 0, 0); + block_copy(symbol, datagrid, 0, 4, 5, 12, 0, 2); + block_copy(symbol, datagrid, 5, 0, 5, 12, 6, 0); + block_copy(symbol, datagrid, 5, 12, 5, 4, 6, 2); + break; + case 2: /* Version B */ + central_finder(symbol, 8, 4, 1); + vert(symbol, 4, 8, 1); + vert(symbol, 16, 7, 0); + set_module(symbol, 7, 16); + spigot(symbol, 0); + spigot(symbol, 21); + block_copy(symbol, datagrid, 0, 0, 7, 4, 0, 0); + block_copy(symbol, datagrid, 0, 4, 7, 16, 0, 2); + block_copy(symbol, datagrid, 7, 0, 7, 16, 8, 0); + block_copy(symbol, datagrid, 7, 16, 7, 4, 8, 2); + break; + case 3: /* Version C */ + central_finder(symbol, 11, 4, 2); + vert(symbol, 4, 11, 1); + vert(symbol, 26, 13, 1); + vert(symbol, 4, 10, 0); + vert(symbol, 26, 10, 0); + spigot(symbol, 0); + spigot(symbol, 27); + block_copy(symbol, datagrid, 0, 0, 10, 4, 0, 0); + block_copy(symbol, datagrid, 0, 4, 10, 20, 0, 2); + block_copy(symbol, datagrid, 0, 24, 10, 4, 0, 4); + block_copy(symbol, datagrid, 10, 0, 10, 4, 8, 0); + block_copy(symbol, datagrid, 10, 4, 10, 20, 8, 2); + block_copy(symbol, datagrid, 10, 24, 10, 4, 8, 4); + break; + case 4: /* Version D */ + central_finder(symbol, 16, 5, 1); + vert(symbol, 4, 16, 1); + vert(symbol, 20, 16, 1); + vert(symbol, 36, 16, 1); + vert(symbol, 4, 15, 0); + vert(symbol, 20, 15, 0); + vert(symbol, 36, 15, 0); + spigot(symbol, 0); + spigot(symbol, 12); + spigot(symbol, 27); + spigot(symbol, 39); + block_copy(symbol, datagrid, 0, 0, 15, 4, 0, 0); + block_copy(symbol, datagrid, 0, 4, 15, 14, 0, 2); + block_copy(symbol, datagrid, 0, 18, 15, 14, 0, 4); + block_copy(symbol, datagrid, 0, 32, 15, 4, 0, 6); + block_copy(symbol, datagrid, 15, 0, 15, 4, 10, 0); + block_copy(symbol, datagrid, 15, 4, 15, 14, 10, 2); + block_copy(symbol, datagrid, 15, 18, 15, 14, 10, 4); + block_copy(symbol, datagrid, 15, 32, 15, 4, 10, 6); + break; + case 5: /* Version E */ + central_finder(symbol, 22, 5, 2); + vert(symbol, 4, 22, 1); + vert(symbol, 26, 24, 1); + vert(symbol, 48, 22, 1); + vert(symbol, 4, 21, 0); + vert(symbol, 26, 21, 0); + vert(symbol, 48, 21, 0); + spigot(symbol, 0); + spigot(symbol, 12); + spigot(symbol, 39); + spigot(symbol, 51); + block_copy(symbol, datagrid, 0, 0, 21, 4, 0, 0); + block_copy(symbol, datagrid, 0, 4, 21, 20, 0, 2); + block_copy(symbol, datagrid, 0, 24, 21, 20, 0, 4); + block_copy(symbol, datagrid, 0, 44, 21, 4, 0, 6); + block_copy(symbol, datagrid, 21, 0, 21, 4, 10, 0); + block_copy(symbol, datagrid, 21, 4, 21, 20, 10, 2); + block_copy(symbol, datagrid, 21, 24, 21, 20, 10, 4); + block_copy(symbol, datagrid, 21, 44, 21, 4, 10, 6); + break; + case 6: /* Version F */ + central_finder(symbol, 31, 5, 3); + vert(symbol, 4, 31, 1); + vert(symbol, 26, 35, 1); + vert(symbol, 48, 31, 1); + vert(symbol, 70, 35, 1); + vert(symbol, 4, 30, 0); + vert(symbol, 26, 30, 0); + vert(symbol, 48, 30, 0); + vert(symbol, 70, 30, 0); + spigot(symbol, 0); + spigot(symbol, 12); + spigot(symbol, 24); + spigot(symbol, 45); + spigot(symbol, 57); + spigot(symbol, 69); + block_copy(symbol, datagrid, 0, 0, 30, 4, 0, 0); + block_copy(symbol, datagrid, 0, 4, 30, 20, 0, 2); + block_copy(symbol, datagrid, 0, 24, 30, 20, 0, 4); + block_copy(symbol, datagrid, 0, 44, 30, 20, 0, 6); + block_copy(symbol, datagrid, 0, 64, 30, 4, 0, 8); + block_copy(symbol, datagrid, 30, 0, 30, 4, 10, 0); + block_copy(symbol, datagrid, 30, 4, 30, 20, 10, 2); + block_copy(symbol, datagrid, 30, 24, 30, 20, 10, 4); + block_copy(symbol, datagrid, 30, 44, 30, 20, 10, 6); + block_copy(symbol, datagrid, 30, 64, 30, 4, 10, 8); + break; + case 7: /* Version G */ + central_finder(symbol, 47, 6, 2); + vert(symbol, 6, 47, 1); + vert(symbol, 27, 49, 1); + vert(symbol, 48, 47, 1); + vert(symbol, 69, 49, 1); + vert(symbol, 90, 47, 1); + vert(symbol, 6, 46, 0); + vert(symbol, 27, 46, 0); + vert(symbol, 48, 46, 0); + vert(symbol, 69, 46, 0); + vert(symbol, 90, 46, 0); + spigot(symbol, 0); + spigot(symbol, 12); + spigot(symbol, 24); + spigot(symbol, 36); + spigot(symbol, 67); + spigot(symbol, 79); + spigot(symbol, 91); + spigot(symbol, 103); + block_copy(symbol, datagrid, 0, 0, 46, 6, 0, 0); + block_copy(symbol, datagrid, 0, 6, 46, 19, 0, 2); + block_copy(symbol, datagrid, 0, 25, 46, 19, 0, 4); + block_copy(symbol, datagrid, 0, 44, 46, 19, 0, 6); + block_copy(symbol, datagrid, 0, 63, 46, 19, 0, 8); + block_copy(symbol, datagrid, 0, 82, 46, 6, 0, 10); + block_copy(symbol, datagrid, 46, 0, 46, 6, 12, 0); + block_copy(symbol, datagrid, 46, 6, 46, 19, 12, 2); + block_copy(symbol, datagrid, 46, 25, 46, 19, 12, 4); + block_copy(symbol, datagrid, 46, 44, 46, 19, 12, 6); + block_copy(symbol, datagrid, 46, 63, 46, 19, 12, 8); + block_copy(symbol, datagrid, 46, 82, 46, 6, 12, 10); + break; + case 8: /* Version H */ + central_finder(symbol, 69, 6, 3); + vert(symbol, 6, 69, 1); + vert(symbol, 26, 73, 1); + vert(symbol, 46, 69, 1); + vert(symbol, 66, 73, 1); + vert(symbol, 86, 69, 1); + vert(symbol, 106, 73, 1); + vert(symbol, 126, 69, 1); + vert(symbol, 6, 68, 0); + vert(symbol, 26, 68, 0); + vert(symbol, 46, 68, 0); + vert(symbol, 66, 68, 0); + vert(symbol, 86, 68, 0); + vert(symbol, 106, 68, 0); + vert(symbol, 126, 68, 0); + spigot(symbol, 0); + spigot(symbol, 12); + spigot(symbol, 24); + spigot(symbol, 36); + spigot(symbol, 48); + spigot(symbol, 60); + spigot(symbol, 87); + spigot(symbol, 99); + spigot(symbol, 111); + spigot(symbol, 123); + spigot(symbol, 135); + spigot(symbol, 147); + block_copy(symbol, datagrid, 0, 0, 68, 6, 0, 0); + block_copy(symbol, datagrid, 0, 6, 68, 18, 0, 2); + block_copy(symbol, datagrid, 0, 24, 68, 18, 0, 4); + block_copy(symbol, datagrid, 0, 42, 68, 18, 0, 6); + block_copy(symbol, datagrid, 0, 60, 68, 18, 0, 8); + block_copy(symbol, datagrid, 0, 78, 68, 18, 0, 10); + block_copy(symbol, datagrid, 0, 96, 68, 18, 0, 12); + block_copy(symbol, datagrid, 0, 114, 68, 6, 0, 14); + block_copy(symbol, datagrid, 68, 0, 68, 6, 12, 0); + block_copy(symbol, datagrid, 68, 6, 68, 18, 12, 2); + block_copy(symbol, datagrid, 68, 24, 68, 18, 12, 4); + block_copy(symbol, datagrid, 68, 42, 68, 18, 12, 6); + block_copy(symbol, datagrid, 68, 60, 68, 18, 12, 8); + block_copy(symbol, datagrid, 68, 78, 68, 18, 12, 10); + block_copy(symbol, datagrid, 68, 96, 68, 18, 12, 12); + block_copy(symbol, datagrid, 68, 114, 68, 6, 12, 14); + break; + } + + for(i = 0; i < symbol->rows; i++) { + symbol->row_height[i] = 1; + } + + return 0; +} diff --git a/backend/code1.h b/backend/code1.h new file mode 100644 index 00000000..093de60b --- /dev/null +++ b/backend/code1.h @@ -0,0 +1,61 @@ +/* code1.h - Lookup info for USS Code One */ + +/* + libzint - the open source barcode library + Copyright (C) 2009 Robin Stuart + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +static int c40_shift[] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; + +static int c40_value[] = { + 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, + 3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, + 15,16,17,18,19,20,21,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39, + 22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; + +static int text_shift[] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; + +static int text_value[] = { + 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, + 3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, + 15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26, + 22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; + +static int c1_height[] = { 16, 22, 28, 40, 52, 70, 104, 148 }; +static int c1_width[] = { 18, 22, 32, 42, 54, 76, 98, 134 }; +static int c1_data_length[] = { 10, 19, 44, 91, 182, 370, 732, 1480 }; +static int c1_ecc_length[] = { 10, 16, 26, 44, 70, 140, 280, 560 }; +static int c1_blocks[] = { 1, 1, 1, 1, 1, 2, 4, 8 }; +static int c1_data_blocks[] = { 10, 19, 44, 91, 182, 185, 183, 185 }; +static int c1_ecc_blocks[] = { 10, 16, 26, 44, 70, 70, 70, 70 }; +static int c1_grid_width[] = { 4, 5, 7, 9, 12, 17, 22, 30 }; +static int c1_grid_height[] = { 5, 7, 10, 15, 21, 30, 46, 68 }; + +#define C1_ASCII 1 +#define C1_C40 2 +#define C1_DECIMAL 3 +#define C1_TEXT 4 +#define C1_EDI 5 +#define C1_BYTE 6 \ No newline at end of file diff --git a/backend/common.c b/backend/common.c index 14cd9fbb..9f7e0559 100644 --- a/backend/common.c +++ b/backend/common.c @@ -259,3 +259,24 @@ int roundup(float input) return integer_part; } +int istwodigits(unsigned char source[], int position) +{ + if((source[position] >= '0') && (source[position] <= '9')) { + if((source[position + 1] >= '0') && (source[position + 1] <= '9')) { + return 1; + } + } + + return 0; +} + +float froundup(float input) +{ + float fraction, output = 0.0; + + fraction = input - (int)input; + if(fraction > 0.01) { output = (input - fraction) + 1.0; } else { output = input; } + + return output; +} + diff --git a/backend/common.h b/backend/common.h index c439683e..2e2a228f 100644 --- a/backend/common.h +++ b/backend/common.h @@ -58,6 +58,8 @@ extern int roundup(float input); extern int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord); extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord); extern void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord); +extern int istwodigits(unsigned char source[], int position); +extern float froundup(float input); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/backend/library.c b/backend/library.c index b9539f22..326a3af8 100644 --- a/backend/library.c +++ b/backend/library.c @@ -125,6 +125,7 @@ extern int korea_post(struct zint_symbol *symbol, unsigned char source[]); /* Ko extern int japan_post(struct zint_symbol *symbol, unsigned char source[]); /* Japanese Post */ extern int code_49(struct zint_symbol *symbol, unsigned char source[]); /* Code 49 */ extern int channel_code(struct zint_symbol *symbol, unsigned char source[]); /* Channel Code */ +extern int code_one(struct zint_symbol *symbol, unsigned char source[]); /* Code One */ #ifndef NO_PNG int png_handle(struct zint_symbol *symbol, int rotate_angle); @@ -438,7 +439,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) 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"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } /* Everything from 128 up is Zint-specific */ - if(symbol->symbology >= 141) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology >= 142) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } if(error_number > 4) { error_tag(symbol->errtxt, error_number); @@ -575,6 +576,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed); break; case BARCODE_CODE49: error_number = code_49(symbol, preprocessed); break; case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed); break; + case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed); break; } if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { diff --git a/backend/zint.h b/backend/zint.h index d457b900..03fb5528 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -138,6 +138,7 @@ struct zint_symbol { #define BARCODE_RSS14_OMNI_CC 138 #define BARCODE_RSS_EXPSTACK_CC 139 #define BARCODE_CHANNEL 140 +#define BARCODE_CODEONE 141 #define BARCODE_NO_ASCII 1 #define BARCODE_BIND 2 diff --git a/backend_qt4/backend_qt4.pro b/backend_qt4/backend_qt4.pro index 990172c2..e9b76abf 100644 --- a/backend_qt4/backend_qt4.pro +++ b/backend_qt4/backend_qt4.pro @@ -94,6 +94,7 @@ SOURCES += ../backend/2of5.c \ ../backend/upcean.c \ ../backend/qr.c \ ../backend/dllversion.c \ + ../backend/code1.c \ qzint.cpp VERSION = 2.1.3 diff --git a/backend_qt4/qzint.cpp b/backend_qt4/qzint.cpp index aec7621b..f4fa90a5 100644 --- a/backend_qt4/qzint.cpp +++ b/backend_qt4/qzint.cpp @@ -291,6 +291,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode painter.save(); painter.setClipRect(paintRect,Qt::IntersectClip); + painter.setRenderHint(QPainter::Antialiasing); qreal xtr=paintRect.x(); qreal ytr=paintRect.y(); diff --git a/frontend_qt4/mainwindow.cpp b/frontend_qt4/mainwindow.cpp index 4b7370b0..7e80d007 100644 --- a/frontend_qt4/mainwindow.cpp +++ b/frontend_qt4/mainwindow.cpp @@ -36,6 +36,8 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) "Aztec Code", "Aztec Runes", "Channel Code", + "Codabar", + "Codablock-F", "Code 11", "Code 128", "Code 16k", @@ -49,8 +51,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) "Code 39 Extended", "Code 49", "Code 93", - "Codabar", - "Codablock-F", + "Code One", "Databar", "Databar Expanded", "Databar Expanded Stacked", @@ -103,7 +104,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) bstyle->addItem(metaObject()->enumerator(0).key(i)); bstyle->setItemText(i,bstyle_text[i]); } - bstyle->setCurrentIndex(8); + bstyle->setCurrentIndex(10); change_options(); update_preview(); view->scene()->addItem(&m_bc); diff --git a/frontend_qt4/mainwindow.h b/frontend_qt4/mainwindow.h index 64fdc726..fd7f1177 100644 --- a/frontend_qt4/mainwindow.h +++ b/frontend_qt4/mainwindow.h @@ -45,6 +45,8 @@ public: AZTEC =92, AZRUNE =128, CHANNEL =140, + CODABAR =18, + CODABLOCKF =74, CODE11 =1, CODE128 =20, CODE16K =23, @@ -58,8 +60,7 @@ public: EXCODE39 =9, CODE49 =24, CODE93 =25, - CODABAR =18, - CODABLOCKF =74, + CODE_ONE =141, RSS14 =29, RSS_EXP =31, RSS_EXPSTACK =81,