GraphicsState.jvm.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. internal GraphicsState(Graphics graphics, bool resetState)
  57. : this(graphics, Matrix.IdentityTransform, resetState) {}
  58. internal GraphicsState Next {
  59. get {
  60. return _next;
  61. }
  62. set {
  63. _next = value;
  64. }
  65. }
  66. internal GraphicsState(Graphics graphics, Matrix matrix, bool resetState)
  67. {
  68. _compositingMode = graphics.CompositingMode;
  69. _compositingQuality = graphics.CompositingQuality;
  70. _clip = graphics.ScaledClip;
  71. _baseClip = graphics.NativeObject.getClip();
  72. _interpolationMode = graphics.InterpolationMode;
  73. _pageScale = graphics.PageScale;
  74. _pageUnit = graphics.PageUnit;
  75. _pixelOffsetMode = graphics.PixelOffsetMode;
  76. // FIXME: render orign is not implemented yet
  77. //_renderingOrigin = new Point( g.RenderingOrigin.X, g.RenderingOrigin.Y );
  78. _smoothingMode = graphics.SmoothingMode;
  79. _transform = graphics.Transform;
  80. _baseTransform = graphics.BaseTransform;
  81. _textContrast = graphics.TextContrast;
  82. _textRenderingHint = graphics.TextRenderingHint;
  83. if (resetState)
  84. ResetState(graphics, matrix);
  85. }
  86. internal void RestoreState(Graphics graphics)
  87. {
  88. graphics.CompositingMode = _compositingMode;
  89. graphics.CompositingQuality = _compositingQuality;
  90. graphics.ScaledClip = _clip;
  91. graphics.InterpolationMode = _interpolationMode;
  92. graphics.PageScale = _pageScale;
  93. graphics.PageUnit = _pageUnit;
  94. graphics.PixelOffsetMode = _pixelOffsetMode;
  95. // FIXME: render orign is not implemented yet
  96. //graphics.RenderingOrigin = new Point( _renderingOrigin.X, _renderingOrigin.Y );
  97. graphics.SmoothingMode = _smoothingMode;
  98. graphics.Transform = _transform;
  99. graphics.BaseTransform = _baseTransform;
  100. graphics.TextContrast = _textContrast;
  101. graphics.TextRenderingHint = _textRenderingHint;
  102. // must be set after the base transform is restored
  103. graphics.NativeObject.setClip(_baseClip);
  104. }
  105. void ResetState(Graphics graphics, Matrix matrix)
  106. {
  107. //should be set before the base transform is changed
  108. if (_baseClip == null)
  109. graphics.IntersectScaledClipWithBase(graphics.VisibleShape);
  110. graphics.CompositingMode = CompositingMode.SourceOver;
  111. graphics.CompositingQuality = CompositingQuality.Default;
  112. graphics.ScaledClip = Region.InfiniteRegion;
  113. graphics.InterpolationMode = InterpolationMode.Bilinear;
  114. graphics.PageScale = 1.0f;
  115. graphics.PageUnit = GraphicsUnit.Display;
  116. graphics.PixelOffsetMode = PixelOffsetMode.Default;
  117. // FIXME: render orign is not implemented yet
  118. //graphics.RenderingOrigin = new Point(0, 0);
  119. graphics.SmoothingMode = SmoothingMode.None;
  120. graphics.ResetTransform();
  121. graphics.PrependBaseTransform(Graphics.GetFinalTransform(_transform.NativeObject, _pageUnit, _pageScale));
  122. graphics.PrependBaseTransform(matrix.NativeObject);
  123. graphics.TextContrast = 4;
  124. graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
  125. }
  126. internal void RestoreBaseClip(Graphics graphics) {
  127. graphics.NativeObject.setClip(_baseClip);
  128. }
  129. }
  130. }