File: metapost.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 (789 lines) | stat: -rw-r--r-- 23,680 bytes parent folder | download
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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
/*
 * $Id: metapost.trm,v 1.5.2.4 1999/09/16 16:05:21 lhecking Exp $
 */

/* GNUPLOT - metapost.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.
]*/

/* 1999/04/22
 *			GNUPLOT -- metapost.trm
 *
 *			This terminal driver supports:
 *		    		Metapost Commands
 *
 * Based on metafont.trm, written by
 *		Pl Hedne
 *		Trondheim, Norway
 *		Pal.Hedne@termo.unit.no;
 *		with improvements by Carsten Steger
 *
 * and pstricks.trm, written by
 *		David Kotz and Raymond Toy
 *
 * Adapted to metapost by:
 * 		Daniel H. Luecking <luecking@comp.uark.edu> and
 * 	 	L Srinivasa Mohan <mohan@chemeng.iisc.ernet.in>
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(mp)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void MP_options __PROTO((void));
TERM_PUBLIC void MP_init __PROTO((void));
TERM_PUBLIC void MP_graphics __PROTO((void));
TERM_PUBLIC void MP_text __PROTO((void));
TERM_PUBLIC void MP_linetype __PROTO((int linetype));
TERM_PUBLIC void MP_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void MP_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC void MP_pointsize __PROTO((double size));
TERM_PUBLIC void MP_linewidth __PROTO((double width));
TERM_PUBLIC void MP_vector __PROTO((unsigned int ux, unsigned int uy));
TERM_PUBLIC void MP_arrow __PROTO((unsigned int sx, unsigned int sy,
				   unsigned int ex, unsigned int ey,
				   TBOOLEAN head));
TERM_PUBLIC void MP_put_text __PROTO((unsigned int x, unsigned int y, char str[]));
TERM_PUBLIC int MP_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC int MP_text_angle __PROTO((int ang));
TERM_PUBLIC void MP_reset __PROTO((void));
TERM_PUBLIC int MP_set_font __PROTO((char *font));
TERM_PUBLIC void MP_boxfill __PROTO((int style,
				     unsigned int x1, unsigned int y1,
				     unsigned int width, unsigned int height));

/* 5 inches wide by 3 inches high (default) */
#define MP_XSIZE 5.0
#define MP_YSIZE 3.0

/* gnuplot units will be one pixel if printing device has this
   resolution */
#define MP_DPI (300)

#define MP_XMAX (MP_XSIZE*MP_DPI)
#define MP_YMAX (MP_YSIZE*MP_DPI)

#define MP_HTIC (5*MP_DPI/72)	/* nominally 5pt   */
#define MP_VTIC (5*MP_DPI/72)	/*    "      5pt   */
#define MP_HCHAR (MP_DPI*53/10/72)	/*    "      5.3pt */
#define MP_VCHAR (MP_DPI*11/72)	/*    "      11pt  */
#endif /* TERM_PROTO */

#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY

static double MP_xsize = MP_XSIZE;
static double MP_ysize = MP_YSIZE;
/* static double MP_xmax = MP_XMAX;
   static double MP_ymax = MP_YMAX;
 * unused, for now
 */
static int MP_posx;
static int MP_posy;
static char MP_fontname[MAX_ID_LEN + 1];
static double MP_fontsize;
static double MP_textmag;
enum JUSTIFY MP_justify = LEFT;
static int MP_ang = 0;
static int MP_char_code = 0;

/* number of nodes in an output line so far */
static int MP_linecount = 1;

/* Number of point types */
#define MP_POINT_TYPES 10

/* Number of line types */
#define MP_LINE_TYPES 8

/* are we in the middle of a MP path? */
static TBOOLEAN MP_inline = FALSE;
/* colored or dashed lines? */
static TBOOLEAN MP_color = FALSE;
static TBOOLEAN MP_solid = FALSE;

