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 HINSTANCE PSDRV_hInstance = 0;
105 HANDLE PSDRV_Heap = 0;
107 static HFONT PSDRV_DefaultFont = 0;
108 static LOGFONTA DefaultLogFont = {
109 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
110 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
113 /*********************************************************************
116 * Initializes font metrics and registers driver. wineps dll entry point.
119 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
121 TRACE("(%p, 0x%08lx, %p)\n", hinst, reason, reserved);
125 case DLL_PROCESS_ATTACH:
126 PSDRV_hInstance = hinst;
127 DisableThreadLibraryCalls(hinst);
129 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
130 if (PSDRV_Heap == NULL)
133 if (PSDRV_GetFontMetrics() == FALSE) {
134 HeapDestroy(PSDRV_Heap);
138 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
139 if (PSDRV_DefaultFont == NULL) {
140 HeapDestroy(PSDRV_Heap);
143 #ifdef HAVE_CUPS_CUPS_H
144 /* dynamically load CUPS if not yet loaded */
146 cupshandle = wine_dlopen(SONAME_LIBCUPS, RTLD_NOW, NULL, 0);
147 if (!cupshandle) cupshandle = (void*)-1;
152 case DLL_PROCESS_DETACH:
154 DeleteObject( PSDRV_DefaultFont );
155 HeapDestroy( PSDRV_Heap );
156 #ifdef HAVE_CUPS_CUPS_H
157 if (cupshandle && (cupshandle != (void*)-1)) {
158 wine_dlclose(cupshandle, NULL, 0);
169 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
172 INT width = 0, height = 0;
174 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
175 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
176 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
181 FIXME("Can't find page\n");
182 physDev->ImageableArea.left = 0;
183 physDev->ImageableArea.right = 0;
184 physDev->ImageableArea.bottom = 0;
185 physDev->ImageableArea.top = 0;
186 physDev->PageSize.cx = 0;
187 physDev->PageSize.cy = 0;
188 } else if(page->ImageableArea) {
189 /* physDev sizes in device units; ppd sizes in 1/72" */
190 physDev->ImageableArea.left = page->ImageableArea->llx *
191 physDev->logPixelsX / 72;
192 physDev->ImageableArea.right = page->ImageableArea->urx *
193 physDev->logPixelsX / 72;
194 physDev->ImageableArea.bottom = page->ImageableArea->lly *
195 physDev->logPixelsY / 72;
196 physDev->ImageableArea.top = page->ImageableArea->ury *
197 physDev->logPixelsY / 72;
198 physDev->PageSize.cx = page->PaperDimension->x *
199 physDev->logPixelsX / 72;
200 physDev->PageSize.cy = page->PaperDimension->y *
201 physDev->logPixelsY / 72;
203 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
204 physDev->ImageableArea.right = physDev->PageSize.cx =
205 page->PaperDimension->x * physDev->logPixelsX / 72;
206 physDev->ImageableArea.top = physDev->PageSize.cy =
207 page->PaperDimension->y * physDev->logPixelsY / 72;
209 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
210 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
211 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
212 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
213 physDev->ImageableArea.right = physDev->PageSize.cx =
214 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
215 physDev->logPixelsX / 254;
216 physDev->ImageableArea.top = physDev->PageSize.cy =
217 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
218 physDev->logPixelsY / 254;
220 FIXME("Odd dmFields %lx\n", physDev->Devmode->dmPublic.dmFields);
221 physDev->ImageableArea.left = 0;
222 physDev->ImageableArea.right = 0;
223 physDev->ImageableArea.bottom = 0;
224 physDev->ImageableArea.top = 0;
225 physDev->PageSize.cx = 0;
226 physDev->PageSize.cy = 0;
229 TRACE("ImageableArea = %ld,%ld - %ld,%ld: PageSize = %ldx%ld\n",
230 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
231 physDev->ImageableArea.right, physDev->ImageableArea.top,
232 physDev->PageSize.cx, physDev->PageSize.cy);
234 /* these are in device units */
235 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
236 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
238 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
239 physDev->horzRes = width;
240 physDev->vertRes = height;
242 physDev->horzRes = height;
243 physDev->vertRes = width;
246 /* these are in mm */
247 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
248 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
250 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
251 "horzRes = %d, vertRes = %d\n",
252 physDev->horzSize, physDev->vertSize,
253 physDev->horzRes, physDev->vertRes);
257 /***********************************************************
260 * Creates an ascii copy of supplied devmode on heap
262 * Copied from dlls/winspool/info.c until full unicodification
264 static LPDEVMODEA DEVMODEdupWtoA(HANDLE heap, const DEVMODEW *dmW)
269 ptrdiff_t off_formname = (const char *)dmW->dmFormName - (const char *)dmW;
271 if(!dmW) return NULL;
272 Formname = (dmW->dmSize > off_formname);
273 size = dmW->dmSize - CCHDEVICENAME - (Formname ? CCHFORMNAME : 0);
274 dmA = HeapAlloc(heap, HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra);
275 WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1, dmA->dmDeviceName,
276 CCHDEVICENAME, NULL, NULL);
278 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
279 dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR));
281 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
282 off_formname - CCHDEVICENAME * sizeof(WCHAR));
283 WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1, dmA->dmFormName,
284 CCHFORMNAME, NULL, NULL);
285 memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
286 (off_formname + CCHFORMNAME * sizeof(WCHAR)));
289 memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize,
295 /**********************************************************************
298 BOOL PSDRV_CreateDC( HDC hdc, PSDRV_PDEVICE **pdev, LPCWSTR driver, LPCWSTR device,
299 LPCWSTR output, const DEVMODEW* initData )
301 PSDRV_PDEVICE *physDev;
303 char deviceA[CCHDEVICENAME];
305 /* If no device name was specified, retrieve the device name
306 * from the DEVMODE structure from the DC's physDev.
307 * (See CreateCompatibleDC) */
308 if ( !device && *pdev )
311 strcpy(deviceA, physDev->Devmode->dmPublic.dmDeviceName);
314 WideCharToMultiByte(CP_ACP, 0, device, -1, deviceA, sizeof(deviceA), NULL, NULL);
315 pi = PSDRV_FindPrinterInfo(deviceA);
317 TRACE("(%s %s %s %p)\n", debugstr_w(driver), debugstr_w(device),
318 debugstr_w(output), initData);
320 if(!pi) return FALSE;
323 MESSAGE("To use WINEPS you need to install some AFM files.\n");
327 physDev = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*physDev) );
328 if (!physDev) return FALSE;
334 physDev->Devmode = HeapAlloc( PSDRV_Heap, 0, 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 HeapFree( PSDRV_Heap, 0, physDev->job.output );
373 HeapFree( PSDRV_Heap, 0, physDev );
379 /**********************************************************************
382 HDC PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEW *lpInitData )
386 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, lpInitData);
387 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, physDev->pi);
388 HeapFree(PSDRV_Heap, 0, devmodeA);
389 PSDRV_UpdateDevCaps(physDev);
390 hrgn = CreateRectRgn(0, 0, physDev->horzRes, physDev->vertRes);
391 SelectVisRgn16(HDC_16(physDev->hdc), HRGN_16(hrgn));
397 /***********************************************************************
398 * GetDeviceCaps (WINEPS.@)
400 INT PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap )
407 return DT_RASPRINTER;
409 return MulDiv(physDev->horzSize, 100,
410 physDev->Devmode->dmPublic.dmScale);
412 return MulDiv(physDev->vertSize, 100,
413 physDev->Devmode->dmPublic.dmScale);
415 return physDev->horzRes;
417 return physDev->vertRes;
419 return physDev->pi->ppd->ColorDevice ? 8 : 1;
431 return (physDev->pi->ppd->ColorDevice ? 256 : -1);
433 return sizeof(PSDRV_PDEVICE);
435 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
436 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
438 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
439 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
441 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
442 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
444 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
448 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
449 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
450 /* Are aspect[XY] and logPixels[XY] correct? */
451 /* Need to handle different res in x and y => fix ppd */
454 return physDev->pi->ppd->DefaultResolution;
456 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
457 (double)physDev->pi->ppd->DefaultResolution );
459 return MulDiv(physDev->logPixelsX,
460 physDev->Devmode->dmPublic.dmScale, 100);
462 return MulDiv(physDev->logPixelsY,
463 physDev->Devmode->dmPublic.dmScale, 100);
471 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
472 physDev->PageSize.cy : physDev->PageSize.cx;
474 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
475 physDev->PageSize.cx : physDev->PageSize.cy;
476 case PHYSICALOFFSETX:
477 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
478 if(physDev->pi->ppd->LandscapeOrientation == -90)
479 return physDev->PageSize.cy - physDev->ImageableArea.top;
481 return physDev->ImageableArea.bottom;
483 return physDev->ImageableArea.left;
485 case PHYSICALOFFSETY:
486 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
487 if(physDev->pi->ppd->LandscapeOrientation == -90)
488 return physDev->PageSize.cx - physDev->ImageableArea.right;
490 return physDev->ImageableArea.left;
492 return physDev->PageSize.cy - physDev->ImageableArea.top;
502 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
508 /**********************************************************************
509 * PSDRV_FindPrinterInfo
511 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
513 static PRINTERINFO *PSDRV_PrinterList;
514 DWORD type = REG_BINARY, needed, res, dwPaperSize;
515 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
519 const char *ppd = NULL;
521 char* ppdFileName = NULL;
523 BOOL using_default_devmode = FALSE;
525 TRACE("'%s'\n", name);
528 * If this loop completes, last will point to the 'next' element of the
529 * final PRINTERINFO in the list
531 for( ; pi; last = &pi->next, pi = pi->next)
532 if(!strcmp(pi->FriendlyName, name))
535 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
539 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
540 strcpy( pi->FriendlyName, name );
542 /* Use Get|SetPrinterDataExA instead? */
544 res = DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
547 if(res == ERROR_INVALID_PRINTER_NAME || needed != sizeof(DefaultDevmode)) {
548 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
549 if (pi->Devmode == NULL)
551 memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) );
552 strcpy(pi->Devmode->dmPublic.dmDeviceName,name);
553 using_default_devmode = TRUE;
555 /* need to do something here AddPrinter?? */
558 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
559 DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
560 (LPBYTE)pi->Devmode, needed, &needed);
563 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
564 ERR ("OpenPrinterA failed with code %li\n", GetLastError ());
568 #ifdef HAVE_CUPS_CUPS_H
569 if (cupshandle != (void*)-1) {
570 typeof(cupsGetPPD) * pcupsGetPPD = NULL;
572 pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0);
574 ppd = pcupsGetPPD(name);
577 needed=strlen(ppd)+1;
578 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
579 memcpy(ppdFileName, ppd, needed);
582 /* we should unlink() that file later */
584 res = ERROR_FILE_NOT_FOUND;
585 WARN("Did not find ppd for %s\n",name);
591 res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed);
592 if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
593 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
594 res = GetPrinterDataA(hPrinter, "PPD File", &ppdType, ppdFileName, needed, &needed);
597 /* Look for a ppd file for this printer in the config file.
598 * First look under that printer's name, and then under 'generic'
600 /* @@ Wine registry key: HKCU\Software\Wine\Printing\PPD Files */
601 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Printing\\PPD Files", &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, (LPBYTE)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);
756 HeapFree(PSDRV_Heap, 0, ppdFileName);
757 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
758 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
759 HeapFree(PSDRV_Heap, 0, pi->Devmode);
761 HeapFree(PSDRV_Heap, 0, pi);
762 if (ppd) unlink(ppd);