Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / hpljii.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: hpljii.trm,v 1.24 2006/07/21 02:35:47 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - hpljii.trm */
7
8 /*[
9  * Copyright 1990 - 1993, 1998, 2004   Thomas Williams, Colin Kelley
10  *
11  * Permission to use, copy, and distribute this software and its
12  * documentation for any purpose with or without fee is hereby granted,
13  * provided that the above copyright notice appear in all copies and
14  * that both that copyright notice and this permission notice appear
15  * in supporting documentation.
16  *
17  * Permission to modify the software is granted, but not the right to
18  * distribute the complete modified source code.  Modifications are to
19  * be distributed as patches to the released version.  Permission to
20  * distribute binaries produced by compiling modified sources is granted,
21  * provided you
22  *   1. distribute the corresponding source modifications from the
23  *    released version in the form of a patch file along with the binaries,
24  *   2. add special version identification to distinguish your version
25  *    in addition to the base release version number,
26  *   3. provide your name and address as the primary contact for the
27  *    support of your modified version, and
28  *   4. retain our contact information in regard to use of the base
29  *    software.
30  * Permission to distribute the released version of the source code along
31  * with corresponding source modifications in the form of a patch file is
32  * granted with same provisions 2 through 4 for binary distributions.
33  *
34  * This software is provided "as is" without express or implied warranty
35  * to the extent permitted by applicable law.
36 ]*/
37
38 /*
39  * This file is included by ../term.c.
40  *
41  * This terminal driver supports:
42  *  hpljii, hpdj
43  *
44  * AUTHORS
45  *  John Engels
46  *  Russell Lang
47  *  Maurice Castro
48  *
49  * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
50  *
51  */
52
53 /* The following HP laserjet series II driver uses generic bit mapped graphics
54    routines from bitmap.c to build up a bit map in memory.  The driver
55    interchanges colomns and lines in order to access entire lines
56    easily and returns the lines to get bits in the right order :
57    (x,y) -> (y,XMAX-1-x). */
58 /* This interchange is done by calling b_makebitmap() with reversed
59    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
60    will then perform the interchange before each pixel is plotted */
61 /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
62    of Jyrki Yli-Nokari */
63
64 /*
65  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
66  */
67
68 #include "driver.h"
69
70 #ifdef TERM_REGISTER
71 register_term(hpljii)
72 register_term(hpdj)
73 #endif
74
75 #ifdef TERM_PROTO
76 TERM_PUBLIC void HPLJII_options __PROTO((void));
77 TERM_PUBLIC void HPLJII_init __PROTO((void));
78 TERM_PUBLIC void HPLJII_graphics __PROTO((void));
79 TERM_PUBLIC void HPLJII_text __PROTO((void));
80 TERM_PUBLIC void HPLJII_linetype __PROTO((int linetype));
81 TERM_PUBLIC void HPLJII_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
82 TERM_PUBLIC void HPLJII_reset __PROTO((void));
83
84 TERM_PUBLIC void HPDJ_graphics __PROTO((void));
85 TERM_PUBLIC void HPDJ_text __PROTO((void));
86
87 /* default values for term_tbl */
88 #define HPLJII_75PPI_XMAX (1920/4)
89 #define HPLJII_75PPI_YMAX (1920/4)
90 #define HPLJII_75PPI_HCHAR (1920/4/6)
91 #define HPLJII_75PPI_VCHAR (1920/4/10)
92 #define HPLJII_75PPI_VTIC 5
93 #define HPLJII_75PPI_HTIC 5
94 #endif
95
96 #ifndef TERM_PROTO_ONLY
97 #ifdef TERM_BODY
98
99 /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
100    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
101
102 #define HPLJII_DPP (hplj_dpp)   /* dots per pixel */
103 #define HPLJII_PPI (300/HPLJII_DPP)     /* pixel per inch */
104 /* make XMAX and YMAX a multiple of 8 */
105 #define HPLJII_XMAX (8*(unsigned int)(xsize*1920/HPLJII_DPP/8.0+0.9))
106 #define HPLJII_YMAX (8*(unsigned int)(ysize*1920/HPLJII_DPP/8.0+0.9))
107
108 /* Courier font with 6 lines per inch */
109 #define HPLJII_VCHAR (HPLJII_PPI/6)
110 /* Courier font with 10 caracters per inch */
111 #define HPLJII_HCHAR (HPLJII_PPI/10)
112 /* Save current cursor position */
113 #define HPLJII_PUSH_CURSOR fputs("\033&f0S",gpoutfile)
114 /* Restore cursor position */
115 #define HPLJII_POP_CURSOR fputs("\033&f1S",gpoutfile)
116 /* be sure to use courier font with 6lpi and 10cpi */
117 #define HPLJII_COURIER fputs("\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D",gpoutfile)
118
119
120 static void HPLJII_putc __PROTO((unsigned int x, unsigned int y, int c, int ang));
121     /* note: c is char, but must be declared int due to an old K&R ANSI-C strict HP cc */
122 static int hplj_dpp = 4;
123 /* bm_pattern not appropriate for 300ppi graphics */
124 #ifndef GOT_300_PATTERN
125 # define GOT_300_PATTERN
126 static unsigned int b_300ppi_pattern[] =
127 {
128     0xffff, 0x1111, 0xffff, 0x3333,
129     0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff
130 };
131 #endif
132
133 TERM_PUBLIC void
134 HPLJII_options()
135 {
136     char opt[4];
137     int parse_error = 0;
138
139     if (END_OF_COMMAND) {
140         term_options[0] = NUL;
141     } else {
142         if (token[c_token].length > 3) {
143             parse_error = 1;    /* see below */
144         } else {
145             /* almost_equals() won't accept numbers - use strcmp() instead */
146             capture(opt, c_token, c_token, 4);
147             if (!strcmp(opt, "75")) {
148                 hplj_dpp = 4;
149             } else if (!strcmp(opt, "100")) {
150                 hplj_dpp = 3;
151             } else if (!strcmp(opt, "150")) {
152                 hplj_dpp = 2;
153             } else if (!strcmp(opt, "300")) {
154                 hplj_dpp = 1;
155             } else {
156                 /* error, but set dpi anyway, since term it already set */
157                 parse_error = 1;
158             }
159             c_token++;
160         }
161     }
162
163     term->xmax = HPLJII_XMAX;
164     term->ymax = HPLJII_YMAX;
165     switch (hplj_dpp) {
166     case 1:
167         strcpy(term_options, "300");
168         term->v_tic = 15;
169         term->h_tic = 15;
170         break;
171     case 2:
172         strcpy(term_options, "150");
173         term->v_tic = 8;
174         term->h_tic = 8;
175         break;
176     case 3:
177         strcpy(term_options, "100");
178         term->v_tic = 6;
179         term->h_tic = 6;
180         break;
181     case 4:
182         strcpy(term_options, "75");
183         term->v_tic = 5;
184         term->h_tic = 5;
185         break;
186     }
187
188     if (parse_error)
189         int_error(c_token, "expecting dots per inch size 75, 100, 150 or 300");
190 }
191
192
193 TERM_PUBLIC void
194 HPLJII_init()
195 {
196     term->v_char = HPLJII_VCHAR;
197     term->h_char = HPLJII_HCHAR;
198 }
199
200
201 TERM_PUBLIC void
202 HPLJII_graphics()
203 {
204     HPLJII_COURIER;
205     HPLJII_PUSH_CURSOR;
206     /* rotate plot -90 degrees by reversing XMAX and YMAX and by
207        setting b_rastermode to TRUE */
208     b_makebitmap(HPLJII_YMAX, HPLJII_XMAX, 1);
209     b_rastermode = TRUE;
210 }
211
212
213 /* HPLJIItext by rjl - no compression */
214 TERM_PUBLIC void
215 HPLJII_text()
216 {
217     register int x, j, row;
218
219     fprintf(gpoutfile, "\033*t%dR", HPLJII_PPI);
220     HPLJII_POP_CURSOR;
221     fputs("\033*r1A", gpoutfile);
222
223     /* dump bitmap in raster mode */
224     for (x = b_xsize - 1; x >= 0; x--) {
225         row = (b_ysize / 8) - 1;
226         fprintf(gpoutfile, "\033*b0m%dW", b_ysize / 8);
227         for (j = row; j >= 0; j--) {
228             (void) fputc((char) (*((*b_p)[j] + x)), gpoutfile);
229         }
230     }
231     fputs("\033*rB", gpoutfile);
232
233     b_freebitmap();
234
235 #ifndef VMS
236     /* most vms spoolers add a formfeed character */
237     putc('\f', gpoutfile);
238 #endif /* !VMS */
239 }
240
241
242
243 TERM_PUBLIC void
244 HPLJII_linetype(int linetype)
245 {
246
247     if (hplj_dpp == 1) {
248         if (linetype >= 7)
249             linetype %= 7;
250         /* b_pattern not appropriate for 300ppi graphics */
251         b_linemask = b_300ppi_pattern[linetype + 2];
252         b_maskcount = 0;
253     } else {
254         b_setlinetype(linetype);
255     }
256 }
257
258 TERM_PUBLIC void
259 HPLJII_put_text(unsigned int x, unsigned int y, const char *str)
260 {
261     switch (b_angle) {
262     case 0:
263         y -= HPLJII_VCHAR / 5;
264         HPLJII_POP_CURSOR;
265         HPLJII_PUSH_CURSOR;
266         /* (0,0) is the upper left point of the paper */
267         fprintf(gpoutfile, "\033*p%+dx%+dY", x * HPLJII_DPP
268                 ,(HPLJII_YMAX - y - 1) * HPLJII_DPP);
269         fputs(str, gpoutfile);
270 /*       for (; *str; ++str, x += HPLJII_HCHAR)
271             HPLJII_putc (x, y, *str, b_angle);*/
272         break;
273     case 1:
274         y += (HPLJII_HCHAR - 2 * HPLJII_VCHAR) / 2;
275         y += (HPLJII_VCHAR + HPLJII_HCHAR) * strlen(str) / 2;
276         for (; *str; ++str, y -= HPLJII_VCHAR)
277             HPLJII_putc(x, y, *str, b_angle);
278         break;
279     }
280 }
281
282 static void
283 HPLJII_putc(unsigned int x, unsigned int y, int c, int ang)
284 {
285     HPLJII_POP_CURSOR;
286     HPLJII_PUSH_CURSOR;
287     (void) ang;                 /* avoid -Wunused warnings */
288     /* (0,0) is the upper left point of the paper */
289     fprintf(gpoutfile, "\033*p%+dx%+dY",
290             x * HPLJII_DPP, (HPLJII_YMAX - y - 1) * HPLJII_DPP);
291     fputc(c, gpoutfile);
292 }
293
294
295 TERM_PUBLIC void
296 HPLJII_reset()
297 {
298 #ifdef VMS
299     fflush_binary();
300 #endif /* VMS */
301 }
302
303
304 /* HP DeskJet routines */
305 TERM_PUBLIC void
306 HPDJ_graphics()
307 {
308     switch (hplj_dpp) {
309     case 1:
310         b_charsize(FNT13X25);
311         term->v_char = FNT13X25_VCHAR;
312         term->h_char = FNT13X25_HCHAR;
313         break;
314     case 2:
315         b_charsize(FNT13X25);
316         term->v_char = FNT13X25_VCHAR;
317         term->h_char = FNT13X25_HCHAR;
318         break;
319     case 3:
320         b_charsize(FNT9X17);
321         term->v_char = FNT9X17_VCHAR;
322         term->h_char = FNT9X17_HCHAR;
323         break;
324     case 4:
325         b_charsize(FNT5X9);
326         term->v_char = FNT5X9_VCHAR;
327         term->h_char = FNT5X9_HCHAR;
328         break;
329     }
330     /* rotate plot -90 degrees by reversing XMAX and YMAX and by
331        setting b_rastermode to TRUE */
332     b_makebitmap(HPLJII_YMAX, HPLJII_XMAX, 1);
333     b_rastermode = TRUE;
334 }
335
336
337 /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
338    hopefully compatible with other HP Deskjet printers */
339 TERM_PUBLIC void
340 HPDJ_text()
341 {
342     register int x, j, row;
343
344     fprintf(gpoutfile, "\
345 \033*b0M\
346 \033*t%dR\
347 \033*r1A",
348             HPLJII_PPI);
349
350     /* dump bitmap in raster mode */
351     for (x = b_xsize - 1; x >= 0; x--) {
352         row = (b_ysize / 8) - 1;
353         fprintf(gpoutfile, "\033*b%dW", b_ysize / 8);
354         for (j = row; j >= 0; j--) {
355             (void) fputc((char) (*((*b_p)[j] + x)), gpoutfile);
356         }
357     }
358     fputs("\033*rbC", gpoutfile);
359
360     b_freebitmap();
361
362 #ifndef VMS                     /* most vms spoolers add a formfeed character */
363     putc('\f', gpoutfile);
364 #endif /* !VMS */
365 }
366
367 #endif
368
369 #ifdef TERM_TABLE
370
371 TERM_TABLE_START(hpljii_driver)
372     "hpljii", "HP Laserjet series II, [75 100 150 300]",
373     HPLJII_75PPI_XMAX, HPLJII_75PPI_YMAX, HPLJII_75PPI_VCHAR,
374     HPLJII_75PPI_HCHAR, HPLJII_75PPI_VTIC, HPLJII_75PPI_HTIC, HPLJII_options,
375     HPLJII_init, HPLJII_reset, HPLJII_text, null_scale,
376     HPLJII_graphics, b_move, b_vector, HPLJII_linetype,
377     HPLJII_put_text, b_text_angle, null_justify_text, line_and_point,
378     do_arrow, set_font_null, 0, TERM_BINARY,
379     0, 0, b_boxfill
380 TERM_TABLE_END(hpljii_driver)
381
382 #undef LAST_TERM
383 #define LAST_TERM hpljii_driver
384
385 TERM_TABLE_START(hpdj_driver)
386     "hpdj", "HP DeskJet 500, [75 100 150 300]",
387     HPLJII_75PPI_XMAX, HPLJII_75PPI_YMAX, HPLJII_75PPI_VCHAR,
388     HPLJII_75PPI_HCHAR, HPLJII_75PPI_VTIC, HPLJII_75PPI_HTIC, HPLJII_options,
389     HPLJII_init, HPLJII_reset, HPDJ_text, null_scale,
390     HPDJ_graphics, b_move, b_vector, HPLJII_linetype,
391     b_put_text, b_text_angle, null_justify_text, line_and_point,
392     do_arrow, set_font_null, 0, TERM_BINARY,
393     0, 0, b_boxfill
394 TERM_TABLE_END(hpdj_driver)
395
396 #undef LAST_TERM
397 #define LAST_TERM hpdj_driver
398
399 #endif
400 #endif
401
402 #ifdef TERM_HELP
403 START_HELP(hpljii)
404 "1 hpljii",
405 "?commands set terminal hpljii",
406 "?set terminal hpljii",
407 "?set term hpljii",
408 "?terminal hpljii",
409 "?term hpljii",
410 "?hpljii",
411 "?commands set terminal hpdj",
412 "?set terminal hpdj",
413 "?set term hpdj",
414 "?terminal hpdj",
415 "?term hpdj",
416 "?hpdj",
417 " The `hpljii` terminal driver supports the HP Laserjet Series II printer.  The",
418 " `hpdj` driver supports the HP DeskJet 500 printer.  These drivers allow a",
419 " choice of resolutions.",
420 "",
421 " Syntax:",
422 "       set terminal hpljii | hpdj {<res>}",
423 "",
424 " where `res` may be 75, 100, 150 or 300 dots per inch; the default is 75.",
425 " Rasterization at the higher resolutions may require a large amount of memory.",
426 "",
427 " The `hp500c` terminal is similar to `hpdj`; `hp500c` additionally supports",
428 " color and compression."
429 END_HELP(hpljii)
430 #endif /* TERM_HELP */