/* compatability mode*/
static TBOOLEAN MP_notex = FALSE;

/* has a font change taken place? */
static TBOOLEAN MP_fontchanged = FALSE;

/* The old types */
static int MP_oldline = -2;

/* The old sizes */
static double MP_oldptsize = 1.0;
static double MP_oldpen = 1.0;

/* terminate any path in progress */
static void MP_endline __PROTO((void));

/* max number of path nodes before a newline */
#define MP_LINEMAX 5

TERM_PUBLIC void
MP_options()
{
    MP_color = FALSE;
    MP_solid = FALSE;
    MP_notex = FALSE;
    MP_fontsize = 10.0;
    MP_textmag = 1.0;
    strcpy(MP_fontname, "cmr10");
    strcpy(default_font, "");	/* output file will store default font info */
    while (!END_OF_COMMAND) {
	if (almost_equals(c_token, "m$onochrome")) {
	    MP_color = FALSE;
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "c$olor") || almost_equals(c_token, "c$olour")) {
	    MP_color = TRUE;
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "s$olid")) {
	    MP_solid = TRUE;
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "da$shed")) {
	    MP_solid = FALSE;
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "n$otex")) {
	    MP_notex = TRUE;
	    strcpy(MP_fontname, "pcrr8r");
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "t$ex")) {
	    MP_notex = FALSE;
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "de$fault")) {
	    c_token++;
	    continue;
	}
	if (almost_equals(c_token, "m$agnification")) {
	    c_token++;
	    if (!END_OF_COMMAND) {	/* global text scaling */
		struct value a;
		MP_textmag = (double) real(const_express(&a));
	    }
	    c_token++;
	    continue;
	}
	break;
    }
    if (!END_OF_COMMAND && isstring(c_token)) {		/* font name */
	quote_str(MP_fontname, c_token, MAX_ID_LEN);
	c_token++;
    }
    if (!END_OF_COMMAND) {	/*font size */
	struct value a;
	MP_fontsize = (double) real(const_express(&a));
	c_token++;
    }
    /* minimal error recovery: */
    if (MP_fontsize < 5.0)
	MP_fontsize = 5.0;
    if (MP_fontsize > 99.99)
	MP_fontsize = 99.99;

    term->v_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 11 / 720);
    if (MP_notex) {		/* Courier is a little wider than cmtt */
	term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 6.0 / 720 + 0.5);
    } else {
	term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 5.3 / 720 + 0.5);
    }
    sprintf(term_options, "%s%s%s%s%6.3f \"%s\" %5.2f",
	    MP_color ? "color " : "", MP_solid ? "solid " : "",
	    MP_notex ? "notex " : "", "mag ",
	    MP_textmag, MP_fontname, MP_fontsize);
}

