code reworked

This commit is contained in:
openapc 2012-12-29 19:37:03 +01:00
parent f48d7ab6a6
commit bf2dbe7494
26 changed files with 284 additions and 499 deletions

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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 <string.h> #include <string.h>
@ -27,13 +13,13 @@
#include <malloc.h> #include <malloc.h>
#endif #endif
static char *C25MatrixTable[10] = {"113311", "311131", "131131", "331111", "113131", "313111", static const char *C25MatrixTable[10] = {"113311", "311131", "131131", "331111", "113131", "313111",
"133111", "111331", "311311", "131311"}; "133111", "111331", "311311", "131311"};
static char *C25IndustTable[10] = {"1111313111", "3111111131", "1131111131", "3131111111", "1111311131", static const char *C25IndustTable[10] = {"1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"}; "3111311111", "1131311111", "1111113131", "3111113111", "1131113111"};
static char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133", static const char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
"31131", "13131"}; "31131", "13131"};
static inline char check_digit(unsigned int count) static inline char check_digit(unsigned int count)
@ -48,7 +34,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/ char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
error_number = 0; error_number = 0;
if(length > 80) { if(length > 80) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -58,7 +44,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
/* start character */ /* start character */
strcpy(dest, "411111"); strcpy(dest, "411111");
@ -68,7 +54,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l
/* Stop character */ /* Stop character */
concat (dest, "41111"); concat (dest, "41111");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
return error_number; return error_number;
@ -81,7 +67,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
char dest[512]; /* 6 + 40 * 10 + 6 + 1 */ char dest[512]; /* 6 + 40 * 10 + 6 + 1 */
error_number = 0; error_number = 0;
if(length > 45) { if(length > 45) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -91,7 +77,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
strcpy(symbol->errtxt, "Invalid character in data"); strcpy(symbol->errtxt, "Invalid character in data");
return error_number; return error_number;
} }
/* start character */ /* start character */
strcpy(dest, "313111"); strcpy(dest, "313111");
@ -101,7 +87,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
/* Stop character */ /* Stop character */
concat (dest, "31113"); concat (dest, "31113");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
return error_number; return error_number;
@ -111,9 +97,9 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int len
{ /* Code 2 of 5 IATA */ { /* Code 2 of 5 IATA */
int i, error_number; int i, error_number;
char dest[512]; /* 4 + 45 * 10 + 3 + 1 */ char dest[512]; /* 4 + 45 * 10 + 3 + 1 */
error_number = 0; error_number = 0;
if(length > 45) { if(length > 45) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -123,17 +109,17 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int len
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
/* start */ /* start */
strcpy(dest, "1111"); strcpy(dest, "1111");
for(i = 0; i < length; i++) { for(i = 0; i < length; i++) {
lookup(NEON, C25IndustTable, source[i], dest); lookup(NEON, C25IndustTable, source[i], dest);
} }
/* stop */ /* stop */
concat (dest, "311"); concat (dest, "311");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
return error_number; return error_number;
@ -144,7 +130,7 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le
int i, error_number; int i, error_number;
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */ char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
error_number = 0; error_number = 0;
if(length > 80) { if(length > 80) {
@ -166,7 +152,7 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le
/* Stop character */ /* Stop character */
concat (dest, "311"); concat (dest, "311");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
return error_number; return error_number;
@ -184,7 +170,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
#endif #endif
error_number = 0; error_number = 0;
if(length > 89) { if(length > 89) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -194,7 +180,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
ustrcpy(temp, (unsigned char *) ""); ustrcpy(temp, (unsigned char *) "");
/* Input must be an even number of characters for Interlaced 2 of 5 to work: /* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered then add a leading zero */ if an odd number of characters has been entered then add a leading zero */
@ -229,7 +215,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
/* Stop character */ /* Stop character */
concat (dest, "311"); concat (dest, "311");
expand(symbol, dest); expand(symbol, dest);
ustrcpy(symbol->text, temp); ustrcpy(symbol->text, temp);
return error_number; return error_number;
@ -241,16 +227,16 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
error_number = 0; error_number = 0;
count = 0; count = 0;
if(length > 13) { if(length > 13) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if(error_number == ERROR_INVALID_DATA) { if(error_number == ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Invalid character in data"); strcpy(symbol->errtxt, "Invalid character in data");
@ -263,7 +249,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
localstr[i] = '0'; localstr[i] = '0';
} }
strcpy(localstr + zeroes, (char *)source); strcpy(localstr + zeroes, (char *)source);
/* Calculate the check digit - the same method used for EAN-13 */ /* Calculate the check digit - the same method used for EAN-13 */
for (i = 12; i >= 0; i--) { for (i = 12; i >= 0; i--) {

View File

@ -26,7 +26,7 @@ POSTAL:= postal.c auspost.c imail.c
POSTAL_OBJ:= postal.o auspost.o imail.o POSTAL_OBJ:= postal.o auspost.o imail.o
TWODIM:= code16k.c dmatrix.c pdf417.c qr.c maxicode.c composite.c aztec.c code49.c code1.c gridmtx.c TWODIM:= code16k.c dmatrix.c pdf417.c qr.c maxicode.c composite.c aztec.c code49.c code1.c gridmtx.c
TWODIM_OBJ:= code16k.o dmatrix.o pdf417.o qr.o maxicode.o composite.o aztec.o code49.o code1.o gridmtx.o TWODIM_OBJ:= code16k.o dmatrix.o pdf417.o qr.o maxicode.o composite.o aztec.o code49.o code1.o gridmtx.o
LIBS:= `libpng12-config --I_opts --L_opts --ldflags` -lz -lm LIBS:= -lz -lm -lpng
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 reedsol.c pdf417.c maxicode.c rss.c common.c render.c png.c library.c ps.c qr.c large.c composite.c aztec.c gs1.c svg.c code49.c code1.c gridmtx.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 reedsol.c pdf417.c maxicode.c rss.c common.c render.c png.c library.c ps.c qr.c large.c composite.c aztec.c gs1.c svg.c code49.c code1.c gridmtx.c
$(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(ONEDIM) $(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(ONEDIM)

View File

@ -3,34 +3,20 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
#define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" #define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
static char *AusNTable[10] = {"00", "01", "02", "10", "11", "12", "20", "21", "22", "30"}; static const char *AusNTable[10] = {"00", "01", "02", "10", "11", "12", "20", "21", "22", "30"};
static char *AusCTable[64] = {"222", "300", "301", "302", "310", "311", "312", "320", "321", "322", static const char *AusCTable[64] = {"222", "300", "301", "302", "310", "311", "312", "320", "321", "322",
"000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110", "000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110",
"111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221", "111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221",
"023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203", "023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203",
"213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333", "213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333",
"003", "013"}; "003", "013"};
static char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011", "012", "013", "020", "021", static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011", "012", "013", "020", "021",
"022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112", "022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112",
"113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203", "113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203",
"210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300", "210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300",
@ -96,12 +82,12 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
unsigned int loopey, reader, h; unsigned int loopey, reader, h;
char data_pattern[200]; char data_pattern[200];
char fcc[3], dpid[10]; char fcc[3] = {0, 0}, dpid[10];
char localstr[30]; char localstr[30];
error_number = 0; error_number = 0;
strcpy(localstr, ""); strcpy(localstr, "");
/* Do all of the length checking first to avoid stack smashing */ /* Do all of the length checking first to avoid stack smashing */
if(symbol->symbology == BARCODE_AUSPOST) { if(symbol->symbology == BARCODE_AUSPOST) {
/* Format control code (FCC) */ /* Format control code (FCC) */
@ -134,7 +120,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
return error_number; return error_number;
} }
} else { } else {
if(length > 8) { if (length > 8) {
strcpy(symbol->errtxt, "Auspost input is too long"); strcpy(symbol->errtxt, "Auspost input is too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
} }
@ -143,7 +129,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
case BARCODE_AUSROUTE: strcpy(fcc, "87"); break; case BARCODE_AUSROUTE: strcpy(fcc, "87"); break;
case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break; case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break;
} }
/* Add leading zeros as required */ /* Add leading zeros as required */
zeroes = 8 - length; zeroes = 8 - length;
memset(localstr, '0', zeroes); memset(localstr, '0', zeroes);
@ -157,7 +143,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
/* Verifiy that the first 8 characters are numbers */ /* Verifiy that the first 8 characters are numbers */
memcpy(dpid, localstr, 8); memcpy(dpid, localstr, 8);
dpid[8] = '\0'; dpid[8] = '\0';
@ -201,14 +187,15 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Filler bar */ /* Filler bar */
h = strlen(data_pattern); h = strlen(data_pattern);
if(h == 22) { switch (h)
concat(data_pattern, "3"); {
} case 22:
else if(h == 37) { case 37:
concat(data_pattern, "3"); case 52:
} concat(data_pattern, "3");
else if(h == 52) { break;
concat(data_pattern, "3"); default:
break;
} }
/* Reed Solomon error correction */ /* Reed Solomon error correction */
@ -216,7 +203,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Stop character */ /* Stop character */
concat(data_pattern, "13"); concat(data_pattern, "13");
/* Turn the symbol into a bar pattern ready for plotting */ /* Turn the symbol into a bar pattern ready for plotting */
writer = 0; writer = 0;
h = strlen(data_pattern); h = strlen(data_pattern);

View File

@ -29,15 +29,20 @@
#include "aztec.h" #include "aztec.h"
#include "reedsol.h" #include "reedsol.h"
/**
* Shorten the string by one character
*/
void mapshorten(int *charmap, int *typemap, int start, int length) void mapshorten(int *charmap, int *typemap, int start, int length)
{ /* Shorten the string by one character */ {
memmove(charmap + start + 1 , charmap + start + 2, (length - 1) * sizeof(int)); memmove(charmap + start + 1 , charmap + start + 2, (length - 1) * sizeof(int));
memmove(typemap + start + 1 , typemap + start + 2, (length - 1) * sizeof(int)); memmove(typemap + start + 1 , typemap + start + 2, (length - 1) * sizeof(int));
} }
/**
* Insert a character into the middle of a string at position posn
*/
void insert(char binary_string[], int posn, char newbit) void insert(char binary_string[], int posn, char newbit)
{ /* Insert a character into the middle of a string at position posn */ {
int i, end; int i, end;
end = strlen(binary_string); end = strlen(binary_string);
@ -47,8 +52,11 @@ void insert(char binary_string[], int posn, char newbit)
binary_string[posn] = newbit; binary_string[posn] = newbit;
} }
/**
* Encode input data into a binary string
*/
int aztec_text_process(unsigned char source[], const unsigned int src_len, char binary_string[], int gs1) int aztec_text_process(unsigned char source[], const unsigned int src_len, char binary_string[], int gs1)
{ /* Encode input data into a binary string */ {
int i, j, k, bytes; int i, j, k, bytes;
int curtable, newtable, lasttable, chartype, maplength, blocks, debug; int curtable, newtable, lasttable, chartype, maplength, blocks, debug;
#ifndef _MSC_VER #ifndef _MSC_VER

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
#define UPPER 1 #define UPPER 1
@ -26,7 +12,7 @@
#define DIGIT 16 #define DIGIT 16
#define BINARY 32 #define BINARY 32
static int AztecMap[] = { /* 151 x 151 data grid */ static const int AztecMap[] = { /* 151 x 151 data grid */
19969,19968,18851,18853,18855,18857,18859,18861,18863,18865,18867,0,18869,18871,18873,18875,18877,18879,18881,18883,18885,18887,18889,18891,18893,18895,18897,0,18899,18901,18903,18905,18907,18909,18911,18913,18915,18917,18919,18921,18923,18925,18927,0,18929,18931,18933,18935,18937,18939,18941,18943,18945,18947,18949,18951,18953,18955,18957,0,18959,18961,18963,18965,18967,18969,18971,18973,18975,18977,18979,18981,18983,18985,18987,0,18989,18991,18993,18995,18997,18999,19001,19003,19005,19007,19009,19011,19013,19015,19017,0,19019,19021,19023,19025,19027,19029,19031,19033,19035,19037,19039,19041,19043,19045,19047,0,19049,19051,19053,19055,19057,19059,19061,19063,19065,19067,19069,19071,19073,19075,19077,0,19079,19081,19083,19085,19087,19089,19091,19093,19095,19097,19099,19101,19103,19105,19107,0,19109,19111,19113,19115,19117,19119,19121,19123,19125,19127,19129, 19969,19968,18851,18853,18855,18857,18859,18861,18863,18865,18867,0,18869,18871,18873,18875,18877,18879,18881,18883,18885,18887,18889,18891,18893,18895,18897,0,18899,18901,18903,18905,18907,18909,18911,18913,18915,18917,18919,18921,18923,18925,18927,0,18929,18931,18933,18935,18937,18939,18941,18943,18945,18947,18949,18951,18953,18955,18957,0,18959,18961,18963,18965,18967,18969,18971,18973,18975,18977,18979,18981,18983,18985,18987,0,18989,18991,18993,18995,18997,18999,19001,19003,19005,19007,19009,19011,19013,19015,19017,0,19019,19021,19023,19025,19027,19029,19031,19033,19035,19037,19039,19041,19043,19045,19047,0,19049,19051,19053,19055,19057,19059,19061,19063,19065,19067,19069,19071,19073,19075,19077,0,19079,19081,19083,19085,19087,19089,19091,19093,19095,19097,19099,19101,19103,19105,19107,0,19109,19111,19113,19115,19117,19119,19121,19123,19125,19127,19129,
19967,19966,18850,18852,18854,18856,18858,18860,18862,18864,18866,1,18868,18870,18872,18874,18876,18878,18880,18882,18884,18886,18888,18890,18892,18894,18896,1,18898,18900,18902,18904,18906,18908,18910,18912,18914,18916,18918,18920,18922,18924,18926,1,18928,18930,18932,18934,18936,18938,18940,18942,18944,18946,18948,18950,18952,18954,18956,1,18958,18960,18962,18964,18966,18968,18970,18972,18974,18976,18978,18980,18982,18984,18986,1,18988,18990,18992,18994,18996,18998,19000,19002,19004,19006,19008,19010,19012,19014,19016,1,19018,19020,19022,19024,19026,19028,19030,19032,19034,19036,19038,19040,19042,19044,19046,1,19048,19050,19052,19054,19056,19058,19060,19062,19064,19066,19068,19070,19072,19074,19076,1,19078,19080,19082,19084,19086,19088,19090,19092,19094,19096,19098,19100,19102,19104,19106,1,19108,19110,19112,19114,19116,19118,19120,19122,19124,19126,19128, 19967,19966,18850,18852,18854,18856,18858,18860,18862,18864,18866,1,18868,18870,18872,18874,18876,18878,18880,18882,18884,18886,18888,18890,18892,18894,18896,1,18898,18900,18902,18904,18906,18908,18910,18912,18914,18916,18918,18920,18922,18924,18926,1,18928,18930,18932,18934,18936,18938,18940,18942,18944,18946,18948,18950,18952,18954,18956,1,18958,18960,18962,18964,18966,18968,18970,18972,18974,18976,18978,18980,18982,18984,18986,1,18988,18990,18992,18994,18996,18998,19000,19002,19004,19006,19008,19010,19012,19014,19016,1,19018,19020,19022,19024,19026,19028,19030,19032,19034,19036,19038,19040,19042,19044,19046,1,19048,19050,19052,19054,19056,19058,19060,19062,19064,19066,19068,19070,19072,19074,19076,1,19078,19080,19082,19084,19086,19088,19090,19092,19094,19096,19098,19100,19102,19104,19106,1,19108,19110,19112,19114,19116,19118,19120,19122,19124,19126,19128,
19965,19964,18849,18848,17763,17765,17767,17769,17771,17773,17775,0,17777,17779,17781,17783,17785,17787,17789,17791,17793,17795,17797,17799,17801,17803,17805,0,17807,17809,17811,17813,17815,17817,17819,17821,17823,17825,17827,17829,17831,17833,17835,0,17837,17839,17841,17843,17845,17847,17849,17851,17853,17855,17857,17859,17861,17863,17865,0,17867,17869,17871,17873,17875,17877,17879,17881,17883,17885,17887,17889,17891,17893,17895,0,17897,17899,17901,17903,17905,17907,17909,17911,17913,17915,17917,17919,17921,17923,17925,0,17927,17929,17931,17933,17935,17937,17939,17941,17943,17945,17947,17949,17951,17953,17955,0,17957,17959,17961,17963,17965,17967,17969,17971,17973,17975,17977,17979,17981,17983,17985,0,17987,17989,17991,17993,17995,17997,17999,18001,18003,18005,18007,18009,18011,18013,18015,0,18017,18019,18021,18023,18025,18027,18029,18031,18033,19130,19131, 19965,19964,18849,18848,17763,17765,17767,17769,17771,17773,17775,0,17777,17779,17781,17783,17785,17787,17789,17791,17793,17795,17797,17799,17801,17803,17805,0,17807,17809,17811,17813,17815,17817,17819,17821,17823,17825,17827,17829,17831,17833,17835,0,17837,17839,17841,17843,17845,17847,17849,17851,17853,17855,17857,17859,17861,17863,17865,0,17867,17869,17871,17873,17875,17877,17879,17881,17883,17885,17887,17889,17891,17893,17895,0,17897,17899,17901,17903,17905,17907,17909,17911,17913,17915,17917,17919,17921,17923,17925,0,17927,17929,17931,17933,17935,17937,17939,17941,17943,17945,17947,17949,17951,17953,17955,0,17957,17959,17961,17963,17965,17967,17969,17971,17973,17975,17977,17979,17981,17983,17985,0,17987,17989,17991,17993,17995,17997,17999,18001,18003,18005,18007,18009,18011,18013,18015,0,18017,18019,18021,18023,18025,18027,18029,18031,18033,19130,19131,
@ -180,7 +166,7 @@ static int AztecMap[] = { /* 151 x 151 data grid */
19689,19687,19685,19683,19681,19679,19677,19675,19673,19671,19669,0,19667,19665,19663,19661,19659,19657,19655,19653,19651,19649,19647,19645,19643,19641,19639,0,19637,19635,19633,19631,19629,19627,19625,19623,19621,19619,19617,19615,19613,19611,19609,0,19607,19605,19603,19601,19599,19597,19595,19593,19591,19589,19587,19585,19583,19581,19579,0,19577,19575,19573,19571,19569,19567,19565,19563,19561,19559,19557,19555,19553,19551,19549,0,19547,19545,19543,19541,19539,19537,19535,19533,19531,19529,19527,19525,19523,19521,19519,0,19517,19515,19513,19511,19509,19507,19505,19503,19501,19499,19497,19495,19493,19491,19489,0,19487,19485,19483,19481,19479,19477,19475,19473,19471,19469,19467,19465,19463,19461,19459,0,19457,19455,19453,19451,19449,19447,19445,19443,19441,19439,19437,19435,19433,19431,19429,0,19427,19425,19423,19421,19419,19417,19415,19413,19411,19408,19409 19689,19687,19685,19683,19681,19679,19677,19675,19673,19671,19669,0,19667,19665,19663,19661,19659,19657,19655,19653,19651,19649,19647,19645,19643,19641,19639,0,19637,19635,19633,19631,19629,19627,19625,19623,19621,19619,19617,19615,19613,19611,19609,0,19607,19605,19603,19601,19599,19597,19595,19593,19591,19589,19587,19585,19583,19581,19579,0,19577,19575,19573,19571,19569,19567,19565,19563,19561,19559,19557,19555,19553,19551,19549,0,19547,19545,19543,19541,19539,19537,19535,19533,19531,19529,19527,19525,19523,19521,19519,0,19517,19515,19513,19511,19509,19507,19505,19503,19501,19499,19497,19495,19493,19491,19489,0,19487,19485,19483,19481,19479,19477,19475,19473,19471,19469,19467,19465,19463,19461,19459,0,19457,19455,19453,19451,19449,19447,19445,19443,19441,19439,19437,19435,19433,19431,19429,0,19427,19425,19423,19421,19419,19417,19415,19413,19411,19408,19409
}; };
static int CompactAztecMap[] = { /* 27 x 27 data grid */ static const int CompactAztecMap[] = { /* 27 x 27 data grid */
609,608,411,413,415,417,419,421,423,425,427,429,431,433,435,437,439,441,443,445,447,449,451,453,455,457,459, 609,608,411,413,415,417,419,421,423,425,427,429,431,433,435,437,439,441,443,445,447,449,451,453,455,457,459,
607,606,410,412,414,416,418,420,422,424,426,428,430,432,434,436,438,440,442,444,446,448,450,452,454,456,458, 607,606,410,412,414,416,418,420,422,424,426,428,430,432,434,436,438,440,442,444,446,448,450,452,454,456,458,
605,604,409,408,243,245,247,249,251,253,255,257,259,261,263,265,267,269,271,273,275,277,279,281,283,460,461, 605,604,409,408,243,245,247,249,251,253,255,257,259,261,263,265,267,269,271,273,275,277,279,281,283,460,461,
@ -210,7 +196,7 @@ static int CompactAztecMap[] = { /* 27 x 27 data grid */
559,557,555,553,551,549,547,545,543,541,539,537,535,533,531,529,527,525,523,521,519,517,515,513,511,508,509 559,557,555,553,551,549,547,545,543,541,539,537,535,533,531,529,527,525,523,521,519,517,515,513,511,508,509
}; };
int AztecCodeSet[128] = { /* From Table 2 */ const int AztecCodeSet[128] = { /* From Table 2 */
32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8, 32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8,
@ -220,7 +206,7 @@ int AztecCodeSet[128] = { /* From Table 2 */
2, 2, 2, 8, 4, 8, 4, 4 2, 2, 2, 8, 4, 8, 4, 4
}; };
int AztecSymbolChar[128] = { /* From Table 2 */ const int AztecSymbolChar[128] = { /* From Table 2 */
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22, 13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22,
@ -236,56 +222,56 @@ int AztecSymbolChar[128] = { /* From Table 2 */
302: Full Stop (ASCII 46) 302: Full Stop (ASCII 46)
*/ */
static char *hexbit[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", static const char *hexbit[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
"01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101",
"10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111" "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
}; };
static char *pentbit[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", static const char *pentbit[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",
"1010", "1011", "1100", "1101", "1110", "1111" "1010", "1011", "1100", "1101", "1110", "1111"
}; };
static char *tribit[8] = {"000", "001", "010", "011", "100", "101", "110", "111"}; static const char *tribit[8] = {"000", "001", "010", "011", "100", "101", "110", "111"};
static int AztecSizes[32] = { /* Codewords per symbol */ static const int AztecSizes[32] = { /* Codewords per symbol */
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664 864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
}; };
static int AztecCompactSizes[4] = { 17, 40, 51, 76 }; static const int AztecCompactSizes[4] = { 17, 40, 51, 76 };
static int Aztec10DataSizes[32] = { /* Data bits per symbol maximum with 10% error correction */ static const int Aztec10DataSizes[32] = { /* Data bits per symbol maximum with 10% error correction */
96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730, 96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730,
5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076, 5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076,
15000, 15948, 16920, 17940 15000, 15948, 16920, 17940
}; };
static int Aztec23DataSizes[32] = { /* Data bits per symbol maximum with 23% error correction */ static const int Aztec23DataSizes[32] = { /* Data bits per symbol maximum with 23% error correction */
84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040, 84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040,
4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036, 4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036,
12828, 13644, 14472, 15348 12828, 13644, 14472, 15348
}; };
static int Aztec36DataSizes[32] = { /* Data bits per symbol maximum with 36% error correction */ static const int Aztec36DataSizes[32] = { /* Data bits per symbol maximum with 36% error correction */
66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350, 66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350,
3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656, 3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656,
11340, 12024, 12744 11340, 12024, 12744
}; };
static int Aztec50DataSizes[32] = { /* Data bits per symbol maximum with 50% error correction */ static const int Aztec50DataSizes[32] = { /* Data bits per symbol maximum with 50% error correction */
48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610, 48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610,
2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316, 2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316,
8844, 9384, 9948 8844, 9384, 9948
}; };
static int AztecCompact10DataSizes [4] = { 78, 198, 336, 520 }; static const int AztecCompact10DataSizes [4] = { 78, 198, 336, 520 };
static int AztecCompact23DataSizes [4] = { 66, 168, 288, 440 }; static const int AztecCompact23DataSizes [4] = { 66, 168, 288, 440 };
static int AztecCompact36DataSizes [4] = { 48, 138, 232, 360 }; static const int AztecCompact36DataSizes [4] = { 48, 138, 232, 360 };
static int AztecCompact50DataSizes [4] = { 36, 102, 176, 280 }; static const int AztecCompact50DataSizes [4] = { 36, 102, 176, 280 };
static int AztecOffset[32] = { static const int AztecOffset[32] = {
66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21, 66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21,
19, 17, 15, 13, 10, 8, 6, 4, 2, 0 19, 17, 15, 13, 10, 8, 6, 4, 2, 0
}; };
static int AztecCompactOffset[4] = { 6, 4, 2, 0 }; static const int AztecCompactOffset[4] = { 6, 4, 2, 0 };

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
/* In version 0.5 this file was 1,553 lines long! */ /* In version 0.5 this file was 1,553 lines long! */
@ -29,15 +15,15 @@
#define SODIUM "0123456789-" #define SODIUM "0123456789-"
#define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd" #define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
static char *C11Table[11] = {"111121", "211121", "121121", "221111", "112121", "212111", "122111", static const char *C11Table[11] = {"111121", "211121", "121121", "221111", "112121", "212111", "122111",
"111221", "211211", "211111", "112111"}; "111221", "211211", "211111", "112111"};
/* Code 39 tables checked against ISO/IEC 16388:2007 */ /* Code 39 tables checked against ISO/IEC 16388:2007 */
/* Incorporates Table A1 */ /* Incorporates Table A1 */
static char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111111", "1112211121", static const char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
"2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121", "2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121",
"1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121", "1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121",
"2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211", "2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211",
@ -47,7 +33,7 @@ static char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111
"1211121211", "1112121211"}; "1211121211", "1112121211"};
/* Code 39 character assignments (Table 1) */ /* Code 39 character assignments (Table 1) */
static char *EC39Ctrl[128] = {"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K", static const char *EC39Ctrl[128] = {"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K",
"$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z", "$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z",
"%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J", "%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J",
"/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F", "/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F",
@ -57,7 +43,7 @@ static char *EC39Ctrl[128] = {"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$
"+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"}; "+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"};
/* Encoding the full ASCII character set in Code 39 (Table A2) */ /* Encoding the full ASCII character set in Code 39 (Table A2) */
static char *C93Ctrl[128] = {"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK", static const char *C93Ctrl[128] = {"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK",
"aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ", "aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ",
"bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "cD", "cE", "cF", "cG", "cH", "cI", "cJ", "bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "cD", "cE", "cF", "cG", "cH", "cI", "cJ",
"cK", "cL", "cM", "cN", "cO", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF", "cK", "cL", "cM", "cN", "cO", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF",
@ -66,7 +52,7 @@ static char *C93Ctrl[128] = {"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH
"bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO", "bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO",
"dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"}; "dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"};
static char *C93Table[47] = {"131112", "111213", "111312", "111411", "121113", "121212", "121311", static const char *C93Table[47] = {"131112", "111213", "111312", "111411", "121113", "121212", "121311",
"111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111", "111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111",
"112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122", "112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122",
"131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221", "131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221",
@ -82,7 +68,7 @@ char pattern[30];
/* Function Prototypes */ /* Function Prototypes */
void NextS(int Chan, int i, int MaxS, int MaxB); void NextS(int Chan, int i, int MaxS, int MaxB);
void NextB(int Chan, int i, int MaxB, int MaxS); void NextB(int Chan, int i, int MaxB, int MaxS);
/* *********************** CODE 11 ******************** */ /* *********************** CODE 11 ******************** */
int code_11(struct zint_symbol *symbol, unsigned char source[], int length) int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
@ -93,7 +79,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
int weight[128], error_number; int weight[128], error_number;
char dest[1024]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/ char dest[1024]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/
char checkstr[3]; char checkstr[3];
error_number = 0; error_number = 0;
if(length > 121) { if(length > 121) {
@ -153,7 +139,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
checkstr[2] = '\0'; checkstr[2] = '\0';
lookup(SODIUM, C11Table, checkstr[0], dest); lookup(SODIUM, C11Table, checkstr[0], dest);
lookup(SODIUM, C11Table, checkstr[1], dest); lookup(SODIUM, C11Table, checkstr[1], dest);
/* Stop character */ /* Stop character */
concat (dest, "11221"); concat (dest, "11221");
@ -172,14 +158,14 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
int error_number; int error_number;
char dest[775]; char dest[775];
char localstr[2] = { 0 }; char localstr[2] = { 0 };
error_number = 0; error_number = 0;
counter = 0; counter = 0;
if((symbol->option_2 < 0) || (symbol->option_2 > 1)) { if((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
symbol->option_2 = 0; symbol->option_2 = 0;
} }
if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) { if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -201,9 +187,9 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
lookup(SILVER, C39Table, source[i], dest); lookup(SILVER, C39Table, source[i], dest);
counter += posn(SILVER, source[i]); counter += posn(SILVER, source[i]);
} }
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) { if((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) {
counter = counter % 43; counter = counter % 43;
if(counter < 10) { if(counter < 10) {
check_digit = itoc(counter); check_digit = itoc(counter);
@ -224,19 +210,19 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
lookup(SILVER, C39Table, check_digit, dest); lookup(SILVER, C39Table, check_digit, dest);
/* Display a space check digit as _, otherwise it looks like an error */ /* Display a space check digit as _, otherwise it looks like an error */
if(check_digit == ' ') { if(check_digit == ' ') {
check_digit = '_'; check_digit = '_';
} }
localstr[0] = check_digit; localstr[0] = check_digit;
localstr[1] = '\0'; localstr[1] = '\0';
} }
/* Stop character */ /* Stop character */
concat (dest, "121121211"); concat (dest, "121121211");
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) { if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
/* LOGMARS uses wider 'wide' bars than normal Code 39 */ /* LOGMARS uses wider 'wide' bars than normal Code 39 */
counter = strlen(dest); counter = strlen(dest);
@ -246,9 +232,9 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
} }
expand(symbol, dest); expand(symbol, dest);
if(symbol->symbology == BARCODE_CODE39) { if(symbol->symbology == BARCODE_CODE39) {
ustrcpy(symbol->text, (unsigned char*)"*"); ustrcpy(symbol->text, (unsigned char*)"*");
uconcat(symbol->text, source); uconcat(symbol->text, source);
@ -263,11 +249,11 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Pharmazentral Nummer (PZN) */ { /* Pharmazentral Nummer (PZN) */
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count, check_digit; unsigned int count, check_digit;
char localstr[10]; char localstr[10];
error_number = 0; error_number = 0;
count = 0; count = 0;
@ -280,17 +266,17 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
localstr[0] = '-'; localstr[0] = '-';
zeroes = 6 - length + 1; zeroes = 6 - length + 1;
for(i = 1; i < zeroes; i++) for(i = 1; i < zeroes; i++)
localstr[i] = '0'; localstr[i] = '0';
strcpy(localstr + zeroes, (char *)source); strcpy(localstr + zeroes, (char *)source);
for (i = 1; i < 7; i++) { for (i = 1; i < 7; i++) {
count += (i + 1) * ctoi(localstr[i]); count += (i + 1) * ctoi(localstr[i]);
} }
check_digit = count%11; check_digit = count%11;
if (check_digit == 11) { check_digit = 0; } if (check_digit == 11) { check_digit = 0; }
localstr[7] = itoc(check_digit); localstr[7] = itoc(check_digit);
@ -321,7 +307,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
} }
/* Creates a buffer string and places control characters into it */ /* Creates a buffer string and places control characters into it */
for(i = 0; i < length; i++) { for(i = 0; i < length; i++) {
if(source[i] > 127) { if(source[i] > 127) {
@ -334,7 +320,7 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
/* Then sends the buffer to the C39 function */ /* Then sends the buffer to the C39 function */
error_number = c39(symbol, buffer, ustrlen(buffer)); error_number = c39(symbol, buffer, ustrlen(buffer));
for(i = 0; i < length; i++) for(i = 0; i < length; i++)
symbol->text[i] = source[i] ? source[i] : ' '; symbol->text[i] = source[i] ? source[i] : ' ';
symbol->text[length] = '\0'; symbol->text[length] = '\0';
@ -356,15 +342,15 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
char buffer[220]; char buffer[220];
char dest[670]; char dest[670];
char set_copy[] = SILVER; char set_copy[] = SILVER;
error_number = 0; error_number = 0;
strcpy(buffer, ""); strcpy(buffer, "");
if(length > 107) { if(length > 107) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
} }
/* Message Content */ /* Message Content */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (source[i] > 127) { if (source[i] > 127) {
@ -375,14 +361,14 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
concat(buffer, C93Ctrl[source[i]]); concat(buffer, C93Ctrl[source[i]]);
symbol->text[i] = source[i] ? source[i] : ' '; symbol->text[i] = source[i] ? source[i] : ' ';
} }
/* Now we can check the true length of the barcode */ /* Now we can check the true length of the barcode */
h = strlen(buffer); h = strlen(buffer);
if (h > 107) { if (h > 107) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
} }
for (i = 0; i < h; i++) { for (i = 0; i < h; i++) {
values[i] = posn(SILVER, buffer[i]); values[i] = posn(SILVER, buffer[i]);
} }
@ -437,7 +423,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
/* Their are used here on the understanding that they form part of the specification /* Their are used here on the understanding that they form part of the specification
for Channel Code and therefore their use is permitted under the following terms for Channel Code and therefore their use is permitted under the following terms
set out in that document: set out in that document:
"It is the intent and understanding of AIM [t]hat the symbology presented in this "It is the intent and understanding of AIM [t]hat the symbology presented in this
specification is entirely in the public domain and free of all use restrictions, specification is entirely in the public domain and free of all use restrictions,
licenses and fees. AIM USA, its memer companies, or individual officers licenses and fees. AIM USA, its memer companies, or individual officers
@ -446,7 +432,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
void CheckCharacter() { void CheckCharacter() {
int i; int i;
char part[3]; char part[3];
if(value == target_value) { if(value == target_value) {
/* Target reached - save the generated pattern */ /* Target reached - save the generated pattern */
strcpy(pattern, "11110"); strcpy(pattern, "11110");
@ -461,7 +447,7 @@ void CheckCharacter() {
void NextB(int Chan, int i, int MaxB, int MaxS) { void NextB(int Chan, int i, int MaxB, int MaxS) {
int b; int b;
b = (S[i]+B[i-1]+S[i-1]+B[i-2] > 4)? 1:2; b = (S[i]+B[i-1]+S[i-1]+B[i-2] > 4)? 1:2;
if (i < Chan+2) { if (i < Chan+2) {
for (; b <= MaxB; b++) { for (; b <= MaxB; b++) {
@ -477,7 +463,7 @@ void NextB(int Chan, int i, int MaxB, int MaxS) {
void NextS(int Chan, int i, int MaxS, int MaxB) { void NextS(int Chan, int i, int MaxS, int MaxB) {
int s; int s;
for (s = (i<Chan+2)? 1: MaxS; s <= MaxS; s++) { for (s = (i<Chan+2)? 1: MaxS; s <= MaxS; s++) {
S[i] = s; S[i] = s;
NextB(Chan,i,MaxB,MaxS+1-s); NextB(Chan,i,MaxB,MaxS+1-s);
@ -486,13 +472,13 @@ void NextS(int Chan, int i, int MaxS, int MaxB) {
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) { int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Channel Code - According to ANSI/AIM BC12-1998 */ /* Channel Code - According to ANSI/AIM BC12-1998 */
int channels, i; int channels, i;
int error_number = 0, range = 0, zeroes; int error_number = 0, range = 0, zeroes;
char hrt[9]; char hrt[9];
target_value = 0; target_value = 0;
if(length > 7) { if(length > 7) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
@ -502,16 +488,16 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(symbol->errtxt, "Invalid characters in data"); strcpy(symbol->errtxt, "Invalid characters in data");
return error_number; return error_number;
} }
if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; } if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; }
if(channels == 0) { channels = length + 1; } if(channels == 0) { channels = length + 1; }
if(channels == 2) { channels = 3; } if(channels == 2) { channels = 3; }
for(i = 0; i < length; i++) { for(i = 0; i < length; i++) {
target_value *= 10; target_value *= 10;
target_value += ctoi((char) source[i]); target_value += ctoi((char) source[i]);
} }
switch(channels) { switch(channels) {
case 3: if(target_value > 26) { range = 1; } break; case 3: if(target_value > 26) { range = 1; } break;
case 4: if(target_value > 292) { range = 1; } break; case 4: if(target_value > 292) { range = 1; } break;
@ -524,19 +510,19 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(symbol->errtxt, "Value out of range"); strcpy(symbol->errtxt, "Value out of range");
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; } for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; }
B[0] = S[1] = B[1] = S[2] = B[2] = 1; B[0] = S[1] = B[1] = S[2] = B[2] = 1;
value = 0; value = 0;
NextS(channels,3,channels,channels); NextS(channels,3,channels,channels);
zeroes = channels - 1 - length; zeroes = channels - 1 - length;
memset(hrt, '0', zeroes); memset(hrt, '0', zeroes);
strcpy(hrt + zeroes, (char *)source); strcpy(hrt + zeroes, (char *)source);
ustrcpy(symbol->text, (unsigned char *)hrt); ustrcpy(symbol->text, (unsigned char *)hrt);
expand(symbol, pattern); expand(symbol, pattern);
return error_number; return error_number;
} }

View File

@ -593,7 +593,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
} }
if(current_mode == C1_EDI) { /* Step E - EDI Encodation */ if(current_mode == C1_EDI) { /* Step E - EDI Encodation */
int value = 0, done = 0, latch = 0; int value = 0,latch = 0;
next_mode = C1_EDI; next_mode = C1_EDI;
if(edi_p == 0) { if(edi_p == 0) {
@ -605,7 +605,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
} }
if (j == 12) { if (j == 12) {
next_mode = C1_ASCII; done = 1; next_mode = C1_ASCII;
} }
} }
@ -626,7 +626,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
} }
if ((j == 8) && latch) { if ((j == 8) && latch) {
next_mode = C1_ASCII; done = 1; next_mode = C1_ASCII;
} }
} }

View File

@ -4,20 +4,6 @@
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
Bugfixes thanks to Christian Sakowski and BogDan Vatra Bugfixes thanks to Christian Sakowski and BogDan Vatra
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 3 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 <stdio.h> #include <stdio.h>
@ -193,9 +179,9 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int
int code_128(struct zint_symbol *symbol, unsigned char source[], int length) int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Handle Code 128 and NVE-18 */ { /* Handle Code 128 and NVE-18 */
int i, j, k, e_count, values[170] = { 0 }, bar_characters, read, total_sum, nve_check; int i, j, k,values[170] = { 0 }, bar_characters, read, total_sum;
int error_number, indexchaine, indexliste, sourcelen, f_state; int error_number, indexchaine, indexliste, sourcelen, f_state;
char set[170] = { ' ' }, fset[170] = { ' ' }, mode, last_set, last_fset, current_set = ' '; char set[170] = { ' ' }, fset[170] = { ' ' }, mode, last_set, current_set = ' ';
float glyph_count; float glyph_count;
char dest[1000]; char dest[1000];
@ -205,9 +191,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
sourcelen = length; sourcelen = length;
j = 0; j = 0;
e_count = 0;
bar_characters = 0; bar_characters = 0;
nve_check = 0;
f_state = 0; f_state = 0;
if(sourcelen > 160) { if(sourcelen > 160) {
@ -346,7 +330,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
/* Now we can calculate how long the barcode is going to be - and stop it from /* Now we can calculate how long the barcode is going to be - and stop it from
being too long */ being too long */
last_set = ' '; last_set = ' ';
last_fset = ' ';
glyph_count = 0.0; glyph_count = 0.0;
for(i = 0; i < sourcelen; i++) { for(i = 0; i < sourcelen; i++) {
if((set[i] == 'a') || (set[i] == 'b')) { if((set[i] == 'a') || (set[i] == 'b')) {
@ -363,16 +346,13 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
} }
if(i == 0) { if(i == 0) {
if(fset[i] == 'F') { if(fset[i] == 'F') {
last_fset = 'F';
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
} }
} else { } else {
if((fset[i] == 'F') && (fset[i - 1] != 'F')) { if((fset[i] == 'F') && (fset[i - 1] != 'F')) {
last_fset = 'F';
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
} }
if((fset[i] != 'F') && (fset[i - 1] == 'F')) { if((fset[i] != 'F') && (fset[i - 1] == 'F')) {
last_fset = ' ';
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
} }
} }
@ -592,7 +572,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Handle EAN-128 (Now known as GS1-128) */ { /* Handle EAN-128 (Now known as GS1-128) */
int i, j, e_count, values[170], bar_characters, read, total_sum; int i, j,values[170], bar_characters, read, total_sum;
int error_number, indexchaine, indexliste; int error_number, indexchaine, indexliste;
char set[170], mode, last_set; char set[170], mode, last_set;
float glyph_count; float glyph_count;
@ -608,7 +588,6 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
linkage_flag = 0; linkage_flag = 0;
j = 0; j = 0;
e_count = 0;
bar_characters = 0; bar_characters = 0;
separator_row = 0; separator_row = 0;

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
/* Updated to comply with BS EN 12323:2005 */ /* Updated to comply with BS EN 12323:2005 */
@ -44,7 +30,7 @@
static int list[2][170]; static int list[2][170];
/* EN 12323 Table 1 - "Code 16K" character encodations */ /* EN 12323 Table 1 - "Code 16K" character encodations */
static char *C16KTable[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213", static const char *C16KTable[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213",
"122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222", "122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222",
"123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222", "123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222",
"321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323", "321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323",
@ -59,11 +45,11 @@ static char *C16KTable[107] = {"212222", "222122", "222221", "121223", "121322",
"211133"}; "211133"};
/* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */ /* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */
static char *C16KStartStop[8] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "3112"}; static const char *C16KStartStop[8] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "3112"};
/* EN 12323 Table 5 - Start and stop values defining row numbers */ /* EN 12323 Table 5 - Start and stop values defining row numbers */
static int C16KStartValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}; static const int C16KStartValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7};
static int C16KStopValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3}; static const int C16KStopValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3};
void grwp16(int *indexliste) void grwp16(int *indexliste)
{ {
@ -172,8 +158,8 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
char width_pattern[100]; char width_pattern[100];
int current_row, rows_needed, flip_flop, looper, first_check, second_check; int current_row, rows_needed, flip_flop, looper, first_check, second_check;
int indexliste, indexchaine, pads_needed, f_state; int indexliste, indexchaine, pads_needed, f_state;
char set[160] = { ' ' }, fset[160] = { ' ' }, mode, last_set, last_fset, current_set; char set[160] = { ' ' }, fset[160] = { ' ' }, mode, last_set,current_set;
unsigned int i, j, k, m, e_count, read, mx_reader, writer; unsigned int i, j, k, m,read, mx_reader, writer;
unsigned int values[160] = { 0 }; unsigned int values[160] = { 0 };
unsigned int bar_characters; unsigned int bar_characters;
float glyph_count; float glyph_count;
@ -192,7 +178,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
return ERROR_TOO_LONG; return ERROR_TOO_LONG;
} }
e_count = 0;
bar_characters = 0; bar_characters = 0;
/* Detect extended ASCII characters */ /* Detect extended ASCII characters */
@ -331,7 +316,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
/* Make sure the data will fit in the symbol */ /* Make sure the data will fit in the symbol */
last_set = ' '; last_set = ' ';
last_fset = ' ';
glyph_count = 0.0; glyph_count = 0.0;
for(i = 0; i < input_length; i++) { for(i = 0; i < input_length; i++) {
if((set[i] == 'a') || (set[i] == 'b')) { if((set[i] == 'a') || (set[i] == 'b')) {
@ -356,16 +340,13 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
if(fset[i] == 'F') { if(fset[i] == 'F') {
last_fset = 'F';
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
} }
} else { } else {
if((fset[i] == 'F') && (fset[i - 1] != 'F')) { if((fset[i] == 'F') && (fset[i - 1] != 'F')) {
last_fset = 'F';
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
} }
if((fset[i] != 'F') && (fset[i - 1] == 'F')) { if((fset[i] != 'F') && (fset[i - 1] == 'F')) {
last_fset = ' ';
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
} }
} }

View File

@ -42,7 +42,7 @@ void ustrcpy(unsigned char target[], unsigned char source[]) {
target[i] = '\0'; target[i] = '\0';
} }
void concat(char dest[], char source[]) void concat(char dest[],const char source[])
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */ { /* Concatinates dest[] with the contents of source[], copying /0 as well */
unsigned int i, j, n; unsigned int i, j, n;
@ -117,7 +117,7 @@ int posn(char set_string[], char data)
return 0; return 0;
} }
void lookup(char set_string[], char *table[], char data, char dest[]) void lookup(char set_string[],const char *table[], char data, char dest[])
{ /* Replaces huge switch statements for looking up in tables */ { /* Replaces huge switch statements for looking up in tables */
unsigned int i, n = strlen(set_string); unsigned int i, n = strlen(set_string);

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
/* Used in some logic */ /* Used in some logic */
@ -43,13 +29,13 @@ extern "C"
extern int ustrlen(unsigned char source[]); extern int ustrlen(unsigned char source[]);
extern void ustrcpy(unsigned char target[], unsigned char source[]); extern void ustrcpy(unsigned char target[], unsigned char source[]);
extern void concat(char dest[], char source[]); extern void concat(char dest[],const char source[]);
extern void uconcat(unsigned char dest[], unsigned char source[]); extern void uconcat(unsigned char dest[], unsigned char source[]);
extern int ctoi(char source); extern int ctoi(char source);
extern char itoc(int source); extern char itoc(int source);
extern void to_upper(unsigned char source[]); extern void to_upper(unsigned char source[]);
extern int is_sane(char test_string[], unsigned char source[], int length); extern int is_sane(char test_string[], unsigned char source[], int length);
extern void lookup(char set_string[], char *table[], char data, char dest[]); extern void lookup(char set_string[],const char *table[], char data, char dest[]);
extern int posn(char set_string[], char data); extern int posn(char set_string[], char data);
extern void expand(struct zint_symbol *symbol, char data[]); extern void expand(struct zint_symbol *symbol, char data[]);
extern int is_stackable(int symbology); extern int is_stackable(int symbology);

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
/* The functions "getBit", "init928" and "encode928" are copyright BSI and are /* The functions "getBit", "init928" and "encode928" are copyright BSI and are
@ -710,7 +696,7 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level)
int cc_binary_string(struct zint_symbol *symbol, const char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width) int cc_binary_string(struct zint_symbol *symbol, const char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width)
{ /* Handles all data encodation from section 5 of ISO/IEC 24723 */ { /* Handles all data encodation from section 5 of ISO/IEC 24723 */
int encoding_method, read_posn, d1, d2, value, alpha_pad; int encoding_method, read_posn, d1, d2, value, alpha_pad;
int i, j, mask, ai_crop, ai_crop_posn, fnc1_latch; int i, j, mask, ai_crop,fnc1_latch;
long int group_val; long int group_val;
int ai90_mode, latch, remainder, binary_length; int ai90_mode, latch, remainder, binary_length;
char date_str[4]; char date_str[4];
@ -725,7 +711,6 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
encoding_method = 1; encoding_method = 1;
read_posn = 0; read_posn = 0;
ai_crop = 0; ai_crop = 0;
ai_crop_posn = -1;
fnc1_latch = 0; fnc1_latch = 0;
alpha_pad = 0; alpha_pad = 0;
ai90_mode = 0; ai90_mode = 0;
@ -910,13 +895,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
if((source[next_ai_posn + 1] == '2') && (source[next_ai_posn + 2] == '1')) { if((source[next_ai_posn + 1] == '2') && (source[next_ai_posn + 2] == '1')) {
/* AI 21 follows */ /* AI 21 follows */
ai_crop = 1; ai_crop = 1;
ai_crop_posn = next_ai_posn + 1;
} }
if((source[next_ai_posn + 1] == '8') && (source[next_ai_posn + 2] == '0') && (source[next_ai_posn + 3] == '0') && (source[next_ai_posn + 4] == '4')) { if((source[next_ai_posn + 1] == '8') && (source[next_ai_posn + 2] == '0') && (source[next_ai_posn + 3] == '0') && (source[next_ai_posn + 4] == '4')) {
/* AI 8004 follows */ /* AI 8004 follows */
ai_crop = 2; ai_crop = 2;
ai_crop_posn = next_ai_posn + 1;
} }
} }
@ -1740,7 +1723,7 @@ void add_leading_zeroes(struct zint_symbol *symbol)
int composite(struct zint_symbol *symbol, unsigned char source[], int length) int composite(struct zint_symbol *symbol, unsigned char source[], int length)
{ {
int error_number, cc_mode, cc_width, ecc_level; int error_number, cc_mode, cc_width, ecc_level;
int j, i, k, separator_row; int j, i, k;
unsigned int rs = length + 1; unsigned int rs = length + 1;
unsigned int bs = 20 * rs; unsigned int bs = 20 * rs;
unsigned int pri_len; unsigned int pri_len;
@ -1755,7 +1738,6 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
int top_shift, bottom_shift; int top_shift, bottom_shift;
error_number = 0; error_number = 0;
separator_row = 0;
pri_len = strlen(symbol->primary); pri_len = strlen(symbol->primary);
if(pri_len == 0) { if(pri_len == 0) {
strcpy(symbol->errtxt, "No primary (linear) message in 2D composite"); strcpy(symbol->errtxt, "No primary (linear) message in 2D composite");

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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.
*/ */
#define NUMERIC 110 #define NUMERIC 110
@ -27,7 +13,7 @@
#define ALPHA_OR_ISO 121 #define ALPHA_OR_ISO 121
/* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */ /* CC-A component coefficients from ISO/IEC 24728:2006 Annex F */
static int ccaCoeffs[30] = { static const int ccaCoeffs[30] = {
/* k = 4 */ /* k = 4 */
522, 568, 723, 809, 522, 568, 723, 809,
@ -45,14 +31,14 @@ static int ccaCoeffs[30] = {
}; };
/* rows, error codewords, k-offset of valid CC-A sizes from ISO/IEC 24723:2006 Table 9 */ /* rows, error codewords, k-offset of valid CC-A sizes from ISO/IEC 24723:2006 Table 9 */
static int ccaVariants[51] = { static const int ccaVariants[51] = {
5, 6, 7, 8, 9, 10, 12, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7, 5, 6, 7, 8, 9, 10, 12, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7,
4, 4, 5, 5, 6, 6, 7, 4, 5, 6, 7, 7, 4, 5, 6, 7, 8, 4, 4, 5, 5, 6, 6, 7, 4, 5, 6, 7, 7, 4, 5, 6, 7, 8,
0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22 0, 0, 4, 4, 9, 9, 15, 0, 4, 9, 15, 15, 0, 4, 9, 15, 22
}; };
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24723:2006 tables 10 and 11 */ /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24723:2006 tables 10 and 11 */
static int aRAPTable[68] = { static const int aRAPTable[68] = {
39, 1, 32, 8, 14, 43, 20, 11, 1, 5, 15, 21, 40, 43, 46, 34, 29, 39, 1, 32, 8, 14, 43, 20, 11, 1, 5, 15, 21, 40, 43, 46, 34, 29,
0, 0, 0, 0, 0, 0, 0, 43, 33, 37, 47, 1, 20, 23, 26, 14, 9, 0, 0, 0, 0, 0, 0, 0, 43, 33, 37, 47, 1, 20, 23, 26, 14, 9,
19, 33, 12, 40, 46, 23, 52, 23, 13, 17, 27, 33, 52, 3, 6, 46, 41, 19, 33, 12, 40, 46, 23, 52, 23, 13, 17, 27, 33, 52, 3, 6, 46, 41,

View File

@ -18,14 +18,14 @@ HRESULT DllGetVersion (DLLVERSIONINFO2* pdvi)
{ {
if (!pdvi || (sizeof(*pdvi) != pdvi->info1.cbSize)) if (!pdvi || (sizeof(*pdvi) != pdvi->info1.cbSize))
return (E_INVALIDARG); return (E_INVALIDARG);
pdvi->info1.dwMajorVersion = 2; pdvi->info1.dwMajorVersion = 2;
pdvi->info1.dwMinorVersion = 2; pdvi->info1.dwMinorVersion = 2;
pdvi->info1.dwBuildNumber = 1; pdvi->info1.dwBuildNumber = 1;
pdvi->info1.dwPlatformID = DLLVER_PLATFORM_WINDOWS; pdvi->info1.dwPlatformID = DLLVER_PLATFORM_WINDOWS;
if (sizeof(DLLVERSIONINFO2) == pdvi->info1.cbSize) if (sizeof(DLLVERSIONINFO2) == pdvi->info1.cbSize)
pdvi->ullVersion = MAKEDLLVERULL(2, 2, 1, 0); pdvi->ullVersion = MAKEDLLVERULL(2, 2, 1, 0);
return S_OK; return S_OK;
} }
#endif /* _WIN32 */ #endif /* _WIN32 */

View File

@ -775,7 +775,7 @@ void add_tail(unsigned char target[], int tp, int tail_length, int last_mode)
int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length) int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length)
{ {
int inputlen, i, skew = 0; int i, skew = 0;
unsigned char binary[2200]; unsigned char binary[2200];
int binlen; int binlen;
int symbolsize, optionsize, calcsize; int symbolsize, optionsize, calcsize;
@ -783,7 +783,6 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
int H, W, FH, FW, datablock, bytes, rsblock; int H, W, FH, FW, datablock, bytes, rsblock;
int last_mode; int last_mode;
unsigned char *grid = 0; unsigned char *grid = 0;
inputlen = length;
binlen = dm200encode(symbol, source, binary, &last_mode, length); binlen = dm200encode(symbol, source, binary, &last_mode, length);

View File

@ -732,19 +732,18 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int word[]) void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int word[])
{ {
int total_cw, data_cw, i, j, wp; int data_cw, i, j, wp;
int n1, b1, n2, b2, e1, b3, e2; int n1, b1, n2, b2, e1, b3, e2;
int block_size, data_size, ecc_size, toggle; int block_size, data_size, ecc_size;
int data[1320], block[130]; int data[1320], block[130];
unsigned char data_block[115], ecc_block[70]; unsigned char data_block[115], ecc_block[70];
total_cw = gm_total_cw[(layers - 1)];
data_cw = gm_data_codewords[((layers - 1) * 5) + (ecc_level - 1)]; data_cw = gm_data_codewords[((layers - 1) * 5) + (ecc_level - 1)];
for(i = 0; i < 1320; i++) { for(i = 0; i < 1320; i++) {
data[i] = 0; data[i] = 0;
} }
/* Convert from binary sream to 7-bit codewords */ /* Convert from binary sream to 7-bit codewords */
for(i = 0; i < data_posn; i++) { for(i = 0; i < data_posn; i++) {
if(binary[i * 7] == '1') { data[i] += 0x40; } if(binary[i * 7] == '1') { data[i] += 0x40; }
@ -755,19 +754,17 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
if(binary[(i * 7) + 5] == '1') { data[i] += 0x02; } if(binary[(i * 7) + 5] == '1') { data[i] += 0x02; }
if(binary[(i * 7) + 6] == '1') { data[i] += 0x01; } if(binary[(i * 7) + 6] == '1') { data[i] += 0x01; }
} }
/* Add padding codewords */ /* Add padding codewords */
data[data_posn] = 0x00; data[data_posn] = 0x00;
for(i = (data_posn + 1); i < data_cw; i++) { for(i = (data_posn + 1); i < data_cw; i++) {
if(i & 1) { if(i & 1) {
data[i] = 0x7e; data[i] = 0x7e;
toggle = 1;
} else { } else {
data[i] = 0x00; data[i] = 0x00;
toggle = 0;
} }
} }
/* Get block sizes */ /* Get block sizes */
n1 = gm_n1[(layers - 1)]; n1 = gm_n1[(layers - 1)];
b1 = gm_b1[(layers - 1)]; b1 = gm_b1[(layers - 1)];
@ -776,27 +773,27 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
e1 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4)]; e1 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4)];
b3 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4) + 1]; b3 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4) + 1];
e2 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4) + 2]; e2 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4) + 2];
/* Split the data into blocks */ /* Split the data into blocks */
wp = 0; wp = 0;
for(i = 0; i < (b1 + b2); i++) { for(i = 0; i < (b1 + b2); i++) {
if(i < b1) { block_size = n1; } else { block_size = n2; } if(i < b1) { block_size = n1; } else { block_size = n2; }
if(i < b3) { ecc_size = e1; } else { ecc_size = e2; } if(i < b3) { ecc_size = e1; } else { ecc_size = e2; }
data_size = block_size - ecc_size; data_size = block_size - ecc_size;
/* printf("block %d/%d: data %d / ecc %d\n", i + 1, (b1 + b2), data_size, ecc_size);*/ /* printf("block %d/%d: data %d / ecc %d\n", i + 1, (b1 + b2), data_size, ecc_size);*/
for(j = 0; j < data_size; j++) { for(j = 0; j < data_size; j++) {
data_block[j] = data[wp]; data_block[j] = data[wp];
wp++; wp++;
} }
/* Calculate ECC data for this block */ /* Calculate ECC data for this block */
rs_init_gf(0x89); rs_init_gf(0x89);
rs_init_code(ecc_size, 1); rs_init_code(ecc_size, 1);
rs_encode(data_size, data_block, ecc_block); rs_encode(data_size, data_block, ecc_block);
rs_free(); rs_free();
/* Correct error correction data but in reverse order */ /* Correct error correction data but in reverse order */
for(j = 0; j < data_size; j++) { for(j = 0; j < data_size; j++) {
block[j] = data_block[j]; block[j] = data_block[j];
@ -804,7 +801,7 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
for(j = 0; j < ecc_size; j++) { for(j = 0; j < ecc_size; j++) {
block[(j + data_size)] = ecc_block[ecc_size - j - 1]; block[(j + data_size)] = ecc_block[ecc_size - j - 1];
} }
for(j = 0; j < n2; j++) { for(j = 0; j < n2; j++) {
word[((b1 + b2) * j) + i] = block[j]; word[((b1 + b2) * j) + i] = block[j];
} }

View File

@ -28,7 +28,7 @@
#define EUROPIUM "0123456789ABCDEFGHIJKLMOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz " #define EUROPIUM "0123456789ABCDEFGHIJKLMOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
static char shift_set[] = { static const char shift_set[] = {
/* From Table 7 - Encoding of control characters */ /* From Table 7 - Encoding of control characters */
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* NULL -> SI */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* NULL -> SI */
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* DLE -> US */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* DLE -> US */
@ -36,11 +36,11 @@ static char shift_set[] = {
';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~' ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
}; };
static int gm_recommend_cw[] = { 9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021 }; static const int gm_recommend_cw[] = { 9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021 };
static int gm_max_cw[] = { 11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313 }; static const int gm_max_cw[] = { 11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313 };
static int gm_total_cw[] = { 18, 50, 98, 162, 242, 338, 450, 578, 722, 882, 1058, 1250, 1458 }; //static const int gm_total_cw[] = { 18, 50, 98, 162, 242, 338, 450, 578, 722, 882, 1058, 1250, 1458 };
static int gm_data_codewords[] = { static const int gm_data_codewords[] = {
0, 15, 13, 11, 9, 0, 15, 13, 11, 9,
45, 40, 35, 30, 25, 45, 40, 35, 30, 25,
89, 79, 69, 59, 49, 89, 79, 69, 59, 49,
@ -56,11 +56,11 @@ static int gm_data_codewords[] = {
1313, 1167, 1021, 875, 729 1313, 1167, 1021, 875, 729
}; };
static int gm_n1[] = { 18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122 }; static const int gm_n1[] = { 18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122 };
static int gm_b1[] = { 1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6 }; static const int gm_b1[] = { 1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6 };
static int gm_b2[] = { 0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6 }; static const int gm_b2[] = { 0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6 };
static int gm_ebeb[] = { static const int gm_ebeb[] = {
/* E1 B3 E2 B4 */ /* E1 B3 E2 B4 */
0, 0, 0, 0, // version 1 0, 0, 0, 0, // version 1
3, 1, 0, 0, 3, 1, 0, 0,
@ -129,7 +129,7 @@ static int gm_ebeb[] = {
61, 9, 60, 3 61, 9, 60, 3
}; };
static int gm_macro_matrix[] = { static const int gm_macro_matrix[] = {
728,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650, 728,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,
727,624,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,651, 727,624,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,651,
726,623,528,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,553,652, 726,623,528,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,553,652,

View File

@ -79,9 +79,11 @@ void ZBarcode_Clear(struct zint_symbol *symbol)
symbol->width = 0; symbol->width = 0;
symbol->text[0] = '\0'; symbol->text[0] = '\0';
symbol->errtxt[0] = '\0'; symbol->errtxt[0] = '\0';
if (symbol->bitmap != NULL) if (symbol->bitmap != NULL)
{
free(symbol->bitmap); free(symbol->bitmap);
symbol->bitmap = NULL; symbol->bitmap = NULL;
}
symbol->bitmap_width = 0; symbol->bitmap_width = 0;
symbol->bitmap_height = 0; symbol->bitmap_height = 0;
} }
@ -108,7 +110,7 @@ void ZBarcode_Delete(struct zint_symbol *symbol)
while (string) { while (string) {
s = string; s = string;
string = string->next; string = string->next;
free(s->text); free(s->text);
free(s); free(s);
} }
@ -225,7 +227,11 @@ int dump_plot(struct zint_symbol *symbol)
} }
fputs("]\n", f); fputs("]\n", f);
fclose(f); if(symbol->output_options & BARCODE_STDOUT) {
fflush(f);
} else {
fclose(f);
}
return 0; return 0;
} }
@ -836,7 +842,8 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
buffer = (unsigned char *)malloc(fileLen * sizeof(unsigned char)); buffer = (unsigned char *)malloc(fileLen * sizeof(unsigned char));
if(!buffer) { if(!buffer) {
strcpy(symbol->errtxt, "Internal memory error"); strcpy(symbol->errtxt, "Internal memory error");
fclose(file); if (strcmp(filename, "-"))
fclose(file);
return ERROR_MEMORY; return ERROR_MEMORY;
} }

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
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 3 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 <stdio.h> #include <stdio.h>
@ -29,7 +15,7 @@ extern int c39(struct zint_symbol *symbol, unsigned char source[], int length);
#define CALCIUM "0123456789-$:/.+ABCD" #define CALCIUM "0123456789-$:/.+ABCD"
static char *CodaTable[20] = {"11111221", "11112211", "11121121", "22111111", "11211211", "21111211", static const char *CodaTable[20] = {"11111221", "11112211", "11121121", "22111111", "11211211", "21111211",
"12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121", "12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121",
"21212111", "11212121", "11221211", "12121121", "11121221", "11122211"}; "21212111", "11212121", "11221211", "12121121", "11121221", "11122211"};

View File

@ -4,20 +4,6 @@
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
Portions Copyright (C) 2004 Grandzebu Portions Copyright (C) 2004 Grandzebu
Bug Fixes thanks to KL Chin <klchin@users.sourceforge.net> Bug Fixes thanks to KL Chin <klchin@users.sourceforge.net>
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 3 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.
*/ */
/* This code is adapted from "Code barre PDF 417 / PDF 417 barcode" v2.5.0 /* This code is adapted from "Code barre PDF 417 / PDF 417 barcode" v2.5.0
@ -53,19 +39,19 @@
/* text mode processing tables */ /* text mode processing tables */
static int asciix[95] = { 7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4, static const int asciix[95] = { 7, 8, 8, 4, 12, 4, 4, 8, 8, 8, 12, 4, 12, 12, 12, 12, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 12, 8, 8, 4, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 12, 8, 8, 4, 8, 8, 8, 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, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 8, 8, 8, 4, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 8, 8, 8, 8 }; 2, 2, 2, 2, 8, 8, 8, 8 };
static int asciiy[95] = { 26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3, static const int asciiy[95] = { 26, 10, 20, 15, 18, 21, 10, 28, 23, 24, 22, 20, 13, 16, 17, 19, 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 14, 0, 1, 23, 2, 25, 3, 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, 4, 5, 6, 24, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 4, 5, 6, 24, 7, 8, 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, 21, 27, 9 }; 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 21, 27, 9 };
/* Automatic sizing table */ /* Automatic sizing table */
static int MicroAutosize[56] = static const int MicroAutosize[56] =
{ 4, 6, 7, 8, 10, 12, 13, 14, 16, 18, 19, 20, 24, 29, 30, 33, 34, 37, 39, 46, 54, 58, 70, 72, 82, 90, 108, 126, { 4, 6, 7, 8, 10, 12, 13, 14, 16, 18, 19, 20, 24, 29, 30, 33, 34, 37, 39, 46, 54, 58, 70, 72, 82, 90, 108, 126,
1, 14, 2, 7, 3, 25, 8, 16, 5, 17, 9, 6, 10, 11, 28, 12, 19, 13, 29, 20, 30, 21, 22, 31, 23, 32, 33, 34 1, 14, 2, 7, 3, 25, 8, 16, 5, 17, 9, 6, 10, 11, 28, 12, 19, 13, 29, 20, 30, 21, 22, 31, 23, 32, 33, 34
}; };

View File

@ -4,20 +4,6 @@
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
Portions Copyright (C) 2004 Grandzebu Portions Copyright (C) 2004 Grandzebu
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 3 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.
*/ */
/* this file contains the character table, the pre-calculated coefficients and the /* this file contains the character table, the pre-calculated coefficients and the
@ -32,7 +18,7 @@
#define BRSET "ABCDEFabcdefghijklmnopqrstuvwxyz*+-" #define BRSET "ABCDEFabcdefghijklmnopqrstuvwxyz*+-"
/* PDF417 error correction coefficients from Grand Zebu */ /* PDF417 error correction coefficients from Grand Zebu */
static int coefrs[1022] = { static const int coefrs[1022] = {
/* k = 2 */ /* k = 2 */
27, 917, 27, 917,
@ -118,7 +104,7 @@ static int coefrs[1022] = {
63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263 }; 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263 };
static char *codagemc[2787] = { "urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA", "uls", "pBk", "eBA", static const char *codagemc[2787] = { "urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA", "uls", "pBk", "eBA",
"pAs", "eAk", "prA", "uvs", "xhy", "pnk", "utw", "xgz", "fDA", "pls", "fBk", "frA", "pvs", "pAs", "eAk", "prA", "uvs", "xhy", "pnk", "utw", "xgz", "fDA", "pls", "fBk", "frA", "pvs",
"uxy", "fnk", "ptw", "uwz", "fls", "psy", "fvs", "pxy", "ftw", "pwz", "fxy", "yrx", "ufk", "uxy", "fnk", "ptw", "uwz", "fls", "psy", "fvs", "pxy", "ftw", "pwz", "fxy", "yrx", "ufk",
"xFw", "ymz", "onA", "uds", "xEy", "olk", "ucw", "dBA", "oks", "uci", "dAk", "okg", "dAc", "xFw", "ymz", "onA", "uds", "xEy", "olk", "ucw", "dBA", "oks", "uci", "dAk", "okg", "dAc",
@ -335,13 +321,13 @@ static char *codagemc[2787] = { "urA", "xfs", "ypy", "unk", "xdw", "yoz", "pDA",
"Ayv", "kze", "kzd", "Aye", "Byu", "Ayd", "Byt", "szp" }; "Ayv", "kze", "kzd", "Aye", "Byu", "Ayd", "Byt", "szp" };
/* converts values into bar patterns - replacing Grand Zebu's true type font */ /* converts values into bar patterns - replacing Grand Zebu's true type font */
static char *PDFttf[35] = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", static const char *PDFttf[35] = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
"01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001",
"10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010",
"11011", "11100", "11101", "11110", "11111", "01", "1111111101010100", "11111101000101001"}; "11011", "11100", "11101", "11110", "11111", "01", "1111111101010100", "11111101000101001"};
/* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F */ /* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F */
static int Microcoeffs[344] = { static const int Microcoeffs[344] = {
/* k = 7 */ /* k = 7 */
76, 925, 537, 597, 784, 691, 437, 76, 925, 537, 597, 784, 691, 437,
@ -405,7 +391,7 @@ static int Microcoeffs[344] = {
718, 435 }; 718, 435 };
/* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */ /* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */
static int MicroVariants[170] = static const int MicroVariants[170] =
{ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44,
7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50,
@ -413,14 +399,14 @@ static int MicroVariants[170] =
/* rows, columns, error codewords, k-offset */ /* rows, columns, error codewords, k-offset */
/* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */ /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */
static int RAPTable[136] = static const int RAPTable[136] =
{ 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, { 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25,
9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49,
0, 3, 6, 0, 6, 0, 0, 0, 3, 6, 0, 6, 6, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0, 3, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0 }; 0, 3, 6, 0, 6, 0, 0, 0, 3, 6, 0, 6, 6, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0, 3, 0, 0, 6, 0, 0, 0, 0, 6, 6, 0 };
/* Left and Right Row Address Pattern from Table 2 */ /* Left and Right Row Address Pattern from Table 2 */
static char *RAPLR[53] = {"", "221311", "311311", "312211", "222211", "213211", "214111", "223111", static const char *RAPLR[53] = {"", "221311", "311311", "312211", "222211", "213211", "214111", "223111",
"313111", "322111", "412111", "421111", "331111", "241111", "232111", "231211", "321211", "313111", "322111", "412111", "421111", "331111", "241111", "232111", "231211", "321211",
"411211", "411121", "411112", "321112", "312112", "311212", "311221", "311131", "311122", "411211", "411121", "411112", "321112", "312112", "311212", "311221", "311131", "311122",
"311113", "221113", "221122", "221131", "221221", "222121", "312121", "321121", "231121", "311113", "221113", "221122", "221131", "221221", "222121", "312121", "321121", "231121",
@ -428,7 +414,7 @@ static char *RAPLR[53] = {"", "221311", "311311", "312211", "222211", "213211",
"211123", "211132", "211141", "211231", "211222", "211312", "211321", "211411", "212311" }; "211123", "211132", "211141", "211231", "211222", "211312", "211321", "211411", "212311" };
/* Centre Row Address Pattern from Table 2 */ /* Centre Row Address Pattern from Table 2 */
static char *RAPC[53] = {"", "112231", "121231", "122131", "131131", "131221", "132121", "141121", static const char *RAPC[53] = {"", "112231", "121231", "122131", "131131", "131221", "132121", "141121",
"141211", "142111", "133111", "132211", "131311", "122311", "123211", "124111", "115111", "141211", "142111", "133111", "132211", "131311", "122311", "123211", "124111", "115111",
"114211", "114121", "123121", "123112", "122212", "122221", "121321", "121411", "112411", "114211", "114121", "123121", "123112", "122212", "122221", "121321", "121411", "112411",
"113311", "113221", "113212", "113122", "122122", "131122", "131113", "122113", "113113", "113311", "113221", "113212", "113122", "122122", "131122", "131113", "122113", "113113",

View File

@ -26,11 +26,11 @@
#define SSET "0123456789ABCDEF" #define SSET "0123456789ABCDEF"
static char *PlessTable[16] = {"13131313", "31131313", "13311313", "31311313", "13133113", "31133113", static const char *PlessTable[16] = {"13131313", "31131313", "13311313", "31311313", "13133113", "31133113",
"13313113", "31313113", "13131331", "31131331", "13311331", "31311331", "13133131", "13313113", "31313113", "13131331", "31131331", "13311331", "31311331", "13133131",
"31133131", "13313131", "31313131"}; "31133131", "13313131", "31313131"};
static char *MSITable[10] = {"12121212", "12121221", "12122112", "12122121", "12211212", "12211221", static const char *MSITable[10] = {"12121212", "12121221", "12122112", "12122121", "12211212", "12211221",
"12212112", "12212121", "21121212", "21121221"}; "12212112", "12212121", "21121212", "21121221"};

View File

@ -82,7 +82,6 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
png_structp png_ptr; png_structp png_ptr;
png_infop info_ptr; png_infop info_ptr;
graphic = &wpng_info; graphic = &wpng_info;
unsigned long rowbytes;
unsigned char *image_data; unsigned char *image_data;
int i, row, column, errno; int i, row, column, errno;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
@ -171,7 +170,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
png_init_io(png_ptr, graphic->outfile); png_init_io(png_ptr, graphic->outfile);
/* set compression */ /* set compression */
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); png_set_compression_level(png_ptr,9);
/* set Header block */ /* set Header block */
png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height, png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height,
@ -185,9 +184,6 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
into bytes (one, two or four pixels per byte) */ into bytes (one, two or four pixels per byte) */
png_set_packing(png_ptr); png_set_packing(png_ptr);
/* set rowbytes - depends on picture depth */
rowbytes = wpng_info.width * 3;
/* Pixel Plotting */ /* Pixel Plotting */
switch(rotate_angle) { switch(rotate_angle) {
@ -304,7 +300,6 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle)
{ {
unsigned long rowbytes;
int i, row, column, errno; int i, row, column, errno;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
@ -357,9 +352,6 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
/* set rowbytes - depends on picture depth */
rowbytes = symbol->bitmap_width * 3;
/* Pixel Plotting */ /* Pixel Plotting */
i = 0; i = 0;
switch(rotate_angle) { switch(rotate_angle) {

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
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 3 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 <locale.h> #include <locale.h>
@ -47,14 +33,14 @@ int ps_plot(struct zint_symbol *symbol)
float default_text_posn; float default_text_posn;
int plot_text = 1; int plot_text = 1;
const char *locale = NULL; const char *locale = NULL;
row_height=0; row_height=0;
textdone = 0; textdone = 0;
main_width = symbol->width; main_width = symbol->width;
strcpy(addon, ""); strcpy(addon, "");
comp_offset = 0; comp_offset = 0;
addon_text_posn = 0.0; addon_text_posn = 0.0;
if((symbol->output_options & BARCODE_STDOUT) != 0) { if((symbol->output_options & BARCODE_STDOUT) != 0) {
feps = stdout; feps = stdout;
} else { } else {
@ -64,11 +50,11 @@ int ps_plot(struct zint_symbol *symbol)
strcpy(symbol->errtxt, "Could not open output file"); strcpy(symbol->errtxt, "Could not open output file");
return ERROR_FILE_ACCESS; return ERROR_FILE_ACCESS;
} }
/* sort out colour options */ /* sort out colour options */
to_upper((unsigned char*)symbol->fgcolour); to_upper((unsigned char*)symbol->fgcolour);
to_upper((unsigned char*)symbol->bgcolour); to_upper((unsigned char*)symbol->bgcolour);
if(strlen(symbol->fgcolour) != 6) { if(strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target"); strcpy(symbol->errtxt, "Malformed foreground colour target");
return ERROR_INVALID_OPTION; return ERROR_INVALID_OPTION;
@ -88,7 +74,7 @@ int ps_plot(struct zint_symbol *symbol)
return ERROR_INVALID_OPTION; return ERROR_INVALID_OPTION;
} }
locale = setlocale(LC_ALL, "C"); locale = setlocale(LC_ALL, "C");
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
@ -101,11 +87,11 @@ int ps_plot(struct zint_symbol *symbol)
red_paper = bgred / 256.0; red_paper = bgred / 256.0;
green_paper = bggrn / 256.0; green_paper = bggrn / 256.0;
blue_paper = bgblu / 256.0; blue_paper = bgblu / 256.0;
if (symbol->height == 0) { if (symbol->height == 0) {
symbol->height = 50; symbol->height = 50;
} }
large_bar_count = 0; large_bar_count = 0;
preset_height = 0.0; preset_height = 0.0;
for(i = 0; i < symbol->rows; i++) { for(i = 0; i < symbol->rows; i++) {
@ -119,7 +105,7 @@ int ps_plot(struct zint_symbol *symbol)
if (large_bar_count == 0) { if (large_bar_count == 0) {
symbol->height = preset_height; symbol->height = preset_height;
} }
while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) { while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
comp_offset++; comp_offset++;
} }
@ -140,21 +126,21 @@ int ps_plot(struct zint_symbol *symbol)
main_width = 68 + comp_offset; main_width = 68 + comp_offset;
} }
} }
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
if(symbol->whitespace_width == 0) { if(symbol->whitespace_width == 0) {
symbol->whitespace_width = 10; symbol->whitespace_width = 10;
main_width = 96 + comp_offset; main_width = 96 + comp_offset;
} }
} }
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
if(symbol->whitespace_width == 0) { if(symbol->whitespace_width == 0) {
symbol->whitespace_width = 10; symbol->whitespace_width = 10;
main_width = 51 + comp_offset; main_width = 51 + comp_offset;
} }
} }
latch = 0; latch = 0;
r = 0; r = 0;
/* Isolate add-on text */ /* Isolate add-on text */
@ -170,7 +156,7 @@ int ps_plot(struct zint_symbol *symbol)
} }
} }
addon[r] = '\0'; addon[r] = '\0';
if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) { if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
plot_text = 0; plot_text = 0;
} }
@ -181,7 +167,7 @@ int ps_plot(struct zint_symbol *symbol)
} }
xoffset = symbol->border_width + symbol->whitespace_width; xoffset = symbol->border_width + symbol->whitespace_width;
yoffset = symbol->border_width; yoffset = symbol->border_width;
/* Start writing the header */ /* Start writing the header */
fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n"); fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n");
fprintf(feps, "%%%%Creator: Zint %s\n", ZINT_VERSION); fprintf(feps, "%%%%Creator: Zint %s\n", ZINT_VERSION);
@ -197,7 +183,7 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler)); fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
} }
fprintf(feps, "%%%%EndComments\n"); fprintf(feps, "%%%%EndComments\n");
/* Definitions */ /* Definitions */
fprintf(feps, "/TL { setlinewidth moveto lineto stroke } bind def\n"); fprintf(feps, "/TL { setlinewidth moveto lineto stroke } bind def\n");
fprintf(feps, "/TC { moveto 0 360 arc 360 0 arcn fill } bind def\n"); fprintf(feps, "/TC { moveto 0 360 arc 360 0 arcn fill } bind def\n");
@ -205,14 +191,14 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "/TB { 2 copy } bind def\n"); fprintf(feps, "/TB { 2 copy } bind def\n");
fprintf(feps, "/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def\n"); fprintf(feps, "/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def\n");
fprintf(feps, "/TE { pop pop } bind def\n"); fprintf(feps, "/TE { pop pop } bind def\n");
fprintf(feps, "newpath\n"); fprintf(feps, "newpath\n");
/* Now the actual representation */ /* Now the actual representation */
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", (symbol->height + textoffset + yoffset + yoffset) * scaler, (symbol->width + xoffset + xoffset) * scaler); fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", (symbol->height + textoffset + yoffset + yoffset) * scaler, (symbol->width + xoffset + xoffset) * scaler);
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
default_text_posn = 0.5 * scaler; default_text_posn = 0.5 * scaler;
} else { } else {
@ -222,8 +208,8 @@ int ps_plot(struct zint_symbol *symbol)
if(symbol->symbology == BARCODE_MAXICODE) { if(symbol->symbology == BARCODE_MAXICODE) {
/* Maxicode uses hexagons */ /* Maxicode uses hexagons */
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my; float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
textoffset = 0.0; textoffset = 0.0;
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
@ -235,10 +221,10 @@ int ps_plot(struct zint_symbol *symbol)
/* side bars */ /* side bars */
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler); fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, (74.0 + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler); fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, (74.0 + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
} }
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
@ -269,13 +255,13 @@ int ps_plot(struct zint_symbol *symbol)
} }
} }
} }
} }
if(symbol->symbology != BARCODE_MAXICODE) { if(symbol->symbology != BARCODE_MAXICODE) {
/* everything else uses rectangles (or squares) */ /* everything else uses rectangles (or squares) */
/* Works from the bottom of the symbol up */ /* Works from the bottom of the symbol up */
int addon_latch = 0; int addon_latch = 0;
for(r = 0; r < symbol->rows; r++) { for(r = 0; r < symbol->rows; r++) {
this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */ this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
if(symbol->row_height[this_row] == 0) { if(symbol->row_height[this_row] == 0) {
@ -292,7 +278,7 @@ int ps_plot(struct zint_symbol *symbol)
} }
} }
row_posn += (textoffset + yoffset); row_posn += (textoffset + yoffset);
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f ", row_height * scaler, row_posn * scaler); fprintf(feps, "%.2f %.2f ", row_height * scaler, row_posn * scaler);
@ -302,7 +288,7 @@ int ps_plot(struct zint_symbol *symbol)
} else { } else {
latch = 0; latch = 0;
} }
do { do {
block_width = 0; block_width = 0;
do { do {
@ -314,8 +300,8 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "%.2f %.2f ", (row_height - 5.0) * scaler, (row_posn - 5.0) * scaler); fprintf(feps, "%.2f %.2f ", (row_height - 5.0) * scaler, (row_posn - 5.0) * scaler);
addon_text_posn = row_posn + row_height - 8.0; addon_text_posn = row_posn + row_height - 8.0;
addon_latch = 1; addon_latch = 1;
} }
if(latch == 1) { if(latch == 1) {
/* a bar */ /* a bar */
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset) * scaler, block_width * scaler); fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset) * scaler, block_width * scaler);
latch = 0; latch = 0;
@ -324,7 +310,7 @@ int ps_plot(struct zint_symbol *symbol)
latch = 1; latch = 1;
} }
i += block_width; i += block_width;
} while (i < symbol->width); } while (i < symbol->width);
} }
} }
@ -381,7 +367,7 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "setmatrix\n"); fprintf(feps, "setmatrix\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
fprintf(feps, "matrix currentmatrix\n"); fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n"); fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler); fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
@ -464,7 +450,7 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "setmatrix\n"); fprintf(feps, "setmatrix\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
fprintf(feps, "matrix currentmatrix\n"); fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n"); fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler); fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
@ -492,7 +478,7 @@ int ps_plot(struct zint_symbol *symbol)
break; break;
} }
} }
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
/* guard bar extensions and text formatting for UPCA */ /* guard bar extensions and text formatting for UPCA */
@ -500,7 +486,7 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f ", 5.0 * scaler, (4.0 + yoffset) * scaler); fprintf(feps, "%.2f %.2f ", 5.0 * scaler, (4.0 + yoffset) * scaler);
latch = 1; latch = 1;
i = 0 + comp_offset; i = 0 + comp_offset;
do { do {
block_width = 0; block_width = 0;
@ -592,7 +578,7 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "setmatrix\n"); fprintf(feps, "setmatrix\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
fprintf(feps, "matrix currentmatrix\n"); fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n"); fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler); fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
@ -618,7 +604,7 @@ int ps_plot(struct zint_symbol *symbol)
break; break;
} }
} }
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
/* guard bar extensions and text formatting for UPCE */ /* guard bar extensions and text formatting for UPCE */
@ -672,7 +658,7 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "setmatrix\n"); fprintf(feps, "setmatrix\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
fprintf(feps, "matrix currentmatrix\n"); fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n"); fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler); fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
@ -728,12 +714,12 @@ int ps_plot(struct zint_symbol *symbol)
/* side bars */ /* side bars */
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler); fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler); fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
} }
break; break;
} }
/* Put the human readable text at the bottom */ /* Put the human readable text at the bottom */
if(plot_text && (textdone == 0)) { if(plot_text && (textdone == 0)) {
fprintf(feps, "TE\n"); fprintf(feps, "TE\n");
@ -750,12 +736,16 @@ int ps_plot(struct zint_symbol *symbol)
fprintf(feps, "setmatrix\n"); fprintf(feps, "setmatrix\n");
} }
fprintf(feps, "\nshowpage\n"); fprintf(feps, "\nshowpage\n");
fclose(feps); if(symbol->output_options & BARCODE_STDOUT) {
fflush(feps);
} else {
fclose(feps);
}
if (locale) if (locale)
setlocale(LC_ALL, locale); setlocale(LC_ALL, locale);
return error_number; return error_number;
} }

