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.

280 lines
7.6 KiB

  1. /*****************************************************************************
  2. *
  3. * lines - 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. /***************************************************************************
  13. * PolylineTo - Win32 to Win16 Metafile Converter Entry Point
  14. **************************************************************************/
  15. BOOL WINAPI DoPolylineTo
  16. (
  17. PLOCALDC pLocalDC,
  18. PPOINTL pptl,
  19. DWORD cptl
  20. )
  21. {
  22. BOOL b ;
  23. // Handle path.
  24. if (pLocalDC->flags & RECORDING_PATH)
  25. {
  26. if (pfnSetVirtualResolution == NULL)
  27. {
  28. bXformWorkhorse((PPOINTL) pptl, cptl, &pLocalDC->xformRWorldToRDev);
  29. }
  30. return(PolylineTo(pLocalDC->hdcHelper, (LPPOINT) pptl, (DWORD) cptl));
  31. }
  32. // Handle the trivial case.
  33. if (cptl == 0)
  34. return(TRUE);
  35. // This can be done by using a LineTo, PolyLine, & MoveTo.
  36. if (!DoLineTo(pLocalDC, pptl[0].x, pptl[0].y))
  37. return(FALSE);
  38. // If there is only one point, we are done.
  39. if (cptl == 1)
  40. return(TRUE);
  41. if (!DoPoly(pLocalDC, pptl, cptl, EMR_POLYLINE, TRUE))
  42. return(FALSE);
  43. b = DoMoveTo(pLocalDC, pptl[cptl-1].x, pptl[cptl-1].y) ;
  44. return (b) ;
  45. }
  46. /***************************************************************************
  47. * PolyPolyline - Win32 to Win16 Metafile Converter Entry Point
  48. **************************************************************************/
  49. BOOL WINAPI DoPolyPolyline
  50. (
  51. PLOCALDC pLocalDC,
  52. PPOINTL pptl, // -> to PolyPolyline points.
  53. PDWORD pcptl, // -> to PolyCounts
  54. DWORD ccptl, // # of PolyCounts.
  55. BOOL transform // do we want to transform the points
  56. )
  57. {
  58. BOOL b ;
  59. UINT i,
  60. iStart,
  61. nCount ;
  62. b = TRUE; // just in case if there is no poly
  63. // Let polyline do the work.
  64. iStart = 0 ;
  65. for (i = 0 ; i < ccptl ; i++)
  66. {
  67. nCount = pcptl[i] ;
  68. b = DoPoly(pLocalDC, &pptl[iStart], nCount, EMR_POLYLINE, transform) ;
  69. if (b == FALSE)
  70. break ;
  71. iStart += nCount ;
  72. }
  73. return(b) ;
  74. }
  75. /***************************************************************************
  76. * LineTo - Win32 to Win16 Metafile Converter Entry Point
  77. *
  78. * See DoMoveTo() in misc.c for notes on the current position.
  79. **************************************************************************/
  80. BOOL WINAPI DoLineTo
  81. (
  82. PLOCALDC pLocalDC,
  83. LONG x,
  84. LONG y
  85. )
  86. {
  87. BOOL b ;
  88. POINT pt ;
  89. POINT ptCP;
  90. // Whether we are recording for a path or acutally emitting
  91. // a drawing order we must pass the drawing order to the helper DC
  92. // so the helper can maintain the current positon.
  93. // If we're recording the drawing orders for a path
  94. // then just pass the drawing order to the helper DC.
  95. // Do not emit any Win16 drawing orders.
  96. POINTL p = {x, y};
  97. if (pfnSetVirtualResolution == NULL)
  98. {
  99. bXformWorkhorse(&p, 1, &pLocalDC->xformRWorldToRDev);
  100. }
  101. if (pLocalDC->flags & RECORDING_PATH)
  102. {
  103. return(LineTo(pLocalDC->hdcHelper, (INT) p.x, (INT) p.y));
  104. }
  105. // Update the current position in the converted metafile if
  106. // it is different from that of the helper DC. See notes
  107. // in DoMoveTo().
  108. if (!GetCurrentPositionEx(pLocalDC->hdcHelper, &ptCP))
  109. return(FALSE);
  110. if (pfnSetVirtualResolution == NULL)
  111. {
  112. // On Win9x we need to convert from Device Units in the Helper DC
  113. // to WorldUnits
  114. if (!bXformWorkhorse((PPOINTL) &ptCP, 1, &pLocalDC->xformRDevToRWorld))
  115. return(FALSE);
  116. }
  117. // Make sure that the converted metafile has the same CP as the
  118. // helper DC.
  119. if (!bValidateMetaFileCP(pLocalDC, ptCP.x, ptCP.y))
  120. return(FALSE);
  121. // Update the helper DC.
  122. // Update the helper DC. (We only need to update the CP so there's no
  123. // reason to actually call LineTo.)
  124. if (!MoveToEx(pLocalDC->hdcHelper, (INT) p.x, (INT) p.y, 0))
  125. return(FALSE);
  126. // Compute the new current position.
  127. pt.x = x ;
  128. pt.y = y ;
  129. if (!bXformRWorldToPPage(pLocalDC, (PPOINTL) &pt, 1L))
  130. return(FALSE);
  131. // Update the mf16 current position to what it will be when this call
  132. // is finished.
  133. pLocalDC->ptCP = pt ;
  134. // Call the Win16 routine to emit the line to the metafile.
  135. b = bEmitWin16LineTo(pLocalDC, LOWORD(pt.x), LOWORD(pt.y)) ;
  136. return(b) ;
  137. }
  138. /***************************************************************************
  139. * Polyline/Polygon - Win32 to Win16 Metafile Converter Entry Point
  140. **************************************************************************/
  141. BOOL WINAPI DoPoly
  142. (
  143. PLOCALDC pLocalDC,
  144. PPOINTL pptl,
  145. DWORD cptl,
  146. INT mrType,
  147. BOOL transform
  148. )
  149. {
  150. BOOL b ;
  151. PPOINTL pptlBuff ;
  152. // If we're recording the drawing orders for a path
  153. // then just pass the drawing order to the helper DC.
  154. // Do not emit any Win16 drawing orders.
  155. if (pLocalDC->flags & RECORDING_PATH)
  156. {
  157. if (pfnSetVirtualResolution == NULL)
  158. {
  159. bXformWorkhorse(pptl, cptl, &pLocalDC->xformRWorldToRDev);
  160. }
  161. switch(mrType)
  162. {
  163. case EMR_POLYLINE:
  164. b = Polyline(pLocalDC->hdcHelper, (LPPOINT) pptl, (INT) cptl) ;
  165. break;
  166. case EMR_POLYGON:
  167. b = Polygon(pLocalDC->hdcHelper, (LPPOINT) pptl, (INT) cptl) ;
  168. break;
  169. }
  170. return(b) ;
  171. }
  172. // The Win16 poly record is limited to 64K points.
  173. // Need to check this limit.
  174. if (cptl > (DWORD) (WORD) MAXWORD)
  175. {
  176. b = FALSE;
  177. PUTS("MF3216: DoPoly, Too many point in poly array\n") ;
  178. SetLastError(ERROR_NOT_ENOUGH_MEMORY) ;
  179. goto exit1 ;
  180. }
  181. // Allocate a buffer to do the transformation in.
  182. // Then copy the points to this buffer.
  183. pptlBuff = (PPOINTL) LocalAlloc(LMEM_FIXED, cptl * sizeof(POINTL)) ;
  184. if (!pptlBuff)
  185. {
  186. b = FALSE;
  187. PUTS("MF3216: DoPoly, LocalAlloc failed\n") ;
  188. goto exit1 ;
  189. }
  190. RtlCopyMemory(pptlBuff, pptl, cptl * sizeof(POINTL)) ;
  191. // Do the transformations.
  192. if (transform)
  193. {
  194. b = bXformRWorldToPPage(pLocalDC, pptlBuff, cptl) ;
  195. if (b == FALSE)
  196. goto exit2 ;
  197. }
  198. // Compress the POINTLs to POINTSs
  199. vCompressPoints(pptlBuff, cptl) ;
  200. // Call the Win16 routine to emit the poly to the metafile.
  201. b = bEmitWin16Poly(pLocalDC, (LPPOINTS) pptlBuff, (SHORT) cptl,
  202. (WORD) (mrType == EMR_POLYLINE ? META_POLYLINE : META_POLYGON)) ;
  203. // Free the memory used as the transform buffer.
  204. exit2:
  205. if (LocalFree(pptlBuff))
  206. ASSERTGDI(FALSE, "MF3216: DoPoly, LocalFree failed");
  207. exit1:
  208. return(b) ;
  209. }
  210. /***************************************************************************
  211. * vCompressPoints - Utility routine to compress the POINTLs to POINTSs.
  212. **************************************************************************/
  213. VOID vCompressPoints(PVOID pBuff, LONG nCount)
  214. {
  215. PPOINTL pPointl ;
  216. PPOINTS pPoints ;
  217. INT i ;
  218. pPointl = (PPOINTL) pBuff ;
  219. pPoints = (PPOINTS) pBuff ;
  220. for (i = 0 ; i < nCount ; i++)
  221. {
  222. pPoints[i].x = LOWORD(pPointl[i].x) ;
  223. pPoints[i].y = LOWORD(pPointl[i].y) ;
  224. }
  225. }