TERM_PUBLIC void
MP_init()
{
    time_t now;
    time(&now);
    MP_posx = MP_posy = 0;
    fprintf(gpoutfile, "%%GNUPLOT Metapost output: %s\n", asctime(localtime(&now)));
    fputs("\n\
defaultmpt:=mpt:=4;\n\
th:=.6;\n\
\n\
def scalepen expr n = pickup pencircle scaled (n*th) enddef;\n\
def ptsize expr n = mpt:=n*defaultmpt enddef;\n",
	  gpoutfile);

    fprintf(gpoutfile, "\ntextmag:=%6.3f;\n", MP_textmag);

    fputs("\
vardef makepic(expr str) =\n\
  if picture str : str scaled textmag\n\
  % otherwise a string\n\
  else: str infont defaultfont scaled (defaultscale*textmag)\n\
  fi\n\
enddef;\n\
\n\
def	infontsize(expr str, size) =\n\
  infont str scaled (size /	fontsize str)\n\
enddef;\n",
	  gpoutfile);

    if (MP_notex) {
	fprintf(gpoutfile, "\n\
defaultfont:= \"%s\";\n\
defaultscale := %6.3f/fontsize defaultfont;\n",
		MP_fontname, MP_fontsize);
    } else {
	fputs("\n\
%font changes\n\
verbatimtex\n\
  \\def\\setfont#1#2{%.\n\
    \\font\\gpfont=#1 at #2pt\n\
    \\gpfont}\n",
	      gpoutfile);

	fprintf(gpoutfile, "\\setfont{%s}{%5.2f}\netex\n",
		MP_fontname, MP_fontsize);
    }
    fputs("\n\
color currentcolor; currentcolor=black;\n\
boolean colorlines,dashedlines;\n",
	  gpoutfile);
    if (MP_color) {
	fputs("colorlines:=true;\n", gpoutfile);
    } else {
	fputs("colorlines:=false;\n", gpoutfile);
    }
    if (MP_solid) {
	fputs("dashedlines:=false;\n", gpoutfile);
    } else {
	fputs("dashedlines:=true;\n", gpoutfile);
    }
    fputs("\n\
def _wc = withpen currentpen withcolor currentcolor enddef;\n\
def _ac = addto currentpicture enddef;\n\
def _sms = scaled mpt shifted enddef;\n\
% drawing point-types\n\
def gpdraw (expr n, x, y) =\n\
  if n<0: _ac contour fullcircle _sms (x,y)\n\
  elseif (n=1) or (n=3):\n\
    _ac doublepath ptpath[n] _sms (x,y) _wc;\n\
    _ac doublepath ptpath[n] rotated 90 _sms (x,y) _wc\n\
  elseif n<6: _ac doublepath ptpath[n] _sms (x,y) _wc\n\
  else: _ac contour ptpath[n] _sms (x,y) _wc\n\
  fi\n\
enddef;\n\
\n\
% the point shapes\n\
path ptpath[];\n\
%diamond\n\
ptpath0 = ptpath6 = (-1/2,0)--(0,-1/2)--(1/2,0)--(0,1/2)--cycle;\n\
% plus sign\n\
ptpath1 = (-1/2,0)--(1/2,0);\n\
% square\n\
ptpath2 = ptpath7 = (-1/2,-1/2)--(1/2,-1/2)--(1/2,1/2)--(-1/2,1/2)--cycle;\n\
% cross\n\
ptpath3 := (-1/2,-1/2)--(1/2,1/2);\n\
% circle:\n\
ptpath4 = ptpath8:= fullcircle;\n\
% triangle\n\
ptpath5 = ptpath9 := (0,1/2)--(-1/2,-1/2)--(1/2,-1/2)--cycle;\n\
\n\
def linetype expr n =\n\
  currentcolor:= if colorlines : col[n] else: black fi;\n\
  if n = -1 :\n\
      drawoptions(withcolor currentcolor withpen (currentpen scaled .5));\n\
  elseif n < 1 :\n\
    drawoptions(_wc);\n\
  else :\n\
    drawoptions( if dashedlines: dashed lt[n] fi _wc);\n\
  fi\n\
enddef;\n\
\n\
% dash patterns\n\
picture lt[];\n\
lt1=dashpattern(on 2 off 2); % dashes\n\
lt2=dashpattern(on 2 off 2 on 0.2 off 2); %dash-dot\n\
lt3=lt1 scaled 1.414;\n\
lt4=lt2 scaled 1.414;\n\
lt5=lt1 scaled 2;\n\
lt6:=lt2 scaled 2;\n\
lt7=dashpattern(on 0.2 off 2); %dots\n\
\n\
color col[],cyan, magenta, yellow;\n\
cyan=blue+green; magenta=red+blue;yellow=green+red;\n\
col[-2]:=col[-1]:=col0:=black;\n\
col1:=red;\n\
col2:=(.2,.2,1); %blue\n\
col3:=(1,.66,0); %orange\n\
col4:=.85*green;\n\
col5:=.9*magenta;\n\
col6:=0.85*cyan;\n\
col7:=.85*yellow;\n\
\n\
%placing text\n\
picture GPtext;\n\
def put_text(expr pic, x, y, r, j) =\n\
  GPtext:=makepic(pic);\n\
  GPtext:=GPtext shifted\n\
    if j = 1: (-(ulcorner GPtext + llcorner GPtext)/2)\n\
    elseif j = 2: (-center GPtext)\n\
    else: (-(urcorner GPtext + lrcorner GPtext)/2)\n\
    fi\n\
    rotated if r > 0: 90 else: 0 fi;\n\
  draw GPtext shifted (x,y)\n\
enddef;\n",
	  gpoutfile);
}

