Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / hppj.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: hppj.trm,v 1.15 2006/07/21 02:35:47 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - hppj.trm */
7
8 /*[
9  * Copyright 1990 - 1993, 1998, 2004
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  *  hppj
43  *
44  * AUTHORS
45  *  Dan Merget (danm@sr.hp.com)
46  *
47  * This file was based on the hpljii file by:
48  *  John Engels
49  *  Russell Lang
50  *  Maurice Castro
51  *
52  * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
53  *
54  */
55
56 /* The following HP laserjet series II driver uses generic bit mapped graphics
57  * routines from bitmap.c to build up a bit map in memory.
58  */
59
60 /*
61  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
62  */
63
64 #include "driver.h"
65
66 #ifdef TERM_REGISTER
67 register_term(hppj)
68 #endif
69
70 #ifdef TERM_PROTO
71 TERM_PUBLIC void HPPJ_options __PROTO((void));
72 TERM_PUBLIC void HPPJ_init __PROTO((void));
73 TERM_PUBLIC void HPPJ_reset __PROTO((void));
74 TERM_PUBLIC void HPPJ_graphics __PROTO((void));
75 TERM_PUBLIC void HPPJ_text __PROTO((void));
76 TERM_PUBLIC void HPPJ_linetype __PROTO((int linetype));
77
78 /* We define 3 different font sizes: 5x9, 9x17, and 13x25 */
79
80 #define HPPJ_DPI 180            /* dots per inch */
81 #define HPPJ_PLANES 3           /* color planes */
82 #define HPPJ_COLORS (1 << HPPJ_PLANES)
83 /* make XMAX and YMAX a multiple of 8 */
84 #define HPPJ_XMAX (8*(unsigned int)(9.5 * HPPJ_DPI / 8.0 + 0.9))
85 #define HPPJ_YMAX (8 * HPPJ_DPI)
86
87 /* default values for term_tbl */
88 #define HPPJ_9x17_VCHAR FNT9X17_VCHAR
89 #define HPPJ_9x17_HCHAR FNT9X17_HCHAR
90 #define HPPJ_9x17_VTIC (FNT9X17_VCHAR / 2)
91 #define HPPJ_9x17_HTIC (FNT9X17_HCHAR / 2)
92 #endif /* TERM_PROTO */
93
94 #ifndef TERM_PROTO_ONLY
95 #ifdef TERM_BODY
96 static int hppj_font = FNT9X17;
97
98 TERM_PUBLIC void
99 HPPJ_options()
100 {
101     char opt[10];
102 #define HPPJERROR "expecting font size FNT5X9, FNT9X17, or FNT13X25"
103
104     term_options[0] = NUL;      /* default to empty string and 9x17 font */
105     hppj_font = FNT9X17;        /* in case of error or empty options     */
106
107     if (!END_OF_COMMAND) {
108         if (token[c_token].length > 8) {
109             int_error(c_token, HPPJERROR);
110         }
111         capture(opt, c_token, c_token, /*4 */ 9);       /* HBB 980226 */
112         if (!strcmp(opt, "FNT5X9")) {
113             hppj_font = FNT5X9;
114             strcpy(term_options, "FNT5X9");
115         } else if (!strcmp(opt, "FNT9X17")) {
116             hppj_font = FNT9X17;
117             strcpy(term_options, "FNT9X17");
118         } else if (!strcmp(opt, "FNT13X25")) {
119             hppj_font = FNT13X25;
120             strcpy(term_options, "FNT13X25");
121         } else {
122             int_error(c_token, HPPJERROR);
123         }
124         c_token++;
125     }
126 }
127
128
129 TERM_PUBLIC void
130 HPPJ_init()
131 {
132     /* HBB 980226: moved this here, from graphics(): only init() may
133      * change fields of *term ! */
134     switch (hppj_font) {
135     case FNT5X9:
136         term->v_char = FNT5X9_VCHAR;
137         term->h_char = FNT5X9_HCHAR;
138         term->v_tic = FNT5X9_VCHAR / 2;
139         term->h_tic = FNT5X9_HCHAR / 2;
140         break;
141     case FNT9X17:
142         term->v_char = FNT9X17_VCHAR;
143         term->h_char = FNT9X17_HCHAR;
144         term->v_tic = FNT9X17_VCHAR / 2;
145         term->h_tic = FNT9X17_HCHAR / 2;
146         break;
147     case FNT13X25:
148         term->v_char = FNT13X25_VCHAR;
149         term->h_char = FNT13X25_HCHAR;
150         term->v_tic = FNT13X25_VCHAR / 2;
151         term->h_tic = FNT13X25_HCHAR / 2;
152         break;
153     }
154 }
155
156
157 TERM_PUBLIC void
158 HPPJ_reset()
159 {
160 #ifdef VMS
161     fflush_binary();
162 #endif /* VMS */
163 }
164
165
166 TERM_PUBLIC void
167 HPPJ_graphics()
168 {
169     /* HBB 980226: move a block of code from here to init() */
170     b_charsize(hppj_font);
171
172     b_makebitmap(HPPJ_XMAX, HPPJ_YMAX, HPPJ_PLANES);
173 }
174
175
176 TERM_PUBLIC void
177 HPPJ_text()
178 {
179     int x, plane, y;            /* loop indexes */
180     int minRow, maxRow;         /* loop bounds */
181     int numBytes;               /* Number of run-length coded bytes to output */
182     int numReps;                /* Number of times the current byte is repeated */
183
184     fprintf(gpoutfile, "\
185 \033E\033*t%dR\033*r%dS\
186 \033*b0X\033*b0Y\033*r%dU\
187 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
188 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
189 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
190 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
191 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
192 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
193 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
194 \033*v%dA\033*v%dB\033*v%dC\033*v%dI\
195 \033*b1M\033*r1A",
196             HPPJ_DPI, HPPJ_YMAX,
197             HPPJ_PLANES,
198             90, 88, 85, 0,
199             53, 8, 14, 1,
200             3, 26, 22, 2,
201             4, 4, 29, 3,
202             53, 5, 25, 4,
203             2, 22, 64, 5,
204             89, 83, 13, 6,
205             4, 4, 6, 7);
206
207     /* dump bitmap in raster mode using run-length encoding */
208     for (x = HPPJ_XMAX - 1; x >= 0; --x) {
209         for (plane = 0; plane < HPPJ_PLANES; plane++) {
210             minRow = b_psize * plane;
211             maxRow = b_psize * plane + b_psize - 1;
212
213             /* Print column header */
214             numBytes = 0;
215             for (y = maxRow; y >= minRow; --y) {
216                 if (y == minRow || *((*b_p)[y] + x) != *((*b_p)[y - 1] + x)) {
217                     numBytes += 2;
218                 }
219             }
220             fprintf(gpoutfile, "\033*b%d", numBytes);
221             (void) fputc((char) (plane < HPPJ_PLANES - 1 ? 'V' : 'W'), gpoutfile);
222
223             /* Print remainder of column */
224             numReps = 0;
225             for (y = maxRow; y >= minRow; --y) {
226                 if (y == minRow || *((*b_p)[y] + x) != *((*b_p)[y - 1] + x)) {
227                     (void) fputc((char) (numReps), gpoutfile);
228                     (void) fputc((char) (*((*b_p)[y] + x)), gpoutfile);
229                     numReps = 0;
230                 } else {
231                     numReps++;
232                 }
233             }
234         }
235     }
236     fputs("\033*r1B\033E", gpoutfile);
237
238     b_freebitmap();
239 }
240
241
242 TERM_PUBLIC void
243 HPPJ_linetype(int linetype)
244 {
245     if (linetype >= 0) {
246         b_setlinetype(0);
247         b_setvalue((linetype % (HPPJ_COLORS - 1)) + 1);
248     } else {
249         b_setlinetype(linetype + 2);
250         b_setvalue(HPPJ_COLORS - 1);
251     }
252 }
253
254 #endif /* TERM_BODY */
255
256 #ifdef TERM_TABLE
257
258 TERM_TABLE_START(hppj_driver)
259     "hppj", "HP PaintJet and HP3630 [FNT5X9 FNT9X17 FNT13X25]",
260     HPPJ_XMAX, HPPJ_YMAX,
261     HPPJ_9x17_VCHAR, HPPJ_9x17_HCHAR, HPPJ_9x17_VTIC, HPPJ_9x17_HTIC,
262     HPPJ_options, HPPJ_init, HPPJ_reset, HPPJ_text, null_scale, HPPJ_graphics,
263     b_move, b_vector, HPPJ_linetype, b_put_text, b_text_angle,
264     null_justify_text, do_point, do_arrow, set_font_null, 0, TERM_BINARY,
265     0, 0, b_boxfill
266 TERM_TABLE_END(hppj_driver)
267
268 #undef LAST_TERM
269 #define LAST_TERM hppj_driver
270
271 #endif /* TERM_TABLE */
272 #endif /* TERM_PROTO_ONLY */
273
274 #ifdef TERM_HELP
275 START_HELP(hppj)
276 "1 hppj",
277 "?commands set terminal hppj",
278 "?set terminal hppj",
279 "?set term hppj",
280 "?terminal hppj",
281 "?term hppj",
282 "?hppj",
283 " The `hppj` terminal driver supports the HP PaintJet and HP3630 printers.  The",
284 " only option is the choice of font.",
285 "",
286 " Syntax:",
287 "       set terminal hppj {FNT5X9 | FNT9X17 | FNT13X25}",
288 "",
289 " with the middle-sized font (FNT9X17) being the default."
290 END_HELP(hppj)
291 #endif