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