source: trunk/src/gdi32/printer.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 12.6 KB
Line 
1/* $Id: printer.cpp,v 1.14 2004/05/04 13:49:24 sandervl Exp $ */
2
3/*
4 * GDI32 printer apis
5 *
6 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 2002-2003 InnoTek Systemberatung GmbH (sandervl@innotek.de)
8 *
9 * Parts based on Wine code (StartDocW)
10 *
11 * Copyright 1996 John Harvey
12 * Copyright 1998 Huw Davies
13 * Copyright 1998 Andreas Mohr
14 * Copyright 1999 Klaas van Gend
15 *
16 * Project Odin Software License can be found in LICENSE.TXT
17 *
18 */
19#include <os2win.h>
20#include <stdarg.h>
21#include <stdio.h>
22#include <string.h>
23#include <dcdata.h>
24#include <dbglog.h>
25#include <heapstring.h>
26#include "oslibgpi.h"
27
28#define DBG_LOCALLOG DBG_printer
29#include "dbglocal.h"
30
31// Private WGSS escape extensions
32#define PRIVATE_QUERYORIENTATION 0x99990001
33#define PRIVATE_QUERYCOPIES 0x99990002
34#define PRIVATE_QUERYCOLLATE 0x99990003
35
36static char *lpszPassThrough = NULL;
37static int cbPassThrough = 0;
38
39//NOTE: We need to insert this postscript statement into the stream or else
40// the output will be completely inverted (x & y)
41static char szSetupStringPortrait[] = "%%BeginSetup\n[{\n%%BeginColorModelSetup\n<< /ProcessColorModel /DeviceCMYK >> setpagedevice\n%%EndColorModelSetup\n} stopped cleartomark\n%%EndSetup\n";
42static char szSetupStringLandscape[] = "%%BeginSetup\n[{\n%%BeginColorModelSetup\n<< /ProcessColorModel /DeviceCMYK >> setpagedevice\n%%EndColorModelSetup\n} stopped cleartomark\n-90 rotate\n%%EndSetup\n";
43
44
45static BOOL fPostscriptPassthrough = TRUE;
46
47//******************************************************************************
48//******************************************************************************
49BOOL WIN32API ODIN_QueryPostscriptPassthrough()
50{
51 return fPostscriptPassthrough;
52}
53//******************************************************************************
54//******************************************************************************
55void WIN32API ODIN_SetPostscriptPassthrough(BOOL fEnabled)
56{
57 fPostscriptPassthrough = fEnabled;
58}
59//******************************************************************************
60//******************************************************************************
61int WIN32API Escape( HDC hdc, int nEscape, int cbInput, LPCSTR lpvInData, PVOID lpvOutData)
62{
63 int rc;
64 const char *lpszEscape = NULL;
65
66 switch(nEscape)
67 {
68 case SET_BOUNDS:
69 {
70 RECT *r = (RECT *)lpvInData;
71 if(cbInput != sizeof(RECT)) {
72 dprintf(("WARNING: cbInput != sizeof(RECT) (=%d) for SET_BOUNDS", cbInput));
73 return 0;
74 }
75 dprintf(("SET_BOUNDS (%d,%d) (%d,%d)", r->left, r->top, r->right, r->bottom));
76 return 0;
77 }
78 case POSTSCRIPT_PASSTHROUGH:
79 if(!lpszEscape) lpszEscape = "POSTSCRIPT_PASSTHROUGH";
80 nEscape = PASSTHROUGH;
81 case POSTSCRIPT_DATA:
82 if(!lpszEscape) lpszEscape = "POSTSCRIPT_DATA";
83 case PASSTHROUGH:
84 {
85 if(!lpszEscape) lpszEscape = "PASSTHROUGH";
86 dprintf(("Postscript %s data of size %d", lpszEscape, *(WORD *)lpvInData));
87
88 if(fPostscriptPassthrough == FALSE)
89 {
90 return 0;
91 }
92 if(lpszPassThrough) {
93 O32_Escape(hdc, nEscape, cbPassThrough, lpszPassThrough, NULL);
94 free(lpszPassThrough);
95 lpszPassThrough = NULL;
96 }
97 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
98 if(pHps && (pHps->Reserved & DC_FLAG_SEND_POSTSCRIPT_SETUP_STRING))
99 {
100 DWORD dmOrientation = 0, hdrsize, dmCollate, dmCopies;
101 char *pvSetupData = NULL;
102
103 O32_Escape(hdc, PRIVATE_QUERYORIENTATION, 0, NULL, &dmOrientation);
104 if(dmOrientation == DMORIENT_LANDSCAPE) {
105 hdrsize = sizeof(szSetupStringLandscape)-1;
106 pvSetupData = (char *)alloca(hdrsize+sizeof(WORD));
107 }
108 else {//portrait
109 hdrsize = sizeof(szSetupStringPortrait)-1;
110 pvSetupData = (char *)alloca(hdrsize+sizeof(WORD));
111 }
112 if(pvSetupData) {
113 *(WORD *)pvSetupData = hdrsize;
114 memcpy(pvSetupData+sizeof(WORD), (hdrsize == sizeof(szSetupStringPortrait)-1) ? szSetupStringPortrait : szSetupStringLandscape, hdrsize);
115
116 O32_Escape(hdc, nEscape, *(WORD *)pvSetupData, pvSetupData, NULL);
117
118 dprintf(("Send Postscript setup string %d (%x):\n%s", dmOrientation, pHps->Reserved, pvSetupData+sizeof(WORD)));
119 }
120 pHps->Reserved &= ~DC_FLAG_SEND_POSTSCRIPT_SETUP_STRING;
121 }
122
123 rc = O32_Escape(hdc, nEscape, cbInput, lpvInData, lpvOutData);
124 if(rc == 1) rc = *(WORD *)lpvInData;
125 else rc = 0;
126 return rc;
127 }
128
129 case PRIVATE_QUERYORIENTATION:
130 DebugInt3();
131 return 0;
132
133 case SPCLPASSTHROUGH2:
134 {
135 int rawsize = *(WORD *)(lpvInData+4);
136
137 dprintf(("SPCLPASSTHROUGH2: pretend success"));
138 dprintf(("SPCLPASSTHROUGH2: virt mem %x size %x", *(DWORD *)lpvInData, rawsize));
139 if(lpszPassThrough == NULL) {
140 lpszPassThrough = (char *)malloc(rawsize+sizeof(WORD));
141 if(lpszPassThrough == NULL) {
142 DebugInt3();
143 return 0;
144 }
145 memcpy(lpszPassThrough+sizeof(WORD), (char *)lpvInData+6, rawsize);
146 cbPassThrough = rawsize;
147 *(WORD *)lpszPassThrough = (WORD)cbPassThrough;
148 }
149 else {
150 char *tmp = lpszPassThrough;
151
152 lpszPassThrough = (char *)malloc(cbPassThrough+rawsize+sizeof(WORD));
153 if(lpszPassThrough == NULL) {
154 DebugInt3();
155 return 0;
156 }
157 memcpy(lpszPassThrough+sizeof(WORD), tmp+sizeof(WORD), cbPassThrough);
158 free(tmp);
159 memcpy(lpszPassThrough+sizeof(WORD)+cbPassThrough, (char *)lpvInData+6, rawsize);
160 cbPassThrough += rawsize;
161 *(WORD *)lpszPassThrough = (WORD)cbPassThrough;
162 }
163 return 1;
164 }
165
166 case DOWNLOADFACE:
167 dprintf(("DOWNLOADFACE: pretend success"));
168 return 1;
169
170 case POSTSCRIPT_IGNORE:
171 {
172 BOOL ret = FALSE;
173 dprintf(("POSTSCRIPT_IGNORE %d", *(WORD *)lpvInData));
174 return ret;
175 }
176 case EPSPRINTING:
177 {
178 UINT epsprint = *(UINT*)lpvInData;
179 dprintf(("EPSPRINTING support %sable.\n",epsprint?"en":"dis"));
180 return 1;
181 }
182
183 case QUERYESCSUPPORT:
184 {
185 DWORD nEscapeSup = *(DWORD *)lpvInData;
186 BOOL fdprintf = FALSE;
187
188 switch(nEscapeSup) {
189 case SET_BOUNDS:
190 if(!fdprintf) dprintf(("QUERYESCSUPPORT: SET_BOUNDS"));
191 fdprintf = TRUE;
192/* case SPCLPASSTHROUGH2:
193 if(!fdprintf) dprintf(("QUERYESCSUPPORT: SPCLPASSTHROUGH2"));
194 fdprintf = TRUE;
195 case DOWNLOADHEADER:
196 if(!fdprintf) dprintf(("QUERYESCSUPPORT: DOWNLOADHEADER"));
197 fdprintf = TRUE;
198 case DOWNLOADFACE:
199 if(!fdprintf) dprintf(("QUERYESCSUPPORT: DOWNLOADFACE"));
200 fdprintf = TRUE;
201*/
202 case POSTSCRIPT_IGNORE:
203 if(!fdprintf) dprintf(("QUERYESCSUPPORT: POSTSCRIPT_IGNORE"));
204 fdprintf = TRUE;
205 case EPSPRINTING:
206 {
207 if(!fdprintf) dprintf(("QUERYESCSUPPORT: EPSPRINTING"));
208 fdprintf = TRUE;
209
210 nEscapeSup = POSTSCRIPT_PASSTHROUGH;
211 return Escape(hdc, QUERYESCSUPPORT, sizeof(nEscapeSup), (LPCSTR)&nEscapeSup, NULL);
212 }
213 case POSTSCRIPT_PASSTHROUGH:
214 case POSTSCRIPT_DATA:
215 case PASSTHROUGH:
216 if(fPostscriptPassthrough == FALSE)
217 {
218 return 0;
219 }
220 break;
221
222 default:
223 break;
224 }
225 }
226 default:
227 if(cbInput && lpvInData) {
228 ULONG *tmp = (ULONG *)lpvInData;
229 for(int i=0;i<min(16,cbInput/4);i++) {
230 dprintf(("GDI32: Escape par %d: %x", i, *tmp++));
231 }
232 }
233 break;
234 }
235
236 rc = O32_Escape(hdc, nEscape, cbInput, lpvInData, lpvOutData);
237 if(rc == 0) {
238 dprintf(("GDI32: Escape %x %d %d %x %x returned %d (WARNING: might not be implemented!!) ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
239 }
240 else dprintf(("GDI32: Escape %x %d %d %x %x returned %d ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
241
242 return rc;
243}
244//******************************************************************************
245//******************************************************************************
246INT WIN32API ExtEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
247 INT cbOutput, LPSTR lpszOutData)
248{
249 dprintf(("GDI32: ExtEscape, %x %x %d %x %d %x partly implemented", hdc, nEscape, cbInput, lpszInData, cbOutput, lpszOutData));
250
251 switch(nEscape) {
252 case DOWNLOADHEADER:
253 {
254 dprintf(("DOWNLOADHEADER: hardcoded result"));
255 if(lpszOutData && cbOutput >= 8) {
256 strcpy(lpszOutData, "PM_1.2");
257 return 1;
258 }
259 dprintf(("Not enough room for proc name"));
260 return 0;
261 }
262 }
263 return Escape(hdc, nEscape, cbInput, lpszInData, lpszOutData);
264}
265//******************************************************************************
266//******************************************************************************
267INT WIN32API StartDocA(HDC hdc, const DOCINFOA *lpDocInfo)
268{
269 INT ret;
270
271 if(lpDocInfo) {
272 dprintf(("GDI32: StartDocA %x %x (%s %s %s %x)", hdc, lpDocInfo, lpDocInfo->lpszDocName, lpDocInfo->lpszOutput, lpDocInfo->lpszDatatype, lpDocInfo->fwType));
273 }
274 else dprintf(("GDI32: StartDocA %x %x", hdc, lpDocInfo));
275
276 dprintf(("lpDocInfo->cbSize %x", lpDocInfo->cbSize));
277 dprintf(("lpDocInfo->lpszDocName %s", lpDocInfo->lpszDocName));
278 dprintf(("lpDocInfo->lpszOutput %s", lpDocInfo->lpszOutput));
279 dprintf(("lpDocInfo->lpszDatatype %s", lpDocInfo->lpszDatatype));
280 dprintf(("lpDocInfo->fwType %x", lpDocInfo->fwType));
281
282 ret = O32_StartDoc(hdc, (LPDOCINFOA)lpDocInfo);
283
284 if(ret != 0) {
285 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
286 if(pHps)
287 {
288 pHps->Reserved |= DC_FLAG_SEND_POSTSCRIPT_SETUP_STRING;
289 }
290 else DebugInt3();
291 }
292
293 return ret;
294}
295//******************************************************************************
296//******************************************************************************
297INT WIN32API StartDocW(HDC hdc, const DOCINFOW* doc)
298{
299 DOCINFOA docA;
300 INT ret;
301
302 docA.cbSize = doc->cbSize;
303 docA.lpszDocName = doc->lpszDocName ?
304 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDocName ) : NULL;
305 docA.lpszOutput = doc->lpszOutput ?
306 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszOutput ) : NULL;
307 docA.lpszDatatype = doc->lpszDatatype ?
308 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDatatype ) : NULL;
309 docA.fwType = doc->fwType;
310
311 ret = StartDocA(hdc, &docA);
312
313 if(docA.lpszDocName)
314 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDocName );
315 if(docA.lpszOutput)
316 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszOutput );
317 if(docA.lpszDatatype)
318 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDatatype );
319
320 return ret;
321}
322//******************************************************************************
323//******************************************************************************
324int WIN32API EndDoc( HDC hdc)
325{
326 dprintf(("GDI32: EndDoc %x", hdc));
327 return O32_EndDoc(hdc);
328}
329//******************************************************************************
330//******************************************************************************
331int WIN32API AbortDoc(HDC hdc)
332{
333 dprintf(("GDI32: AbortDoc %x", hdc));
334 return O32_AbortDoc(hdc);
335}
336//******************************************************************************
337//******************************************************************************
338int WIN32API StartPage( HDC hdc)
339{
340 dprintf(("GDI32: StartPage %x", hdc));
341 return O32_StartPage(hdc);
342}
343//******************************************************************************
344//******************************************************************************
345int WIN32API EndPage( HDC hdc)
346{
347 dprintf(("GDI32: EndPage %x", hdc));
348 return O32_EndPage(hdc);
349}
350//******************************************************************************
351//******************************************************************************
352int WIN32API SetAbortProc(HDC hdc, ABORTPROC lpAbortProc)
353{
354 dprintf(("GDI32: SetAbortProc %x %x - stub (1)", hdc, lpAbortProc));
355 return(1);
356}
357//******************************************************************************
358//******************************************************************************
Note: See TracBrowser for help on using the repository browser.