2 * pcl.c -- printing the "partial" bar encoding in PCL format
4 * Copyright (c) 1999 Alessandro Rubini (rubini@gnu.org)
5 * Copyright (c) 1999 Prosa Srl. (prosa@prosa.it)
6 * Copyright (c) 2001 Andrea Scopece (a.scopece@tin.it)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
31 #define SHRINK_AMOUNT 0.15 /* shrink the bars to account for ink spreading */
35 * How do the "partial" and "textinfo" strings work? See file "ps.c"
39 int Barcode_pcl_print(struct Barcode_Item *bc, FILE *f)
42 double f1, f2, fsav=0;
43 int mode = '-'; /* text below bars */
44 double scalef=1, xpos, x0, y0, yr;
48 char font_id[6]; /* default font, should be "scalable" */
49 /* 0 Line printer, use on older LJet II, isn't scalable */
50 /* 4148 Univers, use on LJet III series, and Lj 4L, 5L */
51 /* 16602 Arial, default LJ family 4, 5, 6, Color, Djet */
53 if (!bc->partial || !bc->textinfo) {
59 * Maybe this first part can be made common to several printing back-ends,
60 * we'll see how that works when other ouput engines are added
63 /* First, calculate barlen */
64 barlen = bc->partial[0] - '0';
65 for (ptr = bc->partial+1; *ptr; ptr++)
67 barlen += (*ptr - '0');
68 else if (islower(*ptr))
69 barlen += (*ptr - 'a'+1);
71 /* The scale factor depends on bar length */
73 if (!bc->width) bc->width = barlen; /* default */
74 scalef = bc->scalef = (double)bc->width / (double)barlen;
77 /* The width defaults to "just enough" */
78 if (!bc->width) bc->width = barlen * scalef +1;
80 /* But it can be too small, in this case enlarge and center the area */
81 if (bc->width < barlen * scalef) {
82 int wid = barlen * scalef + 1;
83 bc->xoff -= (wid - bc->width)/2 ;
85 /* Can't extend too far on the left */
87 bc->width += -bc->xoff;
92 /* The height defaults to 80 points (rescaled) */
93 if (!bc->height) bc->height = 80 * scalef;
96 /* If too small (5 + text), enlarge and center */
97 i = 5 + 10 * ((bc->flags & BARCODE_NO_ASCII)==0);
98 if (bc->height < i * scalef ) {
100 bc->yoff -= (hei-bc->height)/2;
103 bc->height += -bc->yoff;
108 /* If too small (5 + text), reduce the scale factor and center */
109 i = 5 + 10 * ((bc->flags & BARCODE_NO_ASCII)==0);
110 if (bc->height < i * scalef ) {
111 double scaleg = ((double)bc->height) / i;
112 int wid = bc->width * scaleg / scalef;
113 bc->xoff += (bc->width - wid)/2;
120 * deal with PCL output
123 xpos = bc->margin + (bc->partial[0]-'0') * scalef;
124 for (ptr = bc->partial+1, i=1; *ptr; ptr++, i++) {
125 /* special cases: '+' and '-' */
126 if (*ptr == '+' || *ptr == '-') {
127 mode = *ptr; /* don't count it */ i++; continue;
130 /* j is the width of this bar/space */
131 if (isdigit (*ptr)) j = *ptr-'0';
134 x0 = bc->xoff + xpos;
135 y0 = bc->yoff + bc->margin;
137 if (!(bc->flags & BARCODE_NO_ASCII)) { /* leave space for text */
139 /* text below bars: 10 points or five points */
140 yr -= (isdigit(*ptr) ? 10 : 5) * scalef;
142 /* text above bars: 10 or 0 from bottom, and 10 from top */
143 y0 += (isdigit(*ptr) ? 10 : 0) * scalef;
144 yr -= (isdigit(*ptr) ? 20 : 10) * scalef;
148 fprintf(f,"%c&a%.0fH", 27, x0 * 10.0);
149 fprintf(f,"%c&a%.0fV", 27, y0 * 10.0);
150 fprintf(f,"%c*c%.0fH", 27, ((j*scalef)-SHRINK_AMOUNT) * 10.0);
151 fprintf(f,"%c*c%.0fV", 27, yr * 10.0);
152 fprintf(f,"%c*c0P\n", 27);
159 mode = '-'; /* reinstantiate default */
160 if (!(bc->flags & BARCODE_NO_ASCII)) {
161 k=0; /* k is the "previous font size" */
162 for (ptr = bc->textinfo; ptr; ptr = strchr(ptr, ' ')) {
163 while (*ptr == ' ') ptr++;
165 if (*ptr == '+' || *ptr == '-') {
166 mode = *ptr; continue;
168 if (sscanf(ptr, "%lf:%lf:%c", &f1, &f2, &c) != 3) {
169 fprintf(stderr, "barcode: impossible data: %s\n", ptr);
173 /* select a Scalable Font */
177 if ((bc->flags & BARCODE_OUT_PCL_III) == BARCODE_OUT_PCL_III)
178 { strcpy(font_id, "4148"); /* font Univers */
181 { strcpy(font_id, "16602"); /* font Arial */
184 fprintf(f,"%c(8U%c(s1p%5.2fv0s0b%sT", 27, 27, f2 * scalef, font_id);
188 fprintf(f,"%c&a%.0fH", 27, (bc->xoff + f1 * scalef + bc->margin) * 10.0);
189 fprintf(f,"%c&a%.0fV", 27,
191 ? ((double)bc->yoff + bc->margin + 8*scalef) * 10.0
192 : ((double)bc->yoff + bc->margin + bc->height ) * 10.0);