post: switch to ISC
[neatpost.git] / ps.c
blob12f00158d4518ba5b732383f40098c31a31ee268
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");
18 void ps_trailer(int pages, char *fonts)
20 out("%%%%Trailer\n");
21 out("done\n");
22 out("%%%%DocumentFonts: %s\n", fonts);
23 out("%%%%Pages: %d\n", pages);
24 out("%%%%EOF\n");
27 static char *prolog =
28 "/setup {\n"
29 " counttomark 2 idiv {def} repeat pop\n"
30 " /scaling 72 resolution div def\n"
31 " linewidth setlinewidth\n"
32 " 1 setlinecap\n"
33 " 0 pagesize 1 get translate\n"
34 " scaling scaling scale\n"
35 " 0 0 moveto\n"
36 "} def\n"
37 "\n"
38 "/pagesetup {\n"
39 " /page exch def\n"
40 " currentdict /pagedict known currentdict page known and {\n"
41 " page load pagedict exch get cvx exec\n"
42 " } if\n"
43 "} def\n"
44 "\n"
45 "/w {neg moveto show} bind def\n"
46 "/m {neg moveto} bind def\n"
47 "/g {neg moveto {glyphshow} forall} bind def\n"
48 "/rgb {255 div 3 1 roll 255 div 3 1 roll 255 div 3 1 roll setrgbcolor} bind def\n"
49 "/rot {/y exch def /x exch def x y neg translate rotate x neg y translate} bind def\n"
50 "/done {/lastpage where {pop lastpage} if} def\n"
51 "\n"
52 "% caching fonts, as selectfont is supposed to be doing\n"
53 "/fncache 16 dict def\n"
54 "/selectfont_append { fncache exch dup findfont put } bind def\n"
55 "/selectfont_cached {\n"
56 " exch dup fncache exch known not { dup selectfont_append } if\n"
57 " fncache exch get exch scalefont setfont\n"
58 "} bind def\n"
59 "/f {\n"
60 " exch dup 3 1 roll scaling div selectfont_cached\n"
61 " linewidth mul scaling 10 mul div setlinewidth\n"
62 "} bind def\n"
63 "\n"
64 "/savedmatrix matrix def\n"
65 "/drawl {\n"
66 " neg lineto\n"
67 "} bind def\n"
68 "/drawe {\n"
69 " savedmatrix currentmatrix pop scale\n"
70 " .5 0 rmoveto currentpoint .5 0 rmoveto .5 0 360 arc\n"
71 " savedmatrix setmatrix\n"
72 "} bind def\n"
73 "/drawa {\n"
74 " /dy2 exch def\n"
75 " /dx2 exch def\n"
76 " /dy1 exch def\n"
77 " /dx1 exch def\n"
78 " currentpoint dy1 neg add exch dx1 add exch\n"
79 " dx1 dx1 mul dy1 dy1 mul add sqrt\n"
80 " dy1 dx1 neg atan\n"
81 " dy2 neg dx2 atan\n"
82 " arc\n"
83 "} bind def\n"
84 "/draws {\n"
85 " /y2 exch def\n"
86 " /x2 exch def\n"
87 " /y1 exch def\n"
88 " /x1 exch def\n"
89 " /y0 exch def\n"
90 " /x0 exch def\n"
91 " x0 5 x1 mul add 6 div\n"
92 " y0 5 y1 mul add -6 div\n"
93 " x2 5 x1 mul add 6 div\n"
94 " y2 5 y1 mul add -6 div\n"
95 " x1 x2 add 2 div\n"
96 " y1 y2 add -2 div\n"
97 " curveto\n"
98 "} bind def\n"
99 "% including EPS files\n"
100 "/EPSFBEG {\n"
101 " /epsf_state save def\n"
102 " neg translate\n"
103 " div 3 1 roll div exch scale\n"
104 " neg exch neg exch translate\n"
105 " /dict_count countdictstack def\n"
106 " /op_count count 1 sub def\n"
107 " userdict begin\n"
108 " /showpage { } def\n"
109 " 0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin\n"
110 " 10 setmiterlimit [ ] 0 setdash newpath\n"
111 "} bind def\n"
112 "/EPSFEND {\n"
113 " count op_count sub {pop} repeat\n"
114 " countdictstack dict_count sub {end} repeat\n"
115 " epsf_state restore\n"
116 "} bind def\n";
118 /* pagewidth and pageheight are in tenths of a millimetre */
119 void ps_header(int pagewidth, int pageheight, int linewidth)
121 out("%%!PS-Adobe-2.0\n");
122 out("%%%%Version: 1.0\n");
123 out("%%%%Creator: Neatroff - http://litcave.rudi.ir/\n");
124 out("%%%%DocumentFonts: (atend)\n");
125 out("%%%%Pages: (atend)\n");
126 out("%%%%EndComments\n");
128 out("%%%%BeginProlog\n");
129 out("/resolution %d def\n", dev_res);
130 out("/pagesize [%d %d] def\n", (pagewidth * 72 + 127) / 254,
131 (pageheight * 72 + 127) / 254);
132 out("/linewidth %d.%02d def\n\n", linewidth / 100, linewidth % 100);
133 out("%s", prolog);
134 out("%%%%EndProlog\n");
135 out("%%%%BeginSetup\n");
136 out("<< /PageSize pagesize /ImagingBBox null >> setpagedevice\n");
137 out("mark\n");
138 out("setup\n");
139 out("%%%%EndSetup\n");