2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
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 DEVMODE16
* initData
);
42 static INT
WIN16DRV_Escape( DC
*dc
, INT nEscape
, INT cbInput
,
43 SEGPTR lpInData
, SEGPTR lpOutData
);
45 static const DC_FUNCTIONS WIN16DRV_Funcs
=
49 NULL
, /* pBitmapBits */
51 NULL
, /* pCreateBitmap */
52 WIN16DRV_CreateDC
, /* pCreateDC */
54 NULL
, /* pCreateDIBSection */
55 NULL
, /* pCreateDIBSection16 */
56 NULL
, /* pDeleteObject */
57 WIN16DRV_Ellipse
, /* pEllipse */
58 WIN16DRV_EnumDeviceFonts
, /* pEnumDeviceFonts */
59 WIN16DRV_Escape
, /* pEscape */
60 NULL
, /* pExcludeClipRect */
61 NULL
, /* pExtFloodFill */
62 WIN16DRV_ExtTextOut
, /* pExtTextOut */
65 WIN16DRV_GetCharWidth
, /* pGetCharWidth */
67 WIN16DRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
68 WIN16DRV_GetTextMetrics
, /* pGetTextMetrics */
69 NULL
, /* pIntersectClipRect */
70 NULL
, /* pInvertRgn */
71 WIN16DRV_LineTo
, /* pLineTo */
72 NULL
, /* pLoadOEMResource */
73 WIN16DRV_MoveToEx
, /* pMoveToEx */
74 NULL
, /* pOffsetClipRgn */
75 NULL
, /* pOffsetViewportOrgEx */
76 NULL
, /* pOffsetWindowOrgEx */
78 WIN16DRV_PatBlt
, /* pPatBlt */
80 NULL
, /* pPolyPolygon */
81 NULL
, /* pPolyPolyline */
82 WIN16DRV_Polygon
, /* pPolygon */
83 WIN16DRV_Polyline
, /* pPolyline */
84 NULL
, /* pPolyBezier */
85 NULL
, /* pRealizePalette */
86 WIN16DRV_Rectangle
, /* pRectangle */
87 NULL
, /* pRestoreDC */
88 NULL
, /* pRoundRect */
90 NULL
, /* pScaleViewportExtEx */
91 NULL
, /* pScaleWindowExtEx */
92 NULL
, /* pSelectClipRgn */
93 WIN16DRV_SelectObject
, /* pSelectObject */
94 NULL
, /* pSelectPalette */
95 NULL
, /* pSetBkColor */
96 NULL
, /* pSetBkMode */
97 NULL
, /* pSetDeviceClipping */
98 NULL
, /* pSetDIBitsToDevice */
99 NULL
, /* pSetMapMode */
100 NULL
, /* pSetMapperFlags */
101 NULL
, /* pSetPixel */
102 NULL
, /* pSetPolyFillMode */
104 NULL
, /* pSetRelAbs */
105 NULL
, /* pSetStretchBltMode */
106 NULL
, /* pSetTextAlign */
107 NULL
, /* pSetTextCharacterExtra */
108 NULL
, /* pSetTextColor */
109 NULL
, /* pSetTextJustification */
110 NULL
, /* pSetViewportExtEx */
111 NULL
, /* pSetViewportOrgEx */
112 NULL
, /* pSetWindowExtEx */
113 NULL
, /* pSetWindowOrgEx */
114 NULL
, /* pStretchBlt */
115 NULL
/* pStretchDIBits */
122 /**********************************************************************
125 BOOL
WIN16DRV_Init(void)
127 return DRIVER_RegisterDriver( NULL
/* generic driver */, &WIN16DRV_Funcs
);
131 /* Tempory functions, for initialising structures */
132 /* These values should be calculated, not hardcoded */
133 void InitTextXForm(LPTEXTXFORM16 lpTextXForm
)
135 lpTextXForm
->txfHeight
= 0x0001;
136 lpTextXForm
->txfWidth
= 0x000c;
137 lpTextXForm
->txfEscapement
= 0x0000;
138 lpTextXForm
->txfOrientation
= 0x0000;
139 lpTextXForm
->txfWeight
= 0x0190;
140 lpTextXForm
->txfItalic
= 0x00;
141 lpTextXForm
->txfUnderline
= 0x00;
142 lpTextXForm
->txfStrikeOut
= 0x00;
143 lpTextXForm
->txfOutPrecision
= 0x02;
144 lpTextXForm
->txfClipPrecision
= 0x01;
145 lpTextXForm
->txfAccelerator
= 0x0001;
146 lpTextXForm
->txfOverhang
= 0x0000;
150 void InitDrawMode(LPDRAWMODE lpDrawMode
)
152 lpDrawMode
->Rop2
= 0x000d;
153 lpDrawMode
->bkMode
= 0x0001;
154 lpDrawMode
->bkColor
= 0x3fffffff;
155 lpDrawMode
->TextColor
= 0x20000000;
156 lpDrawMode
->TBreakExtra
= 0x0000;
157 lpDrawMode
->BreakExtra
= 0x0000;
158 lpDrawMode
->BreakErr
= 0x0000;
159 lpDrawMode
->BreakRem
= 0x0000;
160 lpDrawMode
->BreakCount
= 0x0000;
161 lpDrawMode
->CharExtra
= 0x0000;
162 lpDrawMode
->LbkColor
= 0x00ffffff;
163 lpDrawMode
->LTextColor
= 0x00000000;
166 BOOL
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
167 const DEVMODE16
* initData
)
169 LOADED_PRINTER_DRIVER
*pLPD
;
171 DeviceCaps
*printerDevCaps
;
173 PDEVICE_HEADER
*pPDH
;
174 WIN16DRV_PDEVICE
*physDev
;
175 char printerEnabled
[20];
176 PROFILE_GetWineIniString( "wine", "printer", "off",
177 printerEnabled
, sizeof(printerEnabled
) );
178 if (lstrcmpiA(printerEnabled
,"on"))
180 MSG("Printing disabled in wine.conf or .winerc file\n");
181 MSG("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
185 TRACE(win16drv
, "In creatdc for (%s,%s,%s) initData 0x%p\n",
186 driver
, device
, output
, initData
);
188 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( SystemHeap
, 0, sizeof(*physDev
) );
189 if (!physDev
) return FALSE
;
190 dc
->physDev
= physDev
;
192 pLPD
= LoadPrinterDriver(driver
);
195 WARN(win16drv
, "Failed to find printer driver\n");
196 HeapFree( SystemHeap
, 0, physDev
);
199 TRACE(win16drv
, "windevCreateDC pLPD 0x%p\n", pLPD
);
201 /* Now Get the device capabilities from the printer driver */
203 printerDevCaps
= (DeviceCaps
*) xmalloc(sizeof(DeviceCaps
));
204 memset(printerDevCaps
, 0, sizeof(DeviceCaps
));
206 /* Get GDIINFO which is the same as a DeviceCaps structure */
207 wRet
= PRTDRV_Enable(printerDevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
209 /* Add this to the DC */
210 dc
->w
.devCaps
= printerDevCaps
;
211 dc
->w
.hVisRgn
= CreateRectRgn(0, 0, dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
);
212 dc
->w
.bitsPerPixel
= dc
->w
.devCaps
->bitsPixel
;
214 TRACE(win16drv
, "Got devcaps width %d height %d bits %d planes %d\n",
215 dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
,
216 dc
->w
.devCaps
->bitsPixel
, dc
->w
.devCaps
->planes
);
218 /* Now we allocate enough memory for the PDEVICE structure */
219 /* The size of this varies between printer drivers */
220 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
221 /* be accessable from 16 bit code */
222 nPDEVICEsize
= dc
->w
.devCaps
->pdeviceSize
+ sizeof(PDEVICE_HEADER
);
224 /* TTD Shouldn't really do pointer arithmetic on segment points */
225 physDev
->segptrPDEVICE
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
226 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+0) = 'N';
227 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+1) = 'B';
229 /* Set up the header */
230 pPDH
= (PDEVICE_HEADER
*)((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
233 TRACE(win16drv
, "PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
235 /* Now get the printer driver to initialise this data */
236 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
238 physDev
->FontInfo
= NULL
;
239 physDev
->BrushInfo
= NULL
;
240 physDev
->PenInfo
= NULL
;
241 win16drv_SegPtr_TextXForm
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
242 win16drv_TextXFormP
= PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm
);
244 InitTextXForm(win16drv_TextXFormP
);
246 /* TTD Lots more to do here */
247 win16drv_SegPtr_DrawMode
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
248 win16drv_DrawModeP
= PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode
);
250 InitDrawMode(win16drv_DrawModeP
);
255 BOOL
WIN16DRV_PatBlt( struct tagDC
*dc
, INT left
, INT top
,
256 INT width
, INT height
, DWORD rop
)
259 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
262 bRet
= PRTDRV_StretchBlt( physDev
->segptrPDEVICE
, left
, top
, width
, height
, (SEGPTR
)NULL
, 0, 0, width
, height
,
263 PATCOPY
, physDev
->BrushInfo
, win16drv_SegPtr_DrawMode
, NULL
);
270 static INT
WIN16DRV_Escape( DC
*dc
, INT nEscape
, INT cbInput
,
271 SEGPTR lpInData
, SEGPTR lpOutData
)
273 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
276 /* We should really process the nEscape parameter, but for now just
277 pass it all to the driver */
278 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
282 case ENABLEPAIRKERNING
:
283 FIXME(win16drv
,"Escape: ENABLEPAIRKERNING ignored.\n");
286 case GETPAIRKERNTABLE
:
287 FIXME(win16drv
,"Escape: GETPAIRKERNTABLE ignored.\n");
291 /* FIXME: The AbortProc should be called:
292 - After every write to printer port or spool file
293 - Several times when no more disk space
294 - Before every metafile record when GDI does banding
297 /* save the callback address and call Control with hdc as lpInData */
298 HDC16
*seghdc
= SEGPTR_NEW(HDC16
);
300 dc
->w
.lpfnPrint
= (FARPROC16
)lpInData
;
301 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
302 SEGPTR_GET(seghdc
), lpOutData
);
309 LPPOINT16 newInData
= SEGPTR_NEW(POINT16
);
311 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
312 SEGPTR_GET(newInData
), lpOutData
);
313 SEGPTR_FREE(newInData
);
317 case GETEXTENDEDTEXTMETRICS
:
319 EXTTEXTDATA
*textData
= SEGPTR_NEW(EXTTEXTDATA
);
321 textData
->nSize
= cbInput
;
322 textData
->lpindata
= lpInData
;
323 textData
->lpFont
= SEGPTR_GET( physDev
->FontInfo
);
324 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
325 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
326 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
327 SEGPTR_GET(textData
), lpOutData
);
328 SEGPTR_FREE(textData
);
332 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
333 lpInData
, lpOutData
);
336 HDC
*tmpHdc
= SEGPTR_NEW(HDC
);
338 #define SETPRINTERDC SETABORTPROC
341 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
342 SEGPTR_GET(tmpHdc
), (SEGPTR
)NULL
);
347 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
348 lpInData
, lpOutData
);
353 WARN(win16drv
, "Escape(nEscape = %04x) - ???\n", nEscape
);