File: epslatex.trm

package info (click to toggle)
gnuplot 3.7.2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,212 kB
  • ctags: 4,635
  • sloc: ansic: 43,538; cpp: 970; makefile: 883; lisp: 661; sh: 578; asm: 539; objc: 379; csh: 297; pascal: 192; perl: 138
file content (1003 lines) | stat: -rw-r--r-- 26,878 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
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
1001
1002
1003
/*
 * $Id: epslatex.trm,v 1.1.2.4 2002/01/26 19:05:34 lhecking Exp $
 */

/* GNUPLOT - epslatex.trm */

/*[
 * Copyright 2000
 *
 * 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 terminal driver supports:
 *     epslatex
 */

/* Written by Gregor Thalhammer
 * you'll find a lot of similarities with the pslatex, postscript and pstricks terminal drivers
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(epslatex)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void EPSL_options __PROTO((void));
TERM_PUBLIC void EPSL_init __PROTO((void));
TERM_PUBLIC void EPSL_graphics __PROTO((void));
TERM_PUBLIC void EPSL_text __PROTO((void));
TERM_PUBLIC void EPSL_reset __PROTO((void));
TERM_PUBLIC void EPSL_linetype __PROTO((int linetype));
TERM_PUBLIC void EPSL_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void EPSL_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void EPSL_arrow __PROTO((unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, TBOOLEAN head));
TERM_PUBLIC void EPSL_put_text __PROTO((unsigned int x, unsigned int y, char *str));
TERM_PUBLIC int EPSL_text_angle __PROTO((int ang));
TERM_PUBLIC int EPSL_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC void EPSL_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC int EPSL_set_font __PROTO((char *font));
TERM_PUBLIC void EPSL_fillbox __PROTO((int style, unsigned int x1, unsigned int y1, unsigned int width, unsigned int height));
TERM_PUBLIC void EPSL_linewidth __PROTO((double linewidth));
TERM_PUBLIC void EPSL_pointsize __PROTO((double ptsize));

#ifdef PM3D
/* Not needed --- PS terminal version reused:
TERM_PUBLIC int EPSL_make_palette __PROTO((t_sm_palette *));
TERM_PUBLIC void EPSL_previous_palette __PROTO((void));
TERM_PUBLIC void EPSL_set_color __PROTO((double));
*/
TERM_PUBLIC void EPSL_filled_polygon __PROTO((int, gpiPoint *));
#endif

#define EPSL_SC (50)		/* scale is 1pt = 10 units */
/* changed to 50, but gs now renders terribly slowly to display (x11alpha) !! */
#define EPSL_POINT_TYPES 8	/* never used! */
#define EPSL_XOFF	72	/* page offset in pts */
#define EPSL_YOFF	72
#define EPSL_XMAX       (5*72*EPSL_SC)	/* default plot size 5*3 inch */
#define EPSL_YMAX       (3*72*EPSL_SC)
#define EPSL_XLAST      (EPSL_XMAX - 1)
#define EPSL_YLAST      (EPSL_YMAX - 1)
#define EPSL_VTIC       (6.0*EPSL_SC)
#define EPSL_HTIC       (6.0*EPSL_SC)
#define EPSL_POINTSIZE  (2.0*EPSL_SC)
#define	EPSL_LW         (0.4*EPSL_SC)	/* linewidth = 0.4 pts */
#define EPSL_VCHAR      (11*EPSL_SC)	/* default is 11 point characters */
#define EPSL_HCHAR      (11*EPSL_SC*5/10)

#endif /* TERM_PROTO */

#ifndef TERM_PROTO_ONLY

#ifdef TERM_BODY

#define EPSL_FLUSH_PATH \
    if (EPSL_path_count) {fputs("Gpstroke\n",gpoutfile); EPSL_path_count = 0; EPSL_relative_ok = FALSE;}

/* From version.c */
extern char gnuplot_version[];
extern char gnuplot_patchlevel[];

static char EPSL_font[MAX_ID_LEN + 1] = "default";	/* name of font */
static int EPSL_fontsize = 11;	/* size of font in pts */

static TBOOLEAN EPSL_color = FALSE;	/* don't use colors */
static TBOOLEAN EPSL_solid = FALSE;	/*  use solid lines */

static int EPSL_path_count = 0;	/* count of lines in path */
static int EPSL_ang = 0;	/* text angle */

static enum JUSTIFY EPSL_justify = LEFT;	/* text is flush left */
/* static int x = 0; */

