2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
26 #define SUPPORT_REALIZED_FONTS 1
35 } EXTTEXTDATA
, *LPEXTTEXTDATA
;
38 SEGPTR win16drv_SegPtr_TextXForm
;
39 LPTEXTXFORM16 win16drv_TextXFormP
;
40 SEGPTR win16drv_SegPtr_DrawMode
;
41 LPDRAWMODE win16drv_DrawModeP
;
44 static BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
45 LPCSTR output
, const DEVMODE16
* initData
);
46 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
47 SEGPTR lpInData
, SEGPTR lpOutData
);
49 static const DC_FUNCTIONS WIN16DRV_Funcs
=
54 WIN16DRV_CreateDC
, /* pCreateDC */
56 NULL
, /* pDeleteObject */
58 NULL
, /* pEnumDeviceFonts */
59 WIN16DRV_Escape
, /* pEscape */
60 NULL
, /* pExcludeClipRect */
61 NULL
, /* pExcludeVisRect */
62 NULL
, /* pExtFloodFill */
63 WIN16DRV_ExtTextOut
, /* pExtTextOut */
64 WIN16DRV_GetCharWidth
, /* pGetCharWidth */
66 WIN16DRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
67 WIN16DRV_GetTextMetrics
, /* pGetTextMetrics */
68 NULL
, /* pIntersectClipRect */
69 NULL
, /* pIntersectVisRect */
72 NULL
, /* pOffsetClipRgn */
73 NULL
, /* pOffsetViewportOrgEx */
74 NULL
, /* pOffsetWindowOrgEx */
76 WIN16DRV_PatBlt
, /* pPatBlt */
78 NULL
, /* pPolyPolygon */
81 NULL
, /* pRealizePalette */
82 NULL
, /* pRectangle */
83 NULL
, /* pRestoreDC */
84 NULL
, /* pRoundRect */
86 NULL
, /* pScaleViewportExtEx */
87 NULL
, /* pScaleWindowExtEx */
88 NULL
, /* pSelectClipRgn */
89 WIN16DRV_SelectObject
, /* pSelectObject */
90 NULL
, /* pSelectPalette */
91 NULL
, /* pSetBkColor */
92 NULL
, /* pSetBkMode */
93 NULL
, /* pSetDeviceClipping */
94 NULL
, /* pSetDIBitsToDevice */
95 NULL
, /* pSetMapMode */
96 NULL
, /* pSetMapperFlags */
98 NULL
, /* pSetPolyFillMode */
100 NULL
, /* pSetRelAbs */
101 NULL
, /* pSetStretchBltMode */
102 NULL
, /* pSetTextAlign */
103 NULL
, /* pSetTextCharacterExtra */
104 NULL
, /* pSetTextColor */
105 NULL
, /* pSetTextJustification */
106 NULL
, /* pSetViewportExtEx */
107 NULL
, /* pSetViewportOrgEx */
108 NULL
, /* pSetWindowExtEx */
109 NULL
, /* pSetWindowOrgEx */
110 NULL
, /* pStretchBlt */
111 NULL
/* pStretchDIBits */
118 /**********************************************************************
121 BOOL32
WIN16DRV_Init(void)
123 return DRIVER_RegisterDriver( NULL
/* generic driver */, &WIN16DRV_Funcs
);
127 /* Tempory functions, for initialising structures */
128 /* These values should be calculated, not hardcoded */
129 void InitTextXForm(LPTEXTXFORM16 lpTextXForm
)
131 lpTextXForm
->txfHeight
= 0x0001;
132 lpTextXForm
->txfWidth
= 0x000c;
133 lpTextXForm
->txfEscapement
= 0x0000;
134 lpTextXForm
->txfOrientation
= 0x0000;
135 lpTextXForm
->txfWeight
= 0x0190;
136 lpTextXForm
->txfItalic
= 0x00;
137 lpTextXForm
->txfUnderline
= 0x00;
138 lpTextXForm
->txfStrikeOut
= 0x00;
139 lpTextXForm
->txfOutPrecision
= 0x02;
140 lpTextXForm
->txfClipPrecision
= 0x01;
141 lpTextXForm
->txfAccelerator
= 0x0001;
142 lpTextXForm
->txfOverhang
= 0x0000;
146 void InitDrawMode(LPDRAWMODE lpDrawMode
)
148 lpDrawMode
->Rop2
= 0x000d;
149 lpDrawMode
->bkMode
= 0x0001;
150 lpDrawMode
->bkColor
= 0x3fffffff;
151 lpDrawMode
->TextColor
= 0x20000000;
152 lpDrawMode
->TBreakExtra
= 0x0000;
153 lpDrawMode
->BreakExtra
= 0x0000;
154 lpDrawMode
->BreakErr
= 0x0000;
155 lpDrawMode
->BreakRem
= 0x0000;
156 lpDrawMode
->BreakCount
= 0x0000;
157 lpDrawMode
->CharExtra
= 0x0000;
158 lpDrawMode
->LbkColor
= 0x00ffffff;
159 lpDrawMode
->LTextColor
= 0x00000000;
163 * EnumCallback (GDI.158)
165 * This is the callback function used when EnumDFonts is called.
166 * (The printer drivers uses it to pass info on available fonts).
168 * lpvClientData is the pointer passed to EnumDFonts, which points to a WEPFC
169 * structure (WEPFC = WINE_ENUM_PRINTER_FONT_CALLBACK). This structure
170 * contains infomation on how to store the data passed .
172 * There are two modes:
173 * 1) Just count the number of fonts available.
174 * 2) Store all font data passed.
176 WORD
WineEnumDFontCallback(LPLOGFONT16 lpLogFont
, LPTEXTMETRIC16 lpTextMetrics
,
177 WORD wFontType
, LONG lpvClientData
)
180 WEPFC
*pWEPFC
= (WEPFC
*)lpvClientData
;
182 /* Make sure we have the right structure */
185 dprintf_win16drv(stddeb
, "mode is 0x%x\n",pWEPFC
->nMode
);
187 switch (pWEPFC
->nMode
)
189 /* Count how many fonts */
194 /* Store the fonts in the printer driver structure */
197 PRINTER_FONTS_INFO
*pPFI
;
199 dprintf_win16drv(stddeb
, "WineEnumDFontCallback: Found %s %x\n",
200 lpLogFont
->lfFaceName
, wFontType
);
202 pPFI
= &pWEPFC
->pLPD
->paPrinterFonts
[pWEPFC
->nCount
];
203 memcpy(&(pPFI
->lf
), lpLogFont
, sizeof(LOGFONT16
));
204 memcpy(&(pPFI
->tm
), lpTextMetrics
, sizeof(TEXTMETRIC16
));
212 dprintf_win16drv(stddeb
, "WineEnumDFontCallback: returnd %d\n", wRet
);
216 BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
217 const DEVMODE16
* initData
)
219 LOADED_PRINTER_DRIVER
*pLPD
;
221 DeviceCaps
*printerDevCaps
;
222 FARPROC16 pfnCallback
;
224 PDEVICE_HEADER
*pPDH
;
225 WIN16DRV_PDEVICE
*physDev
;
227 /* Realizing fonts */
229 char printerEnabled
[20];
230 PROFILE_GetWineIniString( "wine", "printer", "off",
231 printerEnabled
, sizeof(printerEnabled
) );
232 if (lstrcmpi32A(printerEnabled
,"on"))
234 printf("WIN16DRV_CreateDC disabled in wine.conf file\n");
238 dprintf_win16drv(stddeb
, "In creatdc for (%s,%s,%s) initData 0x%p\n",driver
, device
, output
, initData
);
240 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( SystemHeap
, 0, sizeof(*physDev
) );
241 if (!physDev
) return FALSE
;
242 dc
->physDev
= physDev
;
244 pLPD
= LoadPrinterDriver(driver
);
247 dprintf_win16drv(stddeb
, "LPGDI_CreateDC: Failed to find printer driver\n");
248 HeapFree( SystemHeap
, 0, physDev
);
251 dprintf_win16drv(stddeb
, "windevCreateDC pLPD 0x%p\n", pLPD
);
253 /* Now Get the device capabilities from the printer driver */
255 printerDevCaps
= (DeviceCaps
*) malloc(sizeof(DeviceCaps
));
256 memset(printerDevCaps
, 0, sizeof(DeviceCaps
));
258 /* Get GDIINFO which is the same as a DeviceCaps structure */
259 wRet
= PRTDRV_Enable(printerDevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
261 /* Add this to the DC */
262 dc
->w
.devCaps
= printerDevCaps
;
263 dc
->w
.hVisRgn
= CreateRectRgn32(0, 0, dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
);
264 dc
->w
.bitsPerPixel
= dc
->w
.devCaps
->bitsPixel
;
266 printf("Got devcaps width %d height %d bits %d planes %d\n",
267 dc
->w
.devCaps
->horzRes
,
268 dc
->w
.devCaps
->vertRes
,
269 dc
->w
.devCaps
->bitsPixel
,
270 dc
->w
.devCaps
->planes
);
272 /* Now we allocate enough memory for the PDEVICE structure */
273 /* The size of this varies between printer drivers */
274 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
275 /* be accessable from 16 bit code */
276 nPDEVICEsize
= dc
->w
.devCaps
->pdeviceSize
+ sizeof(PDEVICE_HEADER
);
278 /* TTD Shouldn't really do pointer arithmetic on segment points */
279 physDev
->segptrPDEVICE
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
280 *(BYTE
*)(PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+0) = 'N';
281 *(BYTE
*)(PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+1) = 'B';
283 /* Set up the header */
284 pPDH
= (PDEVICE_HEADER
*)(PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
287 dprintf_win16drv(stddeb
, "PRTDRV_Enable: PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
289 /* Now get the printer driver to initialise this data */
290 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
292 /* Now enumerate the fonts supported by the printer driver*/
293 /* GDI.158 is EnumCallback, which is called by the 16bit printer driver */
294 /* passing information on the available fonts */
295 if (pLPD
->paPrinterFonts
== NULL
)
297 pfnCallback
= MODULE_GetEntryPoint( GetModuleHandle16("GDI"), 158 );
299 if (pfnCallback
!= NULL
)
307 /* First count the number of fonts */
309 PRTDRV_EnumDFonts(physDev
->segptrPDEVICE
, NULL
, pfnCallback
,
312 /* Allocate a buffer to store all of the fonts */
313 pLPD
->nPrinterFonts
= wepfc
.nCount
;
314 dprintf_win16drv(stddeb
, "Got %d fonts\n",wepfc
.nCount
);
316 if (wepfc
.nCount
> 0)
319 pLPD
->paPrinterFonts
= malloc(sizeof(PRINTER_FONTS_INFO
) * wepfc
.nCount
);
321 /* Now get all of the fonts */
324 PRTDRV_EnumDFonts(physDev
->segptrPDEVICE
, NULL
, pfnCallback
,
326 numFonts
= wepfc
.nCount
;
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 win16drv_SegPtr_TextXForm
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
343 win16drv_TextXFormP
= PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm
);
345 InitTextXForm(win16drv_TextXFormP
);
346 #ifdef SUPPORT_REALIZED_FONTS
347 /* TTD should calculate this */
349 /* First get the size of the realized font */
350 nSize
= PRTDRV_RealizeObject(physDev
->segptrPDEVICE
, OBJ_FONT
,
351 &pLPD
->paPrinterFonts
[0], NULL
,
354 physDev
->segptrFontInfo
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nSize
));
355 /* Realize the font */
356 PRTDRV_RealizeObject(physDev
->segptrPDEVICE
, OBJ_FONT
,
357 &pLPD
->paPrinterFonts
[0],
358 (LPVOID
)physDev
->segptrFontInfo
,
359 win16drv_SegPtr_TextXForm
);
360 /* Quick look at structure */
361 if (physDev
->segptrFontInfo
)
363 FONTINFO16
*p
= (FONTINFO16
*)PTR_SEG_TO_LIN(physDev
->segptrFontInfo
);
365 dprintf_win16drv(stddeb
, "T:%d VR:%d HR:%d, F:%d L:%d\n",
367 p
->dfVertRes
, p
->dfHorizRes
,
368 p
->dfFirstCHAR
, p
->dfLastCHAR
373 /* TTD Lots more to do here */
374 win16drv_SegPtr_DrawMode
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
375 win16drv_DrawModeP
= PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode
);
377 InitDrawMode(win16drv_DrawModeP
);
382 extern BOOL32
WIN16DRV_PatBlt( struct tagDC
*dc
, INT32 left
, INT32 top
,
383 INT32 width
, INT32 height
, DWORD rop
)
385 printf("In WIN16DRV_PatBlt\n");
391 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
392 SEGPTR lpInData
, SEGPTR lpOutData
)
394 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
397 /* We should really process the nEscape parameter, but for now just
398 pass it all to the driver */
399 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
404 printf("Escape: SetAbortProc ignored should be stored in dc somewhere\n");
405 /* Make calling application believe this worked */
411 SEGPTR newInData
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(POINT16
)));
412 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
413 newInData
, lpOutData
);
414 GlobalFree16(newInData
);
418 case GETEXTENDEDTEXTMETRICS
:
420 SEGPTR newInData
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(EXTTEXTDATA
)));
421 EXTTEXTDATA
*textData
= (EXTTEXTDATA
*)(PTR_SEG_TO_LIN(newInData
));
423 textData
->nSize
= cbInput
;
424 textData
->lpindata
= lpInData
;
425 textData
->lpFont
= physDev
->segptrFontInfo
;
426 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
427 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
428 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
429 newInData
, lpOutData
);
430 GlobalFree16(newInData
);
435 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
436 lpInData
, lpOutData
);
439 SEGPTR newInData
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(HDC32
)));
440 #define SETPRINTERDC SETABORTPROC
441 HDC32
*tmpHdc
= (HDC32
*)(PTR_SEG_TO_LIN(newInData
));
443 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
444 newInData
, (SEGPTR
)NULL
);
445 GlobalFree16(newInData
);
449 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
450 lpInData
, lpOutData
);
455 fprintf(stderr
, "Escape(nEscape = %04x)\n", nEscape
);
462 /****************** misc. printer releated functions */
465 * The following function should implement a queing system
477 static struct hpq
*hpqueue
;
482 printf("CreatePQ: %d\n",size
);
488 printf("DeletePQ: %x\n", hPQ
);
494 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
495 int key
= 0, tag
= -1;
496 currentPrev
= prev
= NULL
;
497 queue
= current
= hpqueue
;
503 currentPrev
= current
;
504 current
= current
->next
;
507 if (current
->key
< key
)
519 prev
->next
= queue
->next
;
521 hpqueue
= queue
->next
;
525 printf("ExtractPQ: %x got tag %d key %d\n", hPQ
, tag
, key
);
531 InsertPQ(HPQ hPQ
, int tag
, int key
)
533 struct hpq
*queueItem
= malloc(sizeof(struct hpq
));
534 queueItem
->next
= hpqueue
;
536 queueItem
->key
= key
;
537 queueItem
->tag
= tag
;
539 printf("InsertPQ: %x %d %d\n", hPQ
, tag
, key
);
545 printf("MinPQ: %x\n", hPQ
);
549 SizePQ(HPQ hPQ
, int sizechange
)
551 printf("SizePQ: %x %d\n", hPQ
, sizechange
);
556 * The following functions implement part of the spooling process to
557 * print manager. I would like to see wine have a version of print managers
558 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
561 typedef struct PRINTJOB
569 } PRINTJOB
, *PPRINTJOB
;
571 #define MAX_PRINT_JOBS 1
574 PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
577 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
579 return gPrintJobsTable
[0];
582 /* TTD Need to do some DOS->UNIX file conversion here */
583 static int CreateSpoolFile(LPSTR pszOutput
)
587 char *psCmdP
= psCmd
;
589 /* TTD convert the 'output device' into a spool file name */
591 if (pszOutput
== NULL
|| *pszOutput
== '\0')
594 PROFILE_GetWineIniString( "spooler", pszOutput
, "",
595 psCmd
, sizeof(psCmd
) );
596 printf("Got printerSpoolCOmmand \"%s\"\n",psCmd
);
601 while (*psCmdP
&& isspace(*psCmdP
))
617 printf("In child need to exec %s\n",psCmdP
);
627 printf("Need to execut a command and pipe the output to it\n");
631 printf("Just assume its a file\n");
633 if ((fd
= open(psCmdP
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600)) < 0)
635 printf("Failed to create spool file %s, errno = %d\n", psCmdP
, errno
);
641 static int FreePrintJob(HANDLE16 hJob
)
646 pPrintJob
= FindPrintJobFromHandle(hJob
);
647 if (pPrintJob
!= NULL
)
649 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
650 free(pPrintJob
->pszOutput
);
651 free(pPrintJob
->pszTitle
);
652 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
659 HANDLE16
OpenJob(LPSTR lpOutput
, LPSTR lpTitle
, HDC16 hDC
)
661 HANDLE16 hHandle
= SP_ERROR
;
664 dprintf_win16drv(stddeb
, "OpenJob: \"%s\" \"%s\" %04x\n", lpOutput
, lpTitle
, hDC
);
666 pPrintJob
= gPrintJobsTable
[0];
667 if (pPrintJob
== NULL
)
671 /* Try an create a spool file */
672 fd
= CreateSpoolFile(lpOutput
);
677 pPrintJob
= malloc(sizeof(PRINTJOB
));
678 memset(pPrintJob
, 0, sizeof(PRINTJOB
));
680 pPrintJob
->pszOutput
= strdup(lpOutput
);
681 pPrintJob
->pszTitle
= strdup(lpTitle
);
682 pPrintJob
->hDC
= hDC
;
684 pPrintJob
->nIndex
= 0;
685 pPrintJob
->hHandle
= hHandle
;
686 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
689 dprintf_win16drv(stddeb
, "OpenJob: return %04x\n", hHandle
);
693 int CloseJob(HANDLE16 hJob
)
696 PPRINTJOB pPrintJob
= NULL
;
698 dprintf_win16drv(stddeb
, "CloseJob: %04x\n", hJob
);
700 pPrintJob
= FindPrintJobFromHandle(hJob
);
701 if (pPrintJob
!= NULL
)
703 /* Close the spool file */
704 close(pPrintJob
->fd
);
711 int WriteSpool(HANDLE16 hJob
, LPSTR lpData
, WORD cch
)
714 PPRINTJOB pPrintJob
= NULL
;
716 dprintf_win16drv(stddeb
, "WriteSpool: %04x %08lx %04x\n", hJob
, (DWORD
)lpData
, cch
);
718 pPrintJob
= FindPrintJobFromHandle(hJob
);
719 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
721 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
729 int WriteDialog(HANDLE16 hJob
, LPSTR lpMsg
, WORD cchMsg
)
733 dprintf_win16drv(stddeb
, "WriteDialog: %04x %04x \"%s\"\n", hJob
, cchMsg
, lpMsg
);
735 nRet
= MessageBox16(0, lpMsg
, "Printing Error", MB_OKCANCEL
);
739 int DeleteJob(HANDLE16 hJob
, WORD wNotUsed
)
743 dprintf_win16drv(stddeb
, "DeleteJob: %04x\n", hJob
);
745 nRet
= FreePrintJob(hJob
);
750 * The following two function would allow a page to be sent to the printer
751 * when it has been processed. For simplicity they havn't been implemented.
752 * This means a whole job has to be processed before it is sent to the printer.
754 int StartSpoolPage(HANDLE16 hJob
)
756 dprintf_win16drv(stddeb
, "StartSpoolPage GDI.246 unimplemented\n");
760 int EndSpoolPage(HANDLE16 hJob
)
762 dprintf_win16drv(stddeb
, "EndSpoolPage GDI.247 unimplemented\n");
767 DWORD
GetSpoolJob(int nOption
, LONG param
)
770 dprintf_win16drv(stddeb
, "In GetSpoolJob param 0x%lx noption %d\n",param
, nOption
);