1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: hp500c.trm,v 1.17 2006/07/21 02:35:47 sfeam Exp $
6 /* GNUPLOT - hp500c.trm */
9 * Copyright 1990 - 1993, 1998, 2004
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.
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,
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
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.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
46 * Russell Lang ----> HPLJII.trm
48 * UdoHessenauer ----> derived this version from the above one
50 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
54 /* The following HP Deskjet500c driver uses generic bit mapped graphics
55 routines from bitmap.c to build up a bit map in memory. The driver
56 interchanges colomns and lines in order to access entire lines
57 easily and returns the lines to get bits in the right order :
58 (x,y) -> (y,XMAX-1-x). */
59 /* This interchange is done by calling b_makebitmap() with reversed
60 xmax and ymax, and then setting b_rastermode to TRUE. b_setpixel()
61 will then perform the interchange before each pixel is plotted */
62 /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
63 of Jyrki Yli-Nokari */
66 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
76 TERM_PUBLIC void HP500C_options __PROTO((void));
77 TERM_PUBLIC void HP500C_init __PROTO((void));
78 TERM_PUBLIC void HP500C_reset __PROTO((void));
79 TERM_PUBLIC void HP500C_linetype __PROTO((int linetype));
80 TERM_PUBLIC void HP500C_graphics __PROTO((void));
81 TERM_PUBLIC void HP500C_text __PROTO((void));
82 /* default values for term_tbl */
83 #define HP500C_75PPI_XMAX (1920/4)
84 #define HP500C_75PPI_YMAX (1920/4)
85 #define HP500C_75PPI_HCHAR (1920/4/6)
86 #define HP500C_75PPI_VCHAR (1920/4/10)
87 #define HP500C_75PPI_VTIC 5
88 #define HP500C_75PPI_HTIC 5
90 #define GOT_HP500C_PROTO
93 #ifndef TERM_PROTO_ONLY
97 /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
98 75ppi. (Pixel size = 1, 2, 3, 4 dots) */
100 #define HP500C_DPP (hpdj_dpp) /* dots per pixel */
101 #define HP500C_PPI (300/HP500C_DPP) /* pixel per inch */
102 /* make XMAX and YMAX a multiple of 8 */
103 #define HP500C_XMAX (8*(unsigned int)(xsize*1920/HP500C_DPP/8.0+0.9))
104 #define HP500C_YMAX (8*(unsigned int)(ysize*1920/HP500C_DPP/8.0+0.9))
106 /* Courier font with 6 lines per inch */
107 #define HP500C_VCHAR (HP500C_PPI/6)
108 /* Courier font with 10 caracters per inch */
109 #define HP500C_HCHAR (HP500C_PPI/10)
112 /* Save current cursor position */
113 #define HP500C_PUSH_CURSOR fputs("\033&f0S",gpoutfile)
114 /* Restore cursor position */
115 #define HP500C_POP_CURSOR fputs("\033&f1S",gpoutfile)
117 /* be sure to use courier font with 6lpi and 10cpi */
118 #define HP500C_COURIER fputs("\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D",gpoutfile)
121 static int HP_compress __PROTO((unsigned char *op, unsigned char *oe,
123 static unsigned char HP_complement __PROTO((int c));
124 static int HP_compress_to_TIFF __PROTO((unsigned char *op, unsigned char *oe,
126 static int HP_nocompress __PROTO((unsigned char *op, unsigned char *oe,
129 static int hpdj_dpp = 4;
130 static int HP_COMP_MODE = 0;
132 /* bm_pattern not appropriate for 300ppi graphics */
133 #ifndef GOT_300_PATTERN
134 #define GOT_300_PATTERN
135 static unsigned int b_300ppi_pattern[] =
138 0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff
148 #define HPDJCERROR "expecting dots per inch size 75, 100, 150 or 300 and/or compression method"
149 while (!END_OF_COMMAND) {
150 if (token[c_token].length > 4)
151 int_error(c_token, HPDJCERROR);
153 /* almost_equals() won't accept numbers - use strcmp() instead */
154 capture(opt, c_token, c_token, 6);
155 if (!strcmp(opt, "75")) {
159 } else if (!strcmp(opt, "100")) {
162 } else if (!strcmp(opt, "150")) {
165 } else if (!strcmp(opt, "300")) {
168 } else if (!strcmp(opt, "rle")) {
170 } else if (!strcmp(opt, "tiff")) {
176 term->xmax = HP500C_XMAX;
177 term->ymax = HP500C_YMAX;
180 strcpy(term_options, "300");
185 strcpy(term_options, "150");
190 strcpy(term_options, "100");
195 strcpy(term_options, "75");
200 switch (HP_COMP_MODE) {
202 strcat(term_options, " no comp");
205 strcat(term_options, " RLE");
208 strcat(term_options, " TIFF");
210 case 3: /* not implemented yet */
211 strcat(term_options, " Delta Row");
219 /* HBB 980226: all changes to term-> fields *must* happen here, not
223 b_charsize(FNT13X25);
224 term->v_char = FNT13X25_VCHAR;
225 term->h_char = FNT13X25_HCHAR;
228 b_charsize(FNT13X25);
229 term->v_char = FNT13X25_VCHAR;
230 term->h_char = FNT13X25_HCHAR;
234 term->v_char = FNT9X17_VCHAR;
235 term->h_char = FNT9X17_HCHAR;
239 term->v_char = FNT5X9_VCHAR;
240 term->h_char = FNT5X9_HCHAR;
255 /* HP DeskJet 500c routines */
258 HP500C_linetype(int linetype)
262 else if (linetype >= 8) {
287 b_setvalue(linetype);
293 HP500C_point(unsigned int x, unsigned int y, int value)
295 HP500C_linetype(value);
303 /* HBB 980226: moved block of code from here to init() */
304 /* rotate plot -90 degrees by reversing XMAX and YMAX and by
305 setting b_rastermode to TRUE */
306 b_makebitmap(HP500C_YMAX, HP500C_XMAX, 3);
311 * Run-length encoding for the DeskJet. We have pairs of <count>
312 * <what>, where count goes from 0 (meaning one count) to 255
313 * this might double the size of the image.
317 HP_compress(unsigned char *op, unsigned char *oe, unsigned char *cp)
319 unsigned char *ce = cp;
322 unsigned char prevchar;
325 prevchar = *op; /* remember char */
326 count = 1; /* its read the first time */
328 while (++op < oe && *op == prevchar && count < 255) {
329 /* set op to the next char */
330 count++; /* and count it */
332 *ce++ = --count; /* were ready, so correct the count */
333 *ce++ = prevchar; /* and store <what> */
335 *ce = 0; /* just to be safe */
336 return ce - cp; /* length of cbufs */
342 return (unsigned char) (256 - c);
348 unsigned char *op, /* original pointer */
349 unsigned char *oe, /* end of orig string */
350 unsigned char *cp) /* pointer for compressed data */
352 unsigned char *countposition;
353 unsigned char *ce = cp;
356 unsigned char prevchar;
359 prevchar = *op; /* gelesenes Zeichen aufbewaren */
360 count = 1; /* bisher wurde es einmal gelesen */
362 while (++op < oe && *op == prevchar && count < 128) {
365 *ce = HP_complement(count - 1);
366 /* remember count for building blocks of literal bytes */
367 countposition = ce++;
371 while (op < oe && (prevchar != *op || *op != *(op + 1))) {
372 /* only use rle for at leat 3 equal bytes */
377 puts("FATAL op> oe!!\n");
379 if (op < oe && prevchar == *op) {
384 *countposition = count - 1;
397 unsigned char *ce = cp;
404 /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
405 hopefully compatible with other HP Deskjet printers */
410 register int x, j, row, count = 0;
411 unsigned char *obuf, *oe, *cbuf, *ce;
413 if ((obuf = (unsigned char *) malloc(100 * b_psize)) == 0)
414 puts("FATAL!-- couldn't get enough memory for obuf");
415 if ((cbuf = (unsigned char *) malloc(400 * b_psize)) == 0)
416 puts("FATAL!-- couldn't get enough memory for cbuf");
420 fprintf(gpoutfile, "\
430 /* dump bitmap in raster mode */
431 for (x = b_xsize - 1; x >= 0; x--) {
432 row = (b_ysize / 8) - 1;
433 for (j = row; j >= 0; j--) {
434 *oe++ = (char) (*((*b_p)[j] + x));
436 switch (HP_COMP_MODE) {
438 count = HP_compress_to_TIFF(obuf, oe, cbuf);
441 count = HP_compress(obuf, oe, cbuf);
444 count = HP_nocompress(obuf, oe, cbuf);
447 fprintf(gpoutfile, "\033*b%dV", count);
450 fputc(*ce++, gpoutfile);
453 for (j = row; j >= 0; j--) {
454 *oe++ = (char) (*((*b_p)[j + b_psize] + x));
456 switch (HP_COMP_MODE) {
458 count = HP_compress_to_TIFF(obuf, oe, cbuf);
461 count = HP_compress(obuf, oe, cbuf);
464 count = HP_nocompress(obuf, oe, cbuf);
469 fprintf(gpoutfile, "\033*b%dV", count);
472 fputc(*ce++, gpoutfile);
475 for (j = row; j >= 0; j--) {
476 *oe++ = (char) (*((*b_p)[j + (2 * b_psize)] + x));
478 switch (HP_COMP_MODE) {
480 count = HP_compress_to_TIFF(obuf, oe, cbuf);
483 count = HP_compress(obuf, oe, cbuf);
486 count = HP_nocompress(obuf, oe, cbuf);
489 fprintf(gpoutfile, "\033*b%dW", count);
492 fputc(*ce++, gpoutfile);
496 fputs("\033*rbC", gpoutfile);
502 /* most vms spoolers add a formfeed character */
503 putc('\f', gpoutfile);
507 #endif /* TERM_BODY */
511 TERM_TABLE_START(hp500c_driver)
512 "hp500c", "HP DeskJet 500c, [75 100 150 300] [rle tiff]",
513 HP500C_75PPI_XMAX, HP500C_75PPI_YMAX, HP500C_75PPI_VCHAR,
514 HP500C_75PPI_HCHAR, HP500C_75PPI_VTIC, HP500C_75PPI_HTIC, HP500C_options,
515 HP500C_init, HP500C_reset, HP500C_text, null_scale,
516 HP500C_graphics, b_move, b_vector, HP500C_linetype,
517 b_put_text, b_text_angle, null_justify_text, do_point,
518 do_arrow, set_font_null, 0, TERM_BINARY,
520 TERM_TABLE_END(hp500c_driver)
523 #define LAST_TERM hp500c_driver
525 #endif /* TERM_TABLE */
526 #endif /* TERM_PROTO_ONLY */
531 "?commands set terminal hp500c",
532 "?set terminal hp500c",
537 " The `hp500c` terminal driver supports the Hewlett Packard HP DeskJet 500c.",
538 " It has options for resolution and compression.",
541 " set terminal hp500c {<res>} {<comp>}",
543 " where `res` can be 75, 100, 150 or 300 dots per inch and `comp` can be \"rle\",",
544 " or \"tiff\". Any other inputs are replaced by the defaults, which are 75 dpi",
545 " and no compression. Rasterization at the higher resolutions may require a",
546 " large amount of memory."
548 #endif /* TERM_HELP */