File: hp500c.trm

package info (click to toggle)
gnuplot 3.7.1p1-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,808 kB
  • ctags: 4,418
  • sloc: ansic: 43,279; lisp: 661; makefile: 647; asm: 539; sh: 416; objc: 379; csh: 297; pascal: 194; perl: 138
file content (543 lines) | stat: -rw-r--r-- 13,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/*
 * $Id: hp500c.trm,v 1.7 1998/12/14 18:39:45 lhecking Exp $
 *
 */

/* GNUPLOT - hp500c.trm */

/*[
 * Copyright 1990 - 1993, 1998
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   1. distribute the corresponding source modifications from the
 *    released version in the form of a patch file along with the binaries,
 *   2. add special version identification to distinguish your version
 *    in addition to the base release version number,
 *   3. provide your name and address as the primary contact for the
 *    support of your modified version, and
 *   4. retain our contact information in regard to use of the base
 *    software.
 * Permission to distribute the released version of the source code along
 * with corresponding source modifications in the form of a patch file is
 * granted with same provisions 2 through 4 for binary distributions.
 *
 * This software is provided "as is" without express or implied warranty
 * to the extent permitted by applicable law.
]*/

/*
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *  hpdj 500c
 *
 * AUTHORS
 *  John Engels      -- \
 *  Russell Lang     ----> HPLJII.trm
 *  Maurice Castro   -- /
 *  UdoHessenauer    ----> derived this version from the above one
 *
 * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
 * 
 */

/* The following HP Deskjet500c  driver uses generic bit mapped graphics
   routines from bitmap.c to build up a bit map in memory.  The driver
   interchanges colomns and lines in order to access entire lines
   easily and returns the lines to get bits in the right order :
   (x,y) -> (y,XMAX-1-x). */
/* This interchange is done by calling b_makebitmap() with reversed 
   xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
   will then perform the interchange before each pixel is plotted */
/* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
   of Jyrki Yli-Nokari */

/*
 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(hp500c)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void HP500Coptions __PROTO((void));
TERM_PUBLIC void HP500Cinit __PROTO((void));
TERM_PUBLIC void HP500Creset __PROTO((void));
TERM_PUBLIC void HP500Clinetype __PROTO((int linetype));
TERM_PUBLIC void HP500Cgraphics __PROTO((void));
TERM_PUBLIC void HP500Ctext __PROTO((void));
#define HP500Ctext_angle b_text_angle
#define HP500Cput_text b_put_text
#define HP500Cmove b_move
#define HP500Cvector b_vector
/* default values for term_tbl */
#define HP500C_75PPI_XMAX (1920/4)
#define HP500C_75PPI_YMAX (1920/4)
#define HP500C_75PPI_HCHAR (1920/4/6)
#define HP500C_75PPI_VCHAR (1920/4/10)
#define HP500C_75PPI_VTIC 5
#define HP500C_75PPI_HTIC 5

#define GOT_HP500C_PROTO
#endif

#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY


/* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
   75ppi.  (Pixel size = 1, 2, 3, 4 dots) */

#define HP500C_DPP (hpdj_dpp)	/* dots per pixel */
#define HP500C_PPI (300/HP500C_DPP)	/* pixel per inch */
/* make XMAX and YMAX a multiple of 8 */
#define HP500C_XMAX (8*(unsigned int)(xsize*1920/HP500C_DPP/8.0+0.9))
#define HP500C_YMAX (8*(unsigned int)(ysize*1920/HP500C_DPP/8.0+0.9))

/* Courier font with 6 lines per inch */
#define HP500C_VCHAR (HP500C_PPI/6)
/* Courier font with 10 caracters per inch */
#define HP500C_HCHAR (HP500C_PPI/10)


/* Save current cursor position */
#define HP500C_PUSH_CURSOR fputs("\033&f0S",gpoutfile)
/* Restore cursor position */
#define HP500C_POP_CURSOR fputs("\033&f1S",gpoutfile)

/* be sure to use courier font with 6lpi and 10cpi */
#define HP500C_COURIER fputs("\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D",gpoutfile)