View File

@ -3,20 +3,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
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 3 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 <locale.h> #include <locale.h>
@ -32,8 +18,6 @@ int svg_plot(struct zint_symbol *symbol)
int i, block_width, latch, r, this_row; int i, block_width, latch, r, this_row;
float textpos, large_bar_height, preset_height, row_height, row_posn = 0.0; float textpos, large_bar_height, preset_height, row_height, row_posn = 0.0;
FILE *fsvg; FILE *fsvg;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
float red_ink, green_ink, blue_ink, red_paper, green_paper, blue_paper;
int error_number = 0; int error_number = 0;
int textoffset, xoffset, yoffset, textdone, main_width; int textoffset, xoffset, yoffset, textdone, main_width;
char textpart[10], addon[6]; char textpart[10], addon[6];
@ -43,14 +27,14 @@ int svg_plot(struct zint_symbol *symbol)
float default_text_posn; float default_text_posn;
int plot_text = 1; int plot_text = 1;
const char *locale = NULL; const char *locale = NULL;
row_height=0; row_height=0;
textdone = 0; textdone = 0;
main_width = symbol->width; main_width = symbol->width;
strcpy(addon, ""); strcpy(addon, "");
comp_offset = 0; comp_offset = 0;
addon_text_posn = 0.0; addon_text_posn = 0.0;
if((symbol->output_options & BARCODE_STDOUT) != 0) { if((symbol->output_options & BARCODE_STDOUT) != 0) {
fsvg = stdout; fsvg = stdout;
} else { } else {
@ -60,11 +44,11 @@ int svg_plot(struct zint_symbol *symbol)
strcpy(symbol->errtxt, "Could not open output file"); strcpy(symbol->errtxt, "Could not open output file");
return ERROR_FILE_ACCESS; return ERROR_FILE_ACCESS;
} }
/* sort out colour options */ /* sort out colour options */
to_upper((unsigned char*)symbol->fgcolour); to_upper((unsigned char*)symbol->fgcolour);
to_upper((unsigned char*)symbol->bgcolour); to_upper((unsigned char*)symbol->bgcolour);
if(strlen(symbol->fgcolour) != 6) { if(strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target"); strcpy(symbol->errtxt, "Malformed foreground colour target");
return ERROR_INVALID_OPTION; return ERROR_INVALID_OPTION;
@ -85,23 +69,10 @@ int svg_plot(struct zint_symbol *symbol)
} }
locale = setlocale(LC_ALL, "C"); locale = setlocale(LC_ALL, "C");
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
red_ink = fgred / 256.0;
green_ink = fggrn / 256.0;
blue_ink = fgblu / 256.0;
red_paper = bgred / 256.0;
green_paper = bggrn / 256.0;
blue_paper = bgblu / 256.0;
if (symbol->height == 0) { if (symbol->height == 0) {
symbol->height = 50; symbol->height = 50;
} }
large_bar_count = 0; large_bar_count = 0;
preset_height = 0.0; preset_height = 0.0;
for(i = 0; i < symbol->rows; i++) { for(i = 0; i < symbol->rows; i++) {
@ -115,7 +86,7 @@ int svg_plot(struct zint_symbol *symbol)
if (large_bar_count == 0) { if (large_bar_count == 0) {
symbol->height = preset_height; symbol->height = preset_height;
} }
while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) { while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
comp_offset++; comp_offset++;
} }
@ -136,21 +107,21 @@ int svg_plot(struct zint_symbol *symbol)
main_width = 68 + comp_offset; main_width = 68 + comp_offset;
} }
} }
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
if(symbol->whitespace_width == 0) { if(symbol->whitespace_width == 0) {
symbol->whitespace_width = 10; symbol->whitespace_width = 10;
main_width = 96 + comp_offset; main_width = 96 + comp_offset;
} }
} }
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
if(symbol->whitespace_width == 0) { if(symbol->whitespace_width == 0) {
symbol->whitespace_width = 10; symbol->whitespace_width = 10;
main_width = 51 + comp_offset; main_width = 51 + comp_offset;
} }
} }
latch = 0; latch = 0;
r = 0; r = 0;
/* Isolate add-on text */ /* Isolate add-on text */
@ -166,7 +137,7 @@ int svg_plot(struct zint_symbol *symbol)
} }
} }
addon[r] = '\0'; addon[r] = '\0';
if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) { if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
plot_text = 0; plot_text = 0;
} }
@ -177,7 +148,7 @@ int svg_plot(struct zint_symbol *symbol)
} }
xoffset = symbol->border_width + symbol->whitespace_width; xoffset = symbol->border_width + symbol->whitespace_width;
yoffset = symbol->border_width; yoffset = symbol->border_width;
/* Start writing the header */ /* Start writing the header */
fprintf(fsvg, "<?xml version=\"1.0\" standalone=\"no\"?>\n"); fprintf(fsvg, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
fprintf(fsvg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"); fprintf(fsvg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
@ -211,8 +182,8 @@ int svg_plot(struct zint_symbol *symbol)
if(symbol->symbology == BARCODE_MAXICODE) { if(symbol->symbology == BARCODE_MAXICODE) {
/* Maxicode uses hexagons */ /* Maxicode uses hexagons */
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my; float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
textoffset = 0.0; textoffset = 0.0;
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (74.0 + xoffset + xoffset) * scaler, symbol->border_width * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (74.0 + xoffset + xoffset) * scaler, symbol->border_width * scaler);
@ -255,13 +226,13 @@ int svg_plot(struct zint_symbol *symbol)
} }
} }
} }
} }
if(symbol->symbology != BARCODE_MAXICODE) { if(symbol->symbology != BARCODE_MAXICODE) {
/* everything else uses rectangles (or squares) */ /* everything else uses rectangles (or squares) */
/* Works from the bottom of the symbol up */ /* Works from the bottom of the symbol up */
int addon_latch = 0; int addon_latch = 0;
for(r = 0; r < symbol->rows; r++) { for(r = 0; r < symbol->rows; r++) {
this_row = r; this_row = r;
if(symbol->row_height[this_row] == 0) { if(symbol->row_height[this_row] == 0) {
@ -278,14 +249,14 @@ int svg_plot(struct zint_symbol *symbol)
} }
} }
row_posn += yoffset; row_posn += yoffset;
i = 0; i = 0;
if(module_is_set(symbol, this_row, 0)) { if(module_is_set(symbol, this_row, 0)) {
latch = 1; latch = 1;
} else { } else {
latch = 0; latch = 0;
} }
do { do {
block_width = 0; block_width = 0;
do { do {
@ -294,8 +265,8 @@ int svg_plot(struct zint_symbol *symbol)
if((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_width)) { if((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_width)) {
addon_text_posn = (row_posn + 8.0) * scaler; addon_text_posn = (row_posn + 8.0) * scaler;
addon_latch = 1; addon_latch = 1;
} }
if(latch == 1) { if(latch == 1) {
/* a bar */ /* a bar */
if(addon_latch == 0) { if(addon_latch == 0) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset) * scaler, row_posn * scaler, block_width * scaler, row_height * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset) * scaler, row_posn * scaler, block_width * scaler, row_height * scaler);
@ -308,7 +279,7 @@ int svg_plot(struct zint_symbol *symbol)
latch = 1; latch = 1;
} }
i += block_width; i += block_width;
} while (i < symbol->width); } while (i < symbol->width);
} }
} }
@ -330,7 +301,7 @@ int svg_plot(struct zint_symbol *symbol)
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (32 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (32 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (34 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (34 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (64 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (64 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (66 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (66 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
for(i = 0; i < 4; i++) { for(i = 0; i < 4; i++) {
textpart[i] = symbol->text[i]; textpart[i] = symbol->text[i];
} }
@ -351,7 +322,7 @@ int svg_plot(struct zint_symbol *symbol)
fprintf(fsvg, " </text>\n"); fprintf(fsvg, " </text>\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = xoffset + 86; textpos = xoffset + 86;
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler); fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour); fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
@ -376,7 +347,7 @@ int svg_plot(struct zint_symbol *symbol)
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (46 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (46 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (48 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (48 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (92 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (92 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (94 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (94 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
textpart[0] = symbol->text[0]; textpart[0] = symbol->text[0];
textpart[1] = '\0'; textpart[1] = '\0';
textpos = -7; textpos = -7;
@ -404,7 +375,7 @@ int svg_plot(struct zint_symbol *symbol)
fprintf(fsvg, " </text>\n"); fprintf(fsvg, " </text>\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = xoffset + 114; textpos = xoffset + 114;
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler); fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour); fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
@ -422,12 +393,12 @@ int svg_plot(struct zint_symbol *symbol)
break; break;
} }
} }
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
/* guard bar extensions and text formatting for UPCA */ /* guard bar extensions and text formatting for UPCA */
latch = 1; latch = 1;
i = 0 + comp_offset; i = 0 + comp_offset;
do { do {
block_width = 0; block_width = 0;
@ -497,7 +468,7 @@ int svg_plot(struct zint_symbol *symbol)
fprintf(fsvg, " </text>\n"); fprintf(fsvg, " </text>\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = xoffset + 116; textpos = xoffset + 116;
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler); fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour); fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
@ -513,7 +484,7 @@ int svg_plot(struct zint_symbol *symbol)
break; break;
} }
} }
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
/* guard bar extensions and text formatting for UPCE */ /* guard bar extensions and text formatting for UPCE */
@ -547,7 +518,7 @@ int svg_plot(struct zint_symbol *symbol)
fprintf(fsvg, " </text>\n"); fprintf(fsvg, " </text>\n");
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = xoffset + 70; textpos = xoffset + 70;
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler); fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour); fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
@ -592,7 +563,7 @@ int svg_plot(struct zint_symbol *symbol)
} }
break; break;
} }
/* Put the human readable text at the bottom */ /* Put the human readable text at the bottom */
if(plot_text && (textdone == 0)) { if(plot_text && (textdone == 0)) {
textpos = symbol->width / 2.0; textpos = symbol->width / 2.0;
@ -603,12 +574,16 @@ int svg_plot(struct zint_symbol *symbol)
} }
fprintf(fsvg, " </g>\n"); fprintf(fsvg, " </g>\n");
fprintf(fsvg, "</svg>\n"); fprintf(fsvg, "</svg>\n");
fclose(fsvg); if(symbol->output_options & BARCODE_STDOUT) {
fflush(fsvg);
} else {
fclose(fsvg);
}
if (locale) if (locale)
setlocale(LC_ALL, locale); setlocale(LC_ALL, locale);
return error_number; return error_number;
} }

