Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
7.6 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* These routines are the guts of the graphics print code. */
  5. #define NOGDICAPMASKS
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINMESSAGES
  8. #define NOWINSTYLES
  9. #define NOSYSMETRICS
  10. #define NOICON
  11. #define NOKEYSTATE
  12. #define NOSYSCOMMANDS
  13. #define NOSHOWWINDOW
  14. //#define NOATOM
  15. #define NOFONT
  16. #define NOBRUSH
  17. #define NOCLIPBOARD
  18. #define NOCOLOR
  19. #define NOCREATESTRUCT
  20. #define NOCTLMGR
  21. #define NODRAWTEXT
  22. #define NOMB
  23. #define NOOPENFILE
  24. #define NOPEN
  25. #define NOREGION
  26. #define NOSCROLL
  27. #define NOSOUND
  28. #define NOWH
  29. #define NOWINOFFSETS
  30. #define NOWNDCLASS
  31. #define NOCOMM
  32. #include <windows.h>
  33. #include "mw.h"
  34. #include "printdef.h"
  35. #include "fmtdefs.h"
  36. #include "docdefs.h"
  37. #define NOKCCODES
  38. #include "winddefs.h"
  39. #include "debug.h"
  40. #include "str.h"
  41. #if defined(OLE)
  42. #include "obj.h"
  43. #endif
  44. PrintGraphics(xpPrint, ypPrint)
  45. int xpPrint;
  46. int ypPrint;
  47. {
  48. /* This routine prints the picture in the vfli structure at position
  49. (xpPrint, ypPrint). */
  50. extern HDC vhDCPrinter;
  51. extern struct FLI vfli;
  52. extern struct DOD (**hpdocdod)[];
  53. extern int dxpPrPage;
  54. extern int dypPrPage;
  55. extern FARPROC lpFPrContinue;
  56. typeCP cp;
  57. typeCP cpMac = (**hpdocdod)[vfli.doc].cpMac;
  58. struct PICINFOX picInfo;
  59. HANDLE hBits = NULL;
  60. HDC hMDC = NULL;
  61. HBITMAP hbm = NULL;
  62. LPCH lpBits;
  63. int cchRun;
  64. unsigned long cbPict = 0;
  65. int dxpOrig; /* Size of picture in the original */
  66. int dypOrig;
  67. int dxpDisplay; /* Size of picture as we want to show it */
  68. int dypDisplay;
  69. BOOL fRescale;
  70. BOOL fBitmap;
  71. BOOL fPrint = FALSE;
  72. int iLevel = 0;
  73. RECT bounds;
  74. Assert(vhDCPrinter);
  75. GetPicInfo(vfli.cpMin, cpMac, vfli.doc, &picInfo);
  76. /* Compute desired display size of picture (in device pixels) */
  77. dxpDisplay = vfli.xpReal - vfli.xpLeft;
  78. dypDisplay = vfli.dypLine;
  79. /* Compute original size of picture (in device pixels) */
  80. /* MM_ANISOTROPIC and MM_ISOTROPIC pictures have no original size */
  81. fRescale = FALSE;
  82. switch (picInfo.mfp.mm)
  83. {
  84. case MM_ISOTROPIC:
  85. case MM_ANISOTROPIC:
  86. break;
  87. #if defined(OLE)
  88. case MM_OLE:
  89. if (lpOBJ_QUERY_INFO(&picInfo) == NULL)
  90. goto DontDraw;
  91. if (lpOBJ_QUERY_OBJECT(&picInfo) == NULL)
  92. goto DontDraw;
  93. break;
  94. #endif
  95. case MM_BITMAP:
  96. dxpOrig = picInfo.bm.bmWidth;
  97. dypOrig = picInfo.bm.bmHeight;
  98. break;
  99. default:
  100. dxpOrig = PxlConvert(picInfo.mfp.mm, picInfo.mfp.xExt, dxpPrPage,
  101. GetDeviceCaps(vhDCPrinter, HORZSIZE));
  102. dypOrig = PxlConvert(picInfo.mfp.mm, picInfo.mfp.yExt, dypPrPage,
  103. GetDeviceCaps(vhDCPrinter, VERTSIZE));
  104. if (dxpOrig == 0 || dypOrig == 0)
  105. {
  106. #ifdef DPRINT
  107. CommSz("PrintGraphics: nodraw because dxpOrig==0 | dypOrig==0\r\n");
  108. #endif
  109. goto DontDraw;
  110. }
  111. fRescale = (dxpOrig != dxpDisplay) || (dypOrig != dypDisplay);
  112. break;
  113. }
  114. /* Get a handle to a global object large enough to hold the picture. */
  115. if (picInfo.mfp.mm != MM_OLE)
  116. {
  117. if ((hBits = GlobalAlloc(GMEM_MOVEABLE, (long)picInfo.cbSize)) == NULL)
  118. {
  119. /* Not enough global heap space to load bitmap/metafile */
  120. #ifdef DPRINT
  121. CommSz("PrintGraphics: nodraw because not enough mem to alloc\r\n");
  122. #endif
  123. goto DontDraw;
  124. }
  125. /* Build up all bytes associated with the picture (except the header) into
  126. the global handle hBits */
  127. for (cbPict = 0, cp = vfli.cpMin + picInfo.cbHeader; cbPict <
  128. picInfo.cbSize; cbPict += cchRun, cp += cchRun)
  129. {
  130. CHAR rgch[256];
  131. LPCH lpch;
  132. #define ulmin(a,b) ((a) < (b) ? (a) : (b))
  133. FetchRgch(&cchRun, rgch, vfli.doc, cp, cpMac, (int)ulmin(picInfo.cbSize
  134. - cbPict, 256));
  135. if ((lpch = GlobalLock(hBits)) == NULL)
  136. {
  137. #ifdef DPRINT
  138. CommSz("PrintGraphics: nodraw because couldn't lock\r\n");
  139. #endif
  140. goto DontDraw;
  141. }
  142. bltbx((LPSTR)rgch, lpch + cbPict, cchRun);
  143. GlobalUnlock(hBits);
  144. }
  145. }
  146. /* Save the printer DC as a guard against DC attribute alteration by a
  147. metafile */
  148. iLevel = SaveDC(vhDCPrinter);
  149. fBitmap = picInfo.mfp.mm == MM_BITMAP;
  150. #if defined(OLE)
  151. /* CASE 0: OLE */
  152. if (picInfo.mfp.mm == MM_OLE)
  153. {
  154. RECT rcPict;
  155. rcPict.left = xpPrint;
  156. rcPict.top = ypPrint;
  157. rcPict.right = rcPict.left + dxpDisplay;
  158. rcPict.bottom = rcPict.top + dypDisplay;
  159. SetMapMode(vhDCPrinter, MM_TEXT);
  160. //SetViewportOrg( vhDCPrinter, xpPrint, ypPrint);
  161. fPrint = ObjDisplayObjectInDoc(&picInfo, vfli.doc, vfli.cpMin, vhDCPrinter, &rcPict);
  162. }
  163. else
  164. #endif
  165. if (fBitmap)
  166. {
  167. if (((hMDC = CreateCompatibleDC(vhDCPrinter)) != NULL) &&
  168. ((picInfo.bm.bmBits = GlobalLock(hBits)) != NULL) && ((hbm =
  169. CreateBitmapIndirect((LPBITMAP)&picInfo.bm)) != NULL))
  170. {
  171. picInfo.bm.bmBits = NULL;
  172. GlobalUnlock(hBits);
  173. if (SelectObject(hMDC, hbm) != NULL)
  174. {
  175. fPrint = StretchBlt(vhDCPrinter, xpPrint, ypPrint, dxpDisplay,
  176. dypDisplay, hMDC, 0, 0, dxpOrig, dypOrig, SRCCOPY);
  177. #ifdef DPRINT
  178. CommSzNum("PrintGraphics: after StretchBlt1, fPrint==", fPrint);
  179. #endif
  180. }
  181. }
  182. }
  183. /* Case 2: a non-scalable picture which we are nevertheless scaling by force
  184. using StretchBlt */
  185. else if (fRescale)
  186. {
  187. if (((hMDC = CreateCompatibleDC(vhDCPrinter)) != NULL) && ((hbm =
  188. CreateCompatibleBitmap(vhDCPrinter, dxpOrig, dypOrig)) != NULL))
  189. {
  190. if (SelectObject(hMDC, hbm) && PatBlt(hMDC, 0, 0, dxpOrig, dypOrig,
  191. WHITENESS) && SetMapMode(hMDC, picInfo.mfp.mm) &&
  192. PlayMetaFile(hMDC, hBits))
  193. {
  194. /* Successfully played metafile */
  195. SetMapMode(hMDC, MM_TEXT);
  196. fPrint = StretchBlt(vhDCPrinter, xpPrint, ypPrint, dxpDisplay,
  197. dypDisplay, hMDC, 0, 0, dxpOrig, dypOrig, SRCCOPY);
  198. #ifdef DPRINT
  199. CommSzNum("PrintGraphics: after StretchBlt2, fPrint==", fPrint);
  200. #endif
  201. }
  202. }
  203. }
  204. /* Case 3: A metafile picture which can be directly scaled or does not
  205. need to be because its size has not changed */
  206. else
  207. {
  208. SetMapMode(vhDCPrinter, picInfo.mfp.mm);
  209. SetViewportOrg(vhDCPrinter, xpPrint, ypPrint);
  210. switch (picInfo.mfp.mm)
  211. {
  212. case MM_ISOTROPIC:
  213. if (picInfo.mfp.xExt && picInfo.mfp.yExt)
  214. {
  215. /* So we get the correct shape rectangle when SetViewportExt
  216. gets called */
  217. SetWindowExt(vhDCPrinter, picInfo.mfp.xExt, picInfo.mfp.yExt);
  218. }
  219. /* FALL THROUGH */
  220. case MM_ANISOTROPIC:
  221. /** (9.17.91) v-dougk
  222. Set the window extent in case the metafile is bad
  223. and doesn't call it itself. This will prevent
  224. possible gpfaults in GDI
  225. **/
  226. SetWindowExt( vhDCPrinter, dxpDisplay, dypDisplay );
  227. SetViewportExt(vhDCPrinter, dxpDisplay, dypDisplay);
  228. break;
  229. }
  230. fPrint = PlayMetaFile(vhDCPrinter, hBits);
  231. #ifdef DPRINT
  232. CommSzNum("PrintGraphics: after PlayMetaFile, fPrint==", fPrint);
  233. #endif
  234. }
  235. DontDraw:
  236. /* We've drawn all we are going to draw; now its time to clean up. */
  237. if (iLevel > 0)
  238. {
  239. RestoreDC(vhDCPrinter, iLevel);
  240. }
  241. if (hMDC != NULL)
  242. {
  243. DeleteDC(hMDC);
  244. }
  245. if (hbm != NULL)
  246. {
  247. DeleteObject(hbm);
  248. }
  249. if (hBits != NULL)
  250. {
  251. if (fBitmap && picInfo.bm.bmBits != NULL)
  252. {
  253. GlobalUnlock(hBits);
  254. }
  255. GlobalFree(hBits);
  256. }
  257. /* If we couldn't print the picture, warn the user. */
  258. if (!fPrint)
  259. {
  260. Error(IDPMTPrPictErr);
  261. }
  262. }
  263.