gdi32: Remove the remaining OpenGL entry points from the DC driver.
[wine/multimedia.git] / dlls / wineps.drv / init.c
blobf659287f3ec3a3b6ab6e5f994d03a3f5c5a2b5ef
1 /*
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "winreg.h"
35 #include "winnls.h"
36 #include "psdrv.h"
37 #include "winspool.h"
38 #include "wine/library.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
43 static const PSDRV_DEVMODE DefaultDevmode =
45 { /* dmPublic */
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_SCALE |
52 DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
53 DM_YRESOLUTION | DM_TTOPTION,
54 { /* u1 */
55 { /* s1 */
56 /* dmOrientation */ DMORIENT_PORTRAIT,
57 /* dmPaperSize */ DMPAPER_LETTER,
58 /* dmPaperLength */ 2794,
59 /* dmPaperWidth */ 2159,
60 /* dmScale */ 100, /* ?? */
61 /* dmCopies */ 1,
62 /* dmDefaultSource */ DMBIN_AUTO,
63 /* dmPrintQuality */ 0
66 /* dmColor */ DMCOLOR_COLOR,
67 /* dmDuplex */ DMDUP_SIMPLEX,
68 /* dmYResolution */ 0,
69 /* dmTTOption */ DMTT_SUBDEV,
70 /* dmCollate */ 0,
71 /* dmFormName */ {},
72 /* dmUnusedPadding */ 0,
73 /* dmBitsPerPel */ 0,
74 /* dmPelsWidth */ 0,
75 /* dmPelsHeight */ 0,
76 { /* u2 */
77 /* dmDisplayFlags */ 0
79 /* dmDisplayFrequency */ 0,
80 /* dmICMMethod */ 0,
81 /* dmICMIntent */ 0,
82 /* dmMediaType */ 0,
83 /* dmDitherType */ 0,
84 /* dmReserved1 */ 0,
85 /* dmReserved2 */ 0,
86 /* dmPanningWidth */ 0,
87 /* dmPanningHeight */ 0
89 { /* dmDocPrivate */
90 /* dummy */ 0
92 { /* dmDrvPrivate */
93 /* numInstalledOptions */ 0
97 HINSTANCE PSDRV_hInstance = 0;
98 HANDLE PSDRV_Heap = 0;
100 static HFONT PSDRV_DefaultFont = 0;
101 static const LOGFONTA DefaultLogFont = {
102 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
103 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
106 static const struct gdi_dc_funcs psdrv_funcs;
108 /*********************************************************************
109 * DllMain
111 * Initializes font metrics and registers driver. wineps dll entry point.
114 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
116 TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
118 switch(reason) {
120 case DLL_PROCESS_ATTACH:
121 PSDRV_hInstance = hinst;
122 DisableThreadLibraryCalls(hinst);
124 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
125 if (PSDRV_Heap == NULL)
126 return FALSE;
128 if (PSDRV_GetFontMetrics() == FALSE) {
129 HeapDestroy(PSDRV_Heap);
130 return FALSE;
133 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
134 if (PSDRV_DefaultFont == NULL) {
135 HeapDestroy(PSDRV_Heap);
136 return FALSE;
138 break;
140 case DLL_PROCESS_DETACH:
142 DeleteObject( PSDRV_DefaultFont );
143 HeapDestroy( PSDRV_Heap );
144 break;
147 return TRUE;
150 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
152 PAGESIZE *page;
153 INT width = 0, height = 0;
155 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
156 LIST_FOR_EACH_ENTRY(page, &physDev->pi->ppd->PageSizes, PAGESIZE, entry) {
157 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
158 break;
161 if(&page->entry == &physDev->pi->ppd->PageSizes) {
162 FIXME("Can't find page\n");
163 physDev->ImageableArea.left = 0;
164 physDev->ImageableArea.right = 0;
165 physDev->ImageableArea.bottom = 0;
166 physDev->ImageableArea.top = 0;
167 physDev->PageSize.cx = 0;
168 physDev->PageSize.cy = 0;
169 } else if(page->ImageableArea) {
170 /* physDev sizes in device units; ppd sizes in 1/72" */
171 physDev->ImageableArea.left = page->ImageableArea->llx *
172 physDev->logPixelsX / 72;
173 physDev->ImageableArea.right = page->ImageableArea->urx *
174 physDev->logPixelsX / 72;
175 physDev->ImageableArea.bottom = page->ImageableArea->lly *
176 physDev->logPixelsY / 72;
177 physDev->ImageableArea.top = page->ImageableArea->ury *
178 physDev->logPixelsY / 72;
179 physDev->PageSize.cx = page->PaperDimension->x *
180 physDev->logPixelsX / 72;
181 physDev->PageSize.cy = page->PaperDimension->y *
182 physDev->logPixelsY / 72;
183 } else {
184 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
185 physDev->ImageableArea.right = physDev->PageSize.cx =
186 page->PaperDimension->x * physDev->logPixelsX / 72;
187 physDev->ImageableArea.top = physDev->PageSize.cy =
188 page->PaperDimension->y * physDev->logPixelsY / 72;
190 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
191 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
192 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
193 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
194 physDev->ImageableArea.right = physDev->PageSize.cx =
195 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
196 physDev->logPixelsX / 254;
197 physDev->ImageableArea.top = physDev->PageSize.cy =
198 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
199 physDev->logPixelsY / 254;
200 } else {
201 FIXME("Odd dmFields %x\n", physDev->Devmode->dmPublic.dmFields);
202 physDev->ImageableArea.left = 0;
203 physDev->ImageableArea.right = 0;
204 physDev->ImageableArea.bottom = 0;
205 physDev->ImageableArea.top = 0;
206 physDev->PageSize.cx = 0;
207 physDev->PageSize.cy = 0;
210 TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %dx%d\n",
211 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
212 physDev->ImageableArea.right, physDev->ImageableArea.top,
213 physDev->PageSize.cx, physDev->PageSize.cy);
215 /* these are in device units */
216 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
217 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
219 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
220 physDev->horzRes = width;
221 physDev->vertRes = height;
222 } else {
223 physDev->horzRes = height;
224 physDev->vertRes = width;
227 /* these are in mm */
228 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
229 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
231 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
232 "horzRes = %d, vertRes = %d\n",
233 physDev->horzSize, physDev->vertSize,
234 physDev->horzRes, physDev->vertRes);
237 static PSDRV_PDEVICE *create_psdrv_physdev( PRINTERINFO *pi )
239 PSDRV_PDEVICE *physDev;
241 physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev) );
242 if (!physDev) return NULL;
244 physDev->Devmode = HeapAlloc( GetProcessHeap(), 0, sizeof(PSDRV_DEVMODE) );
245 if (!physDev->Devmode)
247 HeapFree( GetProcessHeap(), 0, physDev );
248 return NULL;
251 *physDev->Devmode = *pi->Devmode;
252 physDev->pi = pi;
253 physDev->logPixelsX = pi->ppd->DefaultResolution;
254 physDev->logPixelsY = pi->ppd->DefaultResolution;
255 return physDev;
258 /**********************************************************************
259 * PSDRV_CreateDC
261 static BOOL PSDRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
262 LPCWSTR output, const DEVMODEW* initData )
264 PSDRV_PDEVICE *physDev;
265 PRINTERINFO *pi;
267 TRACE("(%s %s %s %p)\n", debugstr_w(driver), debugstr_w(device),
268 debugstr_w(output), initData);
270 if (!device) return FALSE;
271 pi = PSDRV_FindPrinterInfo( device );
272 if(!pi) return FALSE;
274 if(!pi->Fonts) {
275 RASTERIZER_STATUS status;
276 if(!GetRasterizerCaps(&status, sizeof(status)) ||
277 !(status.wFlags & TT_AVAILABLE) ||
278 !(status.wFlags & TT_ENABLED)) {
279 MESSAGE("Disabling printer %s since it has no builtin fonts and there are no TrueType fonts available.\n",
280 debugstr_w(device));
281 return FALSE;
285 if (!(physDev = create_psdrv_physdev( pi ))) return FALSE;
287 if (output && *output) physDev->job.output = strdupW( output );
289 if(initData)
290 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODE *)initData, pi);
292 PSDRV_UpdateDevCaps(physDev);
293 SelectObject( (*pdev)->hdc, PSDRV_DefaultFont );
294 push_dc_driver( pdev, &physDev->dev, &psdrv_funcs );
295 return TRUE;
299 /**********************************************************************
300 * PSDRV_CreateCompatibleDC
302 static BOOL PSDRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
304 HDC hdc = (*pdev)->hdc;
305 PSDRV_PDEVICE *physDev, *orig_dev = get_psdrv_dev( orig );
306 PRINTERINFO *pi = PSDRV_FindPrinterInfo( orig_dev->pi->friendly_name );
308 if (!pi) return FALSE;
309 if (!(physDev = create_psdrv_physdev( pi ))) return FALSE;
310 PSDRV_MergeDevmodes( physDev->Devmode, orig_dev->Devmode, pi );
311 PSDRV_UpdateDevCaps(physDev);
312 SelectObject( hdc, PSDRV_DefaultFont );
313 push_dc_driver( pdev, &physDev->dev, &psdrv_funcs );
314 return TRUE;
319 /**********************************************************************
320 * PSDRV_DeleteDC
322 static BOOL PSDRV_DeleteDC( PHYSDEV dev )
324 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
326 TRACE("\n");
328 HeapFree( GetProcessHeap(), 0, physDev->Devmode );
329 HeapFree( GetProcessHeap(), 0, physDev->job.output );
330 HeapFree( GetProcessHeap(), 0, physDev );
332 return TRUE;
336 /**********************************************************************
337 * ResetDC (WINEPS.@)
339 static HDC PSDRV_ResetDC( PHYSDEV dev, const DEVMODEW *lpInitData )
341 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
343 if (lpInitData)
345 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODE *)lpInitData, physDev->pi);
346 PSDRV_UpdateDevCaps(physDev);
348 return dev->hdc;
351 /***********************************************************************
352 * GetDeviceCaps (WINEPS.@)
354 static INT PSDRV_GetDeviceCaps( PHYSDEV dev, INT cap )
356 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
358 switch(cap)
360 case DRIVERVERSION:
361 return 0;
362 case TECHNOLOGY:
363 return DT_RASPRINTER;
364 case HORZSIZE:
365 return MulDiv(physDev->horzSize, 100,
366 physDev->Devmode->dmPublic.u1.s1.dmScale);
367 case VERTSIZE:
368 return MulDiv(physDev->vertSize, 100,
369 physDev->Devmode->dmPublic.u1.s1.dmScale);
370 case HORZRES:
371 case DESKTOPHORZRES:
372 return physDev->horzRes;
373 case VERTRES:
374 case DESKTOPVERTRES:
375 return physDev->vertRes;
376 case BITSPIXEL:
377 return (physDev->pi->ppd->ColorDevice != CD_False) ? 32 : 1;
378 case PLANES:
379 return 1;
380 case NUMBRUSHES:
381 return -1;
382 case NUMPENS:
383 return 10;
384 case NUMMARKERS:
385 return 0;
386 case NUMFONTS:
387 return 39;
388 case NUMCOLORS:
389 return -1;
390 case PDEVICESIZE:
391 return sizeof(PSDRV_PDEVICE);
392 case CURVECAPS:
393 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
394 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
395 case LINECAPS:
396 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
397 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
398 case POLYGONALCAPS:
399 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
400 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
401 case TEXTCAPS:
402 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
403 case CLIPCAPS:
404 return CP_RECTANGLE;
405 case RASTERCAPS:
406 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
407 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
408 /* Are aspect[XY] and logPixels[XY] correct? */
409 /* Need to handle different res in x and y => fix ppd */
410 case ASPECTX:
411 case ASPECTY:
412 return physDev->pi->ppd->DefaultResolution;
413 case ASPECTXY:
414 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
415 (double)physDev->pi->ppd->DefaultResolution );
416 case LOGPIXELSX:
417 return MulDiv(physDev->logPixelsX,
418 physDev->Devmode->dmPublic.u1.s1.dmScale, 100);
419 case LOGPIXELSY:
420 return MulDiv(physDev->logPixelsY,
421 physDev->Devmode->dmPublic.u1.s1.dmScale, 100);
422 case SIZEPALETTE:
423 return 0;
424 case NUMRESERVED:
425 return 0;
426 case COLORRES:
427 return 0;
428 case PHYSICALWIDTH:
429 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
430 physDev->PageSize.cy : physDev->PageSize.cx;
431 case PHYSICALHEIGHT:
432 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
433 physDev->PageSize.cx : physDev->PageSize.cy;
434 case PHYSICALOFFSETX:
435 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
436 if(physDev->pi->ppd->LandscapeOrientation == -90)
437 return physDev->PageSize.cy - physDev->ImageableArea.top;
438 else
439 return physDev->ImageableArea.bottom;
441 return physDev->ImageableArea.left;
443 case PHYSICALOFFSETY:
444 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
445 if(physDev->pi->ppd->LandscapeOrientation == -90)
446 return physDev->PageSize.cx - physDev->ImageableArea.right;
447 else
448 return physDev->ImageableArea.left;
450 return physDev->PageSize.cy - physDev->ImageableArea.top;
452 case SCALINGFACTORX:
453 case SCALINGFACTORY:
454 case VREFRESH:
455 case BLTALIGNMENT:
456 return 0;
457 case SHADEBLENDCAPS:
458 return SB_NONE;
459 default:
460 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
461 return 0;
465 static PRINTER_ENUM_VALUESA *load_font_sub_table( HANDLE printer, DWORD *num_entries )
467 DWORD res, needed, num;
468 PRINTER_ENUM_VALUESA *table = NULL;
469 static const char fontsubkey[] = "PrinterDriverData\\FontSubTable";
471 *num_entries = 0;
473 res = EnumPrinterDataExA( printer, fontsubkey, NULL, 0, &needed, &num );
474 if (res != ERROR_MORE_DATA) return NULL;
476 table = HeapAlloc( PSDRV_Heap, 0, needed );
477 if (!table) return NULL;
479 res = EnumPrinterDataExA( printer, fontsubkey, (LPBYTE)table, needed, &needed, &num );
480 if (res != ERROR_SUCCESS)
482 HeapFree( PSDRV_Heap, 0, table );
483 return NULL;
486 *num_entries = num;
487 return table;
490 static PSDRV_DEVMODE *get_printer_devmode( HANDLE printer )
492 DWORD needed, dm_size;
493 BOOL res;
494 PRINTER_INFO_9W *info;
495 PSDRV_DEVMODE *dm;
497 GetPrinterW( printer, 9, NULL, 0, &needed );
498 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL;
500 info = HeapAlloc( PSDRV_Heap, 0, needed );
501 res = GetPrinterW( printer, 9, (BYTE *)info, needed, &needed );
502 if (!res || !info->pDevMode)
504 HeapFree( PSDRV_Heap, 0, info );
505 return NULL;
508 /* sanity check the sizes */
509 dm_size = info->pDevMode->dmSize + info->pDevMode->dmDriverExtra;
510 if ((char *)info->pDevMode - (char *)info + dm_size > needed)
512 HeapFree( PSDRV_Heap, 0, info );
513 return NULL;
516 dm = (PSDRV_DEVMODE*)info;
517 memmove( dm, info->pDevMode, dm_size );
518 return dm;
521 static PSDRV_DEVMODE *get_devmode( HANDLE printer, const WCHAR *name, BOOL *is_default )
523 PSDRV_DEVMODE *dm = get_printer_devmode( printer );
525 *is_default = FALSE;
527 if (dm && dm->dmPublic.dmSize + dm->dmPublic.dmDriverExtra >= sizeof(DefaultDevmode))
529 TRACE( "Retrieved devmode from winspool\n" );
530 return dm;
532 HeapFree( PSDRV_Heap, 0, dm );
534 TRACE( "Using default devmode\n" );
535 dm = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
536 if (dm)
538 *dm = DefaultDevmode;
539 lstrcpynW( (WCHAR *)dm->dmPublic.dmDeviceName, name, CCHDEVICENAME );
540 *is_default = TRUE;
542 return dm;
545 static BOOL set_devmode( HANDLE printer, PSDRV_DEVMODE *dm )
547 PRINTER_INFO_9W info;
548 info.pDevMode = &dm->dmPublic;
550 return SetPrinterW( printer, 9, (BYTE *)&info, 0 );
553 static char *get_ppd_filename( HANDLE printer )
555 DWORD needed;
556 DRIVER_INFO_2W *info;
557 char *unixname;
559 GetPrinterDriverW( printer, NULL, 2, NULL, 0, &needed );
560 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL;
561 info = HeapAlloc( GetProcessHeap(), 0, needed );
562 if (!info) return NULL;
563 GetPrinterDriverW( printer, NULL, 2, (BYTE*)info, needed, &needed );
564 unixname = wine_get_unix_file_name( info->pDataFile );
565 HeapFree( GetProcessHeap(), 0, info );
567 return unixname;
570 static struct list printer_list = LIST_INIT( printer_list );
572 /**********************************************************************
573 * PSDRV_FindPrinterInfo
575 PRINTERINFO *PSDRV_FindPrinterInfo(LPCWSTR name)
577 DWORD needed, res, dwPaperSize;
578 PRINTERINFO *pi;
579 FONTNAME *font;
580 const AFM *afm;
581 HANDLE hPrinter = 0;
582 char *ppd_filename = NULL, *nameA = NULL;
583 BOOL using_default_devmode = FALSE;
584 int len;
586 TRACE("'%s'\n", debugstr_w(name));
588 LIST_FOR_EACH_ENTRY( pi, &printer_list, PRINTERINFO, entry )
590 if (!strcmpW( pi->friendly_name, name ))
591 return pi;
594 pi = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
595 if (pi == NULL) return NULL;
597 if (!(pi->friendly_name = HeapAlloc( PSDRV_Heap, 0, (strlenW(name)+1)*sizeof(WCHAR) ))) goto fail;
598 strcpyW( pi->friendly_name, name );
600 if (OpenPrinterW( pi->friendly_name, &hPrinter, NULL ) == 0) {
601 ERR ("OpenPrinter failed with code %i\n", GetLastError ());
602 goto fail;
605 len = WideCharToMultiByte( CP_ACP, 0, name, -1, NULL, 0, NULL, NULL );
606 nameA = HeapAlloc( GetProcessHeap(), 0, len );
607 WideCharToMultiByte( CP_ACP, 0, name, -1, nameA, len, NULL, NULL );
609 pi->Devmode = get_devmode( hPrinter, name, &using_default_devmode );
610 if (!pi->Devmode) goto fail;
612 ppd_filename = get_ppd_filename( hPrinter );
613 if (!ppd_filename) goto fail;
615 pi->ppd = PSDRV_ParsePPD( ppd_filename, hPrinter );
616 if (!pi->ppd)
618 WARN( "Couldn't parse PPD file '%s'\n", ppd_filename );
619 goto fail;
622 if(using_default_devmode) {
623 DWORD papersize;
625 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
626 (LPWSTR)&papersize, sizeof(papersize)/sizeof(WCHAR))) {
627 PSDRV_DEVMODE dm;
628 memset(&dm, 0, sizeof(dm));
629 dm.dmPublic.dmFields = DM_PAPERSIZE;
630 dm.dmPublic.u1.s1.dmPaperSize = papersize;
631 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
635 if(pi->ppd->DefaultPageSize) { /* We'll let the ppd override the devmode */
636 PSDRV_DEVMODE dm;
637 memset(&dm, 0, sizeof(dm));
638 dm.dmPublic.dmFields = DM_PAPERSIZE;
639 dm.dmPublic.u1.s1.dmPaperSize = pi->ppd->DefaultPageSize->WinPage;
640 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
644 * This is a hack. The default paper size should be read in as part of
645 * the Devmode structure, but Wine doesn't currently provide a convenient
646 * way to configure printers.
648 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "Paper Size", NULL,
649 (LPBYTE)&dwPaperSize, sizeof(DWORD), &needed);
650 if (res == ERROR_SUCCESS)
651 pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize;
652 else if (res == ERROR_FILE_NOT_FOUND)
653 TRACE ("No 'Paper Size' for printer '%s'\n", debugstr_w(name));
654 else {
655 ERR ("GetPrinterDataA returned %i\n", res);
656 goto fail;
659 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
660 WinDuplex == 0 is a special case which means that the ppd has a
661 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
662 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
663 PSDRV_WriteHeader understands this and copes. */
664 pi->Devmode->dmPublic.dmFields &= ~DM_DUPLEX;
665 if(pi->ppd->DefaultDuplex) {
666 pi->Devmode->dmPublic.dmDuplex = pi->ppd->DefaultDuplex->WinDuplex;
667 if(pi->Devmode->dmPublic.dmDuplex != 0)
668 pi->Devmode->dmPublic.dmFields |= DM_DUPLEX;
669 else
670 pi->Devmode->dmPublic.dmDuplex = DMDUP_SIMPLEX;
673 set_devmode( hPrinter, pi->Devmode );
675 pi->FontSubTable = load_font_sub_table( hPrinter, &pi->FontSubTableSize );
677 LIST_FOR_EACH_ENTRY( font, &pi->ppd->InstalledFonts, FONTNAME, entry )
679 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
680 if(!afm) {
681 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
682 "ignoring\n", font->Name);
684 else {
685 BOOL added;
686 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
687 PSDRV_FreeAFMList(pi->Fonts);
688 goto fail;
693 ClosePrinter( hPrinter );
694 HeapFree( GetProcessHeap(), 0, nameA );
695 HeapFree( GetProcessHeap(), 0, ppd_filename );
696 list_add_head( &printer_list, &pi->entry );
697 return pi;
699 fail:
700 if (hPrinter) ClosePrinter( hPrinter );
701 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
702 HeapFree(PSDRV_Heap, 0, pi->friendly_name);
703 HeapFree(PSDRV_Heap, 0, pi->Devmode);
704 HeapFree(PSDRV_Heap, 0, pi);
705 HeapFree( GetProcessHeap(), 0, nameA );
706 HeapFree( GetProcessHeap(), 0, ppd_filename );
707 return NULL;
711 static const struct gdi_dc_funcs psdrv_funcs =
713 NULL, /* pAbortDoc */
714 NULL, /* pAbortPath */
715 NULL, /* pAlphaBlend */
716 NULL, /* pAngleArc */
717 PSDRV_Arc, /* pArc */
718 NULL, /* pArcTo */
719 NULL, /* pBeginPath */
720 NULL, /* pBlendImage */
721 PSDRV_Chord, /* pChord */
722 NULL, /* pCloseFigure */
723 PSDRV_CreateCompatibleDC, /* pCreateCompatibleDC */
724 PSDRV_CreateDC, /* pCreateDC */
725 PSDRV_DeleteDC, /* pDeleteDC */
726 NULL, /* pDeleteObject */
727 NULL, /* pDescribePixelFormat */
728 PSDRV_DeviceCapabilities, /* pDeviceCapabilities */
729 PSDRV_Ellipse, /* pEllipse */
730 PSDRV_EndDoc, /* pEndDoc */
731 PSDRV_EndPage, /* pEndPage */
732 NULL, /* pEndPath */
733 PSDRV_EnumFonts, /* pEnumFonts */
734 NULL, /* pEnumICMProfiles */
735 NULL, /* pExcludeClipRect */
736 PSDRV_ExtDeviceMode, /* pExtDeviceMode */
737 PSDRV_ExtEscape, /* pExtEscape */
738 NULL, /* pExtFloodFill */
739 NULL, /* pExtSelectClipRgn */
740 PSDRV_ExtTextOut, /* pExtTextOut */
741 PSDRV_FillPath, /* pFillPath */
742 NULL, /* pFillRgn */
743 NULL, /* pFlattenPath */
744 NULL, /* pFontIsLinked */
745 NULL, /* pFrameRgn */
746 NULL, /* pGdiComment */
747 NULL, /* pGdiRealizationInfo */
748 NULL, /* pGetBoundsRect */
749 NULL, /* pGetCharABCWidths */
750 NULL, /* pGetCharABCWidthsI */
751 PSDRV_GetCharWidth, /* pGetCharWidth */
752 PSDRV_GetDeviceCaps, /* pGetDeviceCaps */
753 NULL, /* pGetDeviceGammaRamp */
754 NULL, /* pGetFontData */
755 NULL, /* pGetFontUnicodeRanges */
756 NULL, /* pGetGlyphIndices */
757 NULL, /* pGetGlyphOutline */
758 NULL, /* pGetICMProfile */
759 NULL, /* pGetImage */
760 NULL, /* pGetKerningPairs */
761 NULL, /* pGetNearestColor */
762 NULL, /* pGetOutlineTextMetrics */
763 NULL, /* pGetPixel */
764 NULL, /* pGetSystemPaletteEntries */
765 NULL, /* pGetTextCharsetInfo */
766 PSDRV_GetTextExtentExPoint, /* pGetTextExtentExPoint */
767 NULL, /* pGetTextExtentExPointI */
768 NULL, /* pGetTextFace */
769 PSDRV_GetTextMetrics, /* pGetTextMetrics */
770 NULL, /* pGradientFill */
771 NULL, /* pIntersectClipRect */
772 NULL, /* pInvertRgn */
773 PSDRV_LineTo, /* pLineTo */
774 NULL, /* pModifyWorldTransform */
775 NULL, /* pMoveTo */
776 NULL, /* pOffsetClipRgn */
777 NULL, /* pOffsetViewportOrg */
778 NULL, /* pOffsetWindowOrg */
779 PSDRV_PaintRgn, /* pPaintRgn */
780 PSDRV_PatBlt, /* pPatBlt */
781 PSDRV_Pie, /* pPie */
782 PSDRV_PolyBezier, /* pPolyBezier */
783 PSDRV_PolyBezierTo, /* pPolyBezierTo */
784 NULL, /* pPolyDraw */
785 PSDRV_PolyPolygon, /* pPolyPolygon */
786 PSDRV_PolyPolyline, /* pPolyPolyline */
787 NULL, /* pPolygon */
788 NULL, /* pPolyline */
789 NULL, /* pPolylineTo */
790 PSDRV_PutImage, /* pPutImage */
791 NULL, /* pRealizeDefaultPalette */
792 NULL, /* pRealizePalette */
793 PSDRV_Rectangle, /* pRectangle */
794 PSDRV_ResetDC, /* pResetDC */
795 NULL, /* pRestoreDC */
796 PSDRV_RoundRect, /* pRoundRect */
797 NULL, /* pSaveDC */
798 NULL, /* pScaleViewportExt */
799 NULL, /* pScaleWindowExt */
800 NULL, /* pSelectBitmap */
801 PSDRV_SelectBrush, /* pSelectBrush */
802 NULL, /* pSelectClipPath */
803 PSDRV_SelectFont, /* pSelectFont */
804 NULL, /* pSelectPalette */
805 PSDRV_SelectPen, /* pSelectPen */
806 NULL, /* pSetArcDirection */
807 PSDRV_SetBkColor, /* pSetBkColor */
808 NULL, /* pSetBkMode */
809 NULL, /* pSetBoundsRect */
810 PSDRV_SetDCBrushColor, /* pSetDCBrushColor */
811 PSDRV_SetDCPenColor, /* pSetDCPenColor */
812 NULL, /* pSetDIBitsToDevice */
813 NULL, /* pSetDeviceClipping */
814 NULL, /* pSetDeviceGammaRamp */
815 NULL, /* pSetLayout */
816 NULL, /* pSetMapMode */
817 NULL, /* pSetMapperFlags */
818 PSDRV_SetPixel, /* pSetPixel */
819 NULL, /* pSetPixelFormat */
820 NULL, /* pSetPolyFillMode */
821 NULL, /* pSetROP2 */
822 NULL, /* pSetRelAbs */
823 NULL, /* pSetStretchBltMode */
824 NULL, /* pSetTextAlign */
825 NULL, /* pSetTextCharacterExtra */
826 PSDRV_SetTextColor, /* pSetTextColor */
827 NULL, /* pSetTextJustification */
828 NULL, /* pSetViewportExt */
829 NULL, /* pSetViewportOrg */
830 NULL, /* pSetWindowExt */
831 NULL, /* pSetWindowOrg */
832 NULL, /* pSetWorldTransform */
833 PSDRV_StartDoc, /* pStartDoc */
834 PSDRV_StartPage, /* pStartPage */
835 NULL, /* pStretchBlt */
836 NULL, /* pStretchDIBits */
837 PSDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
838 PSDRV_StrokePath, /* pStrokePath */
839 NULL, /* pSwapBuffers */
840 NULL, /* pUnrealizePalette */
841 NULL, /* pWidenPath */
842 NULL, /* wine_get_wgl_driver */
843 GDI_PRIORITY_GRAPHICS_DRV /* priority */
847 /******************************************************************************
848 * PSDRV_get_gdi_driver
850 const struct gdi_dc_funcs * CDECL PSDRV_get_gdi_driver( unsigned int version )
852 if (version != WINE_GDI_DRIVER_VERSION)
854 ERR( "version mismatch, gdi32 wants %u but wineps has %u\n", version, WINE_GDI_DRIVER_VERSION );
855 return NULL;
857 return &psdrv_funcs;