TERM_PUBLIC void
MP_graphics()
{
    /* initialize "remembered" drawing parameters */
    MP_oldline = -2;
    MP_oldpen = 1.0;
    MP_oldptsize = pointsize;
    fprintf(gpoutfile, "\nbeginfig(%d);\nw:=%gin;h:=%gin;\n",
	    MP_char_code, MP_xsize, MP_ysize);
    fprintf(gpoutfile, "a:=w/%d;b:=h/%d;\n", term->xmax, term->ymax);
    fprintf(gpoutfile, "scalepen 1; ptsize %g;linetype -2;\n", pointsize);
    MP_char_code++;
}

TERM_PUBLIC void
MP_text()
{
    if (MP_inline)
	MP_endline();
    fputs("endfig;\n", gpoutfile);
}

TERM_PUBLIC void
MP_linetype(lt)
int lt;
{
    int linetype = lt;
    if (linetype >= MP_LINE_TYPES)
	linetype %= MP_LINE_TYPES;
    if (MP_inline)
	MP_endline();
    if (MP_oldline != linetype) {
	fprintf(gpoutfile, "linetype %d;\n", linetype);
	MP_oldline = linetype;
    }
}

TERM_PUBLIC void
MP_move(x, y)
unsigned int x;
unsigned int y;
{
    if ((x != MP_posx) || (y != MP_posy)) {
	if (MP_inline)
	    MP_endline();
	MP_posx = x;
	MP_posy = y;
    }				/* else we seem to be there already */
}

TERM_PUBLIC void
MP_point(x, y, pt)
unsigned int x;
unsigned int y;
int pt;
{
    int pointtype = pt;
    if (MP_inline)
	MP_endline();

    /* Print the shape defined by 'number'; number < 0 means
       to use a dot, otherwise one of the defined points. */

    if (pointtype >= MP_POINT_TYPES)
	pointtype %= MP_POINT_TYPES;
    fprintf(gpoutfile, "gpdraw(%d,%da,%db);\n", pointtype, x, y);
}

TERM_PUBLIC void
MP_pointsize(ps)
double ps;
{
    if (MP_oldptsize != ps) {
	if (MP_inline)
	    MP_endline();
	fprintf(gpoutfile, "ptsize %g;\n", ps);
	MP_oldptsize = ps;
    }
}


TERM_PUBLIC void
MP_linewidth(lw)
double lw;
{
    if (MP_oldpen != lw) {
	if (MP_inline)
	    MP_endline();
	fprintf(gpoutfile, "scalepen %g;\n", lw);
	MP_oldpen = lw;
    }
}


TERM_PUBLIC void
MP_vector(ux, uy)
unsigned int ux;
unsigned int uy;
{
    if ((ux == MP_posx) && (uy == MP_posy))
	return;			/* Zero length line */

    if (MP_inline) {
	if (MP_linecount++ >= MP_LINEMAX) {
	    fputs("\n", gpoutfile);
	    MP_linecount = 1;
	}
    } else {
	MP_inline = TRUE;
	fprintf(gpoutfile, "draw (%da,%db)", MP_posx, MP_posy);
	MP_linecount = 2;
    }
    MP_posx = ux;
    MP_posy = uy;
    fprintf(gpoutfile, "--(%da,%db)", MP_posx, MP_posy);
}

