2 * PostScript driver Escape function
4 * Copyright 1998 Huw D M Davies
8 #include "wine/winuser16.h"
10 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(psdrv);
17 INT PSDRV_Escape( DC *dc, INT nEscape, INT cbInput,
18 SEGPTR lpInData, SEGPTR lpOutData )
20 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
25 RECT16 *r = MapSL(lpOutData);
26 if(!physDev->job.banding) {
27 physDev->job.banding = TRUE;
30 r->right = dc->devCaps->horzRes;
31 r->bottom = dc->devCaps->vertRes;
32 TRACE("NEXTBAND returning %d,%d - %d,%d\n", r->left,
33 r->top, r->right, r->bottom );
40 TRACE("NEXTBAND rect to 0,0 - 0,0\n" );
41 physDev->job.banding = FALSE;
47 if(!physDev->job.hJob) {
48 FIXME("hJob == 0. Now what?\n");
52 if(!PSDRV_EndPage( dc ))
58 WARN("cbInput < 2 (=%d) for QUERYESCSUPPORT\n", cbInput);
61 UINT16 num = *(UINT16 *)MapSL(lpInData);
62 TRACE("QUERYESCSUPPORT for %d\n", num);
72 case GETPRINTINGOFFSET:
73 case GETSCALINGFACTOR:
84 case POSTSCRIPT_PASSTHROUGH:
93 TRACE("SETABORTPROC\n");
104 /* lpInData may not be 0 terminated so we must copy it */
106 name = HeapAlloc( GetProcessHeap(), 0, cbInput+1 );
107 memcpy(name, MapSL(lpInData), cbInput);
108 name[cbInput] = '\0';
110 doc.cbSize = sizeof(doc);
111 doc.lpszDocName = name;
112 doc.lpszOutput = doc.lpszDatatype = NULL;
115 ret = PSDRV_StartDoc(dc, &doc);
116 if(name) HeapFree( GetProcessHeap(), 0, name );
117 if(ret <= 0) return -1;
118 ret = PSDRV_StartPage(dc);
119 if(ret <= 0) return -1;
125 return PSDRV_EndDoc( dc );
127 case GETPHYSPAGESIZE:
129 PSDRV_PDEVICE *pdev = (PSDRV_PDEVICE *)(dc->physDev);
130 POINT16 *p = MapSL(lpOutData);
134 if ((pdev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) != 0 &&
135 pdev->Devmode->dmPublic.u1.s1.dmPaperSize != 0)
137 PAGESIZE *page = pdev->pi->ppd->PageSizes;
142 pdev->Devmode->dmPublic.u1.s1.dmPaperSize)
149 ERR("No entry for papersize %u in PPD file for '%s'\n",
150 pdev->Devmode->dmPublic.u1.s1.dmPaperSize,
151 pdev->pi->FriendlyName);
155 TRACE("Found '%s' for paper size %u\n", page->FullName,
156 pdev->Devmode->dmPublic.u1.s1.dmPaperSize);
158 p->x = page->PaperDimension->x * dc->devCaps->logPixelsX / 72;
159 p->y = page->PaperDimension->y * dc->devCaps->logPixelsY / 72;
161 TRACE("%fx%f PostScript points = %ix%i device units\n",
162 page->PaperDimension->x, page->PaperDimension->y,
166 /* These are in tenths of a millimeter */
168 if ((pdev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH) != 0 &&
169 pdev->Devmode->dmPublic.u1.s1.dmPaperWidth != 0)
171 p->x = (pdev->Devmode->dmPublic.u1.s1.dmPaperWidth *
172 dc->devCaps->logPixelsX) / 254;
173 TRACE("dmPaperWidth = %i device units\n", p->x);
176 if ((pdev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) != 0 &&
177 pdev->Devmode->dmPublic.u1.s1.dmPaperLength != 0)
179 p->y = (pdev->Devmode->dmPublic.u1.s1.dmPaperLength *
180 dc->devCaps->logPixelsY) / 254;
181 TRACE("dmPaperLength = %i device units\n", p->y);
184 if (p->x == 0 || p->y == 0)
186 ERR("Paper size not properly set for '%s'\n",
187 pdev->pi->FriendlyName);
191 if ((pdev->Devmode->dmPublic.dmFields & DM_ORIENTATION) != 0 &&
192 pdev->Devmode->dmPublic.u1.s1.dmOrientation ==
195 register INT16 temp = p->y;
203 case GETPRINTINGOFFSET:
205 POINT16 *p = MapSL(lpOutData);
208 TRACE("GETPRINTINGOFFSET: returning %dx%d\n", p->x, p->y);
212 case GETSCALINGFACTOR:
214 POINT16 *p = MapSL(lpOutData);
217 TRACE("GETSCALINGFACTOR: returning %dx%d\n", p->x, p->y);
223 INT16 *NumCopies = MapSL(lpInData);
224 INT16 *ActualCopies = MapSL(lpOutData);
226 WARN("cbInput != 2 (=%d) for SETCOPYCOUNT\n", cbInput);
229 TRACE("SETCOPYCOUNT %d\n", *NumCopies);
236 LPSTR p = MapSL(lpOutData);
237 strcpy(p, "PostScript");
238 *(p + strlen(p) + 1) = '\0'; /* 2 '\0's at end of string */
244 INT16 newCap = *(INT16 *)MapSL(lpInData);
246 WARN("cbInput != 2 (=%d) for SETLINECAP\n", cbInput);
249 TRACE("SETLINECAP %d\n", newCap);
255 INT16 newJoin = *(INT16 *)MapSL(lpInData);
257 WARN("cbInput != 2 (=%d) for SETLINEJOIN\n", cbInput);
260 TRACE("SETLINEJOIN %d\n", newJoin);
266 INT16 newLimit = *(INT16 *)MapSL(lpInData);
268 WARN("cbInput != 2 (=%d) for SETMITERLIMIT\n", cbInput);
271 TRACE("SETMITERLIMIT %d\n", newLimit);
276 /* Undocumented escape used by winword6.
277 Switches between ANSI and a special charset.
278 If *lpInData == 1 we require that
282 0x94 is quotedblright
286 0xa0 is non break space - yeah right.
288 If *lpInData == 0 we get ANSI.
289 Since there's nothing else there, let's just make these the default
290 anyway and see what happens...
294 case EXT_DEVICE_CAPS:
296 UINT16 cap = *(UINT16 *)MapSL(lpInData);
298 WARN("cbInput != 2 (=%d) for EXT_DEVICE_CAPS\n",
302 TRACE("EXT_DEVICE_CAPS %d\n", cap);
308 RECT16 *r = MapSL(lpInData);
310 WARN("cbInput != 8 (=%d) for SET_BOUNDS\n", cbInput);
313 TRACE("SET_BOUNDS (%d,%d) - (%d,%d)\n", r->left, r->top,
314 r->right, r->bottom);
320 UINT16 epsprint = *(UINT16*)MapSL(lpInData);
321 /* FIXME: In this mode we do not need to send page intros and page
322 * ends according to the doc. But I just ignore that detail
325 TRACE("EPS Printing support %sable.\n",epsprint?"en":"dis");
329 case POSTSCRIPT_PASSTHROUGH:
331 /* Write directly to spool file, bypassing normal PS driver
332 * processing that is done along with writing PostScript code
334 * (Usually we have a WORD before the data counting the size, but
335 * cbInput is just this +2.)
337 return WriteSpool16(physDev->job.hJob,((char*)lpInData)+2,cbInput-2);
340 case GETSETPRINTORIENT:
342 /* If lpInData is present, it is a 20 byte structure, first 32
343 * bit LONG value is the orientation. if lpInData is NULL, it
344 * returns the current orientation.
346 FIXME("GETSETPRINTORIENT not implemented (lpInData %ld)!\n",lpInData);
350 FIXME("Unimplemented code 0x%x\n", nEscape);
355 /************************************************************************
358 INT PSDRV_StartPage( DC *dc )
360 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
362 if(!physDev->job.OutOfPage) {
363 FIXME("Already started a page?\n");
366 physDev->job.PageNo++;
367 if(!PSDRV_WriteNewPage( dc ))
369 physDev->job.OutOfPage = FALSE;
374 /************************************************************************
377 INT PSDRV_EndPage( DC *dc )
379 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
381 if(physDev->job.OutOfPage) {
382 FIXME("Already ended a page?\n");
385 if(!PSDRV_WriteEndPage( dc ))
387 physDev->job.OutOfPage = TRUE;
392 /************************************************************************
395 INT PSDRV_StartDoc( DC *dc, const DOCINFOA *doc )
397 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
399 if(physDev->job.hJob) {
400 FIXME("hJob != 0. Now what?\n");
404 if(doc->lpszOutput) {
405 HeapFree( PSDRV_Heap, 0, physDev->job.output );
406 physDev->job.output = HEAP_strdupA( PSDRV_Heap, 0, doc->lpszOutput );
408 physDev->job.hJob = OpenJob16(physDev->job.output, doc->lpszDocName,
410 if(!physDev->job.hJob) {
411 WARN("OpenJob failed\n");
414 physDev->job.banding = FALSE;
415 physDev->job.OutOfPage = TRUE;
416 physDev->job.PageNo = 0;
417 if(!PSDRV_WriteHeader( dc, doc->lpszDocName ))
420 return physDev->job.hJob;
424 /************************************************************************
427 INT PSDRV_EndDoc( DC *dc )
429 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
431 if(!physDev->job.hJob) {
432 FIXME("hJob == 0. Now what?\n");
436 if(!physDev->job.OutOfPage) {
437 WARN("Somebody forgot a EndPage\n");
440 if(!PSDRV_WriteFooter( dc ))
443 if( CloseJob16( physDev->job.hJob ) == SP_ERROR ) {
444 WARN("CloseJob error\n");
447 physDev->job.hJob = 0;