static int HPcompress __PROTO((unsigned char *op, unsigned char *oe,
			       unsigned char *cp));
static unsigned char HPcomplement __PROTO((int c));
static int HPcompress_to_TIFF __PROTO((unsigned char *op, unsigned char *oe,
				       unsigned char *cp));
static int HPnocompress __PROTO((unsigned char *op, unsigned char *oe,
				 unsigned char *cp));

static int hpdj_dpp = 4;
static int HP_COMP_MODE = 0;

/* bm_pattern not appropriate for 300ppi graphics */
#ifndef GOT_300_PATTERN
#define GOT_300_PATTERN
static unsigned int b_300ppi_pattern[] =
{
    0xffff, 0x1111,
    0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff
};
#endif


TERM_PUBLIC void HP500Coptions()
{
    char opt[6];

#define HPDJCERROR "expecting dots per inch size 75, 100, 150 or 300 and/or compression method"
    while (!END_OF_COMMAND) {
	if (token[c_token].length > 4)
	    int_error(HPDJCERROR, c_token);

	/* almost_equals() won't accept numbers - use strcmp() instead */
	capture(opt, c_token, c_token, 6);
	if (!strcmp(opt, "75")) {
	    hpdj_dpp = 4;
	    HP_COMP_MODE = 0;

	} else if (!strcmp(opt, "100")) {
	    hpdj_dpp = 3;
	    HP_COMP_MODE = 0;
	} else if (!strcmp(opt, "150")) {
	    hpdj_dpp = 2;
	    HP_COMP_MODE = 0;
	} else if (!strcmp(opt, "300")) {
	    hpdj_dpp = 1;
	    HP_COMP_MODE = 0;
	} else if (!strcmp(opt, "rle")) {
	    HP_COMP_MODE = 1;
	} else if (!strcmp(opt, "tiff")) {
	    HP_COMP_MODE = 2;
	}
	c_token++;
    }

    term->xmax = HP500C_XMAX;
    term->ymax = HP500C_YMAX;
    switch (hpdj_dpp) {
    case 1:
	strcpy(term_options, "300");
	term->v_tic = 15;
	term->h_tic = 15;
	break;
    case 2:
	strcpy(term_options, "150");
	term->v_tic = 8;
	term->h_tic = 8;
	break;
    case 3:
	strcpy(term_options, "100");
	term->v_tic = 6;
	term->h_tic = 6;
	break;
    case 4:
	strcpy(term_options, "75");
	term->v_tic = 5;
	term->h_tic = 5;
	break;
    }
    switch (HP_COMP_MODE) {
    case 0:
	strcat(term_options, " no comp");
	break;
    case 1:
	strcat(term_options, " RLE");
	break;
    case 2:
	strcat(term_options, " TIFF");
	break;
    case 3:			/* not implemented yet */
	strcat(term_options, " Delta Row");
	break;
    }
}

TERM_PUBLIC void HP500Cinit()
{
    /* HBB 980226: all changes to term-> fields *must* happen here, not
     * in graphics() !*/
    switch (hpdj_dpp) {
    case 1:
	b_charsize(FNT13X25);
	term->v_char = FNT13X25_VCHAR;
	term->h_char = FNT13X25_HCHAR;
	break;
    case 2:
	b_charsize(FNT13X25);
	term->v_char = FNT13X25_VCHAR;
	term->h_char = FNT13X25_HCHAR;
	break;
    case 3:
	b_charsize(FNT9X17);
	term->v_char = FNT9X17_VCHAR;
	term->h_char = FNT9X17_HCHAR;
	break;
    case 4:
	b_charsize(FNT5X9);
	term->v_char = FNT5X9_VCHAR;
	term->h_char = FNT5X9_HCHAR;
	break;
    }
}

TERM_PUBLIC void HP500Creset()
{
#ifdef VMS
    fflush_binary();
#endif
}



/* HP DeskJet 500c routines */