/* for testing */
/* 
char GPFAR * GPFAR EPSL_header[] = {"(prolog.ps) run\n", NULL}; 
 */

char GPFAR *GPFAR EPSL_header[] = {
" /hpt hpt_ def  \n",
" /vpt vpt_ def  \n",
" /Gppointsize_ 1 def \n",
" /Gplinewidth_ 1 def \n",
"  \n",
" /ArrowDict 25 dict def  \n",
"  \n",
" /M /moveto load def  \n",
" /L /lineto load def  \n",
" /R /rmoveto load def  \n",
" /V /rlineto load def  \n",
" /ED { exch def} bind def  \n",
"  \n",
" /Atan {/atan load stopped {pop pop 0} if } def  \n",
" /Div {dup 0 eq { pop } { div } ifelse } def  \n",
" /Pyth {dup mul exch dup mul add sqrt} def  \n",
"  \n",
" %Sizes  \n",
" /Gpsetlinewidth  \n",
" { \n",
"   dup \n",
" %  /Gplinewidth_ ED %save \n",
"   Gplinewidth mul setlinewidth \n",
" } def  \n",
"  \n",
" /Gpsetpointsize   \n",
" {  \n",
"   dup  \n",
"   /Gppointsize_ ED %save \n",
"   dup  \n",
"   vpt_ mul /vpt ED \n",
"   hpt_ mul /hpt ED  \n",
" } def  \n",
"      \n",
" %Color  \n",
" /SetHsbColor { Color {sethsbcolor} {pop pop pop} ifelse } def  \n",
" /SetCmykColor { Color {setcmykcolor} {pop pop pop pop} ifelse } def  \n",
" /SimpleSetColor {6 div 1 1 SetHsbColor} def  \n",
" /Black {0 0 0 0 SetCmykColor} def  \n",
" /Red {0 SimpleSetColor} def  \n",
" /Blue {1 1 0 0 SetCmykColor} def  \n",
" /Cyan {1 0 0 0 SetCmykColor} def  \n",
" /Magenta {0 1 0 0 SetCmykColor} def \n",
"  \n",
" %Stroking  \n",
" /PathLength@ % z = z + sqrt{(x-xlast)^2 + (y-ylast)^2}  \n",
"  {  \n",
"    /z   \n",
"    z  \n",
"    y ylast sub  \n",
"    x xlast sub  \n",
"    Pyth  \n",
"    add  \n",
"    def   \n",
"    /ylast y def  \n",
"    /xlast x def  \n",
"  } def  \n",
"      \n",
"  /PathLength  \n",
"  {  \n",
"    flattenpath  \n",
"    /z 0 def  \n",
"    { %move  \n",
"      /ystart ED  \n",
"      /xstart ED  \n",
"      /xlast xstart def  \n",
"      /ylast ystart def  \n",
"    }  \n",
"    { %line  \n",
"      /y ED  \n",
"      /x ED  \n",
"      PathLength@  \n",
"    }  \n",
"    { %curve  \n",
"    }  \n",
"    { %close  \n",
"      /x xstart def  \n",
"      /y ystart def  \n",
"      PathLength@   \n",
"    }  \n",
"    /pathforall load  \n",
"    stopped {pop pop pop pop} if  \n",
"    z  \n",
"  } def  \n",
"    \n",
" %dotsep DotLine  \n",
" /DotLine   \n",
" {  \n",
"   PathLength /b ED   \n",
"   /z ED   \n",
"   /y currentlinewidth def   \n",
"   /z y z add def   \n",
"   [ 0 b b z Div round Div dup 0 le { pop 1 } if] 0 setdash   \n",
"   1 setlinecap  \n",
" } def  \n",
"  \n",
" /DashLine   \n",
"  {  \n",
"    PathLength /b ED   \n",
"    /x ED   \n",
"    /y ED   \n",
"    /z y x add def   \n",
"    b y sub z Div round z mul y add b exch Div \n",
"    dup  \n",
"    y mul /y ED   \n",
"    x mul /x ED   \n",
"    x 0 gt y 0 gt and   \n",
"    { [ y x ] 0 }  \n",
"    { [ 1 0 ] 0 }  \n",
"    ifelse  \n",
"    setdash  \n",
"  } def  \n",
"  \n",
" /DashLineTwo \n",
"  {  \n",
"    PathLength /b ED   \n",
"    /u ED \n",
"    /v ED \n",
"    /x ED   \n",
"    /y ED \n",
"    /z y x add u add v add def   \n",
"    b y sub z Div round z mul y add b exch Div \n",
"    dup  \n",
"    y mul /y ED   \n",
"    x mul /x ED   \n",
"    x 0 gt y 0 gt and   \n",
"    { [ y x v u] 0 }  \n",
"    { [ 1 0 ] 0 }  \n",
"    ifelse  \n",
"    setdash  \n",
"  } def  \n",
"      \n",
"  \n",
" /DotLineStroke   \n",
" {  \n",
"   gsave  \n",
"     Dashed {currentlinewidth 2 mul DotLine} if  \n",
"     stroke  \n",
"   grestore  \n",
" } def  \n",
"    \n",
" /SolidLineStroke  \n",
" {  \n",
"   gsave  \n",
"     [] 0 setdash  \n",
"     stroke  \n",
"   grestore  \n",
" } def  \n",
"    \n",
" /DashLineStroke  \n",
" {  \n",
"   gsave   \n",
"     Dashed {Gplinewidth 8 mul Gplinewidth 5 mul DashLine} if  \n",
"     stroke  \n",
"   grestore  \n",
" } def  \n",
"   \n",
" /DashDotLineStroke  \n",
" {  \n",
"   gsave   \n",
"     Dashed {Gplinewidth 8 mul Gplinewidth 5 mul 0 Gplinewidth 5 mul DashLineTwo} if  \n",
"     stroke  \n",
"   grestore  \n",
" } def  \n",
"    \n",
" /DashShortLineStroke  \n",
" {  \n",
"   gsave   \n",
"     Dashed {Gplinewidth 4 mul dup DashLine} if  \n",
"     stroke  \n",
"   grestore  \n",
" } def  \n",
"    \n",
" /ArrowHead  \n",
" {   \n",
"   currentlinewidth mul add dup 2 div /w ED  \n",
"   mul dup /h ED  \n",
"   mul /a ED   \n",
"   w neg h moveto   \n",
"   0 0 L   \n",
"   w h L   \n",
"   w neg a neg rlineto   \n",
"   gsave fill grestore   \n",
" } def  \n",
"    \n",
"  %/DrawArrowHead {1 dup scale 0.2 1.4 50 3 ArrowHead} def  \n",
"  %%%%%  \n",
"  %inset length dim num  \n",
"  %arrowwidth = dim + num*linewidth  \n",
"  %arrowlength = length*arrowwidth  \n",
"  %arrowinset = width * inset  \n",
"    \n",
"  /DrawArrowHead {0.2 1.4 Gplinewidth 3 mul 4 ArrowHead} def  \n",
"    \n",
"  /Arrow  \n",
"  {  \n",
"    currentpoint  \n",
"    4 2 roll  \n",
"    ArrowDict  \n",
"    begin  \n",
"      /@mtrx matrix currentmatrix def  \n",
"      gsave  \n",
"        2 copy translate  \n",
"        2 index sub neg exch  \n",
"        3 index sub exch Atan  \n",
"        rotate  \n",
"        newpath  \n",
"        DrawArrowHead  \n",
"        @mtrx setmatrix  \n",
"        currentpoint  \n",
"      grestore  \n",
"    end %ArrowDicht  \n",
"    lineto  \n",
"    Gpstroke  \n",
"  } def  \n",
"    \n",
"  %axis  \n",
"  /LTa   \n",
"  {  \n",
"    Gpstroke      \n",
"    newpath  \n",
"    0 setgray  \n",
"    /Gpstroke {DotLineStroke newpath} def  \n",
"  } def  \n",
"    \n",
"  %border  \n",
"  /LTb  \n",
"  {  \n",
"    Gpstroke      \n",
"    newpath  \n",
"    0 setgray  \n",
"    /Gpstroke {SolidLineStroke newpath} def  \n",
"  } def  \n",
"    \n",
"  /LT0  \n",
"  {  \n",
"    Gpstroke      \n",
"    newpath  \n",
"    Red  \n",
"    /Gpstroke {SolidLineStroke newpath} def  \n",
"  } def  \n",
"    \n",
"  /LT1  \n",
"  {  \n",
"    Gpstroke      \n",
"    newpath  \n",
"    Blue  \n",
"    /Gpstroke {DashLineStroke newpath} def  \n",
"  } def  \n",
"    \n",
"  /LT2   \n",
"  {  \n",
"    Gpstroke  \n",
"    newpath  \n",
"    Cyan  \n",
"    /Gpstroke {DashShortLineStroke newpath} def  \n",
"  } def  \n",
"  \n",
"  /LT3   \n",
"  {  \n",
"    Gpstroke  \n",
"    newpath  \n",
"    Magenta  \n",
"    /Gpstroke {DashDotLineStroke newpath} def  \n",
"  } def  \n",
"    \n",
"  /Pnt  \n",
"  {  \n",
"    gsave   \n",
"      [] 0 setdash  \n",
"      1 setlinecap   \n",
"      Gplinewidth Gppointsize_ mul setlinewidth \n",
"      M  \n",
"      0 0 V  \n",
"      stroke  \n",
"    grestore  \n",
"  } def  \n",
"    \n",
"  /DiaPath  \n",
"  {  \n",
"      [] 0 setdash  \n",
"      Gplinewidth setlinewidth  \n",
"      2 copy   \n",
"      newpath  \n",
"      vpt add moveto  \n",
"      hpt neg vpt neg rlineto   \n",
"      hpt vpt neg rlineto  \n",
"      hpt vpt rlineto   \n",
"      hpt neg vpt rlineto  \n",
"      closepath  \n",
"  } def  \n",
"    \n",
"  /Dia   \n",
"  {   \n",
"    gsave  \n",
"      DiaPath  \n",
"      stroke  \n",
"    grestore  \n",
"  } def  \n",
"    \n",
"  /DaF  \n",
"  {  \n",
"    gsave  \n",
"      DiaPath  \n",
"      fill  \n",
"    grestore  \n",
"  } def  \n",
"    \n",
"  /Crc  \n",
"  {  \n",
"    gsave  \n",
"      [] 0 setdash  \n",
"      Gplinewidth setlinewidth  \n",
"      newpath  \n",
"      vpt 0.85 mul 0 360 arc  \n",
"      closepath  \n",
"      stroke  \n",
"    grestore  \n",
"  } def  \n",
"        \n",
"    \n",
"  /Crs  \n",
"  {  \n",
"    gsave  \n",
"      [] 0 setdash  \n",
"      Gplinewidth setlinewidth  \n",
"      0 setlinecap  \n",
"      newpath  \n",
"      vpt sub  \n",
"      moveto  \n",
"      0 vpt 2 mul rlineto  \n",
"      hpt vpt neg rmoveto  \n",
"      hpt 2 mul neg 0 rlineto  \n",
"      stroke  \n",
"    grestore  \n",
"  } def  \n",
"    \n",
"  /CrX  \n",
"  {  \n",
"  gsave  \n",
"   translate  \n",
"   45 rotate  \n",
"   0 0 Crs  \n",
"  grestore  \n",
"  } def  \n",
"    \n",
"  /CcF  \n",
"  {  \n",
"    gsave  \n",
"      [] 0 setdash  \n",
"      Gplinewidth setlinewidth  \n",
"      newpath  \n",
"      vpt 0.85 mul 0 360 arc  \n",
"      closepath  \n",
"      fill  \n",
"    grestore  \n",
"  } def  \n",
"    \n",
"  /Box  \n",
"  {  \n",
"     gsave  \n",
"       translate  \n",
"       45 rotate  \n",
"       0 0 DiaPath  \n",
"       stroke  \n",
"     grestore  \n",
"  } def  \n",
"    \n",
"  /BxF  \n",
"  {  \n",
"     gsave  \n",
"       translate  \n",
"       45 rotate  \n",
"       0 0 DiaPath  \n",
"       fill  \n",
"     grestore  \n",
"  } def  \n",
"    \n",
"  /Gpstroke {stroke} def  \n",
"  1 setlinecap  \n",
"  1 setlinejoin \n",
    NULL
};

