2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "win16drv/win16drv.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(win16drv);
35 #define SUPPORT_REALIZED_FONTS 1
44 } EXTTEXTDATA, *LPEXTTEXTDATA;
47 SEGPTR win16drv_SegPtr_TextXForm;
48 LPTEXTXFORM16 win16drv_TextXFormP;
49 SEGPTR win16drv_SegPtr_DrawMode;
50 LPDRAWMODE win16drv_DrawModeP;
53 static BOOL WIN16DRV_CreateDC( DC *dc, PHYSDEV *pdev, LPCSTR driver, LPCSTR device,
54 LPCSTR output, const DEVMODEA* initData );
55 static INT WIN16DRV_GetDeviceCaps( PHYSDEV dev, INT cap );
56 static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
57 INT out_count, LPVOID out_data );
59 static const DC_FUNCTIONS WIN16DRV_Funcs =
62 NULL, /* pAbortPath */
66 NULL, /* pBeginPath */
68 NULL, /* pChoosePixelFormat */
70 NULL, /* pCloseFigure */
71 NULL, /* pCreateBitmap */
72 WIN16DRV_CreateDC, /* pCreateDC */
73 NULL, /* pCreateDIBSection */
74 NULL, /* pDeleteBitmap */
76 NULL, /* pDescribePixelFormat */
77 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
78 WIN16DRV_Ellipse, /* pEllipse */
82 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
83 NULL, /* pExcludeClipRect */
84 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
85 WIN16DRV_ExtEscape, /* pExtEscape */
86 NULL, /* pExtFloodFill */
87 NULL, /* pExtSelectClipRgn */
88 WIN16DRV_ExtTextOut, /* pExtTextOut */
91 NULL, /* pFlattenPath */
93 NULL, /* pGetBitmapBits */
94 WIN16DRV_GetCharWidth, /* pGetCharWidth */
95 NULL, /* pGetDCOrgEx */
96 NULL, /* pGetDIBColorTable */
97 NULL, /* pGetDIBits */
98 WIN16DRV_GetDeviceCaps, /* pGetDeviceCaps */
99 NULL, /* pGetDeviceGammaRamp */
100 NULL, /* pGetNearestColor */
101 NULL, /* pGetPixel */
102 NULL, /* pGetPixelFormat */
103 NULL, /* pGetSystemPaletteEntries */
104 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
105 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
106 NULL, /* pIntersectClipRect */
107 NULL, /* pInvertRgn */
108 WIN16DRV_LineTo, /* pLineTo */
110 NULL, /* pOffsetClipRgn */
111 NULL, /* pOffsetViewportOrgEx */
112 NULL, /* pOffsetWindowOrgEx */
113 NULL, /* pPaintRgn */
114 WIN16DRV_PatBlt, /* pPatBlt */
116 NULL, /* pPolyBezier */
117 NULL, /* pPolyBezierTo */
118 NULL, /* pPolyDraw */
119 NULL, /* pPolyPolygon */
120 NULL, /* pPolyPolyline */
121 WIN16DRV_Polygon, /* pPolygon */
122 WIN16DRV_Polyline, /* pPolyline */
123 NULL, /* pPolylineTo */
124 NULL, /* pRealizeDefaultPalette */
125 NULL, /* pRealizePalette */
126 WIN16DRV_Rectangle, /* pRectangle */
128 NULL, /* pRestoreDC */
129 NULL, /* pRoundRect */
131 NULL, /* pScaleViewportExtEx */
132 NULL, /* pScaleWindowExtEx */
133 WIN16DRV_SelectBitmap, /* pSelectBitmap */
134 WIN16DRV_SelectBrush, /* pSelectBrush */
135 NULL, /* pSelectClipPath */
136 WIN16DRV_SelectFont, /* pSelectFont */
137 NULL, /* pSelectPalette */
138 WIN16DRV_SelectPen, /* pSelectPen */
139 NULL, /* pSetBitmapBits */
140 NULL, /* pSetBkColor */
141 NULL, /* pSetBkMode */
142 NULL, /* pSetDCOrg */
143 NULL, /* pSetDIBColorTable */
144 NULL, /* pSetDIBits */
145 NULL, /* pSetDIBitsToDevice */
146 NULL, /* pSetDeviceClipping */
147 NULL, /* pSetDeviceGammaRamp */
148 NULL, /* pSetMapMode */
149 NULL, /* pSetMapperFlags */
150 NULL, /* pSetPixel */
151 NULL, /* pSetPixelFormat */
152 NULL, /* pSetPolyFillMode */
154 NULL, /* pSetRelAbs */
155 NULL, /* pSetStretchBltMode */
156 NULL, /* pSetTextAlign */
157 NULL, /* pSetTextCharacterExtra */
158 NULL, /* pSetTextColor */
159 NULL, /* pSetTextJustification */
160 NULL, /* pSetViewportExtEx */
161 NULL, /* pSetViewportOrgEx */
162 NULL, /* pSetWindowExtEx */
163 NULL, /* pSetWindowOrgEx */
164 NULL, /* pStartDoc */
165 NULL, /* pStartPage */
166 NULL, /* pStretchBlt */
167 NULL, /* pStretchDIBits */
168 NULL, /* pStrokeAndFillPath */
169 NULL, /* pStrokePath */
170 NULL, /* pSwapBuffers */
171 NULL /* pWidenPath */
175 /**********************************************************************
178 const DC_FUNCTIONS *WIN16DRV_Init(void)
180 static int enabled = -1;
184 char printerEnabled[20];
188 strcpy( printerEnabled, "off" );
189 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\wine", &hkey))
191 DWORD type, count = sizeof(printerEnabled);
192 RegQueryValueExA(hkey, "printer", 0, &type, printerEnabled, &count);
195 enabled = !strcasecmp( printerEnabled, "on" );
198 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
199 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
203 return enabled ? &WIN16DRV_Funcs : NULL;
206 /* Tempory functions, for initialising structures */
207 /* These values should be calculated, not hardcoded */
208 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
210 lpTextXForm->txfHeight = 0x0001;
211 lpTextXForm->txfWidth = 0x000c;
212 lpTextXForm->txfEscapement = 0x0000;
213 lpTextXForm->txfOrientation = 0x0000;
214 lpTextXForm->txfWeight = 0x0190;
215 lpTextXForm->txfItalic = 0x00;
216 lpTextXForm->txfUnderline = 0x00;
217 lpTextXForm->txfStrikeOut = 0x00;
218 lpTextXForm->txfOutPrecision = 0x02;
219 lpTextXForm->txfClipPrecision = 0x01;
220 lpTextXForm->txfAccelerator = 0x0001;
221 lpTextXForm->txfOverhang = 0x0000;
225 void InitDrawMode(LPDRAWMODE lpDrawMode)
227 lpDrawMode->Rop2 = 0x000d;
228 lpDrawMode->bkMode = 0x0001;
229 lpDrawMode->bkColor = 0x3fffffff;
230 lpDrawMode->TextColor = 0x20000000;
231 lpDrawMode->TBreakExtra = 0x0000;
232 lpDrawMode->BreakExtra = 0x0000;
233 lpDrawMode->BreakErr = 0x0000;
234 lpDrawMode->BreakRem = 0x0000;
235 lpDrawMode->BreakCount = 0x0000;
236 lpDrawMode->CharExtra = 0x0000;
237 lpDrawMode->LbkColor = 0x00ffffff;
238 lpDrawMode->LTextColor = 0x00000000;
239 lpDrawMode->ICMCXform = 0; /* ? */
240 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
241 lpDrawMode->eMiterLimit = 1;
244 BOOL WIN16DRV_CreateDC( DC *dc, PHYSDEV *pdev, LPCSTR driver, LPCSTR device, LPCSTR output,
245 const DEVMODEA* initData )
247 LOADED_PRINTER_DRIVER *pLPD;
250 PDEVICE_HEADER *pPDH;
251 WIN16DRV_PDEVICE *physDev;
253 TRACE("In creatdc for (%s,%s,%s) initData %p\n",
254 driver, device, output, initData);
256 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
257 if (!physDev) return FALSE;
258 *pdev = (PHYSDEV)physDev;
259 physDev->hdc = dc->hSelf;
261 physDev->org.x = physDev->org.y = 0;
263 pLPD = LoadPrinterDriver(driver);
266 WARN("Failed to find printer driver\n");
267 HeapFree( GetProcessHeap(), 0, physDev );
270 TRACE("windevCreateDC pLPD %p\n", pLPD);
272 /* Now Get the device capabilities from the printer driver */
273 memset( &physDev->DevCaps, 0, sizeof(physDev->DevCaps) );
274 if(!output) output = "LPT1:";
276 /* Get GDIINFO which is the same as a DeviceCaps structure */
277 wRet = PRTDRV_Enable(&physDev->DevCaps, GETGDIINFO, device, driver, output,NULL);
279 /* Add this to the DC */
280 dc->bitsPerPixel = physDev->DevCaps.bitsPixel;
282 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
283 physDev->DevCaps.horzRes, physDev->DevCaps.vertRes,
284 physDev->DevCaps.bitsPixel, physDev->DevCaps.planes);
286 /* Now we allocate enough memory for the PDEVICE structure */
287 /* The size of this varies between printer drivers */
288 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
289 /* be accessable from 16 bit code */
290 nPDEVICEsize = physDev->DevCaps.pdeviceSize + sizeof(PDEVICE_HEADER);
292 /* TTD Shouldn't really do pointer arithmetic on segment points */
293 physDev->segptrPDEVICE = K32WOWGlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
294 *((BYTE *)MapSL(physDev->segptrPDEVICE)+0) = 'N';
295 *((BYTE *)MapSL(physDev->segptrPDEVICE)+1) = 'B';
297 /* Set up the header */
298 pPDH = (PDEVICE_HEADER *)((BYTE*)MapSL(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
301 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
303 /* Now get the printer driver to initialise this data */
304 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
306 physDev->FontInfo = NULL;
307 physDev->BrushInfo = NULL;
308 physDev->PenInfo = NULL;
309 win16drv_SegPtr_TextXForm = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
310 win16drv_TextXFormP = MapSL(win16drv_SegPtr_TextXForm);
312 InitTextXForm(win16drv_TextXFormP);
314 /* TTD Lots more to do here */
315 win16drv_SegPtr_DrawMode = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
316 win16drv_DrawModeP = MapSL(win16drv_SegPtr_DrawMode);
318 InitDrawMode(win16drv_DrawModeP);
323 BOOL WIN16DRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
326 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
329 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
330 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
336 /***********************************************************************
337 * WIN16DRV_GetDeviceCaps
339 static INT WIN16DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
341 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
342 if (cap >= PHYSICALWIDTH || (cap % 2))
344 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
347 return *((WORD *)&physDev->DevCaps + (cap / 2));
351 /***********************************************************************
354 static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
355 INT out_count, LPVOID out_data )
358 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
361 /* We should really process the nEscape parameter, but for now just
362 pass it all to the driver */
363 if (dc != NULL && physDev->segptrPDEVICE != 0)
367 case ENABLEPAIRKERNING:
368 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
371 case GETPAIRKERNTABLE:
372 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
376 /* FIXME: The AbortProc should be called:
377 - After every write to printer port or spool file
378 - Several times when no more disk space
379 - Before every metafile record when GDI does banding
382 /* Call Control with hdc as lpInData */
383 HDC16 *seghdc = SEGPTR_NEW(HDC16);
385 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
386 SEGPTR_GET(seghdc), lpOutData);
393 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
395 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
396 SEGPTR_GET(newInData), lpOutData);
397 SEGPTR_FREE(newInData);
401 case GETEXTENDEDTEXTMETRICS:
403 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
405 textData->nSize = cbInput;
406 textData->lpindata = lpInData;
407 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
408 textData->lpXForm = win16drv_SegPtr_TextXForm;
409 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
410 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
411 SEGPTR_GET(textData), lpOutData);
412 SEGPTR_FREE(textData);
417 /* lpInData is not necessarily \0 terminated so make it so */
418 char *cp = SEGPTR_ALLOC(cbInput + 1);
419 memcpy(cp, MapSL(lpInData), cbInput);
422 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
423 SEGPTR_GET(cp), lpOutData);
427 HDC *tmpHdc = SEGPTR_NEW(HDC);
429 #define SETPRINTERDC SETABORTPROC
432 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
433 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
439 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
440 lpInData, lpOutData);
445 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
448 /* FIXME: should convert args to SEGPTR and redo all the above */
449 FIXME("temporarily broken, please fix\n");