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.

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