Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1 | /* |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 2 | * PostScript driver initialization functions |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1998 Huw D M Davies |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 5 | * Copyright 2001 Marcus Meissner |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 6 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 20 | */ |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 21 | |
Patrik Stridvall | 172cd1b | 2001-06-11 20:16:11 +0000 | [diff] [blame] | 22 | #include "config.h" |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 23 | #include "wine/port.h" |
Patrik Stridvall | 172cd1b | 2001-06-11 20:16:11 +0000 | [diff] [blame] | 24 | |
Jeff Garzik | c3e1f72 | 1999-02-19 15:42:11 +0000 | [diff] [blame] | 25 | #include <string.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 26 | #ifdef HAVE_UNISTD_H |
| 27 | # include <unistd.h> |
| 28 | #endif |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 29 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 30 | #include "gdi.h" |
| 31 | #include "psdrv.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 32 | #include "wine/debug.h" |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 33 | #include "winreg.h" |
Alexandre Julliard | 5954560 | 1999-02-10 06:52:57 +0000 | [diff] [blame] | 34 | #include "winspool.h" |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 35 | #include "winerror.h" |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 36 | |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 37 | WINE_DEFAULT_DEBUG_CHANNEL(psdrv); |
| 38 | |
| 39 | #ifdef HAVE_CUPS_CUPS_H |
| 40 | #include <cups/cups.h> |
| 41 | |
| 42 | #ifndef CUPS_SONAME |
| 43 | #define CUPS_SONAME "libcups.so" |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 46 | static void *cupshandle = NULL; |
| 47 | #endif |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 48 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 49 | static PSDRV_DEVMODEA DefaultDevmode = |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 50 | { |
| 51 | { /* dmPublic */ |
| 52 | /* dmDeviceName */ "Wine PostScript Driver", |
| 53 | /* dmSpecVersion */ 0x30a, |
| 54 | /* dmDriverVersion */ 0x001, |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 55 | /* dmSize */ sizeof(DEVMODEA), |
Marcus Meissner | 0f53dbf | 2002-11-04 22:37:57 +0000 | [diff] [blame] | 56 | /* dmDriverExtra */ sizeof(PSDRV_DEVMODEA)-sizeof(DEVMODEA), |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 57 | /* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE | |
| 58 | DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR | |
Luc Tourangeau | effc55e | 1999-07-18 18:34:45 +0000 | [diff] [blame] | 59 | DM_DUPLEX | DM_YRESOLUTION | DM_TTOPTION, |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 60 | { /* u1 */ |
| 61 | { /* s1 */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 62 | /* dmOrientation */ DMORIENT_PORTRAIT, |
Huw D M Davies | 7526fc5 | 2002-04-06 00:04:31 +0000 | [diff] [blame] | 63 | /* dmPaperSize */ DMPAPER_LETTER, |
| 64 | /* dmPaperLength */ 2794, |
| 65 | /* dmPaperWidth */ 2159 |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 66 | } |
| 67 | }, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 68 | /* dmScale */ 100, /* ?? */ |
| 69 | /* dmCopies */ 1, |
| 70 | /* dmDefaultSource */ DMBIN_AUTO, |
| 71 | /* dmPrintQuality */ 0, |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 72 | /* dmColor */ DMCOLOR_COLOR, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 73 | /* dmDuplex */ 0, |
| 74 | /* dmYResolution */ 0, |
| 75 | /* dmTTOption */ DMTT_SUBDEV, |
| 76 | /* dmCollate */ 0, |
| 77 | /* dmFormName */ "", |
| 78 | /* dmUnusedPadding */ 0, |
| 79 | /* dmBitsPerPel */ 0, |
| 80 | /* dmPelsWidth */ 0, |
| 81 | /* dmPelsHeight */ 0, |
| 82 | /* dmDisplayFlags */ 0, |
Patrik Stridvall | a9f6a9d | 2000-10-24 02:22:16 +0000 | [diff] [blame] | 83 | /* dmDisplayFrequency */ 0, |
| 84 | /* dmICMMethod */ 0, |
| 85 | /* dmICMIntent */ 0, |
| 86 | /* dmMediaType */ 0, |
| 87 | /* dmDitherType */ 0, |
| 88 | /* dmReserved1 */ 0, |
| 89 | /* dmReserved2 */ 0, |
| 90 | /* dmPanningWidth */ 0, |
| 91 | /* dmPanningHeight */ 0 |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 92 | }, |
| 93 | { /* dmDocPrivate */ |
Patrik Stridvall | a9f6a9d | 2000-10-24 02:22:16 +0000 | [diff] [blame] | 94 | /* dummy */ 0 |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 95 | }, |
| 96 | { /* dmDrvPrivate */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 97 | /* numInstalledOptions */ 0 |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 98 | } |
| 99 | }; |
| 100 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 101 | HANDLE PSDRV_Heap = 0; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 102 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 103 | static HANDLE PSDRV_DefaultFont = 0; |
| 104 | static LOGFONTA DefaultLogFont = { |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 105 | 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0, |
| 106 | DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" |
| 107 | }; |
| 108 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 109 | /********************************************************************* |
Alexandre Julliard | 1e1313d | 2002-11-04 23:53:41 +0000 | [diff] [blame] | 110 | * DllMain |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 111 | * |
Alexandre Julliard | 1e1313d | 2002-11-04 23:53:41 +0000 | [diff] [blame] | 112 | * Initializes font metrics and registers driver. wineps dll entry point. |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 113 | * |
| 114 | */ |
Alexandre Julliard | 1e1313d | 2002-11-04 23:53:41 +0000 | [diff] [blame] | 115 | BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved ) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 116 | { |
Alexandre Julliard | b34fb35 | 2002-10-18 23:48:57 +0000 | [diff] [blame] | 117 | TRACE("(%p, 0x%08lx, %p)\n", hinst, reason, reserved); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 118 | |
Dimitrie O. Paun | 84bde6a | 2000-05-30 20:27:23 +0000 | [diff] [blame] | 119 | switch(reason) { |
Ian Pilcher | 2ce7bc8 | 2001-04-30 18:17:13 +0000 | [diff] [blame] | 120 | |
Dimitrie O. Paun | 84bde6a | 2000-05-30 20:27:23 +0000 | [diff] [blame] | 121 | case DLL_PROCESS_ATTACH: |
Ian Pilcher | 2ce7bc8 | 2001-04-30 18:17:13 +0000 | [diff] [blame] | 122 | |
| 123 | PSDRV_Heap = HeapCreate(0, 0x10000, 0); |
| 124 | if (PSDRV_Heap == (HANDLE)NULL) |
| 125 | return FALSE; |
| 126 | |
| 127 | if (PSDRV_GetFontMetrics() == FALSE) { |
| 128 | HeapDestroy(PSDRV_Heap); |
| 129 | return FALSE; |
| 130 | } |
| 131 | |
| 132 | PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont); |
| 133 | if (PSDRV_DefaultFont == (HANDLE)NULL) { |
| 134 | HeapDestroy(PSDRV_Heap); |
| 135 | return FALSE; |
| 136 | } |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 137 | #ifdef HAVE_CUPS_CUPS_H |
| 138 | /* dynamically load CUPS if not yet loaded */ |
| 139 | if (!cupshandle) { |
| 140 | cupshandle = wine_dlopen(CUPS_SONAME, RTLD_NOW, NULL, 0); |
| 141 | if (!cupshandle) cupshandle = (void*)-1; |
| 142 | } |
| 143 | #endif |
Ian Pilcher | 2ce7bc8 | 2001-04-30 18:17:13 +0000 | [diff] [blame] | 144 | break; |
| 145 | |
Dimitrie O. Paun | 84bde6a | 2000-05-30 20:27:23 +0000 | [diff] [blame] | 146 | case DLL_PROCESS_DETACH: |
Ian Pilcher | 2ce7bc8 | 2001-04-30 18:17:13 +0000 | [diff] [blame] | 147 | |
| 148 | DeleteObject( PSDRV_DefaultFont ); |
| 149 | HeapDestroy( PSDRV_Heap ); |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 150 | #ifdef HAVE_CUPS_CUPS_H |
| 151 | if (cupshandle && (cupshandle != (void*)-1)) { |
| 152 | wine_dlclose(cupshandle, NULL, 0); |
| 153 | cupshandle = NULL; |
| 154 | } |
| 155 | #endif |
Ian Pilcher | 2ce7bc8 | 2001-04-30 18:17:13 +0000 | [diff] [blame] | 156 | break; |
Dimitrie O. Paun | 84bde6a | 2000-05-30 20:27:23 +0000 | [diff] [blame] | 157 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 158 | |
Dimitrie O. Paun | 84bde6a | 2000-05-30 20:27:23 +0000 | [diff] [blame] | 159 | return TRUE; |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Dimitrie O. Paun | 84bde6a | 2000-05-30 20:27:23 +0000 | [diff] [blame] | 162 | |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 163 | static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev ) |
| 164 | { |
| 165 | PAGESIZE *page; |
| 166 | INT width = 0, height = 0; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 167 | |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 168 | if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) { |
| 169 | for(page = physDev->pi->ppd->PageSizes; page; page = page->next) { |
| 170 | if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | if(!page) { |
| 175 | FIXME("Can't find page\n"); |
| 176 | physDev->ImageableArea.left = 0; |
| 177 | physDev->ImageableArea.right = 0; |
| 178 | physDev->ImageableArea.bottom = 0; |
| 179 | physDev->ImageableArea.top = 0; |
| 180 | physDev->PageSize.cx = 0; |
| 181 | physDev->PageSize.cy = 0; |
| 182 | } else if(page->ImageableArea) { |
| 183 | /* physDev sizes in device units; ppd sizes in 1/72" */ |
| 184 | physDev->ImageableArea.left = page->ImageableArea->llx * |
| 185 | physDev->logPixelsX / 72; |
| 186 | physDev->ImageableArea.right = page->ImageableArea->urx * |
| 187 | physDev->logPixelsX / 72; |
| 188 | physDev->ImageableArea.bottom = page->ImageableArea->lly * |
| 189 | physDev->logPixelsY / 72; |
| 190 | physDev->ImageableArea.top = page->ImageableArea->ury * |
| 191 | physDev->logPixelsY / 72; |
| 192 | physDev->PageSize.cx = page->PaperDimension->x * |
| 193 | physDev->logPixelsX / 72; |
| 194 | physDev->PageSize.cy = page->PaperDimension->y * |
| 195 | physDev->logPixelsY / 72; |
| 196 | } else { |
| 197 | physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0; |
| 198 | physDev->ImageableArea.right = physDev->PageSize.cx = |
| 199 | page->PaperDimension->x * physDev->logPixelsX / 72; |
| 200 | physDev->ImageableArea.top = physDev->PageSize.cy = |
| 201 | page->PaperDimension->y * physDev->logPixelsY / 72; |
| 202 | } |
| 203 | } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) && |
| 204 | (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) { |
| 205 | /* physDev sizes in device units; Devmode sizes in 1/10 mm */ |
| 206 | physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0; |
| 207 | physDev->ImageableArea.right = physDev->PageSize.cx = |
| 208 | physDev->Devmode->dmPublic.u1.s1.dmPaperWidth * |
| 209 | physDev->logPixelsX / 254; |
| 210 | physDev->ImageableArea.top = physDev->PageSize.cy = |
| 211 | physDev->Devmode->dmPublic.u1.s1.dmPaperLength * |
| 212 | physDev->logPixelsY / 254; |
| 213 | } else { |
| 214 | FIXME("Odd dmFields %lx\n", physDev->Devmode->dmPublic.dmFields); |
| 215 | physDev->ImageableArea.left = 0; |
| 216 | physDev->ImageableArea.right = 0; |
| 217 | physDev->ImageableArea.bottom = 0; |
| 218 | physDev->ImageableArea.top = 0; |
| 219 | physDev->PageSize.cx = 0; |
| 220 | physDev->PageSize.cy = 0; |
| 221 | } |
| 222 | |
| 223 | TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %ldx%ld\n", |
| 224 | physDev->ImageableArea.left, physDev->ImageableArea.bottom, |
| 225 | physDev->ImageableArea.right, physDev->ImageableArea.top, |
| 226 | physDev->PageSize.cx, physDev->PageSize.cy); |
| 227 | |
| 228 | /* these are in device units */ |
| 229 | width = physDev->ImageableArea.right - physDev->ImageableArea.left; |
| 230 | height = physDev->ImageableArea.top - physDev->ImageableArea.bottom; |
| 231 | |
| 232 | if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) { |
| 233 | physDev->horzRes = width; |
| 234 | physDev->vertRes = height; |
| 235 | } else { |
| 236 | physDev->horzRes = height; |
| 237 | physDev->vertRes = width; |
| 238 | } |
| 239 | |
| 240 | /* these are in mm */ |
| 241 | physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX; |
| 242 | physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY; |
| 243 | |
| 244 | TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, " |
| 245 | "horzRes = %d, vertRes = %d\n", |
| 246 | physDev->horzSize, physDev->vertSize, |
| 247 | physDev->horzRes, physDev->vertRes); |
| 248 | } |
| 249 | |
| 250 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 251 | /********************************************************************** |
| 252 | * PSDRV_CreateDC |
| 253 | */ |
Alexandre Julliard | d3cab18 | 2002-06-10 22:52:47 +0000 | [diff] [blame] | 254 | BOOL PSDRV_CreateDC( DC *dc, PSDRV_PDEVICE **pdev, LPCSTR driver, LPCSTR device, |
Alexandre Julliard | 3dd63eb | 2001-07-27 19:37:31 +0000 | [diff] [blame] | 255 | LPCSTR output, const DEVMODEA* initData ) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 256 | { |
| 257 | PSDRV_PDEVICE *physDev; |
Noel Borthwick | 86b686f | 1999-06-05 08:52:30 +0000 | [diff] [blame] | 258 | PRINTERINFO *pi; |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 259 | |
Noel Borthwick | 86b686f | 1999-06-05 08:52:30 +0000 | [diff] [blame] | 260 | /* If no device name was specified, retrieve the device name |
| 261 | * from the DEVMODE structure from the DC's physDev. |
| 262 | * (See CreateCompatibleDC) */ |
Alexandre Julliard | d3cab18 | 2002-06-10 22:52:47 +0000 | [diff] [blame] | 263 | if ( !device && *pdev ) |
Noel Borthwick | 86b686f | 1999-06-05 08:52:30 +0000 | [diff] [blame] | 264 | { |
Alexandre Julliard | d3cab18 | 2002-06-10 22:52:47 +0000 | [diff] [blame] | 265 | physDev = *pdev; |
Noel Borthwick | 86b686f | 1999-06-05 08:52:30 +0000 | [diff] [blame] | 266 | device = physDev->Devmode->dmPublic.dmDeviceName; |
| 267 | } |
| 268 | pi = PSDRV_FindPrinterInfo(device); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 269 | |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 270 | TRACE("(%s %s %s %p)\n", driver, device, output, initData); |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 271 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 272 | if(!pi) return FALSE; |
| 273 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 274 | if(!pi->Fonts) { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 275 | MESSAGE("To use WINEPS you need to install some AFM files.\n"); |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 276 | return FALSE; |
| 277 | } |
| 278 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 279 | physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 280 | sizeof(*physDev) ); |
| 281 | if (!physDev) return FALSE; |
Alexandre Julliard | d3cab18 | 2002-06-10 22:52:47 +0000 | [diff] [blame] | 282 | *pdev = physDev; |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 283 | physDev->hdc = dc->hSelf; |
| 284 | physDev->dc = dc; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 285 | |
| 286 | physDev->pi = pi; |
| 287 | |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 288 | physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0, |
| 289 | sizeof(PSDRV_DEVMODEA) ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 290 | if(!physDev->Devmode) { |
| 291 | HeapFree( PSDRV_Heap, 0, physDev ); |
| 292 | return FALSE; |
| 293 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 294 | |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 295 | memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 296 | |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 297 | physDev->logPixelsX = physDev->pi->ppd->DefaultResolution; |
| 298 | physDev->logPixelsY = physDev->pi->ppd->DefaultResolution; |
Huw D M Davies | d4b933e | 2001-01-28 23:13:45 +0000 | [diff] [blame] | 299 | |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 300 | if (!output) output = "LPT1:"; /* HACK */ |
| 301 | physDev->job.output = HeapAlloc( PSDRV_Heap, 0, strlen(output)+1 ); |
| 302 | strcpy( physDev->job.output, output ); |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 303 | physDev->job.hJob = 0; |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 304 | |
| 305 | if(initData) { |
| 306 | PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)initData, pi); |
| 307 | } |
| 308 | |
| 309 | PSDRV_UpdateDevCaps(physDev); |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 310 | dc->hFont = PSDRV_DefaultFont; |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 311 | return TRUE; |
| 312 | } |
| 313 | |
| 314 | |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 315 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 316 | /********************************************************************** |
| 317 | * PSDRV_DeleteDC |
| 318 | */ |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 319 | BOOL PSDRV_DeleteDC( PSDRV_PDEVICE *physDev ) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 320 | { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 321 | TRACE("\n"); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 322 | |
| 323 | HeapFree( PSDRV_Heap, 0, physDev->Devmode ); |
| 324 | HeapFree( PSDRV_Heap, 0, physDev->job.output ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 325 | HeapFree( PSDRV_Heap, 0, physDev ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 326 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 327 | return TRUE; |
| 328 | } |
| 329 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 330 | |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 331 | /********************************************************************** |
| 332 | * ResetDC (WINEPS.@) |
Alexandre Julliard | 9208301 | 2001-07-29 20:25:14 +0000 | [diff] [blame] | 333 | */ |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 334 | HDC PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEA *lpInitData ) |
Alexandre Julliard | 9208301 | 2001-07-29 20:25:14 +0000 | [diff] [blame] | 335 | { |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 336 | if(lpInitData) { |
| 337 | PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)lpInitData, physDev->pi); |
| 338 | PSDRV_UpdateDevCaps(physDev); |
Alexandre Julliard | 9208301 | 2001-07-29 20:25:14 +0000 | [diff] [blame] | 339 | } |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 340 | return physDev->hdc; |
Alexandre Julliard | 9208301 | 2001-07-29 20:25:14 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Alexandre Julliard | 9208301 | 2001-07-29 20:25:14 +0000 | [diff] [blame] | 343 | /*********************************************************************** |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 344 | * GetDeviceCaps (WINEPS.@) |
| 345 | */ |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 346 | INT PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap ) |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 347 | { |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 348 | switch(cap) |
| 349 | { |
| 350 | case DRIVERVERSION: |
| 351 | return 0; |
| 352 | case TECHNOLOGY: |
| 353 | return DT_RASPRINTER; |
| 354 | case HORZSIZE: |
Huw D M Davies | 7a6ea91 | 2002-06-24 23:41:55 +0000 | [diff] [blame] | 355 | return MulDiv(physDev->horzSize, 100, |
| 356 | physDev->Devmode->dmPublic.dmScale); |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 357 | case VERTSIZE: |
Huw D M Davies | 7a6ea91 | 2002-06-24 23:41:55 +0000 | [diff] [blame] | 358 | return MulDiv(physDev->vertSize, 100, |
| 359 | physDev->Devmode->dmPublic.dmScale); |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 360 | case HORZRES: |
| 361 | return physDev->horzRes; |
| 362 | case VERTRES: |
| 363 | return physDev->vertRes; |
| 364 | case BITSPIXEL: |
| 365 | return (physDev->pi->ppd->ColorDevice ? 8 : 1); |
| 366 | case PLANES: |
| 367 | return 1; |
| 368 | case NUMBRUSHES: |
| 369 | return -1; |
| 370 | case NUMPENS: |
| 371 | return 10; |
| 372 | case NUMMARKERS: |
| 373 | return 0; |
| 374 | case NUMFONTS: |
| 375 | return 39; |
| 376 | case NUMCOLORS: |
| 377 | return (physDev->pi->ppd->ColorDevice ? 256 : -1); |
| 378 | case PDEVICESIZE: |
| 379 | return sizeof(PSDRV_PDEVICE); |
| 380 | case CURVECAPS: |
| 381 | return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE | |
| 382 | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT); |
| 383 | case LINECAPS: |
| 384 | return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE | |
| 385 | LC_STYLED | LC_WIDESTYLED | LC_INTERIORS); |
| 386 | case POLYGONALCAPS: |
| 387 | return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE | |
| 388 | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS); |
| 389 | case TEXTCAPS: |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 390 | return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */ |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 391 | case CLIPCAPS: |
| 392 | return CP_RECTANGLE; |
| 393 | case RASTERCAPS: |
| 394 | return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV | |
| 395 | RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */ |
| 396 | /* Are aspect[XY] and logPixels[XY] correct? */ |
| 397 | /* Need to handle different res in x and y => fix ppd */ |
| 398 | case ASPECTX: |
| 399 | case ASPECTY: |
| 400 | return physDev->pi->ppd->DefaultResolution; |
| 401 | case ASPECTXY: |
| 402 | return (int)hypot( (double)physDev->pi->ppd->DefaultResolution, |
| 403 | (double)physDev->pi->ppd->DefaultResolution ); |
| 404 | case LOGPIXELSX: |
Huw D M Davies | 7a6ea91 | 2002-06-24 23:41:55 +0000 | [diff] [blame] | 405 | return MulDiv(physDev->logPixelsX, |
| 406 | physDev->Devmode->dmPublic.dmScale, 100); |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 407 | case LOGPIXELSY: |
Huw D M Davies | 7a6ea91 | 2002-06-24 23:41:55 +0000 | [diff] [blame] | 408 | return MulDiv(physDev->logPixelsY, |
| 409 | physDev->Devmode->dmPublic.dmScale, 100); |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 410 | case SIZEPALETTE: |
| 411 | return 0; |
| 412 | case NUMRESERVED: |
| 413 | return 0; |
| 414 | case COLORRES: |
| 415 | return 0; |
| 416 | case PHYSICALWIDTH: |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 417 | return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ? |
| 418 | physDev->PageSize.cy : physDev->PageSize.cx; |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 419 | case PHYSICALHEIGHT: |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 420 | return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ? |
| 421 | physDev->PageSize.cx : physDev->PageSize.cy; |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 422 | case PHYSICALOFFSETX: |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 423 | if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) { |
| 424 | if(physDev->pi->ppd->LandscapeOrientation == -90) |
| 425 | return physDev->PageSize.cy - physDev->ImageableArea.top; |
| 426 | else |
| 427 | return physDev->ImageableArea.bottom; |
| 428 | } |
| 429 | return physDev->ImageableArea.left; |
| 430 | |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 431 | case PHYSICALOFFSETY: |
Huw D M Davies | b88f724 | 2002-04-06 00:12:42 +0000 | [diff] [blame] | 432 | if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) { |
| 433 | if(physDev->pi->ppd->LandscapeOrientation == -90) |
| 434 | return physDev->PageSize.cx - physDev->ImageableArea.right; |
| 435 | else |
| 436 | return physDev->ImageableArea.left; |
| 437 | } |
| 438 | return physDev->PageSize.cy - physDev->ImageableArea.top; |
| 439 | |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 440 | case SCALINGFACTORX: |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 441 | case SCALINGFACTORY: |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 442 | case VREFRESH: |
| 443 | case DESKTOPVERTRES: |
| 444 | case DESKTOPHORZRES: |
| 445 | case BTLALIGNMENT: |
| 446 | return 0; |
| 447 | default: |
Alexandre Julliard | b34fb35 | 2002-10-18 23:48:57 +0000 | [diff] [blame] | 448 | FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap ); |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 454 | /********************************************************************** |
| 455 | * PSDRV_FindPrinterInfo |
| 456 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 457 | PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 458 | { |
| 459 | static PRINTERINFO *PSDRV_PrinterList; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 460 | DWORD type = REG_BINARY, needed, res, dwPaperSize; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 461 | PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList; |
| 462 | FONTNAME *font; |
Ian Pilcher | 4bc1ebb5 | 2001-07-24 20:52:19 +0000 | [diff] [blame] | 463 | const AFM *afm; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 464 | HANDLE hPrinter; |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 465 | const char *ppd = NULL; |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 466 | DWORD ppdType; |
| 467 | char* ppdFileName = NULL; |
Dmitry Timoshkov | 043f640 | 2001-07-02 18:00:33 +0000 | [diff] [blame] | 468 | HKEY hkey; |
Huw D M Davies | 933733c | 2002-08-15 23:20:19 +0000 | [diff] [blame] | 469 | BOOL using_default_devmode = FALSE; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 470 | |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 471 | TRACE("'%s'\n", name); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 472 | |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 473 | /* |
| 474 | * If this loop completes, last will point to the 'next' element of the |
| 475 | * final PRINTERINFO in the list |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 476 | */ |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 477 | for( ; pi; last = &pi->next, pi = pi->next) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 478 | if(!strcmp(pi->FriendlyName, name)) |
| 479 | return pi; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 480 | |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 481 | pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) ); |
| 482 | if (pi == NULL) |
| 483 | return NULL; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 484 | |
| 485 | if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail; |
| 486 | strcpy( pi->FriendlyName, name ); |
| 487 | |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 488 | /* Use Get|SetPrinterDataExA instead? */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 489 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 490 | res = DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 491 | NULL, 0, &needed ); |
| 492 | |
Huw D M Davies | 450270b | 1999-07-10 11:58:50 +0000 | [diff] [blame] | 493 | if(res == ERROR_INVALID_PRINTER_NAME || needed != sizeof(DefaultDevmode)) { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 494 | pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) ); |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 495 | if (pi->Devmode == NULL) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 496 | goto cleanup; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 497 | memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) ); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 498 | strcpy(pi->Devmode->dmPublic.dmDeviceName,name); |
Huw D M Davies | 933733c | 2002-08-15 23:20:19 +0000 | [diff] [blame] | 499 | using_default_devmode = TRUE; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 500 | |
| 501 | /* need to do something here AddPrinter?? */ |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 502 | } |
| 503 | else { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 504 | pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 505 | DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 506 | (LPBYTE)pi->Devmode, needed, &needed); |
| 507 | } |
| 508 | |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 509 | if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 510 | ERR ("OpenPrinterA failed with code %li\n", GetLastError ()); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 511 | goto cleanup; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 512 | } |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 513 | |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 514 | #ifdef HAVE_CUPS_CUPS_H |
| 515 | if (cupshandle != (void*)-1) { |
| 516 | typeof(cupsGetPPD) * pcupsGetPPD = NULL; |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 517 | |
Marcus Meissner | f061f76 | 2002-11-12 02:22:24 +0000 | [diff] [blame^] | 518 | pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0); |
| 519 | if (pcupsGetPPD) { |
| 520 | ppd = pcupsGetPPD(name); |
| 521 | |
| 522 | if (ppd) { |
| 523 | needed=strlen(ppd)+1; |
| 524 | ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed); |
| 525 | memcpy(ppdFileName, ppd, needed); |
| 526 | ppdType=REG_SZ; |
| 527 | res = ERROR_SUCCESS; |
| 528 | /* we should unlink() that file later */ |
| 529 | } else { |
| 530 | res = ERROR_FILE_NOT_FOUND; |
| 531 | WARN("Did not find ppd for %s\n",name); |
| 532 | } |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | #endif |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 536 | if (!ppdFileName) { |
| 537 | res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed); |
| 538 | if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) { |
| 539 | ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed); |
| 540 | res = GetPrinterDataA(hPrinter, "PPD File", &ppdType, ppdFileName, needed, &needed); |
| 541 | } |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 542 | } |
Marcus Meissner | 0c63012 | 2001-05-09 17:10:41 +0000 | [diff] [blame] | 543 | /* Look for a ppd file for this printer in the config file. |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 544 | * First look under that printer's name, and then under 'generic' |
Marcus Meissner | 0c63012 | 2001-05-09 17:10:41 +0000 | [diff] [blame] | 545 | */ |
Dmitry Timoshkov | 043f640 | 2001-07-02 18:00:33 +0000 | [diff] [blame] | 546 | if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey)) |
| 547 | { |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 548 | const char* value_name; |
| 549 | |
| 550 | if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) { |
| 551 | value_name=name; |
| 552 | } else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) { |
| 553 | value_name="generic"; |
| 554 | } else { |
| 555 | value_name=NULL; |
| 556 | } |
| 557 | if (value_name) { |
| 558 | ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed); |
| 559 | RegQueryValueExA(hkey, value_name, 0, &ppdType, ppdFileName, &needed); |
| 560 | } |
| 561 | RegCloseKey(hkey); |
Dmitry Timoshkov | 043f640 | 2001-07-02 18:00:33 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 564 | if (!ppdFileName) { |
| 565 | res = ERROR_FILE_NOT_FOUND; |
| 566 | ERR ("Error %li getting PPD file name for printer '%s'\n", res, name); |
| 567 | goto closeprinter; |
| 568 | } else { |
| 569 | res = ERROR_SUCCESS; |
| 570 | if (ppdType==REG_EXPAND_SZ) { |
| 571 | char* tmp; |
Marcus Meissner | 0c63012 | 2001-05-09 17:10:41 +0000 | [diff] [blame] | 572 | |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 573 | /* Expand environment variable references */ |
| 574 | needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0); |
| 575 | tmp=HeapAlloc(PSDRV_Heap, 0, needed); |
| 576 | ExpandEnvironmentStringsA(ppdFileName,tmp,needed); |
| 577 | HeapFree(PSDRV_Heap, 0, ppdFileName); |
| 578 | ppdFileName=tmp; |
| 579 | } |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 580 | } |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 581 | |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 582 | pi->ppd = PSDRV_ParsePPD(ppdFileName); |
| 583 | if(!pi->ppd) { |
| 584 | MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n", |
| 585 | ppdFileName); |
| 586 | goto closeprinter; |
| 587 | } |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 588 | |
Huw D M Davies | 933733c | 2002-08-15 23:20:19 +0000 | [diff] [blame] | 589 | |
| 590 | if(using_default_devmode) { |
| 591 | DWORD papersize; |
| 592 | |
| 593 | if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER, |
| 594 | (LPWSTR)&papersize, sizeof(papersize))) { |
| 595 | PSDRV_DEVMODEA dm; |
| 596 | memset(&dm, 0, sizeof(dm)); |
| 597 | dm.dmPublic.dmFields = DM_PAPERSIZE; |
| 598 | dm.dmPublic.u1.s1.dmPaperSize = papersize; |
| 599 | PSDRV_MergeDevmodes(pi->Devmode, &dm, pi); |
| 600 | } |
| 601 | DrvSetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, |
| 602 | REG_BINARY, (LPBYTE)pi->Devmode, sizeof(DefaultDevmode) ); |
| 603 | } |
| 604 | |
| 605 | |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 606 | /* |
| 607 | * This is a hack. The default paper size should be read in as part of |
| 608 | * the Devmode structure, but Wine doesn't currently provide a convenient |
| 609 | * way to configure printers. |
| 610 | */ |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 611 | res = GetPrinterDataA (hPrinter, "Paper Size", NULL, (LPBYTE) &dwPaperSize, |
| 612 | sizeof (DWORD), &needed); |
| 613 | if (res == ERROR_SUCCESS) |
| 614 | pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize; |
| 615 | else if (res == ERROR_FILE_NOT_FOUND) |
| 616 | TRACE ("No 'Paper Size' for printer '%s'\n", name); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 617 | else { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 618 | ERR ("GetPrinterDataA returned %li\n", res); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 619 | goto closeprinter; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL, |
| 623 | 0, &needed, &pi->FontSubTableSize); |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 624 | if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 625 | TRACE ("No 'FontSubTable' for printer '%s'\n", name); |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 626 | } |
| 627 | else if (res == ERROR_MORE_DATA) { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 628 | pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 629 | if (pi->FontSubTable == NULL) { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 630 | ERR ("Failed to allocate %li bytes from heap\n", needed); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 631 | goto closeprinter; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", |
| 635 | (LPBYTE) pi->FontSubTable, needed, &needed, |
| 636 | &pi->FontSubTableSize); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 637 | if (res != ERROR_SUCCESS) { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 638 | ERR ("EnumPrinterDataExA returned %li\n", res); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 639 | goto closeprinter; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 640 | } |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 641 | } |
| 642 | else { |
| 643 | ERR("EnumPrinterDataExA returned %li\n", res); |
| 644 | goto closeprinter; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 647 | if (ClosePrinter (hPrinter) == 0) { |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 648 | ERR ("ClosePrinter failed with code %li\n", GetLastError ()); |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 649 | goto cleanup; |
Ian Pilcher | 744820d | 2001-04-02 19:14:41 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 652 | pi->next = NULL; |
| 653 | pi->Fonts = NULL; |
| 654 | |
| 655 | for(font = pi->ppd->InstalledFonts; font; font = font->next) { |
| 656 | afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name); |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 657 | if(!afm) { |
| 658 | TRACE( "Couldn't find AFM file for installed printer font '%s' - " |
| 659 | "ignoring\n", font->Name); |
| 660 | } |
| 661 | else { |
Ian Pilcher | 42e052d | 2001-07-26 21:42:45 +0000 | [diff] [blame] | 662 | BOOL added; |
| 663 | if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) { |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 664 | PSDRV_FreeAFMList(pi->Fonts); |
| 665 | goto cleanup; |
| 666 | } |
| 667 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 668 | |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 669 | } |
| 670 | if (ppd) unlink(ppd); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 671 | return pi; |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 672 | |
| 673 | closeprinter: |
| 674 | ClosePrinter(hPrinter); |
| 675 | cleanup: |
Francois Gouget | f101e27 | 2001-10-22 19:00:08 +0000 | [diff] [blame] | 676 | if (ppdFileName) |
| 677 | HeapFree(PSDRV_Heap, 0, ppdFileName); |
Ian Pilcher | 91857a6 | 2001-05-03 18:34:27 +0000 | [diff] [blame] | 678 | if (pi->FontSubTable) |
| 679 | HeapFree(PSDRV_Heap, 0, pi->FontSubTable); |
| 680 | if (pi->FriendlyName) |
| 681 | HeapFree(PSDRV_Heap, 0, pi->FriendlyName); |
| 682 | if (pi->Devmode) |
| 683 | HeapFree(PSDRV_Heap, 0, pi->Devmode); |
| 684 | fail: |
Marcus Meissner | ab8b7db | 2001-04-27 18:02:46 +0000 | [diff] [blame] | 685 | HeapFree(PSDRV_Heap, 0, pi); |
| 686 | if (ppd) unlink(ppd); |
| 687 | *last = NULL; |
| 688 | return NULL; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 689 | } |