static int EPSL_pen_x, EPSL_pen_y;
static int EPSL_taken;
static int EPSL_linetype_last;
static TBOOLEAN EPSL_relative_ok;
static char *EPSL_texfilename = NULL;
static FILE *EPSL_texfile;

TERM_PUBLIC void
EPSL_options()
{
    if (!END_OF_COMMAND) {	/* set all options to their default values */
	if (almost_equals(c_token, "d$efault")) {
	    EPSL_color = FALSE;
	    EPSL_solid = FALSE;
	    strcpy(EPSL_font, "default");
	    EPSL_fontsize = 11;
	    term->v_char = (unsigned int) (EPSL_fontsize * EPSL_SC);
	    term->h_char = (unsigned int) (EPSL_fontsize * EPSL_SC * 5 / 10);
	    c_token++;
	}
    }

    if (!END_OF_COMMAND) {
	if (almost_equals(c_token, "m$onochrome")) {
	    EPSL_color = FALSE;
	    c_token++;
	} else if (almost_equals(c_token, "c$olor")
		   || almost_equals(c_token, "c$olour")) {
	    EPSL_color = TRUE;
	    c_token++;
	}
    }

    if (!END_OF_COMMAND) {
	if (almost_equals(c_token, "so$lid")) {
	    EPSL_solid = TRUE;
	    c_token++;
	} else if (almost_equals(c_token, "da$shed")) {
	    EPSL_solid = FALSE;
	    c_token++;
	}
    }

    if (!END_OF_COMMAND && isstring(c_token)) {
	quote_str(EPSL_font, c_token, MAX_ID_LEN);
	c_token++;
    }

    if (!END_OF_COMMAND) {
	/* We have font size specified */
	struct value a;
	EPSL_fontsize = (int) real(const_express(&a));
	term->v_char = (unsigned int) (EPSL_fontsize * EPSL_SC);
	term->h_char = (unsigned int) (EPSL_fontsize * EPSL_SC * 5 / 10);
    }

    sprintf(default_font, "%s,%d", EPSL_font, EPSL_fontsize);	/* 'default_font' declared in set.c */

    sprintf(term_options, "%s %s \"%s\" %d",
	    EPSL_color ? "color" : "monochrome",
	    EPSL_solid ? "solid" : "dashed",
	    EPSL_font, EPSL_fontsize);
}


