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( PHYSDEV dev
, const void *data
, DWORD num
)
52 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
55 if (!WritePrinter(physDev
->job
.hprinter
, (LPBYTE
) data
, num
, &written
) || (written
!= num
))
61 /**********************************************************************
62 * ExtEscape (WINEPS.@)
64 INT
PSDRV_ExtEscape( PHYSDEV dev
, INT nEscape
, INT cbInput
, LPCVOID in_data
,
65 INT cbOutput
, LPVOID out_data
)
67 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
72 if(cbInput
< sizeof(INT
))
74 WARN("cbInput < sizeof(INT) (=%d) for QUERYESCSUPPORT\n", cbInput
);
77 UINT num
= *(const UINT
*)in_data
;
78 TRACE("QUERYESCSUPPORT for %d\n", num
);
94 case POSTSCRIPT_PASSTHROUGH
:
95 case POSTSCRIPT_IGNORE
:
99 /*case DRAWPATTERNRECT:*/
103 FIXME("QUERYESCSUPPORT(%d) - not supported.\n", num
);
110 FIXME("MFCOMMENT(%p, %d)\n", in_data
, cbInput
);
113 case DRAWPATTERNRECT
:
115 DRAWPATRECT
*dpr
= (DRAWPATRECT
*)in_data
;
117 FIXME("DRAWPATTERNRECT(pos (%d,%d), size %dx%d, style %d, pattern %x), stub!\n",
118 dpr
->ptPosition
.x
, dpr
->ptPosition
.y
,
119 dpr
->ptSize
.x
, dpr
->ptSize
.y
,
120 dpr
->wStyle
, dpr
->wPattern
126 BANDINFOSTRUCT
*ibi
= (BANDINFOSTRUCT
*)in_data
;
127 BANDINFOSTRUCT
*obi
= (BANDINFOSTRUCT
*)out_data
;
129 FIXME("BANDINFO(graphics %d, text %d, rect [%dx%d-%dx%d]), stub!\n",
132 ibi
->GraphicsRect
.top
,
133 ibi
->GraphicsRect
.bottom
,
134 ibi
->GraphicsRect
.left
,
135 ibi
->GraphicsRect
.right
143 if(!physDev
->job
.banding
) {
144 physDev
->job
.banding
= TRUE
;
147 r
->right
= physDev
->horzRes
;
148 r
->bottom
= physDev
->vertRes
;
149 TRACE("NEXTBAND returning %d,%d - %d,%d\n", r
->left
, r
->top
, r
->right
, r
->bottom
);
156 TRACE("NEXTBAND rect to 0,0 - 0,0\n" );
157 physDev
->job
.banding
= FALSE
;
158 return EndPage( dev
->hdc
);
163 const INT
*NumCopies
= in_data
;
164 INT
*ActualCopies
= out_data
;
165 if(cbInput
!= sizeof(INT
)) {
166 WARN("cbInput != sizeof(INT) (=%d) for SETCOPYCOUNT\n", cbInput
);
169 TRACE("SETCOPYCOUNT %d\n", *NumCopies
);
177 strcpy(p
, "PostScript");
178 *(p
+ strlen(p
) + 1) = '\0'; /* 2 '\0's at end of string */
184 INT newCap
= *(const INT
*)in_data
;
185 if(cbInput
!= sizeof(INT
)) {
186 WARN("cbInput != sizeof(INT) (=%d) for SETLINECAP\n", cbInput
);
189 TRACE("SETLINECAP %d\n", newCap
);
195 INT newJoin
= *(const INT
*)in_data
;
196 if(cbInput
!= sizeof(INT
)) {
197 WARN("cbInput != sizeof(INT) (=%d) for SETLINEJOIN\n", cbInput
);
200 TRACE("SETLINEJOIN %d\n", newJoin
);
206 INT newLimit
= *(const INT
*)in_data
;
207 if(cbInput
!= sizeof(INT
)) {
208 WARN("cbInput != sizeof(INT) (=%d) for SETMITERLIMIT\n", cbInput
);
211 TRACE("SETMITERLIMIT %d\n", newLimit
);
216 /* Undocumented escape used by winword6.
217 Switches between ANSI and a special charset.
218 If *lpInData == 1 we require that
222 0x94 is quotedblright
226 0xa0 is non break space - yeah right.
228 If *lpInData == 0 we get ANSI.
229 Since there's nothing else there, let's just make these the default
230 anyway and see what happens...
234 case EXT_DEVICE_CAPS
:
236 UINT cap
= *(const UINT
*)in_data
;
237 if(cbInput
!= sizeof(UINT
)) {
238 WARN("cbInput != sizeof(UINT) (=%d) for EXT_DEVICE_CAPS\n", cbInput
);
241 TRACE("EXT_DEVICE_CAPS %d\n", cap
);
247 const RECT
*r
= in_data
;
248 if(cbInput
!= sizeof(RECT
)) {
249 WARN("cbInput != sizeof(RECT) (=%d) for SET_BOUNDS\n", cbInput
);
252 TRACE("SET_BOUNDS (%d,%d) - (%d,%d)\n", r
->left
, r
->top
,
253 r
->right
, r
->bottom
);
259 UINT epsprint
= *(const UINT
*)in_data
;
260 /* FIXME: In this mode we do not need to send page intros and page
261 * ends according to the doc. But I just ignore that detail
264 TRACE("EPS Printing support %sable.\n",epsprint
?"en":"dis");
268 case POSTSCRIPT_DATA
:
270 case POSTSCRIPT_PASSTHROUGH
:
272 /* Write directly to spool file, bypassing normal PS driver
273 * processing that is done along with writing PostScript code
275 * We have a WORD before the data counting the size, but
276 * cbInput is just this +2.
277 * However Photoshop 7 has a bug that sets cbInput to 2 less than the
278 * length of the string, rather than 2 more. So we'll use the WORD at
279 * in_data[0] instead.
281 if(!physDev
->job
.in_passthrough
) {
282 write_spool(dev
, psbegindocument
, sizeof(psbegindocument
)-1);
283 physDev
->job
.in_passthrough
= TRUE
;
285 return write_spool(dev
,((char*)in_data
)+2,*(const WORD
*)in_data
);
288 case POSTSCRIPT_IGNORE
:
290 BOOL ret
= physDev
->job
.quiet
;
291 TRACE("POSTSCRIPT_IGNORE %d\n", *(const short*)in_data
);
292 physDev
->job
.quiet
= *(const short*)in_data
;
296 case GETSETPRINTORIENT
:
298 /* If lpInData is present, it is a 20 byte structure, first 32
299 * bit LONG value is the orientation. if lpInData is NULL, it
300 * returns the current orientation.
302 FIXME("GETSETPRINTORIENT not implemented (data %p)!\n",in_data
);
306 TRACE("BEGIN_PATH\n");
307 if(physDev
->pathdepth
)
308 FIXME("Nested paths not yet handled\n");
309 return ++physDev
->pathdepth
;
313 const struct PATH_INFO
*info
= (const struct PATH_INFO
*)in_data
;
316 if(!physDev
->pathdepth
) {
317 ERR("END_PATH called without a BEGIN_PATH\n");
320 TRACE("RenderMode = %d, FillMode = %d, BkMode = %d\n",
321 info
->RenderMode
, info
->FillMode
, info
->BkMode
);
322 switch(info
->RenderMode
) {
323 case RENDERMODE_NO_DISPLAY
:
324 PSDRV_WriteClosePath(dev
); /* not sure if this is necessary, but it can't hurt */
326 case RENDERMODE_OPEN
:
327 case RENDERMODE_CLOSED
:
329 FIXME("END_PATH: RenderMode %d, not yet supported\n", info
->RenderMode
);
332 return --physDev
->pathdepth
;
337 WORD mode
= *(const WORD
*)in_data
;
341 TRACE("CLIP_TO_PATH: CLIP_SAVE\n");
342 PSDRV_WriteGSave(dev
);
345 TRACE("CLIP_TO_PATH: CLIP_RESTORE\n");
346 PSDRV_WriteGRestore(dev
);
349 TRACE("CLIP_TO_PATH: CLIP_INCLUSIVE\n");
350 /* FIXME to clip or eoclip ? (see PATH_INFO.FillMode) */
351 PSDRV_WriteClip(dev
);
352 PSDRV_WriteNewPath(dev
);
355 FIXME("CLIP_EXCLUSIVE: not implemented\n");
358 FIXME("Unknown CLIP_TO_PATH mode %d\n", mode
);
363 FIXME("Unimplemented code %d\n", nEscape
);
368 /************************************************************************
371 INT
PSDRV_StartPage( PHYSDEV dev
)
373 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
375 if(!physDev
->job
.OutOfPage
) {
376 FIXME("Already started a page?\n");
380 if(physDev
->job
.PageNo
++ == 0) {
381 if(!PSDRV_WriteHeader( dev
, physDev
->job
.DocName
))
385 if(!PSDRV_WriteNewPage( dev
))
387 physDev
->job
.OutOfPage
= FALSE
;
392 /************************************************************************
395 INT
PSDRV_EndPage( PHYSDEV dev
)
397 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
399 if(physDev
->job
.OutOfPage
) {
400 FIXME("Already ended a page?\n");
403 if(!PSDRV_WriteEndPage( dev
))
405 PSDRV_EmptyDownloadList(dev
, FALSE
);
406 physDev
->job
.OutOfPage
= TRUE
;
411 /************************************************************************
414 static INT
PSDRV_StartDocA( PHYSDEV dev
, const DOCINFOA
*doc
)
416 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
419 TRACE("(%p, %p) => %s, %s, %s\n", physDev
, doc
, debugstr_a(doc
->lpszDocName
),
420 debugstr_a(doc
->lpszOutput
), debugstr_a(doc
->lpszDatatype
));
422 if(physDev
->job
.id
) {
423 FIXME("hJob != 0. Now what?\n");
427 /* FIXME: use PRINTER_DEFAULTS here */
428 if(!OpenPrinterA(physDev
->pi
->FriendlyName
, &physDev
->job
.hprinter
, NULL
)) {
429 WARN("OpenPrinter(%s, ...) failed: %d\n",
430 debugstr_a(physDev
->pi
->FriendlyName
), GetLastError());
434 di
.pDocName
= (LPSTR
) doc
->lpszDocName
;
438 di
.pOutputFile
= (LPSTR
) doc
->lpszOutput
;
439 else if(physDev
->job
.output
)
440 di
.pOutputFile
= physDev
->job
.output
;
442 di
.pOutputFile
= NULL
;
444 TRACE("using output: %s\n", debugstr_a(di
.pOutputFile
));
446 /* redirection located in HKCU\Software\Wine\Printing\Spooler
447 is done during winspool.drv,ScheduleJob */
448 physDev
->job
.id
= StartDocPrinterA(physDev
->job
.hprinter
, 1, (LPBYTE
) &di
);
449 if(!physDev
->job
.id
) {
450 WARN("StartDocPrinter() failed: %d\n", GetLastError());
451 ClosePrinter(physDev
->job
.hprinter
);
454 physDev
->job
.banding
= FALSE
;
455 physDev
->job
.OutOfPage
= TRUE
;
456 physDev
->job
.PageNo
= 0;
457 physDev
->job
.quiet
= FALSE
;
458 physDev
->job
.in_passthrough
= FALSE
;
459 physDev
->job
.had_passthrough_rect
= FALSE
;
460 if(doc
->lpszDocName
) {
461 physDev
->job
.DocName
= HeapAlloc(GetProcessHeap(), 0, strlen(doc
->lpszDocName
)+1);
462 strcpy(physDev
->job
.DocName
, doc
->lpszDocName
);
464 physDev
->job
.DocName
= NULL
;
466 return physDev
->job
.id
;
469 /************************************************************************
472 INT
PSDRV_StartDoc( PHYSDEV dev
, const DOCINFOW
*doc
)
476 LPSTR docname
= NULL
, output
= NULL
, datatype
= NULL
;
478 TRACE("(%p, %p) => %d,%s,%s,%s\n", dev
, doc
, doc
->cbSize
, debugstr_w(doc
->lpszDocName
),
479 debugstr_w(doc
->lpszOutput
), debugstr_w(doc
->lpszDatatype
));
481 docA
.cbSize
= doc
->cbSize
;
482 if (doc
->lpszDocName
)
484 len
= WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDocName
, -1, NULL
, 0, NULL
, NULL
);
485 if ((docname
= HeapAlloc( GetProcessHeap(), 0, len
)))
486 WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDocName
, -1, docname
, len
, NULL
, NULL
);
490 len
= WideCharToMultiByte( CP_ACP
, 0, doc
->lpszOutput
, -1, NULL
, 0, NULL
, NULL
);
491 if ((output
= HeapAlloc( GetProcessHeap(), 0, len
)))
492 WideCharToMultiByte( CP_ACP
, 0, doc
->lpszOutput
, -1, output
, len
, NULL
, NULL
);
494 if (doc
->lpszDatatype
)
496 len
= WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDatatype
, -1, NULL
, 0, NULL
, NULL
);
497 if ((datatype
= HeapAlloc( GetProcessHeap(), 0, len
)))
498 WideCharToMultiByte( CP_ACP
, 0, doc
->lpszDatatype
, -1, datatype
, len
, NULL
, NULL
);
500 docA
.lpszDocName
= docname
;
501 docA
.lpszOutput
= output
;
502 docA
.lpszDatatype
= datatype
;
503 docA
.fwType
= doc
->fwType
;
505 ret
= PSDRV_StartDocA(dev
, &docA
);
507 HeapFree( GetProcessHeap(), 0, docname
);
508 HeapFree( GetProcessHeap(), 0, output
);
509 HeapFree( GetProcessHeap(), 0, datatype
);
514 /************************************************************************
517 INT
PSDRV_EndDoc( PHYSDEV dev
)
519 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
522 if(!physDev
->job
.id
) {
523 FIXME("hJob == 0. Now what?\n");
527 if(!physDev
->job
.OutOfPage
) {
528 WARN("Somebody forgot an EndPage\n");
529 PSDRV_EndPage( dev
);
532 if (physDev
->job
.PageNo
)
533 PSDRV_WriteFooter( dev
);
535 ret
= EndDocPrinter(physDev
->job
.hprinter
);
536 ClosePrinter(physDev
->job
.hprinter
);
537 physDev
->job
.hprinter
= NULL
;
539 HeapFree(GetProcessHeap(), 0, physDev
->job
.DocName
);
540 physDev
->job
.DocName
= NULL
;