Moved mode setting out of .spec file into Makefile.
[wine/gsoc_dplay.git] / dlls / wineps / init.c
blob9888e5b582fb0948f974aa807d0bcd45a9c06e11
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <string.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
29 #include "gdi.h"
30 #include "psdrv.h"
31 #include "wine/debug.h"
32 #include "winreg.h"
33 #include "winspool.h"
34 #include "winerror.h"
36 #ifdef HAVE_CUPS
37 # include <cups/cups.h>
38 #endif
40 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
42 static PSDRV_DEVMODEA DefaultDevmode =
44 { /* dmPublic */
45 /* dmDeviceName */ "Wine PostScript Driver",
46 /* dmSpecVersion */ 0x30a,
47 /* dmDriverVersion */ 0x001,
48 /* dmSize */ sizeof(DEVMODEA),
49 /* dmDriverExtra */ 0,
50 /* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE |
51 DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
52 DM_DUPLEX | DM_YRESOLUTION | DM_TTOPTION,
53 { /* u1 */
54 { /* s1 */
55 /* dmOrientation */ DMORIENT_PORTRAIT,
56 /* dmPaperSize */ DMPAPER_LETTER,
57 /* dmPaperLength */ 2794,
58 /* dmPaperWidth */ 2159
61 /* dmScale */ 100, /* ?? */
62 /* dmCopies */ 1,
63 /* dmDefaultSource */ DMBIN_AUTO,
64 /* dmPrintQuality */ 0,
65 /* dmColor */ DMCOLOR_COLOR,
66 /* dmDuplex */ 0,
67 /* dmYResolution */ 0,
68 /* dmTTOption */ DMTT_SUBDEV,
69 /* dmCollate */ 0,
70 /* dmFormName */ "",
71 /* dmUnusedPadding */ 0,
72 /* dmBitsPerPel */ 0,
73 /* dmPelsWidth */ 0,
74 /* dmPelsHeight */ 0,
75 /* dmDisplayFlags */ 0,
76 /* dmDisplayFrequency */ 0,
77 /* dmICMMethod */ 0,
78 /* dmICMIntent */ 0,
79 /* dmMediaType */ 0,
80 /* dmDitherType */ 0,
81 /* dmReserved1 */ 0,
82 /* dmReserved2 */ 0,
83 /* dmPanningWidth */ 0,
84 /* dmPanningHeight */ 0
86 { /* dmDocPrivate */
87 /* dummy */ 0
89 { /* dmDrvPrivate */
90 /* numInstalledOptions */ 0
94 HANDLE PSDRV_Heap = 0;
96 static HANDLE PSDRV_DefaultFont = 0;
97 static LOGFONTA DefaultLogFont = {
98 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
99 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
102 /*********************************************************************
103 * PSDRV_Init
105 * Initializes font metrics and registers driver. Called from GDI_Init()
108 BOOL WINAPI PSDRV_Init( HINSTANCE hinst, DWORD reason, LPVOID reserved )
110 TRACE("(0x%4x, 0x%08lx, %p)\n", hinst, reason, reserved);
112 switch(reason) {
114 case DLL_PROCESS_ATTACH:
116 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
117 if (PSDRV_Heap == (HANDLE)NULL)
118 return FALSE;
120 if (PSDRV_GetFontMetrics() == FALSE) {
121 HeapDestroy(PSDRV_Heap);
122 return FALSE;
125 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
126 if (PSDRV_DefaultFont == (HANDLE)NULL) {
127 HeapDestroy(PSDRV_Heap);
128 return FALSE;
130 break;
132 case DLL_PROCESS_DETACH:
134 DeleteObject( PSDRV_DefaultFont );
135 HeapDestroy( PSDRV_Heap );
136 break;
139 return TRUE;
143 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
145 PAGESIZE *page;
146 INT width = 0, height = 0;
148 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
149 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
150 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
151 break;
154 if(!page) {
155 FIXME("Can't find page\n");
156 physDev->ImageableArea.left = 0;
157 physDev->ImageableArea.right = 0;
158 physDev->ImageableArea.bottom = 0;
159 physDev->ImageableArea.top = 0;
160 physDev->PageSize.cx = 0;
161 physDev->PageSize.cy = 0;
162 } else if(page->ImageableArea) {
163 /* physDev sizes in device units; ppd sizes in 1/72" */
164 physDev->ImageableArea.left = page->ImageableArea->llx *
165 physDev->logPixelsX / 72;
166 physDev->ImageableArea.right = page->ImageableArea->urx *
167 physDev->logPixelsX / 72;
168 physDev->ImageableArea.bottom = page->ImageableArea->lly *
169 physDev->logPixelsY / 72;
170 physDev->ImageableArea.top = page->ImageableArea->ury *
171 physDev->logPixelsY / 72;
172 physDev->PageSize.cx = page->PaperDimension->x *
173 physDev->logPixelsX / 72;
174 physDev->PageSize.cy = page->PaperDimension->y *
175 physDev->logPixelsY / 72;
176 } else {
177 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
178 physDev->ImageableArea.right = physDev->PageSize.cx =
179 page->PaperDimension->x * physDev->logPixelsX / 72;
180 physDev->ImageableArea.top = physDev->PageSize.cy =
181 page->PaperDimension->y * physDev->logPixelsY / 72;
183 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
184 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
185 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
186 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
187 physDev->ImageableArea.right = physDev->PageSize.cx =
188 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
189 physDev->logPixelsX / 254;
190 physDev->ImageableArea.top = physDev->PageSize.cy =
191 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
192 physDev->logPixelsY / 254;
193 } else {
194 FIXME("Odd dmFields %lx\n", physDev->Devmode->dmPublic.dmFields);
195 physDev->ImageableArea.left = 0;
196 physDev->ImageableArea.right = 0;
197 physDev->ImageableArea.bottom = 0;
198 physDev->ImageableArea.top = 0;
199 physDev->PageSize.cx = 0;
200 physDev->PageSize.cy = 0;
203 TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %ldx%ld\n",
204 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
205 physDev->ImageableArea.right, physDev->ImageableArea.top,
206 physDev->PageSize.cx, physDev->PageSize.cy);
208 /* these are in device units */
209 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
210 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
212 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
213 physDev->horzRes = width;
214 physDev->vertRes = height;
215 } else {
216 physDev->horzRes = height;
217 physDev->vertRes = width;
220 /* these are in mm */
221 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
222 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
224 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
225 "horzRes = %d, vertRes = %d\n",
226 physDev->horzSize, physDev->vertSize,
227 physDev->horzRes, physDev->vertRes);
231 /**********************************************************************
232 * PSDRV_CreateDC
234 BOOL PSDRV_CreateDC( DC *dc, PSDRV_PDEVICE **pdev, LPCSTR driver, LPCSTR device,
235 LPCSTR output, const DEVMODEA* initData )
237 PSDRV_PDEVICE *physDev;
238 PRINTERINFO *pi;
240 /* If no device name was specified, retrieve the device name
241 * from the DEVMODE structure from the DC's physDev.
242 * (See CreateCompatibleDC) */
243 if ( !device && *pdev )
245 physDev = *pdev;
246 device = physDev->Devmode->dmPublic.dmDeviceName;
248 pi = PSDRV_FindPrinterInfo(device);
250 TRACE("(%s %s %s %p)\n", driver, device, output, initData);
252 if(!pi) return FALSE;
254 if(!pi->Fonts) {
255 MESSAGE("To use WINEPS you need to install some AFM files.\n");
256 return FALSE;
259 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
260 sizeof(*physDev) );
261 if (!physDev) return FALSE;
262 *pdev = physDev;
263 physDev->hdc = dc->hSelf;
264 physDev->dc = dc;
266 physDev->pi = pi;
268 physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0,
269 sizeof(PSDRV_DEVMODEA) );
270 if(!physDev->Devmode) {
271 HeapFree( PSDRV_Heap, 0, physDev );
272 return FALSE;
275 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) );
277 physDev->logPixelsX = physDev->pi->ppd->DefaultResolution;
278 physDev->logPixelsY = physDev->pi->ppd->DefaultResolution;
280 if (!output) output = "LPT1:"; /* HACK */
281 physDev->job.output = HeapAlloc( PSDRV_Heap, 0, strlen(output)+1 );
282 strcpy( physDev->job.output, output );
283 physDev->job.hJob = 0;
285 if(initData) {
286 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)initData, pi);
289 PSDRV_UpdateDevCaps(physDev);
290 dc->hFont = PSDRV_DefaultFont;
291 return TRUE;
296 /**********************************************************************
297 * PSDRV_DeleteDC
299 BOOL PSDRV_DeleteDC( PSDRV_PDEVICE *physDev )
301 TRACE("\n");
303 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
304 HeapFree( PSDRV_Heap, 0, physDev->job.output );
305 HeapFree( PSDRV_Heap, 0, physDev );
307 return TRUE;
311 /**********************************************************************
312 * ResetDC (WINEPS.@)
314 HDC PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEA *lpInitData )
316 if(lpInitData) {
317 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)lpInitData, physDev->pi);
318 PSDRV_UpdateDevCaps(physDev);
320 return physDev->hdc;
323 /***********************************************************************
324 * GetDeviceCaps (WINEPS.@)
326 INT PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap )
328 switch(cap)
330 case DRIVERVERSION:
331 return 0;
332 case TECHNOLOGY:
333 return DT_RASPRINTER;
334 case HORZSIZE:
335 return MulDiv(physDev->horzSize, 100,
336 physDev->Devmode->dmPublic.dmScale);
337 case VERTSIZE:
338 return MulDiv(physDev->vertSize, 100,
339 physDev->Devmode->dmPublic.dmScale);
340 case HORZRES:
341 return physDev->horzRes;
342 case VERTRES:
343 return physDev->vertRes;
344 case BITSPIXEL:
345 return (physDev->pi->ppd->ColorDevice ? 8 : 1);
346 case PLANES:
347 return 1;
348 case NUMBRUSHES:
349 return -1;
350 case NUMPENS:
351 return 10;
352 case NUMMARKERS:
353 return 0;
354 case NUMFONTS:
355 return 39;
356 case NUMCOLORS:
357 return (physDev->pi->ppd->ColorDevice ? 256 : -1);
358 case PDEVICESIZE:
359 return sizeof(PSDRV_PDEVICE);
360 case CURVECAPS:
361 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
362 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
363 case LINECAPS:
364 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
365 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
366 case POLYGONALCAPS:
367 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
368 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
369 case TEXTCAPS:
370 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
371 case CLIPCAPS:
372 return CP_RECTANGLE;
373 case RASTERCAPS:
374 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
375 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
376 /* Are aspect[XY] and logPixels[XY] correct? */
377 /* Need to handle different res in x and y => fix ppd */
378 case ASPECTX:
379 case ASPECTY:
380 return physDev->pi->ppd->DefaultResolution;
381 case ASPECTXY:
382 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
383 (double)physDev->pi->ppd->DefaultResolution );
384 case LOGPIXELSX:
385 return MulDiv(physDev->logPixelsX,
386 physDev->Devmode->dmPublic.dmScale, 100);
387 case LOGPIXELSY:
388 return MulDiv(physDev->logPixelsY,
389 physDev->Devmode->dmPublic.dmScale, 100);
390 case SIZEPALETTE:
391 return 0;
392 case NUMRESERVED:
393 return 0;
394 case COLORRES:
395 return 0;
396 case PHYSICALWIDTH:
397 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
398 physDev->PageSize.cy : physDev->PageSize.cx;
399 case PHYSICALHEIGHT:
400 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
401 physDev->PageSize.cx : physDev->PageSize.cy;
402 case PHYSICALOFFSETX:
403 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
404 if(physDev->pi->ppd->LandscapeOrientation == -90)
405 return physDev->PageSize.cy - physDev->ImageableArea.top;
406 else
407 return physDev->ImageableArea.bottom;
409 return physDev->ImageableArea.left;
411 case PHYSICALOFFSETY:
412 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
413 if(physDev->pi->ppd->LandscapeOrientation == -90)
414 return physDev->PageSize.cx - physDev->ImageableArea.right;
415 else
416 return physDev->ImageableArea.left;
418 return physDev->PageSize.cy - physDev->ImageableArea.top;
420 case SCALINGFACTORX:
421 case SCALINGFACTORY:
422 case VREFRESH:
423 case DESKTOPVERTRES:
424 case DESKTOPHORZRES:
425 case BTLALIGNMENT:
426 return 0;
427 default:
428 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
429 return 0;
434 /**********************************************************************
435 * PSDRV_FindPrinterInfo
437 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
439 static PRINTERINFO *PSDRV_PrinterList;
440 DWORD type = REG_BINARY, needed, res, dwPaperSize;
441 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
442 FONTNAME *font;
443 const AFM *afm;
444 HANDLE hPrinter;
445 const char *ppd = NULL;
446 DWORD ppdType;
447 char* ppdFileName = NULL;
448 HKEY hkey;
449 BOOL using_default_devmode = FALSE;
451 TRACE("'%s'\n", name);
454 * If this loop completes, last will point to the 'next' element of the
455 * final PRINTERINFO in the list
457 for( ; pi; last = &pi->next, pi = pi->next)
458 if(!strcmp(pi->FriendlyName, name))
459 return pi;
461 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
462 if (pi == NULL)
463 return NULL;
465 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
466 strcpy( pi->FriendlyName, name );
468 /* Use Get|SetPrinterDataExA instead? */
470 res = DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
471 NULL, 0, &needed );
473 if(res == ERROR_INVALID_PRINTER_NAME || needed != sizeof(DefaultDevmode)) {
474 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
475 if (pi->Devmode == NULL)
476 goto cleanup;
477 memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) );
478 strcpy(pi->Devmode->dmPublic.dmDeviceName,name);
479 using_default_devmode = TRUE;
481 /* need to do something here AddPrinter?? */
483 else {
484 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
485 DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
486 (LPBYTE)pi->Devmode, needed, &needed);
489 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
490 ERR ("OpenPrinterA failed with code %li\n", GetLastError ());
491 goto cleanup;
494 #ifdef HAVE_CUPS
496 ppd = cupsGetPPD(name);
498 if (ppd) {
499 needed=strlen(ppd)+1;
500 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
501 memcpy(ppdFileName, ppd, needed);
502 ppdType=REG_SZ;
503 res = ERROR_SUCCESS;
504 /* we should unlink() that file later */
505 } else {
506 res = ERROR_FILE_NOT_FOUND;
507 WARN("Did not find ppd for %s\n",name);
510 #endif
512 if (!ppdFileName) {
513 res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed);
514 if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
515 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
516 res = GetPrinterDataA(hPrinter, "PPD File", &ppdType, ppdFileName, needed, &needed);
519 /* Look for a ppd file for this printer in the config file.
520 * First look under that printer's name, and then under 'generic'
522 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey))
524 const char* value_name;
526 if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
527 value_name=name;
528 } else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
529 value_name="generic";
530 } else {
531 value_name=NULL;
533 if (value_name) {
534 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
535 RegQueryValueExA(hkey, value_name, 0, &ppdType, ppdFileName, &needed);
537 RegCloseKey(hkey);
540 if (!ppdFileName) {
541 res = ERROR_FILE_NOT_FOUND;
542 ERR ("Error %li getting PPD file name for printer '%s'\n", res, name);
543 goto closeprinter;
544 } else {
545 res = ERROR_SUCCESS;
546 if (ppdType==REG_EXPAND_SZ) {
547 char* tmp;
549 /* Expand environment variable references */
550 needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0);
551 tmp=HeapAlloc(PSDRV_Heap, 0, needed);
552 ExpandEnvironmentStringsA(ppdFileName,tmp,needed);
553 HeapFree(PSDRV_Heap, 0, ppdFileName);
554 ppdFileName=tmp;
558 pi->ppd = PSDRV_ParsePPD(ppdFileName);
559 if(!pi->ppd) {
560 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
561 ppdFileName);
562 goto closeprinter;
566 if(using_default_devmode) {
567 DWORD papersize;
569 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
570 (LPWSTR)&papersize, sizeof(papersize))) {
571 PSDRV_DEVMODEA dm;
572 memset(&dm, 0, sizeof(dm));
573 dm.dmPublic.dmFields = DM_PAPERSIZE;
574 dm.dmPublic.u1.s1.dmPaperSize = papersize;
575 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
577 DrvSetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE,
578 REG_BINARY, (LPBYTE)pi->Devmode, sizeof(DefaultDevmode) );
583 * This is a hack. The default paper size should be read in as part of
584 * the Devmode structure, but Wine doesn't currently provide a convenient
585 * way to configure printers.
587 res = GetPrinterDataA (hPrinter, "Paper Size", NULL, (LPBYTE) &dwPaperSize,
588 sizeof (DWORD), &needed);
589 if (res == ERROR_SUCCESS)
590 pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize;
591 else if (res == ERROR_FILE_NOT_FOUND)
592 TRACE ("No 'Paper Size' for printer '%s'\n", name);
593 else {
594 ERR ("GetPrinterDataA returned %li\n", res);
595 goto closeprinter;
598 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL,
599 0, &needed, &pi->FontSubTableSize);
600 if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) {
601 TRACE ("No 'FontSubTable' for printer '%s'\n", name);
603 else if (res == ERROR_MORE_DATA) {
604 pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed);
605 if (pi->FontSubTable == NULL) {
606 ERR ("Failed to allocate %li bytes from heap\n", needed);
607 goto closeprinter;
610 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable",
611 (LPBYTE) pi->FontSubTable, needed, &needed,
612 &pi->FontSubTableSize);
613 if (res != ERROR_SUCCESS) {
614 ERR ("EnumPrinterDataExA returned %li\n", res);
615 goto closeprinter;
618 else {
619 ERR("EnumPrinterDataExA returned %li\n", res);
620 goto closeprinter;
623 if (ClosePrinter (hPrinter) == 0) {
624 ERR ("ClosePrinter failed with code %li\n", GetLastError ());
625 goto cleanup;
628 pi->next = NULL;
629 pi->Fonts = NULL;
631 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
632 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
633 if(!afm) {
634 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
635 "ignoring\n", font->Name);
637 else {
638 BOOL added;
639 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
640 PSDRV_FreeAFMList(pi->Fonts);
641 goto cleanup;
646 if (ppd) unlink(ppd);
647 return pi;
649 closeprinter:
650 ClosePrinter(hPrinter);
651 cleanup:
652 if (ppdFileName)
653 HeapFree(PSDRV_Heap, 0, ppdFileName);
654 if (pi->FontSubTable)
655 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
656 if (pi->FriendlyName)
657 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
658 if (pi->Devmode)
659 HeapFree(PSDRV_Heap, 0, pi->Devmode);
660 fail:
661 HeapFree(PSDRV_Heap, 0, pi);
662 if (ppd) unlink(ppd);
663 *last = NULL;
664 return NULL;