/* the init fn for the epslatex driver */
TERM_PUBLIC void
EPSL_init()
{
    char *dotIndex=NULL;
    char *name;

    /* Why is EPSL_header global, and psi1, psi2 not? */

    static char GPFAR psi1[] = "%%%%Creator: gnuplot %s patchlevel %s\n\
%%%%CreationDate: %s";
    static char GPFAR psi2[] = "%%%%EndComments\n\
/Gpdict 100 dict def\n\
Gpdict begin\n\
/Color %s def\n\
/Dashed %s def\n\
/Gplinewidth %.3f def\n\
/hpt_ %.3f def\n\
/vpt_ %.3f def\n";

    time_t now;

    unsigned int xmin_t, ymin_t, xmax_t, ymax_t;
    int i;
    term->xmax = EPSL_XMAX;
    term->ymax = EPSL_YMAX;
    xmin_t = EPSL_XMAX * xoffset / (EPSL_SC);
    xmax_t = EPSL_XMAX * (xsize + xoffset) / (EPSL_SC);
    ymin_t = EPSL_YMAX * yoffset / (EPSL_SC);
    ymax_t = EPSL_YMAX * (yoffset + ysize) / (EPSL_SC);

    fputs("%%!PS-Adobe-3.0 EPSF-3.0\n", gpoutfile);
    if (outstr)
	fprintf(gpoutfile, "%%%%Title: (%s)\n", outstr);
    time(&now);
    fprintf(gpoutfile, psi1, gnuplot_version, gnuplot_patchlevel, asctime(localtime(&now)));

    fprintf(gpoutfile, "%%%%BoundingBox: %d %d %d %d\n",
	    EPSL_XOFF + xmin_t, EPSL_XOFF + ymin_t,
	    EPSL_XOFF + xmax_t, EPSL_YOFF + ymax_t);

    fprintf(gpoutfile, psi2,
	    EPSL_color ? "true" : "false",
	    EPSL_solid ? "false" : "true",
	    (double) EPSL_LW, (double) EPSL_POINTSIZE, (double) EPSL_POINTSIZE);

    for (i = 0; EPSL_header[i] != NULL; i++)
	fprintf(gpoutfile, "%s", EPSL_header[i]);

    fputs("end\n%%%%EndProlog\n", gpoutfile);

    EPSL_texfile = NULL;

    if (outstr && (dotIndex = strrchr(outstr, '.'))) {
	/* assume file name is ending in ".eps" */
	if (EPSL_texfilename)
	    free(EPSL_texfilename);
	EPSL_texfilename = gp_alloc(dotIndex - outstr + 5, "epslatex texfilename");
	if (EPSL_texfilename) {
	    /* including . */
	    safe_strncpy(EPSL_texfilename, outstr, dotIndex - outstr + 2);
	    strcpy(EPSL_texfilename + (dotIndex - outstr) + 1, "tex");
	    if ((EPSL_texfile = fopen(EPSL_texfilename, "w")) == (FILE *) NULL) {
		fprintf(stderr, "Cannot open tex file %s for output\n", EPSL_texfilename);
	    }
	} else {
	    fprintf(stderr, "Cannot make LaTeX file name from %s\nTurning off LaTeX output\n", outstr);
	}
    }
    if (EPSL_texfile) {
	name = gp_alloc(dotIndex - outstr + 1, "epslatex temp filename");
	safe_strncpy(name, outstr, dotIndex - outstr + 1);
	name[dotIndex - outstr] = 0;
	fprintf(EPSL_texfile, "%%GNUPLOT: LaTeX picture with Postscript\n\
\\begin{picture}(0,0)%%\n\
\\includegraphics{%s}%%\n\
\\end{picture}%%\n\
\\setlength{\\unitlength}{%.4fbp}%%\n", name, 1.0 / EPSL_SC);
    }
#ifdef PM3D
    /* to optimize output for postscript terminals family */
    postscript_gpoutfile = gpoutfile;
#endif
}


