Added support for special treatments (use 2 or more fonts, codepage
[wine.git] / graphics / win16drv / init.c
blob6ee437c95005a48cf0f53587b5941cd7ae6e246f
1 /*
2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
5 * 1998 Huw Davies
6 */
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include "win16drv.h"
13 #include "gdi.h"
14 #include "bitmap.h"
15 #include "heap.h"
16 #include "font.h"
17 #include "options.h"
18 #include "debugtools.h"
19 #include "dc.h"
21 DEFAULT_DEBUG_CHANNEL(win16drv)
23 #define SUPPORT_REALIZED_FONTS 1
24 #include "pshpack1.h"
25 typedef struct
27 SHORT nSize;
28 SEGPTR lpindata;
29 SEGPTR lpFont;
30 SEGPTR lpXForm;
31 SEGPTR lpDrawMode;
32 } EXTTEXTDATA, *LPEXTTEXTDATA;
33 #include "poppack.h"
35 SEGPTR win16drv_SegPtr_TextXForm;
36 LPTEXTXFORM16 win16drv_TextXFormP;
37 SEGPTR win16drv_SegPtr_DrawMode;
38 LPDRAWMODE win16drv_DrawModeP;
41 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
42 LPCSTR output, const DEVMODEA* initData );
43 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
44 SEGPTR lpInData, SEGPTR lpOutData );
46 static const DC_FUNCTIONS WIN16DRV_Funcs =
48 NULL, /* pAbortDoc */
49 NULL, /* pAbortPath */
50 NULL, /* pAngleArc */
51 NULL, /* pArc */
52 NULL, /* pArcTo */
53 NULL, /* pBeginPath */
54 NULL, /* pBitBlt */
55 NULL, /* pBitmapBits */
56 NULL, /* pChoosePixelFormat */
57 NULL, /* pChord */
58 NULL, /* pCloseFigure */
59 NULL, /* pCreateBitmap */
60 WIN16DRV_CreateDC, /* pCreateDC */
61 NULL, /* pCreateDIBSection */
62 NULL, /* pCreateDIBSection16 */
63 NULL, /* pDeleteDC */
64 NULL, /* pDeleteObject */
65 NULL, /* pDescribePixelFormat */
66 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
67 WIN16DRV_Ellipse, /* pEllipse */
68 NULL, /* pEndDoc */
69 NULL, /* pEndPage */
70 NULL, /* pEndPath */
71 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
72 WIN16DRV_Escape, /* pEscape */
73 NULL, /* pExcludeClipRect */
74 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
75 NULL, /* pExtFloodFill */
76 WIN16DRV_ExtTextOut, /* pExtTextOut */
77 NULL, /* pFillPath */
78 NULL, /* pFillRgn */
79 NULL, /* pFlattenPath */
80 NULL, /* pFrameRgn */
81 WIN16DRV_GetCharWidth, /* pGetCharWidth */
82 NULL, /* pGetDCOrgEx */
83 NULL, /* pGetPixel */
84 NULL, /* pGetPixelFormat */
85 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
86 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
87 NULL, /* pIntersectClipRect */
88 NULL, /* pInvertRgn */
89 WIN16DRV_LineTo, /* pLineTo */
90 WIN16DRV_MoveToEx, /* pMoveToEx */
91 NULL, /* pOffsetClipRgn */
92 NULL, /* pOffsetViewportOrgEx */
93 NULL, /* pOffsetWindowOrgEx */
94 NULL, /* pPaintRgn */
95 WIN16DRV_PatBlt, /* pPatBlt */
96 NULL, /* pPie */
97 NULL, /* pPolyBezier */
98 NULL, /* pPolyBezierTo */
99 NULL, /* pPolyDraw */
100 NULL, /* pPolyPolygon */
101 NULL, /* pPolyPolyline */
102 WIN16DRV_Polygon, /* pPolygon */
103 WIN16DRV_Polyline, /* pPolyline */
104 NULL, /* pPolylineTo */
105 NULL, /* pRealizePalette */
106 WIN16DRV_Rectangle, /* pRectangle */
107 NULL, /* pRestoreDC */
108 NULL, /* pRoundRect */
109 NULL, /* pSaveDC */
110 NULL, /* pScaleViewportExtEx */
111 NULL, /* pScaleWindowExtEx */
112 NULL, /* pSelectClipPath */
113 NULL, /* pSelectClipRgn */
114 WIN16DRV_SelectObject, /* pSelectObject */
115 NULL, /* pSelectPalette */
116 NULL, /* pSetBkColor */
117 NULL, /* pSetBkMode */
118 NULL, /* pSetDeviceClipping */
119 NULL, /* pSetDIBitsToDevice */
120 NULL, /* pSetMapMode */
121 NULL, /* pSetMapperFlags */
122 NULL, /* pSetPixel */
123 NULL, /* pSetPixelFormat */
124 NULL, /* pSetPolyFillMode */
125 NULL, /* pSetROP2 */
126 NULL, /* pSetRelAbs */
127 NULL, /* pSetStretchBltMode */
128 NULL, /* pSetTextAlign */
129 NULL, /* pSetTextCharacterExtra */
130 NULL, /* pSetTextColor */
131 NULL, /* pSetTextJustification */
132 NULL, /* pSetViewportExtEx */
133 NULL, /* pSetViewportOrgEx */
134 NULL, /* pSetWindowExtEx */
135 NULL, /* pSetWindowOrgEx */
136 NULL, /* pStartDoc */
137 NULL, /* pStartPage */
138 NULL, /* pStretchBlt */
139 NULL, /* pStretchDIBits */
140 NULL, /* pStrokeAndFillPath */
141 NULL, /* pStrokePath */
142 NULL, /* pSwapBuffers */
143 NULL /* pWidenPath */
150 /**********************************************************************
151 * WIN16DRV_Init
153 BOOL WIN16DRV_Init(void)
155 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
159 /* Tempory functions, for initialising structures */
160 /* These values should be calculated, not hardcoded */
161 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
163 lpTextXForm->txfHeight = 0x0001;
164 lpTextXForm->txfWidth = 0x000c;
165 lpTextXForm->txfEscapement = 0x0000;
166 lpTextXForm->txfOrientation = 0x0000;
167 lpTextXForm->txfWeight = 0x0190;
168 lpTextXForm->txfItalic = 0x00;
169 lpTextXForm->txfUnderline = 0x00;
170 lpTextXForm->txfStrikeOut = 0x00;
171 lpTextXForm->txfOutPrecision = 0x02;
172 lpTextXForm->txfClipPrecision = 0x01;
173 lpTextXForm->txfAccelerator = 0x0001;
174 lpTextXForm->txfOverhang = 0x0000;
178 void InitDrawMode(LPDRAWMODE lpDrawMode)
180 lpDrawMode->Rop2 = 0x000d;
181 lpDrawMode->bkMode = 0x0001;
182 lpDrawMode->bkColor = 0x3fffffff;
183 lpDrawMode->TextColor = 0x20000000;
184 lpDrawMode->TBreakExtra = 0x0000;
185 lpDrawMode->BreakExtra = 0x0000;
186 lpDrawMode->BreakErr = 0x0000;
187 lpDrawMode->BreakRem = 0x0000;
188 lpDrawMode->BreakCount = 0x0000;
189 lpDrawMode->CharExtra = 0x0000;
190 lpDrawMode->LbkColor = 0x00ffffff;
191 lpDrawMode->LTextColor = 0x00000000;
192 lpDrawMode->ICMCXform = 0; /* ? */
193 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
194 lpDrawMode->eMiterLimit = 1;
197 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
198 const DEVMODEA* initData )
200 LOADED_PRINTER_DRIVER *pLPD;
201 WORD wRet;
202 DeviceCaps *printerDevCaps;
203 int nPDEVICEsize;
204 PDEVICE_HEADER *pPDH;
205 WIN16DRV_PDEVICE *physDev;
206 char printerEnabled[20];
207 PROFILE_GetWineIniString( "wine", "printer", "off",
208 printerEnabled, sizeof(printerEnabled) );
209 if (strcasecmp(printerEnabled,"on"))
211 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
212 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
213 return FALSE;
216 TRACE("In creatdc for (%s,%s,%s) initData 0x%p\n",
217 driver, device, output, initData);
219 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
220 if (!physDev) return FALSE;
221 dc->physDev = physDev;
223 pLPD = LoadPrinterDriver(driver);
224 if (pLPD == NULL)
226 WARN("Failed to find printer driver\n");
227 HeapFree( GetProcessHeap(), 0, physDev );
228 return FALSE;
230 TRACE("windevCreateDC pLPD 0x%p\n", pLPD);
232 /* Now Get the device capabilities from the printer driver */
234 printerDevCaps = (DeviceCaps *) calloc(1, sizeof(DeviceCaps));
235 if(printerDevCaps == NULL) {
236 ERR("No memory to read the device capabilities!");
237 HeapFree( GetProcessHeap(), 0, physDev );
238 return FALSE;
241 if(!output) output = "LPT1:";
242 /* Get GDIINFO which is the same as a DeviceCaps structure */
243 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
245 /* Add this to the DC */
246 dc->w.devCaps = printerDevCaps;
247 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
248 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
250 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
251 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
252 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
254 /* Now we allocate enough memory for the PDEVICE structure */
255 /* The size of this varies between printer drivers */
256 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
257 /* be accessable from 16 bit code */
258 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
260 /* TTD Shouldn't really do pointer arithmetic on segment points */
261 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
262 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
263 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
265 /* Set up the header */
266 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
267 pPDH->pLPD = pLPD;
269 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
271 /* Now get the printer driver to initialise this data */
272 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
274 physDev->FontInfo = NULL;
275 physDev->BrushInfo = NULL;
276 physDev->PenInfo = NULL;
277 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
278 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
280 InitTextXForm(win16drv_TextXFormP);
282 /* TTD Lots more to do here */
283 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
284 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
286 InitDrawMode(win16drv_DrawModeP);
288 return TRUE;
291 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
292 INT width, INT height, DWORD rop )
295 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
296 BOOL bRet = 0;
298 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
299 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
301 return bRet;
304 * Escape (GDI.38)
306 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
307 SEGPTR lpInData, SEGPTR lpOutData )
309 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
310 int nRet = 0;
312 /* We should really process the nEscape parameter, but for now just
313 pass it all to the driver */
314 if (dc != NULL && physDev->segptrPDEVICE != 0)
316 switch(nEscape)
318 case ENABLEPAIRKERNING:
319 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
320 nRet = 1;
321 break;
322 case GETPAIRKERNTABLE:
323 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
324 nRet = 0;
325 break;
326 case SETABORTPROC: {
327 /* FIXME: The AbortProc should be called:
328 - After every write to printer port or spool file
329 - Several times when no more disk space
330 - Before every metafile record when GDI does banding
333 /* Call Control with hdc as lpInData */
334 HDC16 *seghdc = SEGPTR_NEW(HDC16);
335 *seghdc = dc->hSelf;
336 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
337 SEGPTR_GET(seghdc), lpOutData);
338 SEGPTR_FREE(seghdc);
339 break;
342 case NEXTBAND:
344 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
346 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
347 SEGPTR_GET(newInData), lpOutData);
348 SEGPTR_FREE(newInData);
349 break;
352 case GETEXTENDEDTEXTMETRICS:
354 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
356 textData->nSize = cbInput;
357 textData->lpindata = lpInData;
358 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
359 textData->lpXForm = win16drv_SegPtr_TextXForm;
360 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
361 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
362 SEGPTR_GET(textData), lpOutData);
363 SEGPTR_FREE(textData);
365 break;
366 case STARTDOC:
368 /* lpInData is not necessarily \0 terminated so make it so */
369 char *cp = SEGPTR_ALLOC(cbInput + 1);
370 memcpy(cp, PTR_SEG_TO_LIN(lpInData), cbInput);
371 cp[cbInput] = '\0';
373 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
374 SEGPTR_GET(cp), lpOutData);
375 SEGPTR_FREE(cp);
376 if (nRet != -1)
378 HDC *tmpHdc = SEGPTR_NEW(HDC);
380 #define SETPRINTERDC SETABORTPROC
382 *tmpHdc = dc->hSelf;
383 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
384 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
385 SEGPTR_FREE(tmpHdc);
388 break;
389 default:
390 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
391 lpInData, lpOutData);
392 break;
395 else
396 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
397 return nRet;