Implement DocumentProperties, DeviceCapabilities, beginnings of
[wine/wine64.git] / graphics / win16drv / init.c
blob303eb7e6426c08324f4d949a4ca405228b309527
1 /*
2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
5 * 1998 Huw Davies
6 */
8 #include <string.h>
9 #include <ctype.h>
10 #include "win16drv.h"
11 #include "gdi.h"
12 #include "bitmap.h"
13 #include "heap.h"
14 #include "font.h"
15 #include "options.h"
16 #include "xmalloc.h"
17 #include "debug.h"
18 #include "dc.h"
20 DEFAULT_DEBUG_CHANNEL(win16drv)
22 #define SUPPORT_REALIZED_FONTS 1
23 #include "pshpack1.h"
24 typedef struct
26 SHORT nSize;
27 SEGPTR lpindata;
28 SEGPTR lpFont;
29 SEGPTR lpXForm;
30 SEGPTR lpDrawMode;
31 } EXTTEXTDATA, *LPEXTTEXTDATA;
32 #include "poppack.h"
34 SEGPTR win16drv_SegPtr_TextXForm;
35 LPTEXTXFORM16 win16drv_TextXFormP;
36 SEGPTR win16drv_SegPtr_DrawMode;
37 LPDRAWMODE win16drv_DrawModeP;
40 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
41 LPCSTR output, const DEVMODEA* initData );
42 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
43 SEGPTR lpInData, SEGPTR lpOutData );
45 static const DC_FUNCTIONS WIN16DRV_Funcs =
47 NULL, /* pAbortDoc */
48 NULL, /* pArc */
49 NULL, /* pBitBlt */
50 NULL, /* pBitmapBits */
51 NULL, /* pChord */
52 NULL, /* pCreateBitmap */
53 WIN16DRV_CreateDC, /* pCreateDC */
54 NULL, /* pCreateDIBSection */
55 NULL, /* pCreateDIBSection16 */
56 NULL, /* pDeleteDC */
57 NULL, /* pDeleteObject */
58 NULL, /* pDeviceCapabilities */
59 WIN16DRV_Ellipse, /* pEllipse */
60 NULL, /* pEndDoc */
61 NULL, /* pEndPage */
62 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
63 WIN16DRV_Escape, /* pEscape */
64 NULL, /* pExcludeClipRect */
65 NULL, /* pExtDeviceMode */
66 NULL, /* pExtFloodFill */
67 WIN16DRV_ExtTextOut, /* pExtTextOut */
68 NULL, /* pFillRgn */
69 NULL, /* pFrameRgn */
70 WIN16DRV_GetCharWidth, /* pGetCharWidth */
71 NULL, /* pGetPixel */
72 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
73 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
74 NULL, /* pIntersectClipRect */
75 NULL, /* pInvertRgn */
76 WIN16DRV_LineTo, /* pLineTo */
77 NULL, /* pLoadOEMResource */
78 WIN16DRV_MoveToEx, /* pMoveToEx */
79 NULL, /* pOffsetClipRgn */
80 NULL, /* pOffsetViewportOrgEx */
81 NULL, /* pOffsetWindowOrgEx */
82 NULL, /* pPaintRgn */
83 WIN16DRV_PatBlt, /* pPatBlt */
84 NULL, /* pPie */
85 NULL, /* pPolyPolygon */
86 NULL, /* pPolyPolyline */
87 WIN16DRV_Polygon, /* pPolygon */
88 WIN16DRV_Polyline, /* pPolyline */
89 NULL, /* pPolyBezier */
90 NULL, /* pRealizePalette */
91 WIN16DRV_Rectangle, /* pRectangle */
92 NULL, /* pRestoreDC */
93 NULL, /* pRoundRect */
94 NULL, /* pSaveDC */
95 NULL, /* pScaleViewportExtEx */
96 NULL, /* pScaleWindowExtEx */
97 NULL, /* pSelectClipRgn */
98 WIN16DRV_SelectObject, /* pSelectObject */
99 NULL, /* pSelectPalette */
100 NULL, /* pSetBkColor */
101 NULL, /* pSetBkMode */
102 NULL, /* pSetDeviceClipping */
103 NULL, /* pSetDIBitsToDevice */
104 NULL, /* pSetMapMode */
105 NULL, /* pSetMapperFlags */
106 NULL, /* pSetPixel */
107 NULL, /* pSetPolyFillMode */
108 NULL, /* pSetROP2 */
109 NULL, /* pSetRelAbs */
110 NULL, /* pSetStretchBltMode */
111 NULL, /* pSetTextAlign */
112 NULL, /* pSetTextCharacterExtra */
113 NULL, /* pSetTextColor */
114 NULL, /* pSetTextJustification */
115 NULL, /* pSetViewportExtEx */
116 NULL, /* pSetViewportOrgEx */
117 NULL, /* pSetWindowExtEx */
118 NULL, /* pSetWindowOrgEx */
119 NULL, /* pStartDoc */
120 NULL, /* pStartPage */
121 NULL, /* pStretchBlt */
122 NULL /* pStretchDIBits */
129 /**********************************************************************
130 * WIN16DRV_Init
132 BOOL WIN16DRV_Init(void)
134 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
138 /* Tempory functions, for initialising structures */
139 /* These values should be calculated, not hardcoded */
140 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
142 lpTextXForm->txfHeight = 0x0001;
143 lpTextXForm->txfWidth = 0x000c;
144 lpTextXForm->txfEscapement = 0x0000;
145 lpTextXForm->txfOrientation = 0x0000;
146 lpTextXForm->txfWeight = 0x0190;
147 lpTextXForm->txfItalic = 0x00;
148 lpTextXForm->txfUnderline = 0x00;
149 lpTextXForm->txfStrikeOut = 0x00;
150 lpTextXForm->txfOutPrecision = 0x02;
151 lpTextXForm->txfClipPrecision = 0x01;
152 lpTextXForm->txfAccelerator = 0x0001;
153 lpTextXForm->txfOverhang = 0x0000;
157 void InitDrawMode(LPDRAWMODE lpDrawMode)
159 lpDrawMode->Rop2 = 0x000d;
160 lpDrawMode->bkMode = 0x0001;
161 lpDrawMode->bkColor = 0x3fffffff;
162 lpDrawMode->TextColor = 0x20000000;
163 lpDrawMode->TBreakExtra = 0x0000;
164 lpDrawMode->BreakExtra = 0x0000;
165 lpDrawMode->BreakErr = 0x0000;
166 lpDrawMode->BreakRem = 0x0000;
167 lpDrawMode->BreakCount = 0x0000;
168 lpDrawMode->CharExtra = 0x0000;
169 lpDrawMode->LbkColor = 0x00ffffff;
170 lpDrawMode->LTextColor = 0x00000000;
173 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
174 const DEVMODEA* initData )
176 LOADED_PRINTER_DRIVER *pLPD;
177 WORD wRet;
178 DeviceCaps *printerDevCaps;
179 int nPDEVICEsize;
180 PDEVICE_HEADER *pPDH;
181 WIN16DRV_PDEVICE *physDev;
182 char printerEnabled[20];
183 PROFILE_GetWineIniString( "wine", "printer", "off",
184 printerEnabled, sizeof(printerEnabled) );
185 if (lstrcmpiA(printerEnabled,"on"))
187 MSG("Printing disabled in wine.conf or .winerc file\n");
188 MSG("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
189 return FALSE;
192 TRACE(win16drv, "In creatdc for (%s,%s,%s) initData 0x%p\n",
193 driver, device, output, initData);
195 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( SystemHeap, 0, sizeof(*physDev) );
196 if (!physDev) return FALSE;
197 dc->physDev = physDev;
199 pLPD = LoadPrinterDriver(driver);
200 if (pLPD == NULL)
202 WARN(win16drv, "Failed to find printer driver\n");
203 HeapFree( SystemHeap, 0, physDev );
204 return FALSE;
206 TRACE(win16drv, "windevCreateDC pLPD 0x%p\n", pLPD);
208 /* Now Get the device capabilities from the printer driver */
210 printerDevCaps = (DeviceCaps *) xmalloc(sizeof(DeviceCaps));
211 memset(printerDevCaps, 0, sizeof(DeviceCaps));
213 /* Get GDIINFO which is the same as a DeviceCaps structure */
214 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
216 /* Add this to the DC */
217 dc->w.devCaps = printerDevCaps;
218 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
219 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
221 TRACE(win16drv, "Got devcaps width %d height %d bits %d planes %d\n",
222 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
223 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
225 /* Now we allocate enough memory for the PDEVICE structure */
226 /* The size of this varies between printer drivers */
227 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
228 /* be accessable from 16 bit code */
229 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
231 /* TTD Shouldn't really do pointer arithmetic on segment points */
232 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
233 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
234 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
236 /* Set up the header */
237 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
238 pPDH->pLPD = pLPD;
240 TRACE(win16drv, "PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
242 /* Now get the printer driver to initialise this data */
243 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
245 physDev->FontInfo = NULL;
246 physDev->BrushInfo = NULL;
247 physDev->PenInfo = NULL;
248 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
249 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
251 InitTextXForm(win16drv_TextXFormP);
253 /* TTD Lots more to do here */
254 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
255 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
257 InitDrawMode(win16drv_DrawModeP);
259 return TRUE;
262 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
263 INT width, INT height, DWORD rop )
266 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
267 BOOL bRet = 0;
269 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
270 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
272 return bRet;
275 * Escape (GDI.38)
277 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
278 SEGPTR lpInData, SEGPTR lpOutData )
280 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
281 int nRet = 0;
283 /* We should really process the nEscape parameter, but for now just
284 pass it all to the driver */
285 if (dc != NULL && physDev->segptrPDEVICE != 0)
287 switch(nEscape)
289 case ENABLEPAIRKERNING:
290 FIXME(win16drv,"Escape: ENABLEPAIRKERNING ignored.\n");
291 nRet = 1;
292 break;
293 case GETPAIRKERNTABLE:
294 FIXME(win16drv,"Escape: GETPAIRKERNTABLE ignored.\n");
295 nRet = 0;
296 break;
297 case SETABORTPROC: {
298 /* FIXME: The AbortProc should be called:
299 - After every write to printer port or spool file
300 - Several times when no more disk space
301 - Before every metafile record when GDI does banding
304 /* save the callback address and call Control with hdc as lpInData */
305 HDC16 *seghdc = SEGPTR_NEW(HDC16);
306 *seghdc = dc->hSelf;
307 dc->w.lpfnPrint = (FARPROC16)lpInData;
308 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
309 SEGPTR_GET(seghdc), lpOutData);
310 SEGPTR_FREE(seghdc);
311 break;
314 case NEXTBAND:
316 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
318 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
319 SEGPTR_GET(newInData), lpOutData);
320 SEGPTR_FREE(newInData);
321 break;
324 case GETEXTENDEDTEXTMETRICS:
326 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
328 textData->nSize = cbInput;
329 textData->lpindata = lpInData;
330 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
331 textData->lpXForm = win16drv_SegPtr_TextXForm;
332 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
333 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
334 SEGPTR_GET(textData), lpOutData);
335 SEGPTR_FREE(textData);
337 break;
338 case STARTDOC:
339 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
340 lpInData, lpOutData);
341 if (nRet != -1)
343 HDC *tmpHdc = SEGPTR_NEW(HDC);
345 #define SETPRINTERDC SETABORTPROC
347 *tmpHdc = dc->hSelf;
348 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
349 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
350 SEGPTR_FREE(tmpHdc);
352 break;
353 default:
354 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
355 lpInData, lpOutData);
356 break;
359 else
360 WARN(win16drv, "Escape(nEscape = %04x) - ???\n", nEscape);
361 return nRet;