TERM_PUBLIC void
EPSL_graphics()
{
    static char GPFAR psg1[] = "0 setgray\nnewpath\n";
    struct termentry *t = term;

    fprintf(gpoutfile, "\
Gpdict begin\ngsave\n\
%d %d translate\n\
%.4f %.4f scale\n\
%s",
	    EPSL_XOFF, EPSL_YOFF,
	    1.0 / EPSL_SC, 1.0 / EPSL_SC,
	    psg1);
    EPSL_pointsize(pointsize);
    EPSL_linewidth(1.0);
    EPSL_path_count = 0;
    EPSL_relative_ok = FALSE;
    EPSL_pen_x = EPSL_pen_y = -4000;
    EPSL_taken = 0;
    EPSL_linetype_last = -1;

    if (EPSL_texfile)
	fprintf(EPSL_texfile, "\\begin{picture}(%d,%d)(0,0)%%\n",
		(int) (xsize * t->xmax), (int) (ysize * t->ymax));
}


TERM_PUBLIC void
EPSL_text()
{
    EPSL_FLUSH_PATH;
    fputs("grestore\nend\nshowpage\n%%%%EOF\n", gpoutfile);
    if (EPSL_texfile) {
	fputs("\\end{picture}%\n\\endinput\n", EPSL_texfile);
    }
}

