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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
42 #ifdef HAVE_CUPS_CUPS_H
43 #include <cups/cups.h>
45 #ifndef SONAME_LIBCUPS
46 #define SONAME_LIBCUPS "libcups.so"
49 static void *cupshandle = NULL;
52 static PSDRV_DEVMODEA DefaultDevmode =
55 /* dmDeviceName */ "Wine PostScript Driver",
56 /* dmSpecVersion */ 0x30a,
57 /* dmDriverVersion */ 0x001,
58 /* dmSize */ sizeof(DEVMODEA),
59 /* dmDriverExtra */ sizeof(PSDRV_DEVMODEA)-sizeof(DEVMODEA),
60 /* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE |
61 DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
62 DM_YRESOLUTION | DM_TTOPTION,
65 /* dmOrientation */ DMORIENT_PORTRAIT,
66 /* dmPaperSize */ DMPAPER_LETTER,
67 /* dmPaperLength */ 2794,
68 /* dmPaperWidth */ 2159
71 /* dmScale */ 100, /* ?? */
73 /* dmDefaultSource */ DMBIN_AUTO,
74 /* dmPrintQuality */ 0,
75 /* dmColor */ DMCOLOR_COLOR,
76 /* dmDuplex */ DMDUP_SIMPLEX,
77 /* dmYResolution */ 0,
78 /* dmTTOption */ DMTT_SUBDEV,
81 /* dmUnusedPadding */ 0,
85 /* dmDisplayFlags */ 0,
86 /* dmDisplayFrequency */ 0,
93 /* dmPanningWidth */ 0,
94 /* dmPanningHeight */ 0
100 /* numInstalledOptions */ 0
104 HANDLE PSDRV_Heap = 0;
106 static HFONT PSDRV_DefaultFont = 0;
107 static LOGFONTA DefaultLogFont = {
108 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
109 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
112 /*********************************************************************
115 * Initializes font metrics and registers driver. wineps dll entry point.
118 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
120 TRACE("(%p, 0x%08lx, %p)\n", hinst, reason, reserved);
124 case DLL_PROCESS_ATTACH:
125 DisableThreadLibraryCalls(hinst);
127 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
128 if (PSDRV_Heap == NULL)
131 if (PSDRV_GetFontMetrics() == FALSE) {
132 HeapDestroy(PSDRV_Heap);
136 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
137 if (PSDRV_DefaultFont == NULL) {
138 HeapDestroy(PSDRV_Heap);
141 #ifdef HAVE_CUPS_CUPS_H
142 /* dynamically load CUPS if not yet loaded */
144 cupshandle = wine_dlopen(SONAME_LIBCUPS, RTLD_NOW, NULL, 0);
145 if (!cupshandle) cupshandle = (void*)-1;
150 case DLL_PROCESS_DETACH:
152 DeleteObject( PSDRV_DefaultFont );
153 HeapDestroy( PSDRV_Heap );
154 #ifdef HAVE_CUPS_CUPS_H
155 if (cupshandle && (cupshandle != (void*)-1)) {
156 wine_dlclose(cupshandle, NULL, 0);
167 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
170 INT width = 0, height = 0;
172 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
173 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
174 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
179 FIXME("Can't find page\n");
180 physDev->ImageableArea.left = 0;
181 physDev->ImageableArea.right = 0;
182 physDev->ImageableArea.bottom = 0;
183 physDev->ImageableArea.top = 0;
184 physDev->PageSize.cx = 0;
185 physDev->PageSize.cy = 0;
186 } else if(page->ImageableArea) {
187 /* physDev sizes in device units; ppd sizes in 1/72" */
188 physDev->ImageableArea.left = page->ImageableArea->llx *
189 physDev->logPixelsX / 72;
190 physDev->ImageableArea.right = page->ImageableArea->urx *
191 physDev->logPixelsX / 72;
192 physDev->ImageableArea.bottom = page->ImageableArea->lly *
193 physDev->logPixelsY / 72;
194 physDev->ImageableArea.top = page->ImageableArea->ury *
195 physDev->logPixelsY / 72;
196 physDev->PageSize.cx = page->PaperDimension->x *
197 physDev->logPixelsX / 72;
198 physDev->PageSize.cy = page->PaperDimension->y *
199 physDev->logPixelsY / 72;
201 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
202 physDev->ImageableArea.right = physDev->PageSize.cx =
203 page->PaperDimension->x * physDev->logPixelsX / 72;
204 physDev->ImageableArea.top = physDev->PageSize.cy =
205 page->PaperDimension->y * physDev->logPixelsY / 72;
207 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
208 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
209 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
210 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
211 physDev->ImageableArea.right = physDev->PageSize.cx =
212 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
213 physDev->logPixelsX / 254;
214 physDev->ImageableArea.top = physDev->PageSize.cy =
215 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
216 physDev->logPixelsY / 254;
218 FIXME("Odd dmFields %lx\n", physDev->Devmode->dmPublic.dmFields);
219 physDev->ImageableArea.left = 0;
220 physDev->ImageableArea.right = 0;
221 physDev->ImageableArea.bottom = 0;
222 physDev->ImageableArea.top = 0;
223 physDev->PageSize.cx = 0;
224 physDev->PageSize.cy = 0;
227 TRACE("ImageableArea = %ld,%ld - %ld,%ld: PageSize = %ldx%ld\n",
228 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
229 physDev->ImageableArea.right, physDev->ImageableArea.top,
230 physDev->PageSize.cx, physDev->PageSize.cy);
232 /* these are in device units */
233 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
234 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
236 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
237 physDev->horzRes = width;
238 physDev->vertRes = height;
240 physDev->horzRes = height;
241 physDev->vertRes = width;
244 /* these are in mm */
245 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
246 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
248 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
249 "horzRes = %d, vertRes = %d\n",
250 physDev->horzSize, physDev->vertSize,
251 physDev->horzRes, physDev->vertRes);
255 /***********************************************************
258 * Creates an ascii copy of supplied devmode on heap
260 * Copied from dlls/winspool/info.c until full unicodification
262 static LPDEVMODEA DEVMODEdupWtoA(HANDLE heap, const DEVMODEW *dmW)
267 ptrdiff_t off_formname = (const char *)dmW->dmFormName - (const char *)dmW;
269 if(!dmW) return NULL;
270 Formname = (dmW->dmSize > off_formname);
271 size = dmW->dmSize - CCHDEVICENAME - (Formname ? CCHFORMNAME : 0);
272 dmA = HeapAlloc(heap, HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra);
273 WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1, dmA->dmDeviceName,
274 CCHDEVICENAME, NULL, NULL);
276 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
277 dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR));
279 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
280 off_formname - CCHDEVICENAME * sizeof(WCHAR));
281 WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1, dmA->dmFormName,
282 CCHFORMNAME, NULL, NULL);
283 memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
284 (off_formname + CCHFORMNAME * sizeof(WCHAR)));
287 memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize,
293 /**********************************************************************
296 BOOL PSDRV_CreateDC( HDC hdc, PSDRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device,
297 LPCWSTR output, const DEVMODEW* initData )
299 PSDRV_PDEVICE *physDev;
301 char deviceA[CCHDEVICENAME];
303 /* If no device name was specified, retrieve the device name
304 * from the DEVMODE structure from the DC's physDev.
305 * (See CreateCompatibleDC) */
306 if ( !device && *pdev )
309 strcpy(deviceA, physDev->Devmode->dmPublic.dmDeviceName);
312 WideCharToMultiByte(CP_ACP, 0, device, -1, deviceA, sizeof(deviceA), NULL, NULL);
313 pi = PSDRV_FindPrinterInfo(deviceA);
315 TRACE("(%s %s %s %p)\n", debugstr_w(driver), debugstr_w(device),
316 debugstr_w(output), initData);
318 if(!pi) return FALSE;
321 MESSAGE("To use WINEPS you need to install some AFM files.\n");
325 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
327 if (!physDev) return FALSE;
333 physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0,
334 sizeof(PSDRV_DEVMODEA) );
335 if(!physDev->Devmode) {
336 HeapFree( PSDRV_Heap, 0, physDev );
340 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) );
342 physDev->logPixelsX = physDev->pi->ppd->DefaultResolution;
343 physDev->logPixelsY = physDev->pi->ppd->DefaultResolution;
346 physDev->job.output = HEAP_strdupWtoA( PSDRV_Heap, 0, output );
348 physDev->job.output = NULL;
349 physDev->job.hJob = 0;
352 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, initData);
353 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, pi);
354 HeapFree(PSDRV_Heap, 0, devmodeA);
357 PSDRV_UpdateDevCaps(physDev);
358 SelectObject( hdc, PSDRV_DefaultFont );
364 /**********************************************************************
367 BOOL PSDRV_DeleteDC( PSDRV_PDEVICE *physDev )
371 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
372 if(physDev->job.output)
373 HeapFree( PSDRV_Heap, 0, physDev->job.output );
374 HeapFree( PSDRV_Heap, 0, physDev );
380 /**********************************************************************
383 HDC PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEW *lpInitData )
387 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, lpInitData);
388 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, physDev->pi);
389 HeapFree(PSDRV_Heap, 0, devmodeA);
390 PSDRV_UpdateDevCaps(physDev);
391 hrgn = CreateRectRgn(0, 0, physDev->horzRes, physDev->vertRes);
392 SelectVisRgn16(HDC_16(physDev->hdc), HRGN_16(hrgn));
398 /***********************************************************************
399 * GetDeviceCaps (WINEPS.@)
401 INT PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap )
408 return DT_RASPRINTER;
410 return MulDiv(physDev->horzSize, 100,
411 physDev->Devmode->dmPublic.dmScale);
413 return MulDiv(physDev->vertSize, 100,
414 physDev->Devmode->dmPublic.dmScale);
416 return physDev->horzRes;
418 return physDev->vertRes;
420 return physDev->pi->ppd->ColorDevice ? 8 : 1;
432 return (physDev->pi->ppd->ColorDevice ? 256 : -1);
434 return sizeof(PSDRV_PDEVICE);
436 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
437 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
439 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
440 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
442 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
443 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
445 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
449 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
450 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
451 /* Are aspect[XY] and logPixels[XY] correct? */
452 /* Need to handle different res in x and y => fix ppd */
455 return physDev->pi->ppd->DefaultResolution;
457 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
458 (double)physDev->pi->ppd->DefaultResolution );
460 return MulDiv(physDev->logPixelsX,
461 physDev->Devmode->dmPublic.dmScale, 100);
463 return MulDiv(physDev->logPixelsY,
464 physDev->Devmode->dmPublic.dmScale, 100);
472 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
473 physDev->PageSize.cy : physDev->PageSize.cx;
475 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
476 physDev->PageSize.cx : physDev->PageSize.cy;
477 case PHYSICALOFFSETX:
478 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
479 if(physDev->pi->ppd->LandscapeOrientation == -90)
480 return physDev->PageSize.cy - physDev->ImageableArea.top;
482 return physDev->ImageableArea.bottom;
484 return physDev->ImageableArea.left;
486 case PHYSICALOFFSETY:
487 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
488 if(physDev->pi->ppd->LandscapeOrientation == -90)
489 return physDev->PageSize.cx - physDev->ImageableArea.right;
491 return physDev->ImageableArea.left;
493 return physDev->PageSize.cy - physDev->ImageableArea.top;
503 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
509 /**********************************************************************
510 * PSDRV_FindPrinterInfo
512 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
514 static PRINTERINFO *PSDRV_PrinterList;
515 DWORD type = REG_BINARY, needed, res, dwPaperSize;
516 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
520 const char *ppd = NULL;
522 char* ppdFileName = NULL;
524 BOOL using_default_devmode = FALSE;
526 TRACE("'%s'\n", name);
529 * If this loop completes, last will point to the 'next' element of the
530 * final PRINTERINFO in the list
532 for( ; pi; last = &pi->next, pi = pi->next)
533 if(!strcmp(pi->FriendlyName, name))
536 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
540 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
541 strcpy( pi->FriendlyName, name );
543 /* Use Get|SetPrinterDataExA instead? */
545 res = DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
548 if(res == ERROR_INVALID_PRINTER_NAME || needed != sizeof(DefaultDevmode)) {
549 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
550 if (pi->Devmode == NULL)
552 memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) );
553 strcpy(pi->Devmode->dmPublic.dmDeviceName,name);
554 using_default_devmode = TRUE;
556 /* need to do something here AddPrinter?? */
559 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
560 DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
561 (LPBYTE)pi->Devmode, needed, &needed);
564 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
565 ERR ("OpenPrinterA failed with code %li\n", GetLastError ());
569 #ifdef HAVE_CUPS_CUPS_H
570 if (cupshandle != (void*)-1) {
571 typeof(cupsGetPPD) * pcupsGetPPD = NULL;
573 pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0);
575 ppd = pcupsGetPPD(name);
578 needed=strlen(ppd)+1;
579 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
580 memcpy(ppdFileName, ppd, needed);
583 /* we should unlink() that file later */
585 res = ERROR_FILE_NOT_FOUND;
586 WARN("Did not find ppd for %s\n",name);
592 res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed);
593 if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
594 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
595 res = GetPrinterDataA(hPrinter, "PPD File", &ppdType, ppdFileName, needed, &needed);
598 /* Look for a ppd file for this printer in the config file.
599 * First look under that printer's name, and then under 'generic'
601 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey))
603 const char* value_name;
605 if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
607 } else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
608 value_name="generic";
613 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
614 RegQueryValueExA(hkey, value_name, 0, &ppdType, ppdFileName, &needed);
620 res = ERROR_FILE_NOT_FOUND;
621 ERR ("Error %li getting PPD file name for printer '%s'\n", res, name);
625 if (ppdType==REG_EXPAND_SZ) {
628 /* Expand environment variable references */
629 needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0);
630 tmp=HeapAlloc(PSDRV_Heap, 0, needed);
631 ExpandEnvironmentStringsA(ppdFileName,tmp,needed);
632 HeapFree(PSDRV_Heap, 0, ppdFileName);
637 pi->ppd = PSDRV_ParsePPD(ppdFileName);
639 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
644 /* Some gimp-print ppd files don't contain a DefaultResolution line
645 set it to 300 if it's not specified */
646 if(pi->ppd->DefaultResolution == 0)
647 pi->ppd->DefaultResolution = 300;
649 if(using_default_devmode) {
652 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
653 (LPWSTR)&papersize, sizeof(papersize)/sizeof(WCHAR))) {
655 memset(&dm, 0, sizeof(dm));
656 dm.dmPublic.dmFields = DM_PAPERSIZE;
657 dm.dmPublic.u1.s1.dmPaperSize = papersize;
658 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
660 DrvSetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE,
661 REG_BINARY, (LPBYTE)pi->Devmode, sizeof(DefaultDevmode) );
664 if(pi->ppd->DefaultPageSize) { /* We'll let the ppd override the devmode */
666 memset(&dm, 0, sizeof(dm));
667 dm.dmPublic.dmFields = DM_PAPERSIZE;
668 dm.dmPublic.u1.s1.dmPaperSize = pi->ppd->DefaultPageSize->WinPage;
669 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
673 * This is a hack. The default paper size should be read in as part of
674 * the Devmode structure, but Wine doesn't currently provide a convenient
675 * way to configure printers.
677 res = GetPrinterDataA (hPrinter, "Paper Size", NULL, (LPBYTE) &dwPaperSize,
678 sizeof (DWORD), &needed);
679 if (res == ERROR_SUCCESS)
680 pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize;
681 else if (res == ERROR_FILE_NOT_FOUND)
682 TRACE ("No 'Paper Size' for printer '%s'\n", name);
684 ERR ("GetPrinterDataA returned %li\n", res);
688 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
689 WinDuplex == 0 is a special case which means that the ppd has a
690 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
691 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
692 PSDRV_WriteHeader understands this and copes. */
693 pi->Devmode->dmPublic.dmFields &= ~DM_DUPLEX;
694 if(pi->ppd->DefaultDuplex) {
695 pi->Devmode->dmPublic.dmDuplex = pi->ppd->DefaultDuplex->WinDuplex;
696 if(pi->Devmode->dmPublic.dmDuplex != 0)
697 pi->Devmode->dmPublic.dmFields |= DM_DUPLEX;
699 pi->Devmode->dmPublic.dmDuplex = DMDUP_SIMPLEX;
702 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL,
703 0, &needed, &pi->FontSubTableSize);
704 if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) {
705 TRACE ("No 'FontSubTable' for printer '%s'\n", name);
707 else if (res == ERROR_MORE_DATA) {
708 pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed);
709 if (pi->FontSubTable == NULL) {
710 ERR ("Failed to allocate %li bytes from heap\n", needed);
714 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable",
715 (LPBYTE) pi->FontSubTable, needed, &needed,
716 &pi->FontSubTableSize);
717 if (res != ERROR_SUCCESS) {
718 ERR ("EnumPrinterDataExA returned %li\n", res);
723 ERR("EnumPrinterDataExA returned %li\n", res);
727 if (ClosePrinter (hPrinter) == 0) {
728 ERR ("ClosePrinter failed with code %li\n", GetLastError ());
735 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
736 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
738 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
739 "ignoring\n", font->Name);
743 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
744 PSDRV_FreeAFMList(pi->Fonts);
750 if (ppd) unlink(ppd);
754 ClosePrinter(hPrinter);
757 HeapFree(PSDRV_Heap, 0, ppdFileName);
758 if (pi->FontSubTable)
759 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
760 if (pi->FriendlyName)
761 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
763 HeapFree(PSDRV_Heap, 0, pi->Devmode);
765 HeapFree(PSDRV_Heap, 0, pi);
766 if (ppd) unlink(ppd);