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"
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
38 #include "wine/library.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
43 static const PSDRV_DEVMODE DefaultDevmode
=
46 /* dmDeviceName */ {'W','i','n','e',' ','P','o','s','t','S','c','r','i','p','t',' ','D','r','i','v','e','r',0},
47 /* dmSpecVersion */ 0x30a,
48 /* dmDriverVersion */ 0x001,
49 /* dmSize */ sizeof(DEVMODEW
),
50 /* dmDriverExtra */ sizeof(PSDRV_DEVMODE
)-sizeof(DEVMODEW
),
51 /* dmFields */ DM_ORIENTATION
| DM_PAPERSIZE
| DM_PAPERLENGTH
| DM_PAPERWIDTH
|
52 DM_SCALE
| DM_COPIES
| DM_DEFAULTSOURCE
| DM_PRINTQUALITY
|
53 DM_COLOR
| DM_DUPLEX
| DM_YRESOLUTION
| DM_TTOPTION
|
54 DM_COLLATE
| DM_FORMNAME
,
57 /* dmOrientation */ DMORIENT_PORTRAIT
,
58 /* dmPaperSize */ DMPAPER_LETTER
,
59 /* dmPaperLength */ 2794,
60 /* dmPaperWidth */ 2159,
63 /* dmDefaultSource */ DMBIN_AUTO
,
64 /* dmPrintQuality */ 300
67 /* dmColor */ DMCOLOR_COLOR
,
68 /* dmDuplex */ DMDUP_SIMPLEX
,
69 /* dmYResolution */ 300,
70 /* dmTTOption */ DMTT_SUBDEV
,
71 /* dmCollate */ DMCOLLATE_FALSE
,
72 /* dmFormName */ {'L','e','t','t','e','r',0},
78 /* dmDisplayFlags */ 0
80 /* dmDisplayFrequency */ 0,
87 /* dmPanningWidth */ 0,
88 /* dmPanningHeight */ 0
94 /* numInstalledOptions */ 0
98 HINSTANCE PSDRV_hInstance
= 0;
99 HANDLE PSDRV_Heap
= 0;
101 static HFONT PSDRV_DefaultFont
= 0;
102 static const LOGFONTA DefaultLogFont
= {
103 100, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
, 0, 0,
104 DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, ""
107 static const struct gdi_dc_funcs psdrv_funcs
;
109 /*********************************************************************
112 * Initializes font metrics and registers driver. wineps dll entry point.
115 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
117 TRACE("(%p, %d, %p)\n", hinst
, reason
, reserved
);
121 case DLL_PROCESS_ATTACH
:
122 PSDRV_hInstance
= hinst
;
123 DisableThreadLibraryCalls(hinst
);
125 PSDRV_Heap
= HeapCreate(0, 0x10000, 0);
126 if (PSDRV_Heap
== NULL
)
129 if (PSDRV_GetFontMetrics() == FALSE
) {
130 HeapDestroy(PSDRV_Heap
);
134 PSDRV_DefaultFont
= CreateFontIndirectA(&DefaultLogFont
);
135 if (PSDRV_DefaultFont
== NULL
) {
136 HeapDestroy(PSDRV_Heap
);
141 case DLL_PROCESS_DETACH
:
143 DeleteObject( PSDRV_DefaultFont
);
144 HeapDestroy( PSDRV_Heap
);
151 static void dump_fields(DWORD fields
)
155 #define CHECK_FIELD(flag) \
160 if (add_space++) DPRINTF(" "); \
167 CHECK_FIELD(DM_ORIENTATION
);
168 CHECK_FIELD(DM_PAPERSIZE
);
169 CHECK_FIELD(DM_PAPERLENGTH
);
170 CHECK_FIELD(DM_PAPERWIDTH
);
171 CHECK_FIELD(DM_SCALE
);
172 CHECK_FIELD(DM_POSITION
);
174 CHECK_FIELD(DM_DISPLAYORIENTATION
);
175 CHECK_FIELD(DM_COPIES
);
176 CHECK_FIELD(DM_DEFAULTSOURCE
);
177 CHECK_FIELD(DM_PRINTQUALITY
);
178 CHECK_FIELD(DM_COLOR
);
179 CHECK_FIELD(DM_DUPLEX
);
180 CHECK_FIELD(DM_YRESOLUTION
);
181 CHECK_FIELD(DM_TTOPTION
);
182 CHECK_FIELD(DM_COLLATE
);
183 CHECK_FIELD(DM_FORMNAME
);
184 CHECK_FIELD(DM_LOGPIXELS
);
185 CHECK_FIELD(DM_BITSPERPEL
);
186 CHECK_FIELD(DM_PELSWIDTH
);
187 CHECK_FIELD(DM_PELSHEIGHT
);
188 CHECK_FIELD(DM_DISPLAYFLAGS
);
189 CHECK_FIELD(DM_DISPLAYFREQUENCY
);
190 CHECK_FIELD(DM_ICMMETHOD
);
191 CHECK_FIELD(DM_ICMINTENT
);
192 CHECK_FIELD(DM_MEDIATYPE
);
193 CHECK_FIELD(DM_DITHERTYPE
);
194 CHECK_FIELD(DM_PANNINGWIDTH
);
195 CHECK_FIELD(DM_PANNINGHEIGHT
);
196 if (fields
) TRACE(" %#x", fields
);
201 /* Dump DEVMODE structure without a device specific part.
202 * Some applications and drivers fail to specify correct field
203 * flags (like DM_FORMNAME), so dump everything.
205 static void dump_devmode(const DEVMODEW
*dm
)
207 if (!TRACE_ON(psdrv
)) return;
209 TRACE("dmDeviceName: %s\n", debugstr_w(dm
->dmDeviceName
));
210 TRACE("dmSpecVersion: 0x%04x\n", dm
->dmSpecVersion
);
211 TRACE("dmDriverVersion: 0x%04x\n", dm
->dmDriverVersion
);
212 TRACE("dmSize: 0x%04x\n", dm
->dmSize
);
213 TRACE("dmDriverExtra: 0x%04x\n", dm
->dmDriverExtra
);
214 TRACE("dmFields: 0x%04x\n", dm
->dmFields
);
215 dump_fields(dm
->dmFields
);
216 TRACE("dmOrientation: %d\n", dm
->u1
.s1
.dmOrientation
);
217 TRACE("dmPaperSize: %d\n", dm
->u1
.s1
.dmPaperSize
);
218 TRACE("dmPaperLength: %d\n", dm
->u1
.s1
.dmPaperLength
);
219 TRACE("dmPaperWidth: %d\n", dm
->u1
.s1
.dmPaperWidth
);
220 TRACE("dmScale: %d\n", dm
->u1
.s1
.dmScale
);
221 TRACE("dmCopies: %d\n", dm
->u1
.s1
.dmCopies
);
222 TRACE("dmDefaultSource: %d\n", dm
->u1
.s1
.dmDefaultSource
);
223 TRACE("dmPrintQuality: %d\n", dm
->u1
.s1
.dmPrintQuality
);
224 TRACE("dmColor: %d\n", dm
->dmColor
);
225 TRACE("dmDuplex: %d\n", dm
->dmDuplex
);
226 TRACE("dmYResolution: %d\n", dm
->dmYResolution
);
227 TRACE("dmTTOption: %d\n", dm
->dmTTOption
);
228 TRACE("dmCollate: %d\n", dm
->dmCollate
);
229 TRACE("dmFormName: %s\n", debugstr_w(dm
->dmFormName
));
230 TRACE("dmLogPixels %u\n", dm
->dmLogPixels
);
231 TRACE("dmBitsPerPel %u\n", dm
->dmBitsPerPel
);
232 TRACE("dmPelsWidth %u\n", dm
->dmPelsWidth
);
233 TRACE("dmPelsHeight %u\n", dm
->dmPelsHeight
);
236 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE
*physDev
)
240 INT width
= 0, height
= 0, resx
= 0, resy
= 0;
242 dump_devmode(&physDev
->Devmode
->dmPublic
);
244 if (physDev
->Devmode
->dmPublic
.dmFields
& (DM_PRINTQUALITY
| DM_YRESOLUTION
| DM_LOGPIXELS
))
246 if (physDev
->Devmode
->dmPublic
.dmFields
& DM_PRINTQUALITY
)
247 resx
= resy
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPrintQuality
;
249 if (physDev
->Devmode
->dmPublic
.dmFields
& DM_YRESOLUTION
)
250 resy
= physDev
->Devmode
->dmPublic
.dmYResolution
;
252 if (physDev
->Devmode
->dmPublic
.dmFields
& DM_LOGPIXELS
)
253 resx
= resy
= physDev
->Devmode
->dmPublic
.dmLogPixels
;
255 LIST_FOR_EACH_ENTRY(res
, &physDev
->pi
->ppd
->Resolutions
, RESOLUTION
, entry
)
257 if (res
->resx
== resx
&& res
->resy
== resy
)
259 physDev
->logPixelsX
= resx
;
260 physDev
->logPixelsY
= resy
;
265 if (&res
->entry
== &physDev
->pi
->ppd
->Resolutions
)
267 WARN("Requested resolution %dx%d is not supported by device\n", resx
, resy
);
268 physDev
->logPixelsX
= physDev
->pi
->ppd
->DefaultResolution
;
269 physDev
->logPixelsY
= physDev
->logPixelsX
;
274 WARN("Using default device resolution %d\n", physDev
->pi
->ppd
->DefaultResolution
);
275 physDev
->logPixelsX
= physDev
->pi
->ppd
->DefaultResolution
;
276 physDev
->logPixelsY
= physDev
->logPixelsX
;
279 if(physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERSIZE
) {
280 LIST_FOR_EACH_ENTRY(page
, &physDev
->pi
->ppd
->PageSizes
, PAGESIZE
, entry
) {
281 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
)
285 if(&page
->entry
== &physDev
->pi
->ppd
->PageSizes
) {
286 FIXME("Can't find page\n");
287 physDev
->ImageableArea
.left
= 0;
288 physDev
->ImageableArea
.right
= 0;
289 physDev
->ImageableArea
.bottom
= 0;
290 physDev
->ImageableArea
.top
= 0;
291 physDev
->PageSize
.cx
= 0;
292 physDev
->PageSize
.cy
= 0;
293 } else if(page
->ImageableArea
) {
294 /* physDev sizes in device units; ppd sizes in 1/72" */
295 physDev
->ImageableArea
.left
= page
->ImageableArea
->llx
*
296 physDev
->logPixelsX
/ 72;
297 physDev
->ImageableArea
.right
= page
->ImageableArea
->urx
*
298 physDev
->logPixelsX
/ 72;
299 physDev
->ImageableArea
.bottom
= page
->ImageableArea
->lly
*
300 physDev
->logPixelsY
/ 72;
301 physDev
->ImageableArea
.top
= page
->ImageableArea
->ury
*
302 physDev
->logPixelsY
/ 72;
303 physDev
->PageSize
.cx
= page
->PaperDimension
->x
*
304 physDev
->logPixelsX
/ 72;
305 physDev
->PageSize
.cy
= page
->PaperDimension
->y
*
306 physDev
->logPixelsY
/ 72;
308 physDev
->ImageableArea
.left
= physDev
->ImageableArea
.bottom
= 0;
309 physDev
->ImageableArea
.right
= physDev
->PageSize
.cx
=
310 page
->PaperDimension
->x
* physDev
->logPixelsX
/ 72;
311 physDev
->ImageableArea
.top
= physDev
->PageSize
.cy
=
312 page
->PaperDimension
->y
* physDev
->logPixelsY
/ 72;
314 } else if((physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERLENGTH
) &&
315 (physDev
->Devmode
->dmPublic
.dmFields
& DM_PAPERWIDTH
)) {
316 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
317 physDev
->ImageableArea
.left
= physDev
->ImageableArea
.bottom
= 0;
318 physDev
->ImageableArea
.right
= physDev
->PageSize
.cx
=
319 physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
*
320 physDev
->logPixelsX
/ 254;
321 physDev
->ImageableArea
.top
= physDev
->PageSize
.cy
=
322 physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
*
323 physDev
->logPixelsY
/ 254;
325 FIXME("Odd dmFields %x\n", physDev
->Devmode
->dmPublic
.dmFields
);
326 physDev
->ImageableArea
.left
= 0;
327 physDev
->ImageableArea
.right
= 0;
328 physDev
->ImageableArea
.bottom
= 0;
329 physDev
->ImageableArea
.top
= 0;
330 physDev
->PageSize
.cx
= 0;
331 physDev
->PageSize
.cy
= 0;
334 TRACE("ImageableArea = %s: PageSize = %dx%d\n", wine_dbgstr_rect(&physDev
->ImageableArea
),
335 physDev
->PageSize
.cx
, physDev
->PageSize
.cy
);
337 /* these are in device units */
338 width
= physDev
->ImageableArea
.right
- physDev
->ImageableArea
.left
;
339 height
= physDev
->ImageableArea
.top
- physDev
->ImageableArea
.bottom
;
341 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
) {
342 physDev
->horzRes
= width
;
343 physDev
->vertRes
= height
;
345 physDev
->horzRes
= height
;
346 physDev
->vertRes
= width
;
349 /* these are in mm */
350 physDev
->horzSize
= (physDev
->horzRes
* 25.4) / physDev
->logPixelsX
;
351 physDev
->vertSize
= (physDev
->vertRes
* 25.4) / physDev
->logPixelsY
;
353 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
354 "horzRes = %d, vertRes = %d\n",
355 physDev
->horzSize
, physDev
->vertSize
,
356 physDev
->horzRes
, physDev
->vertRes
);
359 static PSDRV_PDEVICE
*create_psdrv_physdev( PRINTERINFO
*pi
)
361 PSDRV_PDEVICE
*physDev
;
363 physDev
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physDev
) );
364 if (!physDev
) return NULL
;
366 physDev
->Devmode
= HeapAlloc( GetProcessHeap(), 0, sizeof(PSDRV_DEVMODE
) );
367 if (!physDev
->Devmode
)
369 HeapFree( GetProcessHeap(), 0, physDev
);
373 *physDev
->Devmode
= *pi
->Devmode
;
375 physDev
->logPixelsX
= pi
->ppd
->DefaultResolution
;
376 physDev
->logPixelsY
= pi
->ppd
->DefaultResolution
;
380 /**********************************************************************
383 static BOOL
PSDRV_CreateDC( PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
384 LPCWSTR output
, const DEVMODEW
* initData
)
386 PSDRV_PDEVICE
*physDev
;
389 TRACE("(%s %s %s %p)\n", debugstr_w(driver
), debugstr_w(device
),
390 debugstr_w(output
), initData
);
392 if (!device
) return FALSE
;
393 pi
= PSDRV_FindPrinterInfo( device
);
394 if(!pi
) return FALSE
;
397 RASTERIZER_STATUS status
;
398 if(!GetRasterizerCaps(&status
, sizeof(status
)) ||
399 !(status
.wFlags
& TT_AVAILABLE
) ||
400 !(status
.wFlags
& TT_ENABLED
)) {
401 MESSAGE("Disabling printer %s since it has no builtin fonts and there are no TrueType fonts available.\n",
407 if (!(physDev
= create_psdrv_physdev( pi
))) return FALSE
;
409 if (output
&& *output
) physDev
->job
.output
= strdupW( output
);
413 dump_devmode(initData
);
414 PSDRV_MergeDevmodes(physDev
->Devmode
, (const PSDRV_DEVMODE
*)initData
, pi
);
417 PSDRV_UpdateDevCaps(physDev
);
418 SelectObject( (*pdev
)->hdc
, PSDRV_DefaultFont
);
419 push_dc_driver( pdev
, &physDev
->dev
, &psdrv_funcs
);
424 /**********************************************************************
425 * PSDRV_CreateCompatibleDC
427 static BOOL
PSDRV_CreateCompatibleDC( PHYSDEV orig
, PHYSDEV
*pdev
)
429 HDC hdc
= (*pdev
)->hdc
;
430 PSDRV_PDEVICE
*physDev
, *orig_dev
= get_psdrv_dev( orig
);
431 PRINTERINFO
*pi
= PSDRV_FindPrinterInfo( orig_dev
->pi
->friendly_name
);
433 if (!pi
) return FALSE
;
434 if (!(physDev
= create_psdrv_physdev( pi
))) return FALSE
;
435 PSDRV_MergeDevmodes( physDev
->Devmode
, orig_dev
->Devmode
, pi
);
436 PSDRV_UpdateDevCaps(physDev
);
437 SelectObject( hdc
, PSDRV_DefaultFont
);
438 push_dc_driver( pdev
, &physDev
->dev
, &psdrv_funcs
);
444 /**********************************************************************
447 static BOOL
PSDRV_DeleteDC( PHYSDEV dev
)
449 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
453 HeapFree( GetProcessHeap(), 0, physDev
->Devmode
);
454 HeapFree( GetProcessHeap(), 0, physDev
->job
.output
);
455 HeapFree( GetProcessHeap(), 0, physDev
);
461 /**********************************************************************
464 static HDC
PSDRV_ResetDC( PHYSDEV dev
, const DEVMODEW
*lpInitData
)
466 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
470 PSDRV_MergeDevmodes(physDev
->Devmode
, (const PSDRV_DEVMODE
*)lpInitData
, physDev
->pi
);
471 PSDRV_UpdateDevCaps(physDev
);
476 /***********************************************************************
477 * GetDeviceCaps (WINEPS.@)
479 static INT
PSDRV_GetDeviceCaps( PHYSDEV dev
, INT cap
)
481 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
483 TRACE("%p,%d\n", dev
->hdc
, cap
);
490 return DT_RASPRINTER
;
492 return MulDiv(physDev
->horzSize
, 100,
493 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
);
495 return MulDiv(physDev
->vertSize
, 100,
496 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
);
499 return physDev
->horzRes
;
502 return physDev
->vertRes
;
504 /* Although Windows returns 1 for monochrome printers, we want
505 CreateCompatibleBitmap to provide something other than 1 bpp */
520 return sizeof(PSDRV_PDEVICE
);
522 return (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
523 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
525 return (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
526 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
528 return (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
529 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
531 return TC_CR_ANY
| TC_VA_ABLE
; /* psdrv 0x59f7 */
535 return (RC_BITBLT
| RC_BITMAP64
| RC_GDI20_OUTPUT
| RC_DIBTODEV
|
536 RC_STRETCHBLT
| RC_STRETCHDIB
); /* psdrv 0x6e99 */
538 return physDev
->logPixelsX
;
540 return physDev
->logPixelsY
;
542 return (int)hypot( (double)physDev
->logPixelsX
,
543 (double)physDev
->logPixelsY
);
545 return MulDiv(physDev
->logPixelsX
,
546 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
, 100);
548 return MulDiv(physDev
->logPixelsY
,
549 physDev
->Devmode
->dmPublic
.u1
.s1
.dmScale
, 100);
557 return (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) ?
558 physDev
->PageSize
.cy
: physDev
->PageSize
.cx
;
560 return (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) ?
561 physDev
->PageSize
.cx
: physDev
->PageSize
.cy
;
562 case PHYSICALOFFSETX
:
563 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
564 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90)
565 return physDev
->PageSize
.cy
- physDev
->ImageableArea
.top
;
567 return physDev
->ImageableArea
.bottom
;
569 return physDev
->ImageableArea
.left
;
571 case PHYSICALOFFSETY
:
572 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
573 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90)
574 return physDev
->PageSize
.cx
- physDev
->ImageableArea
.right
;
576 return physDev
->ImageableArea
.left
;
578 return physDev
->PageSize
.cy
- physDev
->ImageableArea
.top
;
588 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
593 static PRINTER_ENUM_VALUESA
*load_font_sub_table( HANDLE printer
, DWORD
*num_entries
)
595 DWORD res
, needed
, num
;
596 PRINTER_ENUM_VALUESA
*table
= NULL
;
597 static const char fontsubkey
[] = "PrinterDriverData\\FontSubTable";
601 res
= EnumPrinterDataExA( printer
, fontsubkey
, NULL
, 0, &needed
, &num
);
602 if (res
!= ERROR_MORE_DATA
) return NULL
;
604 table
= HeapAlloc( PSDRV_Heap
, 0, needed
);
605 if (!table
) return NULL
;
607 res
= EnumPrinterDataExA( printer
, fontsubkey
, (LPBYTE
)table
, needed
, &needed
, &num
);
608 if (res
!= ERROR_SUCCESS
)
610 HeapFree( PSDRV_Heap
, 0, table
);
618 static PSDRV_DEVMODE
*get_printer_devmode( HANDLE printer
)
620 DWORD needed
, dm_size
;
622 PRINTER_INFO_9W
*info
;
625 GetPrinterW( printer
, 9, NULL
, 0, &needed
);
626 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) return NULL
;
628 info
= HeapAlloc( PSDRV_Heap
, 0, needed
);
629 res
= GetPrinterW( printer
, 9, (BYTE
*)info
, needed
, &needed
);
630 if (!res
|| !info
->pDevMode
)
632 HeapFree( PSDRV_Heap
, 0, info
);
636 /* sanity check the sizes */
637 dm_size
= info
->pDevMode
->dmSize
+ info
->pDevMode
->dmDriverExtra
;
638 if ((char *)info
->pDevMode
- (char *)info
+ dm_size
> needed
)
640 HeapFree( PSDRV_Heap
, 0, info
);
644 dm
= (PSDRV_DEVMODE
*)info
;
645 memmove( dm
, info
->pDevMode
, dm_size
);
649 static PSDRV_DEVMODE
*get_devmode( HANDLE printer
, const WCHAR
*name
, BOOL
*is_default
)
651 PSDRV_DEVMODE
*dm
= get_printer_devmode( printer
);
655 if (dm
&& dm
->dmPublic
.dmSize
+ dm
->dmPublic
.dmDriverExtra
>= sizeof(DefaultDevmode
))
657 TRACE( "Retrieved devmode from winspool\n" );
660 HeapFree( PSDRV_Heap
, 0, dm
);
662 TRACE( "Using default devmode\n" );
663 dm
= HeapAlloc( PSDRV_Heap
, 0, sizeof(DefaultDevmode
) );
666 *dm
= DefaultDevmode
;
667 lstrcpynW( (WCHAR
*)dm
->dmPublic
.dmDeviceName
, name
, CCHDEVICENAME
);
673 static BOOL
set_devmode( HANDLE printer
, PSDRV_DEVMODE
*dm
)
675 PRINTER_INFO_9W info
;
676 info
.pDevMode
= &dm
->dmPublic
;
678 return SetPrinterW( printer
, 9, (BYTE
*)&info
, 0 );
681 static WCHAR
*get_ppd_filename( HANDLE printer
)
684 DRIVER_INFO_2W
*info
;
687 GetPrinterDriverW( printer
, NULL
, 2, NULL
, 0, &needed
);
688 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) return NULL
;
689 info
= HeapAlloc( GetProcessHeap(), 0, needed
);
690 if (!info
) return NULL
;
691 GetPrinterDriverW( printer
, NULL
, 2, (BYTE
*)info
, needed
, &needed
);
692 name
= (WCHAR
*)info
;
693 memmove( name
, info
->pDataFile
, (strlenW( info
->pDataFile
) + 1) * sizeof(WCHAR
) );
697 static struct list printer_list
= LIST_INIT( printer_list
);
699 /**********************************************************************
700 * PSDRV_FindPrinterInfo
702 PRINTERINFO
*PSDRV_FindPrinterInfo(LPCWSTR name
)
708 WCHAR
*ppd_filename
= NULL
;
710 BOOL using_default_devmode
= FALSE
;
713 TRACE("'%s'\n", debugstr_w(name
));
715 LIST_FOR_EACH_ENTRY( pi
, &printer_list
, PRINTERINFO
, entry
)
717 if (!strcmpW( pi
->friendly_name
, name
))
721 pi
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*pi
) );
722 if (pi
== NULL
) return NULL
;
724 if (!(pi
->friendly_name
= HeapAlloc( PSDRV_Heap
, 0, (strlenW(name
)+1)*sizeof(WCHAR
) ))) goto fail
;
725 strcpyW( pi
->friendly_name
, name
);
727 if (OpenPrinterW( pi
->friendly_name
, &hPrinter
, NULL
) == 0) {
728 ERR ("OpenPrinter failed with code %i\n", GetLastError ());
732 len
= WideCharToMultiByte( CP_ACP
, 0, name
, -1, NULL
, 0, NULL
, NULL
);
733 nameA
= HeapAlloc( GetProcessHeap(), 0, len
);
734 WideCharToMultiByte( CP_ACP
, 0, name
, -1, nameA
, len
, NULL
, NULL
);
736 pi
->Devmode
= get_devmode( hPrinter
, name
, &using_default_devmode
);
737 if (!pi
->Devmode
) goto fail
;
739 ppd_filename
= get_ppd_filename( hPrinter
);
740 if (!ppd_filename
) goto fail
;
742 pi
->ppd
= PSDRV_ParsePPD( ppd_filename
, hPrinter
);
745 WARN( "Couldn't parse PPD file %s\n", debugstr_w(ppd_filename
) );
749 if(using_default_devmode
) {
752 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IPAPERSIZE
| LOCALE_RETURN_NUMBER
,
753 (LPWSTR
)&papersize
, sizeof(papersize
)/sizeof(WCHAR
))) {
755 memset(&dm
, 0, sizeof(dm
));
756 dm
.dmPublic
.dmFields
= DM_PAPERSIZE
;
757 dm
.dmPublic
.u1
.s1
.dmPaperSize
= papersize
;
758 PSDRV_MergeDevmodes(pi
->Devmode
, &dm
, pi
);
762 if(pi
->ppd
->DefaultPageSize
) { /* We'll let the ppd override the devmode */
764 memset(&dm
, 0, sizeof(dm
));
765 dm
.dmPublic
.dmFields
= DM_PAPERSIZE
;
766 dm
.dmPublic
.u1
.s1
.dmPaperSize
= pi
->ppd
->DefaultPageSize
->WinPage
;
767 PSDRV_MergeDevmodes(pi
->Devmode
, &dm
, pi
);
770 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
771 WinDuplex == 0 is a special case which means that the ppd has a
772 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
773 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
774 PSDRV_WriteHeader understands this and copes. */
775 pi
->Devmode
->dmPublic
.dmFields
&= ~DM_DUPLEX
;
776 if(pi
->ppd
->DefaultDuplex
) {
777 pi
->Devmode
->dmPublic
.dmDuplex
= pi
->ppd
->DefaultDuplex
->WinDuplex
;
778 if(pi
->Devmode
->dmPublic
.dmDuplex
!= 0)
779 pi
->Devmode
->dmPublic
.dmFields
|= DM_DUPLEX
;
781 pi
->Devmode
->dmPublic
.dmDuplex
= DMDUP_SIMPLEX
;
784 set_devmode( hPrinter
, pi
->Devmode
);
786 pi
->FontSubTable
= load_font_sub_table( hPrinter
, &pi
->FontSubTableSize
);
788 LIST_FOR_EACH_ENTRY( font
, &pi
->ppd
->InstalledFonts
, FONTNAME
, entry
)
790 afm
= PSDRV_FindAFMinList(PSDRV_AFMFontList
, font
->Name
);
792 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
793 "ignoring\n", font
->Name
);
797 if (PSDRV_AddAFMtoList(&pi
->Fonts
, afm
, &added
) == FALSE
) {
798 PSDRV_FreeAFMList(pi
->Fonts
);
804 ClosePrinter( hPrinter
);
805 HeapFree( GetProcessHeap(), 0, nameA
);
806 HeapFree( GetProcessHeap(), 0, ppd_filename
);
807 list_add_head( &printer_list
, &pi
->entry
);
811 if (hPrinter
) ClosePrinter( hPrinter
);
812 HeapFree(PSDRV_Heap
, 0, pi
->FontSubTable
);
813 HeapFree(PSDRV_Heap
, 0, pi
->friendly_name
);
814 HeapFree(PSDRV_Heap
, 0, pi
->Devmode
);
815 HeapFree(PSDRV_Heap
, 0, pi
);
816 HeapFree( GetProcessHeap(), 0, nameA
);
817 HeapFree( GetProcessHeap(), 0, ppd_filename
);
822 static const struct gdi_dc_funcs psdrv_funcs
=
824 NULL
, /* pAbortDoc */
825 NULL
, /* pAbortPath */
826 NULL
, /* pAlphaBlend */
827 NULL
, /* pAngleArc */
828 PSDRV_Arc
, /* pArc */
830 NULL
, /* pBeginPath */
831 NULL
, /* pBlendImage */
832 PSDRV_Chord
, /* pChord */
833 NULL
, /* pCloseFigure */
834 PSDRV_CreateCompatibleDC
, /* pCreateCompatibleDC */
835 PSDRV_CreateDC
, /* pCreateDC */
836 PSDRV_DeleteDC
, /* pDeleteDC */
837 NULL
, /* pDeleteObject */
838 PSDRV_DeviceCapabilities
, /* pDeviceCapabilities */
839 PSDRV_Ellipse
, /* pEllipse */
840 PSDRV_EndDoc
, /* pEndDoc */
841 PSDRV_EndPage
, /* pEndPage */
843 PSDRV_EnumFonts
, /* pEnumFonts */
844 NULL
, /* pEnumICMProfiles */
845 NULL
, /* pExcludeClipRect */
846 PSDRV_ExtDeviceMode
, /* pExtDeviceMode */
847 PSDRV_ExtEscape
, /* pExtEscape */
848 NULL
, /* pExtFloodFill */
849 NULL
, /* pExtSelectClipRgn */
850 PSDRV_ExtTextOut
, /* pExtTextOut */
851 PSDRV_FillPath
, /* pFillPath */
853 NULL
, /* pFlattenPath */
854 NULL
, /* pFontIsLinked */
855 NULL
, /* pFrameRgn */
856 NULL
, /* pGdiComment */
857 NULL
, /* pGetBoundsRect */
858 NULL
, /* pGetCharABCWidths */
859 NULL
, /* pGetCharABCWidthsI */
860 PSDRV_GetCharWidth
, /* pGetCharWidth */
861 PSDRV_GetDeviceCaps
, /* pGetDeviceCaps */
862 NULL
, /* pGetDeviceGammaRamp */
863 NULL
, /* pGetFontData */
864 NULL
, /* pGetFontRealizationInfo */
865 NULL
, /* pGetFontUnicodeRanges */
866 NULL
, /* pGetGlyphIndices */
867 NULL
, /* pGetGlyphOutline */
868 NULL
, /* pGetICMProfile */
869 NULL
, /* pGetImage */
870 NULL
, /* pGetKerningPairs */
871 NULL
, /* pGetNearestColor */
872 NULL
, /* pGetOutlineTextMetrics */
873 NULL
, /* pGetPixel */
874 NULL
, /* pGetSystemPaletteEntries */
875 NULL
, /* pGetTextCharsetInfo */
876 PSDRV_GetTextExtentExPoint
, /* pGetTextExtentExPoint */
877 NULL
, /* pGetTextExtentExPointI */
878 NULL
, /* pGetTextFace */
879 PSDRV_GetTextMetrics
, /* pGetTextMetrics */
880 NULL
, /* pGradientFill */
881 NULL
, /* pIntersectClipRect */
882 NULL
, /* pInvertRgn */
883 PSDRV_LineTo
, /* pLineTo */
884 NULL
, /* pModifyWorldTransform */
886 NULL
, /* pOffsetClipRgn */
887 NULL
, /* pOffsetViewportOrg */
888 NULL
, /* pOffsetWindowOrg */
889 PSDRV_PaintRgn
, /* pPaintRgn */
890 PSDRV_PatBlt
, /* pPatBlt */
891 PSDRV_Pie
, /* pPie */
892 PSDRV_PolyBezier
, /* pPolyBezier */
893 PSDRV_PolyBezierTo
, /* pPolyBezierTo */
894 NULL
, /* pPolyDraw */
895 PSDRV_PolyPolygon
, /* pPolyPolygon */
896 PSDRV_PolyPolyline
, /* pPolyPolyline */
898 NULL
, /* pPolyline */
899 NULL
, /* pPolylineTo */
900 PSDRV_PutImage
, /* pPutImage */
901 NULL
, /* pRealizeDefaultPalette */
902 NULL
, /* pRealizePalette */
903 PSDRV_Rectangle
, /* pRectangle */
904 PSDRV_ResetDC
, /* pResetDC */
905 NULL
, /* pRestoreDC */
906 PSDRV_RoundRect
, /* pRoundRect */
908 NULL
, /* pScaleViewportExt */
909 NULL
, /* pScaleWindowExt */
910 NULL
, /* pSelectBitmap */
911 PSDRV_SelectBrush
, /* pSelectBrush */
912 NULL
, /* pSelectClipPath */
913 PSDRV_SelectFont
, /* pSelectFont */
914 NULL
, /* pSelectPalette */
915 PSDRV_SelectPen
, /* pSelectPen */
916 NULL
, /* pSetArcDirection */
917 PSDRV_SetBkColor
, /* pSetBkColor */
918 NULL
, /* pSetBkMode */
919 NULL
, /* pSetBoundsRect */
920 PSDRV_SetDCBrushColor
, /* pSetDCBrushColor */
921 PSDRV_SetDCPenColor
, /* pSetDCPenColor */
922 NULL
, /* pSetDIBitsToDevice */
923 NULL
, /* pSetDeviceClipping */
924 NULL
, /* pSetDeviceGammaRamp */
925 NULL
, /* pSetLayout */
926 NULL
, /* pSetMapMode */
927 NULL
, /* pSetMapperFlags */
928 PSDRV_SetPixel
, /* pSetPixel */
929 NULL
, /* pSetPolyFillMode */
931 NULL
, /* pSetRelAbs */
932 NULL
, /* pSetStretchBltMode */
933 NULL
, /* pSetTextAlign */
934 NULL
, /* pSetTextCharacterExtra */
935 PSDRV_SetTextColor
, /* pSetTextColor */
936 NULL
, /* pSetTextJustification */
937 NULL
, /* pSetViewportExt */
938 NULL
, /* pSetViewportOrg */
939 NULL
, /* pSetWindowExt */
940 NULL
, /* pSetWindowOrg */
941 NULL
, /* pSetWorldTransform */
942 PSDRV_StartDoc
, /* pStartDoc */
943 PSDRV_StartPage
, /* pStartPage */
944 NULL
, /* pStretchBlt */
945 NULL
, /* pStretchDIBits */
946 PSDRV_StrokeAndFillPath
, /* pStrokeAndFillPath */
947 PSDRV_StrokePath
, /* pStrokePath */
948 NULL
, /* pUnrealizePalette */
949 NULL
, /* pWidenPath */
950 NULL
, /* wine_get_wgl_driver */
951 GDI_PRIORITY_GRAPHICS_DRV
/* priority */
955 /******************************************************************************
956 * PSDRV_get_gdi_driver
958 const struct gdi_dc_funcs
* CDECL
PSDRV_get_gdi_driver( unsigned int version
)
960 if (version
!= WINE_GDI_DRIVER_VERSION
)
962 ERR( "version mismatch, gdi32 wants %u but wineps has %u\n", version
, WINE_GDI_DRIVER_VERSION
);