TERM_PUBLIC void HP500Clinetype(linetype)
int linetype;
{
    if (linetype < 0)
	linetype = 7;
    else if (linetype >= 8) {
	linetype %= 8;
    }
    switch (linetype) {
    case 0:
	linetype = 6;
	break;
    case 1:
	linetype = 5;
	break;
    case 2:
	linetype = 3;
	break;
    case 3:
	linetype = 2;
	break;
    case 4:
	linetype = 1;
	break;
    case 5:
	linetype = 4;
	break;
    case 6:
	linetype = 7;
    }
    b_setvalue(linetype);

}

/*
void HP500Cpoint(x,y,value)
int x;
int y;
int value;
{
	 HP500Clinetype(value);
	 do_point(x,y,value);
}
*/

TERM_PUBLIC void HP500Cgraphics()
{
    /* HBB 980226: moved block of code from here to init() */
    /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
       setting b_rastermode to TRUE */
    b_makebitmap(HP500C_YMAX, HP500C_XMAX, 3);
    b_rastermode = TRUE;
}

/*
 * Run-length encoding for the DeskJet. We have pairs of <count>
 * <what>, where count goes from 0 (meaning one count) to 255
 * this might double the size of the image.
 */

static int HPcompress(op, oe, cp)
unsigned char *op, *oe, *cp;
{
    unsigned char *ce = cp;
    while (op < oe) {
	unsigned char prevchar;
	unsigned char count;

	prevchar = *op;		/* remember char */
	count = 1;		/* its read the first time */

	while (++op < oe && *op == prevchar && count < 255) {
            /* set op to the next char */
	    count++;		/* and count it  */
	}
	*ce++ = --count;	/* were ready, so correct the count */
	*ce++ = prevchar;	/* and store <what> */
    }
    *ce = 0;			/* just to be safe   */
    return ce - cp;		/* length of  cbufs */
}

static unsigned char HPcomplement(c)
int c;
{
    return (unsigned char) (256 - c);
}


static int HPcompress_to_TIFF(op, oe, cp)
unsigned char *op;		/* original pointer */
unsigned char *oe;		/* end of orig string */
unsigned char *cp;		/* pointer for compressed data */
{
    unsigned char *countposition;
    unsigned char *ce = cp;
    while (op < oe) {
	unsigned char prevchar;
	unsigned char count;

	prevchar = *op;		/* gelesenes Zeichen aufbewaren */
	count = 1;		/* bisher wurde es einmal gelesen */

	while (++op < oe && *op == prevchar && count < 128) {
	    count++;
	}
	*ce = HPcomplement(count - 1);
        /* remember count for building blocks of literal bytes */
	countposition = ce++;
	*ce++ = prevchar;

	if (count < 2) {
	    while (op < oe && (prevchar != *op || *op != *(op + 1))) {
                /* only use rle for at leat 3 equal bytes */
		*ce++ = *op;
		count++;
		prevchar = *op++;
		if (op > oe)
		    puts("FATAL op> oe!!\n");
	    }
	    if (op < oe && prevchar == *op) {
		op--;
		count--;
		ce--;
	    }
	    *countposition = count - 1;
	}
    }
    return ce - cp;

}

static int HPnocompress(op, oe, cp)
unsigned char *op;
unsigned char *oe;
unsigned char *cp;
{
    unsigned char *ce = cp;
    while (op < oe)
	*ce++ = *op++;
    return ce - cp;
}

/* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
   hopefully compatible with other HP Deskjet printers */

