2 * PostScript driver initialization functions
4 * Copyright 1998 Huw D M Davies
5 * Copyright 2001 Marcus Meissner
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
30 #ifdef HAVE_CUPS_CUPS_H
31 # include <cups/cups.h>
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
44 #include "wine/library.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
50 static void *cupshandle
= NULL
;
53 static const PSDRV_DEVMODEA DefaultDevmode
=
56 /* dmDeviceName */ "Wine PostScript Driver",
57 /* dmSpecVersion */ 0x30a,
58 /* dmDriverVersion */ 0x001,
59 /* dmSize */ sizeof(DEVMODEA
),
60 /* dmDriverExtra */ sizeof(PSDRV_DEVMODEA
)-sizeof(DEVMODEA
),
61 /* dmFields */ DM_ORIENTATION
| DM_PAPERSIZE
| DM_SCALE
|
62 DM_COPIES
| DM_DEFAULTSOURCE
| DM_COLOR
|
63 DM_YRESOLUTION
| DM_TTOPTION
,
66 /* dmOrientation */ DMORIENT_PORTRAIT
,
67 /* dmPaperSize */ DMPAPER_LETTER
,
68 /* dmPaperLength */ 2794,
69 /* dmPaperWidth */ 2159,
70 /* dmScale */ 100, /* ?? */
72 /* dmDefaultSource */ DMBIN_AUTO
,
73 /* dmPrintQuality */ 0
76 /* dmColor */ DMCOLOR_COLOR
,
77 /* dmDuplex */ DMDUP_SIMPLEX
,
78 /* dmYResolution */ 0,
79 /* dmTTOption */ DMTT_SUBDEV
,
82 /* dmUnusedPadding */ 0,
87 /* dmDisplayFlags */ 0
89 /* dmDisplayFrequency */ 0,
96 /* dmPanningWidth */ 0,
97 /* dmPanningHeight */ 0
103 /* numInstalledOptions */ 0
107 HINSTANCE PSDRV_hInstance
= 0;
108 HANDLE PSDRV_Heap
= 0;
110 static HFONT PSDRV_DefaultFont
= 0;
111 static const LOGFONTA DefaultLogFont
= {
112 100, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
, 0, 0,
113 DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, ""
116 static const CHAR default_devmodeA
[] = "Default DevMode";
118 /*********************************************************************
121 * Initializes font metrics and registers driver. wineps dll entry point.
124 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
126 TRACE("(%p, %d, %p)\n", hinst
, reason
, reserved
);
130 case DLL_PROCESS_ATTACH
:
131 PSDRV_hInstance
= hinst
;
132 DisableThreadLibraryCalls(hinst
);
134 PSDRV_Heap
= HeapCreate(0, 0x10000, 0);
135 if (PSDRV_Heap
== NULL
)
138 if (PSDRV_GetFontMetrics() == FALSE
) {
139 HeapDestroy(PSDRV_Heap
);
143 PSDRV_DefaultFont
= CreateFontIndirectA(&DefaultLogFont
);
144 if (PSDRV_DefaultFont
== NULL
) {
145 HeapDestroy(PSDRV_Heap
);
148 #ifdef SONAME_LIBCUPS
149 /* dynamically load CUPS if not yet loaded */
151 cupshandle
= wine_dlopen(SONAME_LIBCUPS
, RTLD_NOW
, NULL
, 0);
152 if (!cupshandle
) cupshandle
= (void*)-1;
157 case DLL_PROCESS_DETACH
:
159 DeleteObject( PSDRV_DefaultFont
);
160 HeapDestroy( PSDRV_Heap
);
161 #ifdef SONAME_LIBCUPS
162 if (cupshandle
&& (cupshandle
!= (void*)-1)) {
163 wine_dlclose(cupshandle
, NULL
, 0);
174 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE
*physDev
)
177 INT width
= 0, height
= 0;
179 if(physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERSIZE
) {
180 LIST_FOR_EACH_ENTRY(page
, &physDev
->pi
->ppd
->PageSizes
, PAGESIZE
, entry
) {
181 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
)
185 if(&page
->entry
== &physDev
->pi
->ppd
->PageSizes
) {
186 FIXME("Can't find page\n");
187 physDev
->ImageableArea
.left
= 0;
188 physDev
->ImageableArea
.right
= 0;
189 physDev
->ImageableArea
.bottom
= 0;
190 physDev
->ImageableArea
.top
= 0;
191 physDev
->PageSize
.cx
= 0;
192 physDev
->PageSize
.cy
= 0;
193 } else if(page
->ImageableArea
) {
194 /* physDev sizes in device units; ppd sizes in 1/72" */
195 physDev
->ImageableArea
.left
= page
->ImageableArea
->llx
*
196 physDev
->logPixelsX
/ 72;
197 physDev
->ImageableArea
.right
= page
->ImageableArea
->urx
*
198 physDev
->logPixelsX
/ 72;
199 physDev
->ImageableArea
.bottom
= page
->ImageableArea
->lly
*
200 physDev
->logPixelsY
/ 72;
201 physDev
->ImageableArea
.top
= page
->ImageableArea
->ury
*
202 physDev
->logPixelsY
/ 72;
203 physDev
->PageSize
.cx
= page
->PaperDimension
->x
*
204 physDev
->logPixelsX
/ 72;
205 physDev
->PageSize
.cy
= page
->PaperDimension
->y
*
206 physDev
->logPixelsY
/ 72;
208 physDev
->ImageableArea
.left
= physDev
->ImageableArea
.bottom
= 0;
209 physDev
->ImageableArea
.right
= physDev
->PageSize
.cx
=
210 page
->PaperDimension
->x
* physDev
->logPixelsX
/ 72;
211 physDev
->ImageableArea
.top
= physDev
->PageSize
.cy
=
212 page
->PaperDimension
->y
* physDev
->logPixelsY
/ 72;
214 } else if((physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERLENGTH
) &&
215 (physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERWIDTH
)) {
216 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
217 physDev
->ImageableArea
.left
= physDev
->ImageableArea
.bottom
= 0;
218 physDev
->ImageableArea
.right
= physDev
->PageSize
.cx
=
219 physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
*
220 physDev
->logPixelsX
/ 254;
221 physDev
->ImageableArea
.top
= physDev
->PageSize
.cy
=
222 physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
*
223 physDev
->logPixelsY
/ 254;
225 FIXME("Odd dmFields %x\n", physDev
->Devmode
->dmPublic
.dmFields
);
226 physDev
->ImageableArea
.left
= 0;
227 physDev
->ImageableArea
.right
= 0;
228 physDev
->ImageableArea
.bottom
= 0;
229 physDev
->ImageableArea
.top
= 0;
230 physDev
->PageSize
.cx
= 0;
231 physDev
->PageSize
.cy
= 0;
234 TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %dx%d\n",
235 physDev
->ImageableArea
.left
, physDev
->ImageableArea
.bottom
,
236 physDev
->ImageableArea
.right
, physDev
->ImageableArea
.top
,
237 physDev
->PageSize
.cx
, physDev
->PageSize
.cy
);
239 /* these are in device units */
240 width
= physDev
->ImageableArea
.right
- physDev
->ImageableArea
.left
;
241 height
= physDev
->ImageableArea
.top
- physDev
->ImageableArea
.bottom
;
243 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
) {
244 physDev
->horzRes
= width
;
245 physDev
->vertRes
= height
;
247 physDev
->horzRes
= height
;
248 physDev
->vertRes
= width
;
251 /* these are in mm */
252 physDev
->horzSize
= (physDev
->horzRes
* 25.4) / physDev
->logPixelsX
;
253 physDev
->vertSize
= (physDev
->vertRes
* 25.4) / physDev
->logPixelsY
;
255 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
256 "horzRes = %d, vertRes = %d\n",
257 physDev
->horzSize
, physDev
->vertSize
,
258 physDev
->horzRes
, physDev
->vertRes
);
262 /***********************************************************
265 * Creates an ascii copy of supplied devmode on heap
267 * Copied from dlls/winspool/info.c until full unicodification
269 static LPDEVMODEA
DEVMODEdupWtoA(HANDLE heap
, const DEVMODEW
*dmW
)
274 ptrdiff_t off_formname
= (const char *)dmW
->dmFormName
- (const char *)dmW
;
276 if(!dmW
) return NULL
;
277 Formname
= (dmW
->dmSize
> off_formname
);
278 size
= dmW
->dmSize
- CCHDEVICENAME
- (Formname
? CCHFORMNAME
: 0);
279 dmA
= HeapAlloc(heap
, HEAP_ZERO_MEMORY
, size
+ dmW
->dmDriverExtra
);
280 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1, (LPSTR
)dmA
->dmDeviceName
,
281 CCHDEVICENAME
, NULL
, NULL
);
283 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
284 dmW
->dmSize
- CCHDEVICENAME
* sizeof(WCHAR
));
286 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
287 off_formname
- CCHDEVICENAME
* sizeof(WCHAR
));
288 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1, (LPSTR
)dmA
->dmFormName
,
289 CCHFORMNAME
, NULL
, NULL
);
290 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
-
291 (off_formname
+ CCHFORMNAME
* sizeof(WCHAR
)));
294 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
,
300 /**********************************************************************
303 BOOL CDECL
PSDRV_CreateDC( HDC hdc
, PSDRV_PDEVICE
**pdev
, LPCWSTR driver
, LPCWSTR device
,
304 LPCWSTR output
, const DEVMODEW
* initData
)
306 PSDRV_PDEVICE
*physDev
;
309 /* If no device name was specified, retrieve the device name
310 * from the PRINTERINFO structure from the DC's physDev.
311 * (See CreateCompatibleDC) */
312 if ( !device
&& *pdev
)
314 pi
= PSDRV_FindPrinterInfo((*pdev
)->pi
->FriendlyName
);
318 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, device
, -1, NULL
, 0, NULL
, NULL
);
319 char *deviceA
= HeapAlloc(GetProcessHeap(), 0, len
);
320 WideCharToMultiByte(CP_ACP
, 0, device
, -1, deviceA
, len
, NULL
, NULL
);
321 pi
= PSDRV_FindPrinterInfo(deviceA
);
322 HeapFree(GetProcessHeap(), 0, deviceA
);
325 TRACE("(%s %s %s %p)\n", debugstr_w(driver
), debugstr_w(device
),
326 debugstr_w(output
), initData
);
328 if(!pi
) return FALSE
;
331 RASTERIZER_STATUS status
;
332 if(!GetRasterizerCaps(&status
, sizeof(status
)) ||
333 !(status
.wFlags
& TT_AVAILABLE
) ||
334 !(status
.wFlags
& TT_ENABLED
)) {
335 MESSAGE("Disabling printer %s since it has no builtin fonts and there are no TrueType fonts available.\n",
341 physDev
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*physDev
) );
342 if (!physDev
) return FALSE
;
348 physDev
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(PSDRV_DEVMODEA
) );
349 if(!physDev
->Devmode
) {
350 HeapFree( PSDRV_Heap
, 0, physDev
);
354 *physDev
->Devmode
= *pi
->Devmode
;
356 physDev
->logPixelsX
= physDev
->pi
->ppd
->DefaultResolution
;
357 physDev
->logPixelsY
= physDev
->pi
->ppd
->DefaultResolution
;
359 if (output
&& *output
) {
360 INT len
= WideCharToMultiByte( CP_ACP
, 0, output
, -1, NULL
, 0, NULL
, NULL
);
361 if ((physDev
->job
.output
= HeapAlloc( PSDRV_Heap
, 0, len
)))
362 WideCharToMultiByte( CP_ACP
, 0, output
, -1, physDev
->job
.output
, len
, NULL
, NULL
);
364 physDev
->job
.output
= NULL
;
368 DEVMODEA
*devmodeA
= DEVMODEdupWtoA(PSDRV_Heap
, initData
);
369 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)devmodeA
, pi
);
370 HeapFree(PSDRV_Heap
, 0, devmodeA
);
373 PSDRV_UpdateDevCaps(physDev
);
374 SelectObject( hdc
, PSDRV_DefaultFont
);
380 /**********************************************************************
383 BOOL CDECL
PSDRV_DeleteDC( PSDRV_PDEVICE
*physDev
)
387 HeapFree( PSDRV_Heap
, 0, physDev
->Devmode
);
388 HeapFree( PSDRV_Heap
, 0, physDev
->job
.output
);
389 HeapFree( PSDRV_Heap
, 0, physDev
);
395 /**********************************************************************
398 HDC CDECL
PSDRV_ResetDC( PSDRV_PDEVICE
*physDev
, const DEVMODEW
*lpInitData
)
401 DEVMODEA
*devmodeA
= DEVMODEdupWtoA(PSDRV_Heap
, lpInitData
);
402 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)devmodeA
, physDev
->pi
);
403 HeapFree(PSDRV_Heap
, 0, devmodeA
);
404 PSDRV_UpdateDevCaps(physDev
);
409 /***********************************************************************
410 * GetDeviceCaps (WINEPS.@)
412 INT CDECL
PSDRV_GetDeviceCaps( PSDRV_PDEVICE
*physDev
, INT cap
)
419 return DT_RASPRINTER
;
421 return MulDiv(physDev
->horzSize
, 100,
422 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
);
424 return MulDiv(physDev
->vertSize
, 100,
425 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
);
428 return physDev
->horzRes
;
431 return physDev
->vertRes
;
433 return (physDev
->pi
->ppd
->ColorDevice
!= CD_False
) ? 8 : 1;
445 return (physDev
->pi
->ppd
->ColorDevice
!= CD_False
) ? 256 : -1;
447 return sizeof(PSDRV_PDEVICE
);
449 return (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
450 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
452 return (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
453 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
455 return (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
456 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
458 return TC_CR_ANY
| TC_VA_ABLE
; /* psdrv 0x59f7 */
462 return (RC_BITBLT
| RC_BITMAP64
| RC_GDI20_OUTPUT
| RC_DIBTODEV
|
463 RC_STRETCHBLT
| RC_STRETCHDIB
); /* psdrv 0x6e99 */
464 /* Are aspect[XY] and logPixels[XY] correct? */
465 /* Need to handle different res in x and y => fix ppd */
468 return physDev
->pi
->ppd
->DefaultResolution
;
470 return (int)hypot( (double)physDev
->pi
->ppd
->DefaultResolution
,
471 (double)physDev
->pi
->ppd
->DefaultResolution
);
473 return MulDiv(physDev
->logPixelsX
,
474 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
, 100);
476 return MulDiv(physDev
->logPixelsY
,
477 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
, 100);
485 return (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) ?
486 physDev
->PageSize
.cy
: physDev
->PageSize
.cx
;
488 return (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) ?
489 physDev
->PageSize
.cx
: physDev
->PageSize
.cy
;
490 case PHYSICALOFFSETX
:
491 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
492 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90)
493 return physDev
->PageSize
.cy
- physDev
->ImageableArea
.top
;
495 return physDev
->ImageableArea
.bottom
;
497 return physDev
->ImageableArea
.left
;
499 case PHYSICALOFFSETY
:
500 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
501 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90)
502 return physDev
->PageSize
.cx
- physDev
->ImageableArea
.right
;
504 return physDev
->ImageableArea
.left
;
506 return physDev
->PageSize
.cy
- physDev
->ImageableArea
.top
;
514 FIXME("(%p): unsupported capability %d, will return 0\n", physDev
->hdc
, cap
);
520 /**********************************************************************
521 * PSDRV_FindPrinterInfo
523 PRINTERINFO
*PSDRV_FindPrinterInfo(LPCSTR name
)
525 static PRINTERINFO
*PSDRV_PrinterList
;
526 DWORD type
= REG_BINARY
, needed
, res
, dwPaperSize
;
527 PRINTERINFO
*pi
= PSDRV_PrinterList
, **last
= &PSDRV_PrinterList
;
531 const char *ppd
= NULL
;
533 char* ppdFileName
= NULL
;
535 BOOL using_default_devmode
= FALSE
;
537 TRACE("'%s'\n", name
);
540 * If this loop completes, last will point to the 'next' element of the
541 * final PRINTERINFO in the list
543 for( ; pi
; last
= &pi
->next
, pi
= pi
->next
)
544 if(!strcmp(pi
->FriendlyName
, name
))
547 pi
= *last
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*pi
) );
551 if (!(pi
->FriendlyName
= HeapAlloc( PSDRV_Heap
, 0, strlen(name
)+1 ))) goto fail
;
552 strcpy( pi
->FriendlyName
, name
);
554 if (OpenPrinterA (pi
->FriendlyName
, &hPrinter
, NULL
) == 0) {
555 ERR ("OpenPrinterA failed with code %i\n", GetLastError ());
560 res
= GetPrinterDataExA(hPrinter
, NULL
, default_devmodeA
, &type
, NULL
, 0, &needed
);
562 if (needed
< sizeof(DefaultDevmode
)) {
563 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(DefaultDevmode
) );
564 if (pi
->Devmode
== NULL
)
567 *pi
->Devmode
= DefaultDevmode
;
568 lstrcpynA((LPSTR
)pi
->Devmode
->dmPublic
.dmDeviceName
,name
,CCHDEVICENAME
);
569 using_default_devmode
= TRUE
;
572 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, needed
);
573 if (pi
->Devmode
== NULL
)
576 GetPrinterDataExA(hPrinter
, NULL
, default_devmodeA
, &type
, (LPBYTE
)pi
->Devmode
, needed
, &needed
);
581 #ifdef SONAME_LIBCUPS
582 if (cupshandle
!= (void*)-1) {
583 typeof(cupsGetPPD
) * pcupsGetPPD
= NULL
;
585 pcupsGetPPD
= wine_dlsym(cupshandle
, "cupsGetPPD", NULL
, 0);
587 ppd
= pcupsGetPPD(name
);
590 needed
=strlen(ppd
)+1;
591 ppdFileName
=HeapAlloc(PSDRV_Heap
, 0, needed
);
592 memcpy(ppdFileName
, ppd
, needed
);
595 /* we should unlink() that file later */
597 res
= ERROR_FILE_NOT_FOUND
;
598 WARN("Did not find ppd for %s\n",name
);
604 res
= GetPrinterDataExA(hPrinter
, "PrinterDriverData", "PPD File", NULL
, NULL
, 0, &needed
);
605 if ((res
==ERROR_SUCCESS
) || (res
==ERROR_MORE_DATA
)) {
606 ppdFileName
=HeapAlloc(PSDRV_Heap
, 0, needed
);
607 res
= GetPrinterDataExA(hPrinter
, "PrinterDriverData", "PPD File", &ppdType
,
608 (LPBYTE
)ppdFileName
, needed
, &needed
);
611 /* Look for a ppd file for this printer in the config file.
612 * First look under that printer's name, and then under 'generic'
614 /* @@ Wine registry key: HKCU\Software\Wine\Printing\PPD Files */
615 if((res
!= ERROR_SUCCESS
) && !RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Printing\\PPD Files", &hkey
))
617 const char* value_name
;
619 if (RegQueryValueExA(hkey
, name
, 0, NULL
, NULL
, &needed
) == ERROR_SUCCESS
) {
621 } else if (RegQueryValueExA(hkey
, "generic", 0, NULL
, NULL
, &needed
) == ERROR_SUCCESS
) {
622 value_name
="generic";
627 HeapFree(PSDRV_Heap
, 0, ppdFileName
);
628 ppdFileName
=HeapAlloc(PSDRV_Heap
, 0, needed
);
629 RegQueryValueExA(hkey
, value_name
, 0, &ppdType
, (LPBYTE
)ppdFileName
, &needed
);
636 const char *data_dir
, *filename
;
638 if ((data_dir
= wine_get_data_dir())) filename
= "/generic.ppd";
639 else if ((data_dir
= wine_get_build_dir())) filename
= "/dlls/wineps.drv/generic.ppd";
642 res
= ERROR_FILE_NOT_FOUND
;
643 ERR ("Error %i getting PPD file name for printer '%s'\n", res
, name
);
646 ppdFileName
= HeapAlloc( PSDRV_Heap
, 0, strlen(data_dir
) + strlen(filename
) + 1 );
647 strcpy( ppdFileName
, data_dir
);
648 strcat( ppdFileName
, filename
);
651 if (ppdType
==REG_EXPAND_SZ
) {
654 /* Expand environment variable references */
655 needed
=ExpandEnvironmentStringsA(ppdFileName
,NULL
,0);
656 tmp
=HeapAlloc(PSDRV_Heap
, 0, needed
);
657 ExpandEnvironmentStringsA(ppdFileName
,tmp
,needed
);
658 HeapFree(PSDRV_Heap
, 0, ppdFileName
);
663 pi
->ppd
= PSDRV_ParsePPD(ppdFileName
);
665 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
670 /* Some gimp-print ppd files don't contain a DefaultResolution line
671 set it to 300 if it's not specified */
672 if(pi
->ppd
->DefaultResolution
== 0)
673 pi
->ppd
->DefaultResolution
= 300;
675 if(using_default_devmode
) {
678 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IPAPERSIZE
| LOCALE_RETURN_NUMBER
,
679 (LPWSTR
)&papersize
, sizeof(papersize
)/sizeof(WCHAR
))) {
681 memset(&dm
, 0, sizeof(dm
));
682 dm
.dmPublic
.dmFields
= DM_PAPERSIZE
;
683 dm
.dmPublic
.u1
.s1
.dmPaperSize
= papersize
;
684 PSDRV_MergeDevmodes(pi
->Devmode
, &dm
, pi
);
687 SetPrinterDataExA(hPrinter
, NULL
, default_devmodeA
, REG_BINARY
,
688 (LPBYTE
)pi
->Devmode
, sizeof(DefaultDevmode
));
691 if(pi
->ppd
->DefaultPageSize
) { /* We'll let the ppd override the devmode */
693 memset(&dm
, 0, sizeof(dm
));
694 dm
.dmPublic
.dmFields
= DM_PAPERSIZE
;
695 dm
.dmPublic
.u1
.s1
.dmPaperSize
= pi
->ppd
->DefaultPageSize
->WinPage
;
696 PSDRV_MergeDevmodes(pi
->Devmode
, &dm
, pi
);
700 * This is a hack. The default paper size should be read in as part of
701 * the Devmode structure, but Wine doesn't currently provide a convenient
702 * way to configure printers.
704 res
= GetPrinterDataExA(hPrinter
, "PrinterDriverData", "Paper Size", NULL
,
705 (LPBYTE
)&dwPaperSize
, sizeof(DWORD
), &needed
);
706 if (res
== ERROR_SUCCESS
)
707 pi
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
= (SHORT
) dwPaperSize
;
708 else if (res
== ERROR_FILE_NOT_FOUND
)
709 TRACE ("No 'Paper Size' for printer '%s'\n", name
);
711 ERR ("GetPrinterDataA returned %i\n", res
);
715 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
716 WinDuplex == 0 is a special case which means that the ppd has a
717 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
718 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
719 PSDRV_WriteHeader understands this and copes. */
720 pi
->Devmode
->dmPublic
.dmFields
&= ~DM_DUPLEX
;
721 if(pi
->ppd
->DefaultDuplex
) {
722 pi
->Devmode
->dmPublic
.dmDuplex
= pi
->ppd
->DefaultDuplex
->WinDuplex
;
723 if(pi
->Devmode
->dmPublic
.dmDuplex
!= 0)
724 pi
->Devmode
->dmPublic
.dmFields
|= DM_DUPLEX
;
726 pi
->Devmode
->dmPublic
.dmDuplex
= DMDUP_SIMPLEX
;
729 res
= EnumPrinterDataExA (hPrinter
, "PrinterDriverData\\FontSubTable", NULL
,
730 0, &needed
, &pi
->FontSubTableSize
);
731 if (res
== ERROR_SUCCESS
|| res
== ERROR_FILE_NOT_FOUND
) {
732 TRACE ("No 'FontSubTable' for printer '%s'\n", name
);
734 else if (res
== ERROR_MORE_DATA
) {
735 pi
->FontSubTable
= HeapAlloc (PSDRV_Heap
, 0, needed
);
736 if (pi
->FontSubTable
== NULL
) {
737 ERR ("Failed to allocate %i bytes from heap\n", needed
);
741 res
= EnumPrinterDataExA (hPrinter
, "PrinterDriverData\\FontSubTable",
742 (LPBYTE
) pi
->FontSubTable
, needed
, &needed
,
743 &pi
->FontSubTableSize
);
744 if (res
!= ERROR_SUCCESS
) {
745 ERR ("EnumPrinterDataExA returned %i\n", res
);
750 ERR("EnumPrinterDataExA returned %i\n", res
);
754 if (ClosePrinter (hPrinter
) == 0) {
755 ERR ("ClosePrinter failed with code %i\n", GetLastError ());
762 for(font
= pi
->ppd
->InstalledFonts
; font
; font
= font
->next
) {
763 afm
= PSDRV_FindAFMinList(PSDRV_AFMFontList
, font
->Name
);
765 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
766 "ignoring\n", font
->Name
);
770 if (PSDRV_AddAFMtoList(&pi
->Fonts
, afm
, &added
) == FALSE
) {
771 PSDRV_FreeAFMList(pi
->Fonts
);
777 if (ppd
) unlink(ppd
);
781 ClosePrinter(hPrinter
);
783 HeapFree(PSDRV_Heap
, 0, ppdFileName
);
784 HeapFree(PSDRV_Heap
, 0, pi
->FontSubTable
);
785 HeapFree(PSDRV_Heap
, 0, pi
->FriendlyName
);
786 HeapFree(PSDRV_Heap
, 0, pi
->Devmode
);
788 HeapFree(PSDRV_Heap
, 0, pi
);
789 if (ppd
) unlink(ppd
);