static void
MP_endline()
{
    MP_inline = FALSE;
    fprintf(gpoutfile, ";\n");
}

TERM_PUBLIC void
MP_arrow(sx, sy, ex, ey, head)
unsigned int sx;
unsigned int sy;
unsigned int ex;
unsigned int ey;
TBOOLEAN head;
{
    MP_move(sx, sy);
    if (head) {
	fprintf(gpoutfile, "drawarrow (%da,%db)--(%da,%db);\n",
		sx, sy, ex, ey);
    } else if ((sx != ex) || (sy != ey)) {
	fprintf(gpoutfile, "draw (%da,%db)--(%da,%db);\n",
		sx, sy, ex, ey);
    }				/* else: arrow with no length and no head = sound of one hand clapping? */
    MP_posx = ex;
    MP_posy = ey;

}

TERM_PUBLIC void
MP_put_text(x, y, str)
unsigned int x, y;
char str[];
{
    int i, j = 0;
    char *text;

    /* ignore empty strings */
    if (!str || !*str)
	return;

    /* F***. why do drivers need to modify string args? */
    text = gp_alloc(strlen(str)+1, "temp string");
    strcpy(text,str);

    if (MP_inline)
	MP_endline();


    switch (MP_justify) {
    case LEFT:
	j = 1;
	break;
    case CENTRE:
	j = 2;
	break;
    case RIGHT:
	j = 3;
	break;
    }
    if (MP_notex) {
	for (i = 0; i < strlen(text); i++)
	    if (text[i] == '"')
		text[i] = '\'';	/* Replace " with ' */
	if (MP_fontchanged) {
	    fprintf(gpoutfile, "\
put_text(\"%s\" infontsize(\"%s\",%5.2f), %da, %db, %d, %d);\n",
		    text, MP_fontname, MP_fontsize, x, y, MP_ang, j);
	} else {
	    fprintf(gpoutfile, "put_text(\"%s\", %da, %db, %d, %d);\n",
		    text, x, y, MP_ang, j);
	}
    } else if (MP_fontchanged) {
	fprintf(gpoutfile, "\
put_text( btex \\setfont{%s}{%5.2f} %s etex, %da, %db, %d, %d);\n",
		MP_fontname, MP_fontsize, text, x, y, MP_ang, j);
    } else {
	fprintf(gpoutfile, "put_text( btex %s etex, %da, %db, %d, %d);\n",
		text, x, y, MP_ang, j);
    }

    free(text);
}

TERM_PUBLIC int
MP_justify_text(mode)
enum JUSTIFY mode;
{
    MP_justify = mode;
    return (TRUE);
}

TERM_PUBLIC int
MP_text_angle(ang)
int ang;
{
    /* Metapost code does the conversion */
    MP_ang = ang;
    return (TRUE);
}

TERM_PUBLIC int
MP_set_font(font)
char *font;
{
    if (*font) {
	size_t sep = strcspn(font, ",");
	strncpy(MP_fontname, font, sep);
	MP_fontname[sep] = NUL;
	sscanf(&(font[sep + 1]), "%lf", &MP_fontsize);
	if (MP_fontsize < 5)
	    MP_fontsize = 5.0;
	if (MP_fontsize >= 100)
	    MP_fontsize = 99.99;
	/*  */
	MP_fontchanged = TRUE;
    } else {
	MP_fontchanged = FALSE;
    }
    return TRUE;
}


TERM_PUBLIC void
MP_reset()
{
    fputs("end.\n", gpoutfile);
}

