FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/term/metapost.trm at master · gnuplot/gnuplot-old · GitHub
gnuplot
/
gnuplot-old
Public
Notifications
You must be signed in to change notification settings
Fork
56
Star
139
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot-old
/
term
/
metapost.trm
Copy path
More file actions
More file actions
Latest commit
History
History
History
1225 lines (1128 loc) · 37.7 KB
Breadcrumbs
gnuplot-old
/
term
/
metapost.trm
Copy path
File metadata and controls
1225 lines (1128 loc) · 37.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Hello, Emacs, this is -*-C-*-
* $Id: metapost.trm,v 1.48 2017-08-08 04:10:33 sfeam Exp $
*/
/* GNUPLOT - metapost.trm */
/*[
* Copyright 1990 - 1993, 1998, 2004
*
* 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
,
int
head
));
TERM_PUBLIC
void
MP_put_text
__PROTO
((
unsigned
int
x
,
unsigned
int
y
,
const
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
((
const
char
*
font
));
TERM_PUBLIC
void
MP_boxfill
__PROTO
((
int
style
,
unsigned
int
x1
,
unsigned
int
y1
,
unsigned
int
width
,
unsigned
int
height
));
TERM_PUBLIC
int
MP_make_palette
__PROTO
((
t_sm_palette
*
));
TERM_PUBLIC
void
MP_previous_palette
__PROTO
((
void
));
TERM_PUBLIC
void
MP_set_color
__PROTO
((
t_colorspec
*
));
TERM_PUBLIC
void
MP_filled_polygon
__PROTO
((
int
,
gpiPoint
*
));
TERM_PUBLIC
void
MP_dashtype
__PROTO
((
int
type
,
t_dashtype
*
custom_dash_type
));
/* 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. Too small resolutions (like 300) can give rough
appearence to curves when user tries to smooth a curve by choosing
high sampling rate. */
#define
MP_DPI
(2400)
#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
;
static
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; */
#define
MP_NO_TEX
0
#define
MP_TEX
1
#define
MP_LATEX
2
static
int
MP_tex
=
MP_TEX
;
/* add usepackage instructions for PSNFSS ? */
#define
MP_PSNFSS_NONE
0
#define
MP_PSNFSS_7
1
#define
MP_PSNFSS_8
2
static
int
MP_psnfss
=
MP_PSNFSS_NONE
;
/* should amstex packages be included? */
static
int
MP_amstex
=
0
;
/* add a4paper option to documentclass */
static
int
MP_a4paper
=
0
;
/* write a prologues line */
static
int
MP_prologues
=
-1
;
/* has color changed? */
static
int
MP_color_changed
=
0
;
static
int
MP_dash_changed
=
0
;
/* 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
enum
MP_id
{
MP_OPT_MONOCHROME
,
MP_OPT_COLOUR
,
MP_OPT_SOLID
,
MP_OPT_DASHED
,
MP_OPT_NOTEX
,
MP_OPT_TEX
,
MP_OPT_LATEX
,
MP_OPT_A4PAPER
,
MP_OPT_PSNFSS
,
MP_OPT_PSNFSS_V7
,
MP_OPT_NOPSNFSS
,
MP_OPT_AMSTEX
,
MP_OPT_FONT
,
MP_OPT_FONTSIZE
,
MP_OPT_PROLOGUES
,
MP_OPT_NOPROLOGUES
,
MP_OPT_MAGNIFICATION
,
MP_OPT_OTHER
};
static
struct
gen_table
MP_opts
[]
=
{
{
"mo$nochrome"
,
MP_OPT_MONOCHROME
},
{
"c$olor"
,
MP_OPT_COLOUR
},
{
"c$olour"
,
MP_OPT_COLOUR
},
{
"s$olid"
,
MP_OPT_SOLID
},
{
"da$shed"
,
MP_OPT_DASHED
},
{
"n$otex"
,
MP_OPT_NOTEX
},
{
"t$ex"
,
MP_OPT_TEX
},
{
"la$tex"
,
MP_OPT_LATEX
},
{
"a4$paper"
,
MP_OPT_A4PAPER
},
{
"am$stex"
,
MP_OPT_AMSTEX
},
{
"ps$nfss"
,
MP_OPT_PSNFSS
},
{
"psnfss-v$ersion7"
,
MP_OPT_PSNFSS_V7
},
{
"nops$nfss"
,
MP_OPT_NOPSNFSS
},
{
"pro$logues"
,
MP_OPT_PROLOGUES
},
{
"nopro$logues"
,
MP_OPT_NOPROLOGUES
},
{
"ma$gnification"
,
MP_OPT_MAGNIFICATION
},
{
"fo$nt"
,
MP_OPT_FONT
},
{
NULL
,
MP_OPT_OTHER
}
};
TERM_PUBLIC
void
MP_options
()
{
struct
value
a
;
/* Annoying hack to handle the case of 'set termoption' after */
/* we have already initialized the terminal. */
if
(!
almost_equals
(
c_token
-
1
,
"termopt$ion"
)) {
MP_color
=
FALSE;
MP_solid
=
FALSE;
MP_tex
=
MP_TEX
;
MP_a4paper
=
0
;
MP_amstex
=
0
;
MP_psnfss
=
MP_PSNFSS_NONE
;
MP_fontsize
=
10.0
;
MP_textmag
=
1.0
;
MP_prologues
=
-1
;
strcpy
(
MP_fontname
,
"cmr10"
);
term
->
flags
|=
TERM_IS_LATEX
;
}
while
(!
END_OF_COMMAND
) {
int
option
=
lookup_table
(
&
MP_opts
[
0
],
c_token
);
switch
(
option
) {
case
MP_OPT_MONOCHROME
:
MP_color
=
FALSE;
c_token
++
;
break
;
case
MP_OPT_COLOUR
:
MP_color
=
TRUE;
c_token
++
;
break
;
case
MP_OPT_SOLID
:
MP_solid
=
TRUE;
c_token
++
;
break
;
case
MP_OPT_DASHED
:
MP_solid
=
FALSE;
c_token
++
;
break
;
case
MP_OPT_NOTEX
:
MP_tex
=
MP_NO_TEX
;
strcpy
(
MP_fontname
,
"pcrr8r"
);
term
->
flags
&= ~
TERM_IS_LATEX
;
c_token
++
;
break
;
case
MP_OPT_TEX
:
MP_tex
=
MP_TEX
;
c_token
++
;
break
;
case
MP_OPT_LATEX
:
MP_tex
=
MP_LATEX
;
c_token
++
;
break
;
case
MP_OPT_AMSTEX
:
MP_tex
=
MP_LATEX
;
/* only makes sense when using LaTeX */
MP_amstex
=
1
;
c_token
++
;
break
;
case
MP_OPT_A4PAPER
:
MP_tex
=
MP_LATEX
;
/* only makes sense when using LaTeX */
MP_a4paper
=
1
;
c_token
++
;
break
;
case
MP_OPT_PSNFSS
:
MP_tex
=
MP_LATEX
;
/* only makes sense when using LaTeX */
MP_psnfss
=
MP_PSNFSS_8
;
c_token
++
;
break
;
case
MP_OPT_PSNFSS_V7
:
MP_tex
=
MP_LATEX
;
/* only makes sense when using LaTeX */
MP_psnfss
=
MP_PSNFSS_7
;
c_token
++
;
break
;
case
MP_OPT_NOPSNFSS
:
MP_psnfss
=
MP_PSNFSS_NONE
;
c_token
++
;
break
;
case
MP_OPT_PROLOGUES
:
c_token
++
;
if
(!(
END_OF_COMMAND
)) {
int
dummy_for_prologues
;
if
(
sscanf
(
gp_input_line
+
token
[
c_token
].
start_index
,
"%d"
,
&
dummy_for_prologues
)
==
1
) {
MP_prologues
=
dummy_for_prologues
;
}
c_token
++
;
}
break
;
case
MP_OPT_NOPROLOGUES
:
MP_prologues
=
-1
;
c_token
++
;
break
;
case
MP_OPT_MAGNIFICATION
:
c_token
++
;
if
(!
END_OF_COMMAND
)
/* global text scaling */
MP_textmag
=
(
double
)
real
(
const_express
(
&
a
));
/* c_token++; */
/* Needed ??? */
break
;
case
MP_OPT_FONT
:
c_token
++
;
case
MP_OPT_OTHER
:
default
:
{
char
*
s
;
if
((
s
=
try_to_get_string
())) {
int
sep
=
strcspn
(
s
,
","
);
if
(
sep
>
0
) {
strncpy
(
MP_fontname
,
s
,
sizeof
(
MP_fontname
));
MP_fontname
[
sep
]
=
'\0'
;
}
if
(
s
[
sep
]
==
','
)
sscanf
(
&
s
[
sep
+
1
],
"%lf"
,
&
MP_fontsize
);
free
(
s
);
}
else
if
(
option
==
MP_OPT_FONT
) {
int_error
(
c_token
,
"expecting font name"
);
}
else
if
(!
END_OF_COMMAND
) {
/*font size */
MP_fontsize
=
(
double
)
real
(
const_express
(
&
a
));
c_token
++
;
}
break
;
}
}
}
/* 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_tex
==
MP_NO_TEX
) {
/* 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
);
}
if
(
MP_psnfss
==
MP_PSNFSS_NONE
) {
/* using the normal font scheme */
sprintf
(
term_options
,
"%s %s %stex%s%s mag %.3f font \"%s,%.2f\" %sprologues(%d)"
,
MP_color
?
"color"
:
"monochrome"
,
MP_solid
?
"solid"
:
"dashed"
,
(
MP_tex
==
MP_NO_TEX
) ?
"no"
: (
MP_tex
==
MP_LATEX
) ?
"la"
:
""
,
MP_a4paper
?
" a4paper"
:
""
,
MP_amstex
?
" amstex"
:
""
,
MP_textmag
,
MP_fontname
,
MP_fontsize
,
(
MP_prologues
>
-1
) ?
""
:
"no"
,
MP_prologues
);
}
else
{
/* using postscript fonts */
sprintf
(
term_options
,
"%s %s %stex%s%s mag %.3f %s %sprologues(%d)"
,
MP_color
?
"color"
:
"monochrome"
,
MP_solid
?
"solid"
:
"dashed"
,
(
MP_tex
==
MP_NO_TEX
) ?
"no"
: (
MP_tex
==
MP_LATEX
) ?
"la"
:
""
,
MP_a4paper
?
" a4paper"
:
""
,
MP_amstex
?
" amstex"
:
""
,
MP_textmag
,
(
MP_psnfss
==
MP_PSNFSS_7
) ?
"psnsfss(v7)"
:
"psnsfss"
,
(
MP_prologues
>
-1
) ?
""
:
"no"
,
MP_prologues
);
};
}
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
)));
if
(
MP_prologues
>
-1
) {
fprintf
(
gpoutfile
,
"prologues:=%d;\n"
,
MP_prologues
);
}
if
(
MP_tex
==
MP_LATEX
) {
fputs
(
"\n\
%% Add \\documentclass and \\begin{dcoument} for latex\n\
%% NB you should set the environment variable TEX to the name of your\n\
%% latex executable (normally latex) inorder for metapost to work\n\
%% or run\n\
%% mpost --tex=latex ...\n\
\n\
% BEGPRE\n\
verbatimtex\n"
,
gpoutfile
);
if
(
MP_a4paper
) {
fputs
(
"\\documentclass[a4paper]{article}\n"
,
gpoutfile
);
}
else
{
fputs
(
"\\documentclass{article}\n"
,
gpoutfile
);
}
switch
(
MP_psnfss
) {
case
MP_PSNFSS_7
:{
fputs
(
"\\usepackage[latin1]{inputenc}\n\
\\usepackage[T1]{fontenc}\n\
\\usepackage{times,mathptmx}\n\
\\usepackage{helvet}\n\
\\usepackage{courier}\n"
,
gpoutfile
);
}
break
;
case
MP_PSNFSS_8
:{
fputs
(
"\\usepackage[latin1]{inputenc}\n\
\\usepackage[T1]{fontenc}\n\
\\usepackage{textcomp}\n\
\\usepackage{mathptmx}\n\
\\usepackage[scaled=.92]{helvet}\n\
\\usepackage{courier}\n\
\\usepackage{latexsym}\n"
,
gpoutfile
);
}
break
;
}
if
(
MP_amstex
) {
fputs
(
"\\usepackage[intlimits]{amsmath}\n\
\\usepackage{amsfonts}\n"
,
gpoutfile
);
};
fputs
(
"\\begin{document}\n\
etex\n% ENDPRE\n"
,
gpoutfile
);
}
fputs
(
"\n\
warningcheck:=0;\n\
defaultmpt:=mpt:=4;\n\
th:=.6;\n\
%% Have nice sharp joins on our lines\n\
linecap:=butt;\n\
linejoin:=mitered;\n\
\n\
def scalepen expr n = pickup pencircle scaled (n*th) enddef;\n\
def ptsize expr n = mpt:=n*defaultmpt enddef;\n\
\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_tex
==
MP_NO_TEX
) {
fprintf
(
gpoutfile
,
"\n\
defaultfont:= \"%s\";\n\
defaultscale := %6.3f/fontsize defaultfont;\n"
,
MP_fontname
,
MP_fontsize
);
}
else
{
if
(
MP_tex
!=
MP_LATEX
) {
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\
picture currentdash; currentdash:=dashpattern(on 1);\n\
color fillcolor;\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 dashed currentdash 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\
currentdash:= if dashedlines : lt[n] else: dashpattern(on 1) fi;\n\
if n = -1 :\n\
drawoptions(withcolor currentcolor withpen (currentpen scaled .5));\n\
else :\n\
drawoptions(_wc);\n\
fi\n\
enddef;\n\
\n\
% dash patterns\n\
picture lt[];\n\
lt[-2]:=lt[-1]:=lt0:=dashpattern(on 1);\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 r;\n\
addto currentpicture also 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:=%.3fin;h:=%.3fin;\n"
,
MP_char_code
,
MP_xsize
,
MP_ysize
);
/* MetaPost can only handle numbers up to 4096. When MP_DPI
* is larger than 819, this is exceeded by (term->xmax). So we
* scale it and all coordinates down by factor of 10.0. And
* compensate by scaling a and b up.
*/
fprintf
(
gpoutfile
,
"a:=w/%.1f;b:=h/%.1f;\n"
,
(
term
->
xmax
) /
10.0
, (
term
->
ymax
) /
10.0
);
fprintf
(
gpoutfile
,
"scalepen 1; ptsize %.3f;linetype -2;\n"
,
pointsize
);
MP_char_code
++
;
/* reset MP_color_changed */
MP_color_changed
=
0
;
MP_dash_changed
=
0
;
}
TERM_PUBLIC
void
MP_text
()
{
if
(
MP_inline
)
MP_endline
();
fputs
(
"endfig;\n"
,
gpoutfile
);
}
TERM_PUBLIC
void
MP_linetype
(
int
lt
)
{
int
linetype
=
lt
;
if
(
linetype
>=
MP_LINE_TYPES
)
linetype
%=
MP_LINE_TYPES
;
if
(
MP_inline
)
MP_endline
();
/* reset the color in case it has been changed in MP_set_color() */
if
((
MP_color_changed
)
||
(
MP_dash_changed
)) {
MP_oldline
=
linetype
+
1
;
MP_color_changed
=
0
;
MP_dash_changed
=
0
;
}
if
(
MP_oldline
!=
linetype
) {
fprintf
(
gpoutfile
,
"linetype %d;\n"
,
linetype
);
MP_oldline
=
linetype
;
}
}
TERM_PUBLIC
void
MP_move
(
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
(
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
;
/* Change %d to %f, divide x,y by 10 */
fprintf
(
gpoutfile
,
"gpdraw(%d,%.1fa,%.1fb);\n"
,
pointtype
,
x
/
10.0
,
y
/
10.0
);
}
TERM_PUBLIC
void
MP_pointsize
(
double
ps
)
{
if
(
ps
<
0
)
ps
=
1
;
if
(
MP_oldptsize
!=
ps
) {
if
(
MP_inline
)
MP_endline
();
fprintf
(
gpoutfile
,
"ptsize %.3f;\n"
,
ps
);
MP_oldptsize
=
ps
;
}
}
TERM_PUBLIC
void
MP_linewidth
(
double
lw
)
{
if
(
MP_oldpen
!=
lw
) {
if
(
MP_inline
)
MP_endline
();
fprintf
(
gpoutfile
,
"scalepen %.3f;\n"
,
lw
);
MP_oldpen
=
lw
;
}
}
TERM_PUBLIC
void
MP_vector
(
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 (%.1fa,%.1fb)"
,
MP_posx
/
10.0
,
MP_posy
/
10.0
);
MP_linecount
=
2
;
}
MP_posx
=
ux
;
MP_posy
=
uy
;
fprintf
(
gpoutfile
,
"--(%.1fa,%.1fb)"
,
MP_posx
/
10.0
,
MP_posy
/
10.0
);
}
static
void
MP_endline
()
{
MP_inline
=
FALSE;
fprintf
(
gpoutfile
,
";\n"
);
}
TERM_PUBLIC
void
MP_arrow
(
unsigned
int
sx
,
unsigned
int
sy
,
unsigned
int
ex
,
unsigned
int
ey
,
int
head
)
{
MP_move
(
sx
,
sy
);
if
(
head
) {
fprintf
(
gpoutfile
,
"%s (%.1fa,%.1fb)--(%.1fa,%.1fb);\n"
,
head
==
1
?
"drawarrow"
:
"drawdblarrow"
,
sx
/
10.0
,
sy
/
10.0
,
ex
/
10.0
,
ey
/
10.0
);
}
else
if
((
sx
!=
ex
)
||
(
sy
!=
ey
)) {
fprintf
(
gpoutfile
,
"draw (%.1fa,%.1fb)--(%.1fa,%.1fb);\n"
,
sx
/
10.0
,
sy
/
10.0
,
ex
/
10.0
,
ey
/
10.0
);
}
/* 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
(
unsigned
int
x
,
unsigned
int
y
,
const
char
str
[])
{
int
i
,
j
=
0
;
char
*
text
;
/* ignore empty strings */
if
(!
str
||
!
*
str
)
return
;
text
=
gp_strdup
(
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_tex
==
MP_NO_TEX
) {
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), %.1fa, %.1fb, %d, %d);\n"
,
text
,
MP_fontname
,
MP_fontsize
,
x
/
10.0
,
y
/
10.0
,
MP_ang
,
j
);
}
else
{
fprintf
(
gpoutfile
,
"put_text(\"%s\", %.1fa, %.1fb, %d, %d);\n"
,
text
,
x
/
10.0
,
y
/
10.0
,
MP_ang
,
j
);
}
}
else
if
(
MP_fontchanged
) {
if
(
MP_tex
!=
MP_LATEX
) {
fprintf
(
gpoutfile
,
"\
put_text( btex \\setfont{%s}{%5.2f} %s etex, %.1fa, %.1fb, %d, %d);\n"
,
MP_fontname
,
MP_fontsize
,
text
,
x
/
10.0
,
y
/
10.0
,
MP_ang
,
j
);
}
else
{
fprintf
(
gpoutfile
,
"put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n"
,
text
,
x
/
10.0
,
y
/
10.0
,
MP_ang
,
j
);
}
}
else
{
fprintf
(
gpoutfile
,
"put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n"
,
text
,
x
/
10.0
,
y
/
10.0
,
MP_ang
,
j
);
}
free
(
text
);
}
TERM_PUBLIC
int
MP_justify_text
(
enum
JUSTIFY
mode
)
{
MP_justify
=
mode
;
return
(TRUE);
}
TERM_PUBLIC
int
MP_text_angle
(
int
ang
)
{
/* Metapost code does the conversion */
MP_ang
=
ang
;
return
(TRUE);
}
TERM_PUBLIC
int
MP_set_font
(
const
char
*
font
)
{
if
(
*
font
) {
size_t
sep
=
strcspn
(
font
,
","
);
if
(
sep
<
sizeof
(
MP_fontname
))
strncpy
(
MP_fontname
,
font
,
sizeof
(
MP_fontname
));
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
()
{
if
(
MP_tex
==
MP_LATEX
) {
fputs
(
"% BEGPOST\n"
,
gpoutfile
);
fputs
(
"verbatimtex\n"
,
gpoutfile
);
fputs
(
" \\end{document}\n"
,
gpoutfile
);
fputs
(
"etex\n"
,
gpoutfile
);
fputs
(
"% ENDPOST\n"
,
gpoutfile
);
};
fputs
(
"end.\n"
,
gpoutfile
);
}
TERM_PUBLIC
void
MP_boxfill
(
int
style
,
unsigned
int
x1
,
unsigned
int
y1
,
unsigned
int
wd
,
unsigned
int
ht
)
{
/* fillpar:
* - solid : 0 - 100% intensity
* - pattern : 0 - n pattern number
*/
int
fillpar
=
style
>>
4
;
style
&=
0xf
;
if
(
MP_inline
)
MP_endline
();
switch
(
style
) {
case
FS_EMPTY
:
/* fill with background color */
fprintf
(
gpoutfile
,
"\
fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withcolor background;\n"
,
x1
/
10.0
,
y1
/
10.0
, (
x1
+
wd
) /
10.0
,
y1
/
10.0
,
(
x1
+
wd
) /
10.0
, (
y1
+
ht
) /
10.0
,
x1
/
10.0
,
(
y1
+
ht
) /
10.0
);
break
;
case
FS_PATTERN
:
/* pattern fill */
case
FS_TRANSPARENT_PATTERN
:
/* FIXME: not yet implemented, dummy it up as fill density */
fillpar
*=
12
;
default
:
case
FS_SOLID
:
/* solid fill */
case
FS_TRANSPARENT_SOLID
:
if
(
fillpar
<
100
) {
double
density
=
(
100
-
fillpar
)
*
0.01
;
fprintf
(
gpoutfile
,
"fillcolor:=currentcolor*%.2f+background*%.2f;\n"
,
1.0
-
density
,
density
);
MP_color_changed
=
1
;
}
else
fprintf
(
gpoutfile
,
"fillcolor:=currentcolor;\n"
);
fprintf
(
gpoutfile
,
"\
fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withpen (pencircle scaled 0pt) withcolor fillcolor;\n"
,
x1
/
10.0
,
y1
/
10.0
, (
x1
+
wd
) /
10.0
,
y1
/
10.0
,
(
x1
+
wd
) /
10.0
, (
y1
+
ht
) /
10.0
,
x1
/
10.0
,
(
y1
+
ht
) /
10.0
);
break
;
}
}
TERM_PUBLIC
int
MP_make_palette
(
t_sm_palette
*
palette
)
{
/* metapost can do continuous number of colours */
return
0
;
}
TERM_PUBLIC
void
MP_set_color
(
t_colorspec
*
colorspec
)
{
double
gray
=
colorspec
->
value
;
rgb_color
color
;
/* remeber that we changed the color, needed to reset color in MP_linetype()*/
MP_color_changed
=
1
;
if
(
MP_inline
)
MP_endline
();
if
(!
MP_color
) {
/* gray mode */
if
(
gray
<
1e-3
)
gray
=
0
;
fprintf
(
gpoutfile
,
"currentcolor:=%.3gwhite;\n"
,
gray
);
}
else
{
/* color mode */
if
(
colorspec
->
type
==
TC_LT
) {
int
linecolor
=
colorspec
->
lt
;
if
(
linecolor
>=
MP_LINE_TYPES
)
linecolor
%=
MP_LINE_TYPES
;
if
(
linecolor
==
-1
)
fprintf
(
gpoutfile
,
"currentcolor:=black;\n"
);
else
if
(
linecolor
>=
0
)
fprintf
(
gpoutfile
,
"currentcolor:=col%d;\n"
,
linecolor
);
}
if
(
colorspec
->
type
==
TC_FRAC
) {
if
(
sm_palette
.
colors
!=
0
)
/* finite nb of colors explicitly requested */
gray
=
(
gray
>= ((
double
)(
sm_palette
.
colors
-
1
)) /
sm_palette
.
colors
) ?
1
:
floor
(
gray
*
sm_palette
.
colors
) /
sm_palette
.
colors
;
rgb1_from_gray
(
gray
,
&
color
);
}
else
if
(
colorspec
->
type
==
TC_RGB
) {
color
.
r
=
(
double
)((
colorspec
->
lt
>>
16
)
&
255
) /
255.
;
color
.
g
=
(
double
)((
colorspec
->
lt
>>
8
)
&
255
) /
255.
;
color
.
b
=
(
double
)(
colorspec
->
lt
&
255
) /
255.
;
}
else
return
;
if
(
color
.
r
<
1e-4
)
color
.
r
=
0
;
if
(
color
.
g
<
1e-4
)
color
.
g
=
0
;
if
(
color
.
b
<
1e-4
)
color
.
b
=
0
;
fprintf
(
gpoutfile
,
"currentcolor:=%.4g*red+%.4g*green+%.4g*blue;\n"
,
color
.
r
,
color
.
g
,
color
.
b
);
}
return
;
}
TERM_PUBLIC
void
MP_filled_polygon
(
int
points
,
gpiPoint
*
corners
)
{
int
i
;
int
fillpar
=
corners
->
style
>>
4
;
int
style
=
corners
->
style
&
0xf
;
if
(
MP_inline
)
MP_endline
();
switch
(
style
) {
case
FS_EMPTY
:
/* fill with background color */
fprintf
(
gpoutfile
,
"fillcolor:=background;\n"
);
break
;
case
FS_PATTERN
:
/* pattern fill implemented as partial density */
case
FS_TRANSPARENT_PATTERN
:
fillpar
*=
12
;
case
FS_SOLID
:
/* solid fill */
case
FS_TRANSPARENT_SOLID
:
if
(
fillpar
<
100
) {
double
density
=
(
100
-
fillpar
)
*
0.01
;
fprintf
(
gpoutfile
,
"fillcolor:=currentcolor*%.2f+background*%.2f;\n"
,
1.0
-
density
,
density
);
}
else
{
fprintf
(
gpoutfile
,
"fillcolor:=currentcolor;\n"
);
}
default
:
break
;
}
fprintf
(
gpoutfile
,
"fill "
);
for
(
i
=
0
;
i
<
points
;
i
++
)
fprintf
(
gpoutfile
,
"(%.1fa,%.1fb)%s"
,
corners
[
i
].
x
/
10.0
,
corners
[
i
].
y
/
10.0
,
(
i
<
points
-
1
&&
(
i
+
1
) %
MP_LINEMAX
==
0
) ?
"\n--"
:
"--"
);
fprintf
(
gpoutfile
,
"cycle withcolor fillcolor;\n"
);
}
TERM_PUBLIC
void
MP_dashtype
(
int
type
,
t_dashtype
*
custom_dash_type
)
{
switch
(
type
) {
case
DASHTYPE_SOLID
:
fprintf
(
gpoutfile
,
"%%MP_dashtype%% DASHTYPE_SOLID\n"
);
break
;
case
DASHTYPE_AXIS
:
fprintf
(
gpoutfile
,
"%%MP_dashtype%% DASHTYPE_AXIS\n"
);
/* Currently handled elsewhere? */
break
;
case
DASHTYPE_CUSTOM
:
fprintf
(
gpoutfile
,
"%%MP_dashtype%% DASHTYPE_CUSTOM: "
);
if
(
custom_dash_type
) {
int
i
;
if
(
custom_dash_type
->
dstring
[
0
]
!=
'\0'
)
fprintf
(
gpoutfile
,
"\"%s\"; "
,
custom_dash_type
->
dstring
);
fprintf
(
gpoutfile
,
"["
);
for
(
i
=
0
;
i
<
DASHPATTERN_LENGTH
&&
custom_dash_type
->
pattern
[
i
]
>
0
;
i
++
)
fprintf
(
gpoutfile
,
i
?
", %.2f"
:
"%.2f"
,
custom_dash_type
->
pattern
[
i
]);
fprintf
(
gpoutfile
,
"]"
);
fprintf
(
gpoutfile
,
"\n"
);
MP_dash_changed
=
1
;
fprintf
(
gpoutfile
,
"currentdash:=dashpattern("
);
for
(
i
=
0
;
i
<
DASHPATTERN_LENGTH
&&
custom_dash_type
->
pattern
[
i
]
>
0
;
i
++
)
fprintf
(
gpoutfile
,
"%s %.2f "
,
i
%
2
?
"off"
:
"on"
,
custom_dash_type
->
pattern
[
i
]);
fprintf
(
gpoutfile
,
");\n"
);
}
else
{
fprintf
(
gpoutfile
,
"\n"
);
}
break
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL