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, 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, /* pBitmapBits */
69 NULL, /* pChoosePixelFormat */
71 NULL, /* pCloseFigure */
72 NULL, /* pCreateBitmap */
73 WIN16DRV_CreateDC, /* pCreateDC */
74 NULL, /* pCreateDIBSection */
76 NULL, /* pDeleteObject */
77 NULL, /* pDescribePixelFormat */
78 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
79 WIN16DRV_Ellipse, /* pEllipse */
83 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
84 NULL, /* pExcludeClipRect */
85 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
86 WIN16DRV_ExtEscape, /* pExtEscape */
87 NULL, /* pExtFloodFill */
88 NULL, /* pExtSelectClipRgn */
89 WIN16DRV_ExtTextOut, /* pExtTextOut */
92 NULL, /* pFlattenPath */
94 WIN16DRV_GetCharWidth, /* pGetCharWidth */
95 NULL, /* pGetDCOrgEx */
96 NULL, /* pGetDIBColorTable */
97 NULL, /* pGetDIBits */
98 WIN16DRV_GetDeviceCaps, /* pGetDeviceCaps */
99 NULL, /* pGetDeviceGammaRamp */
100 NULL, /* pGetPixel */
101 NULL, /* pGetPixelFormat */
102 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
103 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
104 NULL, /* pIntersectClipRect */
105 NULL, /* pInvertRgn */
106 WIN16DRV_LineTo, /* pLineTo */
108 NULL, /* pOffsetClipRgn */
109 NULL, /* pOffsetViewportOrgEx */
110 NULL, /* pOffsetWindowOrgEx */
111 NULL, /* pPaintRgn */
112 WIN16DRV_PatBlt, /* pPatBlt */
114 NULL, /* pPolyBezier */
115 NULL, /* pPolyBezierTo */
116 NULL, /* pPolyDraw */
117 NULL, /* pPolyPolygon */
118 NULL, /* pPolyPolyline */
119 WIN16DRV_Polygon, /* pPolygon */
120 WIN16DRV_Polyline, /* pPolyline */
121 NULL, /* pPolylineTo */
122 NULL, /* pRealizePalette */
123 WIN16DRV_Rectangle, /* pRectangle */
125 NULL, /* pRestoreDC */
126 NULL, /* pRoundRect */
128 NULL, /* pScaleViewportExtEx */
129 NULL, /* pScaleWindowExtEx */
130 WIN16DRV_SelectBitmap, /* pSelectBitmap */
131 WIN16DRV_SelectBrush, /* pSelectBrush */
132 NULL, /* pSelectClipPath */
133 WIN16DRV_SelectFont, /* pSelectFont */
134 NULL, /* pSelectPalette */
135 WIN16DRV_SelectPen, /* pSelectPen */
136 NULL, /* pSetBkColor */
137 NULL, /* pSetBkMode */
138 NULL, /* pSetDIBColorTable */
139 NULL, /* pSetDIBits */
140 NULL, /* pSetDIBitsToDevice */
141 NULL, /* pSetDeviceClipping */
142 NULL, /* pSetDeviceGammaRamp */
143 NULL, /* pSetMapMode */
144 NULL, /* pSetMapperFlags */
145 NULL, /* pSetPixel */
146 NULL, /* pSetPixelFormat */
147 NULL, /* pSetPolyFillMode */
149 NULL, /* pSetRelAbs */
150 NULL, /* pSetStretchBltMode */
151 NULL, /* pSetTextAlign */
152 NULL, /* pSetTextCharacterExtra */
153 NULL, /* pSetTextColor */
154 NULL, /* pSetTextJustification */
155 NULL, /* pSetViewportExtEx */
156 NULL, /* pSetViewportOrgEx */
157 NULL, /* pSetWindowExtEx */
158 NULL, /* pSetWindowOrgEx */
159 NULL, /* pStartDoc */
160 NULL, /* pStartPage */
161 NULL, /* pStretchBlt */
162 NULL, /* pStretchDIBits */
163 NULL, /* pStrokeAndFillPath */
164 NULL, /* pStrokePath */
165 NULL, /* pSwapBuffers */
166 NULL /* pWidenPath */
170 /**********************************************************************
173 const DC_FUNCTIONS *WIN16DRV_Init(void)
175 static int enabled = -1;
179 char printerEnabled[20];
183 strcpy( printerEnabled, "off" );
184 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\wine", &hkey))
186 DWORD type, count = sizeof(printerEnabled);
187 RegQueryValueExA(hkey, "printer", 0, &type, printerEnabled, &count);
190 enabled = !strcasecmp( printerEnabled, "on" );
193 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
194 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
198 return enabled ? &WIN16DRV_Funcs : NULL;
201 /* Tempory functions, for initialising structures */
202 /* These values should be calculated, not hardcoded */
203 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
205 lpTextXForm->txfHeight = 0x0001;
206 lpTextXForm->txfWidth = 0x000c;
207 lpTextXForm->txfEscapement = 0x0000;
208 lpTextXForm->txfOrientation = 0x0000;
209 lpTextXForm->txfWeight = 0x0190;
210 lpTextXForm->txfItalic = 0x00;
211 lpTextXForm->txfUnderline = 0x00;
212 lpTextXForm->txfStrikeOut = 0x00;
213 lpTextXForm->txfOutPrecision = 0x02;
214 lpTextXForm->txfClipPrecision = 0x01;
215 lpTextXForm->txfAccelerator = 0x0001;
216 lpTextXForm->txfOverhang = 0x0000;
220 void InitDrawMode(LPDRAWMODE lpDrawMode)
222 lpDrawMode->Rop2 = 0x000d;
223 lpDrawMode->bkMode = 0x0001;
224 lpDrawMode->bkColor = 0x3fffffff;
225 lpDrawMode->TextColor = 0x20000000;
226 lpDrawMode->TBreakExtra = 0x0000;
227 lpDrawMode->BreakExtra = 0x0000;
228 lpDrawMode->BreakErr = 0x0000;
229 lpDrawMode->BreakRem = 0x0000;
230 lpDrawMode->BreakCount = 0x0000;
231 lpDrawMode->CharExtra = 0x0000;
232 lpDrawMode->LbkColor = 0x00ffffff;
233 lpDrawMode->LTextColor = 0x00000000;
234 lpDrawMode->ICMCXform = 0; /* ? */
235 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
236 lpDrawMode->eMiterLimit = 1;
239 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
240 const DEVMODEA* initData )
242 LOADED_PRINTER_DRIVER *pLPD;
245 PDEVICE_HEADER *pPDH;
246 WIN16DRV_PDEVICE *physDev;
248 TRACE("In creatdc for (%s,%s,%s) initData %p\n",
249 driver, device, output, initData);
251 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
252 if (!physDev) return FALSE;
253 dc->physDev = (PHYSDEV)physDev;
254 physDev->hdc = dc->hSelf;
257 pLPD = LoadPrinterDriver(driver);
260 WARN("Failed to find printer driver\n");
261 HeapFree( GetProcessHeap(), 0, physDev );
264 TRACE("windevCreateDC pLPD %p\n", pLPD);
266 /* Now Get the device capabilities from the printer driver */
267 memset( &physDev->DevCaps, 0, sizeof(physDev->DevCaps) );
268 if(!output) output = "LPT1:";
270 /* Get GDIINFO which is the same as a DeviceCaps structure */
271 wRet = PRTDRV_Enable(&physDev->DevCaps, GETGDIINFO, device, driver, output,NULL);
273 /* Add this to the DC */
274 dc->bitsPerPixel = physDev->DevCaps.bitsPixel;
276 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
277 physDev->DevCaps.horzRes, physDev->DevCaps.vertRes,
278 physDev->DevCaps.bitsPixel, physDev->DevCaps.planes);
280 /* Now we allocate enough memory for the PDEVICE structure */
281 /* The size of this varies between printer drivers */
282 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
283 /* be accessable from 16 bit code */
284 nPDEVICEsize = physDev->DevCaps.pdeviceSize + sizeof(PDEVICE_HEADER);
286 /* TTD Shouldn't really do pointer arithmetic on segment points */
287 physDev->segptrPDEVICE = K32WOWGlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
288 *((BYTE *)MapSL(physDev->segptrPDEVICE)+0) = 'N';
289 *((BYTE *)MapSL(physDev->segptrPDEVICE)+1) = 'B';
291 /* Set up the header */
292 pPDH = (PDEVICE_HEADER *)((BYTE*)MapSL(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
295 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
297 /* Now get the printer driver to initialise this data */
298 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
300 physDev->FontInfo = NULL;
301 physDev->BrushInfo = NULL;
302 physDev->PenInfo = NULL;
303 win16drv_SegPtr_TextXForm = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
304 win16drv_TextXFormP = MapSL(win16drv_SegPtr_TextXForm);
306 InitTextXForm(win16drv_TextXFormP);
308 /* TTD Lots more to do here */
309 win16drv_SegPtr_DrawMode = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
310 win16drv_DrawModeP = MapSL(win16drv_SegPtr_DrawMode);
312 InitDrawMode(win16drv_DrawModeP);
317 BOOL WIN16DRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
320 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
323 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
324 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
330 /***********************************************************************
331 * WIN16DRV_GetDeviceCaps
333 static INT WIN16DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
335 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
336 if (cap >= PHYSICALWIDTH || (cap % 2))
338 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
341 return *((WORD *)&physDev->DevCaps + (cap / 2));
345 /***********************************************************************
348 static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
349 INT out_count, LPVOID out_data )
352 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
355 /* We should really process the nEscape parameter, but for now just
356 pass it all to the driver */
357 if (dc != NULL && physDev->segptrPDEVICE != 0)
361 case ENABLEPAIRKERNING:
362 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
365 case GETPAIRKERNTABLE:
366 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
370 /* FIXME: The AbortProc should be called:
371 - After every write to printer port or spool file
372 - Several times when no more disk space
373 - Before every metafile record when GDI does banding
376 /* Call Control with hdc as lpInData */
377 HDC16 *seghdc = SEGPTR_NEW(HDC16);
379 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
380 SEGPTR_GET(seghdc), lpOutData);
387 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
389 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
390 SEGPTR_GET(newInData), lpOutData);
391 SEGPTR_FREE(newInData);
395 case GETEXTENDEDTEXTMETRICS:
397 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
399 textData->nSize = cbInput;
400 textData->lpindata = lpInData;
401 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
402 textData->lpXForm = win16drv_SegPtr_TextXForm;
403 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
404 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
405 SEGPTR_GET(textData), lpOutData);
406 SEGPTR_FREE(textData);
411 /* lpInData is not necessarily \0 terminated so make it so */
412 char *cp = SEGPTR_ALLOC(cbInput + 1);
413 memcpy(cp, MapSL(lpInData), cbInput);
416 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
417 SEGPTR_GET(cp), lpOutData);
421 HDC *tmpHdc = SEGPTR_NEW(HDC);
423 #define SETPRINTERDC SETABORTPROC
426 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
427 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
433 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
434 lpInData, lpOutData);
439 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
442 /* FIXME: should convert args to SEGPTR and redo all the above */
443 FIXME("temporarily broken, please fix\n");