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.

211 lines
7.3 KiB

  1. /*****************************************************************************
  2. *
  3. * Preamble - Preamble routines for MF3216
  4. *
  5. * Date: 7/18/91
  6. * Author: Jeffrey Newman (c-jeffn)
  7. *
  8. * Copyright 1991 Microsoft Corp
  9. *****************************************************************************/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. BOOL bSetWindowOrgAndExtToFrame(PLOCALDC pLocalDC, PENHMETAHEADER pmf32header) ;
  13. /*----------------------------------------------------------------------------
  14. * DoHeader - Emit the Win16 metafile header
  15. *---------------------------------------------------------------------------*/
  16. BOOL APIENTRY DoHeader(PLOCALDC pLocalDC, PENHMETAHEADER pemfheader)
  17. {
  18. BOOL b ;
  19. b = bInitHandleTableManager(pLocalDC, pemfheader) ;
  20. if (b == FALSE)
  21. goto error_exit ;
  22. b = bInitXformMatrices(pLocalDC, pemfheader) ;
  23. if (b == FALSE)
  24. goto error_exit ;
  25. // The metafile will always be memory based.
  26. pLocalDC->mf16Header.mtType = MEMORYMETAFILE ;
  27. pLocalDC->mf16Header.mtVersion = 0x300 ; // magic number for Win3.0
  28. pLocalDC->mf16Header.mtHeaderSize = sizeof (METAHEADER) / 2 ;
  29. // Init fields to 0. They will be updated at the end of translation.
  30. pLocalDC->mf16Header.mtSize = 0 ;
  31. pLocalDC->mf16Header.mtNoObjects = 0 ;
  32. pLocalDC->mf16Header.mtMaxRecord = 0 ; // NOTE: We need a max record size.
  33. pLocalDC->mf16Header.mtNoParameters = 0 ;
  34. // Emit the MF16 metafile header to the metafile.
  35. b = bEmit(pLocalDC, &pLocalDC->mf16Header, sizeof(METAHEADER)) ;
  36. if (b == FALSE)
  37. goto error_exit ;
  38. if (pLocalDC->flags & INCLUDE_W32MF_COMMENT)
  39. {
  40. b = bHandleWin32Comment(pLocalDC) ;
  41. if (b == FALSE)
  42. goto error_exit ;
  43. }
  44. // Prepare the transform for the 16-bit metafile. See comments in
  45. // xforms.c.
  46. // Emit the Win16 MapMode record
  47. b = bEmitWin16SetMapMode(pLocalDC, LOWORD(pLocalDC->iMapMode)) ;
  48. if (b == FALSE)
  49. goto error_exit ;
  50. // Set the Win16 metafile WindowExt to the size of the frame
  51. // in play-time device units.
  52. b = bSetWindowOrgAndExtToFrame(pLocalDC, pemfheader) ;
  53. if (b == FALSE)
  54. {
  55. RIP("MF3216: DoHeader, bSetWindowOrgAndExtToFrame failure\n") ;
  56. goto error_exit ;
  57. }
  58. error_exit:
  59. return(b) ;
  60. }
  61. /*----------------------------------------------------------------------------
  62. * Calculate and Emit into the Win16 metafile a Window origin
  63. * and extent drawing order
  64. * that will set the Window Origin and Extent to the size of the picture frame in
  65. * play-time-page (reference-logical) units.
  66. *---------------------------------------------------------------------------*/
  67. BOOL bSetWindowOrgAndExtToFrame(PLOCALDC pLocalDC, PENHMETAHEADER pmf32header)
  68. {
  69. FLOAT ecxPpmmPlay, // cx pixels per millimeter play
  70. ecyPpmmPlay, // cy pixels per millimeter play
  71. ecx01PpmmPlay, // cx pixels per .01 millimeter play
  72. ecy01PpmmPlay, // cy pixels per .01 millimeter play
  73. ecxPelsFrame, // cx play-time frame in device units
  74. ecyPelsFrame, // cy play-time frame in device units
  75. exPelsFrame, // x play-time frame in device units
  76. eyPelsFrame ; // y play-time frame in device units
  77. INT cxFrame, // cx Picture Frame
  78. cyFrame, // cy Picture Frame
  79. xFrame, // x Picture Frame
  80. yFrame ; // y Picture Frame
  81. SIZEL szlFrame ;
  82. POINTL ptlFrame ;
  83. // Calculate the play-time (reference) pixels per millimeter.
  84. ecxPpmmPlay = (FLOAT) pLocalDC->cxPlayDevPels / (FLOAT) pLocalDC->cxPlayDevMM ;
  85. ecyPpmmPlay = (FLOAT) pLocalDC->cyPlayDevPels / (FLOAT) pLocalDC->cyPlayDevMM ;
  86. // Scale the pixels per millimeter to pixels per .01 millimeters.
  87. ecx01PpmmPlay = ecxPpmmPlay / 100.0f ;
  88. ecy01PpmmPlay = ecyPpmmPlay / 100.0f ;
  89. // Pickup the fram origin
  90. xFrame = pmf32header->rclFrame.left ;
  91. yFrame = pmf32header->rclFrame.top ;
  92. // Translate the frame origin to play-time-device units.
  93. exPelsFrame = ecx01PpmmPlay * (FLOAT) xFrame ;
  94. eyPelsFrame = ecy01PpmmPlay * (FLOAT) yFrame ;
  95. // Convert the Frame origin to play-time-page units.
  96. // (aka reference-logical units.)
  97. ptlFrame.x = (LONG) (exPelsFrame * pLocalDC->xformPDevToPPage.eM11 + 0.5f);
  98. ptlFrame.y = (LONG) (eyPelsFrame * pLocalDC->xformPDevToPPage.eM22 + 0.5f);
  99. if (!bCoordinateOverflowTest((PLONG) &ptlFrame, 2))
  100. return(FALSE);
  101. // Set the Window origin.
  102. if (!bEmitWin16SetWindowOrg(pLocalDC,
  103. (SHORT) ptlFrame.x,
  104. (SHORT) ptlFrame.y))
  105. {
  106. RIP("MF3216: bEmitWin16SetWindowOrg failed\n") ;
  107. return(FALSE);
  108. }
  109. // Calculate the Frame width and height.
  110. cxFrame = pmf32header->rclFrame.right - pmf32header->rclFrame.left ;
  111. cyFrame = pmf32header->rclFrame.bottom - pmf32header->rclFrame.top ;
  112. // Convert the frame width and height into play-time-device units.
  113. // (aka reference-device units.)
  114. ecxPelsFrame = ecx01PpmmPlay * (FLOAT) cxFrame ;
  115. ecyPelsFrame = ecy01PpmmPlay * (FLOAT) cyFrame ;
  116. // Translate the play-time device units into play-time-page units.
  117. // (aka reference-device to reference-logical units.)
  118. // This is an identity transform for MM_ANISOTROPIC mode. For other
  119. // fixed mapping modes, the SetWindowExt record has no effect.
  120. szlFrame.cx = (LONG) (ecxPelsFrame + 0.5f);
  121. szlFrame.cy = (LONG) (ecyPelsFrame + 0.5f);
  122. if (!bCoordinateOverflowTest((PLONG) &szlFrame, 2))
  123. return(FALSE);
  124. // Set the Window Extent.
  125. if (!bEmitWin16SetWindowExt(pLocalDC,
  126. (SHORT) szlFrame.cx,
  127. (SHORT) szlFrame.cy))
  128. {
  129. RIP("MF3216: bEmitWin16SetWindowExt failed\n") ;
  130. return(FALSE);
  131. }
  132. return(TRUE);
  133. }
  134. /*----------------------------------------------------------------------------
  135. * UpdateMf16Header - Update the metafile header with the:
  136. * metafile size,
  137. * number of objects,
  138. * the max record size.
  139. *---------------------------------------------------------------------------*/
  140. BOOL bUpdateMf16Header(PLOCALDC pLocalDC)
  141. {
  142. BOOL b ;
  143. INT iCpTemp ;
  144. // Fill in the missing info in the Win16 metafile header.
  145. pLocalDC->mf16Header.mtSize = pLocalDC->ulBytesEmitted / 2 ;
  146. pLocalDC->mf16Header.mtNoObjects = (WORD) (pLocalDC->nObjectHighWaterMark + 1) ;
  147. pLocalDC->mf16Header.mtMaxRecord = pLocalDC->ulMaxRecord ;
  148. // Reset the output buffer index to the beginning of the buffer.
  149. iCpTemp = pLocalDC->ulBytesEmitted ;
  150. pLocalDC->ulBytesEmitted = 0 ;
  151. // re-emit the Win16 metafile header.
  152. b = bEmit(pLocalDC, &pLocalDC->mf16Header, (DWORD) sizeof (pLocalDC->mf16Header)) ;
  153. pLocalDC->ulBytesEmitted = iCpTemp ;
  154. return (b) ;
  155. }