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
32 #include "wine/wingdi16.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
41 DWORD
write_spool( PHYSDEV dev
, const void *data
, DWORD num
)
43 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
46 if (!WritePrinter(physDev
->job
.hprinter
, (LPBYTE
) data
, num
, &written
) || (written
!= num
))
52 /**********************************************************************
53 * ExtEscape (WINEPS.@)
55 INT CDECL
PSDRV_ExtEscape( PHYSDEV dev
, INT nEscape
, INT cbInput
, LPCVOID in_data
,
56 INT cbOutput
, LPVOID out_data
)
58 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
60 TRACE("%p,%d,%d,%p,%d,%p\n",
61 dev
->hdc
, nEscape
, cbInput
, in_data
, cbOutput
, out_data
);
66 if(cbInput
< sizeof(SHORT
))
68 WARN("cbInput < sizeof(SHORT) (=%d) for QUERYESCSUPPORT\n", cbInput
);
71 DWORD num
= (cbInput
< sizeof(DWORD
)) ? *(const USHORT
*)in_data
: *(const DWORD
*)in_data
;
72 TRACE("QUERYESCSUPPORT for %d\n", num
);
88 case POSTSCRIPT_PASSTHROUGH
:
89 case POSTSCRIPT_IGNORE
:
93 /*case DRAWPATTERNRECT:*/
95 /* PageMaker checks for it */
98 /* PageMaker doesn't check for DOWNLOADFACE and GETFACENAME but
99 * uses them, they are supposed to be supported by any PS printer.
103 /* PageMaker checks for these as a part of process of detecting
104 * a "fully compatible" PS printer, but doesn't actually use them.
110 /* Windows PS driver reports 0, but still supports this escape */
112 return FALSE
; /* suppress the FIXME below */
115 FIXME("QUERYESCSUPPORT(%d) - not supported.\n", num
);
121 FIXME("OPENCHANNEL: stub\n");
125 FIXME("CLOSECHANNEL: stub\n");
129 FIXME("DOWNLOADHEADER: stub\n");
130 /* should return name of the downloaded procset */
131 *(char *)out_data
= 0;
135 FIXME("GETFACENAME: stub\n");
136 lstrcpynA(out_data
, "Courier", cbOutput
);
140 FIXME("DOWNLOADFACE: stub\n");
145 FIXME("MFCOMMENT(%p, %d)\n", in_data
, cbInput
);
148 case DRAWPATTERNRECT
:
150 DRAWPATRECT
*dpr
= (DRAWPATRECT
*)in_data
;
152 FIXME("DRAWPATTERNRECT(pos (%d,%d), size %dx%d, style %d, pattern %x), stub!\n",
153 dpr
->ptPosition
.x
, dpr
->ptPosition
.y
,
154 dpr
->ptSize
.x
, dpr
->ptSize
.y
,
155 dpr
->wStyle
, dpr
->wPattern
161 BANDINFOSTRUCT
*ibi
= (BANDINFOSTRUCT
*)in_data
;
162 BANDINFOSTRUCT
*obi
= (BANDINFOSTRUCT
*)out_data
;
164 FIXME("BANDINFO(graphics %d, text %d, rect %s), stub!\n", ibi
->GraphicsFlag
,
165 ibi
->TextFlag
, wine_dbgstr_rect(&ibi
->GraphicsRect
));
172 if(!physDev
->job
.banding
) {
173 physDev
->job
.banding
= TRUE
;
174 SetRect(r
, 0, 0, physDev
->horzRes
, physDev
->vertRes
);
175 TRACE("NEXTBAND returning %s\n", wine_dbgstr_rect(r
));
179 TRACE("NEXTBAND rect to 0,0 - 0,0\n" );
180 physDev
->job
.banding
= FALSE
;
181 return EndPage( dev
->hdc
);
186 const INT
*NumCopies
= in_data
;
187 INT
*ActualCopies
= out_data
;
188 if(cbInput
!= sizeof(INT
)) {
189 WARN("cbInput != sizeof(INT) (=%d) for SETCOPYCOUNT\n", cbInput
);
192 TRACE("SETCOPYCOUNT %d\n", *NumCopies
);
200 strcpy(p
, "PostScript");
201 *(p
+ strlen(p
) + 1) = '\0'; /* 2 '\0's at end of string */
207 INT newCap
= *(const INT
*)in_data
;
208 if(cbInput
!= sizeof(INT
)) {
209 WARN("cbInput != sizeof(INT) (=%d) for SETLINECAP\n", cbInput
);
212 TRACE("SETLINECAP %d\n", newCap
);
218 INT newJoin
= *(const INT
*)in_data
;
219 if(cbInput
!= sizeof(INT
)) {
220 WARN("cbInput != sizeof(INT) (=%d) for SETLINEJOIN\n", cbInput
);
223 TRACE("SETLINEJOIN %d\n", newJoin
);
229 INT newLimit
= *(const INT
*)in_data
;
230 if(cbInput
!= sizeof(INT
)) {
231 WARN("cbInput != sizeof(INT) (=%d) for SETMITERLIMIT\n", cbInput
);
234 TRACE("SETMITERLIMIT %d\n", newLimit
);
239 /* Undocumented escape used by winword6.
240 Switches between ANSI and a special charset.
241 If *lpInData == 1 we require that
245 0x94 is quotedblright
249 0xa0 is non break space - yeah right.
251 If *lpInData == 0 we get ANSI.
252 Since there's nothing else there, let's just make these the default
253 anyway and see what happens...
257 case EXT_DEVICE_CAPS
:
259 UINT cap
= *(const UINT
*)in_data
;
260 if(cbInput
!= sizeof(UINT
)) {
261 WARN("cbInput != sizeof(UINT) (=%d) for EXT_DEVICE_CAPS\n", cbInput
);
264 TRACE("EXT_DEVICE_CAPS %d\n", cap
);
270 const RECT
*r
= in_data
;
271 if(cbInput
!= sizeof(RECT
)) {
272 WARN("cbInput != sizeof(RECT) (=%d) for SET_BOUNDS\n", cbInput
);
275 TRACE("SET_BOUNDS %s\n", wine_dbgstr_rect(r
));
281 UINT epsprint
= *(const UINT
*)in_data
;
282 /* FIXME: In this mode we do not need to send page intros and page
283 * ends according to the doc. But I just ignore that detail
286 TRACE("EPS Printing support %sable.\n",epsprint
?"en":"dis");
290 case POSTSCRIPT_DATA
:
292 case POSTSCRIPT_PASSTHROUGH
:
294 /* Write directly to spool file, bypassing normal PS driver
295 * processing that is done along with writing PostScript code
297 * We have a WORD before the data counting the size, but
298 * cbInput is just this +2.
299 * However Photoshop 7 has a bug that sets cbInput to 2 less than the
300 * length of the string, rather than 2 more. So we'll use the WORD at
301 * in_data[0] instead.
303 passthrough_enter(dev
);
304 return write_spool(dev
, ((char*)in_data
) + 2, *(const WORD
*)in_data
);
307 case POSTSCRIPT_IGNORE
:
309 BOOL ret
= physDev
->job
.quiet
;
310 TRACE("POSTSCRIPT_IGNORE %d\n", *(const short*)in_data
);
311 physDev
->job
.quiet
= *(const short*)in_data
;
315 case GETSETPRINTORIENT
:
317 /* If lpInData is present, it is a 20 byte structure, first 32
318 * bit LONG value is the orientation. if lpInData is NULL, it
319 * returns the current orientation.
321 FIXME("GETSETPRINTORIENT not implemented (data %p)!\n",in_data
);
325 TRACE("BEGIN_PATH\n");
326 if(physDev
->pathdepth
)
327 FIXME("Nested paths not yet handled\n");
328 return ++physDev
->pathdepth
;
332 const struct PATH_INFO
*info
= (const struct PATH_INFO
*)in_data
;
335 if(!physDev
->pathdepth
) {
336 ERR("END_PATH called without a BEGIN_PATH\n");
339 TRACE("RenderMode = %d, FillMode = %d, BkMode = %d\n",
340 info
->RenderMode
, info
->FillMode
, info
->BkMode
);
341 switch(info
->RenderMode
) {
342 case RENDERMODE_NO_DISPLAY
:
343 PSDRV_WriteClosePath(dev
); /* not sure if this is necessary, but it can't hurt */
345 case RENDERMODE_OPEN
:
346 case RENDERMODE_CLOSED
:
348 FIXME("END_PATH: RenderMode %d, not yet supported\n", info
->RenderMode
);
351 return --physDev
->pathdepth
;
356 WORD mode
= *(const WORD
*)in_data
;
360 TRACE("CLIP_TO_PATH: CLIP_SAVE\n");
361 PSDRV_WriteGSave(dev
);
364 TRACE("CLIP_TO_PATH: CLIP_RESTORE\n");
365 PSDRV_WriteGRestore(dev
);
368 TRACE("CLIP_TO_PATH: CLIP_INCLUSIVE\n");
369 /* FIXME to clip or eoclip ? (see PATH_INFO.FillMode) */
370 PSDRV_WriteClip(dev
);
371 PSDRV_WriteNewPath(dev
);
374 FIXME("CLIP_EXCLUSIVE: not implemented\n");
377 FIXME("Unknown CLIP_TO_PATH mode %d\n", mode
);
382 FIXME("Unimplemented code %d\n", nEscape
);
387 /************************************************************************
390 INT CDECL
PSDRV_StartPage( PHYSDEV dev
)
392 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
394 TRACE("%p\n", dev
->hdc
);
396 if(!physDev
->job
.OutOfPage
) {
397 FIXME("Already started a page?\n");
401 physDev
->job
.PageNo
++;
403 if(!PSDRV_WriteNewPage( dev
))
405 physDev
->job
.OutOfPage
= FALSE
;
410 /************************************************************************
413 INT CDECL
PSDRV_EndPage( PHYSDEV dev
)
415 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
417 TRACE("%p\n", dev
->hdc
);
419 if(physDev
->job
.OutOfPage
) {
420 FIXME("Already ended a page?\n");
424 passthrough_leave(dev
);
425 if(!PSDRV_WriteEndPage( dev
))
427 PSDRV_EmptyDownloadList(dev
, FALSE
);
428 physDev
->job
.OutOfPage
= TRUE
;
433 /************************************************************************
436 INT CDECL
PSDRV_StartDoc( PHYSDEV dev
, const DOCINFOW
*doc
)
438 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
440 PRINTER_DEFAULTSW prn_def
;
442 TRACE("(%p, %p) => %s, %s, %s\n", physDev
, doc
, debugstr_w(doc
->lpszDocName
),
443 debugstr_w(doc
->lpszOutput
), debugstr_w(doc
->lpszDatatype
));
445 if(physDev
->job
.id
) {
446 FIXME("hJob != 0. Now what?\n");
450 prn_def
.pDatatype
= NULL
;
451 prn_def
.pDevMode
= &physDev
->pi
->Devmode
->dmPublic
;
452 prn_def
.DesiredAccess
= PRINTER_ACCESS_USE
;
454 if (!OpenPrinterW( physDev
->pi
->friendly_name
, &physDev
->job
.hprinter
, &prn_def
))
456 WARN("OpenPrinter(%s, ...) failed: %d\n",
457 debugstr_w(physDev
->pi
->friendly_name
), GetLastError());
461 di
.pDocName
= (LPWSTR
) doc
->lpszDocName
;
465 di
.pOutputFile
= (LPWSTR
) doc
->lpszOutput
;
466 else if(physDev
->job
.output
)
467 di
.pOutputFile
= physDev
->job
.output
;
469 di
.pOutputFile
= NULL
;
471 TRACE("using output: %s\n", debugstr_w(di
.pOutputFile
));
473 /* redirection located in HKCU\Software\Wine\Printing\Spooler
474 is done during winspool.drv,ScheduleJob */
475 physDev
->job
.id
= StartDocPrinterW(physDev
->job
.hprinter
, 1, (LPBYTE
) &di
);
476 if(!physDev
->job
.id
) {
477 WARN("StartDocPrinter() failed: %d\n", GetLastError());
478 ClosePrinter(physDev
->job
.hprinter
);
482 if (!PSDRV_WriteHeader( dev
, doc
->lpszDocName
)) {
483 WARN("Failed to write header\n");
484 ClosePrinter(physDev
->job
.hprinter
);
488 physDev
->job
.banding
= FALSE
;
489 physDev
->job
.OutOfPage
= TRUE
;
490 physDev
->job
.PageNo
= 0;
491 physDev
->job
.quiet
= FALSE
;
492 physDev
->job
.passthrough_state
= passthrough_none
;
493 physDev
->job
.doc_name
= strdupW( doc
->lpszDocName
);
495 return physDev
->job
.id
;
498 /************************************************************************
501 INT CDECL
PSDRV_EndDoc( PHYSDEV dev
)
503 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
506 TRACE("%p\n", dev
->hdc
);
508 if(!physDev
->job
.id
) {
509 FIXME("hJob == 0. Now what?\n");
513 if(!physDev
->job
.OutOfPage
) {
514 WARN("Somebody forgot an EndPage\n");
515 PSDRV_EndPage( dev
);
518 if (physDev
->job
.PageNo
)
519 PSDRV_WriteFooter( dev
);
521 ret
= EndDocPrinter(physDev
->job
.hprinter
);
522 ClosePrinter(physDev
->job
.hprinter
);
523 physDev
->job
.hprinter
= NULL
;
525 HeapFree( GetProcessHeap(), 0, physDev
->job
.doc_name
);
526 physDev
->job
.doc_name
= NULL
;