DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / graphics / psdrv / init.c
blob99d81d8c909feb3a0bc26af84fa788fe7d6b693d
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 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 */
46 NULL, /* pEndPath */
47 PSDRV_EnumDeviceFonts, /* pEnumDeviceFonts */
48 PSDRV_Escape, /* pEscape */
49 NULL, /* pExcludeClipRect */
50 PSDRV_ExtDeviceMode, /* pExtDeviceMode */
51 NULL, /* pExtFloodFill */
52 PSDRV_ExtTextOut, /* pExtTextOut */
53 NULL, /* pFillPath */
54 NULL, /* pFillRgn */
55 NULL, /* pFlattenPath */
56 NULL, /* pFrameRgn */
57 PSDRV_GetCharWidth, /* pGetCharWidth */
58 NULL, /* pGetDCOrgEx */
59 NULL, /* pGetPixel */
60 PSDRV_GetTextExtentPoint, /* pGetTextExtentPoint */
61 PSDRV_GetTextMetrics, /* pGetTextMetrics */
62 NULL, /* pIntersectClipRect */
63 NULL, /* pInvertRgn */
64 PSDRV_LineTo, /* pLineTo */
65 NULL, /* pLoadOEMResource */
66 NULL, /* pMoveToEx */
67 NULL, /* pOffsetClipRgn */
68 NULL, /* pOffsetViewportOrg (optional) */
69 NULL, /* pOffsetWindowOrg (optional) */
70 NULL, /* pPaintRgn */
71 PSDRV_PatBlt, /* pPatBlt */
72 PSDRV_Pie, /* pPie */
73 NULL, /* pPolyBezier */
74 NULL, /* pPolyBezierTo */
75 NULL, /* pPolyDraw */
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 */
85 NULL, /* pSaveDC */
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 */
100 NULL, /* pSetROP2 */
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 = {
124 /* version */ 0,
125 /* technology */ DT_RASPRINTER,
126 /* horzSize */ 210,
127 /* vertSize */ 297,
128 /* horzRes */ 4961,
129 /* vertRes */ 7016,
130 /* bitsPixel */ 1,
131 /* planes */ 1,
132 /* numBrushes */ -1,
133 /* numPens */ 10,
134 /* numMarkers */ 0,
135 /* numFonts */ 39,
136 /* numColors */ 2,
137 /* pdeviceSize */ 0,
138 /* curveCaps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
139 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS |
140 CC_ROUNDRECT,
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 |
145 PC_INTERIORS,
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 */
151 /* aspectX */ 600,
152 /* aspectY */ 600,
153 /* aspectXY */ 848,
154 /* pad1 */ { 0 },
155 /* logPixelsX */ 600,
156 /* logPixelsY */ 600,
157 /* pad2 */ { 0 },
158 /* palette size */ 0,
159 /* ..etc */ 0, 0 };
161 static PSDRV_DEVMODEA DefaultDevmode =
163 { /* dmPublic */
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,
172 { /* u1 */
173 { /* s1 */
174 /* dmOrientation */ DMORIENT_PORTRAIT,
175 /* dmPaperSize */ DMPAPER_A4,
176 /* dmPaperLength */ 2969,
177 /* dmPaperWidth */ 2101
180 /* dmScale */ 100, /* ?? */
181 /* dmCopies */ 1,
182 /* dmDefaultSource */ DMBIN_AUTO,
183 /* dmPrintQuality */ 0,
184 /* dmColor */ DMCOLOR_MONOCHROME,
185 /* dmDuplex */ 0,
186 /* dmYResolution */ 0,
187 /* dmTTOption */ DMTT_SUBDEV,
188 /* dmCollate */ 0,
189 /* dmFormName */ "",
190 /* dmUnusedPadding */ 0,
191 /* dmBitsPerPel */ 0,
192 /* dmPelsWidth */ 0,
193 /* dmPelsHeight */ 0,
194 /* dmDisplayFlags */ 0,
195 /* dmDisplayFrequency */ 0
197 { /* dmDocPrivate */
198 0 /* dummy */
200 { /* dmDrvPrivate */
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 /*********************************************************************
214 * PSDRV_Init
216 * Initializes font metrics and registers driver. Called from GDI_Init()
219 BOOL PSDRV_Init(void)
221 TRACE("\n");
222 PSDRV_Heap = HeapCreate(0, 0x10000, 0);
223 PSDRV_GetFontMetrics();
224 PSDRV_DefaultFont = CreateFontIndirectA(&DefaultLogFont);
225 return DRIVER_RegisterDriver( "WINEPS", &PSDRV_Funcs );
228 /**********************************************************************
229 * PSDRV_CreateDC
231 static BOOL PSDRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
232 LPCSTR output, const DEVMODEA* initData )
234 PSDRV_PDEVICE *physDev;
235 PRINTERINFO *pi;
236 DeviceCaps *devCaps;
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;
252 if(!pi->Fonts) {
253 MESSAGE("To use WINEPS you need to install some AFM files.\n");
254 return FALSE;
257 physDev = (PSDRV_PDEVICE *)HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
258 sizeof(*physDev) );
259 if (!physDev) return FALSE;
260 dc->physDev = physDev;
262 physDev->pi = pi;
264 physDev->Devmode = (PSDRV_DEVMODEA *)HeapAlloc( PSDRV_Heap, 0,
265 sizeof(PSDRV_DEVMODEA) );
266 if(!physDev->Devmode) {
267 HeapFree( PSDRV_Heap, 0, physDev );
268 return FALSE;
271 memcpy( physDev->Devmode, pi->Devmode, sizeof(PSDRV_DEVMODEA) );
273 if(initData) {
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;
284 } else {
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? */
309 /* etc */
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;
321 return TRUE;
325 /**********************************************************************
326 * PSDRV_DeleteDC
328 static BOOL PSDRV_DeleteDC( DC *dc )
330 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
332 TRACE("\n");
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 );
338 dc->physDev = NULL;
340 return TRUE;
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;
354 FONTNAME *font;
355 AFM *afm;
357 TRACE("'%s'\n", name);
359 for( ; pi; last = &pi->next, pi = pi->next) {
360 if(!strcmp(pi->FriendlyName, name))
361 return pi;
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,
367 NULL, 0, &needed );
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?? */
376 } else {
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);
385 if(!pi->ppd) {
386 HeapFree(PSDRV_Heap, 0, pi->FriendlyName);
387 HeapFree(PSDRV_Heap, 0, pi->Devmode);
388 HeapFree(PSDRV_Heap, 0, pi);
389 *last = NULL;
390 MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
391 pi->Devmode->dmDrvPrivate.ppdFileName);
392 return NULL;
395 pi->next = NULL;
396 pi->Fonts = NULL;
398 for(font = pi->ppd->InstalledFonts; font; font = font->next) {
399 afm = PSDRV_FindAFMinList(PSDRV_AFMFontList, font->Name);
400 if(!afm) {
401 MESSAGE(
402 "Couldn't find AFM file for installed printer font '%s' - ignoring\n",
403 font->Name);
404 } else {
405 PSDRV_AddAFMtoList(&pi->Fonts, afm);
409 return pi;