2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
25 #define SUPPORT_REALIZED_FONTS 1
34 } EXTTEXTDATA
, *LPEXTTEXTDATA
;
38 static BOOL16
windrvExtTextOut16( DC
*dc
, INT16 x
, INT16 y
, UINT16 flags
, const RECT16
* lprect
,
39 LPCSTR str
, UINT16 count
, const INT16
*lpDx
);
43 static BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
44 LPCSTR output
, const DEVMODE16
* initData
);
45 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
46 SEGPTR lpInData
, SEGPTR lpOutData
);
48 static const DC_FUNCTIONS WIN16DRV_Funcs
=
53 WIN16DRV_CreateDC
, /* pCreateDC */
55 NULL
, /* pDeleteObject */
57 NULL
, /* pEnumDeviceFonts */
58 WIN16DRV_Escape
, /* pEscape */
59 NULL
, /* pExcludeClipRect */
60 NULL
, /* pExcludeVisRect */
61 NULL
, /* pExtFloodFill */
62 WIN16DRV_ExtTextOut
, /* pExtTextOut */
63 WIN16DRV_GetCharWidth
, /* pGetCharWidth */
65 WIN16DRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
66 WIN16DRV_GetTextMetrics
, /* pGetTextMetrics */
67 NULL
, /* pIntersectClipRect */
68 NULL
, /* pIntersectVisRect */
71 NULL
, /* pOffsetClipRgn */
72 NULL
, /* pOffsetViewportOrgEx */
73 NULL
, /* pOffsetWindowOrgEx */
77 NULL
, /* pPolyPolygon */
80 NULL
, /* pRealizePalette */
81 NULL
, /* pRectangle */
82 NULL
, /* pRestoreDC */
83 NULL
, /* pRoundRect */
85 NULL
, /* pScaleViewportExtEx */
86 NULL
, /* pScaleWindowExtEx */
87 NULL
, /* pSelectClipRgn */
88 WIN16DRV_SelectObject
, /* pSelectObject */
89 NULL
, /* pSelectPalette */
90 NULL
, /* pSetBkColor */
91 NULL
, /* pSetBkMode */
92 NULL
, /* pSetDeviceClipping */
93 NULL
, /* pSetDIBitsToDevice */
94 NULL
, /* pSetMapMode */
95 NULL
, /* pSetMapperFlags */
97 NULL
, /* pSetPolyFillMode */
99 NULL
, /* pSetRelAbs */
100 NULL
, /* pSetStretchBltMode */
101 NULL
, /* pSetTextAlign */
102 NULL
, /* pSetTextCharacterExtra */
103 NULL
, /* pSetTextColor */
104 NULL
, /* pSetTextJustification */
105 NULL
, /* pSetViewportExtEx */
106 NULL
, /* pSetViewportOrgEx */
107 NULL
, /* pSetWindowExtEx */
108 NULL
, /* pSetWindowOrgEx */
109 NULL
, /* pStretchBlt */
110 NULL
/* pStretchDIBits */
117 /**********************************************************************
120 BOOL32
WIN16DRV_Init(void)
122 return DRIVER_RegisterDriver( NULL
/* generic driver */, &WIN16DRV_Funcs
);
126 /* Tempory functions, for initialising structures */
127 /* These values should be calculated, not hardcoded */
128 void InitTextXForm(LPTEXTXFORM16 lpTextXForm
)
130 lpTextXForm
->txfHeight
= 0x0001;
131 lpTextXForm
->txfWidth
= 0x000c;
132 lpTextXForm
->txfEscapement
= 0x0000;
133 lpTextXForm
->txfOrientation
= 0x0000;
134 lpTextXForm
->txfWeight
= 0x0190;
135 lpTextXForm
->txfItalic
= 0x00;
136 lpTextXForm
->txfUnderline
= 0x00;
137 lpTextXForm
->txfStrikeOut
= 0x00;
138 lpTextXForm
->txfOutPrecision
= 0x02;
139 lpTextXForm
->txfClipPrecision
= 0x01;
140 lpTextXForm
->txfAccelerator
= 0x0001;
141 lpTextXForm
->txfOverhang
= 0x0000;
145 void InitDrawMode(LPDRAWMODE lpDrawMode
)
147 lpDrawMode
->Rop2
= 0x000d;
148 lpDrawMode
->bkMode
= 0x0001;
149 lpDrawMode
->bkColor
= 0x3fffffff;
150 lpDrawMode
->TextColor
= 0x20000000;
151 lpDrawMode
->TBreakExtra
= 0x0000;
152 lpDrawMode
->BreakExtra
= 0x0000;
153 lpDrawMode
->BreakErr
= 0x0000;
154 lpDrawMode
->BreakRem
= 0x0000;
155 lpDrawMode
->BreakCount
= 0x0000;
156 lpDrawMode
->CharExtra
= 0x0000;
157 lpDrawMode
->LbkColor
= 0x00ffffff;
158 lpDrawMode
->LTextColor
= 0x00000000;
162 * EnumCallback (GDI.158)
164 * This is the callback function used when EnumDFonts is called.
165 * (The printer drivers uses it to pass info on available fonts).
167 * lpvClientData is the pointer passed to EnumDFonts, which points to a WEPFC
168 * structure (WEPFC = WINE_ENUM_PRINTER_FONT_CALLBACK). This structure
169 * contains infomation on how to store the data passed .
171 * There are two modes:
172 * 1) Just count the number of fonts available.
173 * 2) Store all font data passed.
175 WORD
WineEnumDFontCallback(LPLOGFONT16 lpLogFont
, LPTEXTMETRIC16 lpTextMetrics
,
176 WORD wFontType
, LONG lpvClientData
)
179 WEPFC
*pWEPFC
= (WEPFC
*)lpvClientData
;
181 /* Make sure we have the right structure */
184 dprintf_win16drv(stddeb
, "mode is 0x%x\n",pWEPFC
->nMode
);
186 switch (pWEPFC
->nMode
)
188 /* Count how many fonts */
193 /* Store the fonts in the printer driver structure */
196 PRINTER_FONTS_INFO
*pPFI
;
198 dprintf_win16drv(stddeb
, "WineEnumDFontCallback: Found %s %x\n",
199 lpLogFont
->lfFaceName
, wFontType
);
201 pPFI
= &pWEPFC
->pLPD
->paPrinterFonts
[pWEPFC
->nCount
];
202 memcpy(&(pPFI
->lf
), lpLogFont
, sizeof(LOGFONT16
));
203 memcpy(&(pPFI
->tm
), lpTextMetrics
, sizeof(TEXTMETRIC16
));
211 dprintf_win16drv(stddeb
, "WineEnumDFontCallback: returnd %d\n", wRet
);
215 BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
216 const DEVMODE16
* initData
)
218 LOADED_PRINTER_DRIVER
*pLPD
;
220 DeviceCaps
*printerDevCaps
;
221 FARPROC16 pfnCallback
;
223 PDEVICE_HEADER
*pPDH
;
224 WIN16DRV_PDEVICE
*physDev
;
225 LPDRAWMODE lpDrawMode
= &DrawMode
;
227 /* Realizing fonts */
228 TEXTXFORM16 TextXForm
;
230 char printerEnabled
[20];
231 PROFILE_GetWineIniString( "wine", "printer", "off",
232 printerEnabled
, sizeof(printerEnabled
) );
233 if (strcmp(printerEnabled
,"on"))
235 printf("WIN16DRV_CreateDC disabled in wine.conf file\n");
239 dprintf_win16drv(stddeb
, "In creatdc for (%s,%s,%s) initData 0x%p\n",driver
, device
, output
, initData
);
241 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( SystemHeap
, 0, sizeof(*physDev
) );
242 if (!physDev
) return FALSE
;
243 dc
->physDev
= physDev
;
245 pLPD
= LoadPrinterDriver(driver
);
248 dprintf_win16drv(stddeb
, "LPGDI_CreateDC: Failed to find printer driver\n");
249 HeapFree( SystemHeap
, 0, physDev
);
252 dprintf_win16drv(stddeb
, "windevCreateDC pLPD 0x%p\n", pLPD
);
254 /* Now Get the device capabilities from the printer driver */
256 printerDevCaps
= (DeviceCaps
*) malloc(sizeof(DeviceCaps
));
257 memset(printerDevCaps
, 0, sizeof(DeviceCaps
));
259 /* Get GDIINFO which is the same as a DeviceCaps structure */
260 wRet
= PRTDRV_Enable(printerDevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
262 /* Add this to the DC */
263 dc
->w
.devCaps
= printerDevCaps
;
264 dc
->w
.hVisRgn
= CreateRectRgn32(0, 0, dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
);
265 dc
->w
.bitsPerPixel
= dc
->w
.devCaps
->bitsPixel
;
267 printf("Got devcaps width %d height %d bits %d planes %d\n",
268 dc
->w
.devCaps
->horzRes
,
269 dc
->w
.devCaps
->vertRes
,
270 dc
->w
.devCaps
->bitsPixel
,
271 dc
->w
.devCaps
->planes
);
273 /* Now we allocate enough memory for the PDEVICE structure */
274 /* The size of this varies between printer drivers */
275 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
276 /* be accessable from 16 bit code */
277 nPDEVICEsize
= dc
->w
.devCaps
->pdeviceSize
+ sizeof(PDEVICE_HEADER
);
279 /* TTD Shouldn't really do pointer arithmetic on segment points */
280 physDev
->segptrPDEVICE
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
281 *(BYTE
*)(PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+0) = 'N';
282 *(BYTE
*)(PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+1) = 'B';
284 /* Set up the header */
285 pPDH
= (PDEVICE_HEADER
*)(PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
288 dprintf_win16drv(stddeb
, "PRTDRV_Enable: PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
290 /* Now get the printer driver to initialise this data */
291 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
293 /* Now enumerate the fonts supported by the printer driver*/
294 /* GDI.158 is EnumCallback, which is called by the 16bit printer driver */
295 /* passing information on the available fonts */
296 if (pLPD
->paPrinterFonts
== NULL
)
298 pfnCallback
= MODULE_GetEntryPoint( GetModuleHandle16("GDI"), 158 );
300 if (pfnCallback
!= NULL
)
308 /* First count the number of fonts */
310 PRTDRV_EnumDFonts(physDev
->segptrPDEVICE
, NULL
, pfnCallback
,
313 /* Allocate a buffer to store all of the fonts */
314 pLPD
->nPrinterFonts
= wepfc
.nCount
;
315 dprintf_win16drv(stddeb
, "Got %d fonts\n",wepfc
.nCount
);
317 if (wepfc
.nCount
> 0)
320 pLPD
->paPrinterFonts
= malloc(sizeof(PRINTER_FONTS_INFO
) * wepfc
.nCount
);
322 /* Now get all of the fonts */
325 PRTDRV_EnumDFonts(physDev
->segptrPDEVICE
, NULL
, pfnCallback
,
331 /* Select the first font into the DC */
332 /* Set up the logfont */
334 &pLPD
->paPrinterFonts
[0].lf
,
337 /* Set up the textmetrics */
339 &pLPD
->paPrinterFonts
[0].tm
,
340 sizeof(TEXTMETRIC16
));
342 #ifdef SUPPORT_REALIZED_FONTS
343 /* TTD should calculate this */
344 InitTextXForm(&TextXForm
);
346 /* First get the size of the realized font */
347 nSize
= PRTDRV_RealizeObject(physDev
->segptrPDEVICE
, OBJ_FONT
,
348 &pLPD
->paPrinterFonts
[0], NULL
,
351 physDev
->segptrFontInfo
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nSize
));
352 /* Realize the font */
353 PRTDRV_RealizeObject(physDev
->segptrPDEVICE
, OBJ_FONT
,
354 &pLPD
->paPrinterFonts
[0],
355 (LPVOID
)physDev
->segptrFontInfo
,
357 /* Quick look at structure */
358 if (physDev
->segptrFontInfo
)
360 FONTINFO16
*p
= (FONTINFO16
*)PTR_SEG_TO_LIN(physDev
->segptrFontInfo
);
362 dprintf_win16drv(stddeb
, "T:%d VR:%d HR:%d, F:%d L:%d\n",
364 p
->dfVertRes
, p
->dfHorizRes
,
365 p
->dfFirstCHAR
, p
->dfLastCHAR
370 /* TTD Lots more to do here */
371 InitDrawMode(lpDrawMode
);
380 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
381 SEGPTR lpInData
, SEGPTR lpOutData
)
383 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
386 /* We should really process the nEscape parameter, but for now just
387 pass it all to the driver */
388 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
393 printf("Escape: SetAbortProc ignored\n");
397 LPEXTTEXTDATA textData
= PTR_SEG_TO_LIN(lpInData
);
398 printf("Got in data 0x%x textData 0x%x\n",lpInData
, textData
);
399 printf("size %d in 0x%x:0x%x font 0x%x:0x%x xform 0x%x:0x%x drawm 0x%x:0x%x\n",
401 textData
->lpindata
,PTR_SEG_TO_LIN(textData
->lpindata
),
402 textData
->lpFont
,PTR_SEG_TO_LIN(textData
->lpFont
),
403 textData
->lpXForm
,PTR_SEG_TO_LIN(textData
->lpXForm
),
404 textData
->lpDrawMode
,PTR_SEG_TO_LIN(textData
->lpDrawMode
));
408 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
409 lpInData
, lpOutData
);
413 fprintf(stderr
, "Escape(nEscape = %04x)\n", nEscape
);
420 /****************** misc. printer releated functions */
423 * The following function should implement a queing system
435 static struct hpq
*hpqueue
;
440 printf("CreatePQ: %d\n",size
);
446 printf("DeletePQ: %x\n", hPQ
);
452 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
454 currentPrev
= prev
= NULL
;
455 queue
= current
= hpqueue
;
461 currentPrev
= current
;
462 current
= current
->next
;
465 if (current
->key
< key
)
477 prev
->next
= queue
->next
;
479 hpqueue
= queue
->next
;
483 printf("ExtractPQ: %x got tag %d key %d\n", hPQ
, tag
, key
);
489 InsertPQ(HPQ hPQ
, int tag
, int key
)
491 struct hpq
*queueItem
= malloc(sizeof(struct hpq
));
492 queueItem
->next
= hpqueue
;
494 queueItem
->key
= key
;
495 queueItem
->tag
= tag
;
497 printf("InsertPQ: %x %d %d\n", hPQ
, tag
, key
);
503 printf("MinPQ: %x\n", hPQ
);
507 SizePQ(HPQ hPQ
, int sizechange
)
509 printf("SizePQ: %x %d\n", hPQ
, sizechange
);
514 * The following functions implement part of the spooling process to
515 * print manager. I would like to see wine have a version of print managers
516 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
519 typedef struct PRINTJOB
527 } PRINTJOB
, *PPRINTJOB
;
529 #define MAX_PRINT_JOBS 1
532 PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
535 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
537 return gPrintJobsTable
[0];
540 /* TTD Need to do some DOS->UNIX file conversion here */
541 static int CreateSpoolFile(LPSTR pszOutput
)
544 char szSpoolFile
[32];
546 /* TTD convert the 'output device' into a spool file name */
548 if (pszOutput
== NULL
|| *pszOutput
== '\0')
549 strcpy(szSpoolFile
,"lp.out");
551 strcpy(szSpoolFile
, pszOutput
);
553 if ((fd
= open(szSpoolFile
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600)) < 0)
555 printf("Failed to create spool file %s, errno = %d\n", szSpoolFile
, errno
);
560 static int FreePrintJob(HANDLE16 hJob
)
565 pPrintJob
= FindPrintJobFromHandle(hJob
);
566 if (pPrintJob
!= NULL
)
568 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
569 free(pPrintJob
->pszOutput
);
570 free(pPrintJob
->pszTitle
);
571 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
578 HANDLE16
OpenJob(LPSTR lpOutput
, LPSTR lpTitle
, HDC16 hDC
)
580 HANDLE16 hHandle
= SP_ERROR
;
583 dprintf_win16drv(stddeb
, "OpenJob: \"%s\" \"%s\" %04x\n", lpOutput
, lpTitle
, hDC
);
585 pPrintJob
= gPrintJobsTable
[0];
586 if (pPrintJob
== NULL
)
590 /* Try an create a spool file */
591 fd
= CreateSpoolFile(lpOutput
);
596 pPrintJob
= malloc(sizeof(PRINTJOB
));
597 memset(pPrintJob
, 0, sizeof(PRINTJOB
));
599 pPrintJob
->pszOutput
= strdup(lpOutput
);
600 pPrintJob
->pszTitle
= strdup(lpTitle
);
601 pPrintJob
->hDC
= hDC
;
603 pPrintJob
->nIndex
= 0;
604 pPrintJob
->hHandle
= hHandle
;
605 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
608 dprintf_win16drv(stddeb
, "OpenJob: return %04x\n", hHandle
);
612 int CloseJob(HANDLE16 hJob
)
615 PPRINTJOB pPrintJob
= NULL
;
617 dprintf_win16drv(stddeb
, "CloseJob: %04x\n", hJob
);
619 pPrintJob
= FindPrintJobFromHandle(hJob
);
620 if (pPrintJob
!= NULL
)
622 /* Close the spool file */
623 close(pPrintJob
->fd
);
630 int WriteSpool(HANDLE16 hJob
, LPSTR lpData
, WORD cch
)
633 PPRINTJOB pPrintJob
= NULL
;
635 dprintf_win16drv(stddeb
, "WriteSpool: %04x %08lx %04x\n", hJob
, (DWORD
)lpData
, cch
);
637 pPrintJob
= FindPrintJobFromHandle(hJob
);
638 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
640 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
648 int WriteDialog(HANDLE16 hJob
, LPSTR lpMsg
, WORD cchMsg
)
652 dprintf_win16drv(stddeb
, "WriteDialog: %04x %04x \"%s\"\n", hJob
, cchMsg
, lpMsg
);
654 nRet
= MessageBox16(NULL
, lpMsg
, "Printing Error", MB_OKCANCEL
);
658 int DeleteJob(HANDLE16 hJob
, WORD wNotUsed
)
662 dprintf_win16drv(stddeb
, "DeleteJob: %04x\n", hJob
);
664 nRet
= FreePrintJob(hJob
);
669 * The following two function would allow a page to be sent to the printer
670 * when it has been processed. For simplicity they havn't been implemented.
671 * This means a whole job has to be processed before it is sent to the printer.
673 int StartSpoolPage(HANDLE16 hJob
)
675 dprintf_win16drv(stddeb
, "StartSpoolPage GDI.246 unimplemented\n");
679 int EndSpoolPage(HANDLE16 hJob
)
681 dprintf_win16drv(stddeb
, "EndSpoolPage GDI.247 unimplemented\n");
686 DWORD
GetSpoolJob(int nOption
, LONG param
)
689 dprintf_win16drv(stddeb
, "In GetSpoolJob param 0x%lx noption %d\n",param
, nOption
);