TERM_PUBLIC void
EPSL_reset()
{
    if (EPSL_texfile) {
	fclose(EPSL_texfile);
	EPSL_texfile = NULL;
    }
}


TERM_PUBLIC void
EPSL_linetype(linetype)
int linetype;
{
    EPSL_FLUSH_PATH;
    linetype = (linetype % 4) + 2;
    if (linetype < 0)
	linetype = 0;
    EPSL_relative_ok = FALSE;
#if 0
    if (EPSL_linetype_last == linetype)
	return;
#endif
    EPSL_linetype_last = linetype;
    fprintf(gpoutfile, "LT%c\n", "ba0123"[linetype]);
    EPSL_path_count = 0;
}


TERM_PUBLIC void
EPSL_linewidth(linewidth)
double linewidth;
{
    EPSL_FLUSH_PATH;
    fprintf(gpoutfile, "%.3f Gpsetlinewidth\n", linewidth);
}

TERM_PUBLIC void
EPSL_pointsize(ptsize)
double ptsize;
{
    fprintf(gpoutfile, "%.3f Gpsetpointsize\n", ptsize);
}

TERM_PUBLIC void
EPSL_move(x, y)
unsigned int x, y;
{
    int dx, dy;
    /* Make this semi-dynamic and independent of architecture */
    char abso[5 + 2 * INT_STR_LEN], rel[5 + 2 * INT_STR_LEN];

    /*if (EPSL_path_count) {EPSL_FLUSH_PATH}; */
    EPSL_FLUSH_PATH;
    dx = x - EPSL_pen_x;
    dy = y - EPSL_pen_y;
    /* can't cancel all null moves--need a move after stroke'ing */
    if (dx == 0 && dy == 0 && EPSL_relative_ok)
	return;
    sprintf(abso, "%d %d M\n", x, y);
    sprintf(rel, "%d %d R\n", dx, dy);
    if (strlen(rel) < strlen(abso) && EPSL_relative_ok) {
	fputs(rel, gpoutfile);
	EPSL_taken++;
    } else
	fputs(abso, gpoutfile);
    EPSL_relative_ok = TRUE;
    EPSL_path_count += 1;

    EPSL_pen_x = x;
    EPSL_pen_y = y;
}

