post: print a help message when unknown options are given
[neatpost.git] / ps.c
blobe85ce2f33221ef7e8a91d0253b48692c7b3dfaaf
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 "/pagesize [612 792] def\n"
30 "\n"
31 "/setup {\n"
32 " counttomark 2 idiv {def} repeat pop\n"
33 " /scaling 72 resolution div def\n"
34 " linewidth setlinewidth\n"
35 " 1 setlinecap\n"
36 " 0 pagesize 1 get translate\n"
37 " scaling scaling scale\n"
38 " 0 0 moveto\n"
39 "} def\n"
40 "\n"
41 "/pagesetup {\n"
42 " /page exch def\n"
43 " currentdict /pagedict known currentdict page known and {\n"
44 " page load pagedict exch get cvx exec\n"
45 " } if\n"
46 "} def\n"
47 "\n"
48 "/w {neg moveto show} bind def\n"
49 "/m {neg moveto} bind def\n"
50 "/g {neg moveto {glyphshow} forall} bind def\n"
51 "/rgb {255 div 3 1 roll 255 div 3 1 roll 255 div 3 1 roll setrgbcolor} bind def\n"
52 "/done {/lastpage where {pop lastpage} if} def\n"
53 "\n"
54 "% caching fonts, as selectfont is supposed to be doing\n"
55 "/fncache 7 array def\n"
56 "/fncidx 0 def\n"
57 "/selectfont_cached {\n"
58 " /fsize exch def\n"
59 " /fname exch def\n"
60 " /font null def\n"
61 " fncache {\n"
62 " /ent exch def\n"
63 " ent null eq not {\n"
64 " ent 0 get fname eq {\n"
65 " /font ent 1 get def\n"
66 " } if\n"
67 " } if\n"
68 " } forall\n"
69 " font null eq {\n"
70 " /font fname findfont def\n"
71 " fncache fncidx [fname font] put\n"
72 " /fncidx fncidx 1 add def\n"
73 " fncidx fncache length ge {\n"
74 " /fncidx 0 def\n"
75 " } if\n"
76 " } if\n"
77 " font fsize scalefont setfont\n"
78 "} bind def\n"
79 "/f {\n"
80 " /font exch def /ptsize exch def\n"
81 " ptsize scaling div /size exch def\n"
82 " font size selectfont_cached\n"
83 " linewidth ptsize mul scaling 10 mul div setlinewidth\n"
84 "} bind def\n"
85 "\n"
86 "/savedmatrix matrix def\n"
87 "/drawl {\n"
88 " neg lineto\n"
89 "} bind def\n"
90 "/drawe {\n"
91 " savedmatrix currentmatrix pop scale\n"
92 " .5 0 rmoveto currentpoint .5 0 rmoveto .5 0 360 arc\n"
93 " savedmatrix setmatrix\n"
94 "} bind def\n"
95 "/drawa {\n"
96 " /dy2 exch def\n"
97 " /dx2 exch def\n"
98 " /dy1 exch def\n"
99 " /dx1 exch def\n"
100 " currentpoint dy1 neg add exch dx1 add exch\n"
101 " dx1 dx1 mul dy1 dy1 mul add sqrt\n"
102 " dy1 dx1 neg atan\n"
103 " dy2 neg dx2 atan\n"
104 " arc\n"
105 "} bind def\n"
106 "/draws {\n"
107 " /y2 exch def\n"
108 " /x2 exch def\n"
109 " /y1 exch def\n"
110 " /x1 exch def\n"
111 " /y0 exch def\n"
112 " /x0 exch def\n"
113 " x0 5 x1 mul add 6 div\n"
114 " y0 5 y1 mul add -6 div\n"
115 " x2 5 x1 mul add 6 div\n"
116 " y2 5 y1 mul add -6 div\n"
117 " x1 x2 add 2 div\n"
118 " y1 y2 add -2 div\n"
119 " curveto\n"
120 "} bind def\n";
122 void ps_header(void)
124 out("%%!PS-Adobe-2.0\n");
125 out("%%%%Version: 1.0\n");
126 out("%%%%Creator: neatroff - http://litcave.rudi.ir/\n");
127 out("%%%%DocumentFonts: (atend)\n");
128 out("%%%%Pages: (atend)\n");
129 out("%%%%EndComments\n");
131 out("%%%%BeginProlog\n");
132 out("/resolution %d def\n", dev_res);
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");