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.

247 lines
6.3 KiB

  1. /*****************************************************************************
  2. *
  3. * rects - 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. extern fnSetVirtualResolution pfnSetVirtualResolution;
  13. /***************************************************************************
  14. * Rectangle - Win32 to Win16 Metafile Converter Entry Point
  15. **************************************************************************/
  16. BOOL WINAPI DoRectangle
  17. (
  18. PLOCALDC pLocalDC,
  19. int x1,
  20. int y1,
  21. int x2,
  22. int y2
  23. )
  24. {
  25. BOOL b ;
  26. b = bConicCommon (pLocalDC, x1, y1, x2, y2, 0, 0, 0, 0, EMR_RECTANGLE) ;
  27. return(b) ;
  28. }
  29. /***************************************************************************
  30. * RoundRect - Win32 to Win16 Metafile Converter Entry Point
  31. **************************************************************************/
  32. BOOL WINAPI DoRoundRect
  33. (
  34. PLOCALDC pLocalDC,
  35. int x1,
  36. int y1,
  37. int x2,
  38. int y2,
  39. int x3,
  40. int y3
  41. )
  42. {
  43. BOOL b ;
  44. b = bConicCommon (pLocalDC, x1, y1, x2, y2, x3, y3, 0, 0, EMR_ROUNDRECT);
  45. return(b) ;
  46. }
  47. void FixOverflow (int * value)
  48. {
  49. if (*value > 32767)
  50. {
  51. *value = 32767;
  52. }
  53. else if (*value < -32768)
  54. {
  55. *value = -32768;
  56. }
  57. }
  58. /***************************************************************************
  59. * IntersectClipRect/ExcludeClipRect - Win32 to Win16 Metafile Converter
  60. * Entry Point
  61. **************************************************************************/
  62. BOOL WINAPI DoClipRect
  63. (
  64. PLOCALDC pLocalDC,
  65. INT xLeft,
  66. INT yTop,
  67. INT xRight,
  68. INT yBottom,
  69. INT mrType
  70. )
  71. {
  72. BOOL bNoClipRgn ;
  73. POINTL aptl[2] ;
  74. INT temp;
  75. // Do it to the helper DC.
  76. // If there is no initial clip region, we have to
  77. // create one. Otherwise, GDI will create some random default
  78. // clipping region for us!
  79. bNoClipRgn = bNoDCRgn(pLocalDC, DCRGN_CLIP);
  80. if (bNoClipRgn)
  81. {
  82. BOOL bRet;
  83. HRGN hrgnDefault;
  84. if (!(hrgnDefault = CreateRectRgn((int) (SHORT) MINSHORT,
  85. (int) (SHORT) MINSHORT,
  86. (int) (SHORT) MAXSHORT,
  87. (int) (SHORT) MAXSHORT)))
  88. {
  89. ASSERTGDI(FALSE, "MF3216: CreateRectRgn failed");
  90. return(FALSE);
  91. }
  92. bRet = (ExtSelectClipRgn(pLocalDC->hdcHelper, hrgnDefault, RGN_COPY)
  93. != ERROR);
  94. ASSERTGDI(bRet, "MF3216: ExtSelectClipRgn failed");
  95. if (!DeleteObject(hrgnDefault))
  96. ASSERTGDI(FALSE, "MF3216: DeleteObject failed");
  97. if (!bRet)
  98. return(FALSE);
  99. }
  100. // Do the simple case.
  101. // Are they inclusive-exclusive?!
  102. // Make it inclusive-inclusive, and then transform
  103. // then make it back to inclusive-exclusive
  104. aptl[0].x = xLeft;
  105. aptl[0].y = yTop ;
  106. aptl[1].x = xRight;
  107. aptl[1].y = yBottom;
  108. if (aptl[0].x > aptl[1].x)
  109. {
  110. temp = aptl[0].x;
  111. aptl[0].x = aptl[1].x;
  112. aptl[1].x = temp;
  113. }
  114. if (aptl[0].y > aptl[1].y)
  115. {
  116. temp = aptl[0].y;
  117. aptl[0].y = aptl[1].y;
  118. aptl[1].y = temp;
  119. }
  120. aptl[1].x--;
  121. aptl[1].y--;
  122. {
  123. POINTL ppts[2] = {aptl[0].x, aptl[0].y, aptl[1].x, aptl[1].y};
  124. if (pfnSetVirtualResolution == NULL)
  125. {
  126. if (!bXformWorkhorse(ppts, 2, &pLocalDC->xformRWorldToRDev))
  127. {
  128. return FALSE;
  129. }
  130. // Verify rectangle ordering and check off-by-1 error!
  131. if (ppts[0].x > ppts[1].x)
  132. {
  133. temp = ppts[0].x;
  134. ppts[0].x = ppts[1].x;
  135. ppts[1].x = temp;
  136. }
  137. if (ppts[0].y > ppts[1].y)
  138. {
  139. temp = ppts[0].y;
  140. ppts[0].y = ppts[1].y;
  141. ppts[1].y = temp;
  142. }
  143. }
  144. ppts[1].x++;
  145. ppts[1].y++;
  146. switch(mrType)
  147. {
  148. case EMR_INTERSECTCLIPRECT:
  149. if (!IntersectClipRect(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y))
  150. return(FALSE);
  151. break;
  152. case EMR_EXCLUDECLIPRECT:
  153. if (!ExcludeClipRect(pLocalDC->hdcHelper, ppts[0].x, ppts[0].y, ppts[1].x, ppts[1].y))
  154. return(FALSE);
  155. break;
  156. default:
  157. ASSERTGDI(FALSE, "MF3216: DoClipRect, bad mrType\n");
  158. break;
  159. }
  160. }
  161. // Dump the clip region data if there is a strange xform.
  162. // Even if there is a clipping region, when playing back the WMF, we
  163. // will already have a clip rect and we will simply want to intersect
  164. // or exclude the new region.
  165. if (pLocalDC->flags & STRANGE_XFORM)
  166. return(bDumpDCClipping(pLocalDC));
  167. if (!bXformRWorldToPPage(pLocalDC, (PPOINTL) aptl, 2))
  168. return(FALSE);
  169. if (!bCoordinateOverflowTest((PLONG) aptl, 4))
  170. {
  171. RIPS("MF3216: coord overflow");
  172. FixOverflow (&(aptl[0].x));
  173. FixOverflow (&(aptl[0].y));
  174. FixOverflow (&(aptl[1].x));
  175. FixOverflow (&(aptl[1].y));
  176. }
  177. // Verify rectangle ordering and check off-by-1 error!
  178. if (aptl[0].x > aptl[1].x)
  179. {
  180. temp = aptl[0].x;
  181. aptl[0].x = aptl[1].x;
  182. aptl[1].x = temp;
  183. }
  184. if (aptl[0].y > aptl[1].y)
  185. {
  186. temp = aptl[0].y;
  187. aptl[0].y = aptl[1].y;
  188. aptl[1].y = temp;
  189. }
  190. aptl[1].x++;
  191. aptl[1].y++;
  192. if (mrType == EMR_INTERSECTCLIPRECT)
  193. return(bEmitWin16IntersectClipRect(pLocalDC,
  194. (SHORT) aptl[0].x,
  195. (SHORT) aptl[0].y,
  196. (SHORT) aptl[1].x,
  197. (SHORT) aptl[1].y));
  198. else
  199. return(bEmitWin16ExcludeClipRect(pLocalDC,
  200. (SHORT) aptl[0].x,
  201. (SHORT) aptl[0].y,
  202. (SHORT) aptl[1].x,
  203. (SHORT) aptl[1].y));
  204. }