TERM_PUBLIC void
EPSL_vector(x, y)
unsigned int x, y;
{
    int dx, dy;
    char abso[5 + 2 * INT_STR_LEN], rel[5 + 2 * INT_STR_LEN];

    dx = x - EPSL_pen_x;
    dy = y - EPSL_pen_y;
    if (dx == 0 && dy == 0)
	return;
    sprintf(abso, "%d %d L\n", x, y);
    sprintf(rel, "%d %d V\n", dx, dy);
    if (strlen(rel) < strlen(abso) && EPSL_relative_ok) {
	fputs(rel, gpoutfile);
	EPSL_taken++;
    } else
	fputs(abso, gpoutfile);
    EPSL_relative_ok = TRUE;
    EPSL_path_count += 1;
    EPSL_pen_x = x;
    EPSL_pen_y = y;
    /* if (ps_path_count >= 400) {
       fprintf(gpoutfile,"currentpoint stroke M\n");
       ps_path_count = 0;
       }
     */
}

TERM_PUBLIC void
EPSL_arrow(xstart, ystart, xend, yend, head)
unsigned int xstart, ystart, xend, yend;
TBOOLEAN head;
{
    fprintf(gpoutfile, "%d %d M\n%d %d %s\n", xstart, ystart, xend, yend, head ? "Arrow" : "L Gpstroke");
}

TERM_PUBLIC void
EPSL_put_text(x, y, str)
    unsigned int x, y;
    char *str;
{
    if (EPSL_texfile) {
	fprintf(EPSL_texfile, "\\put(%d,%d){", x, y);
	if (EPSL_ang) {
	    fputs("\\rotatebox{90}{", EPSL_texfile);
	}
	if (((str[0] == '{') || (str[0] == '['))) {
	    fprintf(EPSL_texfile, "\\makebox(0,0)%s", str);
	} else
	    switch (EPSL_justify) {
	    case LEFT:
		fprintf(EPSL_texfile, "\\makebox(0,0)[l]{\\strut{}%s}", str);
		break;
	    case CENTRE:
		fprintf(EPSL_texfile, "\\makebox(0,0){\\strut{}%s}", str);
		break;
	    case RIGHT:
		fprintf(EPSL_texfile, "\\makebox(0,0)[r]{\\strut{}%s}", str);
		break;
	    }
	if (EPSL_ang) {
	    fputs("}", EPSL_texfile);
	}
	fputs("}%\n", EPSL_texfile);
    }
}


TERM_PUBLIC int
EPSL_text_angle(ang)
int ang;
{
    EPSL_ang = ang;
    return TRUE;
}


TERM_PUBLIC int
EPSL_justify_text(mode)
enum JUSTIFY mode;
{
    EPSL_justify = mode;
    return TRUE;
}


TERM_PUBLIC int
EPSL_set_font(font)		/* Entry font added by DJL */
char *font;
{
    char name[32];
    int size, sep;

    sep = strcspn(font, ",");
    strncpy(name, font, sep);
    name[sep] = 0;
    size = EPSL_fontsize;
    sscanf(&(font[sep + 1]), "%d", &size);
    return TRUE;
}

TERM_PUBLIC void
EPSL_point(x, y, number)
unsigned int x, y;
int number;
{
    static char GPFAR *GPFAR pointFNS[] = { "Pnt", "Dia", "Crc", "Crs", "CrX", "Box", "DaF", "CcF", "BxF" };

    EPSL_FLUSH_PATH;
    if (number < 0)
	number = -1;		/* negative types are all 'dot' */
    else
	number %= sizeof(pointFNS) / sizeof(pointFNS[0]) - 1;
    fprintf(gpoutfile, "%d %d %s\n", x, y, pointFNS[number + 1]);

    EPSL_relative_ok = 0;
    EPSL_path_count = 0;
    EPSL_linetype_last = -1;	/* force next linetype change */
}

