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
, /* 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
, /* 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
, /* pSetBitmapBits */
137 NULL
, /* pSetBkColor */
138 NULL
, /* pSetBkMode */
139 NULL
, /* pSetDIBColorTable */
140 NULL
, /* pSetDIBits */
141 NULL
, /* pSetDIBitsToDevice */
142 NULL
, /* pSetDeviceClipping */
143 NULL
, /* pSetDeviceGammaRamp */
144 NULL
, /* pSetMapMode */
145 NULL
, /* pSetMapperFlags */
146 NULL
, /* pSetPixel */
147 NULL
, /* pSetPixelFormat */
148 NULL
, /* pSetPolyFillMode */
150 NULL
, /* pSetRelAbs */
151 NULL
, /* pSetStretchBltMode */
152 NULL
, /* pSetTextAlign */
153 NULL
, /* pSetTextCharacterExtra */
154 NULL
, /* pSetTextColor */
155 NULL
, /* pSetTextJustification */
156 NULL
, /* pSetViewportExtEx */
157 NULL
, /* pSetViewportOrgEx */
158 NULL
, /* pSetWindowExtEx */
159 NULL
, /* pSetWindowOrgEx */
160 NULL
, /* pStartDoc */
161 NULL
, /* pStartPage */
162 NULL
, /* pStretchBlt */
163 NULL
, /* pStretchDIBits */
164 NULL
, /* pStrokeAndFillPath */
165 NULL
, /* pStrokePath */
166 NULL
, /* pSwapBuffers */
167 NULL
/* pWidenPath */
171 /**********************************************************************
174 const DC_FUNCTIONS
*WIN16DRV_Init(void)
176 static int enabled
= -1;
180 char printerEnabled
[20];
184 strcpy( printerEnabled
, "off" );
185 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\wine", &hkey
))
187 DWORD type
, count
= sizeof(printerEnabled
);
188 RegQueryValueExA(hkey
, "printer", 0, &type
, printerEnabled
, &count
);
191 enabled
= !strcasecmp( printerEnabled
, "on" );
194 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
195 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
199 return enabled
? &WIN16DRV_Funcs
: NULL
;
202 /* Tempory functions, for initialising structures */
203 /* These values should be calculated, not hardcoded */
204 void InitTextXForm(LPTEXTXFORM16 lpTextXForm
)
206 lpTextXForm
->txfHeight
= 0x0001;
207 lpTextXForm
->txfWidth
= 0x000c;
208 lpTextXForm
->txfEscapement
= 0x0000;
209 lpTextXForm
->txfOrientation
= 0x0000;
210 lpTextXForm
->txfWeight
= 0x0190;
211 lpTextXForm
->txfItalic
= 0x00;
212 lpTextXForm
->txfUnderline
= 0x00;
213 lpTextXForm
->txfStrikeOut
= 0x00;
214 lpTextXForm
->txfOutPrecision
= 0x02;
215 lpTextXForm
->txfClipPrecision
= 0x01;
216 lpTextXForm
->txfAccelerator
= 0x0001;
217 lpTextXForm
->txfOverhang
= 0x0000;
221 void InitDrawMode(LPDRAWMODE lpDrawMode
)
223 lpDrawMode
->Rop2
= 0x000d;
224 lpDrawMode
->bkMode
= 0x0001;
225 lpDrawMode
->bkColor
= 0x3fffffff;
226 lpDrawMode
->TextColor
= 0x20000000;
227 lpDrawMode
->TBreakExtra
= 0x0000;
228 lpDrawMode
->BreakExtra
= 0x0000;
229 lpDrawMode
->BreakErr
= 0x0000;
230 lpDrawMode
->BreakRem
= 0x0000;
231 lpDrawMode
->BreakCount
= 0x0000;
232 lpDrawMode
->CharExtra
= 0x0000;
233 lpDrawMode
->LbkColor
= 0x00ffffff;
234 lpDrawMode
->LTextColor
= 0x00000000;
235 lpDrawMode
->ICMCXform
= 0; /* ? */
236 lpDrawMode
->StretchBltMode
= STRETCH_ANDSCANS
;
237 lpDrawMode
->eMiterLimit
= 1;
240 BOOL
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
241 const DEVMODEA
* initData
)
243 LOADED_PRINTER_DRIVER
*pLPD
;
246 PDEVICE_HEADER
*pPDH
;
247 WIN16DRV_PDEVICE
*physDev
;
249 TRACE("In creatdc for (%s,%s,%s) initData %p\n",
250 driver
, device
, output
, initData
);
252 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev
) );
253 if (!physDev
) return FALSE
;
254 dc
->physDev
= (PHYSDEV
)physDev
;
255 physDev
->hdc
= dc
->hSelf
;
258 pLPD
= LoadPrinterDriver(driver
);
261 WARN("Failed to find printer driver\n");
262 HeapFree( GetProcessHeap(), 0, physDev
);
265 TRACE("windevCreateDC pLPD %p\n", pLPD
);
267 /* Now Get the device capabilities from the printer driver */
268 memset( &physDev
->DevCaps
, 0, sizeof(physDev
->DevCaps
) );
269 if(!output
) output
= "LPT1:";
271 /* Get GDIINFO which is the same as a DeviceCaps structure */
272 wRet
= PRTDRV_Enable(&physDev
->DevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
274 /* Add this to the DC */
275 dc
->bitsPerPixel
= physDev
->DevCaps
.bitsPixel
;
277 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
278 physDev
->DevCaps
.horzRes
, physDev
->DevCaps
.vertRes
,
279 physDev
->DevCaps
.bitsPixel
, physDev
->DevCaps
.planes
);
281 /* Now we allocate enough memory for the PDEVICE structure */
282 /* The size of this varies between printer drivers */
283 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
284 /* be accessable from 16 bit code */
285 nPDEVICEsize
= physDev
->DevCaps
.pdeviceSize
+ sizeof(PDEVICE_HEADER
);
287 /* TTD Shouldn't really do pointer arithmetic on segment points */
288 physDev
->segptrPDEVICE
= K32WOWGlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
289 *((BYTE
*)MapSL(physDev
->segptrPDEVICE
)+0) = 'N';
290 *((BYTE
*)MapSL(physDev
->segptrPDEVICE
)+1) = 'B';
292 /* Set up the header */
293 pPDH
= (PDEVICE_HEADER
*)((BYTE
*)MapSL(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
296 TRACE("PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
298 /* Now get the printer driver to initialise this data */
299 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
301 physDev
->FontInfo
= NULL
;
302 physDev
->BrushInfo
= NULL
;
303 physDev
->PenInfo
= NULL
;
304 win16drv_SegPtr_TextXForm
= K32WOWGlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
305 win16drv_TextXFormP
= MapSL(win16drv_SegPtr_TextXForm
);
307 InitTextXForm(win16drv_TextXFormP
);
309 /* TTD Lots more to do here */
310 win16drv_SegPtr_DrawMode
= K32WOWGlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
311 win16drv_DrawModeP
= MapSL(win16drv_SegPtr_DrawMode
);
313 InitDrawMode(win16drv_DrawModeP
);
318 BOOL
WIN16DRV_PatBlt( PHYSDEV dev
, INT left
, INT top
, INT width
, INT height
, DWORD rop
)
321 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dev
;
324 bRet
= PRTDRV_StretchBlt( physDev
->segptrPDEVICE
, left
, top
, width
, height
, (SEGPTR
)NULL
, 0, 0, width
, height
,
325 PATCOPY
, physDev
->BrushInfo
, win16drv_SegPtr_DrawMode
, NULL
);
331 /***********************************************************************
332 * WIN16DRV_GetDeviceCaps
334 static INT
WIN16DRV_GetDeviceCaps( PHYSDEV dev
, INT cap
)
336 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dev
;
337 if (cap
>= PHYSICALWIDTH
|| (cap
% 2))
339 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev
->hdc
, cap
);
342 return *((WORD
*)&physDev
->DevCaps
+ (cap
/ 2));
346 /***********************************************************************
349 static INT
WIN16DRV_ExtEscape( PHYSDEV dev
, INT escape
, INT in_count
, LPCVOID in_data
,
350 INT out_count
, LPVOID out_data
)
353 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
356 /* We should really process the nEscape parameter, but for now just
357 pass it all to the driver */
358 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
362 case ENABLEPAIRKERNING
:
363 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
366 case GETPAIRKERNTABLE
:
367 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
371 /* FIXME: The AbortProc should be called:
372 - After every write to printer port or spool file
373 - Several times when no more disk space
374 - Before every metafile record when GDI does banding
377 /* Call Control with hdc as lpInData */
378 HDC16
*seghdc
= SEGPTR_NEW(HDC16
);
380 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
381 SEGPTR_GET(seghdc
), lpOutData
);
388 LPPOINT16 newInData
= SEGPTR_NEW(POINT16
);
390 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
391 SEGPTR_GET(newInData
), lpOutData
);
392 SEGPTR_FREE(newInData
);
396 case GETEXTENDEDTEXTMETRICS
:
398 EXTTEXTDATA
*textData
= SEGPTR_NEW(EXTTEXTDATA
);
400 textData
->nSize
= cbInput
;
401 textData
->lpindata
= lpInData
;
402 textData
->lpFont
= SEGPTR_GET( physDev
->FontInfo
);
403 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
404 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
405 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
406 SEGPTR_GET(textData
), lpOutData
);
407 SEGPTR_FREE(textData
);
412 /* lpInData is not necessarily \0 terminated so make it so */
413 char *cp
= SEGPTR_ALLOC(cbInput
+ 1);
414 memcpy(cp
, MapSL(lpInData
), cbInput
);
417 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
418 SEGPTR_GET(cp
), lpOutData
);
422 HDC
*tmpHdc
= SEGPTR_NEW(HDC
);
424 #define SETPRINTERDC SETABORTPROC
427 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
428 SEGPTR_GET(tmpHdc
), (SEGPTR
)NULL
);
434 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
435 lpInData
, lpOutData
);
440 WARN("Escape(nEscape = %04x) - ???\n", nEscape
);
443 /* FIXME: should convert args to SEGPTR and redo all the above */
444 FIXME("temporarily broken, please fix\n");