Added correct implementation of GetCaps, changed Play and Stop handling
[wine/multimedia.git] / graphics / psdrv / init.c
blobc4257265b0e66d8c3d6eed243187a7b8142a7c9e
1 /*
2 * PostScript driver initialization functions
4 * Copyright 1998 Huw D M Davies
6 */
8 #include "windows.h"
9 #include "gdi.h"
10 #include "psdrv.h"
11 #include "debug.h"
12 #include "heap.h"
13 #include "winreg.h"
14 #include "print.h"
15 #include "winerror.h"
17 static BOOL32 PSDRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
18 LPCSTR output, const DEVMODE16* initData );
19 static BOOL32 PSDRV_DeleteDC( DC *dc );
21 static const DC_FUNCTIONS PSDRV_Funcs =
23 PSDRV_Arc, /* pArc */
24 NULL, /* pBitBlt */
25 NULL, /* pBitmapBits */
26 PSDRV_Chord, /* pChord */
27 NULL, /* pCreateBitmap */
28 PSDRV_CreateDC, /* pCreateDC */
29 PSDRV_DeleteDC, /* pDeleteDC */
30 NULL, /* pDeleteObject */
31 PSDRV_Ellipse, /* pEllipse */
32 PSDRV_EnumDeviceFonts, /* pEnumDeviceFonts */
33 PSDRV_Escape, /* pEscape */
34 NULL, /* pExcludeClipRect */
35 NULL, /* pExcludeVisRect */
36 NULL, /* pExtFloodFill */
37 PSDRV_ExtTextOut, /* pExtTextOut */
38 PSDRV_GetCharWidth, /* pGetCharWidth */
39 NULL, /* pGetPixel */
40 PSDRV_GetTextExtentPoint, /* pGetTextExtentPoint */
41 PSDRV_GetTextMetrics, /* pGetTextMetrics */
42 NULL, /* pIntersectClipRect */
43 NULL, /* pIntersectVisRect */
44 PSDRV_LineTo, /* pLineTo */
45 PSDRV_MoveToEx, /* pMoveToEx */
46 NULL, /* pOffsetClipRgn */
47 NULL, /* pOffsetViewportOrg (optional) */
48 NULL, /* pOffsetWindowOrg (optional) */
49 NULL, /* pPaintRgn */
50 NULL, /* pPatBlt */
51 PSDRV_Pie, /* pPie */
52 PSDRV_PolyPolygon, /* pPolyPolygon */
53 PSDRV_PolyPolyline, /* pPolyPolyline */
54 PSDRV_Polygon, /* pPolygon */
55 PSDRV_Polyline, /* pPolyline */
56 NULL, /* pPolyBezier */
57 NULL, /* pRealizePalette */
58 PSDRV_Rectangle, /* pRectangle */
59 NULL, /* pRestoreDC */
60 PSDRV_RoundRect, /* pRoundRect */
61 NULL, /* pSaveDC */
62 NULL, /* pScaleViewportExt (optional) */
63 NULL, /* pScaleWindowExt (optional) */
64 NULL, /* pSelectClipRgn */
65 PSDRV_SelectObject, /* pSelectObject */
66 NULL, /* pSelectPalette */
67 PSDRV_SetBkColor, /* pSetBkColor */
68 NULL, /* pSetBkMode */
69 NULL, /* pSetDeviceClipping */
70 NULL, /* pSetDIBitsToDevice */
71 NULL, /* pSetMapMode (optional) */
72 NULL, /* pSetMapperFlags */
73 PSDRV_SetPixel, /* pSetPixel */
74 NULL, /* pSetPolyFillMode */
75 NULL, /* pSetROP2 */
76 NULL, /* pSetRelAbs */
77 NULL, /* pSetStretchBltMode */
78 NULL, /* pSetTextAlign */
79 NULL, /* pSetTextCharacterExtra */
80 PSDRV_SetTextColor, /* pSetTextColor */
81 NULL, /* pSetTextJustification */
82 NULL, /* pSetViewportExt (optional) */
83 NULL, /* pSetViewportOrg (optional) */
84 NULL, /* pSetWindowExt (optional) */
85 NULL, /* pSetWindowOrg (optional) */
86 NULL, /* pStretchBlt */
87 PSDRV_StretchDIBits /* pStretchDIBits */
91 /* Default entries for devcaps */
93 static DeviceCaps PSDRV_DevCaps = {
94 /* version */ 0,
95 /* technology */ DT_RASPRINTER,
96 /* horzSize */ 210,
97 /* vertSize */ 297,
98 /* horzRes */ 4961,
99 /* vertRes */ 7016,
100 /* bitsPixel */ 1,
101 /* planes */ 1,
102 /* numBrushes */ -1,
103 /* numPens */ 10,
104 /* numMarkers */ 0,
105 /* numFonts */ 39,
106 /* numColors */ 2,
107 /* pdeviceSize */ 0,
108 /* curveCaps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
109 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS |
110 CC_ROUNDRECT,
111 /* lineCaps */ LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
112 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
113 /* polygoalnCaps */ PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
114 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED |
115 PC_INTERIORS,
116 /* textCaps */ TC_CR_ANY, /* psdrv 0x59f7 */
117 /* clipCaps */ CP_RECTANGLE,
118 /* rasterCaps */ RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
119 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT |
120 RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
121 /* psdrv 0x6e99 */
122 /* aspectX */ 600,
123 /* aspectY */ 600,
124 /* aspectXY */ 848,
125 /* pad1 */ { 0 },
126 /* logPixelsX */ 600,
127 /* logPixelsY */ 600,
128 /* pad2 */ { 0 },
129 /* palette size */ 0,
130 /* ..etc */ 0, 0 };
132 static PSDRV_DEVMODE16 DefaultDevmode =
134 { /* dmPublic */
135 /* dmDeviceName */ "Wine PostScript Driver",
136 /* dmSpecVersion */ 0x30a,
137 /* dmDriverVersion */ 0x001,
138 /* dmSize */ sizeof(DEVMODE16),
139 /* dmDriverExtra */ 0,
140 /* dmFields */ DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH |
141 DM_PAPERWIDTH | DM_SCALE | DM_COPIES |
142 DM_DEFAULTSOURCE | DM_COLOR | DM_DUPLEX |
143 DM_YRESOLUTION | DM_TTOPTION,
144 /* dmOrientation */ DMORIENT_PORTRAIT,
145 /* dmPaperSize */ DMPAPER_A4,
146 /* dmPaperLength */ 2969,
147 /* dmPaperWidth */ 2101,
148 /* dmScale */ 100, /* ?? */
149 /* dmCopies */ 1,
150 /* dmDefaultSource */ DMBIN_AUTO,
151 /* dmPrintQuality */ 0,
152 /* dmColor */ DMCOLOR_MONOCHROME,
153 /* dmDuplex */ 0,
154 /* dmYResolution */ 0,
155 /* dmTTOption */ DMTT_SUBDEV,
156 /* dmCollate */ 0,
157 /* dmFormName */ "",
158 /* dmUnusedPadding */ 0,
159 /* dmBitsPerPel */ 0,
160 /* dmPelsWidth */ 0,
161 /* dmPelsHeight */ 0,
162 /* dmDisplayFlags */ 0,
163 /* dmDisplayFrequency */ 0
165 { /* dmDocPrivate */
167 { /* dmDrvPrivate */
168 /* ppdfilename */ "default.ppd"
172 HANDLE32 PSDRV_Heap = 0;
174 static HANDLE32 PSDRV_DefaultFont = 0;
175 static LOGFONT32A DefaultLogFont = {
176 100, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 0, 0,
177 DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, ""
180 /*********************************************************************
181 * PSDRV_Init
183 * Initializes font metrics and registers driver. Called from GDI_Init()
186 BOOL32 PSDRV_Init(void)
188 TRACE(psdrv, "\n");
189 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
190 PSDRV_GetFontMetrics();
191 PSDRV_DefaultFont = CreateFontIndirect32A(&DefaultLogFont);
192 return DRIVER_RegisterDriver( "WINEPS", &PSDRV_Funcs );
195 /**********************************************************************
196 * PSDRV_CreateDC
198 static BOOL32 PSDRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
199 LPCSTR output, const DEVMODE16* initData )
201 PSDRV_PDEVICE *physDev;
202 PRINTERINFO *pi = PSDRV_FindPrinterInfo(device);
203 DeviceCaps *devCaps;
205 TRACE(psdrv, "(%s %s %s %p)\n", driver, device, output, initData);
207 if(!pi) return FALSE;
209 if(!pi->Fonts) {
210 MSG("To use WINEPS you need to install some AFM files.\n");
211 return FALSE;
214 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
215 sizeof(*physDev) );
216 if (!physDev) return FALSE;
217 dc->physDev = physDev;
219 physDev->pi = pi;
221 physDev->Devmode = (PSDRV_DEVMODE16 *)HeapAlloc( PSDRV_Heap, 0,
222 sizeof(PSDRV_DEVMODE16) );
223 if(!physDev->Devmode) {
224 HeapFree( PSDRV_Heap, 0, physDev );
225 return FALSE;
228 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODE16) );
230 if(initData) {
231 PSDRV_MergeDevmodes(physDev->Devmode, (PSDRV_DEVMODE16 *)initData, pi);
235 devCaps = HeapAlloc( PSDRV_Heap, 0, sizeof(PSDRV_DevCaps) );
236 memcpy(devCaps, &PSDRV_DevCaps, sizeof(PSDRV_DevCaps));
238 if(physDev->Devmode->dmPublic.dmOrientation == DMORIENT_PORTRAIT) {
239 devCaps->horzSize = physDev->Devmode->dmPublic.dmPaperWidth / 10;
240 devCaps->vertSize = physDev->Devmode->dmPublic.dmPaperLength / 10;
241 } else {
242 devCaps->horzSize = physDev->Devmode->dmPublic.dmPaperLength / 10;
243 devCaps->vertSize = physDev->Devmode->dmPublic.dmPaperWidth / 10;
246 devCaps->horzRes = physDev->pi->ppd->DefaultResolution *
247 devCaps->horzSize / 25.4;
248 devCaps->vertRes = physDev->pi->ppd->DefaultResolution *
249 devCaps->vertSize / 25.4;
251 /* Are aspect[XY] and logPixels[XY] correct? */
252 /* Need to handle different res in x and y => fix ppd */
253 devCaps->aspectX = devCaps->logPixelsX =
254 physDev->pi->ppd->DefaultResolution;
255 devCaps->aspectY = devCaps->logPixelsY =
256 physDev->pi->ppd->DefaultResolution;
257 devCaps->aspectXY = (int)hypot( (double)devCaps->aspectX,
258 (double)devCaps->aspectY );
260 if(physDev->pi->ppd->ColorDevice) {
261 devCaps->bitsPixel = 8;
262 devCaps->numColors = 256;
263 /* FIXME are these values OK? */
266 /* etc */
268 dc->w.devCaps = devCaps;
270 dc->w.hVisRgn = CreateRectRgn32(0, 0, dc->w.devCaps->horzRes,
271 dc->w.devCaps->vertRes);
273 dc->w.hFont = PSDRV_DefaultFont;
274 physDev->job.output = HEAP_strdupA( PSDRV_Heap, 0, output );
275 physDev->job.hJob = 0;
276 return TRUE;
280 /**********************************************************************
281 * PSDRV_DeleteDC
283 static BOOL32 PSDRV_DeleteDC( DC *dc )
285 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
287 TRACE(psdrv, "\n");
289 HeapFree( PSDRV_Heap, 0, physDev->Devmode );
290 HeapFree( PSDRV_Heap, 0, physDev->job.output );
291 HeapFree( PSDRV_Heap, 0, (void *)dc->w.devCaps );
292 HeapFree( PSDRV_Heap, 0, physDev );
293 dc->physDev = NULL;
295 return TRUE;
301 /**********************************************************************
302 * PSDRV_FindPrinterInfo
304 PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
306 static PRINTERINFO *PSDRV_PrinterList;
307 DWORD type = REG_BINARY, needed, res;
308 PRINTERINFO *pi = PSDRV_PrinterList, **last = &PSDRV_PrinterList;
309 FONTNAME *font;
310 AFM *afm;
312 TRACE(psdrv, "'%s'\n", name);
314 for( ; pi; last = &pi->next, pi = pi->next) {
315 if(!strcmp(pi->FriendlyName, name))
316 return pi;
319 pi = *last = HeapAlloc( PSDRV_Heap, 0, sizeof(*pi) );
320 pi->FriendlyName = HEAP_strdupA( PSDRV_Heap, 0, name );
321 res = DrvGetPrinterData((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
322 NULL, 0, &needed );
324 if(res == ERROR_INVALID_PRINTER_NAME) {
325 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, sizeof(DefaultDevmode) );
326 memcpy(pi->Devmode, &DefaultDevmode, sizeof(DefaultDevmode) );
327 DrvSetPrinterData((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE,
328 REG_BINARY, (LPBYTE)&DefaultDevmode, sizeof(DefaultDevmode) );
330 /* need to do something here AddPrinter?? */
331 } else {
332 pi->Devmode = HeapAlloc( PSDRV_Heap, 0, needed );
333 DrvGetPrinterData((LPSTR)name, (LPSTR)INT_PD_DEFAULT_DEVMODE, &type,
334 (LPBYTE)pi->Devmode, needed, &needed);
337 pi->ppd = PSDRV_ParsePPD(pi->Devmode->dmDrvPrivate.ppdFileName);
338 if(!pi->ppd) {
339 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
340 HeapFree(PSDRV_Heap, 0, pi->Devmode);
341 HeapFree(PSDRV_Heap, 0, pi);
342 *last = NULL;
343 MSG("Couldn't find PPD file '%s', expect a crash now!\n",
344 pi->Devmode->dmDrvPrivate.ppdFileName);
345 return NULL;
348 pi->next = NULL;
349 pi->Fonts = NULL;
351 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
352 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
353 if(!afm) {
354 MSG(
355 "Couldn't find AFM file for installed printer font '%s' - ignoring\n",
356 font->Name);
357 } else {
358 PSDRV_AddAFMtoList(&pi->Fonts, afm);
362 return pi;