TERM_PUBLIC void
EPSL_fillbox(style, x1, y1, x2, y2)
int style;
unsigned int x1, y1, x2, y2;
{
    /* ULIG: the style parameter is now used for the fillboxes style
    * (not implemented here), see the documentation */
    EPSL_FLUSH_PATH fprintf(gpoutfile, "%d %d %d %d BoxFill\n", x1, y1, x2, y2);

    EPSL_relative_ok = 0;
    EPSL_linetype_last = -1;
}

#ifdef PM3D

TERM_PUBLIC void
EPSL_filled_polygon(points, corners)
    int points;
    gpiPoint *corners;
{
    PS_filled_polygon(points, corners);
    EPSL_relative_ok = FALSE;
}

#endif /* PM3D */

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(epslatex_driver)
"epslatex",
"LaTeX (Text) and encapsulated PostScript",
EPSL_XMAX, EPSL_YMAX, EPSL_VCHAR, EPSL_HCHAR,
EPSL_VTIC, EPSL_HTIC, EPSL_options, EPSL_init, EPSL_reset,
EPSL_text, null_scale, EPSL_graphics, EPSL_move, EPSL_vector,
EPSL_linetype, EPSL_put_text, EPSL_text_angle,
EPSL_justify_text, EPSL_point, EPSL_arrow, EPSL_set_font, EPSL_pointsize,
0 /*flags */ , 0 /*suspend */ , 0 /*resume */ , EPSL_fillbox, EPSL_linewidth
#ifdef PM3D
#ifdef USE_MOUSE
, 0, 0, 0, 0, 0 /* no mouse support for epslatex */
#endif
, PS_make_palette,
PS_previous_palette,
PS_set_color,
EPSL_filled_polygon
#endif
TERM_TABLE_END(epslatex_driver)

#undef LAST_TERM
#define LAST_TERM epslatex_driver
#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(post)
"1 epslatex",
"?commands set terminal epslatex",
"?set terminal epslatex",
"?set term epslatex",
"?terminal epslatex",
"?term epslatex",
"?epslatex",
" Two options may be set in the `epslatex` driver.",
"",
" Syntax:",
"       set terminal epslatex {default}",
"                               {color | monochrome} {solid | dashed}",
"                               {\"<fontname>\"} {<fontsize>}",
"",
" `default` mode sets all options to their defaults: `monochrome`, `dashed`,",
" \"default\" and 11pt.",
"  Default size of a plot is 5 inches wide and 3 inches high.",
"",
" `solid` draws all plots with solid lines, overriding any dashed patterns;",
" `\"<fontname>\"` is the name of font; and `<fontsize>` is",
" the size of the font in PostScript points. Font selection isn't supported yet.",
" Font size selection is supported only for the calculation of proper spacing.",
" The actual LaTeX font at the point of inclusion is taken, so use LaTeX commands",
" for changing fonts. If you use e.g. 12pt as font size for your LaTeX documents, ",
" use '\"default\" 12' as options.",
"",
" All drivers for LaTeX offer a special way of controlling text positioning:",
" If any text string begins with '{', you also need to include a '}' at the",
" end of the text, and the whole text will be centered both horizontally",
" and vertically by LaTeX. --- If the text string begins with '[', you need",
" to continue it with: a position specification (up to two out of t,b,l,r),",
" ']{', the text itself, and finally, '}'. The text itself may be anything",
" LaTeX can typeset as an LR-box. \\rule{}{}'s may help for best positioning.",
" See also the documenation of the pslatex terminal driver.",
" To create multiline labels, use \\shortstack, example",
"    set ylabel '[r]{\\shortstack{first line \\\\ second line}}' ",
"",
" The driver produces two different files, one for the LaTeX part and one for",
" the eps part of the figure. ",
" The name of the LaTeX file is derived from the name of",
" the eps file given on the `set output` command; it is determined by replacing",
" the trailing `.eps` (actually just the final extent in the file name---and",
" the option will be turned off if there is no extent) with `.tex` in the output",
" file name.  Remember to close the file before leaving `gnuplot`.",
" There is no LaTeX output if no output file is given!",
" In your LaTeX documents use '\\input{filename}' for inclusion of the figure.",
" Include \\usepackage{graphics} in the preambel!",
" Via 'epstopdf' (contained e.g. in the teTeX package, requires ghostscript)",
" pdf files can made out of the eps files. If the graphics package is properly",
" configured, the LaTeX files can also be processed by pdflatex without",
" changes, and the pdf files are included instead of the eps files"
END_HELP(post)
#endif