TERM_PUBLIC void
MP_boxfill(sty, x1, y1, wd, ht)
int sty;
unsigned int x1, y1, wd, ht;
{
    /* for now simply clear box if sty <= 0, do nothing otherwise */
    if (MP_inline)
	MP_endline();
    if (sty <= 0)
	fprintf(gpoutfile, "\
fill (%da,%db)--(%da,%db)--(%da,%db)--(%da,%db)--cycle withcolor background;\n",
		x1, y1, x1 + wd, y1, x1 + wd, y1 + ht, x1, y1 + ht);
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(mp_driver)
    "mp", "MetaPost plotting standard",
    MP_XMAX, MP_YMAX, MP_VCHAR, MP_HCHAR,
    MP_VTIC, MP_HTIC, MP_options, MP_init, MP_reset,
    MP_text, null_scale, MP_graphics, MP_move, MP_vector,
    MP_linetype, MP_put_text, MP_text_angle,
    MP_justify_text, MP_point, MP_arrow, MP_set_font, MP_pointsize,
    0, 0, 0, MP_boxfill, MP_linewidth
    TERM_TABLE_END(mp_driver)
#undef LAST_TERM
#define LAST_TERM mp_driver

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

#ifdef TERM_HELP
START_HELP(mp)
"1 mp",
"?commands set terminal mpost",
"?set terminal mp",
"?set term mp",
"?terminal mp",
"?term mp",
"?mp",
"?metapost",
"",
" The `mp` driver produces output intended to be input to the Metapost program.",
" Running Metapost on the file creates EPS files containing the plots. By",
" default, Metapost passes all text through TeX.  This has the advantage of",
" allowing essentially  any TeX symbols in titles and labels.",
"",
" The `mp` terminal is selected with a command of the form",
"    set term mp {color} {solid} {notex} {mag <magsize>} {\"<name>\"} {<size>}",
" The option `color` causes lines to be drawn in color (on a printer or display",
" that supports it), `monochrome` (or nothing) selects black lines.  The option",
" `solid` draws solid lines, while `dashed` (or nothing) selects lines with",
" different patterns of dashes.  If `solid` is selected but `color` is not,",
" nearly all lines will be identical.  This may occasionally be useful, so it is",
" allowed.",
"",
" The option `notex` bypasses TeX entirely, therefore no TeX code can be used in",
" labels under this option.  This is intended for use on old plot files or files",
" that make frequent use of common characters like `$` and `%` that require",
" special handling in TeX.",
"",
" Changing font sizes in TeX has no effect on the size of mathematics, and there",
" is no foolproof way to make such a change, except by globally  setting a",
" magnification factor. This is the purpose of the `magnification` option. It",
" must be followed by a scaling factor. All text (NOT the graphs) will be scaled",
" by this factor. Use this if you have math that you want at some size other",
" than the default 10pt. Unfortunately, all math will be the same size, but see",
" the discussion below on editing the MP output. `mag` will also work under",
" `notex` but there seems no point in using it as the font size option (below)",
" works as well.",
"",
" A name in quotes selects the font that will be used when no explicit font is",
" given in a `set label` or `set title`.  A name recognized by TeX (a TFM file",
" exists) must be used.  The default is \"cmr10\" unless `notex` is selected,",
" then it is \"pcrr8r\" (Courier).  Even under `notex`, a TFM file is needed by",
" Metapost. The file `pcrr8r.tfm` is the name given to Courier in LaTeX's psnfss",
" package.  If you change the font from the `notex` default, choose a font that",
" matches the ASCII encoding at least in the range 32-126.  `cmtt10` almost",
" works, but it has a nonblank character in position 32 (space).",
"",
" The size can be any number between 5.0 and 99.99.  If it is omitted, 10.0 is",
" used.  It is advisable to use `magstep` sizes: 10 times an integer or",
" half-integer power of 1.2, rounded to two decimals, because those are the most",
" available sizes of fonts in TeX systems.",
"",
" All the options are optional.  If font information is given, it must be at the",
" end, with size (if present) last.  The size is needed to select a size for the",
" font, even if the font name includes size information.  For example,",
" `set term mp \"cmtt12\"` selects cmtt12 shrunk to the default size 10.  This",
" is probably not what you want or you would have used cmtt10.",
"",
" The following common ascii characters need special treatment in TeX:",
"    $, &, #, %, _;  |, <, >;  ^, ~,  \\, {, and }",
" The five characters $, #, &, _, and % can simply be escaped, e.g., `\\$`.",
" The three characters <, >, and | can be wrapped in math mode, e.g., `$<$`.",
" The remainder require some TeX work-arounds.  Any good book on TeX will give",
" some guidance.",
"",
" If you type your labels inside double quotes, backslashes in TeX code need to",
" be escaped (doubled). Using single quotes will avoid having to do this, but",
" then you cannot use `\\n` for line breaks.  As of this writing, version 3.7 of",
" gnuplot processess titles given in a `plot` command differently than in other",
" places, and backslashes in TeX commands need to be doubled regardless of the",
" style of quotes.",
"",
" Metapost pictures are typically used in TeX documents.  Metapost deals with",
" fonts pretty much the same way TeX does, which is different from most other",
" document preparation programs.  If the picture is included in a LaTeX document",
" using the graphics package, or in a plainTeX document via epsf.tex, and then",
" converted to PostScript with dvips (or other dvi-to-ps converter), the text in",
" the plot will usually be handled correctly.  However, the text may not appear",
" if you send the Metapost output as-is to a PostScript interpreter.",
"",
"2 Metapost Instructions",
"?commands set terminal mp detailed",
"?set terminal mp detailed",
"?set term mp detailed",
"?mp detailed",
"?metapost detailed",
"",
" - Set your terminal to Metapost, e.g.:",
"    set terminal mp mono \"cmtt12\" 12",
"",
" - Select an output-file, e.g.:",
"    set output \"figure.mp\"",
"",
" - Create your pictures.  Each plot (or multiplot group) will generate a",
" separate Metapost beginfig...endfig group.  Its default size will be 5 by 3",
" inches.  You can change the size by saying `set size 0.5,0.5` or whatever",
" fraction of the default size you want to have.",
"",
" - Quit gnuplot.",
"",
" - Generate EPS files by running Metapost on the output of gnuplot:",
"    mpost figure.mp  OR  mp figure.mp",
" The name of the Metapost program depends on the system, typically `mpost` for",
" a Unix machine and `mp` on many others.  Metapost will generate one EPS file",
" for each picture.",
"",
" - To include your pictures in your document you can use the graphics package",
" in LaTeX or epsf.tex in plainTeX:",
"    \\usepackage{graphics} % LaTeX",
"    \\input epsf.tex       % plainTeX",
" If you use a driver other than dvips for converting TeX DVI output to PS, you",
" may need to add the following line in your LaTeX document:",
"    \\DeclareGraphicsRule{*}{eps}{*}{}",
" Each picture you made is in a separate file.  The first picture is in, e.g.,",
" figure.0, the second in figure.1, and so on....  To place the third picture in",
" your document, for example, all you have to do is:",
"    \\includegraphics{figure.2} % LaTeX",
"    \\epsfbox{figure.2}         % plainTeX",
"",
" The advantage, if any, of the mp terminal over a postscript terminal is",
" editable output.  Considerable effort went into making this output as clean as",
" possible.  For those knowledgeable in the Metapost language, the default line",
" types and colors can be changed by editing the arrays `lt[]` and `col[]`.",
" The choice of solid vs dashed lines, and color vs black lines can be change by",
" changing the values assigned to the booleans `dashedlines` and `colorlines`.",
" If the default `tex` option was in effect, global changes to the text of",
" labels can be achieved by editing the `vebatimtex...etex` block.  In",
" particular, a LaTeX preamble can be added if desired, and then LaTeX's",
" built-in size changing commands can be used for maximum flexibility. Be sure",
" to set the appropriate MP configuration variable to force Metapost to run",
" LaTeX instead of plainTeX."
END_HELP(mp)
#endif /* TERM_HELP */