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
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
48 static void *cupshandle = NULL;
51 static const PSDRV_DEVMODEA DefaultDevmode =
54 /* dmDeviceName */ "Wine PostScript Driver",
55 /* dmSpecVersion */ 0x30a,
56 /* dmDriverVersion */ 0x001,
57 /* dmSize */ sizeof(DEVMODEA),
58 /* dmDriverExtra */ sizeof(PSDRV_DEVMODEA)-sizeof(DEVMODEA),
59 /* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE |
60 DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
61 DM_YRESOLUTION | DM_TTOPTION,
64 /* dmOrientation */ DMORIENT_PORTRAIT,
65 /* dmPaperSize */ DMPAPER_LETTER,
66 /* dmPaperLength */ 2794,
67 /* dmPaperWidth */ 2159,
68 /* dmScale */ 100, /* ?? */
70 /* dmDefaultSource */ DMBIN_AUTO,
71 /* dmPrintQuality */ 0
74 /* dmColor */ DMCOLOR_COLOR,
75 /* dmDuplex */ DMDUP_SIMPLEX,
76 /* dmYResolution */ 0,
77 /* dmTTOption */ DMTT_SUBDEV,
80 /* dmUnusedPadding */ 0,
85 /* dmDisplayFlags */ 0
87 /* dmDisplayFrequency */ 0,
94 /* dmPanningWidth */ 0,
95 /* dmPanningHeight */ 0
101 /* numInstalledOptions */ 0
105 HINSTANCE PSDRV_hInstance = 0;
106 HANDLE PSDRV_Heap = 0;
108 static HFONT PSDRV_DefaultFont = 0;
109 static const LOGFONTA DefaultLogFont = {
110 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
111 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
114 static const CHAR default_devmodeA[] = "Default DevMode";
116 /*********************************************************************
119 * Initializes font metrics and registers driver. wineps dll entry point.
122 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
124 TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
128 case DLL_PROCESS_ATTACH:
129 PSDRV_hInstance = hinst;
130 DisableThreadLibraryCalls(hinst);
132 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
133 if (PSDRV_Heap == NULL)
136 if (PSDRV_GetFontMetrics() == FALSE) {
137 HeapDestroy(PSDRV_Heap);
141 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
142 if (PSDRV_DefaultFont == NULL) {
143 HeapDestroy(PSDRV_Heap);
146 #ifdef SONAME_LIBCUPS
147 /* dynamically load CUPS if not yet loaded */
149 cupshandle = wine_dlopen(SONAME_LIBCUPS, RTLD_NOW, NULL, 0);
150 if (!cupshandle) cupshandle = (void*)-1;
155 case DLL_PROCESS_DETACH:
157 DeleteObject( PSDRV_DefaultFont );
158 HeapDestroy( PSDRV_Heap );
159 #ifdef SONAME_LIBCUPS
160 if (cupshandle && (cupshandle != (void*)-1)) {
161 wine_dlclose(cupshandle, NULL, 0);
172 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
175 INT width = 0, height = 0;
177 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
178 LIST_FOR_EACH_ENTRY(page, &physDev->pi->ppd->PageSizes, PAGESIZE, entry) {
179 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
183 if(&page->entry == &physDev->pi->ppd->PageSizes) {
184 FIXME("Can't find page\n");
185 physDev->ImageableArea.left = 0;
186 physDev->ImageableArea.right = 0;
187 physDev->ImageableArea.bottom = 0;
188 physDev->ImageableArea.top = 0;
189 physDev->PageSize.cx = 0;
190 physDev->PageSize.cy = 0;
191 } else if(page->ImageableArea) {
192 /* physDev sizes in device units; ppd sizes in 1/72" */
193 physDev->ImageableArea.left = page->ImageableArea->llx *
194 physDev->logPixelsX / 72;
195 physDev->ImageableArea.right = page->ImageableArea->urx *
196 physDev->logPixelsX / 72;
197 physDev->ImageableArea.bottom = page->ImageableArea->lly *
198 physDev->logPixelsY / 72;
199 physDev->ImageableArea.top = page->ImageableArea->ury *
200 physDev->logPixelsY / 72;
201 physDev->PageSize.cx = page->PaperDimension->x *
202 physDev->logPixelsX / 72;
203 physDev->PageSize.cy = page->PaperDimension->y *
204 physDev->logPixelsY / 72;
206 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
207 physDev->ImageableArea.right = physDev->PageSize.cx =
208 page->PaperDimension->x * physDev->logPixelsX / 72;
209 physDev->ImageableArea.top = physDev->PageSize.cy =
210 page->PaperDimension->y * physDev->logPixelsY / 72;
212 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
213 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
214 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
215 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
216 physDev->ImageableArea.right = physDev->PageSize.cx =
217 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
218 physDev->logPixelsX / 254;
219 physDev->ImageableArea.top = physDev->PageSize.cy =
220 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
221 physDev->logPixelsY / 254;
223 FIXME("Odd dmFields %x\n", physDev->Devmode->dmPublic.dmFields);
224 physDev->ImageableArea.left = 0;
225 physDev->ImageableArea.right = 0;
226 physDev->ImageableArea.bottom = 0;
227 physDev->ImageableArea.top = 0;
228 physDev->PageSize.cx = 0;
229 physDev->PageSize.cy = 0;
232 TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %dx%d\n",
233 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
234 physDev->ImageableArea.right, physDev->ImageableArea.top,
235 physDev->PageSize.cx, physDev->PageSize.cy);
237 /* these are in device units */
238 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
239 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
241 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
242 physDev->horzRes = width;
243 physDev->vertRes = height;
245 physDev->horzRes = height;
246 physDev->vertRes = width;
249 /* these are in mm */
250 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
251 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
253 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
254 "horzRes = %d, vertRes = %d\n",
255 physDev->horzSize, physDev->vertSize,
256 physDev->horzRes, physDev->vertRes);
260 /***********************************************************
263 * Creates an ascii copy of supplied devmode on heap
265 * Copied from dlls/winspool/info.c until full unicodification
267 static LPDEVMODEA DEVMODEdupWtoA(HANDLE heap, const DEVMODEW *dmW)
272 ptrdiff_t off_formname = (const char *)dmW->dmFormName - (const char *)dmW;
274 if(!dmW) return NULL;
275 Formname = (dmW->dmSize > off_formname);
276 size = dmW->dmSize - CCHDEVICENAME - (Formname ? CCHFORMNAME : 0);
277 dmA = HeapAlloc(heap, HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra);
278 WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1, (LPSTR)dmA->dmDeviceName,
279 CCHDEVICENAME, NULL, NULL);
281 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
282 dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR));
284 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
285 off_formname - CCHDEVICENAME * sizeof(WCHAR));
286 WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1, (LPSTR)dmA->dmFormName,
287 CCHFORMNAME, NULL, NULL);
288 memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
289 (off_formname + CCHFORMNAME * sizeof(WCHAR)));
292 memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize,
298 /**********************************************************************
301 BOOL CDECL PSDRV_CreateDC( HDC hdc, PSDRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device,
302 LPCWSTR output, const DEVMODEW* initData )
304 PSDRV_PDEVICE *physDev;
308 /* If no device name was specified, retrieve the device name
309 * from the DEVMODE structure from the DC's physDev.
310 * (See CreateCompatibleDC) */
311 if ( !device && *pdev )
314 deviceA = HeapAlloc(GetProcessHeap(), 0, CCHDEVICENAME);
315 lstrcpynA(deviceA, (LPCSTR)physDev->Devmode->dmPublic.dmDeviceName, CCHDEVICENAME);
319 DWORD len = WideCharToMultiByte(CP_ACP, 0, device, -1, NULL, 0, NULL, NULL);
320 deviceA = HeapAlloc(GetProcessHeap(), 0, len);
321 WideCharToMultiByte(CP_ACP, 0, device, -1, deviceA, len, NULL, NULL);
323 pi = PSDRV_FindPrinterInfo(deviceA);
325 HeapFree(GetProcessHeap(), 0, deviceA);
328 TRACE("(%s %s %s %p)\n", debugstr_w(driver), debugstr_w(device),
329 debugstr_w(output), initData);
331 if(!pi) return FALSE;
334 RASTERIZER_STATUS status;
335 if(!GetRasterizerCaps(&status, sizeof(status)) ||
336 !(status.wFlags & TT_AVAILABLE) ||
337 !(status.wFlags & TT_ENABLED)) {
338 MESSAGE("Disabling printer %s since it has no builtin fonts and there are no TrueType fonts available.\n",
344 physDev = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*physDev) );
345 if (!physDev) return FALSE;
351 physDev->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(PSDRV_DEVMODEA) );
352 if(!physDev->Devmode) {
353 HeapFree( PSDRV_Heap, 0, physDev );
357 *physDev->Devmode = *pi->Devmode;
359 physDev->logPixelsX = physDev->pi->ppd->DefaultResolution;
360 physDev->logPixelsY = physDev->pi->ppd->DefaultResolution;
362 if (output && *output) {
363 INT len = WideCharToMultiByte( CP_ACP, 0, output, -1, NULL, 0, NULL, NULL );
364 if ((physDev->job.output = HeapAlloc( PSDRV_Heap, 0, len )))
365 WideCharToMultiByte( CP_ACP, 0, output, -1, physDev->job.output, len, NULL, NULL );
367 physDev->job.output = NULL;
368 physDev->job.hJob = 0;
371 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, initData);
372 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, pi);
373 HeapFree(PSDRV_Heap, 0, devmodeA);
376 PSDRV_UpdateDevCaps(physDev);
377 SelectObject( hdc, PSDRV_DefaultFont );
383 /**********************************************************************
386 BOOL CDECL PSDRV_DeleteDC( PSDRV_PDEVICE *physDev )
390 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
391 HeapFree( PSDRV_Heap, 0, physDev->job.output );
392 HeapFree( PSDRV_Heap, 0, physDev );
398 /**********************************************************************
401 HDC CDECL PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEW *lpInitData )
405 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, lpInitData);
406 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, physDev->pi);
407 HeapFree(PSDRV_Heap, 0, devmodeA);
408 PSDRV_UpdateDevCaps(physDev);
409 hrgn = CreateRectRgn(0, 0, physDev->horzRes, physDev->vertRes);
410 SelectVisRgn( physDev->hdc, hrgn );
416 /***********************************************************************
417 * GetDeviceCaps (WINEPS.@)
419 INT CDECL PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap )
426 return DT_RASPRINTER;
428 return MulDiv(physDev->horzSize, 100,
429 physDev->Devmode->dmPublic.u1.s1.dmScale);
431 return MulDiv(physDev->vertSize, 100,
432 physDev->Devmode->dmPublic.u1.s1.dmScale);
435 return physDev->horzRes;
438 return physDev->vertRes;
440 return (physDev->pi->ppd->ColorDevice != CD_False) ? 8 : 1;
452 return (physDev->pi->ppd->ColorDevice != CD_False) ? 256 : -1;
454 return sizeof(PSDRV_PDEVICE);
456 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
457 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
459 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
460 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
462 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
463 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
465 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
469 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
470 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
471 /* Are aspect[XY] and logPixels[XY] correct? */
472 /* Need to handle different res in x and y => fix ppd */
475 return physDev->pi->ppd->DefaultResolution;
477 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
478 (double)physDev->pi->ppd->DefaultResolution );
480 return MulDiv(physDev->logPixelsX,
481 physDev->Devmode->dmPublic.u1.s1.dmScale, 100);
483 return MulDiv(physDev->logPixelsY,
484 physDev->Devmode->dmPublic.u1.s1.dmScale, 100);
492 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
493 physDev->PageSize.cy : physDev->PageSize.cx;
495 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
496 physDev->PageSize.cx : physDev->PageSize.cy;
497 case PHYSICALOFFSETX:
498 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
499 if(physDev->pi->ppd->LandscapeOrientation == -90)
500 return physDev->PageSize.cy - physDev->ImageableArea.top;
502 return physDev->ImageableArea.bottom;
504 return physDev->ImageableArea.left;
506 case PHYSICALOFFSETY:
507 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
508 if(physDev->pi->ppd->LandscapeOrientation == -90)
509 return physDev->PageSize.cx - physDev->ImageableArea.right;
511 return physDev->ImageableArea.left;
513 return physDev->PageSize.cy - physDev->ImageableArea.top;
521 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
527 /**********************************************************************
528 * PSDRV_FindPrinterInfo
530 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
532 static PRINTERINFO *PSDRV_PrinterList;
533 DWORD type = REG_BINARY, needed, res, dwPaperSize;
534 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
538 const char *ppd = NULL;
540 char* ppdFileName = NULL;
542 BOOL using_default_devmode = FALSE;
544 TRACE("'%s'\n", name);
547 * If this loop completes, last will point to the 'next' element of the
548 * final PRINTERINFO in the list
550 for( ; pi; last = &pi->next, pi = pi->next)
551 if(!strcmp(pi->FriendlyName, name))
554 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
558 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
559 strcpy( pi->FriendlyName, name );
561 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
562 ERR ("OpenPrinterA failed with code %i\n", GetLastError ());
567 res = GetPrinterDataExA(hPrinter, NULL, default_devmodeA, &type, NULL, 0, &needed);
569 if (needed < sizeof(DefaultDevmode)) {
570 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
571 if (pi->Devmode == NULL)
574 *pi->Devmode = DefaultDevmode;
575 lstrcpynA((LPSTR)pi->Devmode->dmPublic.dmDeviceName,name,CCHDEVICENAME);
576 using_default_devmode = TRUE;
579 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
580 if (pi->Devmode == NULL)
583 GetPrinterDataExA(hPrinter, NULL, default_devmodeA, &type, (LPBYTE)pi->Devmode, needed, &needed);
588 #ifdef SONAME_LIBCUPS
589 if (cupshandle != (void*)-1) {
590 typeof(cupsGetPPD) * pcupsGetPPD = NULL;
592 pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0);
594 ppd = pcupsGetPPD(name);
597 needed=strlen(ppd)+1;
598 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
599 memcpy(ppdFileName, ppd, needed);
602 /* we should unlink() that file later */
604 res = ERROR_FILE_NOT_FOUND;
605 WARN("Did not find ppd for %s\n",name);
611 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "PPD File", NULL, NULL, 0, &needed);
612 if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
613 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
614 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "PPD File", &ppdType,
615 (LPBYTE)ppdFileName, needed, &needed);
618 /* Look for a ppd file for this printer in the config file.
619 * First look under that printer's name, and then under 'generic'
621 /* @@ Wine registry key: HKCU\Software\Wine\Printing\PPD Files */
622 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Printing\\PPD Files", &hkey))
624 const char* value_name;
626 if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
628 } else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
629 value_name="generic";
634 HeapFree(PSDRV_Heap, 0, ppdFileName);
635 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
636 RegQueryValueExA(hkey, value_name, 0, &ppdType, (LPBYTE)ppdFileName, &needed);
643 const char *data_dir, *filename;
645 if ((data_dir = wine_get_data_dir())) filename = "/generic.ppd";
646 else if ((data_dir = wine_get_build_dir())) filename = "/dlls/wineps.drv/generic.ppd";
649 res = ERROR_FILE_NOT_FOUND;
650 ERR ("Error %i getting PPD file name for printer '%s'\n", res, name);
653 ppdFileName = HeapAlloc( PSDRV_Heap, 0, strlen(data_dir) + strlen(filename) + 1 );
654 strcpy( ppdFileName, data_dir );
655 strcat( ppdFileName, filename );
658 if (ppdType==REG_EXPAND_SZ) {
661 /* Expand environment variable references */
662 needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0);
663 tmp=HeapAlloc(PSDRV_Heap, 0, needed);
664 ExpandEnvironmentStringsA(ppdFileName,tmp,needed);
665 HeapFree(PSDRV_Heap, 0, ppdFileName);
670 pi->ppd = PSDRV_ParsePPD(ppdFileName);
672 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
677 /* Some gimp-print ppd files don't contain a DefaultResolution line
678 set it to 300 if it's not specified */
679 if(pi->ppd->DefaultResolution == 0)
680 pi->ppd->DefaultResolution = 300;
682 if(using_default_devmode) {
685 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
686 (LPWSTR)&papersize, sizeof(papersize)/sizeof(WCHAR))) {
688 memset(&dm, 0, sizeof(dm));
689 dm.dmPublic.dmFields = DM_PAPERSIZE;
690 dm.dmPublic.u1.s1.dmPaperSize = papersize;
691 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
694 SetPrinterDataExA(hPrinter, NULL, default_devmodeA, REG_BINARY,
695 (LPBYTE)pi->Devmode, sizeof(DefaultDevmode));
698 if(pi->ppd->DefaultPageSize) { /* We'll let the ppd override the devmode */
700 memset(&dm, 0, sizeof(dm));
701 dm.dmPublic.dmFields = DM_PAPERSIZE;
702 dm.dmPublic.u1.s1.dmPaperSize = pi->ppd->DefaultPageSize->WinPage;
703 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
707 * This is a hack. The default paper size should be read in as part of
708 * the Devmode structure, but Wine doesn't currently provide a convenient
709 * way to configure printers.
711 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "Paper Size", NULL,
712 (LPBYTE)&dwPaperSize, sizeof(DWORD), &needed);
713 if (res == ERROR_SUCCESS)
714 pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize;
715 else if (res == ERROR_FILE_NOT_FOUND)
716 TRACE ("No 'Paper Size' for printer '%s'\n", name);
718 ERR ("GetPrinterDataA returned %i\n", res);
722 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
723 WinDuplex == 0 is a special case which means that the ppd has a
724 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
725 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
726 PSDRV_WriteHeader understands this and copes. */
727 pi->Devmode->dmPublic.dmFields &= ~DM_DUPLEX;
728 if(pi->ppd->DefaultDuplex) {
729 pi->Devmode->dmPublic.dmDuplex = pi->ppd->DefaultDuplex->WinDuplex;
730 if(pi->Devmode->dmPublic.dmDuplex != 0)
731 pi->Devmode->dmPublic.dmFields |= DM_DUPLEX;
733 pi->Devmode->dmPublic.dmDuplex = DMDUP_SIMPLEX;
736 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL,
737 0, &needed, &pi->FontSubTableSize);
738 if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) {
739 TRACE ("No 'FontSubTable' for printer '%s'\n", name);
741 else if (res == ERROR_MORE_DATA) {
742 pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed);
743 if (pi->FontSubTable == NULL) {
744 ERR ("Failed to allocate %i bytes from heap\n", needed);
748 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable",
749 (LPBYTE) pi->FontSubTable, needed, &needed,
750 &pi->FontSubTableSize);
751 if (res != ERROR_SUCCESS) {
752 ERR ("EnumPrinterDataExA returned %i\n", res);
757 ERR("EnumPrinterDataExA returned %i\n", res);
761 if (ClosePrinter (hPrinter) == 0) {
762 ERR ("ClosePrinter failed with code %i\n", GetLastError ());
769 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
770 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
772 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
773 "ignoring\n", font->Name);
777 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
778 PSDRV_FreeAFMList(pi->Fonts);
784 if (ppd) unlink(ppd);
788 ClosePrinter(hPrinter);
790 HeapFree(PSDRV_Heap, 0, ppdFileName);
791 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
792 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
793 HeapFree(PSDRV_Heap, 0, pi->Devmode);
795 HeapFree(PSDRV_Heap, 0, pi);
796 if (ppd) unlink(ppd);