TERM_PUBLIC void HP500Ctext()
{
    register int x, j, row, count = 0;
    unsigned char *obuf, *oe, *cbuf, *ce;

    if ((obuf = (unsigned char *) malloc(100 * b_psize)) == 0)
	puts("FATAL!-- couldn't get enough memory for obuf");
    if ((cbuf = (unsigned char *) malloc(400 * b_psize)) == 0)
	puts("FATAL!-- couldn't get enough memory for cbuf");

    oe = obuf;

    fprintf(gpoutfile, "\
\033*t%dR\
\033*r1A\
\033*b%1dM\
\033*r%dS\
\033*r-3U",
	    HP500C_PPI,
	    HP_COMP_MODE,
	    b_ysize);

    /* dump bitmap in raster mode */
    for (x = b_xsize - 1; x >= 0; x--) {
	row = (b_ysize / 8) - 1;
	for (j = row; j >= 0; j--) {
	    *oe++ = (char) (*((*b_p)[j] + x));
	}
	switch (HP_COMP_MODE) {
	case 2:
	    count = HPcompress_to_TIFF(obuf, oe, cbuf);
	    break;
	case 1:
	    count = HPcompress(obuf, oe, cbuf);
	    break;
	case 0:
	    count = HPnocompress(obuf, oe, cbuf);
	    break;
	}
	fprintf(gpoutfile, "\033*b%dV", count);
	ce = cbuf;
	while (count--)
	    fputc(*ce++, gpoutfile);
	oe = obuf;

	for (j = row; j >= 0; j--) {
	    *oe++ = (char) (*((*b_p)[j + b_psize] + x));
	}
	switch (HP_COMP_MODE) {
	case 2:
	    count = HPcompress_to_TIFF(obuf, oe, cbuf);
	    break;
	case 1:
	    count = HPcompress(obuf, oe, cbuf);
	    break;
	case 0:
	    count = HPnocompress(obuf, oe, cbuf);
	    break;

	}

	fprintf(gpoutfile, "\033*b%dV", count);
	ce = cbuf;
	while (count--)
	    fputc(*ce++, gpoutfile);
	oe = obuf;

	for (j = row; j >= 0; j--) {
	    *oe++ = (char) (*((*b_p)[j + (2 * b_psize)] + x));
	}
	switch (HP_COMP_MODE) {
	case 2:
	    count = HPcompress_to_TIFF(obuf, oe, cbuf);
	    break;
	case 1:
	    count = HPcompress(obuf, oe, cbuf);
	    break;
	case 0:
	    count = HPnocompress(obuf, oe, cbuf);
	    break;
	}
	fprintf(gpoutfile, "\033*b%dW", count);
	ce = cbuf;
	while (count--)
	    fputc(*ce++, gpoutfile);
	oe = obuf;

    }
    fputs("\033*rbC", gpoutfile);
    free(cbuf);
    free(obuf);
    b_freebitmap();

#ifndef VMS
    /* most vms spoolers add a formfeed character */
    putc('\f', gpoutfile);
#endif /* !VMS */
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(hp500c_driver)
    "hp500c", "HP DeskJet 500c, [75 100 150 300] [rle tiff]",
    HP500C_75PPI_XMAX, HP500C_75PPI_YMAX, HP500C_75PPI_VCHAR,
    HP500C_75PPI_HCHAR, HP500C_75PPI_VTIC, HP500C_75PPI_HTIC, HP500Coptions,
    HP500Cinit, HP500Creset, HP500Ctext, null_scale,
    HP500Cgraphics, HP500Cmove, HP500Cvector, HP500Clinetype,
    HP500Cput_text, HP500Ctext_angle, null_justify_text, do_point,
    do_arrow, set_font_null, 0, TERM_BINARY
TERM_TABLE_END(hp500c_driver)

#undef LAST_TERM
#define LAST_TERM hp500c_driver

#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(hp500c)
"1 hp500c",
"?commands set terminal hp500c",
"?set terminal hp500c",
"?set term hp500c",
"?terminal hp500c",
"?term hp500c",
"?hp500c",
" The `hp500c` terminal driver supports the Hewlett Packard HP DeskJet 500c.",
" It has options for resolution and compression.",
"",
" Syntax:",
"       set terminal hp500c {<res>} {<comp>}",
"",
" where `res` can be 75, 100, 150 or 300 dots per inch and `comp` can be \"rle\",",
" or \"tiff\".  Any other inputs are replaced by the defaults, which are 75 dpi",
" and no compression.  Rasterization at the higher resolutions may require a",
" large amount of memory."
END_HELP(hp500c)
#endif /* TERM_HELP */