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.

176 lines
4.8 KiB

  1. /*****************************************************************************
  2. *
  3. * polygons - 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. * PolyPolygon - Win32 to Win16 Metafile Converter Entry Point
  14. **************************************************************************/
  15. BOOL WINAPI DoPolyPolygon
  16. (
  17. PLOCALDC pLocalDC,
  18. PPOINTL pptl,
  19. PDWORD pcptl,
  20. DWORD cptl,
  21. DWORD ccptl,
  22. BOOL transform
  23. )
  24. {
  25. BOOL b;
  26. PWORD pcptlBuff = (PWORD) NULL;
  27. PPOINTL pptlBuff = (PPOINTL) NULL;
  28. PPOINTL pptlSrc, pptlDst;
  29. DWORD i, cptlMax, cptlNeed, cptli;
  30. // If we're recording the drawing orders for a path
  31. // then just pass the drawing order to the helper DC.
  32. // Do not emit any Win16 drawing orders.
  33. if (pLocalDC->flags & RECORDING_PATH)
  34. {
  35. if (pfnSetVirtualResolution == NULL)
  36. {
  37. bXformWorkhorse(pptl, cptl, &pLocalDC->xformRWorldToRDev);
  38. }
  39. return(PolyPolygon(pLocalDC->hdcHelper, (LPPOINT) pptl, (LPINT) pcptl, (INT) ccptl));
  40. }
  41. // NOTE: There is a semantic between the Win32 PolyPolygon and
  42. // the Win16 PolyPolygon. Win32 will close each polygon, Win16
  43. // will not. As a result, we have to insert points as necessary
  44. // to make the polygons closed. We cannot use multiple polygons
  45. // to replace a single PolyPolygon because they are different if
  46. // the polygons overlap and the polyfill mode is winding.
  47. // If there are not verrics just return TRUE.
  48. if (ccptl == 0)
  49. return(TRUE) ;
  50. b = FALSE; // assume failure
  51. // Compute the maximum size of the temporary point array required
  52. // to create closed PolyPolygon in win16.
  53. cptlMax = cptl + ccptl;
  54. // Allocate a buffer for the temporary point array.
  55. pptlBuff = (PPOINTL) LocalAlloc(LMEM_FIXED, cptlMax * sizeof(POINTL)) ;
  56. if (!pptlBuff)
  57. {
  58. PUTS("MF3216: DoPolyPolygon, LocalAlloc failed\n") ;
  59. goto exit;
  60. }
  61. // Allocate a buffer for the new polycount array and make a copy
  62. // of the old array.
  63. pcptlBuff = (PWORD) LocalAlloc(LMEM_FIXED, ccptl * sizeof(WORD)) ;
  64. if (!pcptlBuff)
  65. {
  66. PUTS("MF3216: DoPolyPolygon, LocalAlloc failed\n") ;
  67. goto exit;
  68. }
  69. for (i = 0; i < ccptl; i++)
  70. pcptlBuff[i] = (WORD) pcptl[i];
  71. // Insert the points and update the polycount as necessary.
  72. pptlDst = pptlBuff;
  73. pptlSrc = pptl;
  74. cptlNeed = cptl;
  75. for (i = 0; i < ccptl; i++)
  76. {
  77. cptli = pcptl[i];
  78. if (cptli < 2)
  79. goto exit;
  80. RtlCopyMemory(pptlDst, pptlSrc, cptli * sizeof(POINTL)) ;
  81. if (pptlDst[0].x != pptlDst[cptli - 1].x
  82. || pptlDst[0].y != pptlDst[cptli - 1].y)
  83. {
  84. pptlDst[cptli] = pptlDst[0];
  85. pptlDst++;
  86. cptlNeed++;
  87. pcptlBuff[i]++;
  88. }
  89. pptlSrc += cptli;
  90. pptlDst += cptli;
  91. }
  92. // The Win16 poly record is limited to 64K points.
  93. // Need to check this limit.
  94. if (cptlNeed > (DWORD) (WORD) MAXWORD)
  95. {
  96. PUTS("MF3216: DoPolyPolygon, Too many point in poly array\n") ;
  97. SetLastError(ERROR_NOT_ENOUGH_MEMORY) ;
  98. goto exit ;
  99. }
  100. // Do the transformations.
  101. if (transform)
  102. {
  103. if (!bXformRWorldToPPage(pLocalDC, pptlBuff, cptlNeed))
  104. goto exit;
  105. }
  106. // Compress the POINTLs to POINTSs
  107. vCompressPoints(pptlBuff, cptlNeed) ;
  108. // Call the Win16 routine to emit the PolyPolygon to the metafile.
  109. if (ccptl == 1)
  110. {
  111. b = bEmitWin16Poly(pLocalDC, (PPOINTS) pptlBuff, (WORD)cptlNeed, META_POLYGON);
  112. }
  113. else
  114. {
  115. b = bEmitWin16PolyPolygon(pLocalDC, (PPOINTS) pptlBuff,
  116. pcptlBuff, (WORD) cptlNeed, (WORD) ccptl);
  117. }
  118. exit:
  119. // Free the memory.
  120. if (pptlBuff)
  121. if (LocalFree(pptlBuff))
  122. ASSERTGDI(FALSE, "MF3216: DoPolyPolygon, LocalFree failed");
  123. if (pcptlBuff)
  124. if (LocalFree(pcptlBuff))
  125. ASSERTGDI(FALSE, "MF3216: DoPolyPolygon, LocalFree failed");
  126. return(b) ;
  127. }
  128. /***************************************************************************
  129. * SetPolyFillMode - Win32 to Win16 Metafile Converter Entry Point
  130. **************************************************************************/
  131. BOOL WINAPI DoSetPolyFillMode
  132. (
  133. PLOCALDC pLocalDC,
  134. DWORD iPolyFillMode
  135. )
  136. {
  137. BOOL b ;
  138. // Emit the Win16 metafile drawing order.
  139. b = bEmitWin16SetPolyFillMode(pLocalDC, LOWORD(iPolyFillMode)) ;
  140. return(b) ;
  141. }