blob: fa6e9da300a74834e74c1b0e2886349817b9de8f [file] [log] [blame]
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001/*
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002 * PostScript driver initialization functions
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003 *
4 * Copyright 1998 Huw D M Davies
Marcus Meissnerab8b7db2001-04-27 18:02:46 +00005 * Copyright 2001 Marcus Meissner
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00006 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 * 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 Julliardebfc0fe1998-06-28 18:40:26 +000020 */
Marcus Meissnerab8b7db2001-04-27 18:02:46 +000021
Patrik Stridvall172cd1b2001-06-11 20:16:11 +000022#include "config.h"
Marcus Meissnerf061f762002-11-12 02:22:24 +000023#include "wine/port.h"
Patrik Stridvall172cd1b2001-06-11 20:16:11 +000024
Jeff Garzikc3e1f721999-02-19 15:42:11 +000025#include <string.h>
Patrik Stridvalld016f812002-08-17 00:43:16 +000026#ifdef HAVE_UNISTD_H
27# include <unistd.h>
28#endif
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +000029
Alexandre Julliarda0d77311998-09-13 16:32:00 +000030#include "gdi.h"
31#include "psdrv.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000032#include "wine/debug.h"
Alexandre Julliarda0d77311998-09-13 16:32:00 +000033#include "winreg.h"
Alexandre Julliard59545601999-02-10 06:52:57 +000034#include "winspool.h"
Alexandre Julliarda0d77311998-09-13 16:32:00 +000035#include "winerror.h"
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +000036
Marcus Meissnerf061f762002-11-12 02:22:24 +000037WINE_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 Meissnerab8b7db2001-04-27 18:02:46 +000044#endif
45
Marcus Meissnerf061f762002-11-12 02:22:24 +000046static void *cupshandle = NULL;
47#endif
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000048
Vincent Béron9a624912002-05-31 23:06:46 +000049static PSDRV_DEVMODEA DefaultDevmode =
Alexandre Julliard767e6f61998-08-09 12:47:43 +000050{
51 { /* dmPublic */
52/* dmDeviceName */ "Wine PostScript Driver",
53/* dmSpecVersion */ 0x30a,
54/* dmDriverVersion */ 0x001,
Huw D M Daviese39b6761999-05-17 16:20:51 +000055/* dmSize */ sizeof(DEVMODEA),
Marcus Meissner0f53dbf2002-11-04 22:37:57 +000056/* dmDriverExtra */ sizeof(PSDRV_DEVMODEA)-sizeof(DEVMODEA),
Vincent Béron9a624912002-05-31 23:06:46 +000057/* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE |
58 DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
Luc Tourangeaueffc55e1999-07-18 18:34:45 +000059 DM_DUPLEX | DM_YRESOLUTION | DM_TTOPTION,
Huw D M Daviese39b6761999-05-17 16:20:51 +000060 { /* u1 */
61 { /* s1 */
Alexandre Julliard767e6f61998-08-09 12:47:43 +000062/* dmOrientation */ DMORIENT_PORTRAIT,
Huw D M Davies7526fc52002-04-06 00:04:31 +000063/* dmPaperSize */ DMPAPER_LETTER,
64/* dmPaperLength */ 2794,
65/* dmPaperWidth */ 2159
Huw D M Daviese39b6761999-05-17 16:20:51 +000066 }
67 },
Alexandre Julliard767e6f61998-08-09 12:47:43 +000068/* dmScale */ 100, /* ?? */
69/* dmCopies */ 1,
70/* dmDefaultSource */ DMBIN_AUTO,
71/* dmPrintQuality */ 0,
Marcus Meissnerab8b7db2001-04-27 18:02:46 +000072/* dmColor */ DMCOLOR_COLOR,
Alexandre Julliard767e6f61998-08-09 12:47:43 +000073/* 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 Stridvalla9f6a9d2000-10-24 02:22:16 +000083/* 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 Julliard767e6f61998-08-09 12:47:43 +000092 },
93 { /* dmDocPrivate */
Patrik Stridvalla9f6a9d2000-10-24 02:22:16 +000094 /* dummy */ 0
Alexandre Julliard767e6f61998-08-09 12:47:43 +000095 },
96 { /* dmDrvPrivate */
Vincent Béron9a624912002-05-31 23:06:46 +000097 /* numInstalledOptions */ 0
Alexandre Julliard767e6f61998-08-09 12:47:43 +000098 }
99};
100
Alexandre Julliarda3960291999-02-26 11:11:13 +0000101HANDLE PSDRV_Heap = 0;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000102
Alexandre Julliarda3960291999-02-26 11:11:13 +0000103static HANDLE PSDRV_DefaultFont = 0;
104static LOGFONTA DefaultLogFont = {
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000105 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
106 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
107};
108
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000109/*********************************************************************
Alexandre Julliard1e1313d2002-11-04 23:53:41 +0000110 * DllMain
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000111 *
Alexandre Julliard1e1313d2002-11-04 23:53:41 +0000112 * Initializes font metrics and registers driver. wineps dll entry point.
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000113 *
114 */
Alexandre Julliard1e1313d2002-11-04 23:53:41 +0000115BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000116{
Alexandre Julliardb34fb352002-10-18 23:48:57 +0000117 TRACE("(%p, 0x%08lx, %p)\n", hinst, reason, reserved);
Vincent Béron9a624912002-05-31 23:06:46 +0000118
Dimitrie O. Paun84bde6a2000-05-30 20:27:23 +0000119 switch(reason) {
Ian Pilcher2ce7bc82001-04-30 18:17:13 +0000120
Dimitrie O. Paun84bde6a2000-05-30 20:27:23 +0000121 case DLL_PROCESS_ATTACH:
Ian Pilcher2ce7bc82001-04-30 18:17:13 +0000122
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 Meissnerf061f762002-11-12 02:22:24 +0000137#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 Pilcher2ce7bc82001-04-30 18:17:13 +0000144 break;
145
Dimitrie O. Paun84bde6a2000-05-30 20:27:23 +0000146 case DLL_PROCESS_DETACH:
Ian Pilcher2ce7bc82001-04-30 18:17:13 +0000147
148 DeleteObject( PSDRV_DefaultFont );
149 HeapDestroy( PSDRV_Heap );
Marcus Meissnerf061f762002-11-12 02:22:24 +0000150#ifdef HAVE_CUPS_CUPS_H
151 if (cupshandle && (cupshandle != (void*)-1)) {
152 wine_dlclose(cupshandle, NULL, 0);
153 cupshandle = NULL;
154 }
155#endif
Ian Pilcher2ce7bc82001-04-30 18:17:13 +0000156 break;
Dimitrie O. Paun84bde6a2000-05-30 20:27:23 +0000157 }
Vincent Béron9a624912002-05-31 23:06:46 +0000158
Dimitrie O. Paun84bde6a2000-05-30 20:27:23 +0000159 return TRUE;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000160}
161
Dimitrie O. Paun84bde6a2000-05-30 20:27:23 +0000162
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000163static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
164{
165 PAGESIZE *page;
166 INT width = 0, height = 0;
Vincent Béron9a624912002-05-31 23:06:46 +0000167
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000168 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 Julliardebfc0fe1998-06-28 18:40:26 +0000251/**********************************************************************
252 * PSDRV_CreateDC
253 */
Alexandre Julliardd3cab182002-06-10 22:52:47 +0000254BOOL PSDRV_CreateDC( DC *dc, PSDRV_PDEVICE **pdev, LPCSTR driver, LPCSTR device,
Alexandre Julliard3dd63eb2001-07-27 19:37:31 +0000255 LPCSTR output, const DEVMODEA* initData )
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000256{
257 PSDRV_PDEVICE *physDev;
Noel Borthwick86b686f1999-06-05 08:52:30 +0000258 PRINTERINFO *pi;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000259
Noel Borthwick86b686f1999-06-05 08:52:30 +0000260 /* If no device name was specified, retrieve the device name
261 * from the DEVMODE structure from the DC's physDev.
262 * (See CreateCompatibleDC) */
Alexandre Julliardd3cab182002-06-10 22:52:47 +0000263 if ( !device && *pdev )
Noel Borthwick86b686f1999-06-05 08:52:30 +0000264 {
Alexandre Julliardd3cab182002-06-10 22:52:47 +0000265 physDev = *pdev;
Noel Borthwick86b686f1999-06-05 08:52:30 +0000266 device = physDev->Devmode->dmPublic.dmDeviceName;
267 }
268 pi = PSDRV_FindPrinterInfo(device);
Vincent Béron9a624912002-05-31 23:06:46 +0000269
Alexandre Julliard61fece01999-06-26 19:09:08 +0000270 TRACE("(%s %s %s %p)\n", driver, device, output, initData);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000271
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000272 if(!pi) return FALSE;
273
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000274 if(!pi->Fonts) {
Alexandre Julliard61fece01999-06-26 19:09:08 +0000275 MESSAGE("To use WINEPS you need to install some AFM files.\n");
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000276 return FALSE;
277 }
278
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000279 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000280 sizeof(*physDev) );
281 if (!physDev) return FALSE;
Alexandre Julliardd3cab182002-06-10 22:52:47 +0000282 *pdev = physDev;
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000283 physDev->hdc = dc->hSelf;
284 physDev->dc = dc;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000285
286 physDev->pi = pi;
287
Huw D M Daviese39b6761999-05-17 16:20:51 +0000288 physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0,
289 sizeof(PSDRV_DEVMODEA) );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000290 if(!physDev->Devmode) {
291 HeapFree( PSDRV_Heap, 0, physDev );
292 return FALSE;
293 }
Vincent Béron9a624912002-05-31 23:06:46 +0000294
Huw D M Daviese39b6761999-05-17 16:20:51 +0000295 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000296
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000297 physDev->logPixelsX = physDev->pi->ppd->DefaultResolution;
298 physDev->logPixelsY = physDev->pi->ppd->DefaultResolution;
Huw D M Daviesd4b933e2001-01-28 23:13:45 +0000299
Alexandre Julliard5f728ca2001-07-24 21:45:22 +0000300 if (!output) output = "LPT1:"; /* HACK */
301 physDev->job.output = HeapAlloc( PSDRV_Heap, 0, strlen(output)+1 );
302 strcpy( physDev->job.output, output );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000303 physDev->job.hJob = 0;
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000304
305 if(initData) {
306 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)initData, pi);
307 }
308
309 PSDRV_UpdateDevCaps(physDev);
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000310 dc->hFont = PSDRV_DefaultFont;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000311 return TRUE;
312}
313
314
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000315
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000316/**********************************************************************
317 * PSDRV_DeleteDC
318 */
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000319BOOL PSDRV_DeleteDC( PSDRV_PDEVICE *physDev )
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000320{
Alexandre Julliard61fece01999-06-26 19:09:08 +0000321 TRACE("\n");
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000322
323 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
324 HeapFree( PSDRV_Heap, 0, physDev->job.output );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000325 HeapFree( PSDRV_Heap, 0, physDev );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000326
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000327 return TRUE;
328}
329
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000330
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000331/**********************************************************************
332 * ResetDC (WINEPS.@)
Alexandre Julliard92083012001-07-29 20:25:14 +0000333 */
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000334HDC PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEA *lpInitData )
Alexandre Julliard92083012001-07-29 20:25:14 +0000335{
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000336 if(lpInitData) {
337 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)lpInitData, physDev->pi);
338 PSDRV_UpdateDevCaps(physDev);
Alexandre Julliard92083012001-07-29 20:25:14 +0000339 }
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000340 return physDev->hdc;
Alexandre Julliard92083012001-07-29 20:25:14 +0000341}
342
Alexandre Julliard92083012001-07-29 20:25:14 +0000343/***********************************************************************
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000344 * GetDeviceCaps (WINEPS.@)
345 */
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000346INT PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap )
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000347{
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000348 switch(cap)
349 {
350 case DRIVERVERSION:
351 return 0;
352 case TECHNOLOGY:
353 return DT_RASPRINTER;
354 case HORZSIZE:
Huw D M Davies7a6ea912002-06-24 23:41:55 +0000355 return MulDiv(physDev->horzSize, 100,
356 physDev->Devmode->dmPublic.dmScale);
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000357 case VERTSIZE:
Huw D M Davies7a6ea912002-06-24 23:41:55 +0000358 return MulDiv(physDev->vertSize, 100,
359 physDev->Devmode->dmPublic.dmScale);
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000360 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 Daviesb88f7242002-04-06 00:12:42 +0000390 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000391 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 Davies7a6ea912002-06-24 23:41:55 +0000405 return MulDiv(physDev->logPixelsX,
406 physDev->Devmode->dmPublic.dmScale, 100);
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000407 case LOGPIXELSY:
Huw D M Davies7a6ea912002-06-24 23:41:55 +0000408 return MulDiv(physDev->logPixelsY,
409 physDev->Devmode->dmPublic.dmScale, 100);
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000410 case SIZEPALETTE:
411 return 0;
412 case NUMRESERVED:
413 return 0;
414 case COLORRES:
415 return 0;
416 case PHYSICALWIDTH:
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000417 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
418 physDev->PageSize.cy : physDev->PageSize.cx;
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000419 case PHYSICALHEIGHT:
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000420 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
421 physDev->PageSize.cx : physDev->PageSize.cy;
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000422 case PHYSICALOFFSETX:
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000423 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 Julliard99bb9f92001-07-28 00:18:02 +0000431 case PHYSICALOFFSETY:
Huw D M Daviesb88f7242002-04-06 00:12:42 +0000432 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 Julliard99bb9f92001-07-28 00:18:02 +0000440 case SCALINGFACTORX:
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000441 case SCALINGFACTORY:
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000442 case VREFRESH:
443 case DESKTOPVERTRES:
444 case DESKTOPHORZRES:
445 case BTLALIGNMENT:
446 return 0;
447 default:
Alexandre Julliardb34fb352002-10-18 23:48:57 +0000448 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
Alexandre Julliard99bb9f92001-07-28 00:18:02 +0000449 return 0;
450 }
451}
452
453
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000454/**********************************************************************
455 * PSDRV_FindPrinterInfo
456 */
Vincent Béron9a624912002-05-31 23:06:46 +0000457PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000458{
459 static PRINTERINFO *PSDRV_PrinterList;
Ian Pilcher744820d2001-04-02 19:14:41 +0000460 DWORD type = REG_BINARY, needed, res, dwPaperSize;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000461 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
462 FONTNAME *font;
Ian Pilcher4bc1ebb52001-07-24 20:52:19 +0000463 const AFM *afm;
Ian Pilcher744820d2001-04-02 19:14:41 +0000464 HANDLE hPrinter;
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000465 const char *ppd = NULL;
Francois Gougetf101e272001-10-22 19:00:08 +0000466 DWORD ppdType;
467 char* ppdFileName = NULL;
Dmitry Timoshkov043f6402001-07-02 18:00:33 +0000468 HKEY hkey;
Huw D M Davies933733c2002-08-15 23:20:19 +0000469 BOOL using_default_devmode = FALSE;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000470
Alexandre Julliard61fece01999-06-26 19:09:08 +0000471 TRACE("'%s'\n", name);
Vincent Béron9a624912002-05-31 23:06:46 +0000472
Ian Pilcher91857a62001-05-03 18:34:27 +0000473 /*
474 * If this loop completes, last will point to the 'next' element of the
475 * final PRINTERINFO in the list
Vincent Béron9a624912002-05-31 23:06:46 +0000476 */
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000477 for( ; pi; last = &pi->next, pi = pi->next)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000478 if(!strcmp(pi->FriendlyName, name))
479 return pi;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000480
Ian Pilcher91857a62001-05-03 18:34:27 +0000481 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
482 if (pi == NULL)
483 return NULL;
Alexandre Julliard5f728ca2001-07-24 21:45:22 +0000484
485 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
486 strcpy( pi->FriendlyName, name );
487
Ian Pilcher91857a62001-05-03 18:34:27 +0000488 /* Use Get|SetPrinterDataExA instead? */
Vincent Béron9a624912002-05-31 23:06:46 +0000489
Alexandre Julliarda3960291999-02-26 11:11:13 +0000490 res = DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000491 NULL, 0, &needed );
492
Huw D M Davies450270b1999-07-10 11:58:50 +0000493 if(res == ERROR_INVALID_PRINTER_NAME || needed != sizeof(DefaultDevmode)) {
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000494 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
Ian Pilcher91857a62001-05-03 18:34:27 +0000495 if (pi->Devmode == NULL)
Vincent Béron9a624912002-05-31 23:06:46 +0000496 goto cleanup;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000497 memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) );
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000498 strcpy(pi->Devmode->dmPublic.dmDeviceName,name);
Huw D M Davies933733c2002-08-15 23:20:19 +0000499 using_default_devmode = TRUE;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000500
501 /* need to do something here AddPrinter?? */
Ian Pilcher91857a62001-05-03 18:34:27 +0000502 }
503 else {
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000504 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000505 DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000506 (LPBYTE)pi->Devmode, needed, &needed);
507 }
508
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000509 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
Ian Pilcher744820d2001-04-02 19:14:41 +0000510 ERR ("OpenPrinterA failed with code %li\n", GetLastError ());
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000511 goto cleanup;
Ian Pilcher744820d2001-04-02 19:14:41 +0000512 }
Francois Gougetf101e272001-10-22 19:00:08 +0000513
Marcus Meissnerf061f762002-11-12 02:22:24 +0000514#ifdef HAVE_CUPS_CUPS_H
515 if (cupshandle != (void*)-1) {
516 typeof(cupsGetPPD) * pcupsGetPPD = NULL;
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000517
Marcus Meissnerf061f762002-11-12 02:22:24 +0000518 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 Meissnerab8b7db2001-04-27 18:02:46 +0000533 }
534 }
535#endif
Francois Gougetf101e272001-10-22 19:00:08 +0000536 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 Meissnerab8b7db2001-04-27 18:02:46 +0000542 }
Marcus Meissner0c630122001-05-09 17:10:41 +0000543 /* Look for a ppd file for this printer in the config file.
Francois Gougetf101e272001-10-22 19:00:08 +0000544 * First look under that printer's name, and then under 'generic'
Marcus Meissner0c630122001-05-09 17:10:41 +0000545 */
Dmitry Timoshkov043f6402001-07-02 18:00:33 +0000546 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey))
547 {
Francois Gougetf101e272001-10-22 19:00:08 +0000548 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 Timoshkov043f6402001-07-02 18:00:33 +0000562 }
563
Francois Gougetf101e272001-10-22 19:00:08 +0000564 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 Meissner0c630122001-05-09 17:10:41 +0000572
Francois Gougetf101e272001-10-22 19:00:08 +0000573 /* 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 Pilcher744820d2001-04-02 19:14:41 +0000580 }
Francois Gougetf101e272001-10-22 19:00:08 +0000581
Ian Pilcher91857a62001-05-03 18:34:27 +0000582 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 Gougetf101e272001-10-22 19:00:08 +0000588
Huw D M Davies933733c2002-08-15 23:20:19 +0000589
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 Pilcher91857a62001-05-03 18:34:27 +0000606 /*
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 Pilcher744820d2001-04-02 19:14:41 +0000611 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 Meissnerab8b7db2001-04-27 18:02:46 +0000617 else {
Ian Pilcher744820d2001-04-02 19:14:41 +0000618 ERR ("GetPrinterDataA returned %li\n", res);
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000619 goto closeprinter;
Ian Pilcher744820d2001-04-02 19:14:41 +0000620 }
621
622 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL,
623 0, &needed, &pi->FontSubTableSize);
Ian Pilcher91857a62001-05-03 18:34:27 +0000624 if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) {
Ian Pilcher744820d2001-04-02 19:14:41 +0000625 TRACE ("No 'FontSubTable' for printer '%s'\n", name);
Ian Pilcher91857a62001-05-03 18:34:27 +0000626 }
627 else if (res == ERROR_MORE_DATA) {
Ian Pilcher744820d2001-04-02 19:14:41 +0000628 pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed);
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000629 if (pi->FontSubTable == NULL) {
Ian Pilcher744820d2001-04-02 19:14:41 +0000630 ERR ("Failed to allocate %li bytes from heap\n", needed);
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000631 goto closeprinter;
Ian Pilcher744820d2001-04-02 19:14:41 +0000632 }
633
634 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable",
635 (LPBYTE) pi->FontSubTable, needed, &needed,
636 &pi->FontSubTableSize);
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000637 if (res != ERROR_SUCCESS) {
Ian Pilcher744820d2001-04-02 19:14:41 +0000638 ERR ("EnumPrinterDataExA returned %li\n", res);
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000639 goto closeprinter;
Ian Pilcher744820d2001-04-02 19:14:41 +0000640 }
Ian Pilcher91857a62001-05-03 18:34:27 +0000641 }
642 else {
643 ERR("EnumPrinterDataExA returned %li\n", res);
644 goto closeprinter;
Ian Pilcher744820d2001-04-02 19:14:41 +0000645 }
646
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000647 if (ClosePrinter (hPrinter) == 0) {
Ian Pilcher744820d2001-04-02 19:14:41 +0000648 ERR ("ClosePrinter failed with code %li\n", GetLastError ());
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000649 goto cleanup;
Ian Pilcher744820d2001-04-02 19:14:41 +0000650 }
651
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000652 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 Pilcher91857a62001-05-03 18:34:27 +0000657 if(!afm) {
658 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
659 "ignoring\n", font->Name);
660 }
661 else {
Ian Pilcher42e052d2001-07-26 21:42:45 +0000662 BOOL added;
663 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
Ian Pilcher91857a62001-05-03 18:34:27 +0000664 PSDRV_FreeAFMList(pi->Fonts);
665 goto cleanup;
666 }
667 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000668
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000669 }
670 if (ppd) unlink(ppd);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000671 return pi;
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000672
673closeprinter:
674 ClosePrinter(hPrinter);
675cleanup:
Francois Gougetf101e272001-10-22 19:00:08 +0000676 if (ppdFileName)
677 HeapFree(PSDRV_Heap, 0, ppdFileName);
Ian Pilcher91857a62001-05-03 18:34:27 +0000678 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);
684fail:
Marcus Meissnerab8b7db2001-04-27 18:02:46 +0000685 HeapFree(PSDRV_Heap, 0, pi);
686 if (ppd) unlink(ppd);
687 *last = NULL;
688 return NULL;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000689}