summaryrefslogtreecommitdiffstats
path: root/private/mvdm/wow16/write/print3.c
blob: abbecc0ab55a1e4b23c6a285a8c17b4ff9cf2313 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/************************************************************/
/* Windows Write, Copyright 1985-1992 Microsoft Corporation */
/************************************************************/

/* These routines are the guts of the graphics print code. */

#define	NOGDICAPMASKS
#define	NOVIRTUALKEYCODES
#define	NOWINMESSAGES
#define	NOWINSTYLES
#define	NOSYSMETRICS
#define	NOICON
#define	NOKEYSTATE
#define	NOSYSCOMMANDS
#define	NOSHOWWINDOW
//#define	NOATOM
#define	NOFONT
#define	NOBRUSH
#define	NOCLIPBOARD
#define	NOCOLOR
#define	NOCREATESTRUCT
#define	NOCTLMGR
#define	NODRAWTEXT
#define	NOMB
#define	NOOPENFILE
#define	NOPEN
#define	NOREGION
#define	NOSCROLL
#define	NOSOUND
#define	NOWH
#define	NOWINOFFSETS
#define	NOWNDCLASS
#define	NOCOMM
#include <windows.h>
#include "mw.h"
#include "printdef.h"
#include "fmtdefs.h"
#include "docdefs.h"
#define	NOKCCODES
#include "winddefs.h"
#include "debug.h"
#include "str.h"
#if defined(OLE)
#include "obj.h"
#endif

