2 * Postscript output functions
4 * Copyright 1998 Huw D M Davies
13 char psheader
[] = /* title */
14 "%%!PS-Adobe-3.0 (not quite)\n"
15 "%%%%Creator: Wine Postscript Driver\n"
17 "%%%%BoundingBox: 0 0 595 842\n"
18 "%%%%Pages: (atend)\n"
23 "dup length dict begin\n"
24 "{1 index /FID ne {def} {pop pop} ifelse} forall\n"
25 "/Encoding ISOLatin1Encoding def\n"
34 char psnewpage
[] = /* name, number */
36 "%%%%BeginPageSetup\n"
38 "72 600 div dup scale\n"
47 char psfooter
[] = /* pages */
52 char psmoveto
[] = /* x, y */
55 char pslineto
[] = /* x, y */
58 char psrlineto
[] = /* dx, dy */
64 char psrectangle
[] = /* x, y, width, height, -width */
71 char psshow
[] = /* string */
74 char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
77 "%d 10 div matrix rotate\n"
78 "matrix concatmatrix\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
) )
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 );
107 WARN(psdrv
, "HeapAlloc failed\n");
110 memcpy(titlebuf
, title
, len
);
111 titlebuf
[len
] = '\0';
113 buf
= (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) + len
);
115 WARN(psdrv
, "HeapAlloc failed\n");
116 HeapFree( GetProcessHeap(), 0, titlebuf
);
120 wsprintf32A(buf
, psheader
, title
);
122 if( WriteSpool( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
124 WARN(psdrv
, "WriteSpool error\n");
125 HeapFree( GetProcessHeap(), 0, titlebuf
);
126 HeapFree( GetProcessHeap(), 0, buf
);
129 HeapFree( GetProcessHeap(), 0, titlebuf
);
130 HeapFree( GetProcessHeap(), 0, buf
);
135 INT32
PSDRV_WriteFooter( DC
*dc
)
137 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
140 buf
= (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
142 WARN(psdrv
, "HeapAlloc failed\n");
146 wsprintf32A(buf
, psfooter
, physDev
->job
.PageNo
);
148 if( WriteSpool( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
150 WARN(psdrv
, "WriteSpool error\n");
151 HeapFree( GetProcessHeap(), 0, buf
);
154 HeapFree( GetProcessHeap(), 0, buf
);
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");
175 INT32
PSDRV_WriteNewPage( DC
*dc
)
177 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
181 wsprintf32A(name
, "%d", physDev
->job
.PageNo
);
183 buf
= (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 100 );
185 WARN(psdrv
, "HeapAlloc failed\n");
189 wsprintf32A(buf
, psnewpage
, name
, physDev
->job
.PageNo
);
190 if( WriteSpool( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
192 WARN(psdrv
, "WriteSpool error\n");
193 HeapFree( GetProcessHeap(), 0, buf
);
196 HeapFree( GetProcessHeap(), 0, buf
);
201 BOOL32
PSDRV_WriteMoveTo(DC
*dc
, INT32 x
, INT32 y
)
205 wsprintf32A(buf
, psmoveto
, x
, y
);
206 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
209 BOOL32
PSDRV_WriteLineTo(DC
*dc
, INT32 x
, INT32 y
)
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
,
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
;
241 buf
= (char *)HeapAlloc( GetProcessHeap(), 0,
242 sizeof(pssetfont
) + strlen(physDev
->font
.afm
->FontName
) + 40);
245 WARN(psdrv
, "HeapAlloc failed\n");
249 newbuf
= (char *)HeapAlloc( GetProcessHeap(), 0,
250 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
253 WARN(psdrv
, "HeapAlloc failed\n");
254 HeapFree(GetProcessHeap(), 0, buf
);
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
);
269 BOOL32
PSDRV_WriteReencodeFont(DC
*dc
)
271 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
274 buf
= (char *)HeapAlloc( GetProcessHeap(), 0,
275 sizeof(psreencodefont
) + 2 * strlen(physDev
->font
.afm
->FontName
)
276 + sizeof(encodingext
));
279 WARN(psdrv
, "HeapAlloc failed\n");
283 newbuf
= (char *)HeapAlloc( GetProcessHeap(), 0,
284 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
287 WARN(psdrv
, "HeapAlloc failed\n");
288 HeapFree(GetProcessHeap(), 0, buf
);
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
);
302 BOOL32
PSDRV_WriteShow(DC
*dc
, char *str
, INT32 count
)
306 buf
= (char *)HeapAlloc( GetProcessHeap(), 0, sizeof(psshow
) + count
);
309 WARN(psdrv
, "HeapAlloc failed\n");
313 wsprintf32A(buf
, psshow
, str
);
315 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
316 HeapFree(GetProcessHeap(), 0, buf
);