/* * COPYRIGHT 1999 * * Mika Seppa * Low Temperature Laboratory * Helsinki University of Technology * SF-02150 Espoo * FINLAND * * http://neuro.hut.fi/~mseppa/ * * * The program is provided as is and the author makes no warranty of any * kind with regard to the program, to any modified version of it, or to * the labels created by any version of the program, including, but not * limited to, the implied warranties of merchantability and fitness for * a particular use. The author shall not be liable for errors contained * in the program or in the labels or for incidental or consequential * damages in connection with the furnishing, performance, or use of * them. In no event shall the author be liable for any claim, damages or * other liability, whether in an action of contract, tort or otherwise, * arising from, out of or in connection with the program or the labels * created by it. * * The program and the labels created by the program are free for any * non-commercial use. The program and the created bar code labels can be * used freely as long as no cost (in terms of money or otherwise) is * charged for the delivery or use of the program or the labels created * by the program. The program may be modified to produce labels for your * specific needs as long as the modified program clearly states that it * is a modification of the original. The modified program and the labels * created by the modified program must also be free and no cost may be * charged for the modified program or for the labels created by it. * */ #include #include #define NumberOf(xx) (sizeof(xx)/sizeof(xx[0])) #define MM(x) ((x)*72.0/25.4) #define XCOUNT 3 #define YCOUNT 10 #define XSPACE MM(10) #define YSPACE MM(0) #define XOFF MM(10) #define YOFF MM(35) #define THIN 1.0 #define THICK 3.0 #define SLEN (6.0*THIN+3.0*THICK) #define SHEIGHT (MM(line_pos[0])-MM(line_pos[1])) #define START_SYMBOL '*' #define END_SYMBOL '*' #define SYMBOLS 6 #define WIDTH MM(56.0) #define HEIGHT MM(21.0) #define BORDER_LW "0" #define LINES_LW "2" typedef struct { char c; int bars; int spaces; } CodeRec, *Code; CodeRec codes[] = { { '0', 0x06, 0x04 }, { '1', 0x11, 0x04 }, { '2', 0x09, 0x04 }, { '3', 0x18, 0x04 }, { '4', 0x05, 0x04 }, { '5', 0x14, 0x04 }, { '6', 0x0c, 0x04 }, { '7', 0x03, 0x04 }, { '8', 0x12, 0x04 }, { '9', 0x0a, 0x04 }, { 'A', 0x11, 0x02 }, { 'B', 0x09, 0x02 }, { 'C', 0x18, 0x02 }, { 'D', 0x05, 0x02 }, { 'E', 0x14, 0x02 }, { 'F', 0x0c, 0x02 }, { 'G', 0x03, 0x02 }, { 'H', 0x12, 0x02 }, { 'I', 0x0a, 0x02 }, { 'J', 0x06, 0x02 }, { 'K', 0x11, 0x01 }, { 'L', 0x09, 0x01 }, { 'M', 0x18, 0x01 }, { 'N', 0x05, 0x01 }, { 'O', 0x14, 0x01 }, { 'P', 0x0c, 0x01 }, { 'Q', 0x03, 0x01 }, { 'R', 0x12, 0x01 }, { 'S', 0x0a, 0x01 }, { 'T', 0x06, 0x01 }, { 'U', 0x11, 0x08 }, { 'V', 0x09, 0x08 }, { 'W', 0x18, 0x08 }, { 'X', 0x05, 0x08 }, { 'Y', 0x14, 0x08 }, { 'Z', 0x0c, 0x08 }, { '-', 0x03, 0x08 }, { '.', 0x12, 0x08 }, { ' ', 0x0a, 0x08 }, { '$', 0x00, 0x0e }, { '/', 0x00, 0x0d }, { '+', 0x00, 0x0b }, { '%', 0x00, 0x07 }, { '*', 0x06, 0x08 } }; int line_pos[] = { 14.0, 6.0, 2.0 }; char *ps_header = "%!PS-Adobe-3.0\n\ %%Pages: 1\n\ %%EndComments\n\ %%BeginProlog\n\ %%EndProlog\n\ %%BeginSetup\n\ /Helvetica findfont 18 scalefont setfont\n\ /cshow { dup stringwidth pop -0.5 mul 0 rmoveto show } def\n\ %%EndSetup\n\ %%Page: 1 1\n\ %%BeginPageSetup\n\ %%EndPageSetup\n"; char *ps_trailer = "%%PageTrailer\n\ showpage\n\ %%Trailer\n\ %%EOF\n"; void print_bar(FILE *fp, float xoff, float yoff, float xsize, float ysize) { fprintf(fp, "newpath %g %g moveto %g 0 rlineto 0 %g rlineto\n", xoff, yoff, xsize, ysize); fprintf(fp, "%g 0 rlineto 0 %g rlineto closepath fill\n", -xsize, -ysize); } int find_code(char s) { int i; for(i=0;ibars&mask?THICK:THIN); mask>>=1; print_bar(fp, xoff, yoff, f, SHEIGHT); xoff += f + (c->spaces&mask?THICK:THIN); } return j; } void print_label(FILE *fp, float xoff, float yoff, char txt[SYMBOLS], int ccount, int csum) { int i, j, c=0; float f, g; if (ccount) { f = WIDTH*(float)ccount/(float)SYMBOLS; g = HEIGHT-MM(line_pos[0]); fprintf(fp, "0.8 setgray newpath %g %g moveto\n", xoff,yoff+MM(line_pos[0])); fprintf(fp, "%g 0 rlineto 0 %g rlineto %g 0 rlineto 0 %g rlineto\n", f, g, -f, -g); fprintf(fp, "fill 0 setgray\n"); } fprintf(fp, BORDER_LW" setlinewidth newpath %g %g moveto\n", xoff, yoff); fprintf(fp, "%g 0 rlineto 0 %g rlineto %g 0 rlineto 0 %g rlineto\n", WIDTH, HEIGHT, -WIDTH, -HEIGHT); fprintf(fp, "closepath stroke\n"); for(i=0;i0;) if (!isdigit(s[i]) && (!hexmode || s[i]<'A' || s[i]>'F')) break; ret = SYMBOLS - i - 1; } return ret; } int next_label(char txt[SYMBOLS], int numbers, int hexmode) { int i, c=1, j; for(i=0,j=SYMBOLS-1;c&&(i1 && strcmp(argv[1], "-c")==0) csum=1; if (argc>(1+csum) && strcmp(argv[1+csum], "-h")==0) hexmode=1; if (!csum && argc>(1+hexmode) && strcmp(argv[1+hexmode], "-c")==0) csum=1; if (argc<(2+csum+hexmode)) { fprintf(stderr, "Usage: %s [-c] [-h] label [outfile.ps]\n", argv[0]); fprintf(stderr, " -c : Use checksum in the barcode.\n"); fprintf(stderr, " -h : Increment in hexadecimals.\n"); exit(0); } if ((numbers=check_string(argv[1+csum+hexmode], hexmode))<0) exit(1); memcpy(txt, argv[1+csum+hexmode], SYMBOLS); if (numbers!=4) fprintf(stderr, "Warning: Use 2 alpha and 4 digit characters for HP DLT Tape Library!\n"); if (argc>(2+csum+hexmode) && (fp=fopen(argv[2+csum+hexmode], "w"))==NULL) { fprintf(stderr, "Error: Cannot open file %s for writing.\n", argv[2+csum+hexmode]); exit(2); } fputs(ps_header, fp); for(x=0;c&&(x