forked from omnister/pdplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postscript.c
808 lines (728 loc) · 23.7 KB
/
postscript.c
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
#include <stdio.h>
#include <time.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
// #include "db.h"
#include "postscript.h"
#include "points.h"
#include "xwin.h"
// #include "ev.h"
#define MAXBUF 256
int layer=0;
int linetype=0;
int newtype=1;
int pennum=0;
int newpen=1;
int filltype=0;
int newfill=1;
int in_line=0; /* set to 1 when working on a line */
int in_poly=0;
int colorflag=1; // 0=black; 1=color; 2=greyscale
double linewidth=1.5;
int this_pen=0; // we need to save state at start of line
int this_line=0; // because lines are implicitly terminated
int this_fill=0; // by starting a new line which overwrites
int this_isfilled=0; // pen, line and fill
int debug=0;
FILE *fp=NULL; // file descriptor for output file
OMODE outputtype=POSTSCRIPT; // 0=postscript, 1=gerber
double bbllx, bblly, bburx, bbury; // bounding box in screen coords
void ps_set_color(int color) {
if (debug) printf("ps_set_color: %d\n",color);
colorflag=color;
}
void ps_set_linewidth(double width) {
if (debug) printf("ps_set_linewidth: %f\n", width);
linewidth=width;
}
void ps_set_outputtype(OMODE mode) {
if (debug) printf("ps_set_outputtype: %d\n",mode);
outputtype=mode;
}
void ps_set_file(FILE *fout)
{
if (debug) printf("ps_set_file:\n");
fp=fout;
}
void ps_set_layer(int layernumber) {
if (debug) printf("setting layer :%d\n", layernumber);
layer=layernumber;
}
void ps_set_fill(int fill)
{
if (debug) printf("setting fill:%d\n", fill);
if (fill != filltype) {
newfill=1;
}
filltype=fill;
}
void ps_set_line(int line)
{
if (debug) printf("setting line:%d\n", line);
if (line != linetype) {
newtype=1;
}
linetype=line;
}
int hpgl_penmap[] = {
1,2,3,5,
7,6,4,1,
2,3,5,7,
6,4,1,2
};
/*
// colors displayed in open office for dxf
0 blk
1 red
2 yellow
3 green
4 cyanc
5 blue
6 magenta
7 black
8 mid grey
9 light grey
xcolors dxf map
0 blk 7 blk
1 wht 7 blk
2 red 1 red
3 green 3 green
4 blue 5 blue
5 aqua 4 cyan
6 mag 6 magenta
7 yellow 2 yellow
8 pink 6 magenta
9 lime 9 lgrey
10 pale blue 4 cyan
11 blue-green 5 blue
12 purple 6 magenta
13 khaki 9 lgrey (grid)
14 light grey 8 mgrey
15 dark grey 7 black
*/
int dxf_penmap[] = {
7,7,1,3,
5,4,6,2,
6,9,4,5,
6,9,8,7
};
void ps_set_pen(int pen)
{
if (debug) printf("setting pen:%d\n", pen);
if (!colorflag) {
pen = 0; // when !colorflag force to black
}
if (pennum != pen) {
newpen=1;
}
if (outputtype == DXF) {
pennum=dxf_penmap[pen%16];
} else if (outputtype == HPGL) {
pennum=hpgl_penmap[pen%16];
} else {
pennum=pen;
}
if (colorflag != 1) {
pennum=0; // force black and white
}
}
char *pen_to_svg_color(int pen) {
switch (pen) {
default:
case 0:
return("#606000");
break;
case 1:
return("white");
break;
case 2:
return("red");
break;
case 3:
return("green");
break;
case 4:
return("blue");
break;
case 5:
// return("cyan");
return("slateblue");
break;
case 6:
return("magenta");
break;
case 7:
// return("yellow");
return("gold");
// return("black");
break;
case 8:
return("slategrey");
break;
case 9:
return("darkgrey");
break;
}
}
/*
Letter 0 0 8.5i 11i
Legal 0 0 8.5i 14i
Tabloid 0 0 11i 17i
ANSI-C 0 0 17i 22i
ANSI-D 0 0 22i 34i
ANSI-E 0 0 34i 44i
*/
/* the ps interpreter evidently pays attention to pagesize labels... */
/* can't say Letter and give Ansi-A page sizes... */
void ps_preamble(
char *dev,
char *prog,
double pdx, double pdy, /* page size in inches */
double llx, double lly, /* drawing bounding box in screen coords */
double urx, double ury
) {
time_t timep;
char buf[MAXBUF];
double xmid, ymid;
double xdel, ydel;
double s1, s2, scale;
double xmax, ymax;
int landscape;
double tmp;
int debug=0;
if (debug) printf("ps_preamble:\n");
/* some preliminaries... */
/* create transform commands based on bb and paper size */
bbllx=llx; bblly=lly; bburx=urx; bbury=ury;
if (debug) printf("llx:%f lly:%f urx:%f ury:%f\n", llx, lly, urx, ury);
/* FIXME, check that bb is in canonic order */
if ((llx > urx) || (lly > ury)) {
printf("bounding box error in postscript.c\n");
}
xmid = (llx+urx)/2.0;
ymid = (lly+ury)/2.0;
xdel = 1.05*fabs(urx-llx);
ydel = 1.05*fabs(ury-lly);
if ( outputtype == HPGL) {
// 0.0025mm per step = 1016 ticks/in
xmax=pdx*1016.0;
ymax=pdy*1016.0;
} else if ( outputtype == POSTSCRIPT) {
// 72 pts/in
xmax=pdx*72.0;
ymax=pdy*72.0;
if (debug) printf("aspect is xdel: %f, ydel: %f\n", xdel, ydel);
if (xdel > ydel) { /* flip aspect */
landscape=1;
if (debug) printf("setting landscape\n");
tmp=xmax; xmax=ymax; ymax=tmp;
} else {
printf("setting portrait\n");
landscape=0;
}
}
s1 = xmax/xdel;
s2 = ymax/ydel;
scale = s2;
if (s1 < s2) {
scale = s1;
}
if ( outputtype == AUTOPLOT) {
fprintf(fp,"back\n");
fprintf(fp,"isotropic\n");
return;
} else if ( outputtype == SVG || outputtype == WEB) {
lly = bblly-(lly-bbury);
ury = bblly-(ury-bbury);
if (outputtype == WEB) {
fprintf(fp,"<html>\n");
fprintf(fp,"<body>\n");
}
fprintf(fp,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
fprintf(fp,"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
fprintf(fp,"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
if (outputtype == WEB) {
fprintf(fp,"<title> %s </title>\n", dev);
}
fprintf(fp,"<svg xmlns=\"http://www.w3.org/2000/svg\"\n");
if (outputtype == SVG) {
fprintf(fp,"width=\"100%%\" viewBox=\"%g %g %g %g\" preserveAspectRatio=\"xMinYMin meet\">\n",
0.0, 0.0, urx-llx, lly-ury);
// llx, lly, urx-llx, ury-lly);
fprintf(fp,"<rect x=\"0\" y=\"0\" width=\"100%%\" height=\"100%%\" />\n");
//llx, ury-lly, urx-llx, 2*lly-ury);
}
if (outputtype == WEB) {
fprintf(fp,"width=\"100%%\" viewBox=\"%g %g %g %g\" preserveAspectRatio=\"xMinYMin meet\">\n",
llx, lly, urx-llx, ury-lly);
}
// fprintf(fp,"<h1> %s </h1>\n", dev);
// fprintf(fp,"<!-- program %s -->\n", prog);
} else if (outputtype == GERBER) {
fprintf(fp,"G4 Title: %s*\n", dev);
fprintf(fp,"G4 Creator: %s*\n", prog);
timep=time(&timep);
ctime_r(&timep, buf);
buf[strlen(buf)-1]='\0';
fprintf(fp,"G4 CreationDate: %s*\n", buf);
gethostname(buf,MAXBUF);
fprintf(fp,"G4 For: %s@%s (%s)*\n",
getpwuid(getuid())->pw_name, buf, getpwuid(getuid())->pw_gecos );
fprintf(fp,"G01*\n"); // linear interpolation
fprintf(fp,"G70*\n"); // inches
fprintf(fp,"G90*\n"); // absolute
fprintf(fp,"%%MOIN*%%\n"); // absolute
fprintf(fp,"G04 Gerber Fmt 3.4, Leading zero omitted, Abs format*\n");
fprintf(fp,"%%FSLAX34Y34*%%\n");
fprintf(fp,"G04 Define D10 to be a 5mil circle*\n");
fprintf(fp,"%%ADD10C,.005*%%\n");
fprintf(fp,"G04 Make D10 the default aperture*\n");
fprintf(fp,"G54D10*\n");
return;
} else if (outputtype == DXF) {
fprintf(fp, " 0\n");
fprintf(fp, "SECTION\n");
fprintf(fp, " 2\n");
fprintf(fp, "ENTITIES\n");
return;
} else if (outputtype == HPGL) {
fprintf(fp, "IN;PU;\n");
fprintf(fp, "SP%d;\n", pennum);
// HPGL plots in units of 0.025 mm = 1016 ticks per inch...
// fprintf(fp, "page size is %f %f\n", pdx*1016.0, pdy*1016.0);
// fprintf(fp, "bb is llx:%f lly:%f urx:%f ury%f\n", llx, lly, urx, ury);
fprintf(fp, "IP %d,%d,%d,%d;\n", 0, 0, (int) ((urx-llx)*scale), (int) ((ury-lly)*scale) );
// flip y axis (Xwin puts 0,0 at top, increments going down)
fprintf(fp, "SC %.4f,%.4f,%.4f,%.4f;\n", llx, urx, ury, lly);
fprintf(fp, "PA0,0;\n");
//int i,j; char *ps;
//fprintf(fp,"CO \"define stipple patterns\";\n");
//for (i=0;(ps=get_stipple_bits(i))!=NULL;i++) {
// fprintf(fp,"RF%d,8,8",i);
// for (j=0; j<=7; j++) {
// for(k=0; k<=7; k++) {
// fprintf(fp, ",%c", ((ps[j]>>k)&1)?'1':'0');
// }
// }
// fprintf(fp,";\n");
//}
return;
} else if (outputtype == POSTSCRIPT) {
fprintf(fp,"%%!PS-Adobe-2.0\n");
fprintf(fp,"%%%%Title: %s\n", dev);
fprintf(fp,"%%%%Creator: %s\n", prog);
// timep=time(&timep);
fprintf(fp,"%%%%CreationDate: %s", ctime(&timep));
gethostname(buf,MAXBUF);
fprintf(fp,"%%%%For: %s@%s (%s)\n",
getpwuid(getuid())->pw_name,
buf,
getpwuid(getuid())->pw_gecos );
if (landscape) {
fprintf(fp,"%%%%Orientation: Landscape\n");
} else {
fprintf(fp,"%%%%Orientation: Portrait\n");
}
fprintf(fp,"%%%%Pages: (atend)\n");
fprintf(fp,"%%%%BoundingBox: 0 0 %d %d\n",
(int) (pdx*72.0), (int) (pdy*72.0));
fprintf(fp,"%%%%DocumentPaperSizes: custom\n");
fprintf(fp,"%%%%Magnification: 1.0000\n");
fprintf(fp,"%%%%EndComments\n");
fprintf(fp,"%%%%BeginSetup\n");
fprintf(fp,"mark {\n");
fprintf(fp,"%%BeginFeature: *PageRegion custom\n");
fprintf(fp,"<</PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n",
(int)( pdx*72.0), (int) (pdy*72.0));
fprintf(fp,"%%EndFeature\n");
fprintf(fp,"} stopped cleartomark\n");
fprintf(fp,"%%%%EndSetup\n");
fprintf(fp,"%%%%BeginProlog\n");
fprintf(fp,"/$Pig2psDict 200 dict def\n");
fprintf(fp,"$Pig2psDict begin\n");
fprintf(fp,"$Pig2psDict /mtrx matrix put\n");
if (colorflag==1) { // color
fprintf(fp,"/c-1 {0 setgray} bind def\n");
fprintf(fp,"/c0 {0.000 0.000 0.000 srgb} bind def\n"); // blk
fprintf(fp,"/c1 {0.000 0.000 0.000 srgb} bind def\n"); // blk
fprintf(fp,"/c2 {1.000 0.000 0.000 srgb} bind def\n"); // red
fprintf(fp,"/c3 {0.000 1.000 0.000 srgb} bind def\n"); // grn
fprintf(fp,"/c4 {0.000 0.000 1.000 srgb} bind def\n"); // blu
fprintf(fp,"/c5 {0.000 1.000 1.000 srgb} bind def\n"); // aqu
fprintf(fp,"/c6 {1.000 0.000 1.000 srgb} bind def\n"); // mag
fprintf(fp,"/c7 {1.000 1.000 0.000 srgb} bind def\n"); // yel
fprintf(fp,"/c8 {1.000 0.500 0.500 srgb} bind def\n"); // pnk
fprintf(fp,"/c9 {0.500 1.000 0.500 srgb} bind def\n"); // lime
fprintf(fp,"/c10 {0.500 0.500 1.000 srgb} bind def\n"); // pale blu
fprintf(fp,"/c11 {0.000 0.500 0.500 srgb} bind def\n"); // blu-grn
fprintf(fp,"/c12 {0.500 0.000 0.500 srgb} bind def\n"); // pur
fprintf(fp,"/c13 {0.500 0.500 0.000 srgb} bind def\n"); // khaki
fprintf(fp,"/c14 {0.700 0.700 0.700 srgb} bind def\n"); // lt gr
fprintf(fp,"/c15 {0.400 0.400 0.400 srgb} bind def\n"); // dk gr
fprintf(fp,"/c16 {1.000 0.000 1.000 srgb} bind def\n");
fprintf(fp,"/c17 {1.000 1.000 0.000 srgb} bind def\n");
fprintf(fp,"/c18 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c19 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c20 {0.600 0.600 0.600 srgb} bind def\n");
} else if (colorflag==0) { // black
fprintf(fp,"/c-1 {0 setgray} bind def\n");
fprintf(fp,"/c0 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c1 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c2 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c3 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c4 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c5 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c6 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c7 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c8 {1.000 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c9 {0.600 0.600 0.600 srgb} bind def\n");
fprintf(fp,"/c10 {0.500 0.500 1.000 srgb} bind def\n");
fprintf(fp,"/c11 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c12 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c13 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c14 {0.700 0.700 0.700 srgb} bind def\n");
fprintf(fp,"/c15 {0.400 0.400 0.400 srgb} bind def\n");
fprintf(fp,"/c16 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c17 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c18 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c19 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c20 {0.600 0.600 0.600 srgb} bind def\n");
} else { // gray
fprintf(fp,"/c-1 {0 setgray} bind def\n");
fprintf(fp,"/c0 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c1 {0.200 0.200 0.200 srgb} bind def\n");
fprintf(fp,"/c2 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c3 {0.400 0.400 0.400 srgb} bind def\n");
fprintf(fp,"/c4 {0.500 0.500 0.500 srgb} bind def\n");
fprintf(fp,"/c5 {0.600 0.600 0.600 srgb} bind def\n");
fprintf(fp,"/c6 {0.700 0.700 0.700 srgb} bind def\n");
fprintf(fp,"/c7 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c8 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c9 {0.600 0.600 0.600 srgb} bind def\n");
fprintf(fp,"/c10 {0.500 0.500 1.000 srgb} bind def\n");
fprintf(fp,"/c11 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c12 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c13 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c14 {0.700 0.700 0.700 srgb} bind def\n");
fprintf(fp,"/c15 {0.400 0.400 0.400 srgb} bind def\n");
fprintf(fp,"/c16 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c17 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c18 {0.000 0.000 0.000 srgb} bind def\n");
fprintf(fp,"/c19 {0.300 0.300 0.300 srgb} bind def\n");
fprintf(fp,"/c20 {0.600 0.600 0.600 srgb} bind def\n");
}
fprintf(fp,"/cp {closepath} bind def\n");
fprintf(fp,"/ef {eofill} bind def\n");
fprintf(fp,"/gr {grestore} bind def\n");
fprintf(fp,"/gs {gsave} bind def\n");
fprintf(fp,"/sa {save} bind def\n");
fprintf(fp,"/rs {restore} bind def\n");
fprintf(fp,"/kc { currentrgbcolor [/Pattern /DeviceRGB] setcolorspace } bind def\n");
fprintf(fp,"/l {lineto} bind def\n");
fprintf(fp,"/m {moveto} bind def\n");
fprintf(fp,"/rm {rmoveto} bind def\n");
fprintf(fp,"/n {newpath} bind def\n");
fprintf(fp,"/s {stroke} bind def\n");
fprintf(fp,"/sh {show} bind def\n");
fprintf(fp,"/slc {setlinecap} bind def\n");
fprintf(fp,"/slj {setlinejoin} bind def\n");
fprintf(fp,"/slw {setlinewidth} bind def\n");
fprintf(fp,"/srgb {setrgbcolor} bind def\n");
fprintf(fp,"/rot {rotate} bind def\n");
fprintf(fp,"/sc {scale} bind def\n");
fprintf(fp,"/sd {setdash} bind def\n");
fprintf(fp,"/ff {findfont} bind def\n");
fprintf(fp,"/sf {setfont} bind def\n");
fprintf(fp,"/scf {scalefont} bind def\n");
fprintf(fp,"/sw {stringwidth} bind def\n");
fprintf(fp,"/tr {translate} bind def\n");
fprintf(fp,"%% start stipple patterns\n");
int i,j; char *ps;
for (i=0;(ps=get_stipple_bits(i))!=NULL;i++) {
fprintf(fp,"/p%d {\n",i);
fprintf(fp,".5 .5 scale 8 8 true matrix {<");
for (j=0; j<=7; j++) {
fprintf(fp,"%02x",ps[j]&255);
}
fprintf(fp,">} imagemask\n");
fprintf(fp,"} bind def\n");
fprintf(fp,"<< /PatternType 1\n");
fprintf(fp," /PaintType 2\n");
fprintf(fp," /TilingType 1\n");
fprintf(fp," /XStep 4 /YStep 4\n");
fprintf(fp," /BBox [0 0 8 8]\n");
fprintf(fp," /PaintProc { p%d }\n",i);
fprintf(fp,">>\n");
fprintf(fp,"matrix makepattern /f%d exch def\n",i);
}
fprintf(fp,"%% end stipple patterns\n");
fprintf(fp,"end\n");
fprintf(fp,"save\n");
// fprintf(fp,"newpath\n");
// fprintf(fp,"0 %d moveto\n", (int) (pdy*72.0));
// fprintf(fp,"0 0 lineto\n");
// fprintf(fp,"%d 0 lineto\n", (int) (pdx*72.0));
// fprintf(fp,"%d %d lineto closepath clip newpath\n",
// (int) (pdx*72.0), (int) (pdy*72.0));
fprintf(fp,"/$Pig2psBegin\n");
fprintf(fp,"{$Pig2psDict begin /$Pig2psEnteredState save def}def\n");
fprintf(fp,"/$Pig2psEnd {$Pig2psEnteredState restore end} def\n");
fprintf(fp,"%%BeginPageSetup\n");
fprintf(fp,"%%BB is %f,%f %f,%f\n", llx, lly, urx, ury);
if (landscape) {
fprintf(fp,"%f %f scale\n", scale, scale);
fprintf(fp,"%f %f translate\n",
(ymax/(2.0*scale))+ymid, (xmax/(2.0*scale))-xmid);
fprintf(fp,"90 rotate\n");
} else {
fprintf(fp,"%f %f scale\n", scale, scale);
fprintf(fp,"%f %f translate\n",
(xmax/(2.0*scale))-xmid, (ymax/(2.0*scale))-ymid);
}
fprintf(fp,"%%EndPageSetup\n");
fprintf(fp,"%%%%EndProlog\n");
fprintf(fp,"$Pig2psBegin\n");
fprintf(fp,"10 setmiterlimit\n");
fprintf(fp,"1 slj 1 slc\n");
fprintf(fp,"%.1f slw\n",linewidth);
fprintf(fp,"%% here starts figure;\n");
return;
} else {
printf("unrecognized plot type in postscript.c\n");
return;
}
}
void ps_comment(char *comment)
{
if ((fp != NULL)) {
if (outputtype == GERBER) { // GERBER
;
} else if (outputtype == HPGL) { // HPGL
;
} else if (outputtype == DXF) { // DXF
;
} else if (outputtype == POSTSCRIPT) { // PS
;
} else if (outputtype == SVG) { // Scalable vector graphics
// fprintf(fp, "<!--%s-->\n",comment);
} else if (outputtype == WEB) { // WEB = html
fprintf(fp, "<!--%s-->\n",comment);
} else if (outputtype == AUTOPLOT) { // AUTOPLOT
fprintf(fp, "#%s\n",comment);
}
}
}
void ps_end_line()
{
extern int this_pen;
extern int this_line;
extern int in_line;
extern int this_isfilled;
int debug = 0;
if (debug) printf("ps_end_line:\n");
if (outputtype == GERBER) { // GERBER
if (in_poly) {
fprintf(fp, "G37*\n");
}
} else if (outputtype == SVG || outputtype == WEB) { // SVG
fprintf(fp,
"\"\nstyle=\"fill:none;stroke:%s;stroke-width:%g;stroke-linejoin:round;\"/>\n",
pen_to_svg_color(this_pen),linewidth*2.0); // wider lines for power point
if (xwin_svg_dashes(this_line) != NULL) {
fprintf(fp, "stroke-dasharray=\"%s\" ", xwin_svg_dashes(this_line));
}
} else if (outputtype == HPGL) { // HPGL
if (in_poly) {
fprintf(fp, "PM2;\n");
if (this_isfilled) {
fprintf(fp, "%s\n", get_hpgl_fill(this_fill));
fprintf(fp, "LT; FP;\n");
}
if (this_line == 0) {
fprintf(fp, "LT;EP;\n");
} else {
fprintf(fp, "LT%d;EP;\n", this_line);
}
}
} else if (outputtype == POSTSCRIPT) {
fprintf(fp, "c%d ", this_pen);
// if (in_poly) {
// fprintf(fp, "gs kc f%d setpattern fill gr\n",
// get_stipple_index(this_fill,this_pen));
// }
fprintf(fp, "%s ", xwin_ps_dashes(this_line));
fprintf(fp, "s\n");
}
in_poly=0;
in_line=0;
}
void ps_flush() {
if (in_line) {
ps_end_line(fp);
}
in_line=0;
}
double xold, yold;
int in_progress=0;
void ps_start_line(double x1, double y1, int filled)
{
extern int pennum;
extern int linetype;
extern int in_line;
extern int this_pen;
extern int this_line;
extern int this_fill;
extern int this_isfilled;
if (debug) printf("ps_start_line:\n");
if (in_line) {
ps_end_line(fp);
}
in_line++;
if (filled) {
if (outputtype == GERBER) { // GERBER
fprintf(fp,"G04 LAYER %d *\n", layer);
fprintf(fp, "G36*\n");
}
in_poly++;
}
this_pen=pennum; /* save characteristics at start of line */
this_line=linetype;
this_fill=filltype;
this_isfilled=filled;
if (outputtype == SVG || outputtype == WEB) { // SVG
fprintf(fp, "<polyline\n points=\"\n");
y1 = bblly-(y1-bbury);
fprintf(fp, " %g,%g\n", x1, y1);
} else if (outputtype == POSTSCRIPT) { // Postscript
fprintf(fp, "n\n");
// flip y coordinate from Xwin coords
// y1 = bblly-(y1-bbury);
fprintf(fp, "%.10g %.10g m\n",x1, y1);
} else if (outputtype == AUTOPLOT) { // AUTOPLOT
fprintf(fp, "jump\n");
fprintf(fp, "pen %d\n", pennum);
fprintf(fp, "%.10g %.10g\n",x1, y1);
} else if (outputtype == GERBER) { // GERBER
if (!in_poly) {
fprintf(fp,"G04 LAYER %d *\n", layer);
}
fprintf(fp, "X%04dY%04dD02*\n",(int)((x1*10000.0)+0.5), (int)((y1*10000.0)+0.5));
} else if (outputtype == DXF) { // DXF
// fprintf(fp, " 0\n"); // start of entity
// fprintf(fp, "LINE\n"); // line type entity
// fprintf(fp, " 8\n"); // layer name to follow
// fprintf(fp, "%d\n",layer); // layer name
// fprintf(fp, " 62\n"); // color flag
// fprintf(fp, "%d\n", pennum); // color
// fprintf(fp, " 10\n%.10g\n", x1); // initial x value
// fprintf(fp, " 20\n%.10g\n", y1); // initial y value
xold=x1;
yold=y1;
in_progress=0;
} else if (outputtype == HPGL) {
if (!filled) {
if (this_line == 0) {
fprintf(fp, "LT;\n");
} else {
fprintf(fp, "LT%d;\n", this_line);
}
}
fprintf(fp, "SP%d;\n", this_pen);
fprintf(fp, "PU %.4f,%.4f;\n",x1,y1);
if (filled) {
fprintf(fp,"PM0;\n");
}
}
}
void ps_continue_line(double x1, double y1)
{
if (debug) printf("ps_continue_line:\n");
if (outputtype == SVG || outputtype == WEB) { // SVG
y1 = bblly-(y1-bbury);
fprintf(fp, " %g,%g\n", x1, y1);
} else if (outputtype == POSTSCRIPT) {
// flip y coordinate from Xwin coords
// y1 = bblly-(y1-bbury);
fprintf(fp, "%.10g %.10g l\n",x1, y1);
} else if (outputtype == AUTOPLOT) { // AUTOPLOT
fprintf(fp, "%.10g %.10g\n",x1, y1);
} else if (outputtype == GERBER) { // GERBER
fprintf(fp, "X%04dY%04dD01*\n",(int)((x1*10000.0)+0.5), (int)((y1*10000.0)+0.5));
} else if (outputtype == DXF) {
if (!in_progress) {
fprintf(fp, " 0\n"); // start of entity
fprintf(fp, "LINE\n"); // line type entity
fprintf(fp, " 8\n"); // layer name to follow
fprintf(fp, "%d\n",layer); // layer name
fprintf(fp, " 62\n"); // color flag
fprintf(fp, "%d\n", pennum); // color
fprintf(fp, " 10\n%.10g\n", xold); // initial x value
fprintf(fp, " 20\n%.10g\n", yold); // initial y value
fprintf(fp, " 11\n%.10f\n", x1); // initial x value
fprintf(fp, " 21\n%.10f\n", y1); // initial y value
in_progress++;
} else {
fprintf(fp, " 0\n"); // start of entity
fprintf(fp, "LINE\n"); // line type entity
fprintf(fp, " 8\n"); // layer name to follow
fprintf(fp, "%d\n",layer); // layer name
fprintf(fp, " 62\n"); // color flag
fprintf(fp, "%d\n", pennum); // color
fprintf(fp, " 10\n%.10f\n", xold); // initial x value
fprintf(fp, " 20\n%.10f\n", yold); // initial y value
fprintf(fp, " 11\n%.10f\n", x1); // initial x value
fprintf(fp, " 21\n%.10f\n", y1); // initial y value
}
xold = x1;
yold = y1;
} else if (outputtype == HPGL) { // HPGL
fprintf(fp, "PD %.4f,%.4f;\n",x1,y1);
}
in_line++;
}
void ps_postamble()
{
// time_t timep;
// char buf[MAXBUF];
if (debug) printf("ps_postamble:\n");
if (in_line) {
ps_end_line(fp);
in_line=0;
}
if (outputtype == POSTSCRIPT) {
fprintf(fp,"%% here ends figure;\n");
fprintf(fp,"$Pig2psEnd\n");
fprintf(fp,"showpage\n");
fprintf(fp,"%%%%EOF\n");
} else if (outputtype == GERBER) {
fprintf(fp,"G04 LAYER 999 *\n");
fprintf(fp,"M02*\n");
} else if (outputtype == DXF) {
fprintf(fp," 0\nENDSEC\n");
fprintf(fp," 0\nEOF\n");
} else if (outputtype == HPGL) {
fprintf(fp,"PU;\n");
fprintf(fp,"SP;\n");
fprintf(fp,"IN;\n");
} else if (outputtype == SVG || outputtype == WEB) {
fprintf(fp,"</svg>\n");
if (outputtype == WEB) {
fprintf(fp,"</body>\n");
fprintf(fp,"</html>\n");
}
//fprintf(fp,"<hr>\n");
//timep=time(&timep);
//ctime_r(&timep, buf);
//buf[strlen(buf)-1]='\0';
////fprintf(fp,"<p> creation date %s<br>\n", buf);
//gethostname(buf,MAXBUF);
//fprintf(fp,"<p> For: %s@%s (%s) <br>\n",
// getpwuid(getuid())->pw_name,
// buf,
// getpwuid(getuid())->pw_gecos );
}
fclose(fp); fp=NULL;
}