Release 980628
[wine/multimedia.git] / graphics / psdrv / ps.c
blobc544d17ad38bcc6f1052e729376d56eb6ad7607d
1 /*
2 * Postscript output functions
4 * Copyright 1998 Huw D M Davies
6 */
8 #include "windows.h"
9 #include "psdrv.h"
10 #include "print.h"
11 #include "debug.h"
13 char psheader[] = /* title */
14 "%%!PS-Adobe-3.0 (not quite)\n"
15 "%%%%Creator: Wine Postscript Driver\n"
16 "%%%%Title: %s\n"
17 "%%%%BoundingBox: 0 0 595 842\n"
18 "%%%%Pages: (atend)\n"
19 "%%%%EndComments\n"
20 "%%%%BeginProlog\n"
21 "/reencodefont {\n"
22 "findfont\n"
23 "dup length dict begin\n"
24 "{1 index /FID ne {def} {pop pop} ifelse} forall\n"
25 "/Encoding ISOLatin1Encoding def\n"
26 "currentdict\n"
27 "end\n"
28 "definefont pop\n"
29 "} bind def\n"
30 "%%%%EndProlog\n"
31 "%%%%BeginSetup\n"
32 "%%%%EndSetup\n";
34 char psnewpage[] = /* name, number */
35 "%%%%Page: %s %d\n"
36 "%%%%BeginPageSetup\n"
37 "/pgsave save def\n"
38 "72 600 div dup scale\n"
39 "0 7014 translate\n"
40 "1 -1 scale\n"
41 "%%%%EndPageSetup\n";
43 char psendpage[] =
44 "pgsave restore\n"
45 "showpage\n";
47 char psfooter[] = /* pages */
48 "%%%%Trailer\n"
49 "%%%%Pages: %d\n"
50 "%%%%EOF\n";
52 char psmoveto[] = /* x, y */
53 "%d %d moveto\n";
55 char pslineto[] = /* x, y */
56 "%d %d lineto\n";
58 char psrlineto[] = /* dx, dy */
59 "%d %d rlineto\n";
61 char psstroke[] =
62 "stroke\n";
64 char psrectangle[] = /* x, y, width, height, -width */
65 "%d %d moveto\n"
66 "%d 0 rlineto\n"
67 "0 %d rlineto\n"
68 "%d 0 rlineto\n"
69 "closepath\n";
71 char psshow[] = /* string */
72 "(%s) show\n";
74 char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
75 "/%s findfont\n"
76 "[%d 0 0 %d 0 %d]\n"
77 "%d 10 div matrix rotate\n"
78 "matrix concatmatrix\n"
79 "makefont setfont\n";
81 char psreencodefont[] = /* newfontname basefontname*/
82 "/%s /%s reencodefont\n";
85 int PSDRV_WriteSpool(DC *dc, LPSTR lpData, WORD cch)
87 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
89 if(physDev->job.NeedPageHeader) {
90 physDev->job.PageNo++;
91 if( !PSDRV_WriteNewPage(dc) )
92 return FALSE;
93 physDev->job.NeedPageHeader = FALSE;
95 return WriteSpool( physDev->job.hJob, lpData, cch );
99 INT32 PSDRV_WriteHeader( DC *dc, char *title, int len )
101 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
102 char *buf, *titlebuf;
105 titlebuf = (char *)HeapAlloc( GetProcessHeap(), 0, len+1 );
106 if(!titlebuf) {
107 WARN(psdrv, "HeapAlloc failed\n");
108 return 0;
110 memcpy(titlebuf, title, len);
111 titlebuf[len] = '\0';
113 buf = (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psheader) + len);
114 if(!buf) {
115 WARN(psdrv, "HeapAlloc failed\n");
116 HeapFree( GetProcessHeap(), 0, titlebuf );
117 return 0;
120 wsprintf32A(buf, psheader, title);
122 if( WriteSpool( physDev->job.hJob, buf, strlen(buf) ) !=
123 strlen(buf) ) {
124 WARN(psdrv, "WriteSpool error\n");
125 HeapFree( GetProcessHeap(), 0, titlebuf );
126 HeapFree( GetProcessHeap(), 0, buf );
127 return 0;
129 HeapFree( GetProcessHeap(), 0, titlebuf );
130 HeapFree( GetProcessHeap(), 0, buf );
131 return 1;
135 INT32 PSDRV_WriteFooter( DC *dc )
137 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
138 char *buf;
140 buf = (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter) + 100 );
141 if(!buf) {
142 WARN(psdrv, "HeapAlloc failed\n");
143 return 0;
146 wsprintf32A(buf, psfooter, physDev->job.PageNo);
148 if( WriteSpool( physDev->job.hJob, buf, strlen(buf) ) !=
149 strlen(buf) ) {
150 WARN(psdrv, "WriteSpool error\n");
151 HeapFree( GetProcessHeap(), 0, buf );
152 return 0;
154 HeapFree( GetProcessHeap(), 0, buf );
155 return 1;
160 INT32 PSDRV_WriteEndPage( DC *dc )
162 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
164 if( WriteSpool( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
165 sizeof(psendpage)-1 ) {
166 WARN(psdrv, "WriteSpool error\n");
167 return 0;
169 return 1;
175 INT32 PSDRV_WriteNewPage( DC *dc )
177 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
178 char *buf;
179 char name[100];
181 wsprintf32A(name, "%d", physDev->job.PageNo);
183 buf = (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage) + 100 );
184 if(!buf) {
185 WARN(psdrv, "HeapAlloc failed\n");
186 return 0;
189 wsprintf32A(buf, psnewpage, name, physDev->job.PageNo);
190 if( WriteSpool( physDev->job.hJob, buf, strlen(buf) ) !=
191 strlen(buf) ) {
192 WARN(psdrv, "WriteSpool error\n");
193 HeapFree( GetProcessHeap(), 0, buf );
194 return 0;
196 HeapFree( GetProcessHeap(), 0, buf );
197 return 1;
201 BOOL32 PSDRV_WriteMoveTo(DC *dc, INT32 x, INT32 y)
203 char buf[100];
205 wsprintf32A(buf, psmoveto, x, y);
206 return PSDRV_WriteSpool(dc, buf, strlen(buf));
209 BOOL32 PSDRV_WriteLineTo(DC *dc, INT32 x, INT32 y)
211 char buf[100];
213 wsprintf32A(buf, pslineto, x, y);
214 return PSDRV_WriteSpool(dc, buf, strlen(buf));
218 BOOL32 PSDRV_WriteStroke(DC *dc)
220 return PSDRV_WriteSpool(dc, psstroke, sizeof(psstroke)-1);
225 BOOL32 PSDRV_WriteRectangle(DC *dc, INT32 x, INT32 y, INT32 width,
226 INT32 height)
228 char buf[100];
230 wsprintf32A(buf, psrectangle, x, y, width, height, -width);
231 return PSDRV_WriteSpool(dc, buf, strlen(buf));
234 static char encodingext[] = "-ISOLatin1";
236 BOOL32 PSDRV_WriteSetFont(DC *dc)
238 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
239 char *buf, *newbuf;
241 buf = (char *)HeapAlloc( GetProcessHeap(), 0,
242 sizeof(pssetfont) + strlen(physDev->font.afm->FontName) + 40);
244 if(!buf) {
245 WARN(psdrv, "HeapAlloc failed\n");
246 return FALSE;
249 newbuf = (char *)HeapAlloc( GetProcessHeap(), 0,
250 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
252 if(!newbuf) {
253 WARN(psdrv, "HeapAlloc failed\n");
254 HeapFree(GetProcessHeap(), 0, buf);
255 return FALSE;
258 wsprintf32A(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
260 wsprintf32A(buf, pssetfont, newbuf,
261 physDev->font.tm.tmHeight, -physDev->font.tm.tmHeight,
262 physDev->font.tm.tmAscent, -physDev->font.escapement);
264 PSDRV_WriteSpool(dc, buf, strlen(buf));
265 HeapFree(GetProcessHeap(), 0, buf);
266 return TRUE;
269 BOOL32 PSDRV_WriteReencodeFont(DC *dc)
271 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
272 char *buf, *newbuf;
274 buf = (char *)HeapAlloc( GetProcessHeap(), 0,
275 sizeof(psreencodefont) + 2 * strlen(physDev->font.afm->FontName)
276 + sizeof(encodingext));
278 if(!buf) {
279 WARN(psdrv, "HeapAlloc failed\n");
280 return FALSE;
283 newbuf = (char *)HeapAlloc( GetProcessHeap(), 0,
284 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
286 if(!newbuf) {
287 WARN(psdrv, "HeapAlloc failed\n");
288 HeapFree(GetProcessHeap(), 0, buf);
289 return FALSE;
292 wsprintf32A(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
293 wsprintf32A(buf, psreencodefont, newbuf, physDev->font.afm->FontName);
295 PSDRV_WriteSpool(dc, buf, strlen(buf));
297 HeapFree(GetProcessHeap(), 0, newbuf);
298 HeapFree(GetProcessHeap(), 0, buf);
299 return TRUE;
302 BOOL32 PSDRV_WriteShow(DC *dc, char *str, INT32 count)
304 char *buf;
306 buf = (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psshow) + count);
308 if(!buf) {
309 WARN(psdrv, "HeapAlloc failed\n");
310 return FALSE;
313 wsprintf32A(buf, psshow, str);
315 PSDRV_WriteSpool(dc, buf, strlen(buf));
316 HeapFree(GetProcessHeap(), 0, buf);
317 return TRUE;