Release 20030408.
[wine/gsoc-2012-control.git] / dlls / wineps / init.c
blobab692b9ceaea58ff6fbcaaf16a49c6ba5b443beb
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"
23 #include "wine/port.h"
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32 #include "gdi.h"
33 #include "psdrv.h"
34 #include "wine/debug.h"
35 #include "winreg.h"
36 #include "winspool.h"
37 #include "winerror.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
41 #ifdef HAVE_CUPS_CUPS_H
42 #include <cups/cups.h>
44 #ifndef SONAME_LIBCUPS
45 #define SONAME_LIBCUPS "libcups.so"
46 #endif
48 static void *cupshandle = NULL;
49 #endif
51 static PSDRV_DEVMODEA DefaultDevmode =
53 { /* dmPublic */
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_DUPLEX | DM_YRESOLUTION | DM_TTOPTION,
62 { /* u1 */
63 { /* s1 */
64 /* dmOrientation */ DMORIENT_PORTRAIT,
65 /* dmPaperSize */ DMPAPER_LETTER,
66 /* dmPaperLength */ 2794,
67 /* dmPaperWidth */ 2159
70 /* dmScale */ 100, /* ?? */
71 /* dmCopies */ 1,
72 /* dmDefaultSource */ DMBIN_AUTO,
73 /* dmPrintQuality */ 0,
74 /* dmColor */ DMCOLOR_COLOR,
75 /* dmDuplex */ 0,
76 /* dmYResolution */ 0,
77 /* dmTTOption */ DMTT_SUBDEV,
78 /* dmCollate */ 0,
79 /* dmFormName */ "",
80 /* dmUnusedPadding */ 0,
81 /* dmBitsPerPel */ 0,
82 /* dmPelsWidth */ 0,
83 /* dmPelsHeight */ 0,
84 /* dmDisplayFlags */ 0,
85 /* dmDisplayFrequency */ 0,
86 /* dmICMMethod */ 0,
87 /* dmICMIntent */ 0,
88 /* dmMediaType */ 0,
89 /* dmDitherType */ 0,
90 /* dmReserved1 */ 0,
91 /* dmReserved2 */ 0,
92 /* dmPanningWidth */ 0,
93 /* dmPanningHeight */ 0
95 { /* dmDocPrivate */
96 /* dummy */ 0
98 { /* dmDrvPrivate */
99 /* numInstalledOptions */ 0
103 HANDLE PSDRV_Heap = 0;
105 static HANDLE PSDRV_DefaultFont = 0;
106 static LOGFONTA DefaultLogFont = {
107 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
108 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
111 /*********************************************************************
112 * DllMain
114 * Initializes font metrics and registers driver. wineps dll entry point.
117 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
119 TRACE("(%p, 0x%08lx, %p)\n", hinst, reason, reserved);
121 switch(reason) {
123 case DLL_PROCESS_ATTACH:
125 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
126 if (PSDRV_Heap == NULL)
127 return FALSE;
129 if (PSDRV_GetFontMetrics() == FALSE) {
130 HeapDestroy(PSDRV_Heap);
131 return FALSE;
134 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
135 if (PSDRV_DefaultFont == NULL) {
136 HeapDestroy(PSDRV_Heap);
137 return FALSE;
139 #ifdef HAVE_CUPS_CUPS_H
140 /* dynamically load CUPS if not yet loaded */
141 if (!cupshandle) {
142 cupshandle = wine_dlopen(SONAME_LIBCUPS, RTLD_NOW, NULL, 0);
143 if (!cupshandle) cupshandle = (void*)-1;
145 #endif
146 break;
148 case DLL_PROCESS_DETACH:
150 DeleteObject( PSDRV_DefaultFont );
151 HeapDestroy( PSDRV_Heap );
152 #ifdef HAVE_CUPS_CUPS_H
153 if (cupshandle && (cupshandle != (void*)-1)) {
154 wine_dlclose(cupshandle, NULL, 0);
155 cupshandle = NULL;
157 #endif
158 break;
161 return TRUE;
165 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
167 PAGESIZE *page;
168 INT width = 0, height = 0;
170 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
171 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
172 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
173 break;
176 if(!page) {
177 FIXME("Can't find page\n");
178 physDev->ImageableArea.left = 0;
179 physDev->ImageableArea.right = 0;
180 physDev->ImageableArea.bottom = 0;
181 physDev->ImageableArea.top = 0;
182 physDev->PageSize.cx = 0;
183 physDev->PageSize.cy = 0;
184 } else if(page->ImageableArea) {
185 /* physDev sizes in device units; ppd sizes in 1/72" */
186 physDev->ImageableArea.left = page->ImageableArea->llx *
187 physDev->logPixelsX / 72;
188 physDev->ImageableArea.right = page->ImageableArea->urx *
189 physDev->logPixelsX / 72;
190 physDev->ImageableArea.bottom = page->ImageableArea->lly *
191 physDev->logPixelsY / 72;
192 physDev->ImageableArea.top = page->ImageableArea->ury *
193 physDev->logPixelsY / 72;
194 physDev->PageSize.cx = page->PaperDimension->x *
195 physDev->logPixelsX / 72;
196 physDev->PageSize.cy = page->PaperDimension->y *
197 physDev->logPixelsY / 72;
198 } else {
199 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
200 physDev->ImageableArea.right = physDev->PageSize.cx =
201 page->PaperDimension->x * physDev->logPixelsX / 72;
202 physDev->ImageableArea.top = physDev->PageSize.cy =
203 page->PaperDimension->y * physDev->logPixelsY / 72;
205 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
206 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
207 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
208 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
209 physDev->ImageableArea.right = physDev->PageSize.cx =
210 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
211 physDev->logPixelsX / 254;
212 physDev->ImageableArea.top = physDev->PageSize.cy =
213 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
214 physDev->logPixelsY / 254;
215 } else {
216 FIXME("Odd dmFields %lx\n", physDev->Devmode->dmPublic.dmFields);
217 physDev->ImageableArea.left = 0;
218 physDev->ImageableArea.right = 0;
219 physDev->ImageableArea.bottom = 0;
220 physDev->ImageableArea.top = 0;
221 physDev->PageSize.cx = 0;
222 physDev->PageSize.cy = 0;
225 TRACE("ImageableArea = %ld,%ld - %ld,%ld: PageSize = %ldx%ld\n",
226 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
227 physDev->ImageableArea.right, physDev->ImageableArea.top,
228 physDev->PageSize.cx, physDev->PageSize.cy);
230 /* these are in device units */
231 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
232 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
234 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
235 physDev->horzRes = width;
236 physDev->vertRes = height;
237 } else {
238 physDev->horzRes = height;
239 physDev->vertRes = width;
242 /* these are in mm */
243 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
244 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
246 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
247 "horzRes = %d, vertRes = %d\n",
248 physDev->horzSize, physDev->vertSize,
249 physDev->horzRes, physDev->vertRes);
253 /**********************************************************************
254 * PSDRV_CreateDC
256 BOOL PSDRV_CreateDC( DC *dc, PSDRV_PDEVICE **pdev, LPCSTR driver, LPCSTR device,
257 LPCSTR output, const DEVMODEA* initData )
259 PSDRV_PDEVICE *physDev;
260 PRINTERINFO *pi;
262 /* If no device name was specified, retrieve the device name
263 * from the DEVMODE structure from the DC's physDev.
264 * (See CreateCompatibleDC) */
265 if ( !device && *pdev )
267 physDev = *pdev;
268 device = physDev->Devmode->dmPublic.dmDeviceName;
270 pi = PSDRV_FindPrinterInfo(device);
272 TRACE("(%s %s %s %p)\n", driver, device, output, initData);
274 if(!pi) return FALSE;
276 if(!pi->Fonts) {
277 MESSAGE("To use WINEPS you need to install some AFM files.\n");
278 return FALSE;
281 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
282 sizeof(*physDev) );
283 if (!physDev) return FALSE;
284 *pdev = physDev;
285 physDev->hdc = dc->hSelf;
286 physDev->dc = dc;
288 physDev->pi = pi;
290 physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0,
291 sizeof(PSDRV_DEVMODEA) );
292 if(!physDev->Devmode) {
293 HeapFree( PSDRV_Heap, 0, physDev );
294 return FALSE;
297 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) );
299 physDev->logPixelsX = physDev->pi->ppd->DefaultResolution;
300 physDev->logPixelsY = physDev->pi->ppd->DefaultResolution;
302 if (!output) output = "LPT1:"; /* HACK */
303 physDev->job.output = HeapAlloc( PSDRV_Heap, 0, strlen(output)+1 );
304 strcpy( physDev->job.output, output );
305 physDev->job.hJob = 0;
307 if(initData) {
308 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)initData, pi);
311 PSDRV_UpdateDevCaps(physDev);
312 dc->hFont = PSDRV_DefaultFont;
313 return TRUE;
318 /**********************************************************************
319 * PSDRV_DeleteDC
321 BOOL PSDRV_DeleteDC( PSDRV_PDEVICE *physDev )
323 TRACE("\n");
325 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
326 HeapFree( PSDRV_Heap, 0, physDev->job.output );
327 HeapFree( PSDRV_Heap, 0, physDev );
329 return TRUE;
333 /**********************************************************************
334 * ResetDC (WINEPS.@)
336 HDC PSDRV_ResetDC( PSDRV_PDEVICE *physDev, const DEVMODEA *lpInitData )
338 if(lpInitData) {
339 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)lpInitData, physDev->pi);
340 PSDRV_UpdateDevCaps(physDev);
342 return physDev->hdc;
345 /***********************************************************************
346 * GetDeviceCaps (WINEPS.@)
348 INT PSDRV_GetDeviceCaps( PSDRV_PDEVICE *physDev, INT cap )
350 switch(cap)
352 case DRIVERVERSION:
353 return 0;
354 case TECHNOLOGY:
355 return DT_RASPRINTER;
356 case HORZSIZE:
357 return MulDiv(physDev->horzSize, 100,
358 physDev->Devmode->dmPublic.dmScale);
359 case VERTSIZE:
360 return MulDiv(physDev->vertSize, 100,
361 physDev->Devmode->dmPublic.dmScale);
362 case HORZRES:
363 return physDev->horzRes;
364 case VERTRES:
365 return physDev->vertRes;
366 case BITSPIXEL:
367 return (physDev->pi->ppd->ColorDevice ? 8 : 1);
368 case PLANES:
369 return 1;
370 case NUMBRUSHES:
371 return -1;
372 case NUMPENS:
373 return 10;
374 case NUMMARKERS:
375 return 0;
376 case NUMFONTS:
377 return 39;
378 case NUMCOLORS:
379 return (physDev->pi->ppd->ColorDevice ? 256 : -1);
380 case PDEVICESIZE:
381 return sizeof(PSDRV_PDEVICE);
382 case CURVECAPS:
383 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
384 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
385 case LINECAPS:
386 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
387 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
388 case POLYGONALCAPS:
389 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
390 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
391 case TEXTCAPS:
392 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
393 case CLIPCAPS:
394 return CP_RECTANGLE;
395 case RASTERCAPS:
396 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
397 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
398 /* Are aspect[XY] and logPixels[XY] correct? */
399 /* Need to handle different res in x and y => fix ppd */
400 case ASPECTX:
401 case ASPECTY:
402 return physDev->pi->ppd->DefaultResolution;
403 case ASPECTXY:
404 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
405 (double)physDev->pi->ppd->DefaultResolution );
406 case LOGPIXELSX:
407 return MulDiv(physDev->logPixelsX,
408 physDev->Devmode->dmPublic.dmScale, 100);
409 case LOGPIXELSY:
410 return MulDiv(physDev->logPixelsY,
411 physDev->Devmode->dmPublic.dmScale, 100);
412 case SIZEPALETTE:
413 return 0;
414 case NUMRESERVED:
415 return 0;
416 case COLORRES:
417 return 0;
418 case PHYSICALWIDTH:
419 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
420 physDev->PageSize.cy : physDev->PageSize.cx;
421 case PHYSICALHEIGHT:
422 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
423 physDev->PageSize.cx : physDev->PageSize.cy;
424 case PHYSICALOFFSETX:
425 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
426 if(physDev->pi->ppd->LandscapeOrientation == -90)
427 return physDev->PageSize.cy - physDev->ImageableArea.top;
428 else
429 return physDev->ImageableArea.bottom;
431 return physDev->ImageableArea.left;
433 case PHYSICALOFFSETY:
434 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
435 if(physDev->pi->ppd->LandscapeOrientation == -90)
436 return physDev->PageSize.cx - physDev->ImageableArea.right;
437 else
438 return physDev->ImageableArea.left;
440 return physDev->PageSize.cy - physDev->ImageableArea.top;
442 case SCALINGFACTORX:
443 case SCALINGFACTORY:
444 case VREFRESH:
445 case DESKTOPVERTRES:
446 case DESKTOPHORZRES:
447 case BTLALIGNMENT:
448 return 0;
449 default:
450 FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap );
451 return 0;
456 /**********************************************************************
457 * PSDRV_FindPrinterInfo
459 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
461 static PRINTERINFO *PSDRV_PrinterList;
462 DWORD type = REG_BINARY, needed, res, dwPaperSize;
463 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
464 FONTNAME *font;
465 const AFM *afm;
466 HANDLE hPrinter;
467 const char *ppd = NULL;
468 DWORD ppdType;
469 char* ppdFileName = NULL;
470 HKEY hkey;
471 BOOL using_default_devmode = FALSE;
473 TRACE("'%s'\n", name);
476 * If this loop completes, last will point to the 'next' element of the
477 * final PRINTERINFO in the list
479 for( ; pi; last = &pi->next, pi = pi->next)
480 if(!strcmp(pi->FriendlyName, name))
481 return pi;
483 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
484 if (pi == NULL)
485 return NULL;
487 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
488 strcpy( pi->FriendlyName, name );
490 /* Use Get|SetPrinterDataExA instead? */
492 res = DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
493 NULL, 0, &needed );
495 if(res == ERROR_INVALID_PRINTER_NAME || needed != sizeof(DefaultDevmode)) {
496 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
497 if (pi->Devmode == NULL)
498 goto cleanup;
499 memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) );
500 strcpy(pi->Devmode->dmPublic.dmDeviceName,name);
501 using_default_devmode = TRUE;
503 /* need to do something here AddPrinter?? */
505 else {
506 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
507 DrvGetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
508 (LPBYTE)pi->Devmode, needed, &needed);
511 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
512 ERR ("OpenPrinterA failed with code %li\n", GetLastError ());
513 goto cleanup;
516 #ifdef HAVE_CUPS_CUPS_H
517 if (cupshandle != (void*)-1) {
518 typeof(cupsGetPPD) * pcupsGetPPD = NULL;
520 pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0);
521 if (pcupsGetPPD) {
522 ppd = pcupsGetPPD(name);
524 if (ppd) {
525 needed=strlen(ppd)+1;
526 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
527 memcpy(ppdFileName, ppd, needed);
528 ppdType=REG_SZ;
529 res = ERROR_SUCCESS;
530 /* we should unlink() that file later */
531 } else {
532 res = ERROR_FILE_NOT_FOUND;
533 WARN("Did not find ppd for %s\n",name);
537 #endif
538 if (!ppdFileName) {
539 res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed);
540 if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
541 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
542 res = GetPrinterDataA(hPrinter, "PPD File", &ppdType, ppdFileName, needed, &needed);
545 /* Look for a ppd file for this printer in the config file.
546 * First look under that printer's name, and then under 'generic'
548 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey))
550 const char* value_name;
552 if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
553 value_name=name;
554 } else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
555 value_name="generic";
556 } else {
557 value_name=NULL;
559 if (value_name) {
560 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
561 RegQueryValueExA(hkey, value_name, 0, &ppdType, ppdFileName, &needed);
563 RegCloseKey(hkey);
566 if (!ppdFileName) {
567 res = ERROR_FILE_NOT_FOUND;
568 ERR ("Error %li getting PPD file name for printer '%s'\n", res, name);
569 goto closeprinter;
570 } else {
571 res = ERROR_SUCCESS;
572 if (ppdType==REG_EXPAND_SZ) {
573 char* tmp;
575 /* Expand environment variable references */
576 needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0);
577 tmp=HeapAlloc(PSDRV_Heap, 0, needed);
578 ExpandEnvironmentStringsA(ppdFileName,tmp,needed);
579 HeapFree(PSDRV_Heap, 0, ppdFileName);
580 ppdFileName=tmp;
584 pi->ppd = PSDRV_ParsePPD(ppdFileName);
585 if(!pi->ppd) {
586 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
587 ppdFileName);
588 goto closeprinter;
592 if(using_default_devmode) {
593 DWORD papersize;
595 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
596 (LPWSTR)&papersize, sizeof(papersize))) {
597 PSDRV_DEVMODEA dm;
598 memset(&dm, 0, sizeof(dm));
599 dm.dmPublic.dmFields = DM_PAPERSIZE;
600 dm.dmPublic.u1.s1.dmPaperSize = papersize;
601 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
603 DrvSetPrinterData16((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE,
604 REG_BINARY, (LPBYTE)pi->Devmode, sizeof(DefaultDevmode) );
609 * This is a hack. The default paper size should be read in as part of
610 * the Devmode structure, but Wine doesn't currently provide a convenient
611 * way to configure printers.
613 res = GetPrinterDataA (hPrinter, "Paper Size", NULL, (LPBYTE) &dwPaperSize,
614 sizeof (DWORD), &needed);
615 if (res == ERROR_SUCCESS)
616 pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize;
617 else if (res == ERROR_FILE_NOT_FOUND)
618 TRACE ("No 'Paper Size' for printer '%s'\n", name);
619 else {
620 ERR ("GetPrinterDataA returned %li\n", res);
621 goto closeprinter;
624 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL,
625 0, &needed, &pi->FontSubTableSize);
626 if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) {
627 TRACE ("No 'FontSubTable' for printer '%s'\n", name);
629 else if (res == ERROR_MORE_DATA) {
630 pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed);
631 if (pi->FontSubTable == NULL) {
632 ERR ("Failed to allocate %li bytes from heap\n", needed);
633 goto closeprinter;
636 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable",
637 (LPBYTE) pi->FontSubTable, needed, &needed,
638 &pi->FontSubTableSize);
639 if (res != ERROR_SUCCESS) {
640 ERR ("EnumPrinterDataExA returned %li\n", res);
641 goto closeprinter;
644 else {
645 ERR("EnumPrinterDataExA returned %li\n", res);
646 goto closeprinter;
649 if (ClosePrinter (hPrinter) == 0) {
650 ERR ("ClosePrinter failed with code %li\n", GetLastError ());
651 goto cleanup;
654 pi->next = NULL;
655 pi->Fonts = NULL;
657 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
658 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
659 if(!afm) {
660 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
661 "ignoring\n", font->Name);
663 else {
664 BOOL added;
665 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
666 PSDRV_FreeAFMList(pi->Fonts);
667 goto cleanup;
672 if (ppd) unlink(ppd);
673 return pi;
675 closeprinter:
676 ClosePrinter(hPrinter);
677 cleanup:
678 if (ppdFileName)
679 HeapFree(PSDRV_Heap, 0, ppdFileName);
680 if (pi->FontSubTable)
681 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
682 if (pi->FriendlyName)
683 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
684 if (pi->Devmode)
685 HeapFree(PSDRV_Heap, 0, pi->Devmode);
686 fail:
687 HeapFree(PSDRV_Heap, 0, pi);
688 if (ppd) unlink(ppd);
689 *last = NULL;
690 return NULL;