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.

322 lines
9.9 KiB

  1. /*****************************************************************************
  2. *
  3. * beziers - Entry points for Win32 to Win 16 converter
  4. *
  5. * Date: 7/1/91
  6. * Author: Jeffrey Newman (c-jeffn)
  7. *
  8. * Copyright 1991 Microsoft Corp
  9. *****************************************************************************/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. BOOL PolyBezierCommon(PLOCALDC pLocalDC, LPPOINT pptl, PBYTE pb, DWORD cptl, DWORD mrType) ;
  13. /***************************************************************************
  14. * PolyDraw - Win32 to Win16 Metafile Converter Entry Point
  15. **************************************************************************/
  16. BOOL WINAPI DoPolyDraw
  17. (
  18. PLOCALDC pLocalDC,
  19. LPPOINT pptl,
  20. PBYTE pb,
  21. DWORD cptl
  22. )
  23. {
  24. return(PolyBezierCommon(pLocalDC, pptl, pb, cptl, EMR_POLYDRAW));
  25. }
  26. /***************************************************************************
  27. * PolyBezier - Win32 to Win16 Metafile Converter Entry Point
  28. **************************************************************************/
  29. BOOL WINAPI DoPolyBezier
  30. (
  31. PLOCALDC pLocalDC,
  32. LPPOINT pptl,
  33. DWORD cptl
  34. )
  35. {
  36. return(PolyBezierCommon(pLocalDC, pptl, (PBYTE) NULL, cptl, EMR_POLYBEZIER));
  37. }
  38. /***************************************************************************
  39. * PolyBezierTo - Win32 to Win16 Metafile Converter Entry Point
  40. **************************************************************************/
  41. BOOL WINAPI DoPolyBezierTo
  42. (
  43. PLOCALDC pLocalDC,
  44. LPPOINT pptl,
  45. DWORD cptl
  46. )
  47. {
  48. return(PolyBezierCommon(pLocalDC, pptl, (PBYTE) NULL, cptl, EMR_POLYBEZIERTO));
  49. }
  50. /***************************************************************************
  51. * PolyBezierCommon - Common code for PolyDraw, PolyBezier and PolyBezierTo
  52. **************************************************************************/
  53. BOOL PolyBezierCommon(PLOCALDC pLocalDC, LPPOINT pptl, PBYTE pb, DWORD cptl, DWORD mrType)
  54. {
  55. BOOL b ;
  56. // If we're recording the drawing order for a path
  57. // then just pass the drawing order to the helper DC.
  58. // Do not emit any Win16 drawing orders.
  59. if (pLocalDC->flags & RECORDING_PATH)
  60. {
  61. // On Win9x transform the points with the WorldToPage transform
  62. // before calling the HelperDC functions
  63. if (pfnSetVirtualResolution == NULL)
  64. {
  65. if (!bXformWorkhorse((PPOINTL) pptl, cptl, &pLocalDC->xformRWorldToRDev))
  66. return FALSE;
  67. }
  68. switch (mrType)
  69. {
  70. case EMR_POLYBEZIER:
  71. b = PolyBezier(pLocalDC->hdcHelper, pptl, cptl) ;
  72. break ;
  73. case EMR_POLYBEZIERTO:
  74. b = PolyBezierTo(pLocalDC->hdcHelper, pptl, cptl) ;
  75. break ;
  76. case EMR_POLYDRAW:
  77. b = PolyDraw(pLocalDC->hdcHelper, pptl, pb, cptl) ;
  78. break ;
  79. default:
  80. b = FALSE;
  81. RIPS(("MF3216: PolyBezierCommon, bad mrType\n")) ;
  82. break ;
  83. }
  84. ASSERTGDI(b, "MF3216: PolyBezierCommon, in path render failed\n") ;
  85. return (b) ;
  86. }
  87. // Call the common curve renderer.
  88. return
  89. (
  90. bRenderCurveWithPath(pLocalDC, pptl, pb, cptl,
  91. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0f, 0.0f, mrType)
  92. );
  93. }
  94. /***************************************************************************
  95. * bRenderCurveWithPath - Renders a curve or area using the path api.
  96. * The supported curves and areas are PolyDraw, PolyBezier, PolyBezierTo,
  97. * AngleArc, Arc, Chord, Pie, Ellipse, Rectangle, and RoundRect.
  98. **************************************************************************/
  99. BOOL bRenderCurveWithPath
  100. (
  101. PLOCALDC pLocalDC,
  102. LPPOINT pptl,
  103. PBYTE pb,
  104. DWORD cptl,
  105. INT x1,
  106. INT y1,
  107. INT x2,
  108. INT y2,
  109. INT x3,
  110. INT y3,
  111. INT x4,
  112. INT y4,
  113. DWORD nRadius,
  114. FLOAT eStartAngle,
  115. FLOAT eSweepAngle,
  116. DWORD mrType
  117. )
  118. {
  119. BOOL b = FALSE;
  120. INT iPathType;
  121. POINTL ppts[4] = {x1, y1, x2, y2, x3, y3, x4, y4};
  122. if (pfnSetVirtualResolution == NULL)
  123. {
  124. // On Win9x tranform the points before passing them to the DC
  125. if (!bXformWorkhorse((PPOINTL) pptl, cptl, &pLocalDC->xformRWorldToRDev))
  126. {
  127. RIPS("GPMF3216: bRenderCurveWithPath, BeginPath failed\n");
  128. goto exit_bRenderCurveWithPath;
  129. }
  130. if (!bXformWorkhorse(ppts, 4, &pLocalDC->xformRWorldToRDev))
  131. {
  132. RIPS("GPMF3216: bRenderCurveWithPath, BeginPath failed\n");
  133. goto exit_bRenderCurveWithPath;
  134. }
  135. }
  136. // We don't do curves in a path bracket here. They should be
  137. // taken care of by the caller.
  138. ASSERTGDI(!(pLocalDC->flags & RECORDING_PATH),
  139. "MF3216: bRenderCurveWithPath, cannot be in a path bracket\n");
  140. // Save the helper DC first.
  141. // This is to prevent us from accidentally deleteing the current path
  142. // in the helper DC when we create another path to render the curve.
  143. // E.g. BeginPath, Polyline, EndPath, PolyBezier, StrokePath.
  144. if (!SaveDC(pLocalDC->hdcHelper))
  145. {
  146. RIPS("MF3216: bRenderCurveWithPath, SaveDC failed\n");
  147. return(FALSE);
  148. }
  149. // Create the path for the curve and stroke it.
  150. // Be careful not to modify the states of the LocalDC especially in
  151. // DoRenderPath below.
  152. // Note that BeginPath uses the previous current position. So this
  153. // code will work correctly in the case of PolyBezierTo, PolyDraw
  154. // and AngleArc.
  155. // Begin the path.
  156. b = BeginPath(pLocalDC->hdcHelper);
  157. if (!b)
  158. {
  159. RIPS("MF3216: bRenderCurveWithPath, BeginPath failed\n");
  160. goto exit_bRenderCurveWithPath;
  161. }
  162. // Do the curve.
  163. switch (mrType)
  164. {
  165. case EMR_POLYBEZIER:
  166. iPathType = EMR_STROKEPATH;
  167. b = PolyBezier(pLocalDC->hdcHelper, pptl, cptl);
  168. break;
  169. case EMR_POLYBEZIERTO:
  170. iPathType = EMR_STROKEPATH;
  171. b = PolyBezierTo(pLocalDC->hdcHelper, pptl, cptl);
  172. break;
  173. case EMR_POLYDRAW:
  174. iPathType = EMR_STROKEPATH;
  175. b = PolyDraw(pLocalDC->hdcHelper, pptl, pb, cptl);
  176. break;
  177. case EMR_ANGLEARC:
  178. iPathType = EMR_STROKEPATH;
  179. b = AngleArc(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, nRadius, eStartAngle, eSweepAngle);
  180. break;
  181. case EMR_ARC:
  182. iPathType = EMR_STROKEPATH;
  183. b = Arc(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y,
  184. ppts[2].x, ppts[2].y, ppts[3].x, ppts[3].y);
  185. break;
  186. case EMR_CHORD:
  187. iPathType = EMR_STROKEANDFILLPATH;
  188. b = Chord(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y,
  189. ppts[2].x, ppts[2].y, ppts[3].x, ppts[3].y);
  190. break;
  191. case EMR_PIE:
  192. iPathType = EMR_STROKEANDFILLPATH;
  193. b = Pie(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y,
  194. ppts[2].x, ppts[2].y, ppts[3].x, ppts[3].y);
  195. break;
  196. case EMR_ELLIPSE:
  197. iPathType = EMR_STROKEANDFILLPATH;
  198. b = Ellipse(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y);
  199. break;
  200. case EMR_RECTANGLE:
  201. iPathType = EMR_STROKEANDFILLPATH;
  202. b = Rectangle(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y) ;
  203. break;
  204. case EMR_ROUNDRECT:
  205. iPathType = EMR_STROKEANDFILLPATH;
  206. b = RoundRect(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y,
  207. ppts[2].x, ppts[2].y) ;
  208. break;
  209. default:
  210. b = FALSE;
  211. RIPS("MF3216: bRenderCurveWithPath, bad mrType");
  212. break;
  213. }
  214. if (!b)
  215. {
  216. RIPS("MF3216: bRenderCurveWithPath, render failed\n");
  217. goto exit_bRenderCurveWithPath;
  218. }
  219. // End the path
  220. b = EndPath(pLocalDC->hdcHelper);
  221. if (!b)
  222. {
  223. RIPS("MF3216: bRenderCurveWithPath, EndPath failed\n");
  224. goto exit_bRenderCurveWithPath;
  225. }
  226. // Stroke or fill the path.
  227. b = DoRenderPath(pLocalDC, iPathType, FALSE);
  228. if (!b)
  229. {
  230. RIPS("MF3216: bRenderCurveWithPath, DoRenderPath failed\n");
  231. goto exit_bRenderCurveWithPath;
  232. }
  233. exit_bRenderCurveWithPath:
  234. // Restore the helper DC.
  235. if (!RestoreDC(pLocalDC->hdcHelper, -1))
  236. ASSERTGDI(FALSE, "MF3216: bRenderCurveWithPath, RestoreDC failed\n") ;
  237. // If this is a PolyBezeirTo, PolyDraw or AngleArc, make the call to the
  238. // helper DC to update its current position.
  239. if (b)
  240. {
  241. switch (mrType)
  242. {
  243. case EMR_POLYBEZIER:
  244. case EMR_ARC:
  245. case EMR_CHORD:
  246. case EMR_PIE:
  247. case EMR_ELLIPSE:
  248. case EMR_RECTANGLE:
  249. case EMR_ROUNDRECT: // no need to update the helper DC
  250. break ;
  251. case EMR_POLYBEZIERTO:
  252. (void) PolyBezierTo(pLocalDC->hdcHelper, pptl, cptl) ;
  253. break ;
  254. case EMR_POLYDRAW:
  255. (void) PolyDraw(pLocalDC->hdcHelper, pptl, pb, cptl) ;
  256. break ;
  257. case EMR_ANGLEARC:
  258. (void) AngleArc(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, nRadius, eStartAngle, eSweepAngle);
  259. break ;
  260. default:
  261. RIPS("MF3216: bRenderCurveWithPath, bad mrType");
  262. break;
  263. }
  264. }
  265. // Return the result.
  266. return(b);
  267. }