Spelling fixes.
[wine.git] / dlls / wineps / init.c
blob6e9956a07e7c05a717e5c40c2ba336009739d2de
1 /*
2 * PostScript driver initialization functions
4 * Copyright 1998 Huw D M Davies
6 */
7 #include <string.h>
9 #include "gdi.h"
10 #include "psdrv.h"
11 #include "debugtools.h"
12 #include "heap.h"
13 #include "winreg.h"
14 #include "winspool.h"
15 #include "winerror.h"
16 #include "options.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 =
26 NULL, /* pAbortDoc */
27 NULL, /* pAbortPath */
28 NULL, /* pAngleArc */
29 PSDRV_Arc, /* pArc */
30 NULL, /* pArcTo */
31 NULL, /* pBeginPath */
32 NULL, /* pBitBlt */
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 */
48 NULL, /* pEndPath */
49 PSDRV_EnumDeviceFonts, /* pEnumDeviceFonts */
50 PSDRV_Escape, /* pEscape */
51 NULL, /* pExcludeClipRect */
52 PSDRV_ExtDeviceMode, /* pExtDeviceMode */
53 NULL, /* pExtFloodFill */
54 PSDRV_ExtTextOut, /* pExtTextOut */
55 NULL, /* pFillPath */
56 NULL, /* pFillRgn */
57 NULL, /* pFlattenPath */
58 NULL, /* pFrameRgn */
59 PSDRV_GetCharWidth, /* pGetCharWidth */
60 NULL, /* pGetDCOrgEx */
61 NULL, /* pGetPixel */
62 NULL, /* pGetPixelFormat */
63 PSDRV_GetTextExtentPoint, /* pGetTextExtentPoint */
64 PSDRV_GetTextMetrics, /* pGetTextMetrics */
65 NULL, /* pIntersectClipRect */
66 NULL, /* pInvertRgn */
67 PSDRV_LineTo, /* pLineTo */
68 NULL, /* pLoadOEMResource */
69 NULL, /* pMoveToEx */
70 NULL, /* pOffsetClipRgn */
71 NULL, /* pOffsetViewportOrg (optional) */
72 NULL, /* pOffsetWindowOrg (optional) */
73 NULL, /* pPaintRgn */
74 PSDRV_PatBlt, /* pPatBlt */
75 PSDRV_Pie, /* pPie */
76 NULL, /* pPolyBezier */
77 NULL, /* pPolyBezierTo */
78 NULL, /* pPolyDraw */
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 */
88 NULL, /* pSaveDC */
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 */
104 NULL, /* pSetROP2 */
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 = {
129 /* version */ 0,
130 /* technology */ DT_RASPRINTER,
131 /* horzSize */ 210,
132 /* vertSize */ 297,
133 /* horzRes */ 4961,
134 /* vertRes */ 7016,
135 /* bitsPixel */ 1,
136 /* planes */ 1,
137 /* numBrushes */ -1,
138 /* numPens */ 10,
139 /* numMarkers */ 0,
140 /* numFonts */ 39,
141 /* numColors */ 2,
142 /* pdeviceSize */ 0,
143 /* curveCaps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
144 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS |
145 CC_ROUNDRECT,
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 |
150 PC_INTERIORS,
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 */
156 /* aspectX */ 600,
157 /* aspectY */ 600,
158 /* aspectXY */ 848,
159 /* pad1 */ { 0 },
160 /* logPixelsX */ 600,
161 /* logPixelsY */ 600,
162 /* pad2 */ { 0 },
163 /* palette size */ 0,
164 /* ..etc */ 0, 0 };
166 static PSDRV_DEVMODEA DefaultDevmode =
168 { /* dmPublic */
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,
177 { /* u1 */
178 { /* s1 */
179 /* dmOrientation */ DMORIENT_PORTRAIT,
180 /* dmPaperSize */ DMPAPER_A4,
181 /* dmPaperLength */ 2969,
182 /* dmPaperWidth */ 2101
185 /* dmScale */ 100, /* ?? */
186 /* dmCopies */ 1,
187 /* dmDefaultSource */ DMBIN_AUTO,
188 /* dmPrintQuality */ 0,
189 /* dmColor */ DMCOLOR_MONOCHROME,
190 /* dmDuplex */ 0,
191 /* dmYResolution */ 0,
192 /* dmTTOption */ DMTT_SUBDEV,
193 /* dmCollate */ 0,
194 /* dmFormName */ "",
195 /* dmUnusedPadding */ 0,
196 /* dmBitsPerPel */ 0,
197 /* dmPelsWidth */ 0,
198 /* dmPelsHeight */ 0,
199 /* dmDisplayFlags */ 0,
200 /* dmDisplayFrequency */ 0
202 { /* dmDocPrivate */
203 0 /* dummy */
205 { /* dmDrvPrivate */
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 /*********************************************************************
219 * PSDRV_Init
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);
230 switch(reason) {
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 );
239 break;
240 case DLL_PROCESS_DETACH:
241 if (!--process_count) {
242 DeleteObject( PSDRV_DefaultFont );
243 HeapDestroy( PSDRV_Heap );
244 DRIVER_UnregisterDriver( "WINEPS" );
246 break;
249 return TRUE;
253 /**********************************************************************
254 * PSDRV_CreateDC
256 static BOOL PSDRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
257 LPCSTR output, const DEVMODEA* initData )
259 PSDRV_PDEVICE *physDev;
260 PRINTERINFO *pi;
261 DeviceCaps *devCaps;
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;
277 if(!pi->Fonts) {
278 MESSAGE("To use WINEPS you need to install some AFM files.\n");
279 return FALSE;
282 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
283 sizeof(*physDev) );
284 if (!physDev) return FALSE;
285 dc->physDev = physDev;
287 physDev->pi = pi;
289 physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0,
290 sizeof(PSDRV_DEVMODEA) );
291 if(!physDev->Devmode) {
292 HeapFree( PSDRV_Heap, 0, physDev );
293 return FALSE;
296 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) );
298 if(initData) {
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;
309 } else {
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? */
334 /* etc */
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;
346 return TRUE;
350 /**********************************************************************
351 * PSDRV_DeleteDC
353 static BOOL PSDRV_DeleteDC( DC *dc )
355 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
357 TRACE("\n");
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 );
363 dc->physDev = NULL;
365 return TRUE;
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;
379 FONTNAME *font;
380 AFM *afm;
382 TRACE("'%s'\n", name);
384 for( ; pi; last = &pi->next, pi = pi->next) {
385 if(!strcmp(pi->FriendlyName, name))
386 return pi;
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,
392 NULL, 0, &needed );
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?? */
401 } else {
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);
410 if(!pi->ppd) {
411 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
412 HeapFree(PSDRV_Heap, 0, pi->Devmode);
413 HeapFree(PSDRV_Heap, 0, pi);
414 *last = NULL;
415 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
416 pi->Devmode->dmDrvPrivate.ppdFileName);
417 return NULL;
420 pi->next = NULL;
421 pi->Fonts = NULL;
423 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
424 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
425 if(!afm) {
426 MESSAGE(
427 "Couldn't find AFM file for installed printer font '%s' - ignoring\n",
428 font->Name);
429 } else {
430 PSDRV_AddAFMtoList(&pi->Fonts, afm);
434 return pi;