Annotation of OpenXM_contrib/gnuplot/term/hpgl.trm, Revision 1.1.1.2
1.1 maekawa 1: /*
1.1.1.2 ! maekawa 2: * $Id: hpgl.trm,v 1.7 1998/12/14 18:39:49 lhecking Exp $
1.1 maekawa 3: */
4:
5: /* GNUPLOT - hpgl.trm */
6:
7: /*[
8: * Copyright 1990 - 1993, 1998
9: *
10: * Permission to use, copy, and distribute this software and its
11: * documentation for any purpose with or without fee is hereby granted,
12: * provided that the above copyright notice appear in all copies and
13: * that both that copyright notice and this permission notice appear
14: * in supporting documentation.
15: *
16: * Permission to modify the software is granted, but not the right to
17: * distribute the complete modified source code. Modifications are to
18: * be distributed as patches to the released version. Permission to
19: * distribute binaries produced by compiling modified sources is granted,
20: * provided you
21: * 1. distribute the corresponding source modifications from the
22: * released version in the form of a patch file along with the binaries,
23: * 2. add special version identification to distinguish your version
24: * in addition to the base release version number,
25: * 3. provide your name and address as the primary contact for the
26: * support of your modified version, and
27: * 4. retain our contact information in regard to use of the base
28: * software.
29: * Permission to distribute the released version of the source code along
30: * with corresponding source modifications in the form of a patch file is
31: * granted with same provisions 2 through 4 for binary distributions.
32: *
33: * This software is provided "as is" without express or implied warranty
34: * to the extent permitted by applicable law.
35: ]*/
36:
37: /*
38: * This file is included by ../term.c.
39: *
40: * This terminal driver supports:
41: * hpgl, hp7550, hp7580b, HP Laserjet III
42: * hp7550 has been replaced by "hpgl 8 eject"
43: * hp7580b has been replaced by "hpgl 4"
44: *
45: * AUTHORS
46: * Colin Kelley, Thomas Williams, Russell Lang
47: *
48: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
49: *
50: */
51:
52: /*
53: *
54: * MODIFIED for expanded HPGL/2 and PCL utilites
55: * Tom Swiler (tom@silica.mse.ufl.edu)
56: * Modified June 1995 Ian MacPhedran to support newterm format
57: * Modified October 1995 Ian MacPhedran to simplify HPGL terminals
58: * Modified January 96 by David Denholm and Emmanuel Bigler for cp850
59: * and iso international character sets
60: */
61: #define HPGL
62: #define PCL
63:
64: #include "driver.h"
65:
66: #ifdef TERM_REGISTER
67: register_term(hpgl)
68: register_term(pcl5)
69: #endif /* TERM_REGISTER */
70:
71: #ifdef TERM_PROTO
72: TERM_PUBLIC void HPGL_options __PROTO((void));
73: TERM_PUBLIC void HPGL2_options __PROTO((void));
74: TERM_PUBLIC void PCL_options __PROTO((void));
75: TERM_PUBLIC void HPGL_init __PROTO((void));
76: /* TERM_PUBLIC void HPGL2_init __PROTO((void)); */
77: TERM_PUBLIC void PCL_init __PROTO((void));
78: TERM_PUBLIC void HPGL_graphics __PROTO((void));
79: TERM_PUBLIC void HPGL2_graphics __PROTO((void));
80: TERM_PUBLIC void PCL_graphics __PROTO((void));
81: TERM_PUBLIC void HPGL_text __PROTO((void));
82: /* TERM_PUBLIC void HPGL2_text __PROTO((void)); */
83: TERM_PUBLIC void PCL_text __PROTO((void));
84: TERM_PUBLIC void HPGL_linetype __PROTO((int linetype));
85: TERM_PUBLIC void HPGL2_linetype __PROTO((int linetype));
86: TERM_PUBLIC void HPGL_put_text __PROTO((unsigned int x, unsigned int y, char *str));
87: TERM_PUBLIC void HPGL2_put_text __PROTO((unsigned int x, unsigned int y, char *str));
88: TERM_PUBLIC void HPGL_move __PROTO((unsigned int x, unsigned int y));
89: TERM_PUBLIC void HPGL_vector __PROTO((unsigned int x, unsigned int y));
90: TERM_PUBLIC void HPGL2_move __PROTO((unsigned int x, unsigned int y));
91: TERM_PUBLIC void HPGL2_vector __PROTO((unsigned int x, unsigned int y));
92: TERM_PUBLIC void HPGL2_encode __PROTO((int d));
93: TERM_PUBLIC int HPGL_text_angle __PROTO((int ang));
94: TERM_PUBLIC int HPGL2_text_angle __PROTO((int ang));
95: TERM_PUBLIC void HPGL_reset __PROTO((void));
96: /* TERM_PUBLIC void HPGL2_reset __PROTO((void)); */
97: TERM_PUBLIC void PCL_reset __PROTO((void));
98: TERM_PUBLIC int HPGL2_justify_text __PROTO((enum JUSTIFY just));
99: #define GOT_HPGL_PROTO
100: #endif /* TERM_PROTO */
101:
102: #ifndef TERM_PROTO_ONLY
103: #ifdef TERM_BODY
104: /*
105: * The maximum plot size, in plotter units:
106: */
107:
108: #define HPGL_PUPI 1016 /* Plotter units per inch */
109:
110: #define HPGL_XMAX_A 10000
111: #define HPGL_YMAX_A 7500
112:
113: #define HPGL_XMAX_B 15200
114: #define HPGL_YMAX_B 10000
115:
116: #define HPGL_XMAX HPGL_XMAX_A
117: #define HPGL_YMAX HPGL_YMAX_A
118:
119: #define PCL_XMAX HPGL_XMAX_A
120: #define PCL_YMAX (HPGL_YMAX_A-60)
121:
122: /*
123: * Tic sizes
124: */
125:
126: #define HPGL_VTIC (HPGL_YMAX/70)
127: #define HPGL_HTIC (HPGL_YMAX/70)
128:
129: #define PCL_VTIC (PCL_YMAX/70)
130: #define PCL_HTIC (PCL_YMAX/70)
131:
132: /*
133: * Font size for HPGL
134: */
135:
136: #define HPGL_VCHAR (HPGL_YMAX/100*32/10) /* 3.2% */
137: #define HPGL_HCHAR (HPGL_XMAX/100*12/10) /* 1.2% */
138:
139: /*
140: * Font size for HPGL/2
141: */
142:
143: #define HPGL2_DEF_POINT 14 /* Height of font */
144:
145: #define HPGL2_DEF_PITCH (3 * 72 / (HPGL2_DEF_POINT * 2))
146: #define HPGL2_VCHAR ((int) HPGL_PUPI * HPGL2_DEF_POINT / 72)
147: #define HPGL2_HCHAR (HPGL2_VCHAR * 2 / 3)
148:
149: /*
150: * Control constants
151: */
152:
153: #define DOWN 0 /* Pen is down */
154: #define UP 1 /* Pen is up */
155: #define UNKNOWN -10 /* Unknown status for lots of things */
156:
157: /*
158: * For Polyline Encoded, either use base 64 or base 32.
159: * Save space with base 64, but get 8-bit characters.
160: */
161:
162: #ifdef NEXT
163: /* unluckily TRUE is defined as ((boolean_t)1) in mach/boolean.h */
164: #define HPGL2_BASE64 1
165: #else
166: #define HPGL2_BASE64 TRUE
167: #endif
168:
169: #if HPGL2_BASE64
170: #define HPGL2_BITS 6
171: #define HPGL2_LOW_OFFS 63
172: #define HPGL2_HIGH_OFFS 191
173: #define HPGL2_MASK 63
174: #else
175: #define HPGL2_BITS 5
176: #define HPGL2_LOW_OFFS 63
177: #define HPGL2_HIGH_OFFS 95
178: #define HPGL2_MASK 31
179: #endif
180:
181: /*
182: * Data structures for options
183: */
184:
185: struct HPGL2_font_str {
186: char *compare, *name;
187: int symbol_set, spacing;
188: double pitch, height;
189: int posture, stroke_weight, typeface;
190: };
191:
192: struct PCL_mode_str {
193: char *compare, *name, *command;
194: int xmax, ymax;
195: };
196:
197: /*
198: * The default font goes first. Although it is the ugliest, the
199: * stick font is probably supported by the most devices, so it
200: * becomes the default.
201: */
202:
203: static struct HPGL2_font_str GPFAR HPGL2_font_table[] =
204: {
205: {"u$nivers", "univers", 277, 1, 0.0, HPGL2_DEF_POINT, 0, 0, 4148},
206: {"s$tick", "stick", 277, 0, HPGL2_DEF_PITCH, 0.0, 0, 0, 48},
207: {"c$g_times", "cg_times", 277, 1, 0.0, HPGL2_DEF_POINT, 0, 0, 4101}
208: };
209:
210: #define HPGL2_FONTS (sizeof(HPGL2_font_table) / sizeof (struct HPGL2_font_str))
211: static struct HPGL2_font_str *HPGL2_font = &HPGL2_font_table[0];
212:
213: /*
214: * The default mode goes first. Landscape style plots are probably the
215: * most compatable with other HPGL devices.
216: */
217:
218: static struct PCL_mode_str GPFAR PCL_mode_table[] =
219: {
220: {"l$andscape", "landscape", "\033&l1O", PCL_XMAX, PCL_YMAX},
221: {"p$ortrait", "portrait", "\033&l0O", PCL_YMAX, PCL_XMAX}
222: };
223:
224: #define PCL_MODES (sizeof(PCL_mode_table) / sizeof (struct PCL_mode_str))
225: static struct PCL_mode_str *PCL_mode = &PCL_mode_table[0];
226:
227: /*
228: * Various line types and widths to distinguish data sets
229: */
230:
231: static char *HPGL2_lt[] = { "", "4,2", "5,2", "6,2", "7,2", "8,2" },
232: *HPGL2_pw[] = { ".15", ".12", ".08" };
233:
234: #define HPGL2_LINETYPES (sizeof(HPGL2_lt) / sizeof(char *))
235: #define HPGL2_PENWIDTHS (sizeof(HPGL2_pw) / sizeof(char *))
236:
237: /* encoding vector for cp850 , characters 128 (0200) -> 255 (0377) */
238:
239: static char hpgl_cp_850[128][4] =
240: {
241:
242: /* 0200 */ "\0164\017",
243: /* 0201 */ "\016O\017",
244: /* 0202 */ "\016E\017",
245: /* 0203 */ "\016@\017",
246: /* 0204 */ "\016L\017",
247: /* 0205 */ "\016H\017",
248: /* 0206 */ "\016T\017",
249: /* 0207 */ "\0165\017",
250:
251: /* 0210 */ "\016A\017",
252: /* 0211 */ "\016M\017",
253: /* 0212 */ "\016I\017",
254: /* 0213 */ "\016]\017",
255: /* 0214 */ "\016Q\017",
256: /* 0215 */ "\016Y\017",
257: /* 0216 */ "\016X\017",
258: /* 0217 */ "\016P\017",
259:
260: /* 0220 */ "\016\134\017",
261: /* 0221 */ "\016W\017",
262: /* 0222 */ "\016S\017",
263: /* 0223 */ "\016B\017",
264: /* 0224 */ "\016N\017",
265: /* 0225 */ "\016J\017",
266: /* 0226 */ "\016C\017",
267: /* 0227 */ "\016K\017",
268:
269: /* 0230 */ "\016o\017",
270: /* 0231 */ "\016Z\017",
271: /* 0232 */ "\016[\017",
272: /* 0233 */ "\016V\017",
273: /* 0234 */ "\016;\017",
274: /* 0235 */ "\016R\017",
275: /* 0236 */ "",
276: /* 0237 */ "\016>\017",
277:
278: /* 0240 */ "\016D\017",
279: /* 0241 */ "\016U\017",
280: /* 0242 */ "\016F\017",
281: /* 0243 */ "\016G\017",
282: /* 0244 */ "\0167\017",
283: /* 0245 */ "\0166\017",
284: /* 0246 */ "\016y\017",
285: /* 0247 */ "\016z\017",
286:
287: /* 0250 */ "\0169\017",
288:
289: /* 0251 */ "",
290: /* 0252 */ "",
291:
292: /* 0253 */ "\016x\017",
293: /* 0254 */ "\016w\017",
294: /* 0255 */ "\0168\017",
295: /* 0256 */ "\016{\017",
296: /* 0257 */ "\016}\017",
297:
298: /* 0260 */ "",
299: /* 0261 */ "",
300: /* 0262 */ "",
301: /* 0263 */ "",
302: /* 0264 */ "",
303:
304: /* 0265 */ "\016`\017",
305: /* 0266 */ "\016\042\017",
306: /* 0267 */ "\016!\017",
307:
308: /* 0270 */ "",
309: /* 0271 */ "",
310: /* 0272 */ "",
311: /* 0273 */ "",
312: /* 0274 */ "",
313:
314: /* 0275 */ "\016?\017",
315: /* 0276 */ "\016<\017",
316:
317: /* 0277 */ "",
318:
319: /* 0300 */ "",
320: /* 0301 */ "",
321: /* 0302 */ "",
322: /* 0303 */ "",
323: /* 0304 */ "",
324: /* 0305 */ "",
325:
326: /* 0306 */ "\016b\017",
327: /* 0307 */ "\016a\017",
328:
329: /* 0310 */ "",
330: /* 0311 */ "",
331: /* 0312 */ "",
332: /* 0313 */ "",
333: /* 0314 */ "",
334: /* 0315 */ "",
335: /* 0316 */ "",
336:
337: /* 0317 */ "\016:\017",
338:
339: /* 0320 */ "\016d\017",
340: /* 0321 */ "\016c\017",
341: /* 0322 */ "\016$\017",
342: /* 0323 */ "\016%\017",
343: /* 0324 */ "\016#\017",
344:
345: /* 0325 */ "",
346:
347: /* 0326 */ "\016e\017",
348: /* 0327 */ "\016&\017",
349:
350: /* 0330 */ "\016'\017",
351:
352: /* 0331 */ "",
353: /* 0332 */ "",
354: /* 0333 */ "",
355: /* 0334 */ "",
356: /* 0335 */ "",
357:
358: /* 0336 */ "\016f\017",
359: /* 0337 */ "",
360:
361: /* 0340 */ "\016g\017",
362: /* 0341 */ "\016^\017",
363: /* 0342 */ "\016_\017",
364: /* 0343 */ "\016h\017",
365: /* 0344 */ "\016j\017",
366: /* 0345 */ "\016i\017",
367: /* 0346 */ "",
368: /* 0347 */ "\016q\017",
369:
370: /* 0350 */ "\016p\017",
371: /* 0351 */ "\016m\017",
372: /* 0352 */ "\016.\017",
373: /* 0353 */ "\016-\017",
374: /* 0354 */ "",
375: /* 0355 */ "",
376: /* 0356 */ "\0160\017",
377: /* 0357 */ "\016(\017",
378:
379: /* 0360 */ "\016v\017",
380: /* 0361 */ "\016~\017",
381: /* 0362 */ "",
382: /* 0363 */ "",
383: /* 0364 */ "",
384: /* 0365 */ "\016=\017",
385: /* 0366 */ "",
386: /* 0367 */ "",
387:
388: /* 0370 */ "\016z\017",
389: /* 0371 */ "\016+\017",
390: /* 0372 */ "",
391: /* 0373 */ "",
392: /* 0374 */ "",
393: /* 0375 */ "",
394: /* 0376 */ "",
395: /* 0377 */ ""
396: };
397:
398:
399: /* encoding vector for iso-8859-1 , characters 128 (0200) -> 255 (0377) */
400:
401: static char hpgl_iso_8859_1[128][4] =
402: {
403:
404: /* 0200 */ "",
405: /* 0201 */ "",
406: /* 0202 */ "",
407: /* 0203 */ "",
408: /* 0204 */ "",
409: /* 0205 */ "",
410: /* 0206 */ "",
411: /* 0207 */ "",
412:
413: /* 0210 */ "",
414: /* 0211 */ "",
415: /* 0212 */ "",
416: /* 0213 */ "",
417: /* 0214 */ "",
418: /* 0215 */ "",
419: /* 0216 */ "",
420: /* 0217 */ "",
421:
422: /* 0220 */ "",
423: /* 0221 */ "\016\017",
424: /* 0222 */ "\016\017",
425: /* 0223 */ "",
426: /* 0224 */ "",
427: /* 0225 */ "",
428: /* 0226 */ "",
429: /* 0227 */ "",
430:
431: /* 0230 */ "",
432: /* 0231 */ "",
433: /* 0232 */ "",
434: /* 0233 */ "",
435: /* 0234 */ "",
436: /* 0235 */ "",
437: /* 0236 */ "",
438: /* 0237 */ "",
439:
440: /* 0240 */ "",
441: /* 0241 */ "\0168\017",
442: /* 0242 */ "\0165\017",
443: /* 0243 */ "\016;\017",
444: /* 0244 */ "\016:\017",
445: /* 0245 */ "\016<\017",
446: /* 0246 */ "\017|\017",
447: /* 0247 */ "\016=\017",
448:
449: /* 0250 */ "\016+\017",
450: /* 0251 */ "",
451: /* 0252 */ "\016y\017",
452: /* 0253 */ "\016{\017",
453: /* 0254 */ "",
454: /* 0255 */ "",
455: /* 0256 */ "",
456: /* 0257 */ "\0160\017",
457:
458: /* 0260 */ "\016z\017",
459: /* 0261 */ "\016~\017",
460: /* 0262 */ "",
461: /* 0263 */ "",
462: /* 0264 */ "",
463: /* 0265 */ "",
464: /* 0266 */ "",
465: /* 0267 */ "",
466:
467: /* 0270 */ "",
468: /* 0271 */ "",
469: /* 0272 */ "\016z\017",
470: /* 0273 */ "\016}\017",
471: /* 0274 */ "\016w\017",
472: /* 0275 */ "\016x\017",
473: /* 0276 */ "",
474: /* 0277 */ "\0169\017",
475:
476: /* 0300 */ "\016!\017",
477: /* 0301 */ "\016`\017",
478: /* 0302 */ "\016\042\017",
479: /* 0303 */ "\016a\017",
480: /* 0304 */ "\016X\017",
481: /* 0305 */ "\016P\017",
482: /* 0306 */ "\016S\017",
483: /* 0307 */ "\0164\017",
484:
485: /* 0310 */ "\016#\017",
486: /* 0311 */ "\016\134\017",
487: /* 0312 */ "\016$\017",
488: /* 0313 */ "\016%\017",
489: /* 0314 */ "\016f\017",
490: /* 0315 */ "\016e\017",
491: /* 0316 */ "\016\046\017",
492: /* 0317 */ "\016'\017",
493:
494: /* 0320 */ "\016c\017",
495: /* 0321 */ "\0166\017",
496: /* 0322 */ "\016h\017",
497: /* 0323 */ "\016g\017",
498: /* 0324 */ "\016_\017",
499: /* 0325 */ "\016i\017",
500: /* 0326 */ "\016Z\017",
501: /* 0327 */ "",
502:
503: /* 0330 */ "\016R\017",
504: /* 0331 */ "\016-\017",
505: /* 0332 */ "\016m\017",
506: /* 0333 */ "\016.\017",
507: /* 0334 */ "\016[\017",
508: /* 0335 */ "",
509: /* 0336 */ "\016p\017",
510: /* 0337 */ "\016^\017",
511:
512: /* 0340 */ "\016H\017",
513: /* 0341 */ "\016D\017",
514: /* 0342 */ "\016@\017",
515: /* 0343 */ "\016b\017",
516: /* 0344 */ "\016L\017",
517: /* 0345 */ "\016T\017",
518: /* 0346 */ "\016W\017",
519: /* 0347 */ "\0165\017",
520:
521: /* 0350 */ "\016I\017",
522: /* 0351 */ "\016E\017",
523: /* 0352 */ "\016A\017",
524: /* 0353 */ "\016M\017",
525: /* 0354 */ "\016Y\017",
526: /* 0355 */ "\016U\017",
527: /* 0356 */ "\016Q\017",
528: /* 0357 */ "\016]\017",
529:
530: /* 0360 */ "\016d\017",
531: /* 0361 */ "\0167\017",
532: /* 0362 */ "\016J\017",
533: /* 0363 */ "\016F\017",
534: /* 0364 */ "\016B\017",
535: /* 0365 */ "\016j\017",
536: /* 0366 */ "\016N\017",
537: /* 0367 */ "",
538:
539: /* 0370 */ "\016V\017",
540: /* 0371 */ "\016K\017",
541: /* 0372 */ "\016G\017",
542: /* 0373 */ "\016C\017",
543: /* 0374 */ "\016O\017",
544: /* 0375 */ "",
545: /* 0376 */ "\016q\017",
546: /* 0377 */ "\016o\017"
547: };
548:
549:
550: /*
551: * Static variables to keep track of where we are, etc.
552: */
553:
554: static int HPGL_ang = 0, HPGL_x = UNKNOWN, HPGL_y = UNKNOWN, HPGL_penstate = UNKNOWN, HPGL_pentype
555: = UNKNOWN, HPGL2_in_pe, HPGL2_lost;
556:
557: /*
558: * The subroutines, grouped by function for different versions.
559: */
560:
561: static int HPGL_numpen, HPGL_eject;
562:
563: TERM_PUBLIC void HPGL_options()
564: {
565: HPGL_numpen = 6; /* default to six pens */
566: HPGL_eject = 0; /* default to no eject */
567:
568: while (!END_OF_COMMAND) {
569: if (almost_equals(c_token, "eje$ct"))
570: HPGL_eject = 1;
571: else if (isanumber(c_token)) {
572: HPGL_numpen = (int) real(&token[c_token].l_val);
573: if (HPGL_numpen <= 0) {
574: HPGL_numpen = 6;
575: int_error("Number of pens must be positive", c_token);
576: }
577: } else
578: int_error("expecting \"eject\" or number of pens", c_token);
579:
580: c_token++;
581: }
582:
583:
584: sprintf(term_options, "%d pens %s", HPGL_numpen,
585: HPGL_eject ? "eject" : "noeject");
586: }
587:
588: TERM_PUBLIC void HPGL2_options()
589: {
590: struct termentry *t = term;
591: int i;
592: double point_size;
593: char tmp_options[MAX_ID_LEN];
594: if (!END_OF_COMMAND) {
595: for (i = 0; i < HPGL2_FONTS &&
596: !almost_equals(c_token, HPGL2_font_table[i].compare); i++);
597: if (i < HPGL2_FONTS) {
598: HPGL2_font = &HPGL2_font_table[i];
599: } else
600: int_error("expecting font: stick, cg_times, or univers", c_token);
601: c_token++;
602: if (!END_OF_COMMAND) {
603: if ((point_size = real(&token[c_token].l_val)) > 0.0) {
604: t->v_char = (int) HPGL_PUPI *point_size / 72;
605: t->h_char = t->v_char * 2 / 3;
606: if (HPGL2_font->spacing)
607: HPGL2_font->height = point_size;
608: else
609: HPGL2_font->pitch = 72 * 3 / (point_size * 2);
610: } else
611: int_error("expecting font point size: real number", c_token);
612: c_token++;
613: }
614: }
615: sprintf(tmp_options, " %s", HPGL2_font->name);
616: strcat(term_options, tmp_options);
617: if (HPGL2_font->spacing) {
618: sprintf(tmp_options, " %f",
619: HPGL2_font->height);
620: strcat(term_options, tmp_options);
621: } else {
622: sprintf(tmp_options, " %f",
623: HPGL2_font->pitch);
624: strcat(term_options, tmp_options);
625: }
626: }
627:
628: TERM_PUBLIC void PCL_options()
629: {
630: int i;
631: if (!END_OF_COMMAND) {
632: for (i = 0; i < PCL_MODES &&
633: !almost_equals(c_token, PCL_mode_table[i].compare); i++);
634: if (i < PCL_MODES)
635: PCL_mode = &PCL_mode_table[i];
636: else
637: int_error("expecting mode: portrait or landscape", c_token);
638: c_token++;
639: }
640: sprintf(term_options, " %s", PCL_mode->name);
641: HPGL2_options();
642: }
643:
644: TERM_PUBLIC void HPGL_init()
645: {
646: }
647:
648: /* void HPGL2_init ()
649: {
650: } */
651:
652: TERM_PUBLIC void PCL_init()
653: {
654: struct termentry *t = term;
655: /*
656: * Reset printer, set to one copy, orientation of user's choice.
657: * Make the change to the new orientation all at once.
658: */
659: fprintf(gpoutfile, "\033E\033&l1X%s\n", PCL_mode->command);
660: t->xmax = PCL_mode->xmax;
661: t->ymax = PCL_mode->ymax;
662: }
663:
664: TERM_PUBLIC void HPGL_graphics()
665: {
666: fputs("\033.Y\n\033.I81;;17:\033.N;19:\033.M500:\n", gpoutfile);
667: /* 1
668: 1. enable eavesdropping
669: */
670: fprintf(gpoutfile,
671: "IN;%s\nSC0,%d,0,%d;\nSR%f,%f;\n",
672: ((encoding == ENCODING_CP_850) || (encoding == ENCODING_ISO_8859_1)) ?
673: "CA7;" : "",
674: HPGL_XMAX, HPGL_YMAX,
675: ((double) (HPGL_HCHAR) * 200 / 3 / HPGL_XMAX),
676: ((double) (HPGL_VCHAR) * 100 / 2 / HPGL_YMAX));
677: /* 1 2 3
678: 1. reset to power-up defaults
679: 2. set SCaling
680: 3. set character size
681: */
682: HPGL_ang = 0;
683: }
684:
685: TERM_PUBLIC void HPGL2_graphics()
686: {
687: /*
688: * IN - Initialize
689: * SP - Select pen
690: * SD - Set default font
691: */
692: fprintf(gpoutfile, "INSP1SD1,%d,2,%d,",
693: HPGL2_font->symbol_set, HPGL2_font->spacing);
694: if (HPGL2_font->spacing)
695: fprintf(gpoutfile, "4,%f,", HPGL2_font->height);
696: else
697: fprintf(gpoutfile, "3,%f,", HPGL2_font->pitch);
698: fprintf(gpoutfile, "5,%d,6,%d,7,%d\n", HPGL2_font->posture,
699: HPGL2_font->stroke_weight, HPGL2_font->typeface);
700: /*
701: * Control variables
702: */
703: HPGL_ang = 0; /* Horizontal */
704: HPGL2_in_pe = FALSE; /* Not in PE command */
705: HPGL2_lost = TRUE; /* Pen position is unknown */
706: HPGL_penstate = UP; /* Pen is up */
707: }
708:
709: TERM_PUBLIC void PCL_graphics()
710: {
711: /*
712: * Enter HPGL/2 graphics mode
713: */
714: fputs("\033%0B", gpoutfile);
715: HPGL2_graphics();
716: }
717:
718: TERM_PUBLIC void HPGL_text()
719: {
720: if (HPGL_eject == 0) {
721: fputs("PUSP0;\033.Z\n\0", gpoutfile);
722: /* 1 2 3
723: 1. pen up
724: 2. park pen
725: 3. disable eavesdropping
726: */
727: } else {
728: fputs("PUSP0;PG;\033.Z\n\0", gpoutfile);
729: /* 1 2 3 4
730: 1. pen up
731: 2. park pen
732: 3. page eject
733: 4. disable eavesdropping
734: */
735: }
736: HPGL_penstate = UP;
737: }
738:
739: #if 0 /* not used */
740: void HPGL2_text()
741: {
742: /*
743: * If in Polyline Encoded command, leave Polyline Encoded command
744: */
745: if (HPGL2_in_pe) {
746: fputs(";\n", gpoutfile);
747: HPGL2_in_pe = 0;
748: }
749: /*
750: * Pen up, park pen
751: */
752: fputs("PUSP0;", gpoutfile);
753: }
754: #endif
755:
756: TERM_PUBLIC void PCL_text()
757: {
758: if (HPGL2_in_pe) {
759: fputs(";\n", gpoutfile);
760: HPGL2_in_pe = 0;
761: }
762: /*
763: * Go into PCL mode and eject the page
764: */
765: fputs("\033%1A\033&l0H\n\0", gpoutfile);
766: }
767:
768: TERM_PUBLIC void HPGL_linetype(linetype)
769: int linetype;
770: {
771: /* allow for set number of pens */
772: linetype = (linetype + 2) % HPGL_numpen + 1;
773: /* only select pen if necessary */
774: if (HPGL_pentype != linetype) {
775: fprintf(gpoutfile, "PU;\nSP%d;\n", linetype);
776: HPGL_pentype = linetype;
777: HPGL_penstate = UP;
778: }
779: }
780:
781: TERM_PUBLIC void HPGL2_linetype(linetype)
782: int linetype;
783: {
784: /*
785: * If in Polyline Encoded command, leave Polyline Encoded command
786: */
787: if (HPGL2_in_pe) {
788: fputs(";\n", gpoutfile);
789: HPGL2_in_pe = 0;
790: }
791: /*
792: * Allow for lots of linetypes
793: */
794: if (linetype >= 0)
795: linetype = linetype % (HPGL2_LINETYPES * HPGL2_PENWIDTHS);
796: if (linetype != HPGL_pentype) {
797: if (linetype >= 0) {
798: fprintf(gpoutfile, "PW%sLT%s",
799: HPGL2_pw[linetype / HPGL2_LINETYPES],
800: HPGL2_lt[linetype % HPGL2_LINETYPES]);
801: } else if (linetype == -2)
802: /*
803: * Borders and tics
804: */
805: fprintf(gpoutfile, "PW.2LT");
806: else if (linetype == -1)
807: /*
808: * Axes and grids
809: */
810: fprintf(gpoutfile, "PW.1LT1,.25");
811: HPGL_pentype = linetype;
812: }
813: }
814:
815: TERM_PUBLIC void HPGL_put_text(x, y, str)
816: unsigned int x, y;
817: char *str;
818: {
819: if (HPGL_ang == 1)
820: HPGL_move(x + HPGL_VCHAR / 4, y);
821: else
822: HPGL_move(x, y - HPGL_VCHAR / 4);
823: if (encoding == ENCODING_CP_850) {
824: unsigned char *s;
825: fputs("LB", gpoutfile);
826: for (s = (unsigned char *) str; *s; ++s)
827: if (*s >= 128 && hpgl_cp_850[*s - 128][0])
828: fputs(hpgl_cp_850[*s - 128], gpoutfile);
829: else
830: putc(*s, gpoutfile);
831: fputs("\003\n", gpoutfile);
832: } else if (encoding == ENCODING_ISO_8859_1) {
833: unsigned char *s;
834: fputs("LB", gpoutfile);
835: for (s = (unsigned char *) str; *s; ++s)
836: if (*s >= 128 && hpgl_iso_8859_1[*s - 128][0])
837: fputs(hpgl_iso_8859_1[*s - 128], gpoutfile);
838: else
839: putc(*s, gpoutfile);
840: fputs("\003\n", gpoutfile);
841: } else
842: fprintf(gpoutfile, "LB%s\003\n", str);
843: }
844:
845: TERM_PUBLIC void HPGL2_put_text(x, y, str)
846: unsigned int x, y;
847: char *str;
848: {
849: struct termentry *t = term;
850: /*
851: * Position the pen
852: */
853: if (HPGL_ang == 1)
854: HPGL2_move(x + t->v_char / 4, y);
855: else
856: HPGL2_move(x, y - t->v_char / 4);
857: /*
858: * If in Polyline Encoded command, leave Polyline Encoded command
859: */
860: if (HPGL2_in_pe) {
861: fputs(";\n", gpoutfile);
862: HPGL2_in_pe = 0;
863: }
864: /*
865: * Print the text string
866: */
867: fprintf(gpoutfile, "LB%s\003\n", str);
868: HPGL2_lost = 1;
869: }
870: /*
871: * Some early HPGL plotters (e.g. HP7220C) require the
872: * Pen Up/Down and Pen (move) Absolute commands to be separate.
873: */
874:
875: TERM_PUBLIC void HPGL_move(x, y)
876: unsigned int x, y;
877: {
878: if (HPGL_x != x || HPGL_y != y) { /* only move if necessary */
879: fprintf(gpoutfile, "PU;PA%d,%d;\n", x, y);
880: HPGL_penstate = UP;
881: HPGL_x = x;
882: HPGL_y = y;
883: }
884: }
885:
886: TERM_PUBLIC void HPGL_vector(x, y)
887: unsigned int x, y;
888: {
889: if (HPGL_penstate != DOWN) {
890: fprintf(gpoutfile, "PD;PA%d,%d;\n", x, y);
891: HPGL_penstate = DOWN;
892: } else
893: fprintf(gpoutfile, "PA%d,%d;\n", x, y);
894: HPGL_x = x;
895: HPGL_y = y;
896: }
897:
898: TERM_PUBLIC void HPGL2_move(x, y)
899: unsigned int x, y;
900: {
901: register int dx, dy;
902: if (HPGL2_in_pe) {
903: dx = x - HPGL_x;
904: dy = y - HPGL_y;
905: fputs("<", gpoutfile);
906: } else {
907: #if HPGL2_BASE64
908: fputs("PE<", gpoutfile);
909: #else
910: fputs("PE7<", gpoutfile);
911: #endif
912: if (HPGL2_lost) {
913: dx = x;
914: dy = y;
915: HPGL2_lost = 0;
916: fputs("=", gpoutfile);
917: } else {
918: dx = x - HPGL_x;
919: dy = y - HPGL_y;
920: }
921: HPGL2_in_pe = 1;
922: }
923: #if HPGL2_EXPLICIT_PD
924: if (HPGL_penstate == DOWN)
925: HPGL_penstate = UP;
926: #endif
927: HPGL2_encode(dx);
928: HPGL2_encode(dy);
929: fputs("\n", gpoutfile);
930: HPGL_x = x;
931: HPGL_y = y;
932: }
933:
934: TERM_PUBLIC void HPGL2_vector(x, y)
935: unsigned int x, y;
936: {
937: register int dx, dy;
938: if (HPGL2_in_pe) {
939: dx = x - HPGL_x;
940: dy = y - HPGL_y;
941: } else {
942: #if HPGL2_BASE64
943: fputs("PE", gpoutfile);
944: #else
945: fputs("PE7", gpoutfile);
946: #endif
947: if (HPGL2_lost) {
948: dx = x;
949: dy = y;
950: HPGL2_lost = 0;
951: fputs("=", gpoutfile);
952: } else {
953: dx = x - HPGL_x;
954: dy = y - HPGL_y;
955: }
956: HPGL2_in_pe = 1;
957: }
958: #if HPGL2_EXPLICIT_PD
959: /*
960: * Put the pen down in the current position,
961: * relative vector of 0,0.
962: */
963: if (HPGL_penstate == UP) {
964: fputc((char) HPGL2_HIGH_OFFS, gpoutfile);
965: fputc((char) HPGL2_HIGH_OFFS, gpoutfile);
966: HPGL_penstate = DOWN;
967: }
968: #endif
969: HPGL2_encode(dx);
970: HPGL2_encode(dy);
971: fputs("\n", gpoutfile);
972: HPGL_x = x;
973: HPGL_y = y;
974: }
975:
976: /*
977: * Routine to encode position in base 32 or base 64 characters
978: */
979:
980: TERM_PUBLIC void HPGL2_encode(d)
981: register int d;
982: {
983: register int c;
984: if ((d <<= 1) < 0)
985: d = 1 - d;
986: do {
987: c = d & HPGL2_MASK;
988: d >>= HPGL2_BITS;
989: if (d > 0)
990: fputc((char) (c + HPGL2_LOW_OFFS), gpoutfile);
991: else
992: fputc((char) (c + HPGL2_HIGH_OFFS), gpoutfile);
993: } while (d > 0);
994: }
995:
996: TERM_PUBLIC int HPGL_text_angle(ang)
997: int ang;
998: {
999: HPGL_ang = ang;
1000: if (ang == 1)
1001: /*
1002: * Vertical
1003: */
1004: fputs("DI0,1;\n", gpoutfile);
1005: else
1006: /*
1007: * Horizontal
1008: */
1009: fputs("DI1,0;\n", gpoutfile);
1010: return TRUE;
1011: }
1012:
1013: TERM_PUBLIC int HPGL2_text_angle(ang)
1014: int ang;
1015: {
1016: /*
1017: * If in Polyline Encoded command, leave Polyline Encoded command
1018: */
1019: if (HPGL2_in_pe) {
1020: fputs(";", gpoutfile);
1021: HPGL2_in_pe = 0;
1022: }
1023: if (ang == 1)
1024: /*
1025: * Vertical
1026: */
1027: fputs("DI0,1", gpoutfile);
1028: else
1029: /*
1030: * Horizontal
1031: */
1032: fputs("DI1,0", gpoutfile);
1033: HPGL_ang = ang;
1034: return TRUE;
1035: }
1036:
1037: TERM_PUBLIC void HPGL_reset()
1038: {
1039: /*
1040: * do nothing
1041: */
1042: }
1043:
1044: #if 0
1045: void HPGL2_reset()
1046: {
1047: /*
1048: * Park the pen
1049: * Advance a page
1050: * End with ";"
1051: */
1052: fputs("SP0PG;\n", gpoutfile);
1053: }
1054:
1055: #endif
1056:
1057: TERM_PUBLIC void PCL_reset()
1058: {
1059: /*
1060: * Return to PCL mode
1061: * Printer reset (conditional eject)
1062: */
1063: fputs("\033%0A\033E\n", gpoutfile);
1064: }
1065:
1066: TERM_PUBLIC int HPGL2_justify_text(just)
1067: enum JUSTIFY just;
1068: {
1069: /*
1070: * If in Polyline Encoded command, leave Polyline Encoded command
1071: */
1072: if (HPGL2_in_pe) {
1073: fputs(";\n", gpoutfile);
1074: HPGL2_in_pe = 0;
1075: }
1076: switch (just) {
1077: case LEFT:
1078: fputs("LO1", gpoutfile);
1079: break;
1080: case CENTRE:
1081: fputs("LO4", gpoutfile);
1082: break;
1083: case RIGHT:
1084: fputs("LO7", gpoutfile);
1085: break;
1086: default:
1087: return 0;
1088: }
1089: return 1;
1090: }
1091:
1092: #endif /* TERM_BODY */
1093:
1094: #ifdef TERM_TABLE
1095: TERM_TABLE_START(hpgl_driver)
1096: "hpgl", "HP7475 and relatives [number of pens] [eject]",
1097: HPGL_XMAX, HPGL_YMAX, HPGL_VCHAR, HPGL_HCHAR,
1098: HPGL_VTIC, HPGL_HTIC, HPGL_options, HPGL_init, HPGL_reset,
1099: HPGL_text, null_scale, HPGL_graphics, HPGL_move, HPGL_vector,
1100: HPGL_linetype, HPGL_put_text, HPGL_text_angle,
1101: null_justify_text, do_point, do_arrow, set_font_null
1102: TERM_TABLE_END(hpgl_driver)
1103:
1104: #undef LAST_TERM
1105: #define LAST_TERM hpgl_driver
1106:
1107: TERM_TABLE_START(pcl5_driver)
1108: "pcl5", "HP LaserJet III [mode] [font] [point]",
1109: PCL_XMAX, PCL_YMAX, HPGL2_VCHAR, HPGL2_HCHAR,
1110: PCL_VTIC, PCL_HTIC, PCL_options, PCL_init, PCL_reset,
1111: PCL_text, null_scale, PCL_graphics, HPGL2_move, HPGL2_vector,
1112: HPGL2_linetype, HPGL2_put_text, HPGL2_text_angle,
1113: HPGL2_justify_text, do_point, do_arrow, set_font_null
1114: TERM_TABLE_END(pcl5_driver)
1115:
1116: #undef LAST_TERM
1117: #define LAST_TERM pcl5_driver
1118: #endif /* TERM_TABLE */
1119:
1120: #endif /* TERM_PROTO_ONLY */
1121:
1122: #ifdef TERM_HELP
1123: START_HELP(hpgl)
1124: "1 hpgl",
1125: "?commands set terminal hpgl",
1126: "?set terminal hpgl",
1127: "?set term hpgl",
1128: "?terminal hpgl",
1129: "?term hpgl",
1130: "?hpgl",
1131: "?commands set terminal pcl5",
1132: "?set terminal pcl5",
1133: "?set term pcl5",
1134: "?terminal pcl5",
1135: "?term pcl5",
1136: "?pcl5",
1137: " The `hpgl` driver produces HPGL output for devices like the HP7475A plotter.",
1138: " There are two options which can be set---the number of pens and \"eject\", which",
1139: " tells the plotter to eject a page when done. The default is to use 6 pens",
1140: " and not to eject the page when done.",
1141: "",
1142: " The international character sets ISO-8859-1 and CP850 are recognized via",
1143: " `set encoding iso_8859_1` or `set encoding cp850` (see `set encoding` for",
1144: " details).",
1145: "",
1146: " Syntax:",
1147: " set terminal hpgl {<number_of_pens>} {eject}",
1148: "",
1149: " The selection",
1150: "",
1151: " set terminal hpgl 8 eject",
1152: "",
1153: " is equivalent to the previous `hp7550` terminal, and the selection",
1154: "",
1155: " set terminal hpgl 4",
1156: "",
1157: " is equivalent to the previous `hp7580b` terminal.",
1158: "",
1159: " The `pcl5` driver supports the Hewlett-Packard Laserjet III. It actually uses",
1160: " HPGL-2, but there is a name conflict among the terminal devices. It has",
1161: " several options",
1162: "",
1163: " Syntax:",
1164: " set terminal pcl5 {<mode>} {<font>} {<fontsize>}",
1165: "",
1166: " where <mode> is `landscape`, or `portrait`, <font> is `stick`, `univers`, or",
1167: " `cg_times`, and <fontsize> is the size in points.",
1168: "",
1169: " With `pcl5` international characters are handled by the printer; you just put",
1170: " the appropriate 8-bit character codes into the text strings. You don't need",
1171: " to bother with `set encoding`.",
1172: "",
1173: " HPGL graphics can be imported by many software packages."
1174: END_HELP(hpgl)
1175: #endif /* TERM_HELP */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>