1 /* laserbar -- filter to print barcodes on postscript printer */
12 static int code39[256] = {
13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15 /* sp ! " # $ % & ' */
16 0304, 0, 0, 0, 0250, 0052, 0, 0,
18 0, 0, 0224, 0212, 0, 0205, 0604, 0242,
20 0064, 0441, 0141, 0540, 0061, 0460, 0160, 0045,
22 0444, 0144, 0, 0, 0, 0, 0, 0,
24 0, 0411, 0111, 0510, 0031, 0430, 0130, 0015,
26 0414, 0114, 0034, 0403, 0103, 0502, 0023, 0422,
28 0122, 0007, 0406, 0106, 0026, 0601, 0301, 0700,
30 0221, 0620, 0320, 0, 0, 0, 0, 0,
32 0, 0411, 0111, 0510, 0031, 0430, 0130, 0015,
34 0414, 0114, 0034, 0403, 0103, 0502, 0023, 0422,
36 0122, 0007, 0406, 0106, 0026, 0601, 0301, 0700,
37 /* x y z { | } ~ del */
38 0221, 0620, 0320, 0, 0, 0, 0, 0,
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
57 int c, flags = 0, error = 0;
58 double rotate = 0, xoffset = 0, yoffset = 0, xscale = 1, yscale = 1;
64 while ((c = getopt(argc, argv, "r:x:y:X:Y:lns")) != EOF) {
67 rotate = atof(optarg);
70 xoffset = atof(optarg);
73 yoffset = atof(optarg);
76 xscale = atof(optarg);
79 yscale = atof(optarg);
94 if ((argc - optind) != 1)
97 (void) fprintf(stderr,
98 "Usage: %s [-r rotate] [-x xoffset] [-y yoffset] [-X xscale] [-Y yscale] [-lns] string\n",
102 laserbar(stdout, argv[optind], rotate, xoffset, yoffset, xscale, yscale, flags);
108 static int right = 0;
111 laserbar(fp, str, rotate, xoffset, yoffset, xscale, yscale, flags)
114 double rotate, xoffset, yoffset, xscale, yscale;
119 (void) fprintf(fp, "gsave %s\n", (flags & NFLAG) ? "newpath" : "");
120 if (xoffset || yoffset)
121 (void) fprintf(fp, "%f %f moveto\n", xoffset, yoffset);
122 if (xscale != 1 || yscale != 1)
123 (void) fprintf(fp, "%f %f scale\n", xscale, yscale);
125 (void) fprintf(fp, "%f rotate\n", rotate);
126 (void) fputs("/Helvetica findfont 16 scalefont setfont\n", fp);
127 (void) fputs("/w { 0 rmoveto gsave 3 setlinewidth 0 -72 rlineto stroke grestore } def\n", fp);
128 (void) fputs("/n { 0 rmoveto gsave 1 setlinewidth 0 -72 rlineto stroke grestore } def\n", fp);
129 (void) fputs("/l { gsave 2 -88 rmoveto show grestore } def\n", fp);
132 barprt(fp, *(str++), (flags & LABEL));
134 (void) fprintf(fp, "%sgrestore\n", (flags & SFLAG) ? "showpage " : "");
143 int i, mask, bar, wide;
145 if (!(i = code39[c]))
150 (void) fprintf(fp, "(%c) l", c);
152 (void) fputs(" ", fp);
153 for (bar = 1, mask = 0400; mask; bar = 1 - bar, mask >>= 1) {
158 (void) fprintf(fp, " %d %s", right, wide ? "w" : "n");
159 right = (wide ? 2 : 1);
162 right += (wide ? 3 : 1);
164 (void) fputs("\n", fp);