GraphicsState.jvm.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. namespace System.Drawing.Drawing2D
  32. {
  33. /// <summary>
  34. /// Summary description for GraphicsState.
  35. /// </summary>
  36. public sealed class GraphicsState : MarshalByRefObject
  37. {
  38. // Constructor
  39. internal GraphicsState()
  40. {
  41. }
  42. internal GraphicsState(Graphics graphics, bool resetState) : base()
  43. {
  44. this.SaveState(graphics);
  45. if (resetState)
  46. this.ResetState(graphics);
  47. }
  48. private CompositingMode _compositingMode;
  49. private CompositingQuality _compositingQuality;
  50. private Region _clip;
  51. private InterpolationMode _interpolationMode;
  52. private float _pageScale = 0;
  53. private GraphicsUnit _pageUnit;
  54. private PixelOffsetMode _pixelOffsetMode;
  55. private Point _renderingOrigin;
  56. private SmoothingMode _smoothingMode;
  57. private Matrix _transform = null;
  58. private int _textContrast;
  59. private TextRenderingHint _textRenderingHint;
  60. // additional transform in case that new container has one
  61. private Matrix _containerTransform;
  62. internal Matrix ContainerTransfrom
  63. {
  64. get {return _containerTransform;}
  65. set {_containerTransform = value;}
  66. }
  67. internal void SaveState(Graphics g)
  68. {
  69. if (g != null)
  70. {
  71. try
  72. {
  73. _compositingMode = g.CompositingMode;
  74. _compositingQuality = g.CompositingQuality;
  75. _clip = g.Clip.Clone();
  76. _interpolationMode = g.InterpolationMode;
  77. _pageScale = g.PageScale;
  78. _pageUnit = g.PageUnit;
  79. _pixelOffsetMode = g.PixelOffsetMode;
  80. // FIXME: render orign is not implemented yet
  81. //_renderingOrigin = new Point( g.RenderingOrigin.X, g.RenderingOrigin.Y );
  82. _smoothingMode = g.SmoothingMode;
  83. _transform = g.Transform.Clone();
  84. _textContrast = g.TextContrast;
  85. _textRenderingHint = g.TextRenderingHint;
  86. }
  87. finally
  88. {
  89. }
  90. }
  91. }
  92. internal void RestoreState(Graphics g)
  93. {
  94. if (g != null)
  95. {
  96. try
  97. {
  98. g.CompositingMode = _compositingMode;
  99. g.CompositingQuality = _compositingQuality;
  100. g.Clip = _clip;
  101. g.InterpolationMode = _interpolationMode;
  102. g.PageScale = _pageScale;
  103. g.PageUnit = _pageUnit;
  104. g.PixelOffsetMode = _pixelOffsetMode;
  105. // FIXME: render orign is not implemented yet
  106. //g.RenderingOrigin = new Point( _renderingOrigin.X, _renderingOrigin.Y );
  107. g.SmoothingMode = _smoothingMode;
  108. g.Transform = _transform;
  109. g.TextContrast = _textContrast;
  110. g.TextRenderingHint = _textRenderingHint;
  111. }
  112. finally
  113. {
  114. }
  115. }
  116. }
  117. public void ResetState(Graphics g)
  118. {
  119. if (g != null)
  120. {
  121. try
  122. {
  123. g.CompositingMode = CompositingMode.SourceOver;
  124. g.CompositingQuality = CompositingQuality.Default;
  125. g.Clip = Region.InfiniteRegion;
  126. g.InterpolationMode = InterpolationMode.Bilinear;
  127. g.PageScale = 1.0f;
  128. g.PageUnit = GraphicsUnit.Display;
  129. g.PixelOffsetMode = PixelOffsetMode.Default;
  130. // FIXME: render orign is not implemented yet
  131. //g.RenderingOrigin = new Point(0, 0);
  132. g.SmoothingMode = SmoothingMode.None;
  133. g.ResetTransform();
  134. g.TextContrast = 4;
  135. g.TextRenderingHint = TextRenderingHint.SystemDefault;
  136. }
  137. finally
  138. {
  139. }
  140. }
  141. }
  142. }
  143. }