PageSettings.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // System.Drawing.PageSettings.cs
  3. //
  4. // Authors:
  5. // Dennis Hayes ([email protected])
  6. // Herve Poussineau ([email protected])
  7. // Andreas Nahr ([email protected])
  8. //
  9. // (C) 2002 Ximian, Inc
  10. //
  11. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System;
  34. using System.Runtime.InteropServices;
  35. namespace System.Drawing.Printing
  36. {
  37. #if NET_2_0
  38. [Serializable]
  39. #else
  40. [ComVisible (false)]
  41. #endif
  42. public class PageSettings : ICloneable
  43. {
  44. bool _Color;
  45. bool _Landscape;
  46. float _HardMarginX;
  47. float _HardMarginY;
  48. RectangleF _PrintableArea;
  49. // create a new default Margins object (is 1 inch for all margins)
  50. Margins _Margins = new Margins();
  51. PaperSize _PaperSize;
  52. PaperSource _PaperSource;
  53. PrinterResolution _PrinterResolution;
  54. PrinterSettings _PrinterSettings;
  55. public PageSettings() : this(new PrinterSettings())
  56. {
  57. }
  58. public PageSettings(PrinterSettings printerSettings)
  59. {
  60. PrinterSettings = printerSettings;
  61. Color = printerSettings.DefaultPageSettings.Color;
  62. Landscape = printerSettings.DefaultPageSettings.Landscape;
  63. PaperSize = printerSettings.DefaultPageSettings.PaperSize;
  64. PaperSource = printerSettings.DefaultPageSettings.PaperSource;
  65. PrinterResolution = printerSettings.DefaultPageSettings.PrinterResolution;
  66. }
  67. // used by PrinterSettings.DefaultPageSettings
  68. internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
  69. {
  70. PrinterSettings = printerSettings;
  71. Color = color;
  72. Landscape = landscape;
  73. PaperSize = paperSize;
  74. PaperSource = paperSource;
  75. PrinterResolution = printerResolution;
  76. }
  77. //props
  78. public Rectangle Bounds{
  79. get{
  80. int width = this.PaperSize.Width;
  81. int height = this.PaperSize.Height;
  82. width -= this.Margins.Left + this.Margins.Right;
  83. height -= this.Margins.Top + this.Margins.Bottom;
  84. if (this.Landscape) {
  85. // swap width and height
  86. int tmp = width;
  87. width = height;
  88. height = tmp;
  89. }
  90. return new Rectangle(0, 0, width, height);
  91. }
  92. }
  93. public bool Color{
  94. get{
  95. return _Color;
  96. }
  97. set{
  98. _Color = value;
  99. }
  100. }
  101. public bool Landscape {
  102. get{
  103. return _Landscape;
  104. }
  105. set{
  106. _Landscape = value;
  107. }
  108. }
  109. public Margins Margins{
  110. get{
  111. return _Margins;
  112. }
  113. set{
  114. _Margins = value;
  115. }
  116. }
  117. public PaperSize PaperSize{
  118. get{
  119. return _PaperSize;
  120. }
  121. set{
  122. _PaperSize = value;
  123. }
  124. }
  125. public PaperSource PaperSource{
  126. get{
  127. return _PaperSource;
  128. }
  129. set{
  130. _PaperSource = value;
  131. }
  132. }
  133. public PrinterResolution PrinterResolution{
  134. get{
  135. return _PrinterResolution;
  136. }
  137. set{
  138. _PrinterResolution = value;
  139. }
  140. }
  141. public PrinterSettings PrinterSettings{
  142. get{
  143. return _PrinterSettings;
  144. }
  145. set{
  146. _PrinterSettings = value;
  147. }
  148. }
  149. #if NET_2_0
  150. public float HardMarginX {
  151. get {
  152. return _HardMarginX;
  153. }
  154. }
  155. public float HardMarginY {
  156. get {
  157. return _HardMarginY;
  158. }
  159. }
  160. public RectangleF PrintableArea {
  161. get {
  162. return _PrintableArea;
  163. }
  164. }
  165. #endif
  166. public object Clone(){
  167. return new PageSettings(this.PrinterSettings);
  168. }
  169. [MonoTODO("PageSettings.CopyToHdevmode")]
  170. public void CopyToHdevmode (IntPtr hdevmode){
  171. throw new NotImplementedException ();
  172. }
  173. [MonoTODO("PageSettings.SetHdevmode")]
  174. public void SetHdevmode (IntPtr hdevmode){
  175. throw new NotImplementedException ();
  176. }
  177. public override string ToString(){
  178. string ret = "[PageSettings: Color={0}";
  179. ret += ", Landscape={1}";
  180. ret += ", Margins={2}";
  181. ret += ", PaperSize={3}";
  182. ret += ", PaperSource={4}";
  183. ret += ", PrinterResolution={5}";
  184. ret += "]";
  185. return String.Format(ret, this.Color, this.Landscape, this.Margins, this.PaperSize, this.PaperSource, this.PrinterResolution);
  186. }
  187. }
  188. }