2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
17 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(win16drv)
22 #define SUPPORT_REALIZED_FONTS 1
31 } EXTTEXTDATA, *LPEXTTEXTDATA;
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 =
50 NULL, /* pBitmapBits */
52 NULL, /* pCreateBitmap */
53 WIN16DRV_CreateDC, /* pCreateDC */
54 NULL, /* pCreateDIBSection */
55 NULL, /* pCreateDIBSection16 */
57 NULL, /* pDeleteObject */
58 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
59 WIN16DRV_Ellipse, /* pEllipse */
62 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
63 WIN16DRV_Escape, /* pEscape */
64 NULL, /* pExcludeClipRect */
65 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
66 NULL, /* pExtFloodFill */
67 WIN16DRV_ExtTextOut, /* pExtTextOut */
70 WIN16DRV_GetCharWidth, /* pGetCharWidth */
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 */
83 WIN16DRV_PatBlt, /* pPatBlt */
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 */
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 */
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 /**********************************************************************
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;
178 DeviceCaps *printerDevCaps;
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 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
188 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
192 TRACE("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);
202 WARN("Failed to find printer driver\n");
203 HeapFree( SystemHeap, 0, physDev );
206 TRACE("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 if(!output) output = "LPT1:";
214 /* Get GDIINFO which is the same as a DeviceCaps structure */
215 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
217 /* Add this to the DC */
218 dc->w.devCaps = printerDevCaps;
219 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
220 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
222 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
223 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
224 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
226 /* Now we allocate enough memory for the PDEVICE structure */
227 /* The size of this varies between printer drivers */
228 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
229 /* be accessable from 16 bit code */
230 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
232 /* TTD Shouldn't really do pointer arithmetic on segment points */
233 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
234 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
235 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
237 /* Set up the header */
238 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
241 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
243 /* Now get the printer driver to initialise this data */
244 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
246 physDev->FontInfo = NULL;
247 physDev->BrushInfo = NULL;
248 physDev->PenInfo = NULL;
249 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
250 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
252 InitTextXForm(win16drv_TextXFormP);
254 /* TTD Lots more to do here */
255 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
256 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
258 InitDrawMode(win16drv_DrawModeP);
263 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
264 INT width, INT height, DWORD rop )
267 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
270 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
271 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
278 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
279 SEGPTR lpInData, SEGPTR lpOutData )
281 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
284 /* We should really process the nEscape parameter, but for now just
285 pass it all to the driver */
286 if (dc != NULL && physDev->segptrPDEVICE != 0)
290 case ENABLEPAIRKERNING:
291 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
294 case GETPAIRKERNTABLE:
295 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
299 /* FIXME: The AbortProc should be called:
300 - After every write to printer port or spool file
301 - Several times when no more disk space
302 - Before every metafile record when GDI does banding
305 /* Call Control with hdc as lpInData */
306 HDC16 *seghdc = SEGPTR_NEW(HDC16);
308 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
309 SEGPTR_GET(seghdc), lpOutData);
316 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
318 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
319 SEGPTR_GET(newInData), lpOutData);
320 SEGPTR_FREE(newInData);
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);
339 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
340 lpInData, lpOutData);
343 HDC *tmpHdc = SEGPTR_NEW(HDC);
345 #define SETPRINTERDC SETABORTPROC
348 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
349 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
354 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
355 lpInData, lpOutData);
360 WARN("Escape(nEscape = %04x) - ???\n", nEscape);