| 1 | /* $Id: printer.cpp,v 1.2 2004-01-11 11:42:21 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * GDI32 printer apis
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 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 <string.h>
|
|---|
| 22 | #include <dcdata.h>
|
|---|
| 23 | #include <dbglog.h>
|
|---|
| 24 | #include <heapstring.h>
|
|---|
| 25 | #include "oslibgpi.h"
|
|---|
| 26 |
|
|---|
| 27 | #define DBG_LOCALLOG DBG_printer
|
|---|
| 28 | #include "dbglocal.h"
|
|---|
| 29 |
|
|---|
| 30 | static char *lpszPassThrough = NULL;
|
|---|
| 31 | static int cbPassThrough = 0;
|
|---|
| 32 |
|
|---|
| 33 | //NOTE: We need to insert this postscript statement into the stream or else
|
|---|
| 34 | // the output will be completely inverted (x & y)
|
|---|
| 35 | static char szSetupString[] = "%%BeginSetup\n[{\n%%BeginColorModelSetup\n<< /ProcessColorModel /DeviceCMYK >> setpagedevice\n%%EndColorModelSetup\n} stopped cleartomark\n%%EndSetup\n";
|
|---|
| 36 |
|
|---|
| 37 | //******************************************************************************
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | int WIN32API Escape( HDC hdc, int nEscape, int cbInput, LPCSTR lpvInData, PVOID lpvOutData)
|
|---|
| 40 | {
|
|---|
| 41 | int rc;
|
|---|
| 42 | char *lpszEscape = NULL;
|
|---|
| 43 |
|
|---|
| 44 | switch(nEscape)
|
|---|
| 45 | {
|
|---|
| 46 | case SET_BOUNDS:
|
|---|
| 47 | {
|
|---|
| 48 | RECT *r = (RECT *)lpvInData;
|
|---|
| 49 | if(cbInput != sizeof(RECT)) {
|
|---|
| 50 | dprintf(("WARNING: cbInput != sizeof(RECT) (=%d) for SET_BOUNDS", cbInput));
|
|---|
| 51 | return 0;
|
|---|
| 52 | }
|
|---|
| 53 | dprintf(("SET_BOUNDS (%d,%d) (%d,%d)", r->left, r->top, r->right, r->bottom));
|
|---|
| 54 | return 0;
|
|---|
| 55 | }
|
|---|
| 56 | case POSTSCRIPT_PASSTHROUGH:
|
|---|
| 57 | if(!lpszEscape) lpszEscape = "POSTSCRIPT_PASSTHROUGH";
|
|---|
| 58 | nEscape = PASSTHROUGH;
|
|---|
| 59 | case POSTSCRIPT_DATA:
|
|---|
| 60 | if(!lpszEscape) lpszEscape = "POSTSCRIPT_DATA";
|
|---|
| 61 | case PASSTHROUGH:
|
|---|
| 62 | {
|
|---|
| 63 | if(!lpszEscape) lpszEscape = "PASSTHROUGH";
|
|---|
| 64 | dprintf(("Postscript %s data of size %d", lpszEscape, *(WORD *)lpvInData));
|
|---|
| 65 |
|
|---|
| 66 | rc = O32_Escape(hdc, nEscape, cbInput, lpvInData, lpvOutData);
|
|---|
| 67 | if(rc == 1) rc = *(WORD *)lpvInData;
|
|---|
| 68 | else rc = 0;
|
|---|
| 69 | return rc;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | case SPCLPASSTHROUGH2:
|
|---|
| 73 | {
|
|---|
| 74 | int rawsize = *(WORD *)(lpvInData+4);
|
|---|
| 75 |
|
|---|
| 76 | dprintf(("SPCLPASSTHROUGH2: pretend success"));
|
|---|
| 77 | dprintf(("SPCLPASSTHROUGH2: virt mem %x size %x", *(DWORD *)lpvInData, rawsize));
|
|---|
| 78 | return 1;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | case DOWNLOADFACE:
|
|---|
| 82 | dprintf(("DOWNLOADFACE: pretend success"));
|
|---|
| 83 | return 1;
|
|---|
| 84 |
|
|---|
| 85 | case POSTSCRIPT_IGNORE:
|
|---|
| 86 | {
|
|---|
| 87 | BOOL ret = FALSE;
|
|---|
| 88 | dprintf(("POSTSCRIPT_IGNORE %d", *(WORD *)lpvInData));
|
|---|
| 89 | return ret;
|
|---|
| 90 | }
|
|---|
| 91 | case EPSPRINTING:
|
|---|
| 92 | {
|
|---|
| 93 | UINT epsprint = *(UINT*)lpvInData;
|
|---|
| 94 | dprintf(("EPSPRINTING support %sable.\n",epsprint?"en":"dis"));
|
|---|
| 95 | return 1;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | case QUERYESCSUPPORT:
|
|---|
| 99 | {
|
|---|
| 100 | DWORD nEscapeSup = *(DWORD *)lpvInData;
|
|---|
| 101 | BOOL fdprintf = FALSE;
|
|---|
| 102 |
|
|---|
| 103 | switch(nEscapeSup) {
|
|---|
| 104 | case SET_BOUNDS:
|
|---|
| 105 | if(!fdprintf) dprintf(("QUERYESCSUPPORT: SET_BOUNDS"));
|
|---|
| 106 | fdprintf = TRUE;
|
|---|
| 107 | /* case SPCLPASSTHROUGH2:
|
|---|
| 108 | if(!fdprintf) dprintf(("QUERYESCSUPPORT: SPCLPASSTHROUGH2"));
|
|---|
| 109 | fdprintf = TRUE;
|
|---|
| 110 | case DOWNLOADHEADER:
|
|---|
| 111 | if(!fdprintf) dprintf(("QUERYESCSUPPORT: DOWNLOADHEADER"));
|
|---|
| 112 | fdprintf = TRUE;
|
|---|
| 113 | case DOWNLOADFACE:
|
|---|
| 114 | if(!fdprintf) dprintf(("QUERYESCSUPPORT: DOWNLOADFACE"));
|
|---|
| 115 | fdprintf = TRUE;
|
|---|
| 116 | */
|
|---|
| 117 | case POSTSCRIPT_IGNORE:
|
|---|
| 118 | if(!fdprintf) dprintf(("QUERYESCSUPPORT: POSTSCRIPT_IGNORE"));
|
|---|
| 119 | fdprintf = TRUE;
|
|---|
| 120 | case EPSPRINTING:
|
|---|
| 121 | {
|
|---|
| 122 | if(!fdprintf) dprintf(("QUERYESCSUPPORT: EPSPRINTING"));
|
|---|
| 123 | fdprintf = TRUE;
|
|---|
| 124 |
|
|---|
| 125 | nEscapeSup = POSTSCRIPT_PASSTHROUGH;
|
|---|
| 126 | return Escape(hdc, QUERYESCSUPPORT, sizeof(nEscapeSup), (LPCSTR)&nEscapeSup, NULL);
|
|---|
| 127 | }
|
|---|
| 128 | default:
|
|---|
| 129 | break;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | default:
|
|---|
| 133 | if(cbInput && lpvInData) {
|
|---|
| 134 | ULONG *tmp = (ULONG *)lpvInData;
|
|---|
| 135 | for(int i=0;i<min(16,cbInput/4);i++) {
|
|---|
| 136 | dprintf(("GDI32: Escape par %d: %x", i, *tmp++));
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 | break;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | rc = O32_Escape(hdc, nEscape, cbInput, lpvInData, lpvOutData);
|
|---|
| 143 | if(rc == 0) {
|
|---|
| 144 | dprintf(("GDI32: Escape %x %d %d %x %x returned %d (WARNING: might not be implemented!!) ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
|
|---|
| 145 | }
|
|---|
| 146 | else dprintf(("GDI32: Escape %x %d %d %x %x returned %d ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
|
|---|
| 147 |
|
|---|
| 148 | return rc;
|
|---|
| 149 | }
|
|---|
| 150 | //******************************************************************************
|
|---|
| 151 | //******************************************************************************
|
|---|
| 152 | INT WIN32API ExtEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
|
|---|
| 153 | INT cbOutput, LPSTR lpszOutData)
|
|---|
| 154 | {
|
|---|
| 155 | dprintf(("GDI32: ExtEscape, %x %x %d %x %d %x partly implemented", hdc, nEscape, cbInput, lpszInData, cbOutput, lpszOutData));
|
|---|
| 156 |
|
|---|
| 157 | switch(nEscape) {
|
|---|
| 158 | case DOWNLOADHEADER:
|
|---|
| 159 | {
|
|---|
| 160 | dprintf(("DOWNLOADHEADER: hardcoded result"));
|
|---|
| 161 | if(lpszOutData && cbOutput >= 8) {
|
|---|
| 162 | strcpy(lpszOutData, "PM_1.2");
|
|---|
| 163 | return 1;
|
|---|
| 164 | }
|
|---|
| 165 | dprintf(("Not enough room for proc name"));
|
|---|
| 166 | return 0;
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 | return Escape(hdc, nEscape, cbInput, lpszInData, lpszOutData);
|
|---|
| 170 | }
|
|---|
| 171 | //******************************************************************************
|
|---|
| 172 | //******************************************************************************
|
|---|
| 173 | INT WIN32API StartDocA(HDC hdc, const DOCINFOA *lpDocInfo)
|
|---|
| 174 | {
|
|---|
| 175 | INT ret;
|
|---|
| 176 |
|
|---|
| 177 | if(lpDocInfo) {
|
|---|
| 178 | dprintf(("GDI32: StartDocA %x %x (%s %s %s %x)", hdc, lpDocInfo, lpDocInfo->lpszDocName, lpDocInfo->lpszOutput, lpDocInfo->lpszDatatype, lpDocInfo->fwType));
|
|---|
| 179 | }
|
|---|
| 180 | else dprintf(("GDI32: StartDocA %x %x", hdc, lpDocInfo));
|
|---|
| 181 |
|
|---|
| 182 | ret = O32_StartDoc(hdc, (LPDOCINFOA)lpDocInfo);
|
|---|
| 183 |
|
|---|
| 184 | if(ret != 0) {
|
|---|
| 185 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 186 | if(pHps)
|
|---|
| 187 | {
|
|---|
| 188 | pHps->Reserved |= DC_FLAG_SEND_POSTSCRIPT_SETUP_STRING;
|
|---|
| 189 | }
|
|---|
| 190 | else DebugInt3();
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | return ret;
|
|---|
| 194 | }
|
|---|
| 195 | //******************************************************************************
|
|---|
| 196 | //******************************************************************************
|
|---|
| 197 | INT WIN32API StartDocW(HDC hdc, const DOCINFOW* doc)
|
|---|
| 198 | {
|
|---|
| 199 | DOCINFOA docA;
|
|---|
| 200 | INT ret;
|
|---|
| 201 |
|
|---|
| 202 | docA.cbSize = doc->cbSize;
|
|---|
| 203 | docA.lpszDocName = doc->lpszDocName ?
|
|---|
| 204 | HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDocName ) : NULL;
|
|---|
| 205 | docA.lpszOutput = doc->lpszOutput ?
|
|---|
| 206 | HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszOutput ) : NULL;
|
|---|
| 207 | docA.lpszDatatype = doc->lpszDatatype ?
|
|---|
| 208 | HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDatatype ) : NULL;
|
|---|
| 209 | docA.fwType = doc->fwType;
|
|---|
| 210 |
|
|---|
| 211 | ret = StartDocA(hdc, &docA);
|
|---|
| 212 |
|
|---|
| 213 | if(docA.lpszDocName)
|
|---|
| 214 | HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDocName );
|
|---|
| 215 | if(docA.lpszOutput)
|
|---|
| 216 | HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszOutput );
|
|---|
| 217 | if(docA.lpszDatatype)
|
|---|
| 218 | HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDatatype );
|
|---|
| 219 |
|
|---|
| 220 | return ret;
|
|---|
| 221 | }
|
|---|
| 222 | //******************************************************************************
|
|---|
| 223 | //******************************************************************************
|
|---|
| 224 | int WIN32API EndDoc( HDC hdc)
|
|---|
| 225 | {
|
|---|
| 226 | dprintf(("GDI32: EndDoc %x", hdc));
|
|---|
| 227 | return O32_EndDoc(hdc);
|
|---|
| 228 | }
|
|---|
| 229 | //******************************************************************************
|
|---|
| 230 | //******************************************************************************
|
|---|
| 231 | int WIN32API AbortDoc(HDC hdc)
|
|---|
| 232 | {
|
|---|
| 233 | dprintf(("GDI32: AbortDoc %x", hdc));
|
|---|
| 234 | return O32_AbortDoc(hdc);
|
|---|
| 235 | }
|
|---|
| 236 | //******************************************************************************
|
|---|
| 237 | //******************************************************************************
|
|---|
| 238 | int WIN32API StartPage( HDC hdc)
|
|---|
| 239 | {
|
|---|
| 240 | dprintf(("GDI32: StartPage %x", hdc));
|
|---|
| 241 | return O32_StartPage(hdc);
|
|---|
| 242 | }
|
|---|
| 243 | //******************************************************************************
|
|---|
| 244 | //******************************************************************************
|
|---|
| 245 | int WIN32API EndPage( HDC hdc)
|
|---|
| 246 | {
|
|---|
| 247 | dprintf(("GDI32: EndPage %x", hdc));
|
|---|
| 248 | return O32_EndPage(hdc);
|
|---|
| 249 | }
|
|---|
| 250 | //******************************************************************************
|
|---|
| 251 | //******************************************************************************
|
|---|
| 252 | int WIN32API SetAbortProc(HDC hdc, ABORTPROC lpAbortProc)
|
|---|
| 253 | {
|
|---|
| 254 | dprintf(("GDI32: SetAbortProc %x %x - stub (1)", hdc, lpAbortProc));
|
|---|
| 255 | return(1);
|
|---|
| 256 | }
|
|---|
| 257 | //******************************************************************************
|
|---|
| 258 | //******************************************************************************
|
|---|