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.8 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. switch (mrType)
  62. {
  63. case EMR_POLYBEZIER:
  64. b = PolyBezier(pLocalDC->hdcHelper, pptl, cptl) ;
  65. break ;
  66. case EMR_POLYBEZIERTO:
  67. b = PolyBezierTo(pLocalDC->hdcHelper, pptl, cptl) ;
  68. break ;
  69. case EMR_POLYDRAW:
  70. b = PolyDraw(pLocalDC->hdcHelper, pptl, pb, cptl) ;
  71. break ;
  72. default:
  73. b = FALSE;
  74. RIP("MF3216: PolyBezierCommon, bad mrType\n") ;
  75. break ;
  76. }
  77. ASSERTGDI(b, "MF3216: PolyBezierCommon, in path render failed\n") ;
  78. return (b) ;
  79. }
  80. // Call the common curve renderer.
  81. return
  82. (
  83. bRenderCurveWithPath(pLocalDC, pptl, pb, cptl,
  84. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0f, 0.0f, mrType)
  85. );
  86. }
  87. /***************************************************************************
  88. * bRenderCurveWithPath - Renders a curve or area using the path api.
  89. * The supported curves and areas are PolyDraw, PolyBezier, PolyBezierTo,
  90. * AngleArc, Arc, Chord, Pie, Ellipse, Rectangle, and RoundRect.
  91. **************************************************************************/
  92. BOOL bRenderCurveWithPath
  93. (
  94. PLOCALDC pLocalDC,
  95. LPPOINT pptl,
  96. PBYTE pb,
  97. DWORD cptl,
  98. INT x1,
  99. INT y1,
  100. INT x2,
  101. INT y2,
  102. INT x3,
  103. INT y3,
  104. INT x4,
  105. INT y4,
  106. DWORD nRadius,
  107. FLOAT eStartAngle,
  108. FLOAT eSweepAngle,
  109. DWORD mrType
  110. )
  111. {
  112. BOOL b;
  113. INT iPathType;
  114. // We don't do curves in a path bracket here. They should be
  115. // taken care of by the caller.
  116. ASSERTGDI(!(pLocalDC->flags & RECORDING_PATH),
  117. "MF3216: bRenderCurveWithPath, cannot be in a path bracket\n");
  118. // Save the helper DC first.
  119. // This is to prevent us from accidentally deleteing the current path
  120. // in the helper DC when we create another path to render the curve.
  121. // E.g. BeginPath, Polyline, EndPath, PolyBezier, StrokePath.
  122. if (!SaveDC(pLocalDC->hdcHelper))
  123. {
  124. RIP("MF3216: bRenderCurveWithPath, SaveDC failed\n");
  125. return(FALSE);
  126. }
  127. // Create the path for the curve and stroke it.
  128. // Be careful not to modify the states of the LocalDC especially in
  129. // DoRenderPath below.
  130. // Note that BeginPath uses the previous current position. So this
  131. // code will work correctly in the case of PolyBezierTo, PolyDraw
  132. // and AngleArc.
  133. // Begin the path.
  134. b = BeginPath(pLocalDC->hdcHelper);
  135. if (!b)
  136. {
  137. RIP("MF3216: bRenderCurveWithPath, BeginPath failed\n");
  138. goto exit_bRenderCurveWithPath;
  139. }
  140. // Do the curve.
  141. switch (mrType)
  142. {
  143. case EMR_POLYBEZIER:
  144. iPathType = EMR_STROKEPATH;
  145. b = PolyBezier(pLocalDC->hdcHelper, pptl, cptl);
  146. break;
  147. case EMR_POLYBEZIERTO:
  148. iPathType = EMR_STROKEPATH;
  149. b = PolyBezierTo(pLocalDC->hdcHelper, pptl, cptl);
  150. break;
  151. case EMR_POLYDRAW:
  152. iPathType = EMR_STROKEPATH;
  153. b = PolyDraw(pLocalDC->hdcHelper, pptl, pb, cptl);
  154. break;
  155. case EMR_ANGLEARC:
  156. iPathType = EMR_STROKEPATH;
  157. b = AngleArc(pLocalDC->hdcHelper, x1, y1, nRadius, eStartAngle, eSweepAngle);
  158. break;
  159. case EMR_ARC:
  160. iPathType = EMR_STROKEPATH;
  161. b = Arc(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3, x4, y4);
  162. break;
  163. case EMR_CHORD:
  164. iPathType = EMR_STROKEANDFILLPATH;
  165. b = Chord(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3, x4, y4);
  166. break;
  167. case EMR_PIE:
  168. iPathType = EMR_STROKEANDFILLPATH;
  169. b = Pie(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3, x4, y4) ;
  170. break;
  171. case EMR_ELLIPSE:
  172. iPathType = EMR_STROKEANDFILLPATH;
  173. b = Ellipse(pLocalDC->hdcHelper, x1, y1, x2, y2);
  174. break;
  175. case EMR_RECTANGLE:
  176. iPathType = EMR_STROKEANDFILLPATH;
  177. b = Rectangle(pLocalDC->hdcHelper, x1, y1, x2, y2) ;
  178. break;
  179. case EMR_ROUNDRECT:
  180. iPathType = EMR_STROKEANDFILLPATH;
  181. b = RoundRect(pLocalDC->hdcHelper, x1, y1, x2, y2, x3, y3) ;
  182. break;
  183. default:
  184. b = FALSE;
  185. RIP("MF3216: bRenderCurveWithPath, bad mrType");
  186. break;
  187. }
  188. if (!b)
  189. {
  190. RIP("MF3216: bRenderCurveWithPath, render failed\n");
  191. goto exit_bRenderCurveWithPath;
  192. }
  193. // End the path
  194. b = EndPath(pLocalDC->hdcHelper);
  195. if (!b)
  196. {
  197. RIP("MF3216: bRenderCurveWithPath, EndPath failed\n");
  198. goto exit_bRenderCurveWithPath;
  199. }
  200. // Stroke or fill the path.
  201. b = DoRenderPath(pLocalDC, iPathType);
  202. if (!b)
  203. {
  204. RIP("MF3216: bRenderCurveWithPath, DoRenderPath failed\n");
  205. goto exit_bRenderCurveWithPath;
  206. }
  207. exit_bRenderCurveWithPath:
  208. // Restore the helper DC.
  209. if (!RestoreDC(pLocalDC->hdcHelper, -1))
  210. ASSERTGDI(FALSE, "MF3216: bRenderCurveWithPath, RestoreDC failed\n") ;
  211. // If this is a PolyBezeirTo, PolyDraw or AngleArc, make the call to the
  212. // helper DC to update its current position.
  213. if (b)
  214. {
  215. switch (mrType)
  216. {
  217. case EMR_POLYBEZIER:
  218. case EMR_ARC:
  219. case EMR_CHORD:
  220. case EMR_PIE:
  221. case EMR_ELLIPSE:
  222. case EMR_RECTANGLE:
  223. case EMR_ROUNDRECT: // no need to update the helper DC
  224. break ;
  225. case EMR_POLYBEZIERTO:
  226. (void) PolyBezierTo(pLocalDC->hdcHelper, pptl, cptl) ;
  227. break ;
  228. case EMR_POLYDRAW:
  229. (void) PolyDraw(pLocalDC->hdcHelper, pptl, pb, cptl) ;
  230. break ;
  231. case EMR_ANGLEARC:
  232. (void) AngleArc(pLocalDC->hdcHelper, x1, y1, nRadius, eStartAngle, eSweepAngle);
  233. break ;
  234. default:
  235. RIP("MF3216: bRenderCurveWithPath, bad mrType");
  236. break;
  237. }
  238. }
  239. // Return the result.
  240. return(b);
  241. }