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 PSDRV_Chord
, /* pChord */
35 NULL
, /* pCloseFigure */
36 NULL
, /* pCreateBitmap */
37 PSDRV_CreateDC
, /* pCreateDC */
38 NULL
, /* pCreateDIBSection */
39 NULL
, /* pCreateDIBSection16 */
40 PSDRV_DeleteDC
, /* pDeleteDC */
41 NULL
, /* pDeleteObject */
42 PSDRV_DeviceCapabilities
, /* pDeviceCapabilities */
43 PSDRV_Ellipse
, /* pEllipse */
44 PSDRV_EndDoc
, /* pEndDoc */
45 PSDRV_EndPage
, /* pEndPage */
47 PSDRV_EnumDeviceFonts
, /* pEnumDeviceFonts */
48 PSDRV_Escape
, /* pEscape */
49 NULL
, /* pExcludeClipRect */
50 PSDRV_ExtDeviceMode
, /* pExtDeviceMode */
51 NULL
, /* pExtFloodFill */
52 PSDRV_ExtTextOut
, /* pExtTextOut */
55 NULL
, /* pFlattenPath */
57 PSDRV_GetCharWidth
, /* pGetCharWidth */
59 PSDRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
60 PSDRV_GetTextMetrics
, /* pGetTextMetrics */
61 NULL
, /* pIntersectClipRect */
62 NULL
, /* pInvertRgn */
63 PSDRV_LineTo
, /* pLineTo */
64 NULL
, /* pLoadOEMResource */
66 NULL
, /* pOffsetClipRgn */
67 NULL
, /* pOffsetViewportOrg (optional) */
68 NULL
, /* pOffsetWindowOrg (optional) */
70 PSDRV_PatBlt
, /* pPatBlt */
72 NULL
, /* pPolyBezier */
73 NULL
, /* pPolyBezierTo */
75 PSDRV_PolyPolygon
, /* pPolyPolygon */
76 PSDRV_PolyPolyline
, /* pPolyPolyline */
77 PSDRV_Polygon
, /* pPolygon */
78 PSDRV_Polyline
, /* pPolyline */
79 NULL
, /* pPolylineTo */
80 NULL
, /* pRealizePalette */
81 PSDRV_Rectangle
, /* pRectangle */
82 NULL
, /* pRestoreDC */
83 PSDRV_RoundRect
, /* pRoundRect */
85 NULL
, /* pScaleViewportExt (optional) */
86 NULL
, /* pScaleWindowExt (optional) */
87 NULL
, /* pSelectClipPath */
88 NULL
, /* pSelectClipRgn */
89 PSDRV_SelectObject
, /* pSelectObject */
90 NULL
, /* pSelectPalette */
91 PSDRV_SetBkColor
, /* pSetBkColor */
92 NULL
, /* pSetBkMode */
93 PSDRV_SetDeviceClipping
, /* pSetDeviceClipping */
94 NULL
, /* pSetDIBitsToDevice */
95 NULL
, /* pSetMapMode (optional) */
96 NULL
, /* pSetMapperFlags */
97 PSDRV_SetPixel
, /* pSetPixel */
98 NULL
, /* pSetPolyFillMode */
100 NULL
, /* pSetRelAbs */
101 NULL
, /* pSetStretchBltMode */
102 NULL
, /* pSetTextAlign */
103 NULL
, /* pSetTextCharacterExtra */
104 PSDRV_SetTextColor
, /* pSetTextColor */
105 NULL
, /* pSetTextJustification */
106 NULL
, /* pSetViewportExt (optional) */
107 NULL
, /* pSetViewportOrg (optional) */
108 NULL
, /* pSetWindowExt (optional) */
109 NULL
, /* pSetWindowOrg (optional) */
110 PSDRV_StartDoc
, /* pStartDoc */
111 PSDRV_StartPage
, /* pStartPage */
112 NULL
, /* pStretchBlt */
113 PSDRV_StretchDIBits
, /* pStretchDIBits */
114 NULL
, /* pStrokeAndFillPath */
115 NULL
, /* pStrokePath */
116 NULL
/* pWidenPath */
120 /* Default entries for devcaps */
122 static DeviceCaps PSDRV_DevCaps
= {
124 /* technology */ DT_RASPRINTER
,
137 /* curveCaps */ CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
|
138 CC_WIDE
| CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
|
140 /* lineCaps */ LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
141 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
,
142 /* polygoalnCaps */ PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
|
143 PC_SCANLINE
| PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
|
145 /* textCaps */ TC_CR_ANY
, /* psdrv 0x59f7 */
146 /* clipCaps */ CP_RECTANGLE
,
147 /* rasterCaps */ RC_BITBLT
| RC_BITMAP64
| RC_GDI20_OUTPUT
|
148 RC_DIBTODEV
| RC_STRETCHBLT
|
149 RC_STRETCHDIB
, /* psdrv 0x6e99 */
154 /* logPixelsX */ 600,
155 /* logPixelsY */ 600,
157 /* palette size */ 0,
160 static PSDRV_DEVMODEA DefaultDevmode
=
163 /* dmDeviceName */ "Wine PostScript Driver",
164 /* dmSpecVersion */ 0x30a,
165 /* dmDriverVersion */ 0x001,
166 /* dmSize */ sizeof(DEVMODEA
),
167 /* dmDriverExtra */ 0,
168 /* dmFields */ DM_ORIENTATION
| DM_PAPERSIZE
| DM_SCALE
|
169 DM_COPIES
| DM_DEFAULTSOURCE
| DM_COLOR
|
170 DM_DUPLEX
| DM_YRESOLUTION
| DM_TTOPTION
,
173 /* dmOrientation */ DMORIENT_PORTRAIT
,
174 /* dmPaperSize */ DMPAPER_A4
,
175 /* dmPaperLength */ 2969,
176 /* dmPaperWidth */ 2101
179 /* dmScale */ 100, /* ?? */
181 /* dmDefaultSource */ DMBIN_AUTO
,
182 /* dmPrintQuality */ 0,
183 /* dmColor */ DMCOLOR_MONOCHROME
,
185 /* dmYResolution */ 0,
186 /* dmTTOption */ DMTT_SUBDEV
,
189 /* dmUnusedPadding */ 0,
190 /* dmBitsPerPel */ 0,
192 /* dmPelsHeight */ 0,
193 /* dmDisplayFlags */ 0,
194 /* dmDisplayFrequency */ 0
200 /* ppdfilename */ "default.ppd"
204 HANDLE PSDRV_Heap
= 0;
206 static HANDLE PSDRV_DefaultFont
= 0;
207 static LOGFONTA DefaultLogFont
= {
208 100, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
, 0, 0,
209 DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, ""
212 /*********************************************************************
215 * Initializes font metrics and registers driver. Called from GDI_Init()
218 BOOL
PSDRV_Init(void)
221 PSDRV_Heap
= HeapCreate(0, 0x10000, 0);
222 PSDRV_GetFontMetrics();
223 PSDRV_DefaultFont
= CreateFontIndirectA(&DefaultLogFont
);
224 return DRIVER_RegisterDriver( "WINEPS", &PSDRV_Funcs
);
227 /**********************************************************************
230 static BOOL
PSDRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
231 LPCSTR output
, const DEVMODEA
* initData
)
233 PSDRV_PDEVICE
*physDev
;
237 /* If no device name was specified, retrieve the device name
238 * from the DEVMODE structure from the DC's physDev.
239 * (See CreateCompatibleDC) */
240 if ( !device
&& dc
->physDev
)
242 physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
243 device
= physDev
->Devmode
->dmPublic
.dmDeviceName
;
245 pi
= PSDRV_FindPrinterInfo(device
);
247 TRACE("(%s %s %s %p)\n", driver
, device
, output
, initData
);
249 if(!pi
) return FALSE
;
252 MESSAGE("To use WINEPS you need to install some AFM files.\n");
256 physDev
= (PSDRV_PDEVICE
*)HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
,
258 if (!physDev
) return FALSE
;
259 dc
->physDev
= physDev
;
263 physDev
->Devmode
= (PSDRV_DEVMODEA
*)HeapAlloc( PSDRV_Heap
, 0,
264 sizeof(PSDRV_DEVMODEA
) );
265 if(!physDev
->Devmode
) {
266 HeapFree( PSDRV_Heap
, 0, physDev
);
270 memcpy( physDev
->Devmode
, pi
->Devmode
, sizeof(PSDRV_DEVMODEA
) );
273 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)initData
, pi
);
277 devCaps
= HeapAlloc( PSDRV_Heap
, 0, sizeof(PSDRV_DevCaps
) );
278 memcpy(devCaps
, &PSDRV_DevCaps
, sizeof(PSDRV_DevCaps
));
280 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
) {
281 devCaps
->horzSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
/ 10;
282 devCaps
->vertSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
/ 10;
284 devCaps
->horzSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
/ 10;
285 devCaps
->vertSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
/ 10;
288 devCaps
->horzRes
= physDev
->pi
->ppd
->DefaultResolution
*
289 devCaps
->horzSize
/ 25.4;
290 devCaps
->vertRes
= physDev
->pi
->ppd
->DefaultResolution
*
291 devCaps
->vertSize
/ 25.4;
293 /* Are aspect[XY] and logPixels[XY] correct? */
294 /* Need to handle different res in x and y => fix ppd */
295 devCaps
->aspectX
= devCaps
->logPixelsX
=
296 physDev
->pi
->ppd
->DefaultResolution
;
297 devCaps
->aspectY
= devCaps
->logPixelsY
=
298 physDev
->pi
->ppd
->DefaultResolution
;
299 devCaps
->aspectXY
= (int)hypot( (double)devCaps
->aspectX
,
300 (double)devCaps
->aspectY
);
302 if(physDev
->pi
->ppd
->ColorDevice
) {
303 devCaps
->bitsPixel
= 8;
304 devCaps
->numColors
= 256;
305 /* FIXME are these values OK? */
310 dc
->w
.devCaps
= devCaps
;
312 dc
->w
.hVisRgn
= CreateRectRgn(0, 0, dc
->w
.devCaps
->horzRes
,
313 dc
->w
.devCaps
->vertRes
);
315 dc
->w
.hFont
= PSDRV_DefaultFont
;
316 physDev
->job
.output
= output
?
317 HEAP_strdupA( PSDRV_Heap
, 0, output
) :
318 HEAP_strdupA( PSDRV_Heap
, 0, "LPT1:" ); /* HACK */
319 physDev
->job
.hJob
= 0;
324 /**********************************************************************
327 static BOOL
PSDRV_DeleteDC( DC
*dc
)
329 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
333 HeapFree( PSDRV_Heap
, 0, physDev
->Devmode
);
334 HeapFree( PSDRV_Heap
, 0, physDev
->job
.output
);
335 HeapFree( PSDRV_Heap
, 0, (void *)dc
->w
.devCaps
);
336 HeapFree( PSDRV_Heap
, 0, physDev
);
345 /**********************************************************************
346 * PSDRV_FindPrinterInfo
348 PRINTERINFO
*PSDRV_FindPrinterInfo(LPCSTR name
)
350 static PRINTERINFO
*PSDRV_PrinterList
;
351 DWORD type
= REG_BINARY
, needed
, res
;
352 PRINTERINFO
*pi
= PSDRV_PrinterList
, **last
= &PSDRV_PrinterList
;
356 TRACE("'%s'\n", name
);
358 for( ; pi
; last
= &pi
->next
, pi
= pi
->next
) {
359 if(!strcmp(pi
->FriendlyName
, name
))
363 pi
= *last
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*pi
) );
364 pi
->FriendlyName
= HEAP_strdupA( PSDRV_Heap
, 0, name
);
365 res
= DrvGetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
, &type
,
368 if(res
== ERROR_INVALID_PRINTER_NAME
|| needed
!= sizeof(DefaultDevmode
)) {
369 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(DefaultDevmode
) );
370 memcpy(pi
->Devmode
, &DefaultDevmode
, sizeof(DefaultDevmode
) );
371 DrvSetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
,
372 REG_BINARY
, (LPBYTE
)&DefaultDevmode
, sizeof(DefaultDevmode
) );
374 /* need to do something here AddPrinter?? */
376 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, needed
);
377 DrvGetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
, &type
,
378 (LPBYTE
)pi
->Devmode
, needed
, &needed
);
381 PROFILE_GetWineIniString("psdrv", "ppdfile", "default.ppd",
382 pi
->Devmode
->dmDrvPrivate
.ppdFileName
, 256);
383 pi
->ppd
= PSDRV_ParsePPD(pi
->Devmode
->dmDrvPrivate
.ppdFileName
);
385 HeapFree(PSDRV_Heap
, 0, pi
->FriendlyName
);
386 HeapFree(PSDRV_Heap
, 0, pi
->Devmode
);
387 HeapFree(PSDRV_Heap
, 0, pi
);
389 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
390 pi
->Devmode
->dmDrvPrivate
.ppdFileName
);
397 for(font
= pi
->ppd
->InstalledFonts
; font
; font
= font
->next
) {
398 afm
= PSDRV_FindAFMinList(PSDRV_AFMFontList
, font
->Name
);
401 "Couldn't find AFM file for installed printer font '%s' - ignoring\n",
404 PSDRV_AddAFMtoList(&pi
->Fonts
, afm
);