PrintGraphics(xpPrint, ypPrint)
int	xpPrint;
int	ypPrint;
	{
	/* This	routine	prints the picture in the vfli structure at	position
	(xpPrint, ypPrint).	*/

	extern HDC vhDCPrinter;
	extern struct FLI vfli;
	extern struct DOD (**hpdocdod)[];
	extern int dxpPrPage;
	extern int dypPrPage;
	extern FARPROC lpFPrContinue;

	typeCP cp;
	typeCP cpMac = (**hpdocdod)[vfli.doc].cpMac;
	struct PICINFOX	picInfo;
	HANDLE hBits = NULL;
	HDC	hMDC = NULL;
	HBITMAP	hbm	= NULL;
	LPCH lpBits;
	int	cchRun;
	unsigned long cbPict = 0;
	int	dxpOrig;		/* Size	of picture in the original */
	int	dypOrig;
	int	dxpDisplay;		/* Size	of picture as we want to show it */
	int	dypDisplay;
	BOOL fRescale;
	BOOL fBitmap;
	BOOL fPrint	= FALSE;
	int	iLevel = 0;
    RECT bounds;

	Assert(vhDCPrinter);
    GetPicInfo(vfli.cpMin, cpMac, vfli.doc,	&picInfo);

	/* Compute desired display size	of picture (in device pixels) */
	dxpDisplay = vfli.xpReal - vfli.xpLeft;
	dypDisplay = vfli.dypLine;

	/* Compute original	size of	picture	(in	device pixels) */
	/* MM_ANISOTROPIC and MM_ISOTROPIC pictures	have no	original size */

	fRescale = FALSE;
	switch (picInfo.mfp.mm)
		{
	case MM_ISOTROPIC:
	case MM_ANISOTROPIC:
		break;

#if defined(OLE)
    case MM_OLE:
        if (lpOBJ_QUERY_INFO(&picInfo) == NULL)
                goto DontDraw;

        if (lpOBJ_QUERY_OBJECT(&picInfo) == NULL)
                goto DontDraw;
    break;
#endif

	case MM_BITMAP:
		dxpOrig	= picInfo.bm.bmWidth;
		dypOrig	= picInfo.bm.bmHeight;
		break;

	default:
		dxpOrig	= PxlConvert(picInfo.mfp.mm, picInfo.mfp.xExt, dxpPrPage,
		  GetDeviceCaps(vhDCPrinter, HORZSIZE));
		dypOrig	= PxlConvert(picInfo.mfp.mm, picInfo.mfp.yExt, dypPrPage,
		  GetDeviceCaps(vhDCPrinter, VERTSIZE));
		if (dxpOrig	== 0 ||	dypOrig	== 0)
			{
#ifdef DPRINT            
            CommSz("PrintGraphics: nodraw because dxpOrig==0 | dypOrig==0\r\n");
#endif
			goto DontDraw;
			}
		fRescale = (dxpOrig	!= dxpDisplay) || (dypOrig != dypDisplay);
		break;
		}

	/* Get a handle	to a global	object large enough	to hold	the	picture. */
    if (picInfo.mfp.mm != MM_OLE)
    {
	if ((hBits = GlobalAlloc(GMEM_MOVEABLE,	(long)picInfo.cbSize)) == NULL)
		{
		/* Not enough global heap space	to load	bitmap/metafile	*/
#ifdef DPRINT        
        CommSz("PrintGraphics: nodraw because not enough mem to alloc\r\n");
#endif
		goto DontDraw;
		}

	/* Build up	all	bytes associated with the picture (except the header) into
	the	global handle hBits	*/
	for	(cbPict	= 0, cp	= vfli.cpMin + picInfo.cbHeader; cbPict	<
	  picInfo.cbSize; cbPict +=	cchRun,	cp += cchRun)
		{
		CHAR rgch[256];
		LPCH lpch;

		#define	ulmin(a,b)	((a) < (b) ? (a) : (b))

		FetchRgch(&cchRun, rgch, vfli.doc, cp, cpMac, (int)ulmin(picInfo.cbSize
		  -	cbPict,	256));

		if ((lpch =	GlobalLock(hBits)) == NULL)
			{
#ifdef DPRINT            
            CommSz("PrintGraphics: nodraw because couldn't lock\r\n");
#endif
			goto DontDraw;
			}

		bltbx((LPSTR)rgch, lpch	+ cbPict, cchRun);
		GlobalUnlock(hBits);
		}
    }

	/* Save	the	printer	DC as a	guard against DC attribute alteration by a
	metafile */
	iLevel = SaveDC(vhDCPrinter);

	fBitmap	= picInfo.mfp.mm ==	MM_BITMAP;

#if defined(OLE)
        /* CASE 0: OLE */
        if (picInfo.mfp.mm == MM_OLE)
        {
            RECT rcPict;

            rcPict.left  = xpPrint;
            rcPict.top   = ypPrint;
            rcPict.right = rcPict.left + dxpDisplay;
            rcPict.bottom   = rcPict.top  + dypDisplay;
	        SetMapMode(vhDCPrinter, MM_TEXT);
            //SetViewportOrg( vhDCPrinter, xpPrint, ypPrint);
            fPrint = ObjDisplayObjectInDoc(&picInfo, vfli.doc, vfli.cpMin, vhDCPrinter, &rcPict);
        }
        else
#endif
	if (fBitmap)
		{
		if (((hMDC = CreateCompatibleDC(vhDCPrinter)) != NULL) &&
		  ((picInfo.bm.bmBits =	GlobalLock(hBits)) != NULL)	&& ((hbm =
		  CreateBitmapIndirect((LPBITMAP)&picInfo.bm)) != NULL))
			{
			picInfo.bm.bmBits =	NULL;
			GlobalUnlock(hBits);
			if (SelectObject(hMDC, hbm)	!= NULL)
				{
				fPrint = StretchBlt(vhDCPrinter, xpPrint, ypPrint, dxpDisplay,
				  dypDisplay, hMDC,	0, 0, dxpOrig, dypOrig,	SRCCOPY);
#ifdef DPRINT                
                CommSzNum("PrintGraphics: after StretchBlt1, fPrint==", fPrint);
#endif
				}
			}
		}

	/* Case	2: a non-scalable picture which	we are nevertheless	scaling	by force
	using StretchBlt */
	else if	(fRescale)
		{
		if (((hMDC = CreateCompatibleDC(vhDCPrinter)) != NULL) && ((hbm	=
		  CreateCompatibleBitmap(vhDCPrinter, dxpOrig, dypOrig)) !=	NULL))
			{
			if (SelectObject(hMDC, hbm)	&& PatBlt(hMDC,	0, 0, dxpOrig, dypOrig,
			  WHITENESS) &&	SetMapMode(hMDC, picInfo.mfp.mm) &&
			  PlayMetaFile(hMDC, hBits))
				{
				/* Successfully	played metafile	*/
				SetMapMode(hMDC, MM_TEXT);
				fPrint = StretchBlt(vhDCPrinter, xpPrint, ypPrint, dxpDisplay,
				  dypDisplay, hMDC,	0, 0, dxpOrig, dypOrig,	SRCCOPY);
#ifdef DPRINT                
                CommSzNum("PrintGraphics: after StretchBlt2, fPrint==", fPrint);
#endif
				}
			}
		}

	/* Case	3: A metafile picture which	can	be directly	scaled or does not
	need to	be because its size	has	not	changed	*/
	else
		{
		SetMapMode(vhDCPrinter,	picInfo.mfp.mm);

		SetViewportOrg(vhDCPrinter,	xpPrint, ypPrint);
		switch (picInfo.mfp.mm)
			{
		case MM_ISOTROPIC:
			if (picInfo.mfp.xExt &&	picInfo.mfp.yExt)
				{
				/* So we get the correct shape rectangle when SetViewportExt
				gets called	*/
				SetWindowExt(vhDCPrinter, picInfo.mfp.xExt,	picInfo.mfp.yExt);
				}

		/* FALL	THROUGH	*/
		case MM_ANISOTROPIC:
            /** (9.17.91) v-dougk 
                Set the window extent in case the metafile is bad 
                and doesn't call it itself.  This will prevent
                possible gpfaults in GDI
                **/
            SetWindowExt( vhDCPrinter,  dxpDisplay, dypDisplay );

			SetViewportExt(vhDCPrinter,	dxpDisplay,	dypDisplay);
			break;
			}

		fPrint = PlayMetaFile(vhDCPrinter, hBits);
#ifdef DPRINT        
        CommSzNum("PrintGraphics: after PlayMetaFile, fPrint==", fPrint);
#endif
		}

DontDraw:
	/* We've drawn all we are going	to draw; now its time to clean up. */
	if (iLevel > 0)
		{
		RestoreDC(vhDCPrinter, iLevel);
		}
	if (hMDC !=	NULL)
		{
		DeleteDC(hMDC);
		}
	if (hbm	!= NULL)
		{
		DeleteObject(hbm);
		}
	if (hBits != NULL)
		{
		if (fBitmap	&& picInfo.bm.bmBits !=	NULL)
			{
			GlobalUnlock(hBits);
			}
		GlobalFree(hBits);
		}

	/* If we couldn't print	the	picture, warn the user.	*/
	if (!fPrint)
		{
		Error(IDPMTPrPictErr);
		}
	}