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";
49 /* FIXME: should use winspool functions instead */
50 static DWORD
create_job(LPCSTR pszOutput
)
54 const char *psCmdP
= psCmd
;
57 /* TTD convert the 'output device' into a spool file name */
59 if (pszOutput
== NULL
|| *pszOutput
== '\0') return 0;
62 /* @@ Wine registry key: HKCU\Software\Wine\Printing\Spooler */
63 if(!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Printing\\Spooler", &hkey
))
65 DWORD type
, count
= sizeof(psCmd
);
66 RegQueryValueExA(hkey
, pszOutput
, 0, &type
, (LPBYTE
)psCmd
, &count
);
69 if (!psCmd
[0] && !strncmp("LPR:",pszOutput
,4))
70 sprintf(psCmd
,"|lpr -P'%s'",pszOutput
+4);
72 TRACE("Got printerSpoolCommand '%s' for output device '%s'\n",
78 while (*psCmdP
&& isspace(*psCmdP
))
82 if (!*psCmdP
) return 0;
84 TRACE("command: '%s'\n", psCmdP
);
90 ERR("pipe() failed!\n");
97 TRACE("In child need to exec %s\n",psCmdP
);
102 /* reset signals that we previously set to SIG_IGN */
103 signal( SIGPIPE
, SIG_DFL
);
104 signal( SIGCHLD
, SIG_DFL
);
106 execl("/bin/sh", "/bin/sh", "-c", psCmdP
, NULL
);
112 TRACE("Need to execute a cmnd and pipe the output to it\n");
118 WCHAR psCmdPW
[MAX_PATH
];
120 TRACE("Just assume it's a file\n");
123 * The file name can be dos based, we have to find its
124 * corresponding Unix file name.
126 MultiByteToWideChar(CP_ACP
, 0, psCmdP
, -1, psCmdPW
, MAX_PATH
);
127 if ((buffer
= wine_get_unix_file_name(psCmdPW
)))
129 if ((fd
= open(buffer
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0666)) < 0)
131 ERR("Failed to create spool file '%s' ('%s'). (error %s)\n",
132 buffer
, psCmdP
, strerror(errno
));
134 HeapFree(GetProcessHeap(), 0, buffer
);
140 static int close_job( DWORD id
)
147 DWORD
write_spool( PSDRV_PDEVICE
*physDev
, const void *data
, DWORD num
)
149 int fd
= physDev
->job
.id
- 1;
150 if (write( fd
, data
, num
) != num
) return SP_OUTOFDISK
;
154 /**********************************************************************
155 * ExtEscape (WINEPS.@)
157 INT CDECL
PSDRV_ExtEscape( PSDRV_PDEVICE
*physDev
, INT nEscape
, INT cbInput
, LPCVOID in_data
,
158 INT cbOutput
, LPVOID out_data
)
162 case QUERYESCSUPPORT
:
163 if(cbInput
< sizeof(INT
))
165 WARN("cbInput < sizeof(INT) (=%d) for QUERYESCSUPPORT\n", cbInput
);
168 UINT num
= *(const UINT
*)in_data
;
169 TRACE("QUERYESCSUPPORT for %d\n", num
);
180 case EXT_DEVICE_CAPS
:
183 case POSTSCRIPT_DATA
:
185 case POSTSCRIPT_PASSTHROUGH
:
186 case POSTSCRIPT_IGNORE
:
190 /*case DRAWPATTERNRECT:*/
194 FIXME("QUERYESCSUPPORT(%d) - not supported.\n", num
);
201 FIXME("MFCOMMENT(%p, %d)\n", in_data
, cbInput
);
204 case DRAWPATTERNRECT
:
206 DRAWPATRECT
*dpr
= (DRAWPATRECT
*)in_data
;
208 FIXME("DRAWPATTERNRECT(pos (%d,%d), size %dx%d, style %d, pattern %x), stub!\n",
209 dpr
->ptPosition
.x
, dpr
->ptPosition
.y
,
210 dpr
->ptSize
.x
, dpr
->ptSize
.y
,
211 dpr
->wStyle
, dpr
->wPattern
217 BANDINFOSTRUCT
*ibi
= (BANDINFOSTRUCT
*)in_data
;
218 BANDINFOSTRUCT
*obi
= (BANDINFOSTRUCT
*)out_data
;
220 FIXME("BANDINFO(graphics %d, text %d, rect [%dx%d-%dx%d]), stub!\n",
223 ibi
->GraphicsRect
.top
,
224 ibi
->GraphicsRect
.bottom
,
225 ibi
->GraphicsRect
.left
,
226 ibi
->GraphicsRect
.right
234 if(!physDev
->job
.banding
) {
235 physDev
->job
.banding
= TRUE
;
238 r
->right
= physDev
->horzRes
;
239 r
->bottom
= physDev
->vertRes
;
240 TRACE("NEXTBAND returning %d,%d - %d,%d\n", r
->left
, r
->top
, r
->right
, r
->bottom
);
247 TRACE("NEXTBAND rect to 0,0 - 0,0\n" );
248 physDev
->job
.banding
= FALSE
;
249 return EndPage( physDev
->hdc
);
254 const INT
*NumCopies
= in_data
;
255 INT
*ActualCopies
= out_data
;
256 if(cbInput
!= sizeof(INT
)) {
257 WARN("cbInput != sizeof(INT) (=%d) for SETCOPYCOUNT\n", cbInput
);
260 TRACE("SETCOPYCOUNT %d\n", *NumCopies
);
268 strcpy(p
, "PostScript");
269 *(p
+ strlen(p
) + 1) = '\0'; /* 2 '\0's at end of string */
275 INT newCap
= *(const INT
*)in_data
;
276 if(cbInput
!= sizeof(INT
)) {
277 WARN("cbInput != sizeof(INT) (=%d) for SETLINECAP\n", cbInput
);
280 TRACE("SETLINECAP %d\n", newCap
);
286 INT newJoin
= *(const INT
*)in_data
;
287 if(cbInput
!= sizeof(INT
)) {
288 WARN("cbInput != sizeof(INT) (=%d) for SETLINEJOIN\n", cbInput
);
291 TRACE("SETLINEJOIN %d\n", newJoin
);
297 INT newLimit
= *(const INT
*)in_data
;
298 if(cbInput
!= sizeof(INT
)) {
299 WARN("cbInput != sizeof(INT) (=%d) for SETMITERLIMIT\n", cbInput
);
302 TRACE("SETMITERLIMIT %d\n", newLimit
);
307 /* Undocumented escape used by winword6.
308 Switches between ANSI and a special charset.
309 If *lpInData == 1 we require that
313 0x94 is quotedblright
317 0xa0 is non break space - yeah right.
319 If *lpInData == 0 we get ANSI.
320 Since there's nothing else there, let's just make these the default
321 anyway and see what happens...
325 case EXT_DEVICE_CAPS
:
327 UINT cap
= *(const UINT
*)in_data
;
328 if(cbInput
!= sizeof(UINT
)) {
329 WARN("cbInput != sizeof(UINT) (=%d) for EXT_DEVICE_CAPS\n", cbInput
);
332 TRACE("EXT_DEVICE_CAPS %d\n", cap
);
338 const RECT
*r
= in_data
;
339 if(cbInput
!= sizeof(RECT
)) {
340 WARN("cbInput != sizeof(RECT) (=%d) for SET_BOUNDS\n", cbInput
);
343 TRACE("SET_BOUNDS (%d,%d) - (%d,%d)\n", r
->left
, r
->top
,
344 r
->right
, r
->bottom
);
350 UINT epsprint
= *(const UINT
*)in_data
;
351 /* FIXME: In this mode we do not need to send page intros and page
352 * ends according to the doc. But I just ignore that detail
355 TRACE("EPS Printing support %sable.\n",epsprint
?"en":"dis");
359 case POSTSCRIPT_DATA
:
361 case POSTSCRIPT_PASSTHROUGH
:
363 /* Write directly to spool file, bypassing normal PS driver
364 * processing that is done along with writing PostScript code
366 * We have a WORD before the data counting the size, but
367 * cbInput is just this +2.
368 * However Photoshop 7 has a bug that sets cbInput to 2 less than the
369 * length of the string, rather than 2 more. So we'll use the WORD at
370 * in_data[0] instead.
372 if(!physDev
->job
.in_passthrough
) {
373 write_spool(physDev
, psbegindocument
, sizeof(psbegindocument
)-1);
374 physDev
->job
.in_passthrough
= TRUE
;
376 return write_spool(physDev
,((char*)in_data
)+2,*(const WORD
*)in_data
);
379 case POSTSCRIPT_IGNORE
:
381 BOOL ret
= physDev
->job
.quiet
;
382 TRACE("POSTSCRIPT_IGNORE %d\n", *(const short*)in_data
);
383 physDev
->job
.quiet
= *(const short*)in_data
;
387 case GETSETPRINTORIENT
:
389 /* If lpInData is present, it is a 20 byte structure, first 32
390 * bit LONG value is the orientation. if lpInData is NULL, it
391 * returns the current orientation.
393 FIXME("GETSETPRINTORIENT not implemented (data %p)!\n",in_data
);
397 TRACE("BEGIN_PATH\n");
398 if(physDev
->pathdepth
)
399 FIXME("Nested paths not yet handled\n");
400 return ++physDev
->pathdepth
;
404 const struct PATH_INFO
*info
= (const struct PATH_INFO
*)in_data
;
407 if(!physDev
->pathdepth
) {
408 ERR("END_PATH called without a BEIGN_PATH\n");
411 TRACE("RenderMode = %d, FillMode = %d, BkMode = %d\n",
412 info
->RenderMode
, info
->FillMode
, info
->BkMode
);
413 switch(info
->RenderMode
) {
414 case RENDERMODE_NO_DISPLAY
:
415 PSDRV_WriteClosePath(physDev
); /* not sure if this is necessary, but it can't hurt */
417 case RENDERMODE_OPEN
:
418 case RENDERMODE_CLOSED
:
420 FIXME("END_PATH: RenderMode %d, not yet supported\n", info
->RenderMode
);
423 return --physDev
->pathdepth
;
428 WORD mode
= *(const WORD
*)in_data
;
432 TRACE("CLIP_TO_PATH: CLIP_SAVE\n");
433 PSDRV_WriteGSave(physDev
);
436 TRACE("CLIP_TO_PATH: CLIP_RESTORE\n");
437 PSDRV_WriteGRestore(physDev
);
440 TRACE("CLIP_TO_PATH: CLIP_INCLUSIVE\n");
441 /* FIXME to clip or eoclip ? (see PATH_INFO.FillMode) */
442 PSDRV_WriteClip(physDev
);
443 PSDRV_WriteNewPath(physDev
);
446 FIXME("CLIP_EXCLUSIVE: not implemented\n");
449 FIXME("Unknown CLIP_TO_PATH mode %d\n", mode
);
454 FIXME("Unimplemented code 0x%x\n", nEscape
);
459 /************************************************************************
462 INT CDECL
PSDRV_StartPage( PSDRV_PDEVICE
*physDev
)
464 if(!physDev
->job
.OutOfPage
) {
465 FIXME("Already started a page?\n");
469 if(physDev
->job
.PageNo
++ == 0) {
470 if(!PSDRV_WriteHeader( physDev
, physDev
->job
.DocName
))
474 if(!PSDRV_WriteNewPage( physDev
))
476 physDev
->job
.OutOfPage
= FALSE
;
481 /************************************************************************
484 INT CDECL
PSDRV_EndPage( PSDRV_PDEVICE
*physDev
)
486 if(physDev
->job
.OutOfPage
) {
487 FIXME("Already ended a page?\n");
490 if(!PSDRV_WriteEndPage( physDev
))
492 PSDRV_EmptyDownloadList(physDev
, FALSE
);
493 physDev
->job
.OutOfPage
= TRUE
;
498 /************************************************************************
501 static INT
PSDRV_StartDocA( PSDRV_PDEVICE
*physDev
, const DOCINFOA
*doc
)
503 LPCSTR output
= "LPT1:";
505 HANDLE hprn
= INVALID_HANDLE_VALUE
;
506 PRINTER_INFO_5A
*pi5
= (PRINTER_INFO_5A
*)buf
;
509 if(physDev
->job
.id
) {
510 FIXME("hJob != 0. Now what?\n");
515 output
= doc
->lpszOutput
;
516 else if(physDev
->job
.output
)
517 output
= physDev
->job
.output
;
519 if(OpenPrinterA(physDev
->pi
->FriendlyName
, &hprn
, NULL
) &&
520 GetPrinterA(hprn
, 5, buf
, sizeof(buf
), &needed
)) {
521 output
= pi5
->pPortName
;
523 if(hprn
!= INVALID_HANDLE_VALUE
)
527 physDev
->job
.id
= create_job( output
);
528 if(!physDev
->job
.id
) {
529 WARN("OpenJob failed\n");
532 physDev
->job
.banding
= FALSE
;
533 physDev
->job
.OutOfPage
= TRUE
;
534 physDev
->job
.PageNo
= 0;
535 physDev
->job
.quiet
= FALSE
;
536 physDev
->job
.in_passthrough
= FALSE
;
537 physDev
->job
.had_passthrough_rect
= FALSE
;
538 if(doc
->lpszDocName
) {
539 physDev
->job
.DocName
= HeapAlloc(GetProcessHeap(), 0, strlen(doc
->lpszDocName
)+1);
540 strcpy(physDev
->job
.DocName
, doc
->lpszDocName
);
542 physDev
->job
.DocName
= NULL
;
544 return physDev
->job
.id
;
547 /************************************************************************
550 INT CDECL
PSDRV_StartDoc( PSDRV_PDEVICE
*physDev
, const DOCINFOW
*doc
)
554 LPSTR docname
= NULL
, output
= NULL
, datatype
= NULL
;
556 docA
.cbSize
= doc
->cbSize
;
557 if (doc
->lpszDocName
)
559 len
= WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDocName
, -1, NULL
, 0, NULL
, NULL
);
560 if ((docname
= HeapAlloc( GetProcessHeap(), 0, len
)))
561 WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDocName
, -1, docname
, len
, NULL
, NULL
);
565 len
= WideCharToMultiByte( CP_ACP
, 0, doc
->lpszOutput
, -1, NULL
, 0, NULL
, NULL
);
566 if ((output
= HeapAlloc( GetProcessHeap(), 0, len
)))
567 WideCharToMultiByte( CP_ACP
, 0, doc
->lpszOutput
, -1, output
, len
, NULL
, NULL
);
569 if (doc
->lpszDatatype
)
571 len
= WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDatatype
, -1, NULL
, 0, NULL
, NULL
);
572 if ((datatype
= HeapAlloc( GetProcessHeap(), 0, len
)))
573 WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDatatype
, -1, datatype
, len
, NULL
, NULL
);
575 docA
.lpszDocName
= docname
;
576 docA
.lpszOutput
= output
;
577 docA
.lpszDatatype
= datatype
;
578 docA
.fwType
= doc
->fwType
;
580 ret
= PSDRV_StartDocA(physDev
, &docA
);
582 HeapFree( GetProcessHeap(), 0, docname
);
583 HeapFree( GetProcessHeap(), 0, output
);
584 HeapFree( GetProcessHeap(), 0, datatype
);
589 /************************************************************************
592 INT CDECL
PSDRV_EndDoc( PSDRV_PDEVICE
*physDev
)
595 if(!physDev
->job
.id
) {
596 FIXME("hJob == 0. Now what?\n");
600 if(!physDev
->job
.OutOfPage
) {
601 WARN("Somebody forgot an EndPage\n");
602 PSDRV_EndPage( physDev
);
604 PSDRV_WriteFooter( physDev
);
606 ret
= close_job( physDev
->job
.id
);
608 HeapFree(GetProcessHeap(), 0, physDev
->job
.DocName
);
609 physDev
->job
.DocName
= NULL
;