clr: color support with m command
[neatpost.git] / ps.c
blob6c14419f4567e810bc4e2c1156ef82e7ea3f70b9
1 #include "post.h"
3 void ps_pagebeg(int n)
5 out("%%%%Page: %d %d\n", n, n);
6 out("/saveobj save def\n");
7 out("mark\n");
8 out("%d pagesetup\n", n);
11 void ps_pageend(int n)
13 out("cleartomark\n");
14 out("showpage\n");
15 out("saveobj restore\n");
16 out("%%%%EndPage: %d %d\n", n, n);
19 void ps_trailer(int pages, char *fonts)
21 out("%%%%Trailer\n");
22 out("done\n");
23 out("%%%%DocumentFonts: %s\n", fonts);
24 out("%%%%Pages: %d\n", pages);
27 static char *prolog =
28 "/linewidth .4 def\n"
29 "/resolution 720 def\n"
30 "/pagesize [612 792] def\n"
31 "/inch {72 mul} bind def\n"
32 "\n"
33 "/setup {\n"
34 " counttomark 2 idiv {def} repeat pop\n"
35 " /scaling 72 resolution div def\n"
36 " linewidth setlinewidth\n"
37 " 1 setlinecap\n"
38 " 0 pagesize 1 get translate\n"
39 " scaling scaling scale\n"
40 " 0 0 moveto\n"
41 "} def\n"
42 "\n"
43 "/pagesetup {\n"
44 " /page exch def\n"
45 " currentdict /pagedict known currentdict page known and {\n"
46 " page load pagedict exch get cvx exec\n"
47 " } if\n"
48 "} def\n"
49 "\n"
50 "/w {neg moveto show} bind def\n"
51 "/m {neg moveto} bind def\n"
52 "/g {neg moveto {glyphshow} forall} bind def\n"
53 "/rgb {255 div 3 1 roll 255 div 3 1 roll 255 div 3 1 roll setrgbcolor} bind def\n"
54 "/done {/lastpage where {pop lastpage} if} def\n"
55 "\n"
56 "/f {\n"
57 " dup /font exch def findfont exch\n"
58 " dup /ptsize exch def scaling div dup /size exch def scalefont setfont\n"
59 " linewidth ptsize mul scaling 10 mul div setlinewidth\n"
60 "} bind def\n"
61 "\n"
62 "/savedmatrix matrix def\n"
63 "/drawl {\n"
64 " neg lineto\n"
65 "} bind def\n"
66 "/drawe {\n"
67 " savedmatrix currentmatrix pop scale\n"
68 " .5 0 rmoveto currentpoint .5 0 rmoveto .5 0 360 arc\n"
69 " savedmatrix setmatrix\n"
70 "} bind def\n"
71 "/drawa {\n"
72 " /dy2 exch def\n"
73 " /dx2 exch def\n"
74 " /dy1 exch def\n"
75 " /dx1 exch def\n"
76 " currentpoint dy1 neg add exch dx1 add exch\n"
77 " dx1 dx1 mul dy1 dy1 mul add sqrt\n"
78 " dy1 dx1 neg atan\n"
79 " dy2 neg dx2 atan\n"
80 " arc\n"
81 "} bind def\n"
82 "/draws {\n"
83 " /y2 exch def\n"
84 " /x2 exch def\n"
85 " /y1 exch def\n"
86 " /x1 exch def\n"
87 " /y0 exch def\n"
88 " /x0 exch def\n"
89 " x0 5 x1 mul add 6 div\n"
90 " y0 5 y1 mul add -6 div\n"
91 " x2 5 x1 mul add 6 div\n"
92 " y2 5 y1 mul add -6 div\n"
93 " x1 x2 add 2 div\n"
94 " y1 y2 add -2 div\n"
95 " curveto\n"
96 "} bind def\n";
98 void ps_header(void)
100 out("%%!PS-Adobe-2.0\n");
101 out("%%%%Version: 1.0\n");
102 out("%%%%Creator: neatroff - http://litcave.rudi.ir/\n");
103 out("%%%%DocumentFonts: (atend)\n");
104 out("%%%%Pages: (atend)\n");
105 out("%%%%EndComments\n");
107 out("%%%%BeginProlog\n");
108 out("%s", prolog);
109 out("%%%%EndProlog\n");
110 out("%%%%BeginSetup\n");
111 out("<< /PageSize pagesize /ImagingBBox null >> setpagedevice\n");
112 out("mark\n");
113 out("setup\n");
114 out("%%%%EndSetup\n");