View File

@ -29,18 +29,18 @@
/* UPC and EAN tables checked against EN 797:1996 */ /* UPC and EAN tables checked against EN 797:1996 */
static char *UPCParity0[10] = {"BBBAAA", "BBABAA", "BBAABA", "BBAAAB", "BABBAA", "BAABBA", "BAAABB", static const char *UPCParity0[10] = {"BBBAAA", "BBABAA", "BBAABA", "BBAAAB", "BABBAA", "BAABBA", "BAAABB",
"BABABA", "BABAAB", "BAABAB"}; /* Number set for UPC-E symbol (EN Table 4) */ "BABABA", "BABAAB", "BAABAB"}; /* Number set for UPC-E symbol (EN Table 4) */
static char *UPCParity1[10] = {"AAABBB", "AABABB", "AABBAB", "AABBBA", "ABAABB", "ABBAAB", "ABBBAA", static const char *UPCParity1[10] = {"AAABBB", "AABABB", "AABBAB", "AABBBA", "ABAABB", "ABBAAB", "ABBBAA",
"ABABAB", "ABABBA", "ABBABA"}; /* Not covered by BS EN 797:1995 */ "ABABAB", "ABABBA", "ABBABA"}; /* Not covered by BS EN 797:1995 */
static char *EAN2Parity[4] = {"AA", "AB", "BA", "BB"}; /* Number sets for 2-digit add-on (EN Table 6) */ static const char *EAN2Parity[4] = {"AA", "AB", "BA", "BB"}; /* Number sets for 2-digit add-on (EN Table 6) */
static char *EAN5Parity[10] = {"BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA", static const char *EAN5Parity[10] = {"BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA",
"ABAAB", "AABAB"}; /* Number set for 5-digit add-on (EN Table 7) */ "ABAAB", "AABAB"}; /* Number set for 5-digit add-on (EN Table 7) */
static char *EAN13Parity[10] = {"AAAAA", "ABABB", "ABBAB", "ABBBA", "BAABB", "BBAAB", "BBBAA", "BABAB", static const char *EAN13Parity[10] = {"AAAAA", "ABABB", "ABBAB", "ABBBA", "BAABB", "BBAAB", "BBBAA", "BABAB",
"BABBA", "BBABA"}; /* Left hand of the EAN-13 symbol (EN Table 3) */ "BABBA", "BBABA"}; /* Left hand of the EAN-13 symbol (EN Table 3) */
static char *EANsetA[10] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213", static const char *EANsetA[10] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213",
"3112"}; /* Representation set A and C (EN Table 1) */ "3112"}; /* Representation set A and C (EN Table 1) */
static char *EANsetB[10] = {"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121", static const char *EANsetB[10] = {"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121",
"2113"}; /* Representation set B (EN Table 1) */ "2113"}; /* Representation set B (EN Table 1) */
char upc_check(char source[]) char upc_check(char source[])