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";
117 static const struct gdi_dc_funcs psdrv_funcs
;
119 /*********************************************************************
122 * Initializes font metrics and registers driver. wineps dll entry point.
125 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
127 TRACE("(%p, %d, %p)\n", hinst
, reason
, reserved
);
131 case DLL_PROCESS_ATTACH
:
132 PSDRV_hInstance
= hinst
;
133 DisableThreadLibraryCalls(hinst
);
135 PSDRV_Heap
= HeapCreate(0, 0x10000, 0);
136 if (PSDRV_Heap
== NULL
)
139 if (PSDRV_GetFontMetrics() == FALSE
) {
140 HeapDestroy(PSDRV_Heap
);
144 PSDRV_DefaultFont
= CreateFontIndirectA(&DefaultLogFont
);
145 if (PSDRV_DefaultFont
== NULL
) {
146 HeapDestroy(PSDRV_Heap
);
149 #ifdef SONAME_LIBCUPS
150 /* dynamically load CUPS if not yet loaded */
152 cupshandle
= wine_dlopen(SONAME_LIBCUPS
, RTLD_NOW
, NULL
, 0);
153 if (!cupshandle
) cupshandle
= (void*)-1;
158 case DLL_PROCESS_DETACH
:
160 DeleteObject( PSDRV_DefaultFont
);
161 HeapDestroy( PSDRV_Heap
);
162 #ifdef SONAME_LIBCUPS
163 if (cupshandle
&& (cupshandle
!= (void*)-1)) {
164 wine_dlclose(cupshandle
, NULL
, 0);
175 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE
*physDev
)
178 INT width
= 0, height
= 0;
180 if(physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERSIZE
) {
181 LIST_FOR_EACH_ENTRY(page
, &physDev
->pi
->ppd
->PageSizes
, PAGESIZE
, entry
) {
182 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
)
186 if(&page
->entry
== &physDev
->pi
->ppd
->PageSizes
) {
187 FIXME("Can't find page\n");
188 physDev
->ImageableArea
.left
= 0;
189 physDev
->ImageableArea
.right
= 0;
190 physDev
->ImageableArea
.bottom
= 0;
191 physDev
->ImageableArea
.top
= 0;
192 physDev
->PageSize
.cx
= 0;
193 physDev
->PageSize
.cy
= 0;
194 } else if(page
->ImageableArea
) {
195 /* physDev sizes in device units; ppd sizes in 1/72" */
196 physDev
->ImageableArea
.left
= page
->ImageableArea
->llx
*
197 physDev
->logPixelsX
/ 72;
198 physDev
->ImageableArea
.right
= page
->ImageableArea
->urx
*
199 physDev
->logPixelsX
/ 72;
200 physDev
->ImageableArea
.bottom
= page
->ImageableArea
->lly
*
201 physDev
->logPixelsY
/ 72;
202 physDev
->ImageableArea
.top
= page
->ImageableArea
->ury
*
203 physDev
->logPixelsY
/ 72;
204 physDev
->PageSize
.cx
= page
->PaperDimension
->x
*
205 physDev
->logPixelsX
/ 72;
206 physDev
->PageSize
.cy
= page
->PaperDimension
->y
*
207 physDev
->logPixelsY
/ 72;
209 physDev
->ImageableArea
.left
= physDev
->ImageableArea
.bottom
= 0;
210 physDev
->ImageableArea
.right
= physDev
->PageSize
.cx
=
211 page
->PaperDimension
->x
* physDev
->logPixelsX
/ 72;
212 physDev
->ImageableArea
.top
= physDev
->PageSize
.cy
=
213 page
->PaperDimension
->y
* physDev
->logPixelsY
/ 72;
215 } else if((physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERLENGTH
) &&
216 (physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERWIDTH
)) {
217 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
218 physDev
->ImageableArea
.left
= physDev
->ImageableArea
.bottom
= 0;
219 physDev
->ImageableArea
.right
= physDev
->PageSize
.cx
=
220 physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
*
221 physDev
->logPixelsX
/ 254;
222 physDev
->ImageableArea
.top
= physDev
->PageSize
.cy
=
223 physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
*
224 physDev
->logPixelsY
/ 254;
226 FIXME("Odd dmFields %x\n", physDev
->Devmode
->dmPublic
.dmFields
);
227 physDev
->ImageableArea
.left
= 0;
228 physDev
->ImageableArea
.right
= 0;
229 physDev
->ImageableArea
.bottom
= 0;
230 physDev
->ImageableArea
.top
= 0;
231 physDev
->PageSize
.cx
= 0;
232 physDev
->PageSize
.cy
= 0;
235 TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %dx%d\n",
236 physDev
->ImageableArea
.left
, physDev
->ImageableArea
.bottom
,
237 physDev
->ImageableArea
.right
, physDev
->ImageableArea
.top
,
238 physDev
->PageSize
.cx
, physDev
->PageSize
.cy
);
240 /* these are in device units */
241 width
= physDev
->ImageableArea
.right
- physDev
->ImageableArea
.left
;
242 height
= physDev
->ImageableArea
.top
- physDev
->ImageableArea
.bottom
;
244 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
) {
245 physDev
->horzRes
= width
;
246 physDev
->vertRes
= height
;
248 physDev
->horzRes
= height
;
249 physDev
->vertRes
= width
;
252 /* these are in mm */
253 physDev
->horzSize
= (physDev
->horzRes
* 25.4) / physDev
->logPixelsX
;
254 physDev
->vertSize
= (physDev
->vertRes
* 25.4) / physDev
->logPixelsY
;
256 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
257 "horzRes = %d, vertRes = %d\n",
258 physDev
->horzSize
, physDev
->vertSize
,
259 physDev
->horzRes
, physDev
->vertRes
);
263 /***********************************************************
266 * Creates an ascii copy of supplied devmode on heap
268 * Copied from dlls/winspool/info.c until full unicodification
270 static LPDEVMODEA
DEVMODEdupWtoA(HANDLE heap
, const DEVMODEW
*dmW
)
275 /* there is no pointer dereference here, if your code checking tool complains it's broken */
276 ptrdiff_t off_formname
= (const char *)dmW
->dmFormName
- (const char *)dmW
;
278 if(!dmW
) return NULL
;
279 Formname
= (dmW
->dmSize
> off_formname
);
280 size
= dmW
->dmSize
- CCHDEVICENAME
- (Formname
? CCHFORMNAME
: 0);
281 dmA
= HeapAlloc(heap
, HEAP_ZERO_MEMORY
, size
+ dmW
->dmDriverExtra
);
282 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmDeviceName
, -1, (LPSTR
)dmA
->dmDeviceName
,
283 CCHDEVICENAME
, NULL
, NULL
);
285 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
286 dmW
->dmSize
- CCHDEVICENAME
* sizeof(WCHAR
));
288 memcpy(&dmA
->dmSpecVersion
, &dmW
->dmSpecVersion
,
289 off_formname
- CCHDEVICENAME
* sizeof(WCHAR
));
290 WideCharToMultiByte(CP_ACP
, 0, dmW
->dmFormName
, -1, (LPSTR
)dmA
->dmFormName
,
291 CCHFORMNAME
, NULL
, NULL
);
292 memcpy(&dmA
->dmLogPixels
, &dmW
->dmLogPixels
, dmW
->dmSize
-
293 (off_formname
+ CCHFORMNAME
* sizeof(WCHAR
)));
296 memcpy((char *)dmA
+ dmA
->dmSize
, (const char *)dmW
+ dmW
->dmSize
,
302 static PSDRV_PDEVICE
*create_psdrv_physdev( PRINTERINFO
*pi
)
304 PSDRV_PDEVICE
*physDev
;
306 physDev
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*physDev
) );
307 if (!physDev
) return NULL
;
309 physDev
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(PSDRV_DEVMODEA
) );
310 if (!physDev
->Devmode
)
312 HeapFree( PSDRV_Heap
, 0, physDev
);
316 *physDev
->Devmode
= *pi
->Devmode
;
318 physDev
->logPixelsX
= pi
->ppd
->DefaultResolution
;
319 physDev
->logPixelsY
= pi
->ppd
->DefaultResolution
;
323 /**********************************************************************
326 static BOOL
PSDRV_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
327 LPCWSTR output
, const DEVMODEW
* initData
)
329 PSDRV_PDEVICE
*physDev
;
334 TRACE("(%s %s %s %p)\n", debugstr_w(driver
), debugstr_w(device
),
335 debugstr_w(output
), initData
);
337 if (!device
) return FALSE
;
338 len
= WideCharToMultiByte(CP_ACP
, 0, device
, -1, NULL
, 0, NULL
, NULL
);
339 deviceA
= HeapAlloc(GetProcessHeap(), 0, len
);
340 WideCharToMultiByte(CP_ACP
, 0, device
, -1, deviceA
, len
, NULL
, NULL
);
341 pi
= PSDRV_FindPrinterInfo(deviceA
);
342 HeapFree(GetProcessHeap(), 0, deviceA
);
343 if(!pi
) return FALSE
;
346 RASTERIZER_STATUS status
;
347 if(!GetRasterizerCaps(&status
, sizeof(status
)) ||
348 !(status
.wFlags
& TT_AVAILABLE
) ||
349 !(status
.wFlags
& TT_ENABLED
)) {
350 MESSAGE("Disabling printer %s since it has no builtin fonts and there are no TrueType fonts available.\n",
356 if (!(physDev
= create_psdrv_physdev( pi
))) return FALSE
;
358 if (output
&& *output
) {
359 INT len
= WideCharToMultiByte( CP_ACP
, 0, output
, -1, NULL
, 0, NULL
, NULL
);
360 if ((physDev
->job
.output
= HeapAlloc( PSDRV_Heap
, 0, len
)))
361 WideCharToMultiByte( CP_ACP
, 0, output
, -1, physDev
->job
.output
, len
, NULL
, NULL
);
365 DEVMODEA
*devmodeA
= DEVMODEdupWtoA(PSDRV_Heap
, initData
);
366 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)devmodeA
, pi
);
367 HeapFree(PSDRV_Heap
, 0, devmodeA
);
370 PSDRV_UpdateDevCaps(physDev
);
371 SelectObject( (*pdev
)->hdc
, PSDRV_DefaultFont
);
372 push_dc_driver( pdev
, &physDev
->dev
, &psdrv_funcs
);
377 /**********************************************************************
378 * PSDRV_CreateCompatibleDC
380 static BOOL
PSDRV_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
382 HDC hdc
= (*pdev
)->hdc
;
383 PSDRV_PDEVICE
*physDev
, *orig_dev
= get_psdrv_dev( orig
);
384 PRINTERINFO
*pi
= PSDRV_FindPrinterInfo( orig_dev
->pi
->FriendlyName
);
386 if (!pi
) return FALSE
;
387 if (!(physDev
= create_psdrv_physdev( pi
))) return FALSE
;
388 PSDRV_MergeDevmodes( physDev
->Devmode
, orig_dev
->Devmode
, pi
);
389 PSDRV_UpdateDevCaps(physDev
);
390 SelectObject( hdc
, PSDRV_DefaultFont
);
391 push_dc_driver( pdev
, &physDev
->dev
, &psdrv_funcs
);
397 /**********************************************************************
400 static BOOL
PSDRV_DeleteDC( PHYSDEV dev
)
402 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
406 HeapFree( PSDRV_Heap
, 0, physDev
->Devmode
);
407 HeapFree( PSDRV_Heap
, 0, physDev
->job
.output
);
408 HeapFree( PSDRV_Heap
, 0, physDev
);
414 /**********************************************************************
417 static HDC
PSDRV_ResetDC( PHYSDEV dev
, const DEVMODEW
*lpInitData
)
419 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
422 DEVMODEA
*devmodeA
= DEVMODEdupWtoA(PSDRV_Heap
, lpInitData
);
423 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)devmodeA
, physDev
->pi
);
424 HeapFree(PSDRV_Heap
, 0, devmodeA
);
425 PSDRV_UpdateDevCaps(physDev
);
430 /***********************************************************************
431 * GetDeviceCaps (WINEPS.@)
433 static INT
PSDRV_GetDeviceCaps( PHYSDEV dev
, INT cap
)
435 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
442 return DT_RASPRINTER
;
444 return MulDiv(physDev
->horzSize
, 100,
445 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
);
447 return MulDiv(physDev
->vertSize
, 100,
448 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
);
451 return physDev
->horzRes
;
454 return physDev
->vertRes
;
456 return (physDev
->pi
->ppd
->ColorDevice
!= CD_False
) ? 32 : 1;
470 return sizeof(PSDRV_PDEVICE
);
472 return (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
473 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
475 return (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
476 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
478 return (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
479 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
481 return TC_CR_ANY
| TC_VA_ABLE
; /* psdrv 0x59f7 */
485 return (RC_BITBLT
| RC_BITMAP64
| RC_GDI20_OUTPUT
| RC_DIBTODEV
|
486 RC_STRETCHBLT
| RC_STRETCHDIB
); /* psdrv 0x6e99 */
487 /* Are aspect[XY] and logPixels[XY] correct? */
488 /* Need to handle different res in x and y => fix ppd */
491 return physDev
->pi
->ppd
->DefaultResolution
;
493 return (int)hypot( (double)physDev
->pi
->ppd
->DefaultResolution
,
494 (double)physDev
->pi
->ppd
->DefaultResolution
);
496 return MulDiv(physDev
->logPixelsX
,
497 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
, 100);
499 return MulDiv(physDev
->logPixelsY
,
500 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
, 100);
508 return (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) ?
509 physDev
->PageSize
.cy
: physDev
->PageSize
.cx
;
511 return (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) ?
512 physDev
->PageSize
.cx
: physDev
->PageSize
.cy
;
513 case PHYSICALOFFSETX
:
514 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
515 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90)
516 return physDev
->PageSize
.cy
- physDev
->ImageableArea
.top
;
518 return physDev
->ImageableArea
.bottom
;
520 return physDev
->ImageableArea
.left
;
522 case PHYSICALOFFSETY
:
523 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
524 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90)
525 return physDev
->PageSize
.cx
- physDev
->ImageableArea
.right
;
527 return physDev
->ImageableArea
.left
;
529 return physDev
->PageSize
.cy
- physDev
->ImageableArea
.top
;
539 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
545 /**********************************************************************
546 * PSDRV_FindPrinterInfo
548 PRINTERINFO
*PSDRV_FindPrinterInfo(LPCSTR name
)
550 static PRINTERINFO
*PSDRV_PrinterList
;
551 DWORD type
= REG_BINARY
, needed
, res
, dwPaperSize
;
552 PRINTERINFO
*pi
= PSDRV_PrinterList
, **last
= &PSDRV_PrinterList
;
556 const char *ppd
= NULL
;
558 char* ppdFileName
= NULL
;
560 BOOL using_default_devmode
= FALSE
;
562 TRACE("'%s'\n", name
);
565 * If this loop completes, last will point to the 'next' element of the
566 * final PRINTERINFO in the list
568 for( ; pi
; last
= &pi
->next
, pi
= pi
->next
)
569 if(!strcmp(pi
->FriendlyName
, name
))
572 pi
= *last
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*pi
) );
576 if (!(pi
->FriendlyName
= HeapAlloc( PSDRV_Heap
, 0, strlen(name
)+1 ))) goto fail
;
577 strcpy( pi
->FriendlyName
, name
);
579 if (OpenPrinterA (pi
->FriendlyName
, &hPrinter
, NULL
) == 0) {
580 ERR ("OpenPrinterA failed with code %i\n", GetLastError ());
585 res
= GetPrinterDataExA(hPrinter
, NULL
, default_devmodeA
, &type
, NULL
, 0, &needed
);
587 if (needed
< sizeof(DefaultDevmode
)) {
588 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(DefaultDevmode
) );
589 if (pi
->Devmode
== NULL
)
592 *pi
->Devmode
= DefaultDevmode
;
593 lstrcpynA((LPSTR
)pi
->Devmode
->dmPublic
.dmDeviceName
,name
,CCHDEVICENAME
);
594 using_default_devmode
= TRUE
;
597 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, needed
);
598 if (pi
->Devmode
== NULL
)
601 GetPrinterDataExA(hPrinter
, NULL
, default_devmodeA
, &type
, (LPBYTE
)pi
->Devmode
, needed
, &needed
);
606 #ifdef SONAME_LIBCUPS
607 if (cupshandle
!= (void*)-1) {
608 typeof(cupsGetPPD
) * pcupsGetPPD
= NULL
;
610 pcupsGetPPD
= wine_dlsym(cupshandle
, "cupsGetPPD", NULL
, 0);
612 ppd
= pcupsGetPPD(name
);
615 needed
=strlen(ppd
)+1;
616 ppdFileName
=HeapAlloc(PSDRV_Heap
, 0, needed
);
617 memcpy(ppdFileName
, ppd
, needed
);
620 /* we should unlink() that file later */
622 res
= ERROR_FILE_NOT_FOUND
;
623 WARN("Did not find ppd for %s\n",name
);
629 res
= GetPrinterDataExA(hPrinter
, "PrinterDriverData", "PPD File", NULL
, NULL
, 0, &needed
);
630 if ((res
==ERROR_SUCCESS
) || (res
==ERROR_MORE_DATA
)) {
631 ppdFileName
=HeapAlloc(PSDRV_Heap
, 0, needed
);
632 res
= GetPrinterDataExA(hPrinter
, "PrinterDriverData", "PPD File", &ppdType
,
633 (LPBYTE
)ppdFileName
, needed
, &needed
);
636 /* Look for a ppd file for this printer in the config file.
637 * First look under that printer's name, and then under 'generic'
639 /* @@ Wine registry key: HKCU\Software\Wine\Printing\PPD Files */
640 if((res
!= ERROR_SUCCESS
) && !RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Printing\\PPD Files", &hkey
))
642 const char* value_name
;
644 if (RegQueryValueExA(hkey
, name
, 0, NULL
, NULL
, &needed
) == ERROR_SUCCESS
) {
646 } else if (RegQueryValueExA(hkey
, "generic", 0, NULL
, NULL
, &needed
) == ERROR_SUCCESS
) {
647 value_name
="generic";
652 HeapFree(PSDRV_Heap
, 0, ppdFileName
);
653 ppdFileName
=HeapAlloc(PSDRV_Heap
, 0, needed
);
654 RegQueryValueExA(hkey
, value_name
, 0, &ppdType
, (LPBYTE
)ppdFileName
, &needed
);
661 const char *data_dir
, *filename
;
663 if ((data_dir
= wine_get_data_dir())) filename
= "/generic.ppd";
664 else if ((data_dir
= wine_get_build_dir())) filename
= "/dlls/wineps.drv/generic.ppd";
667 res
= ERROR_FILE_NOT_FOUND
;
668 ERR ("Error %i getting PPD file name for printer '%s'\n", res
, name
);
671 ppdFileName
= HeapAlloc( PSDRV_Heap
, 0, strlen(data_dir
) + strlen(filename
) + 1 );
672 strcpy( ppdFileName
, data_dir
);
673 strcat( ppdFileName
, filename
);
676 if (ppdType
==REG_EXPAND_SZ
) {
679 /* Expand environment variable references */
680 needed
=ExpandEnvironmentStringsA(ppdFileName
,NULL
,0);
681 tmp
=HeapAlloc(PSDRV_Heap
, 0, needed
);
682 ExpandEnvironmentStringsA(ppdFileName
,tmp
,needed
);
683 HeapFree(PSDRV_Heap
, 0, ppdFileName
);
688 pi
->ppd
= PSDRV_ParsePPD(ppdFileName
);
690 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
695 /* Some gimp-print ppd files don't contain a DefaultResolution line
696 set it to 300 if it's not specified */
697 if(pi
->ppd
->DefaultResolution
== 0)
698 pi
->ppd
->DefaultResolution
= 300;
700 if(using_default_devmode
) {
703 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IPAPERSIZE
| LOCALE_RETURN_NUMBER
,
704 (LPWSTR
)&papersize
, sizeof(papersize
)/sizeof(WCHAR
))) {
706 memset(&dm
, 0, sizeof(dm
));
707 dm
.dmPublic
.dmFields
= DM_PAPERSIZE
;
708 dm
.dmPublic
.u1
.s1
.dmPaperSize
= papersize
;
709 PSDRV_MergeDevmodes(pi
->Devmode
, &dm
, pi
);
712 SetPrinterDataExA(hPrinter
, NULL
, default_devmodeA
, REG_BINARY
,
713 (LPBYTE
)pi
->Devmode
, sizeof(DefaultDevmode
));
716 if(pi
->ppd
->DefaultPageSize
) { /* We'll let the ppd override the devmode */
718 memset(&dm
, 0, sizeof(dm
));
719 dm
.dmPublic
.dmFields
= DM_PAPERSIZE
;
720 dm
.dmPublic
.u1
.s1
.dmPaperSize
= pi
->ppd
->DefaultPageSize
->WinPage
;
721 PSDRV_MergeDevmodes(pi
->Devmode
, &dm
, pi
);
725 * This is a hack. The default paper size should be read in as part of
726 * the Devmode structure, but Wine doesn't currently provide a convenient
727 * way to configure printers.
729 res
= GetPrinterDataExA(hPrinter
, "PrinterDriverData", "Paper Size", NULL
,
730 (LPBYTE
)&dwPaperSize
, sizeof(DWORD
), &needed
);
731 if (res
== ERROR_SUCCESS
)
732 pi
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
= (SHORT
) dwPaperSize
;
733 else if (res
== ERROR_FILE_NOT_FOUND
)
734 TRACE ("No 'Paper Size' for printer '%s'\n", name
);
736 ERR ("GetPrinterDataA returned %i\n", res
);
740 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
741 WinDuplex == 0 is a special case which means that the ppd has a
742 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
743 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
744 PSDRV_WriteHeader understands this and copes. */
745 pi
->Devmode
->dmPublic
.dmFields
&= ~DM_DUPLEX
;
746 if(pi
->ppd
->DefaultDuplex
) {
747 pi
->Devmode
->dmPublic
.dmDuplex
= pi
->ppd
->DefaultDuplex
->WinDuplex
;
748 if(pi
->Devmode
->dmPublic
.dmDuplex
!= 0)
749 pi
->Devmode
->dmPublic
.dmFields
|= DM_DUPLEX
;
751 pi
->Devmode
->dmPublic
.dmDuplex
= DMDUP_SIMPLEX
;
754 res
= EnumPrinterDataExA (hPrinter
, "PrinterDriverData\\FontSubTable", NULL
,
755 0, &needed
, &pi
->FontSubTableSize
);
756 if (res
== ERROR_SUCCESS
|| res
== ERROR_FILE_NOT_FOUND
) {
757 TRACE ("No 'FontSubTable' for printer '%s'\n", name
);
759 else if (res
== ERROR_MORE_DATA
) {
760 pi
->FontSubTable
= HeapAlloc (PSDRV_Heap
, 0, needed
);
761 if (pi
->FontSubTable
== NULL
) {
762 ERR ("Failed to allocate %i bytes from heap\n", needed
);
766 res
= EnumPrinterDataExA (hPrinter
, "PrinterDriverData\\FontSubTable",
767 (LPBYTE
) pi
->FontSubTable
, needed
, &needed
,
768 &pi
->FontSubTableSize
);
769 if (res
!= ERROR_SUCCESS
) {
770 ERR ("EnumPrinterDataExA returned %i\n", res
);
775 ERR("EnumPrinterDataExA returned %i\n", res
);
779 if (ClosePrinter (hPrinter
) == 0) {
780 ERR ("ClosePrinter failed with code %i\n", GetLastError ());
787 for(font
= pi
->ppd
->InstalledFonts
; font
; font
= font
->next
) {
788 afm
= PSDRV_FindAFMinList(PSDRV_AFMFontList
, font
->Name
);
790 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
791 "ignoring\n", font
->Name
);
795 if (PSDRV_AddAFMtoList(&pi
->Fonts
, afm
, &added
) == FALSE
) {
796 PSDRV_FreeAFMList(pi
->Fonts
);
802 if (ppd
) unlink(ppd
);
806 ClosePrinter(hPrinter
);
808 HeapFree(PSDRV_Heap
, 0, ppdFileName
);
809 HeapFree(PSDRV_Heap
, 0, pi
->FontSubTable
);
810 HeapFree(PSDRV_Heap
, 0, pi
->FriendlyName
);
811 HeapFree(PSDRV_Heap
, 0, pi
->Devmode
);
813 HeapFree(PSDRV_Heap
, 0, pi
);
814 if (ppd
) unlink(ppd
);
820 static const struct gdi_dc_funcs psdrv_funcs
=
822 NULL
, /* pAbortDoc */
823 NULL
, /* pAbortPath */
824 NULL
, /* pAlphaBlend */
825 NULL
, /* pAngleArc */
826 PSDRV_Arc
, /* pArc */
828 NULL
, /* pBeginPath */
829 NULL
, /* pBlendImage */
830 NULL
, /* pChoosePixelFormat */
831 PSDRV_Chord
, /* pChord */
832 NULL
, /* pCloseFigure */
833 NULL
, /* pCopyBitmap */
834 NULL
, /* pCreateBitmap */
835 PSDRV_CreateCompatibleDC
, /* pCreateCompatibleDC */
836 PSDRV_CreateDC
, /* pCreateDC */
837 NULL
, /* pCreateDIBSection */
838 NULL
, /* pDeleteBitmap */
839 PSDRV_DeleteDC
, /* pDeleteDC */
840 NULL
, /* pDeleteObject */
841 NULL
, /* pDescribePixelFormat */
842 PSDRV_DeviceCapabilities
, /* pDeviceCapabilities */
843 PSDRV_Ellipse
, /* pEllipse */
844 PSDRV_EndDoc
, /* pEndDoc */
845 PSDRV_EndPage
, /* pEndPage */
847 PSDRV_EnumFonts
, /* pEnumFonts */
848 NULL
, /* pEnumICMProfiles */
849 NULL
, /* pExcludeClipRect */
850 PSDRV_ExtDeviceMode
, /* pExtDeviceMode */
851 PSDRV_ExtEscape
, /* pExtEscape */
852 NULL
, /* pExtFloodFill */
853 NULL
, /* pExtSelectClipRgn */
854 PSDRV_ExtTextOut
, /* pExtTextOut */
855 PSDRV_FillPath
, /* pFillPath */
857 NULL
, /* pFlattenPath */
858 NULL
, /* pFontIsLinked */
859 NULL
, /* pFrameRgn */
860 NULL
, /* pGdiComment */
861 NULL
, /* pGdiRealizationInfo */
862 NULL
, /* pGetCharABCWidths */
863 NULL
, /* pGetCharABCWidthsI */
864 PSDRV_GetCharWidth
, /* pGetCharWidth */
865 PSDRV_GetDeviceCaps
, /* pGetDeviceCaps */
866 NULL
, /* pGetDeviceGammaRamp */
867 NULL
, /* pGetFontData */
868 NULL
, /* pGetFontUnicodeRanges */
869 NULL
, /* pGetGlyphIndices */
870 NULL
, /* pGetGlyphOutline */
871 NULL
, /* pGetICMProfile */
872 NULL
, /* pGetImage */
873 NULL
, /* pGetKerningPairs */
874 NULL
, /* pGetNearestColor */
875 NULL
, /* pGetOutlineTextMetrics */
876 NULL
, /* pGetPixel */
877 NULL
, /* pGetPixelFormat */
878 NULL
, /* pGetSystemPaletteEntries */
879 NULL
, /* pGetTextCharsetInfo */
880 PSDRV_GetTextExtentExPoint
, /* pGetTextExtentExPoint */
881 NULL
, /* pGetTextExtentExPointI */
882 NULL
, /* pGetTextFace */
883 PSDRV_GetTextMetrics
, /* pGetTextMetrics */
884 NULL
, /* pGradientFill */
885 NULL
, /* pIntersectClipRect */
886 NULL
, /* pInvertRgn */
887 PSDRV_LineTo
, /* pLineTo */
888 NULL
, /* pModifyWorldTransform */
890 NULL
, /* pOffsetClipRgn */
891 NULL
, /* pOffsetViewportOrg */
892 NULL
, /* pOffsetWindowOrg */
893 PSDRV_PaintRgn
, /* pPaintRgn */
894 PSDRV_PatBlt
, /* pPatBlt */
895 PSDRV_Pie
, /* pPie */
896 PSDRV_PolyBezier
, /* pPolyBezier */
897 PSDRV_PolyBezierTo
, /* pPolyBezierTo */
898 NULL
, /* pPolyDraw */
899 PSDRV_PolyPolygon
, /* pPolyPolygon */
900 PSDRV_PolyPolyline
, /* pPolyPolyline */
902 NULL
, /* pPolyline */
903 NULL
, /* pPolylineTo */
904 PSDRV_PutImage
, /* pPutImage */
905 NULL
, /* pRealizeDefaultPalette */
906 NULL
, /* pRealizePalette */
907 PSDRV_Rectangle
, /* pRectangle */
908 PSDRV_ResetDC
, /* pResetDC */
909 NULL
, /* pRestoreDC */
910 PSDRV_RoundRect
, /* pRoundRect */
912 NULL
, /* pScaleViewportExt */
913 NULL
, /* pScaleWindowExt */
914 NULL
, /* pSelectBitmap */
915 PSDRV_SelectBrush
, /* pSelectBrush */
916 NULL
, /* pSelectClipPath */
917 PSDRV_SelectFont
, /* pSelectFont */
918 NULL
, /* pSelectPalette */
919 PSDRV_SelectPen
, /* pSelectPen */
920 NULL
, /* pSetArcDirection */
921 PSDRV_SetBkColor
, /* pSetBkColor */
922 NULL
, /* pSetBkMode */
923 PSDRV_SetDCBrushColor
, /* pSetDCBrushColor */
924 PSDRV_SetDCPenColor
, /* pSetDCPenColor */
925 NULL
, /* pSetDIBColorTable */
926 NULL
, /* pSetDIBitsToDevice */
927 NULL
, /* pSetDeviceClipping */
928 NULL
, /* pSetDeviceGammaRamp */
929 NULL
, /* pSetLayout */
930 NULL
, /* pSetMapMode */
931 NULL
, /* pSetMapperFlags */
932 PSDRV_SetPixel
, /* pSetPixel */
933 NULL
, /* pSetPixelFormat */
934 NULL
, /* pSetPolyFillMode */
936 NULL
, /* pSetRelAbs */
937 NULL
, /* pSetStretchBltMode */
938 NULL
, /* pSetTextAlign */
939 NULL
, /* pSetTextCharacterExtra */
940 PSDRV_SetTextColor
, /* pSetTextColor */
941 NULL
, /* pSetTextJustification */
942 NULL
, /* pSetViewportExt */
943 NULL
, /* pSetViewportOrg */
944 NULL
, /* pSetWindowExt */
945 NULL
, /* pSetWindowOrg */
946 NULL
, /* pSetWorldTransform */
947 PSDRV_StartDoc
, /* pStartDoc */
948 PSDRV_StartPage
, /* pStartPage */
949 NULL
, /* pStretchBlt */
950 NULL
, /* pStretchDIBits */
951 PSDRV_StrokeAndFillPath
, /* pStrokeAndFillPath */
952 PSDRV_StrokePath
, /* pStrokePath */
953 NULL
, /* pSwapBuffers */
954 NULL
, /* pUnrealizePalette */
955 NULL
, /* pWidenPath */
956 /* OpenGL not supported */
960 /******************************************************************************
961 * PSDRV_get_gdi_driver
963 const struct gdi_dc_funcs
* CDECL
PSDRV_get_gdi_driver( unsigned int version
)
965 if (version
!= WINE_GDI_DRIVER_VERSION
)
967 ERR( "version mismatch, gdi32 wants %u but wineps has %u\n", version
, WINE_GDI_DRIVER_VERSION
);