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 */
58 NULL
, /* pGetDCOrgEx */
60 PSDRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
61 PSDRV_GetTextMetrics
, /* pGetTextMetrics */
62 NULL
, /* pIntersectClipRect */
63 NULL
, /* pInvertRgn */
64 PSDRV_LineTo
, /* pLineTo */
65 NULL
, /* pLoadOEMResource */
67 NULL
, /* pOffsetClipRgn */
68 NULL
, /* pOffsetViewportOrg (optional) */
69 NULL
, /* pOffsetWindowOrg (optional) */
71 PSDRV_PatBlt
, /* pPatBlt */
73 NULL
, /* pPolyBezier */
74 NULL
, /* pPolyBezierTo */
76 PSDRV_PolyPolygon
, /* pPolyPolygon */
77 PSDRV_PolyPolyline
, /* pPolyPolyline */
78 PSDRV_Polygon
, /* pPolygon */
79 PSDRV_Polyline
, /* pPolyline */
80 NULL
, /* pPolylineTo */
81 NULL
, /* pRealizePalette */
82 PSDRV_Rectangle
, /* pRectangle */
83 NULL
, /* pRestoreDC */
84 PSDRV_RoundRect
, /* pRoundRect */
86 NULL
, /* pScaleViewportExt (optional) */
87 NULL
, /* pScaleWindowExt (optional) */
88 NULL
, /* pSelectClipPath */
89 NULL
, /* pSelectClipRgn */
90 PSDRV_SelectObject
, /* pSelectObject */
91 NULL
, /* pSelectPalette */
92 PSDRV_SetBkColor
, /* pSetBkColor */
93 NULL
, /* pSetBkMode */
94 PSDRV_SetDeviceClipping
, /* pSetDeviceClipping */
95 NULL
, /* pSetDIBitsToDevice */
96 NULL
, /* pSetMapMode (optional) */
97 NULL
, /* pSetMapperFlags */
98 PSDRV_SetPixel
, /* pSetPixel */
99 NULL
, /* pSetPolyFillMode */
101 NULL
, /* pSetRelAbs */
102 NULL
, /* pSetStretchBltMode */
103 NULL
, /* pSetTextAlign */
104 NULL
, /* pSetTextCharacterExtra */
105 PSDRV_SetTextColor
, /* pSetTextColor */
106 NULL
, /* pSetTextJustification */
107 NULL
, /* pSetViewportExt (optional) */
108 NULL
, /* pSetViewportOrg (optional) */
109 NULL
, /* pSetWindowExt (optional) */
110 NULL
, /* pSetWindowOrg (optional) */
111 PSDRV_StartDoc
, /* pStartDoc */
112 PSDRV_StartPage
, /* pStartPage */
113 NULL
, /* pStretchBlt */
114 PSDRV_StretchDIBits
, /* pStretchDIBits */
115 NULL
, /* pStrokeAndFillPath */
116 NULL
, /* pStrokePath */
117 NULL
/* pWidenPath */
121 /* Default entries for devcaps */
123 static DeviceCaps PSDRV_DevCaps
= {
125 /* technology */ DT_RASPRINTER
,
138 /* curveCaps */ CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
|
139 CC_WIDE
| CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
|
141 /* lineCaps */ LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
142 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
,
143 /* polygoalnCaps */ PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
|
144 PC_SCANLINE
| PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
|
146 /* textCaps */ TC_CR_ANY
, /* psdrv 0x59f7 */
147 /* clipCaps */ CP_RECTANGLE
,
148 /* rasterCaps */ RC_BITBLT
| RC_BITMAP64
| RC_GDI20_OUTPUT
|
149 RC_DIBTODEV
| RC_STRETCHBLT
|
150 RC_STRETCHDIB
, /* psdrv 0x6e99 */
155 /* logPixelsX */ 600,
156 /* logPixelsY */ 600,
158 /* palette size */ 0,
161 static PSDRV_DEVMODEA DefaultDevmode
=
164 /* dmDeviceName */ "Wine PostScript Driver",
165 /* dmSpecVersion */ 0x30a,
166 /* dmDriverVersion */ 0x001,
167 /* dmSize */ sizeof(DEVMODEA
),
168 /* dmDriverExtra */ 0,
169 /* dmFields */ DM_ORIENTATION
| DM_PAPERSIZE
| DM_SCALE
|
170 DM_COPIES
| DM_DEFAULTSOURCE
| DM_COLOR
|
171 DM_DUPLEX
| DM_YRESOLUTION
| DM_TTOPTION
,
174 /* dmOrientation */ DMORIENT_PORTRAIT
,
175 /* dmPaperSize */ DMPAPER_A4
,
176 /* dmPaperLength */ 2969,
177 /* dmPaperWidth */ 2101
180 /* dmScale */ 100, /* ?? */
182 /* dmDefaultSource */ DMBIN_AUTO
,
183 /* dmPrintQuality */ 0,
184 /* dmColor */ DMCOLOR_MONOCHROME
,
186 /* dmYResolution */ 0,
187 /* dmTTOption */ DMTT_SUBDEV
,
190 /* dmUnusedPadding */ 0,
191 /* dmBitsPerPel */ 0,
193 /* dmPelsHeight */ 0,
194 /* dmDisplayFlags */ 0,
195 /* dmDisplayFrequency */ 0
201 /* ppdfilename */ "default.ppd"
205 HANDLE PSDRV_Heap
= 0;
207 static HANDLE PSDRV_DefaultFont
= 0;
208 static LOGFONTA DefaultLogFont
= {
209 100, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
, 0, 0,
210 DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, ""
213 /*********************************************************************
216 * Initializes font metrics and registers driver. Called from GDI_Init()
219 BOOL
PSDRV_Init(void)
222 PSDRV_Heap
= HeapCreate(0, 0x10000, 0);
223 PSDRV_GetFontMetrics();
224 PSDRV_DefaultFont
= CreateFontIndirectA(&DefaultLogFont
);
225 return DRIVER_RegisterDriver( "WINEPS", &PSDRV_Funcs
);
228 /**********************************************************************
231 static BOOL
PSDRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
232 LPCSTR output
, const DEVMODEA
* initData
)
234 PSDRV_PDEVICE
*physDev
;
238 /* If no device name was specified, retrieve the device name
239 * from the DEVMODE structure from the DC's physDev.
240 * (See CreateCompatibleDC) */
241 if ( !device
&& dc
->physDev
)
243 physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
244 device
= physDev
->Devmode
->dmPublic
.dmDeviceName
;
246 pi
= PSDRV_FindPrinterInfo(device
);
248 TRACE("(%s %s %s %p)\n", driver
, device
, output
, initData
);
250 if(!pi
) return FALSE
;
253 MESSAGE("To use WINEPS you need to install some AFM files.\n");
257 physDev
= (PSDRV_PDEVICE
*)HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
,
259 if (!physDev
) return FALSE
;
260 dc
->physDev
= physDev
;
264 physDev
->Devmode
= (PSDRV_DEVMODEA
*)HeapAlloc( PSDRV_Heap
, 0,
265 sizeof(PSDRV_DEVMODEA
) );
266 if(!physDev
->Devmode
) {
267 HeapFree( PSDRV_Heap
, 0, physDev
);
271 memcpy( physDev
->Devmode
, pi
->Devmode
, sizeof(PSDRV_DEVMODEA
) );
274 PSDRV_MergeDevmodes(physDev
->Devmode
, (PSDRV_DEVMODEA
*)initData
, pi
);
278 devCaps
= HeapAlloc( PSDRV_Heap
, 0, sizeof(PSDRV_DevCaps
) );
279 memcpy(devCaps
, &PSDRV_DevCaps
, sizeof(PSDRV_DevCaps
));
281 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_PORTRAIT
) {
282 devCaps
->horzSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
/ 10;
283 devCaps
->vertSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
/ 10;
285 devCaps
->horzSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperLength
/ 10;
286 devCaps
->vertSize
= physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperWidth
/ 10;
289 devCaps
->horzRes
= physDev
->pi
->ppd
->DefaultResolution
*
290 devCaps
->horzSize
/ 25.4;
291 devCaps
->vertRes
= physDev
->pi
->ppd
->DefaultResolution
*
292 devCaps
->vertSize
/ 25.4;
294 /* Are aspect[XY] and logPixels[XY] correct? */
295 /* Need to handle different res in x and y => fix ppd */
296 devCaps
->aspectX
= devCaps
->logPixelsX
=
297 physDev
->pi
->ppd
->DefaultResolution
;
298 devCaps
->aspectY
= devCaps
->logPixelsY
=
299 physDev
->pi
->ppd
->DefaultResolution
;
300 devCaps
->aspectXY
= (int)hypot( (double)devCaps
->aspectX
,
301 (double)devCaps
->aspectY
);
303 if(physDev
->pi
->ppd
->ColorDevice
) {
304 devCaps
->bitsPixel
= 8;
305 devCaps
->numColors
= 256;
306 /* FIXME are these values OK? */
311 dc
->w
.devCaps
= devCaps
;
313 dc
->w
.hVisRgn
= CreateRectRgn(0, 0, dc
->w
.devCaps
->horzRes
,
314 dc
->w
.devCaps
->vertRes
);
316 dc
->w
.hFont
= PSDRV_DefaultFont
;
317 physDev
->job
.output
= output
?
318 HEAP_strdupA( PSDRV_Heap
, 0, output
) :
319 HEAP_strdupA( PSDRV_Heap
, 0, "LPT1:" ); /* HACK */
320 physDev
->job
.hJob
= 0;
325 /**********************************************************************
328 static BOOL
PSDRV_DeleteDC( DC
*dc
)
330 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
334 HeapFree( PSDRV_Heap
, 0, physDev
->Devmode
);
335 HeapFree( PSDRV_Heap
, 0, physDev
->job
.output
);
336 HeapFree( PSDRV_Heap
, 0, (void *)dc
->w
.devCaps
);
337 HeapFree( PSDRV_Heap
, 0, physDev
);
346 /**********************************************************************
347 * PSDRV_FindPrinterInfo
349 PRINTERINFO
*PSDRV_FindPrinterInfo(LPCSTR name
)
351 static PRINTERINFO
*PSDRV_PrinterList
;
352 DWORD type
= REG_BINARY
, needed
, res
;
353 PRINTERINFO
*pi
= PSDRV_PrinterList
, **last
= &PSDRV_PrinterList
;
357 TRACE("'%s'\n", name
);
359 for( ; pi
; last
= &pi
->next
, pi
= pi
->next
) {
360 if(!strcmp(pi
->FriendlyName
, name
))
364 pi
= *last
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*pi
) );
365 pi
->FriendlyName
= HEAP_strdupA( PSDRV_Heap
, 0, name
);
366 res
= DrvGetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
, &type
,
369 if(res
== ERROR_INVALID_PRINTER_NAME
|| needed
!= sizeof(DefaultDevmode
)) {
370 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, sizeof(DefaultDevmode
) );
371 memcpy(pi
->Devmode
, &DefaultDevmode
, sizeof(DefaultDevmode
) );
372 DrvSetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
,
373 REG_BINARY
, (LPBYTE
)&DefaultDevmode
, sizeof(DefaultDevmode
) );
375 /* need to do something here AddPrinter?? */
377 pi
->Devmode
= HeapAlloc( PSDRV_Heap
, 0, needed
);
378 DrvGetPrinterData16((LPSTR
)name
, (LPSTR
)INT_PD_DEFAULT_DEVMODE
, &type
,
379 (LPBYTE
)pi
->Devmode
, needed
, &needed
);
382 PROFILE_GetWineIniString("psdrv", "ppdfile", "default.ppd",
383 pi
->Devmode
->dmDrvPrivate
.ppdFileName
, 256);
384 pi
->ppd
= PSDRV_ParsePPD(pi
->Devmode
->dmDrvPrivate
.ppdFileName
);
386 HeapFree(PSDRV_Heap
, 0, pi
->FriendlyName
);
387 HeapFree(PSDRV_Heap
, 0, pi
->Devmode
);
388 HeapFree(PSDRV_Heap
, 0, pi
);
390 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
391 pi
->Devmode
->dmDrvPrivate
.ppdFileName
);
398 for(font
= pi
->ppd
->InstalledFonts
; font
; font
= font
->next
) {
399 afm
= PSDRV_FindAFMinList(PSDRV_AFMFontList
, font
->Name
);
402 "Couldn't find AFM file for installed printer font '%s' - ignoring\n",
405 PSDRV_AddAFMtoList(&pi
->Fonts
, afm
);