GraphicsState.jvm.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // System.Drawing.Drawing2D.ExtendedGraphicsState.jvm.cs
  3. //
  4. // Author:
  5. // Vladimir Krasnov ([email protected])
  6. //
  7. // Copyright (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Drawing.Text;
  31. using geom = java.awt.geom;
  32. using awt = java.awt;
  33. namespace System.Drawing.Drawing2D
  34. {
  35. /// <summary>
  36. /// Summary description for GraphicsState.
  37. /// </summary>
  38. public sealed class GraphicsState : MarshalByRefObject
  39. {
  40. readonly CompositingMode _compositingMode;
  41. readonly CompositingQuality _compositingQuality;
  42. readonly Region _clip;
  43. readonly awt.Shape _baseClip;
  44. readonly InterpolationMode _interpolationMode;
  45. readonly float _pageScale;
  46. readonly GraphicsUnit _pageUnit;
  47. readonly PixelOffsetMode _pixelOffsetMode;
  48. readonly Point _renderingOrigin;
  49. readonly SmoothingMode _smoothingMode;
  50. readonly int _textContrast;
  51. readonly TextRenderingHint _textRenderingHint;
  52. // additional transform in case that new container has one
  53. readonly Matrix _transform;
  54. readonly Matrix _baseTransform;
  55. GraphicsState _next = null;
  56. awt.Shape _finalBaseClip = null;
  57. internal GraphicsState(Graphics graphics, bool resetState)
  58. : this(graphics, Matrix.IdentityTransform, resetState) {}
  59. internal GraphicsState Next {
  60. get {
  61. return _next;
  62. }
  63. set {
  64. _next = value;
  65. }
  66. }
  67. internal GraphicsState(Graphics graphics, Matrix matrix, bool resetState)
  68. {
  69. _compositingMode = graphics.CompositingMode;
  70. _compositingQuality = graphics.CompositingQuality;
  71. _clip = graphics.ScaledClip;
  72. _baseClip = graphics.NativeObject.getClip();
  73. _interpolationMode = graphics.InterpolationMode;
  74. _pageScale = graphics.PageScale;
  75. _pageUnit = graphics.PageUnit;
  76. _pixelOffsetMode = graphics.PixelOffsetMode;
  77. // FIXME: render orign is not implemented yet
  78. //_renderingOrigin = new Point( g.RenderingOrigin.X, g.RenderingOrigin.Y );
  79. _smoothingMode = graphics.SmoothingMode;
  80. _transform = graphics.Transform;
  81. _baseTransform = graphics.BaseTransform;
  82. _textContrast = graphics.TextContrast;
  83. _textRenderingHint = graphics.TextRenderingHint;
  84. if (resetState)
  85. ResetState(graphics, matrix);
  86. }
  87. internal void RestoreState(Graphics graphics)
  88. {
  89. graphics.CompositingMode = _compositingMode;
  90. graphics.CompositingQuality = _compositingQuality;
  91. graphics.ScaledClip = _clip;
  92. graphics.InterpolationMode = _interpolationMode;
  93. graphics.PageScale = _pageScale;
  94. graphics.PageUnit = _pageUnit;
  95. graphics.PixelOffsetMode = _pixelOffsetMode;
  96. // FIXME: render orign is not implemented yet
  97. //graphics.RenderingOrigin = new Point( _renderingOrigin.X, _renderingOrigin.Y );
  98. graphics.SmoothingMode = _smoothingMode;
  99. graphics.Transform = _transform;
  100. graphics.BaseTransform = _baseTransform;
  101. graphics.TextContrast = _textContrast;
  102. graphics.TextRenderingHint = _textRenderingHint;
  103. // must be set after the base transform is restored
  104. graphics.NativeObject.setClip(_baseClip);
  105. }
  106. void ResetState(Graphics graphics, Matrix matrix)
  107. {
  108. //should be set before the base transform is changed
  109. if (_baseClip == null)
  110. graphics.IntersectScaledClipWithBase(graphics.VisibleShape);
  111. graphics.IntersectScaledClipWithBase(_clip);
  112. graphics.CompositingMode = CompositingMode.SourceOver;
  113. graphics.CompositingQuality = CompositingQuality.Default;
  114. graphics.Clip = Region.InfiniteRegion;
  115. graphics.InterpolationMode = InterpolationMode.Bilinear;
  116. graphics.PageScale = 1.0f;
  117. graphics.PageUnit = GraphicsUnit.Display;
  118. graphics.PixelOffsetMode = PixelOffsetMode.Default;
  119. // FIXME: render orign is not implemented yet
  120. //graphics.RenderingOrigin = new Point(0, 0);
  121. graphics.SmoothingMode = SmoothingMode.None;
  122. graphics.ResetTransform();
  123. graphics.PrependBaseTransform(Graphics.GetFinalTransform(_transform.NativeObject, _pageUnit, _pageScale));
  124. graphics.PrependBaseTransform(matrix.NativeObject);
  125. graphics.TextContrast = 4;
  126. graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
  127. geom.AffineTransform finalBaseTransform = graphics.NativeObject.getTransform();
  128. graphics.NativeObject.setTransform(Matrix.IdentityTransform.NativeObject);
  129. _finalBaseClip = graphics.NativeObject.getClip();
  130. graphics.NativeObject.setTransform(finalBaseTransform);
  131. }
  132. internal void RestoreBaseClip(Graphics graphics) {
  133. if (_finalBaseClip == null) {
  134. graphics.NativeObject.setClip(null);
  135. return;
  136. }
  137. geom.AffineTransform finalBaseTransform = graphics.NativeObject.getTransform();
  138. graphics.NativeObject.setTransform(Matrix.IdentityTransform.NativeObject);
  139. graphics.NativeObject.setClip(_finalBaseClip);
  140. graphics.NativeObject.setTransform(finalBaseTransform);
  141. }
  142. }
  143. }