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 */
70 WIN16DRV_LineTo
, /* pLineTo */
71 WIN16DRV_MoveToEx
, /* pMoveToEx */
72 NULL
, /* pOffsetClipRgn */
73 NULL
, /* pOffsetViewportOrgEx */
74 NULL
, /* pOffsetWindowOrgEx */
76 WIN16DRV_PatBlt
, /* pPatBlt */
78 NULL
, /* pPolyPolygon */
79 WIN16DRV_Polygon
, /* pPolygon */
81 NULL
, /* pRealizePalette */
82 WIN16DRV_Rectangle
, /* 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 WINAPI
WineEnumDFontCallback(LPLOGFONT16 lpLogFont
,
177 LPTEXTMETRIC16 lpTextMetrics
,
178 WORD wFontType
, LONG lpvClientData
)
181 WEPFC
*pWEPFC
= (WEPFC
*)lpvClientData
;
183 /* Make sure we have the right structure */
186 dprintf_win16drv(stddeb
, "mode is 0x%x\n",pWEPFC
->nMode
);
188 switch (pWEPFC
->nMode
)
190 /* Count how many fonts */
195 /* Store the fonts in the printer driver structure */
198 PRINTER_FONTS_INFO
*pPFI
;
200 dprintf_win16drv(stddeb
, "WineEnumDFontCallback: Found %s %x\n",
201 lpLogFont
->lfFaceName
, wFontType
);
203 pPFI
= &pWEPFC
->pLPD
->paPrinterFonts
[pWEPFC
->nCount
];
204 memcpy(&(pPFI
->lf
), lpLogFont
, sizeof(LOGFONT16
));
205 memcpy(&(pPFI
->tm
), lpTextMetrics
, sizeof(TEXTMETRIC16
));
213 dprintf_win16drv(stddeb
, "WineEnumDFontCallback: returnd %d\n", wRet
);
217 BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
218 const DEVMODE16
* initData
)
220 LOADED_PRINTER_DRIVER
*pLPD
;
222 DeviceCaps
*printerDevCaps
;
223 FARPROC16 pfnCallback
;
225 PDEVICE_HEADER
*pPDH
;
226 WIN16DRV_PDEVICE
*physDev
;
228 /* Realizing fonts */
230 char printerEnabled
[20];
231 PROFILE_GetWineIniString( "wine", "printer", "off",
232 printerEnabled
, sizeof(printerEnabled
) );
233 if (lstrcmpi32A(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
*)((BYTE
*)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
,
327 numFonts
= wepfc
.nCount
;
331 /* If the number of fonts returned are zero we can not continue */
332 fprintf( stderr
, "No fonts? Aborting CreateDC...\n");
338 /* Select the first font into the DC */
339 /* Set up the logfont */
341 &pLPD
->paPrinterFonts
[0].lf
,
344 /* Set up the textmetrics */
346 &pLPD
->paPrinterFonts
[0].tm
,
347 sizeof(TEXTMETRIC16
));
349 win16drv_SegPtr_TextXForm
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
350 win16drv_TextXFormP
= PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm
);
352 InitTextXForm(win16drv_TextXFormP
);
353 #ifdef SUPPORT_REALIZED_FONTS
354 /* TTD should calculate this */
356 /* First get the size of the realized font */
357 nSize
= PRTDRV_RealizeObject(physDev
->segptrPDEVICE
, DRVOBJ_FONT
,
358 &pLPD
->paPrinterFonts
[0], NULL
,
361 physDev
->segptrFontInfo
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nSize
));
362 /* Realize the font */
363 PRTDRV_RealizeObject(physDev
->segptrPDEVICE
, DRVOBJ_FONT
,
364 &pLPD
->paPrinterFonts
[0],
365 (LPVOID
)physDev
->segptrFontInfo
,
366 win16drv_SegPtr_TextXForm
);
367 /* Quick look at structure */
368 if (physDev
->segptrFontInfo
)
370 FONTINFO16
*p
= (FONTINFO16
*)PTR_SEG_TO_LIN(physDev
->segptrFontInfo
);
372 dprintf_win16drv(stddeb
, "T:%d VR:%d HR:%d, F:%d L:%d\n",
374 p
->dfVertRes
, p
->dfHorizRes
,
375 p
->dfFirstCHAR
, p
->dfLastCHAR
380 /* TTD Lots more to do here */
381 win16drv_SegPtr_DrawMode
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
382 win16drv_DrawModeP
= PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode
);
384 InitDrawMode(win16drv_DrawModeP
);
389 BOOL32
WIN16DRV_PatBlt( struct tagDC
*dc
, INT32 left
, INT32 top
,
390 INT32 width
, INT32 height
, DWORD rop
)
393 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
396 bRet
= PRTDRV_StretchBlt( physDev
->segptrPDEVICE
, left
, top
, width
, height
, NULL
, 0, 0, width
, height
,
397 PATCOPY
, physDev
->segptrBrushInfo
, win16drv_SegPtr_DrawMode
, NULL
);
404 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
405 SEGPTR lpInData
, SEGPTR lpOutData
)
407 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
410 /* We should really process the nEscape parameter, but for now just
411 pass it all to the driver */
412 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
416 case ENABLEPAIRKERNING
:
417 fprintf(stderr
,"Escape: ENABLEPAIRKERNING ignored.\n");
421 printf("Escape: SetAbortProc ignored should be stored in dc somewhere\n");
422 /* Make calling application believe this worked */
428 LPPOINT16 newInData
= SEGPTR_NEW(POINT16
);
430 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
431 SEGPTR_GET(newInData
), lpOutData
);
432 SEGPTR_FREE(newInData
);
436 case GETEXTENDEDTEXTMETRICS
:
438 EXTTEXTDATA
*textData
= SEGPTR_NEW(EXTTEXTDATA
);
440 textData
->nSize
= cbInput
;
441 textData
->lpindata
= lpInData
;
442 textData
->lpFont
= physDev
->segptrFontInfo
;
443 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
444 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
445 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
446 SEGPTR_GET(textData
), lpOutData
);
447 SEGPTR_FREE(textData
);
451 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
452 lpInData
, lpOutData
);
455 HDC32
*tmpHdc
= SEGPTR_NEW(HDC32
);
457 #define SETPRINTERDC SETABORTPROC
460 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
461 SEGPTR_GET(tmpHdc
), (SEGPTR
)NULL
);
466 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
467 lpInData
, lpOutData
);
472 fprintf(stderr
, "Escape(nEscape = %04x)\n", nEscape
);
479 /****************** misc. printer releated functions */
482 * The following function should implement a queing system
494 static struct hpq
*hpqueue
;
496 HPQ WINAPI
CreatePQ(int size
)
498 printf("CreatePQ: %d\n",size
);
501 int WINAPI
DeletePQ(HPQ hPQ
)
503 printf("DeletePQ: %x\n", hPQ
);
506 int WINAPI
ExtractPQ(HPQ hPQ
)
508 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
509 int key
= 0, tag
= -1;
510 currentPrev
= prev
= NULL
;
511 queue
= current
= hpqueue
;
517 currentPrev
= current
;
518 current
= current
->next
;
521 if (current
->key
< key
)
533 prev
->next
= queue
->next
;
535 hpqueue
= queue
->next
;
539 printf("ExtractPQ: %x got tag %d key %d\n", hPQ
, tag
, key
);
544 int WINAPI
InsertPQ(HPQ hPQ
, int tag
, int key
)
546 struct hpq
*queueItem
= malloc(sizeof(struct hpq
));
547 queueItem
->next
= hpqueue
;
549 queueItem
->key
= key
;
550 queueItem
->tag
= tag
;
552 printf("InsertPQ: %x %d %d\n", hPQ
, tag
, key
);
555 int WINAPI
MinPQ(HPQ hPQ
)
557 printf("MinPQ: %x\n", hPQ
);
560 int WINAPI
SizePQ(HPQ hPQ
, int sizechange
)
562 printf("SizePQ: %x %d\n", hPQ
, sizechange
);
567 * The following functions implement part of the spooling process to
568 * print manager. I would like to see wine have a version of print managers
569 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
572 typedef struct PRINTJOB
580 } PRINTJOB
, *PPRINTJOB
;
582 #define MAX_PRINT_JOBS 1
585 PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
588 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
590 return gPrintJobsTable
[0];
593 /* TTD Need to do some DOS->UNIX file conversion here */
594 static int CreateSpoolFile(LPSTR pszOutput
)
598 char *psCmdP
= psCmd
;
600 /* TTD convert the 'output device' into a spool file name */
602 if (pszOutput
== NULL
|| *pszOutput
== '\0')
605 PROFILE_GetWineIniString( "spooler", pszOutput
, "",
606 psCmd
, sizeof(psCmd
) );
607 printf("Got printerSpoolCommand \"%s\"\n",psCmd
);
612 while (*psCmdP
&& isspace(*psCmdP
))
628 printf("In child need to exec %s\n",psCmdP
);
638 printf("Need to execute a command and pipe the output to it\n");
642 printf("Just assume its a file\n");
644 if ((fd
= open(psCmdP
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600)) < 0)
646 printf("Failed to create spool file %s, errno = %d\n", psCmdP
, errno
);
652 static int FreePrintJob(HANDLE16 hJob
)
657 pPrintJob
= FindPrintJobFromHandle(hJob
);
658 if (pPrintJob
!= NULL
)
660 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
661 free(pPrintJob
->pszOutput
);
662 free(pPrintJob
->pszTitle
);
663 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
670 HANDLE16 WINAPI
OpenJob(LPSTR lpOutput
, LPSTR lpTitle
, HDC16 hDC
)
672 HANDLE16 hHandle
= (HANDLE16
)SP_ERROR
;
675 dprintf_win16drv(stddeb
, "OpenJob: \"%s\" \"%s\" %04x\n", lpOutput
, lpTitle
, hDC
);
677 pPrintJob
= gPrintJobsTable
[0];
678 if (pPrintJob
== NULL
)
682 /* Try an create a spool file */
683 fd
= CreateSpoolFile(lpOutput
);
688 pPrintJob
= malloc(sizeof(PRINTJOB
));
689 memset(pPrintJob
, 0, sizeof(PRINTJOB
));
691 pPrintJob
->pszOutput
= strdup(lpOutput
);
692 pPrintJob
->pszTitle
= strdup(lpTitle
);
693 pPrintJob
->hDC
= hDC
;
695 pPrintJob
->nIndex
= 0;
696 pPrintJob
->hHandle
= hHandle
;
697 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
700 dprintf_win16drv(stddeb
, "OpenJob: return %04x\n", hHandle
);
704 int WINAPI
CloseJob(HANDLE16 hJob
)
707 PPRINTJOB pPrintJob
= NULL
;
709 dprintf_win16drv(stddeb
, "CloseJob: %04x\n", hJob
);
711 pPrintJob
= FindPrintJobFromHandle(hJob
);
712 if (pPrintJob
!= NULL
)
714 /* Close the spool file */
715 close(pPrintJob
->fd
);
722 int WINAPI
WriteSpool(HANDLE16 hJob
, LPSTR lpData
, WORD cch
)
725 PPRINTJOB pPrintJob
= NULL
;
727 dprintf_win16drv(stddeb
, "WriteSpool: %04x %08lx %04x\n", hJob
, (DWORD
)lpData
, cch
);
729 pPrintJob
= FindPrintJobFromHandle(hJob
);
730 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
732 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
740 int WINAPI
WriteDialog(HANDLE16 hJob
, LPSTR lpMsg
, WORD cchMsg
)
744 dprintf_win16drv(stddeb
, "WriteDialog: %04x %04x \"%s\"\n", hJob
, cchMsg
, lpMsg
);
746 nRet
= MessageBox16(0, lpMsg
, "Printing Error", MB_OKCANCEL
);
750 int WINAPI
DeleteJob(HANDLE16 hJob
, WORD wNotUsed
)
754 dprintf_win16drv(stddeb
, "DeleteJob: %04x\n", hJob
);
756 nRet
= FreePrintJob(hJob
);
761 * The following two function would allow a page to be sent to the printer
762 * when it has been processed. For simplicity they havn't been implemented.
763 * This means a whole job has to be processed before it is sent to the printer.
765 int WINAPI
StartSpoolPage(HANDLE16 hJob
)
767 dprintf_win16drv(stddeb
, "StartSpoolPage GDI.246 unimplemented\n");
771 int WINAPI
EndSpoolPage(HANDLE16 hJob
)
773 dprintf_win16drv(stddeb
, "EndSpoolPage GDI.247 unimplemented\n");
778 DWORD WINAPI
GetSpoolJob(int nOption
, LONG param
)
781 dprintf_win16drv(stddeb
, "In GetSpoolJob param 0x%lx noption %d\n",param
, nOption
);