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.

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