2 * PostScript driver initialization functions
4 * Copyright 1998 Huw D M Davies
11 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(psdrv
)
20 static BOOL
PSDRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
21 LPCSTR output
, const DEVMODEA
* initData
);
22 static BOOL
PSDRV_DeleteDC( DC
*dc
);
24 static const DC_FUNCTIONS PSDRV_Funcs
=
27 NULL
, /* pAbortPath */
31 NULL
, /* pBeginPath */
33 NULL
, /* pBitmapBits */
34 NULL
, /* pChoosePixelFormat */
35 PSDRV_Chord
, /* pChord */
36 NULL
, /* pCloseFigure */
37 NULL
, /* pCreateBitmap */
38 PSDRV_CreateDC
, /* pCreateDC */
39 NULL
, /* pCreateDIBSection */
40 NULL
, /* pCreateDIBSection16 */
41 PSDRV_DeleteDC
, /* pDeleteDC */
42 NULL
, /* pDeleteObject */
43 NULL
, /* pDescribePixelFormat */
44 PSDRV_DeviceCapabilities
, /* pDeviceCapabilities */
45 PSDRV_Ellipse
, /* pEllipse */
46 PSDRV_EndDoc
, /* pEndDoc */
47 PSDRV_EndPage
, /* pEndPage */
49 PSDRV_EnumDeviceFonts
, /* pEnumDeviceFonts */
50 PSDRV_Escape
, /* pEscape */
51 NULL
, /* pExcludeClipRect */
52 PSDRV_ExtDeviceMode
, /* pExtDeviceMode */
53 NULL
, /* pExtFloodFill */
54 PSDRV_ExtTextOut
, /* pExtTextOut */
57 NULL
, /* pFlattenPath */
59 PSDRV_GetCharWidth
, /* pGetCharWidth */
60 NULL
, /* pGetDCOrgEx */
62 NULL
, /* pGetPixelFormat */
63 PSDRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
64 PSDRV_GetTextMetrics
, /* pGetTextMetrics */
65 NULL
, /* pIntersectClipRect */
66 NULL
, /* pInvertRgn */
67 PSDRV_LineTo
, /* pLineTo */
68 NULL
, /* pLoadOEMResource */
70 NULL
, /* pOffsetClipRgn */
71 NULL
, /* pOffsetViewportOrg (optional) */
72 NULL
, /* pOffsetWindowOrg (optional) */
74 PSDRV_PatBlt
, /* pPatBlt */
76 NULL
, /* pPolyBezier */
77 NULL
, /* pPolyBezierTo */
79 PSDRV_PolyPolygon
, /* pPolyPolygon */
80 PSDRV_PolyPolyline
, /* pPolyPolyline */
81 PSDRV_Polygon
, /* pPolygon */
82 PSDRV_Polyline
, /* pPolyline */
83 NULL
, /* pPolylineTo */
84 NULL
, /* pRealizePalette */
85 PSDRV_Rectangle
, /* pRectangle */
86 NULL
, /* pRestoreDC */
87 PSDRV_RoundRect
, /* pRoundRect */
89 NULL
, /* pScaleViewportExt (optional) */
90 NULL
, /* pScaleWindowExt (optional) */
91 NULL
, /* pSelectClipPath */
92 NULL
, /* pSelectClipRgn */
93 PSDRV_SelectObject
, /* pSelectObject */
94 NULL
, /* pSelectPalette */
95 PSDRV_SetBkColor
, /* pSetBkColor */
96 NULL
, /* pSetBkMode */
97 PSDRV_SetDeviceClipping
, /* pSetDeviceClipping */
98 NULL
, /* pSetDIBitsToDevice */
99 NULL
, /* pSetMapMode (optional) */
100 NULL
, /* pSetMapperFlags */
101 PSDRV_SetPixel
, /* pSetPixel */
102 NULL
, /* pSetPixelFormat */
103 NULL
, /* pSetPolyFillMode */
105 NULL
, /* pSetRelAbs */
106 NULL
, /* pSetStretchBltMode */
107 NULL
, /* pSetTextAlign */
108 NULL
, /* pSetTextCharacterExtra */
109 PSDRV_SetTextColor
, /* pSetTextColor */
110 NULL
, /* pSetTextJustification */
111 NULL
, /* pSetViewportExt (optional) */
112 NULL
, /* pSetViewportOrg (optional) */
113 NULL
, /* pSetWindowExt (optional) */
114 NULL
, /* pSetWindowOrg (optional) */
115 PSDRV_StartDoc
, /* pStartDoc */
116 PSDRV_StartPage
, /* pStartPage */
117 NULL
, /* pStretchBlt */
118 PSDRV_StretchDIBits
, /* pStretchDIBits */
119 NULL
, /* pStrokeAndFillPath */
120 NULL
, /* pStrokePath */
121 NULL
, /* pSwapBuffers */
122 NULL
/* pWidenPath */
126 /* Default entries for devcaps */
128 static DeviceCaps PSDRV_DevCaps
= {
130 /* technology */ DT_RASPRINTER
,
143 /* curveCaps */ CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
|
144 CC_WIDE
| CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
|
146 /* lineCaps */ LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
147 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
,
148 /* polygoalnCaps */ PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
|
149 PC_SCANLINE
| PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
|
151 /* textCaps */ TC_CR_ANY
, /* psdrv 0x59f7 */
152 /* clipCaps */ CP_RECTANGLE
,
153 /* rasterCaps */ RC_BITBLT
| RC_BITMAP64
| RC_GDI20_OUTPUT
|
154 RC_DIBTODEV
| RC_STRETCHBLT
|
155 RC_STRETCHDIB
, /* psdrv 0x6e99 */
160 /* logPixelsX */ 600,
161 /* logPixelsY */ 600,
163 /* palette size */ 0,
166 static PSDRV_DEVMODEA DefaultDevmode
=
169 /* dmDeviceName */ "Wine PostScript Driver",
170 /* dmSpecVersion */ 0x30a,
171 /* dmDriverVersion */ 0x001,
172 /* dmSize */ sizeof(DEVMODEA
),
173 /* dmDriverExtra */ 0,
174 /* dmFields */ DM_ORIENTATION
| DM_PAPERSIZE
| DM_SCALE
|
175 DM_COPIES
| DM_DEFAULTSOURCE
| DM_COLOR
|
176 DM_DUPLEX
| DM_YRESOLUTION
| DM_TTOPTION
,
179 /* dmOrientation */ DMORIENT_PORTRAIT
,
180 /* dmPaperSize */ DMPAPER_A4
,
181 /* dmPaperLength */ 2969,
182 /* dmPaperWidth */ 2101
185 /* dmScale */ 100, /* ?? */
187 /* dmDefaultSource */ DMBIN_AUTO
,
188 /* dmPrintQuality */ 0,
189 /* dmColor */ DMCOLOR_MONOCHROME
,
191 /* dmYResolution */ 0,
192 /* dmTTOption */ DMTT_SUBDEV
,
195 /* dmUnusedPadding */ 0,
196 /* dmBitsPerPel */ 0,
198 /* dmPelsHeight */ 0,
199 /* dmDisplayFlags */ 0,
200 /* dmDisplayFrequency */ 0
206 /* ppdfilename */ "default.ppd"
210 HANDLE PSDRV_Heap
= 0;
212 static HANDLE PSDRV_DefaultFont
= 0;
213 static LOGFONTA DefaultLogFont
= {
214 100, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
, 0, 0,
215 DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, ""
218 /*********************************************************************
221 * Initializes font metrics and registers driver. Called from GDI_Init()
224 BOOL WINAPI
PSDRV_Init( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
226 static int process_count
= 0;
228 TRACE("(0x%4x, 0x%08lx, %p)\n", hinst
, reason
, reserved
);
231 case DLL_PROCESS_ATTACH
:
232 if (!process_count
++) {
233 /* FIXME: return FALSE if we fail any of these steps */
234 PSDRV_Heap
= HeapCreate(0, 0x10000, 0);
235 PSDRV_GetFontMetrics();
236 PSDRV_DefaultFont
= CreateFontIndirectA(&DefaultLogFont
);
237 DRIVER_RegisterDriver( "WINEPS", &PSDRV_Funcs
);
240 case DLL_PROCESS_DETACH
:
241 if (!--process_count
) {
242 DeleteObject( PSDRV_DefaultFont
);
243 HeapDestroy( PSDRV_Heap
);
244 DRIVER_UnregisterDriver( "WINEPS" );
253 /**********************************************************************
256 static BOOL
PSDRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
257 LPCSTR output
, const DEVMODEA
* initData
)
259 PSDRV_PDEVICE
*physDev
;
263 /* If no device name was specified, retrieve the device name
264 * from the DEVMODE structure from the DC's physDev.
265 * (See CreateCompatibleDC) */
266 if ( !device
&& dc
->physDev
)
268 physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
269 device
= physDev
->Devmode
->dmPublic
.dmDeviceName
;
271 pi
= PSDRV_FindPrinterInfo(device
);
273 TRACE("(%s %s %s %p)\n", driver
, device
, output
, initData
);
275 if(!pi
) return FALSE
;
278 MESSAGE("To use WINEPS you need to install some AFM files.\n");
282 physDev
= (PSDRV_PDEVICE
*)HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
,
284 if (!physDev
) return FALSE
;
285 dc
->physDev
= physDev
;
289 physDev
->Devmode
= (PSDRV_DEVMODEA
*)HeapAlloc( PSDRV_Heap
, 0,
290 sizeof(PSDRV_DEVMODEA
) );
291 if(!physDev
->Devmode
) {
292 HeapFree( PSDRV_Heap
, 0, physDev
);
296 memcpy( physDev
->Devmode
, pi
->Devmode
, sizeof(PSDRV_DEVMODEA
) );
299 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)initData
, pi
);
303 devCaps
= HeapAlloc( PSDRV_Heap
, 0, sizeof(PSDRV_DevCaps
) );
304 memcpy(devCaps
, &PSDRV_DevCaps
, sizeof(PSDRV_DevCaps
));
306 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
) {
307 devCaps
->horzSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
/ 10;
308 devCaps
->vertSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
/ 10;
310 devCaps
->horzSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
/ 10;
311 devCaps
->vertSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
/ 10;
314 devCaps
->horzRes
= physDev
->pi
->ppd
->DefaultResolution
*
315 devCaps
->horzSize
/ 25.4;
316 devCaps
->vertRes
= physDev
->pi
->ppd
->DefaultResolution
*
317 devCaps
->vertSize
/ 25.4;
319 /* Are aspect[XY] and logPixels[XY] correct? */
320 /* Need to handle different res in x and y => fix ppd */
321 devCaps
->aspectX
= devCaps
->logPixelsX
=
322 physDev
->pi
->ppd
->DefaultResolution
;
323 devCaps
->aspectY
= devCaps
->logPixelsY
=
324 physDev
->pi
->ppd
->DefaultResolution
;
325 devCaps
->aspectXY
= (int)hypot( (double)devCaps
->aspectX
,
326 (double)devCaps
->aspectY
);
328 if(physDev
->pi
->ppd
->ColorDevice
) {
329 devCaps
->bitsPixel
= 8;
330 devCaps
->numColors
= 256;
331 /* FIXME are these values OK? */
336 dc
->w
.devCaps
= devCaps
;
338 dc
->w
.hVisRgn
= CreateRectRgn(0, 0, dc
->w
.devCaps
->horzRes
,
339 dc
->w
.devCaps
->vertRes
);
341 dc
->w
.hFont
= PSDRV_DefaultFont
;
342 physDev
->job
.output
= output
?
343 HEAP_strdupA( PSDRV_Heap
, 0, output
) :
344 HEAP_strdupA( PSDRV_Heap
, 0, "LPT1:" ); /* HACK */
345 physDev
->job
.hJob
= 0;
350 /**********************************************************************
353 static BOOL
PSDRV_DeleteDC( DC
*dc
)
355 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
359 HeapFree( PSDRV_Heap
, 0, physDev
->Devmode
);
360 HeapFree( PSDRV_Heap
, 0, physDev
->job
.output
);
361 HeapFree( PSDRV_Heap
, 0, (void *)dc
->w
.devCaps
);
362 HeapFree( PSDRV_Heap
, 0, physDev
);
371 /**********************************************************************
372 * PSDRV_FindPrinterInfo
374 PRINTERINFO
*PSDRV_FindPrinterInfo(LPCSTR name
)
376 static PRINTERINFO
*PSDRV_PrinterList
;
377 DWORD type
= REG_BINARY
, needed
, res
;
378 PRINTERINFO
*pi
= PSDRV_PrinterList
, **last
= &PSDRV_PrinterList
;
382 TRACE("'%s'\n", name
);
384 for( ; pi
; last
= &pi
->next
, pi
= pi
->next
) {
385 if(!strcmp(pi
->FriendlyName
, name
))
389 pi
= *last
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*pi
) );
390 pi
->FriendlyName
= HEAP_strdupA( PSDRV_Heap
, 0, name
);
391 res
= DrvGetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
, &type
,
394 if(res
== ERROR_INVALID_PRINTER_NAME
|| needed
!= sizeof(DefaultDevmode
)) {
395 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(DefaultDevmode
) );
396 memcpy(pi
->Devmode
, &DefaultDevmode
, sizeof(DefaultDevmode
) );
397 DrvSetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
,
398 REG_BINARY
, (LPBYTE
)&DefaultDevmode
, sizeof(DefaultDevmode
) );
400 /* need to do something here AddPrinter?? */
402 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, needed
);
403 DrvGetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
, &type
,
404 (LPBYTE
)pi
->Devmode
, needed
, &needed
);
407 PROFILE_GetWineIniString("psdrv", "ppdfile", "default.ppd",
408 pi
->Devmode
->dmDrvPrivate
.ppdFileName
, 256);
409 pi
->ppd
= PSDRV_ParsePPD(pi
->Devmode
->dmDrvPrivate
.ppdFileName
);
411 HeapFree(PSDRV_Heap
, 0, pi
->FriendlyName
);
412 HeapFree(PSDRV_Heap
, 0, pi
->Devmode
);
413 HeapFree(PSDRV_Heap
, 0, pi
);
415 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
416 pi
->Devmode
->dmDrvPrivate
.ppdFileName
);
423 for(font
= pi
->ppd
->InstalledFonts
; font
; font
= font
->next
) {
424 afm
= PSDRV_FindAFMinList(PSDRV_AFMFontList
, font
->Name
);
427 "Couldn't find AFM file for installed printer font '%s' - ignoring\n",
430 PSDRV_AddAFMtoList(&pi
->Fonts
, afm
);