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.

241 lines
8.3 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * DpContext - DDI-level device context
  8. *
  9. * Abstract:
  10. *
  11. * This is the DDI-level portion of the GpGraphics object.
  12. *
  13. * Notes:
  14. *
  15. *
  16. *
  17. * Revision History:
  18. *
  19. * 12/01/1998 andrewgo
  20. * Created it.
  21. * 03/24/1999 agodfrey
  22. * Moved it into a separate file for the preliminary DDI.
  23. *
  24. \**************************************************************************/
  25. #ifndef _DPCONTEXT_HPP
  26. #define _DPCONTEXT_HPP
  27. // This enum specifies what we should do about
  28. // the ICM mode on the destination HDC.
  29. enum HdcIcmMode {
  30. IcmModeOff, // must turn it off
  31. IcmModeOn // must turn it on
  32. };
  33. //--------------------------------------------------------------------------
  34. // Represent context information for the call
  35. //--------------------------------------------------------------------------
  36. class DpContext
  37. {
  38. public:
  39. static LONG Uniqueness; // Used with Id's
  40. DpContext * Prev; // For save/restore (push/pop)
  41. DpContext * Next;
  42. UINT Id; // For save/restore
  43. INT AntiAliasMode;
  44. GpTextRenderingHint TextRenderHint; // For AntiAlias Text and
  45. GpCompositingMode CompositingMode;
  46. GpCompositingQuality CompositingQuality;
  47. INT RenderingOriginX; // Origin for halftone/dither matrices
  48. INT RenderingOriginY;
  49. UINT TextContrast;
  50. InterpolationMode FilterType;
  51. PixelOffsetMode PixelOffset;
  52. Unit PageUnit;
  53. REAL PageScale;
  54. REAL PageMultiplierX; // combination of PageUnit and PageScale
  55. REAL PageMultiplierY; // combination of PageUnit and PageScale
  56. REAL ContainerDpiX; // The Dpi for the current container
  57. REAL ContainerDpiY; // The Dpi for the current container
  58. REAL MetafileRasterizationLimitDpi;
  59. GpMatrix WorldToPage;
  60. GpMatrix WorldToDevice; // includes container transform
  61. GpMatrix ContainerToDevice; // container transform
  62. mutable GpMatrix DeviceToWorld; // lazy inverse of WorldToDevice
  63. mutable BOOL InverseOk; // if DeviceToWorld is up to date
  64. DpClipRegion VisibleClip; // The combination of all clip regions
  65. DpRegion ContainerClip; // For container clipping. Includes the WindowClip
  66. GpRegion AppClip; // The current logical region that
  67. // defines the current clipping
  68. HDC Hdc; // If the Graphics was derived from
  69. // an 'hdc', this is the DC handle.
  70. // NOTE: We may have changed the
  71. // state in it
  72. HWND Hwnd; // Window handle if we know it
  73. HdcIcmMode IcmMode; // Icm Mode for the DC.
  74. BOOL IsEmfPlusHdc; // If it is an EMF+ metafile HDC or not
  75. BOOL IsPrinter; // Represents a printer context
  76. BOOL IsDisplay; // Is this context associated with a display?
  77. INT SaveDc; // Represents the SaveDC level if the
  78. // Hdc had a SaveDC done on it since
  79. // it was given to us
  80. ColorPalette * Palette; // Context palette or NULL for system palette
  81. EpPaletteMap * PaletteMap; // Mapping to Palette or system palette
  82. HFONT CurrentHFont; // GdiPlus has created an hfont and selected
  83. HFONT OriginalHFont; // it into the DC. Before releasing
  84. // the DC, the original font should be
  85. // reselected, and the current font
  86. // deleted.
  87. const GpFontFace *Face; // Font face of currently selected font
  88. GpMatrix FontTransform; // Transform for currently selected font
  89. INT Style; // Style for currently selected font
  90. BOOL GdiLayered; // TRUE if GDI layering is enabled
  91. // on the target. If so, GDI is
  92. // rendering to the screen is
  93. // actually redirected to a backing
  94. // store inaccessible via DCI.
  95. // GDI must be used for rendering.
  96. public:
  97. DpContext(
  98. BOOL isDisplay
  99. );
  100. DpContext(
  101. DpContext * prev // must not be NULL
  102. );
  103. ~DpContext();
  104. // GetHdc() will automatically initialize (to default values) parts of the
  105. // DC. It doesn't reset *all* attributes, though!
  106. HDC
  107. GetHdc( // May return NULL if not originally a GDI surface
  108. DpBitmap *surface
  109. );
  110. VOID
  111. ReleaseHdc(
  112. HDC hdc,
  113. DpBitmap *surface = NULL
  114. );
  115. VOID
  116. CleanTheHdc(
  117. HDC hdc
  118. );
  119. // ResetHdc() restores the HDC to the state in which it was given
  120. // to us:
  121. VOID ResetHdc(
  122. VOID
  123. );
  124. VOID UpdateWorldToDeviceMatrix()
  125. {
  126. GpMatrix::ScaleMatrix(
  127. WorldToDevice,
  128. WorldToPage,
  129. PageMultiplierX,
  130. PageMultiplierY);
  131. // GillesK:
  132. // PixelOffsetModeDefault and PixelOffsetModeHighSpeed are PixelOffsetNone,
  133. if (PixelOffset == PixelOffsetModeHalf || PixelOffset == PixelOffsetModeHighQuality)
  134. {
  135. WorldToDevice.Translate(-0.5f, -0.5f, MatrixOrderAppend);
  136. }
  137. if (!ContainerToDevice.IsIdentity())
  138. {
  139. GpMatrix::MultiplyMatrix(
  140. WorldToDevice,
  141. WorldToDevice,
  142. ContainerToDevice);
  143. }
  144. }
  145. GpStatus
  146. GetDeviceToWorld(
  147. GpMatrix* deviceToWorld
  148. ) const;
  149. VOID
  150. GetPageMultipliers(
  151. REAL * pageMultiplierX,
  152. REAL * pageMultiplierY,
  153. GpPageUnit unit = UnitDisplay,
  154. REAL scale = 1.0f
  155. ) const;
  156. VOID
  157. GetPageMultipliers()
  158. {
  159. GetPageMultipliers(&PageMultiplierX, &PageMultiplierY,
  160. PageUnit, PageScale);
  161. }
  162. // Text optimisation hdc generation
  163. GpStatus UpdateCurrentHFont(
  164. BYTE quality,
  165. const PointF & scale,
  166. INT angle,
  167. HDC hdc,
  168. BOOL sideway,
  169. BYTE charSet = 0xFF
  170. );
  171. private:
  172. VOID DeleteCurrentHFont();
  173. public:
  174. // successful call to SelectCurrentHFont or GetTextOutputHdc must have
  175. // matching ReleaseTextOutputHdc call
  176. GpStatus SelectCurrentHFont(HDC hdc);
  177. HDC
  178. GetTextOutputHdc(
  179. const GpFaceRealization *faceRealization, // In - Font face required
  180. GpColor color, // In - Required GdiPlus brush effect
  181. DpBitmap *surface, // In
  182. INT *angle // Out
  183. );
  184. VOID ReleaseTextOutputHdc(HDC hdc);
  185. REAL GetDpiX() const { return ContainerDpiX; }
  186. REAL GetDpiY() const { return ContainerDpiY; }
  187. // Used only when recording a EMF or EMF+ through GpMetafile class
  188. VOID
  189. SetMetafileDownLevelRasterizationLimit(
  190. UINT metafileRasterizationLimitDpi
  191. );
  192. // Used only when recording a EMF or EMF+ through GpMetafile class
  193. UINT
  194. GetMetafileDownLevelRasterizationLimit() const
  195. {
  196. return GpRound(MetafileRasterizationLimitDpi);
  197. }
  198. };
  199. #endif