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;
171 lpDrawMode
->ICMCXform
= 0; /* ? */
172 lpDrawMode
->StretchBltMode
= STRETCH_ANDSCANS
;
173 lpDrawMode
->eMiterLimit
= 1;
176 BOOL
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
177 const DEVMODEA
* initData
)
179 LOADED_PRINTER_DRIVER
*pLPD
;
181 DeviceCaps
*printerDevCaps
;
183 PDEVICE_HEADER
*pPDH
;
184 WIN16DRV_PDEVICE
*physDev
;
185 char printerEnabled
[20];
186 PROFILE_GetWineIniString( "wine", "printer", "off",
187 printerEnabled
, sizeof(printerEnabled
) );
188 if (lstrcmpiA(printerEnabled
,"on"))
190 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
191 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
195 TRACE("In creatdc for (%s,%s,%s) initData 0x%p\n",
196 driver
, device
, output
, initData
);
198 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( SystemHeap
, 0, sizeof(*physDev
) );
199 if (!physDev
) return FALSE
;
200 dc
->physDev
= physDev
;
202 pLPD
= LoadPrinterDriver(driver
);
205 WARN("Failed to find printer driver\n");
206 HeapFree( SystemHeap
, 0, physDev
);
209 TRACE("windevCreateDC pLPD 0x%p\n", pLPD
);
211 /* Now Get the device capabilities from the printer driver */
213 printerDevCaps
= (DeviceCaps
*) xmalloc(sizeof(DeviceCaps
));
214 memset(printerDevCaps
, 0, sizeof(DeviceCaps
));
216 if(!output
) output
= "LPT1:";
217 /* Get GDIINFO which is the same as a DeviceCaps structure */
218 wRet
= PRTDRV_Enable(printerDevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
220 /* Add this to the DC */
221 dc
->w
.devCaps
= printerDevCaps
;
222 dc
->w
.hVisRgn
= CreateRectRgn(0, 0, dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
);
223 dc
->w
.bitsPerPixel
= dc
->w
.devCaps
->bitsPixel
;
225 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
226 dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
,
227 dc
->w
.devCaps
->bitsPixel
, dc
->w
.devCaps
->planes
);
229 /* Now we allocate enough memory for the PDEVICE structure */
230 /* The size of this varies between printer drivers */
231 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
232 /* be accessable from 16 bit code */
233 nPDEVICEsize
= dc
->w
.devCaps
->pdeviceSize
+ sizeof(PDEVICE_HEADER
);
235 /* TTD Shouldn't really do pointer arithmetic on segment points */
236 physDev
->segptrPDEVICE
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
237 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+0) = 'N';
238 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+1) = 'B';
240 /* Set up the header */
241 pPDH
= (PDEVICE_HEADER
*)((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
244 TRACE("PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
246 /* Now get the printer driver to initialise this data */
247 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
249 physDev
->FontInfo
= NULL
;
250 physDev
->BrushInfo
= NULL
;
251 physDev
->PenInfo
= NULL
;
252 win16drv_SegPtr_TextXForm
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
253 win16drv_TextXFormP
= PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm
);
255 InitTextXForm(win16drv_TextXFormP
);
257 /* TTD Lots more to do here */
258 win16drv_SegPtr_DrawMode
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
259 win16drv_DrawModeP
= PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode
);
261 InitDrawMode(win16drv_DrawModeP
);
266 BOOL
WIN16DRV_PatBlt( struct tagDC
*dc
, INT left
, INT top
,
267 INT width
, INT height
, DWORD rop
)
270 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
273 bRet
= PRTDRV_StretchBlt( physDev
->segptrPDEVICE
, left
, top
, width
, height
, (SEGPTR
)NULL
, 0, 0, width
, height
,
274 PATCOPY
, physDev
->BrushInfo
, win16drv_SegPtr_DrawMode
, NULL
);
281 static INT
WIN16DRV_Escape( DC
*dc
, INT nEscape
, INT cbInput
,
282 SEGPTR lpInData
, SEGPTR lpOutData
)
284 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
287 /* We should really process the nEscape parameter, but for now just
288 pass it all to the driver */
289 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
293 case ENABLEPAIRKERNING
:
294 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
297 case GETPAIRKERNTABLE
:
298 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
302 /* FIXME: The AbortProc should be called:
303 - After every write to printer port or spool file
304 - Several times when no more disk space
305 - Before every metafile record when GDI does banding
308 /* Call Control with hdc as lpInData */
309 HDC16
*seghdc
= SEGPTR_NEW(HDC16
);
311 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
312 SEGPTR_GET(seghdc
), lpOutData
);
319 LPPOINT16 newInData
= SEGPTR_NEW(POINT16
);
321 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
322 SEGPTR_GET(newInData
), lpOutData
);
323 SEGPTR_FREE(newInData
);
327 case GETEXTENDEDTEXTMETRICS
:
329 EXTTEXTDATA
*textData
= SEGPTR_NEW(EXTTEXTDATA
);
331 textData
->nSize
= cbInput
;
332 textData
->lpindata
= lpInData
;
333 textData
->lpFont
= SEGPTR_GET( physDev
->FontInfo
);
334 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
335 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
336 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
337 SEGPTR_GET(textData
), lpOutData
);
338 SEGPTR_FREE(textData
);
342 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
343 lpInData
, lpOutData
);
346 HDC
*tmpHdc
= SEGPTR_NEW(HDC
);
348 #define SETPRINTERDC SETABORTPROC
351 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
352 SEGPTR_GET(tmpHdc
), (SEGPTR
)NULL
);
357 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
358 lpInData
, lpOutData
);
363 WARN("Escape(nEscape = %04x) - ???\n", nEscape
);