Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 233 lines (200 sloc) 7.079 kb
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
1 /* lpescape.c */
2 /* Copyright 1995 by Steve Kirkendall */
3
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
4 char id_lpescape[] = "$Id: lpescape.c,v 2.14 1997/10/05 19:06:12 steve Exp $";
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
5
6
7 /* This file contains a driver for printer types which use escape sequences
8 * to select fonts. This includes the "epson", "hp", and "dumb" printer types.
9 */
10
11
12 #include "elvis.h"
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
13 #ifdef FEATURE_LPR
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
14
15 /* These values are used to index into the following table of escape codes */
16 typedef enum {BOLD, NOBOLD, UNDLN, NOUNDLN, ITALIC, NOITALIC, BEFORE, AFTER, GCMAP} CODE;
17
18 #if USE_PROTOTYPES
19 static void endfont(void);
20 static void before(int minorno, void (*draw)(_CHAR_));
21 static void fontch(_char_ font, _CHAR_ ch);
22 static void page(int linesleft);
23 static void after(int linesleft);
24 #endif
25
26 /* This table lists the escape codes used by each printer type */
27 static char *codes[][9] =
28 { /* BOLD NOBOLD UNDLN NOUNDLN ITALIC NOITALIC BEFORE AFTER GCMAP */
29 /*epson*/{"E", "F", "-1", "-0", "4", "5", NULL, NULL, "+++++++++-|*"},
30 /*pana*/ {"E", "F", "-1", "-0", "4", "5", "\033t1", "\033t0", "\300\301\331\303\305\264\332\302\277\304\263\371"},
31 /*ibm*/ {"E", "F", "-1", "-0", "4", "5", NULL, NULL, "\300\301\331\303\305\264\332\302\277\304\263\371"},
32 /*hp*/ {"(s3B","(s0B","&d1D", "&d@", "(s1S", "(s0S", "\033(10U", NULL, "\300\301\331\303\305\264\332\302\277\304\263\371"},
33 /*dumb*/ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "+++++++++-|*"}
34 };
35
36 /* This table is used for converting Latin-1 characters to PC-8 characters.
37 * This is necessary because the printer is placed in PC-8 mode so that it can
38 * output the graphic characters used by the <pre graphic> tag, and most
39 * computers these days use Latin-1 internally. This table only maps the
40 * Latin-1 characters within the range 0xa0-0xff; others don't need conversion.
41 * Some conversions are not exact.
42 */
43 static unsigned char topc8[] =
44 {
45 ' ', 0xad, 0x9b, 0x9c, '*', 0x9d, '|', 0xf5, '"', 0xe9, 0xa6, 0xae, 0xaa, '-', 'R', '~',
46 0xf8, 0xf1, 0xfd, '3', '\'', 0xe6, 0xf4, 0xf9, ',', '1', 0xa7, 0xaf, 0xac, 0xab, '3', 0xa8,
47 'A', 'A', 'A', 'A', 0x8e, 0x8f, 0x92, 0x80, 'E', 0x90, 'E', 'E', 'I', 'I', 'I', 'I',
48 'D', 0xa5, 'O', 'O', 'O', 'O', 0x99, 'x', 'O', 'U', 'U', 'U', 0x9a, 'Y', 0xe8, 0xe1,
49 0x85, 0xa0, 0x83, 'a', 0x84, 0x86, 0x91, 0x87, 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b,
50 0xeb, 0xa4, 0x95, 0xa2, 0x93, 'o', 0x94, 0xf6, 'o', 0x97, 0xa3, 0x97, 0x81, 'y', 0xe7, 'y'
51 };
52 static unsigned char *convert;
53
54 /* This value is the minor number of the driver being used. It is set by the
55 * before() function, and remains valid until the after() function returns.
56 */
57 static int ptype;
58
59 /* This is a pointer to the draw() function to use for outputing individual
60 * characters. It is set by the before() function, and remains valid until
61 * the after() function returns.
62 */
63 static void (*prtchar) P_((_CHAR_ ch));
64
65 /* This stores the font currently set for output */
66 static char curfont = 'n';
67
68
69 /* This function switches off a non-normal font */
70 static void endfont()
71 {
72 char *scan;
73
74 switch (curfont)
75 {
76 case 'e':
77 case 'b': scan = codes[ptype][NOBOLD]; break;
78 case 'u': scan = codes[ptype][NOUNDLN]; break;
79 case 'i': scan = codes[ptype][NOITALIC]; break;
80 default: scan = NULL;
81 }
82 if (scan)
83 {
84 (*prtchar)('\033');
85 while (*scan)
86 {
87 (*prtchar)((_CHAR_)*scan);
88 scan++;
89 }
90 }
91 }
92
93 /* This is the before() function. It sets the ptype index, outputs the
94 * BEFORE string if it isn't NULL, and sets the convert variable.
95 */
96 static void before(minorno, draw)
97 int minorno; /* which control codes to use */
98 void (*draw) P_((_CHAR_)); /* function for printing a single character */
99 {
100 char *scan;
101
102 assert(minorno < QTY(codes));
103
104 /* set the ptype and out function */
105 ptype = minorno;
106 prtchar = draw;
107 curfont = '\n';
108
109 /* if there is a BEFORE string, output it now */
110 for (scan = codes[ptype][BEFORE]; scan && *scan; scan++)
111 {
112 (*prtchar)((_CHAR_)*scan);
113 }
114
115 /* if the file appears to use Latin-1, and the lpconvert option is set,
116 * then set the convert pointer to point to the topc8[] array; else
117 * set the convert pointer to NULL.
118 */
119 if (o_lpconvert && digraph('A', 'E') == 0xc6)
120 {
121 convert = topc8;
122 }
123 else
124 {
125 convert = NULL;
126 }
127 }
128
129 /* This function outputs font-change strings, if necessary, and then outputs
130 * a character.
131 */
132 static void fontch(font, ch)
133 _char_ font; /* font of the next character from text image */
134 _CHAR_ ch; /* the next character */
135 {
136 char *scan;
137
138 /* is the font changing? */
139 if (font != curfont)
140 {
141 /* switch off a non-normal font, if we're in one */
142 endfont();
143
144 /* switch on a non-normal font, if we should be in one */
145 switch (font)
146 {
147 case 'e':
148 case 'b': scan = codes[ptype][BOLD]; break;
149 case 'u': scan = codes[ptype][UNDLN]; break;
150 case 'i': scan = codes[ptype][ITALIC]; break;
151 default: scan = NULL;
152 }
153 if (scan)
154 {
155 (*prtchar)('\033');
156 while (*scan)
157 {
158 (*prtchar)((_CHAR_)*scan);
159 scan++;
160 }
161 }
162
163 /* remember what font we just switched to. */
164 curfont = font;
165 }
166
167 /* if in graphic mode, convert graphic characters */
168 if (font == 'g' && codes[ptype][GCMAP])
169 {
170 switch (ch)
171 {
172 case '1': ch = codes[ptype][GCMAP][0]; break;
173 case '2': ch = codes[ptype][GCMAP][1]; break;
174 case '3': ch = codes[ptype][GCMAP][2]; break;
175 case '4': ch = codes[ptype][GCMAP][3]; break;
176 case '5': ch = codes[ptype][GCMAP][4]; break;
177 case '6': ch = codes[ptype][GCMAP][5]; break;
178 case '7': ch = codes[ptype][GCMAP][6]; break;
179 case '8': ch = codes[ptype][GCMAP][7]; break;
180 case '9': ch = codes[ptype][GCMAP][8]; break;
181 case '-': ch = codes[ptype][GCMAP][9]; break;
182 case '|': ch = codes[ptype][GCMAP][10]; break;
183 case '*': ch = codes[ptype][GCMAP][11]; break;
184 }
185 }
186 else if (convert && ch >= 0xa0)
187 {
188 ch = convert[ch - 0xa0];
189 }
190
191 /* output the character */
192 (*prtchar)(ch);
193 }
194
195 /* This function is called after every page except the last one */
196 static void page(linesleft)
197 int linesleft; /* number of lines remaining on page */
198 {
199 /* output a formfeed character */
200 (*prtchar)('\f');
201 }
202
203 /* This function is called at the end of the print job. It can output a
204 * final formfeed, restore fonts, or whatever. Here, it just outputs the
205 * AFTER string, if there is one.
206 */
207 static void after(linesleft)
208 int linesleft; /* number of lines remaining on final page */
209 {
210 char *scan;
211
212 /* if there is an AFTER string, output it now */
213 for (scan = codes[ptype][AFTER]; scan && *scan; scan++)
214 {
215 (*prtchar)((_CHAR_)*scan);
216 }
217
218 /* and maybe output a formfeed, too */
219 if (o_lpformfeed)
220 {
221 (*prtchar)((_CHAR_)'\f');
222 }
223 }
224
225 /* These describe the printer types supported by these functions */
226 LPTYPE lpepson ={"epson", 0, True, before, fontch, page, after};
227 LPTYPE lppana = {"pana", 1, True, before, fontch, page, after};
228 LPTYPE lpibm = {"ibm", 2, True, before, fontch, page, after};
229 LPTYPE lphp = {"hp", 3, True, before, fontch, page, after};
230 LPTYPE lpdumb = {"dumb", 4, True, before, fontch, page, after};
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
231
232 #endif /* FEATURE_LPR */
Something went wrong with that request. Please try again.