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
44 #include "wine/unicode.h"
45 #include "wine/library.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
51 static void *cupshandle = NULL;
54 static const PSDRV_DEVMODEA DefaultDevmode =
57 /* dmDeviceName */ "Wine PostScript Driver",
58 /* dmSpecVersion */ 0x30a,
59 /* dmDriverVersion */ 0x001,
60 /* dmSize */ sizeof(DEVMODEA),
61 /* dmDriverExtra */ sizeof(PSDRV_DEVMODEA)-sizeof(DEVMODEA),
62 /* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_SCALE |
63 DM_COPIES | DM_DEFAULTSOURCE | DM_COLOR |
64 DM_YRESOLUTION | DM_TTOPTION,
67 /* dmOrientation */ DMORIENT_PORTRAIT,
68 /* dmPaperSize */ DMPAPER_LETTER,
69 /* dmPaperLength */ 2794,
70 /* dmPaperWidth */ 2159,
71 /* dmScale */ 100, /* ?? */
73 /* dmDefaultSource */ DMBIN_AUTO,
74 /* dmPrintQuality */ 0
77 /* dmColor */ DMCOLOR_COLOR,
78 /* dmDuplex */ DMDUP_SIMPLEX,
79 /* dmYResolution */ 0,
80 /* dmTTOption */ DMTT_SUBDEV,
83 /* dmUnusedPadding */ 0,
88 /* dmDisplayFlags */ 0
90 /* dmDisplayFrequency */ 0,
97 /* dmPanningWidth */ 0,
98 /* dmPanningHeight */ 0
104 /* numInstalledOptions */ 0
108 HINSTANCE PSDRV_hInstance = 0;
109 HANDLE PSDRV_Heap = 0;
111 static HFONT PSDRV_DefaultFont = 0;
112 static const LOGFONTA DefaultLogFont = {
113 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
114 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
117 static const CHAR default_devmodeA[] = "Default DevMode";
118 static const struct gdi_dc_funcs psdrv_funcs;
120 /*********************************************************************
123 * Initializes font metrics and registers driver. wineps dll entry point.
126 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
128 TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
132 case DLL_PROCESS_ATTACH:
133 PSDRV_hInstance = hinst;
134 DisableThreadLibraryCalls(hinst);
136 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
137 if (PSDRV_Heap == NULL)
140 if (PSDRV_GetFontMetrics() == FALSE) {
141 HeapDestroy(PSDRV_Heap);
145 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
146 if (PSDRV_DefaultFont == NULL) {
147 HeapDestroy(PSDRV_Heap);
150 #ifdef SONAME_LIBCUPS
151 /* dynamically load CUPS if not yet loaded */
153 cupshandle = wine_dlopen(SONAME_LIBCUPS, RTLD_NOW, NULL, 0);
154 if (!cupshandle) cupshandle = (void*)-1;
159 case DLL_PROCESS_DETACH:
161 DeleteObject( PSDRV_DefaultFont );
162 HeapDestroy( PSDRV_Heap );
163 #ifdef SONAME_LIBCUPS
164 if (cupshandle && (cupshandle != (void*)-1)) {
165 wine_dlclose(cupshandle, NULL, 0);
175 static inline WCHAR *strdupW( const WCHAR *str )
180 if (!str) return NULL;
181 size = (strlenW( str ) + 1) * sizeof(WCHAR);
182 ret = HeapAlloc( GetProcessHeap(), 0, size );
183 if (ret) memcpy( ret, str, size );
187 static void PSDRV_UpdateDevCaps( PSDRV_PDEVICE *physDev )
190 INT width = 0, height = 0;
192 if(physDev->Devmode->dmPublic.dmFields & DM_PAPERSIZE) {
193 LIST_FOR_EACH_ENTRY(page, &physDev->pi->ppd->PageSizes, PAGESIZE, entry) {
194 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize)
198 if(&page->entry == &physDev->pi->ppd->PageSizes) {
199 FIXME("Can't find page\n");
200 physDev->ImageableArea.left = 0;
201 physDev->ImageableArea.right = 0;
202 physDev->ImageableArea.bottom = 0;
203 physDev->ImageableArea.top = 0;
204 physDev->PageSize.cx = 0;
205 physDev->PageSize.cy = 0;
206 } else if(page->ImageableArea) {
207 /* physDev sizes in device units; ppd sizes in 1/72" */
208 physDev->ImageableArea.left = page->ImageableArea->llx *
209 physDev->logPixelsX / 72;
210 physDev->ImageableArea.right = page->ImageableArea->urx *
211 physDev->logPixelsX / 72;
212 physDev->ImageableArea.bottom = page->ImageableArea->lly *
213 physDev->logPixelsY / 72;
214 physDev->ImageableArea.top = page->ImageableArea->ury *
215 physDev->logPixelsY / 72;
216 physDev->PageSize.cx = page->PaperDimension->x *
217 physDev->logPixelsX / 72;
218 physDev->PageSize.cy = page->PaperDimension->y *
219 physDev->logPixelsY / 72;
221 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
222 physDev->ImageableArea.right = physDev->PageSize.cx =
223 page->PaperDimension->x * physDev->logPixelsX / 72;
224 physDev->ImageableArea.top = physDev->PageSize.cy =
225 page->PaperDimension->y * physDev->logPixelsY / 72;
227 } else if((physDev->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) &&
228 (physDev->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) {
229 /* physDev sizes in device units; Devmode sizes in 1/10 mm */
230 physDev->ImageableArea.left = physDev->ImageableArea.bottom = 0;
231 physDev->ImageableArea.right = physDev->PageSize.cx =
232 physDev->Devmode->dmPublic.u1.s1.dmPaperWidth *
233 physDev->logPixelsX / 254;
234 physDev->ImageableArea.top = physDev->PageSize.cy =
235 physDev->Devmode->dmPublic.u1.s1.dmPaperLength *
236 physDev->logPixelsY / 254;
238 FIXME("Odd dmFields %x\n", physDev->Devmode->dmPublic.dmFields);
239 physDev->ImageableArea.left = 0;
240 physDev->ImageableArea.right = 0;
241 physDev->ImageableArea.bottom = 0;
242 physDev->ImageableArea.top = 0;
243 physDev->PageSize.cx = 0;
244 physDev->PageSize.cy = 0;
247 TRACE("ImageableArea = %d,%d - %d,%d: PageSize = %dx%d\n",
248 physDev->ImageableArea.left, physDev->ImageableArea.bottom,
249 physDev->ImageableArea.right, physDev->ImageableArea.top,
250 physDev->PageSize.cx, physDev->PageSize.cy);
252 /* these are in device units */
253 width = physDev->ImageableArea.right - physDev->ImageableArea.left;
254 height = physDev->ImageableArea.top - physDev->ImageableArea.bottom;
256 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_PORTRAIT) {
257 physDev->horzRes = width;
258 physDev->vertRes = height;
260 physDev->horzRes = height;
261 physDev->vertRes = width;
264 /* these are in mm */
265 physDev->horzSize = (physDev->horzRes * 25.4) / physDev->logPixelsX;
266 physDev->vertSize = (physDev->vertRes * 25.4) / physDev->logPixelsY;
268 TRACE("devcaps: horzSize = %dmm, vertSize = %dmm, "
269 "horzRes = %d, vertRes = %d\n",
270 physDev->horzSize, physDev->vertSize,
271 physDev->horzRes, physDev->vertRes);
275 /***********************************************************
278 * Creates an ascii copy of supplied devmode on heap
280 * Copied from dlls/winspool/info.c until full unicodification
282 static LPDEVMODEA DEVMODEdupWtoA(HANDLE heap, const DEVMODEW *dmW)
287 /* there is no pointer dereference here, if your code checking tool complains it's broken */
288 ptrdiff_t off_formname = (const char *)dmW->dmFormName - (const char *)dmW;
290 if(!dmW) return NULL;
291 Formname = (dmW->dmSize > off_formname);
292 size = dmW->dmSize - CCHDEVICENAME - (Formname ? CCHFORMNAME : 0);
293 dmA = HeapAlloc(heap, HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra);
294 WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1, (LPSTR)dmA->dmDeviceName,
295 CCHDEVICENAME, NULL, NULL);
297 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
298 dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR));
300 memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
301 off_formname - CCHDEVICENAME * sizeof(WCHAR));
302 WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1, (LPSTR)dmA->dmFormName,
303 CCHFORMNAME, NULL, NULL);
304 memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
305 (off_formname + CCHFORMNAME * sizeof(WCHAR)));
308 memcpy((char *)dmA + dmA->dmSize, (const char *)dmW + dmW->dmSize,
314 static PSDRV_PDEVICE *create_psdrv_physdev( PRINTERINFO *pi )
316 PSDRV_PDEVICE *physDev;
318 physDev = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*physDev) );
319 if (!physDev) return NULL;
321 physDev->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(PSDRV_DEVMODEA) );
322 if (!physDev->Devmode)
324 HeapFree( PSDRV_Heap, 0, physDev );
328 *physDev->Devmode = *pi->Devmode;
330 physDev->logPixelsX = pi->ppd->DefaultResolution;
331 physDev->logPixelsY = pi->ppd->DefaultResolution;
335 /**********************************************************************
338 static BOOL PSDRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
339 LPCWSTR output, const DEVMODEW* initData )
341 PSDRV_PDEVICE *physDev;
346 TRACE("(%s %s %s %p)\n", debugstr_w(driver), debugstr_w(device),
347 debugstr_w(output), initData);
349 if (!device) return FALSE;
350 len = WideCharToMultiByte(CP_ACP, 0, device, -1, NULL, 0, NULL, NULL);
351 deviceA = HeapAlloc(GetProcessHeap(), 0, len);
352 WideCharToMultiByte(CP_ACP, 0, device, -1, deviceA, len, NULL, NULL);
353 pi = PSDRV_FindPrinterInfo(deviceA);
354 HeapFree(GetProcessHeap(), 0, deviceA);
355 if(!pi) return FALSE;
358 RASTERIZER_STATUS status;
359 if(!GetRasterizerCaps(&status, sizeof(status)) ||
360 !(status.wFlags & TT_AVAILABLE) ||
361 !(status.wFlags & TT_ENABLED)) {
362 MESSAGE("Disabling printer %s since it has no builtin fonts and there are no TrueType fonts available.\n",
368 if (!(physDev = create_psdrv_physdev( pi ))) return FALSE;
370 if (output && *output) physDev->job.output = strdupW( output );
373 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, initData);
374 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, pi);
375 HeapFree(PSDRV_Heap, 0, devmodeA);
378 PSDRV_UpdateDevCaps(physDev);
379 SelectObject( (*pdev)->hdc, PSDRV_DefaultFont );
380 push_dc_driver( pdev, &physDev->dev, &psdrv_funcs );
385 /**********************************************************************
386 * PSDRV_CreateCompatibleDC
388 static BOOL PSDRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
390 HDC hdc = (*pdev)->hdc;
391 PSDRV_PDEVICE *physDev, *orig_dev = get_psdrv_dev( orig );
392 PRINTERINFO *pi = PSDRV_FindPrinterInfo( orig_dev->pi->FriendlyName );
394 if (!pi) return FALSE;
395 if (!(physDev = create_psdrv_physdev( pi ))) return FALSE;
396 PSDRV_MergeDevmodes( physDev->Devmode, orig_dev->Devmode, pi );
397 PSDRV_UpdateDevCaps(physDev);
398 SelectObject( hdc, PSDRV_DefaultFont );
399 push_dc_driver( pdev, &physDev->dev, &psdrv_funcs );
405 /**********************************************************************
408 static BOOL PSDRV_DeleteDC( PHYSDEV dev )
410 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
414 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
415 HeapFree( PSDRV_Heap, 0, physDev->job.output );
416 HeapFree( PSDRV_Heap, 0, physDev );
422 /**********************************************************************
425 static HDC PSDRV_ResetDC( PHYSDEV dev, const DEVMODEW *lpInitData )
427 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
430 DEVMODEA *devmodeA = DEVMODEdupWtoA(PSDRV_Heap, lpInitData);
431 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODEA *)devmodeA, physDev->pi);
432 HeapFree(PSDRV_Heap, 0, devmodeA);
433 PSDRV_UpdateDevCaps(physDev);
438 /***********************************************************************
439 * GetDeviceCaps (WINEPS.@)
441 static INT PSDRV_GetDeviceCaps( PHYSDEV dev, INT cap )
443 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
450 return DT_RASPRINTER;
452 return MulDiv(physDev->horzSize, 100,
453 physDev->Devmode->dmPublic.u1.s1.dmScale);
455 return MulDiv(physDev->vertSize, 100,
456 physDev->Devmode->dmPublic.u1.s1.dmScale);
459 return physDev->horzRes;
462 return physDev->vertRes;
464 return (physDev->pi->ppd->ColorDevice != CD_False) ? 32 : 1;
478 return sizeof(PSDRV_PDEVICE);
480 return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
481 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
483 return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
484 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
486 return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
487 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
489 return TC_CR_ANY | TC_VA_ABLE; /* psdrv 0x59f7 */
493 return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DIBTODEV |
494 RC_STRETCHBLT | RC_STRETCHDIB); /* psdrv 0x6e99 */
495 /* Are aspect[XY] and logPixels[XY] correct? */
496 /* Need to handle different res in x and y => fix ppd */
499 return physDev->pi->ppd->DefaultResolution;
501 return (int)hypot( (double)physDev->pi->ppd->DefaultResolution,
502 (double)physDev->pi->ppd->DefaultResolution );
504 return MulDiv(physDev->logPixelsX,
505 physDev->Devmode->dmPublic.u1.s1.dmScale, 100);
507 return MulDiv(physDev->logPixelsY,
508 physDev->Devmode->dmPublic.u1.s1.dmScale, 100);
516 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
517 physDev->PageSize.cy : physDev->PageSize.cx;
519 return (physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) ?
520 physDev->PageSize.cx : physDev->PageSize.cy;
521 case PHYSICALOFFSETX:
522 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
523 if(physDev->pi->ppd->LandscapeOrientation == -90)
524 return physDev->PageSize.cy - physDev->ImageableArea.top;
526 return physDev->ImageableArea.bottom;
528 return physDev->ImageableArea.left;
530 case PHYSICALOFFSETY:
531 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
532 if(physDev->pi->ppd->LandscapeOrientation == -90)
533 return physDev->PageSize.cx - physDev->ImageableArea.right;
535 return physDev->ImageableArea.left;
537 return physDev->PageSize.cy - physDev->ImageableArea.top;
547 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
553 /**********************************************************************
554 * PSDRV_FindPrinterInfo
556 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
558 static PRINTERINFO *PSDRV_PrinterList;
559 DWORD type = REG_BINARY, needed, res, dwPaperSize;
560 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
564 const char *ppd = NULL;
566 char* ppdFileName = NULL;
568 BOOL using_default_devmode = FALSE;
570 TRACE("'%s'\n", name);
573 * If this loop completes, last will point to the 'next' element of the
574 * final PRINTERINFO in the list
576 for( ; pi; last = &pi->next, pi = pi->next)
577 if(!strcmp(pi->FriendlyName, name))
580 pi = *last = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*pi) );
584 if (!(pi->FriendlyName = HeapAlloc( PSDRV_Heap, 0, strlen(name)+1 ))) goto fail;
585 strcpy( pi->FriendlyName, name );
587 if (OpenPrinterA (pi->FriendlyName, &hPrinter, NULL) == 0) {
588 ERR ("OpenPrinterA failed with code %i\n", GetLastError ());
593 res = GetPrinterDataExA(hPrinter, NULL, default_devmodeA, &type, NULL, 0, &needed);
595 if (needed < sizeof(DefaultDevmode)) {
596 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
597 if (pi->Devmode == NULL)
600 *pi->Devmode = DefaultDevmode;
601 lstrcpynA((LPSTR)pi->Devmode->dmPublic.dmDeviceName,name,CCHDEVICENAME);
602 using_default_devmode = TRUE;
605 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
606 if (pi->Devmode == NULL)
609 GetPrinterDataExA(hPrinter, NULL, default_devmodeA, &type, (LPBYTE)pi->Devmode, needed, &needed);
614 #ifdef SONAME_LIBCUPS
615 if (cupshandle != (void*)-1) {
616 typeof(cupsGetPPD) * pcupsGetPPD = NULL;
618 pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0);
620 ppd = pcupsGetPPD(name);
623 needed=strlen(ppd)+1;
624 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
625 memcpy(ppdFileName, ppd, needed);
628 /* we should unlink() that file later */
630 res = ERROR_FILE_NOT_FOUND;
631 WARN("Did not find ppd for %s\n",name);
637 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "PPD File", NULL, NULL, 0, &needed);
638 if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
639 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
640 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "PPD File", &ppdType,
641 (LPBYTE)ppdFileName, needed, &needed);
644 /* Look for a ppd file for this printer in the config file.
645 * First look under that printer's name, and then under 'generic'
647 /* @@ Wine registry key: HKCU\Software\Wine\Printing\PPD Files */
648 if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Printing\\PPD Files", &hkey))
650 const char* value_name;
652 if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
654 } else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
655 value_name="generic";
660 HeapFree(PSDRV_Heap, 0, ppdFileName);
661 ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
662 RegQueryValueExA(hkey, value_name, 0, &ppdType, (LPBYTE)ppdFileName, &needed);
669 const char *data_dir, *filename;
671 if ((data_dir = wine_get_data_dir())) filename = "/generic.ppd";
672 else if ((data_dir = wine_get_build_dir())) filename = "/dlls/wineps.drv/generic.ppd";
675 res = ERROR_FILE_NOT_FOUND;
676 ERR ("Error %i getting PPD file name for printer '%s'\n", res, name);
679 ppdFileName = HeapAlloc( PSDRV_Heap, 0, strlen(data_dir) + strlen(filename) + 1 );
680 strcpy( ppdFileName, data_dir );
681 strcat( ppdFileName, filename );
684 if (ppdType==REG_EXPAND_SZ) {
687 /* Expand environment variable references */
688 needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0);
689 tmp=HeapAlloc(PSDRV_Heap, 0, needed);
690 ExpandEnvironmentStringsA(ppdFileName,tmp,needed);
691 HeapFree(PSDRV_Heap, 0, ppdFileName);
696 pi->ppd = PSDRV_ParsePPD(ppdFileName);
698 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
703 /* Some gimp-print ppd files don't contain a DefaultResolution line
704 set it to 300 if it's not specified */
705 if(pi->ppd->DefaultResolution == 0)
706 pi->ppd->DefaultResolution = 300;
708 if(using_default_devmode) {
711 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE | LOCALE_RETURN_NUMBER,
712 (LPWSTR)&papersize, sizeof(papersize)/sizeof(WCHAR))) {
714 memset(&dm, 0, sizeof(dm));
715 dm.dmPublic.dmFields = DM_PAPERSIZE;
716 dm.dmPublic.u1.s1.dmPaperSize = papersize;
717 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
720 SetPrinterDataExA(hPrinter, NULL, default_devmodeA, REG_BINARY,
721 (LPBYTE)pi->Devmode, sizeof(DefaultDevmode));
724 if(pi->ppd->DefaultPageSize) { /* We'll let the ppd override the devmode */
726 memset(&dm, 0, sizeof(dm));
727 dm.dmPublic.dmFields = DM_PAPERSIZE;
728 dm.dmPublic.u1.s1.dmPaperSize = pi->ppd->DefaultPageSize->WinPage;
729 PSDRV_MergeDevmodes(pi->Devmode, &dm, pi);
733 * This is a hack. The default paper size should be read in as part of
734 * the Devmode structure, but Wine doesn't currently provide a convenient
735 * way to configure printers.
737 res = GetPrinterDataExA(hPrinter, "PrinterDriverData", "Paper Size", NULL,
738 (LPBYTE)&dwPaperSize, sizeof(DWORD), &needed);
739 if (res == ERROR_SUCCESS)
740 pi->Devmode->dmPublic.u1.s1.dmPaperSize = (SHORT) dwPaperSize;
741 else if (res == ERROR_FILE_NOT_FOUND)
742 TRACE ("No 'Paper Size' for printer '%s'\n", name);
744 ERR ("GetPrinterDataA returned %i\n", res);
748 /* Duplex is indicated by the setting of the DM_DUPLEX bit in dmFields.
749 WinDuplex == 0 is a special case which means that the ppd has a
750 *DefaultDuplex: NotCapable entry. In this case we'll try not to confuse
751 apps and set dmDuplex to DMDUP_SIMPLEX but leave the DM_DUPLEX clear.
752 PSDRV_WriteHeader understands this and copes. */
753 pi->Devmode->dmPublic.dmFields &= ~DM_DUPLEX;
754 if(pi->ppd->DefaultDuplex) {
755 pi->Devmode->dmPublic.dmDuplex = pi->ppd->DefaultDuplex->WinDuplex;
756 if(pi->Devmode->dmPublic.dmDuplex != 0)
757 pi->Devmode->dmPublic.dmFields |= DM_DUPLEX;
759 pi->Devmode->dmPublic.dmDuplex = DMDUP_SIMPLEX;
762 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable", NULL,
763 0, &needed, &pi->FontSubTableSize);
764 if (res == ERROR_SUCCESS || res == ERROR_FILE_NOT_FOUND) {
765 TRACE ("No 'FontSubTable' for printer '%s'\n", name);
767 else if (res == ERROR_MORE_DATA) {
768 pi->FontSubTable = HeapAlloc (PSDRV_Heap, 0, needed);
769 if (pi->FontSubTable == NULL) {
770 ERR ("Failed to allocate %i bytes from heap\n", needed);
774 res = EnumPrinterDataExA (hPrinter, "PrinterDriverData\\FontSubTable",
775 (LPBYTE) pi->FontSubTable, needed, &needed,
776 &pi->FontSubTableSize);
777 if (res != ERROR_SUCCESS) {
778 ERR ("EnumPrinterDataExA returned %i\n", res);
783 ERR("EnumPrinterDataExA returned %i\n", res);
787 if (ClosePrinter (hPrinter) == 0) {
788 ERR ("ClosePrinter failed with code %i\n", GetLastError ());
795 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
796 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
798 TRACE( "Couldn't find AFM file for installed printer font '%s' - "
799 "ignoring\n", font->Name);
803 if (PSDRV_AddAFMtoList(&pi->Fonts, afm, &added) == FALSE) {
804 PSDRV_FreeAFMList(pi->Fonts);
810 if (ppd) unlink(ppd);
814 ClosePrinter(hPrinter);
816 HeapFree(PSDRV_Heap, 0, ppdFileName);
817 HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
818 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
819 HeapFree(PSDRV_Heap, 0, pi->Devmode);
821 HeapFree(PSDRV_Heap, 0, pi);
822 if (ppd) unlink(ppd);
828 static const struct gdi_dc_funcs psdrv_funcs =
830 NULL, /* pAbortDoc */
831 NULL, /* pAbortPath */
832 NULL, /* pAlphaBlend */
833 NULL, /* pAngleArc */
834 PSDRV_Arc, /* pArc */
836 NULL, /* pBeginPath */
837 NULL, /* pBlendImage */
838 NULL, /* pChoosePixelFormat */
839 PSDRV_Chord, /* pChord */
840 NULL, /* pCloseFigure */
841 NULL, /* pCopyBitmap */
842 NULL, /* pCreateBitmap */
843 PSDRV_CreateCompatibleDC, /* pCreateCompatibleDC */
844 PSDRV_CreateDC, /* pCreateDC */
845 NULL, /* pDeleteBitmap */
846 PSDRV_DeleteDC, /* pDeleteDC */
847 NULL, /* pDeleteObject */
848 NULL, /* pDescribePixelFormat */
849 PSDRV_DeviceCapabilities, /* pDeviceCapabilities */
850 PSDRV_Ellipse, /* pEllipse */
851 PSDRV_EndDoc, /* pEndDoc */
852 PSDRV_EndPage, /* pEndPage */
854 PSDRV_EnumFonts, /* pEnumFonts */
855 NULL, /* pEnumICMProfiles */
856 NULL, /* pExcludeClipRect */
857 PSDRV_ExtDeviceMode, /* pExtDeviceMode */
858 PSDRV_ExtEscape, /* pExtEscape */
859 NULL, /* pExtFloodFill */
860 NULL, /* pExtSelectClipRgn */
861 PSDRV_ExtTextOut, /* pExtTextOut */
862 PSDRV_FillPath, /* pFillPath */
864 NULL, /* pFlattenPath */
865 NULL, /* pFontIsLinked */
866 NULL, /* pFrameRgn */
867 NULL, /* pGdiComment */
868 NULL, /* pGdiRealizationInfo */
869 NULL, /* pGetCharABCWidths */
870 NULL, /* pGetCharABCWidthsI */
871 PSDRV_GetCharWidth, /* pGetCharWidth */
872 PSDRV_GetDeviceCaps, /* pGetDeviceCaps */
873 NULL, /* pGetDeviceGammaRamp */
874 NULL, /* pGetFontData */
875 NULL, /* pGetFontUnicodeRanges */
876 NULL, /* pGetGlyphIndices */
877 NULL, /* pGetGlyphOutline */
878 NULL, /* pGetICMProfile */
879 NULL, /* pGetImage */
880 NULL, /* pGetKerningPairs */
881 NULL, /* pGetNearestColor */
882 NULL, /* pGetOutlineTextMetrics */
883 NULL, /* pGetPixel */
884 NULL, /* pGetPixelFormat */
885 NULL, /* pGetSystemPaletteEntries */
886 NULL, /* pGetTextCharsetInfo */
887 PSDRV_GetTextExtentExPoint, /* pGetTextExtentExPoint */
888 NULL, /* pGetTextExtentExPointI */
889 NULL, /* pGetTextFace */
890 PSDRV_GetTextMetrics, /* pGetTextMetrics */
891 NULL, /* pGradientFill */
892 NULL, /* pIntersectClipRect */
893 NULL, /* pInvertRgn */
894 PSDRV_LineTo, /* pLineTo */
895 NULL, /* pModifyWorldTransform */
897 NULL, /* pOffsetClipRgn */
898 NULL, /* pOffsetViewportOrg */
899 NULL, /* pOffsetWindowOrg */
900 PSDRV_PaintRgn, /* pPaintRgn */
901 PSDRV_PatBlt, /* pPatBlt */
902 PSDRV_Pie, /* pPie */
903 PSDRV_PolyBezier, /* pPolyBezier */
904 PSDRV_PolyBezierTo, /* pPolyBezierTo */
905 NULL, /* pPolyDraw */
906 PSDRV_PolyPolygon, /* pPolyPolygon */
907 PSDRV_PolyPolyline, /* pPolyPolyline */
909 NULL, /* pPolyline */
910 NULL, /* pPolylineTo */
911 PSDRV_PutImage, /* pPutImage */
912 NULL, /* pRealizeDefaultPalette */
913 NULL, /* pRealizePalette */
914 PSDRV_Rectangle, /* pRectangle */
915 PSDRV_ResetDC, /* pResetDC */
916 NULL, /* pRestoreDC */
917 PSDRV_RoundRect, /* pRoundRect */
919 NULL, /* pScaleViewportExt */
920 NULL, /* pScaleWindowExt */
921 NULL, /* pSelectBitmap */
922 PSDRV_SelectBrush, /* pSelectBrush */
923 NULL, /* pSelectClipPath */
924 PSDRV_SelectFont, /* pSelectFont */
925 NULL, /* pSelectPalette */
926 PSDRV_SelectPen, /* pSelectPen */
927 NULL, /* pSetArcDirection */
928 PSDRV_SetBkColor, /* pSetBkColor */
929 NULL, /* pSetBkMode */
930 PSDRV_SetDCBrushColor, /* pSetDCBrushColor */
931 PSDRV_SetDCPenColor, /* pSetDCPenColor */
932 NULL, /* pSetDIBitsToDevice */
933 NULL, /* pSetDeviceClipping */
934 NULL, /* pSetDeviceGammaRamp */
935 NULL, /* pSetLayout */
936 NULL, /* pSetMapMode */
937 NULL, /* pSetMapperFlags */
938 PSDRV_SetPixel, /* pSetPixel */
939 NULL, /* pSetPixelFormat */
940 NULL, /* pSetPolyFillMode */
942 NULL, /* pSetRelAbs */
943 NULL, /* pSetStretchBltMode */
944 NULL, /* pSetTextAlign */
945 NULL, /* pSetTextCharacterExtra */
946 PSDRV_SetTextColor, /* pSetTextColor */
947 NULL, /* pSetTextJustification */
948 NULL, /* pSetViewportExt */
949 NULL, /* pSetViewportOrg */
950 NULL, /* pSetWindowExt */
951 NULL, /* pSetWindowOrg */
952 NULL, /* pSetWorldTransform */
953 PSDRV_StartDoc, /* pStartDoc */
954 PSDRV_StartPage, /* pStartPage */
955 NULL, /* pStretchBlt */
956 NULL, /* pStretchDIBits */
957 PSDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
958 PSDRV_StrokePath, /* pStrokePath */
959 NULL, /* pSwapBuffers */
960 NULL, /* pUnrealizePalette */
961 NULL, /* pWidenPath */
962 /* OpenGL not supported */
966 /******************************************************************************
967 * PSDRV_get_gdi_driver
969 const struct gdi_dc_funcs * CDECL PSDRV_get_gdi_driver( unsigned int version )
971 if (version != WINE_GDI_DRIVER_VERSION)
973 ERR( "version mismatch, gdi32 wants %u but wineps has %u\n", version, WINE_GDI_DRIVER_VERSION );