2 * PostScript driver Escape function
4 * Copyright 1998 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
38 #include "wine/wingdi16.h"
41 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
46 static const char psbegindocument[] =
47 "%%BeginDocument: Wine passthrough\n";
50 DWORD write_spool( PSDRV_PDEVICE *physDev, const void *data, DWORD num )
53 if (!WritePrinter(physDev->job.hprinter, (LPBYTE) data, num, &written) || (written != num))
59 /**********************************************************************
60 * ExtEscape (WINEPS.@)
62 INT CDECL PSDRV_ExtEscape( PSDRV_PDEVICE *physDev, INT nEscape, INT cbInput, LPCVOID in_data,
63 INT cbOutput, LPVOID out_data )
68 if(cbInput < sizeof(INT))
70 WARN("cbInput < sizeof(INT) (=%d) for QUERYESCSUPPORT\n", cbInput);
73 UINT num = *(const UINT *)in_data;
74 TRACE("QUERYESCSUPPORT for %d\n", num);
90 case POSTSCRIPT_PASSTHROUGH:
91 case POSTSCRIPT_IGNORE:
95 /*case DRAWPATTERNRECT:*/
99 FIXME("QUERYESCSUPPORT(%d) - not supported.\n", num);
106 FIXME("MFCOMMENT(%p, %d)\n", in_data, cbInput);
109 case DRAWPATTERNRECT:
111 DRAWPATRECT *dpr = (DRAWPATRECT*)in_data;
113 FIXME("DRAWPATTERNRECT(pos (%d,%d), size %dx%d, style %d, pattern %x), stub!\n",
114 dpr->ptPosition.x, dpr->ptPosition.y,
115 dpr->ptSize.x, dpr->ptSize.y,
116 dpr->wStyle, dpr->wPattern
122 BANDINFOSTRUCT *ibi = (BANDINFOSTRUCT*)in_data;
123 BANDINFOSTRUCT *obi = (BANDINFOSTRUCT*)out_data;
125 FIXME("BANDINFO(graphics %d, text %d, rect [%dx%d-%dx%d]), stub!\n",
128 ibi->GraphicsRect.top,
129 ibi->GraphicsRect.bottom,
130 ibi->GraphicsRect.left,
131 ibi->GraphicsRect.right
139 if(!physDev->job.banding) {
140 physDev->job.banding = TRUE;
143 r->right = physDev->horzRes;
144 r->bottom = physDev->vertRes;
145 TRACE("NEXTBAND returning %d,%d - %d,%d\n", r->left, r->top, r->right, r->bottom );
152 TRACE("NEXTBAND rect to 0,0 - 0,0\n" );
153 physDev->job.banding = FALSE;
154 return EndPage( physDev->hdc );
159 const INT *NumCopies = in_data;
160 INT *ActualCopies = out_data;
161 if(cbInput != sizeof(INT)) {
162 WARN("cbInput != sizeof(INT) (=%d) for SETCOPYCOUNT\n", cbInput);
165 TRACE("SETCOPYCOUNT %d\n", *NumCopies);
173 strcpy(p, "PostScript");
174 *(p + strlen(p) + 1) = '\0'; /* 2 '\0's at end of string */
180 INT newCap = *(const INT *)in_data;
181 if(cbInput != sizeof(INT)) {
182 WARN("cbInput != sizeof(INT) (=%d) for SETLINECAP\n", cbInput);
185 TRACE("SETLINECAP %d\n", newCap);
191 INT newJoin = *(const INT *)in_data;
192 if(cbInput != sizeof(INT)) {
193 WARN("cbInput != sizeof(INT) (=%d) for SETLINEJOIN\n", cbInput);
196 TRACE("SETLINEJOIN %d\n", newJoin);
202 INT newLimit = *(const INT *)in_data;
203 if(cbInput != sizeof(INT)) {
204 WARN("cbInput != sizeof(INT) (=%d) for SETMITERLIMIT\n", cbInput);
207 TRACE("SETMITERLIMIT %d\n", newLimit);
212 /* Undocumented escape used by winword6.
213 Switches between ANSI and a special charset.
214 If *lpInData == 1 we require that
218 0x94 is quotedblright
222 0xa0 is non break space - yeah right.
224 If *lpInData == 0 we get ANSI.
225 Since there's nothing else there, let's just make these the default
226 anyway and see what happens...
230 case EXT_DEVICE_CAPS:
232 UINT cap = *(const UINT *)in_data;
233 if(cbInput != sizeof(UINT)) {
234 WARN("cbInput != sizeof(UINT) (=%d) for EXT_DEVICE_CAPS\n", cbInput);
237 TRACE("EXT_DEVICE_CAPS %d\n", cap);
243 const RECT *r = in_data;
244 if(cbInput != sizeof(RECT)) {
245 WARN("cbInput != sizeof(RECT) (=%d) for SET_BOUNDS\n", cbInput);
248 TRACE("SET_BOUNDS (%d,%d) - (%d,%d)\n", r->left, r->top,
249 r->right, r->bottom);
255 UINT epsprint = *(const UINT*)in_data;
256 /* FIXME: In this mode we do not need to send page intros and page
257 * ends according to the doc. But I just ignore that detail
260 TRACE("EPS Printing support %sable.\n",epsprint?"en":"dis");
264 case POSTSCRIPT_DATA:
266 case POSTSCRIPT_PASSTHROUGH:
268 /* Write directly to spool file, bypassing normal PS driver
269 * processing that is done along with writing PostScript code
271 * We have a WORD before the data counting the size, but
272 * cbInput is just this +2.
273 * However Photoshop 7 has a bug that sets cbInput to 2 less than the
274 * length of the string, rather than 2 more. So we'll use the WORD at
275 * in_data[0] instead.
277 if(!physDev->job.in_passthrough) {
278 write_spool(physDev, psbegindocument, sizeof(psbegindocument)-1);
279 physDev->job.in_passthrough = TRUE;
281 return write_spool(physDev,((char*)in_data)+2,*(const WORD*)in_data);
284 case POSTSCRIPT_IGNORE:
286 BOOL ret = physDev->job.quiet;
287 TRACE("POSTSCRIPT_IGNORE %d\n", *(const short*)in_data);
288 physDev->job.quiet = *(const short*)in_data;
292 case GETSETPRINTORIENT:
294 /* If lpInData is present, it is a 20 byte structure, first 32
295 * bit LONG value is the orientation. if lpInData is NULL, it
296 * returns the current orientation.
298 FIXME("GETSETPRINTORIENT not implemented (data %p)!\n",in_data);
302 TRACE("BEGIN_PATH\n");
303 if(physDev->pathdepth)
304 FIXME("Nested paths not yet handled\n");
305 return ++physDev->pathdepth;
309 const struct PATH_INFO *info = (const struct PATH_INFO*)in_data;
312 if(!physDev->pathdepth) {
313 ERR("END_PATH called without a BEIGN_PATH\n");
316 TRACE("RenderMode = %d, FillMode = %d, BkMode = %d\n",
317 info->RenderMode, info->FillMode, info->BkMode);
318 switch(info->RenderMode) {
319 case RENDERMODE_NO_DISPLAY:
320 PSDRV_WriteClosePath(physDev); /* not sure if this is necessary, but it can't hurt */
322 case RENDERMODE_OPEN:
323 case RENDERMODE_CLOSED:
325 FIXME("END_PATH: RenderMode %d, not yet supported\n", info->RenderMode);
328 return --physDev->pathdepth;
333 WORD mode = *(const WORD*)in_data;
337 TRACE("CLIP_TO_PATH: CLIP_SAVE\n");
338 PSDRV_WriteGSave(physDev);
341 TRACE("CLIP_TO_PATH: CLIP_RESTORE\n");
342 PSDRV_WriteGRestore(physDev);
345 TRACE("CLIP_TO_PATH: CLIP_INCLUSIVE\n");
346 /* FIXME to clip or eoclip ? (see PATH_INFO.FillMode) */
347 PSDRV_WriteClip(physDev);
348 PSDRV_WriteNewPath(physDev);
351 FIXME("CLIP_EXCLUSIVE: not implemented\n");
354 FIXME("Unknown CLIP_TO_PATH mode %d\n", mode);
359 FIXME("Unimplemented code 0x%x\n", nEscape);
364 /************************************************************************
367 INT CDECL PSDRV_StartPage( PSDRV_PDEVICE *physDev )
369 if(!physDev->job.OutOfPage) {
370 FIXME("Already started a page?\n");
374 if(physDev->job.PageNo++ == 0) {
375 if(!PSDRV_WriteHeader( physDev, physDev->job.DocName ))
379 if(!PSDRV_WriteNewPage( physDev ))
381 physDev->job.OutOfPage = FALSE;
386 /************************************************************************
389 INT CDECL PSDRV_EndPage( PSDRV_PDEVICE *physDev )
391 if(physDev->job.OutOfPage) {
392 FIXME("Already ended a page?\n");
395 if(!PSDRV_WriteEndPage( physDev ))
397 PSDRV_EmptyDownloadList(physDev, FALSE);
398 physDev->job.OutOfPage = TRUE;
403 /************************************************************************
406 static INT PSDRV_StartDocA( PSDRV_PDEVICE *physDev, const DOCINFOA *doc )
410 TRACE("(%p, %p) => %s, %s, %s\n", physDev, doc, debugstr_a(doc->lpszDocName),
411 debugstr_a(doc->lpszOutput), debugstr_a(doc->lpszDatatype));
413 if(physDev->job.id) {
414 FIXME("hJob != 0. Now what?\n");
418 /* FIXME: use PRINTER_DEFAULTS here */
419 if(!OpenPrinterA(physDev->pi->FriendlyName, &physDev->job.hprinter, NULL)) {
420 WARN("OpenPrinter(%s, ...) failed: %d\n",
421 debugstr_a(physDev->pi->FriendlyName), GetLastError());
425 di.pDocName = (LPSTR) doc->lpszDocName;
429 di.pOutputFile = (LPSTR) doc->lpszOutput;
430 else if(physDev->job.output)
431 di.pOutputFile = physDev->job.output;
433 di.pOutputFile = NULL;
435 TRACE("using output: %s\n", debugstr_a(di.pOutputFile));
437 /* redirection located in HKCU\Software\Wine\Printing\Spooler
438 is done during winspool.drv,ScheduleJob */
439 physDev->job.id = StartDocPrinterA(physDev->job.hprinter, 1, (LPBYTE) &di);
440 if(!physDev->job.id) {
441 WARN("StartDocPrinter() failed: %d\n", GetLastError());
442 ClosePrinter(physDev->job.hprinter);
445 physDev->job.banding = FALSE;
446 physDev->job.OutOfPage = TRUE;
447 physDev->job.PageNo = 0;
448 physDev->job.quiet = FALSE;
449 physDev->job.in_passthrough = FALSE;
450 physDev->job.had_passthrough_rect = FALSE;
451 if(doc->lpszDocName) {
452 physDev->job.DocName = HeapAlloc(GetProcessHeap(), 0, strlen(doc->lpszDocName)+1);
453 strcpy(physDev->job.DocName, doc->lpszDocName);
455 physDev->job.DocName = NULL;
457 return physDev->job.id;
460 /************************************************************************
463 INT CDECL PSDRV_StartDoc( PSDRV_PDEVICE *physDev, const DOCINFOW *doc )
467 LPSTR docname = NULL, output = NULL, datatype = NULL;
469 TRACE("(%p, %p) => %d,%s,%s,%s\n", physDev, doc, doc->cbSize, debugstr_w(doc->lpszDocName),
470 debugstr_w(doc->lpszOutput), debugstr_w(doc->lpszDatatype));
472 docA.cbSize = doc->cbSize;
473 if (doc->lpszDocName)
475 len = WideCharToMultiByte( CP_ACP, 0, doc->lpszDocName, -1, NULL, 0, NULL, NULL );
476 if ((docname = HeapAlloc( GetProcessHeap(), 0, len )))
477 WideCharToMultiByte( CP_ACP, 0, doc->lpszDocName, -1, docname, len, NULL, NULL );
481 len = WideCharToMultiByte( CP_ACP, 0, doc->lpszOutput, -1, NULL, 0, NULL, NULL );
482 if ((output = HeapAlloc( GetProcessHeap(), 0, len )))
483 WideCharToMultiByte( CP_ACP, 0, doc->lpszOutput, -1, output, len, NULL, NULL );
485 if (doc->lpszDatatype)
487 len = WideCharToMultiByte( CP_ACP, 0, doc->lpszDatatype, -1, NULL, 0, NULL, NULL );
488 if ((datatype = HeapAlloc( GetProcessHeap(), 0, len )))
489 WideCharToMultiByte( CP_ACP, 0, doc->lpszDatatype, -1, datatype, len, NULL, NULL );
491 docA.lpszDocName = docname;
492 docA.lpszOutput = output;
493 docA.lpszDatatype = datatype;
494 docA.fwType = doc->fwType;
496 ret = PSDRV_StartDocA(physDev, &docA);
498 HeapFree( GetProcessHeap(), 0, docname );
499 HeapFree( GetProcessHeap(), 0, output );
500 HeapFree( GetProcessHeap(), 0, datatype );
505 /************************************************************************
508 INT CDECL PSDRV_EndDoc( PSDRV_PDEVICE *physDev )
511 if(!physDev->job.id) {
512 FIXME("hJob == 0. Now what?\n");
516 if(!physDev->job.OutOfPage) {
517 WARN("Somebody forgot an EndPage\n");
518 PSDRV_EndPage( physDev );
520 PSDRV_WriteFooter( physDev );
522 ret = EndDocPrinter(physDev->job.hprinter);
523 ClosePrinter(physDev->job.hprinter);
524 physDev->job.hprinter = NULL;
526 HeapFree(GetProcessHeap(), 0, physDev->job.DocName);
527 physDev->job.DocName = NULL;